pep8
This commit is contained in:
parent
5ba454752e
commit
92f2d46c47
401
dominion_tabs.py
401
dominion_tabs.py
@ -24,6 +24,7 @@ def split(l, n):
|
|||||||
|
|
||||||
|
|
||||||
class Card:
|
class Card:
|
||||||
|
|
||||||
def __init__(self, name, cardset, types, cost, description='', potcost=0):
|
def __init__(self, name, cardset, types, cost, description='', potcost=0):
|
||||||
self.name = name.strip()
|
self.name = name.strip()
|
||||||
self.cardset = cardset.strip()
|
self.cardset = cardset.strip()
|
||||||
@ -62,6 +63,7 @@ class Card:
|
|||||||
|
|
||||||
|
|
||||||
class BlankCard(Card):
|
class BlankCard(Card):
|
||||||
|
|
||||||
def __init__(self, num):
|
def __init__(self, num):
|
||||||
Card.__init__(self, str(num), 'extra', ('Blank',), 0)
|
Card.__init__(self, str(num), 'extra', ('Blank',), 0)
|
||||||
|
|
||||||
@ -70,6 +72,7 @@ class BlankCard(Card):
|
|||||||
|
|
||||||
|
|
||||||
class CardType:
|
class CardType:
|
||||||
|
|
||||||
def __init__(self, typeNames, tabImageFile, tabTextHeightOffset=0, tabCostHeightOffset=-1):
|
def __init__(self, typeNames, tabImageFile, tabTextHeightOffset=0, tabCostHeightOffset=-1):
|
||||||
self.typeNames = typeNames
|
self.typeNames = typeNames
|
||||||
self.tabImageFile = tabImageFile
|
self.tabImageFile = tabImageFile
|
||||||
@ -95,6 +98,7 @@ class CardType:
|
|||||||
def getTabCostHeightOffset(self):
|
def getTabCostHeightOffset(self):
|
||||||
return self.tabCostHeightOffset
|
return self.tabCostHeightOffset
|
||||||
|
|
||||||
|
|
||||||
class DominionTabs:
|
class DominionTabs:
|
||||||
cardTypes = [
|
cardTypes = [
|
||||||
CardType(('Action',), 'action.png'),
|
CardType(('Action',), 'action.png'),
|
||||||
@ -187,45 +191,51 @@ class DominionTabs:
|
|||||||
self.odd = True
|
self.odd = True
|
||||||
|
|
||||||
def add_inline_images(self, text, fontsize):
|
def add_inline_images(self, text, fontsize):
|
||||||
path = os.path.join(self.filedir,'images')
|
path = os.path.join(self.filedir, 'images')
|
||||||
replace = '<img src='"'%s/coin_small_\\1.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (path,fontsize*1.2)
|
replace = '<img src='"'%s/coin_small_\\1.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||||
text = re.sub('(\d)\s(c|C)oin(s)?', replace,text)
|
path, fontsize * 1.2)
|
||||||
replace = '<img src='"'%s/coin_small_question.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (path,fontsize*1.2)
|
text = re.sub('(\d)\s(c|C)oin(s)?', replace, text)
|
||||||
text = re.sub('\?\s(c|C)oin(s)?', replace,text)
|
replace = '<img src='"'%s/coin_small_question.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||||
replace = '<img src='"'%s/victory_emblem.png'"' width=%d height='"'120%%'"' valign='"'middle'"'/>' % (path,fontsize*1.5)
|
path, fontsize * 1.2)
|
||||||
text = re.sub('\<VP\>', replace,text)
|
text = re.sub('\?\s(c|C)oin(s)?', replace, text)
|
||||||
|
replace = '<img src='"'%s/victory_emblem.png'"' width=%d height='"'120%%'"' valign='"'middle'"'/>' % (
|
||||||
|
path, fontsize * 1.5)
|
||||||
|
text = re.sub('\<VP\>', replace, text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def drawOutline(self, x, y, rightSide, isBack=False, isExpansionDivider=False):
|
def drawOutline(self, x, y, rightSide, isBack=False, isExpansionDivider=False):
|
||||||
#draw outline or cropmarks
|
# draw outline or cropmarks
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
self.canvas.setLineWidth(self.options.linewidth)
|
self.canvas.setLineWidth(self.options.linewidth)
|
||||||
cropmarksright = (x == self.numTabsHorizontal-1)
|
cropmarksright = (x == self.numTabsHorizontal - 1)
|
||||||
cropmarksleft = (x == 0)
|
cropmarksleft = (x == 0)
|
||||||
if rightSide:
|
if rightSide:
|
||||||
self.canvas.translate(self.tabWidth,0)
|
self.canvas.translate(self.tabWidth, 0)
|
||||||
self.canvas.scale(-1,1)
|
self.canvas.scale(-1, 1)
|
||||||
if not self.options.cropmarks and not isBack:
|
if not self.options.cropmarks and not isBack:
|
||||||
#don't draw outline on back, in case lines don't line up with front
|
# don't draw outline on back, in case lines don't line up with
|
||||||
|
# front
|
||||||
if isExpansionDivider and self.options.centre_expansion_dividers:
|
if isExpansionDivider and self.options.centre_expansion_dividers:
|
||||||
outline = self.expansionTabOutline
|
outline = self.expansionTabOutline
|
||||||
else:
|
else:
|
||||||
outline = self.tabOutline
|
outline = self.tabOutline
|
||||||
self.canvas.lines(outline)
|
self.canvas.lines(outline)
|
||||||
elif self.options.cropmarks:
|
elif self.options.cropmarks:
|
||||||
cmw = 0.5*cm
|
cmw = 0.5 * cm
|
||||||
|
|
||||||
# Horizontal-line cropmarks
|
# Horizontal-line cropmarks
|
||||||
mirror = cropmarksright and not rightSide or cropmarksleft and rightSide
|
mirror = cropmarksright and not rightSide or cropmarksleft and rightSide
|
||||||
if mirror:
|
if mirror:
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
self.canvas.translate(self.tabWidth,0)
|
self.canvas.translate(self.tabWidth, 0)
|
||||||
self.canvas.scale(-1,1)
|
self.canvas.scale(-1, 1)
|
||||||
if cropmarksleft or cropmarksright:
|
if cropmarksleft or cropmarksright:
|
||||||
self.canvas.line(-2*cmw,0,-cmw,0)
|
self.canvas.line(-2 * cmw, 0, -cmw, 0)
|
||||||
self.canvas.line(-2*cmw,self.tabBaseHeight,-cmw,self.tabBaseHeight)
|
self.canvas.line(-2 * cmw,
|
||||||
|
self.tabBaseHeight, -cmw, self.tabBaseHeight)
|
||||||
if y > 0:
|
if y > 0:
|
||||||
self.canvas.line(-2*cmw,self.tabHeight,-cmw,self.tabHeight)
|
self.canvas.line(-2 * cmw,
|
||||||
|
self.tabHeight, -cmw, self.tabHeight)
|
||||||
if mirror:
|
if mirror:
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
|
|
||||||
@ -245,18 +255,18 @@ class DominionTabs:
|
|||||||
middleLine = self.tabWidth - self.tabLabelWidth
|
middleLine = self.tabWidth - self.tabLabelWidth
|
||||||
|
|
||||||
if y == 0:
|
if y == 0:
|
||||||
self.canvas.line(rightLine,-2*cmw,rightLine,-cmw)
|
self.canvas.line(rightLine, -2 * cmw, rightLine, -cmw)
|
||||||
self.canvas.line(middleLine,-2*cmw,middleLine,-cmw)
|
self.canvas.line(middleLine, -2 * cmw, middleLine, -cmw)
|
||||||
if cropmarksleft:
|
if cropmarksleft:
|
||||||
self.canvas.line(leftLine,-2*cmw,leftLine,-cmw)
|
self.canvas.line(leftLine, -2 * cmw, leftLine, -cmw)
|
||||||
if y == self.numTabsVertical-1:
|
if y == self.numTabsVertical - 1:
|
||||||
self.canvas.line(rightLine,self.tabHeight+cmw,
|
self.canvas.line(rightLine, self.tabHeight + cmw,
|
||||||
rightLine,self.tabHeight+2*cmw)
|
rightLine, self.tabHeight + 2 * cmw)
|
||||||
self.canvas.line(middleLine, self.tabHeight+cmw,
|
self.canvas.line(middleLine, self.tabHeight + cmw,
|
||||||
middleLine, self.tabHeight+2*cmw)
|
middleLine, self.tabHeight + 2 * cmw)
|
||||||
if cropmarksleft:
|
if cropmarksleft:
|
||||||
self.canvas.line(leftLine,self.tabHeight+cmw,
|
self.canvas.line(leftLine, self.tabHeight + cmw,
|
||||||
leftLine,self.tabHeight+2*cmw)
|
leftLine, self.tabHeight + 2 * cmw)
|
||||||
|
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
|
|
||||||
@ -269,21 +279,24 @@ class DominionTabs:
|
|||||||
potHeight = y - 3
|
potHeight = y - 3
|
||||||
potSize = 11
|
potSize = 11
|
||||||
|
|
||||||
self.canvas.drawImage(os.path.join(self.filedir,'images','coin_small.png'),x,coinHeight,16,16,preserveAspectRatio=True,mask='auto')
|
self.canvas.drawImage(os.path.join(self.filedir, 'images', 'coin_small.png'),
|
||||||
|
x, coinHeight, 16, 16, preserveAspectRatio=True, mask='auto')
|
||||||
if card.potcost:
|
if card.potcost:
|
||||||
self.canvas.drawImage(os.path.join(self.filedir,'images','potion.png'),x+17,potHeight,potSize,potSize,preserveAspectRatio=True,mask=[255,255,255,255,255,255])
|
self.canvas.drawImage(os.path.join(self.filedir, 'images', 'potion.png'), x + 17,
|
||||||
|
potHeight, potSize, potSize, preserveAspectRatio=True, mask=[255, 255, 255, 255, 255, 255])
|
||||||
width += potSize
|
width += potSize
|
||||||
|
|
||||||
self.canvas.setFont('MinionPro-Bold',12)
|
self.canvas.setFont('MinionPro-Bold', 12)
|
||||||
cost = str(card.cost)
|
cost = str(card.cost)
|
||||||
if 'Prize' in card.types:
|
if 'Prize' in card.types:
|
||||||
cost += '*'
|
cost += '*'
|
||||||
self.canvas.drawCentredString(x+8,costHeight,cost)
|
self.canvas.drawCentredString(x + 8, costHeight, cost)
|
||||||
return width
|
return width
|
||||||
|
|
||||||
def drawSetIcon(self, setImage, x, y):
|
def drawSetIcon(self, setImage, x, y):
|
||||||
# set image
|
# set image
|
||||||
self.canvas.drawImage(os.path.join(self.filedir,'images',setImage), x, y, 14, 12, mask='auto')
|
self.canvas.drawImage(
|
||||||
|
os.path.join(self.filedir, 'images', setImage), x, y, 14, 12, mask='auto')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def nameWidth(self, name, fontSize):
|
def nameWidth(self, name, fontSize):
|
||||||
@ -291,31 +304,35 @@ class DominionTabs:
|
|||||||
name_parts = name.split()
|
name_parts = name.split()
|
||||||
for i, part in enumerate(name_parts):
|
for i, part in enumerate(name_parts):
|
||||||
if i != 0:
|
if i != 0:
|
||||||
w += pdfmetrics.stringWidth(' ','MinionPro-Regular',fontSize)
|
w += pdfmetrics.stringWidth(' ', 'MinionPro-Regular', fontSize)
|
||||||
w += pdfmetrics.stringWidth(part[0],'MinionPro-Regular',fontSize)
|
w += pdfmetrics.stringWidth(part[0], 'MinionPro-Regular', fontSize)
|
||||||
w += pdfmetrics.stringWidth(part[1:],'MinionPro-Regular',fontSize-2)
|
w += pdfmetrics.stringWidth(part[1:],
|
||||||
|
'MinionPro-Regular', fontSize - 2)
|
||||||
return w
|
return w
|
||||||
|
|
||||||
def drawTab(self, card, rightSide):
|
def drawTab(self, card, rightSide):
|
||||||
# draw tab flap
|
# draw tab flap
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
if card.isExpansion() and self.options.centre_expansion_dividers:
|
if card.isExpansion() and self.options.centre_expansion_dividers:
|
||||||
self.canvas.translate(self.tabWidth/2-self.tabLabelWidth/2,
|
self.canvas.translate(self.tabWidth / 2 - self.tabLabelWidth / 2,
|
||||||
self.tabHeight-self.tabLabelHeight)
|
self.tabHeight - self.tabLabelHeight)
|
||||||
elif not rightSide:
|
elif not rightSide:
|
||||||
self.canvas.translate(self.tabWidth-self.tabLabelWidth,
|
self.canvas.translate(self.tabWidth - self.tabLabelWidth,
|
||||||
self.tabHeight-self.tabLabelHeight)
|
self.tabHeight - self.tabLabelHeight)
|
||||||
else:
|
else:
|
||||||
self.canvas.translate(0,self.tabHeight-self.tabLabelHeight)
|
self.canvas.translate(0, self.tabHeight - self.tabLabelHeight)
|
||||||
|
|
||||||
textWidth = self.tabLabelWidth - 6 # allow for 3 pt border on each side
|
# allow for 3 pt border on each side
|
||||||
textHeight = self.tabLabelHeight/2-7+card.getType().getTabTextHeightOffset()
|
textWidth = self.tabLabelWidth - 6
|
||||||
|
textHeight = self.tabLabelHeight / 2 - 7 + \
|
||||||
|
card.getType().getTabTextHeightOffset()
|
||||||
|
|
||||||
# draw banner
|
# draw banner
|
||||||
img = card.getType().getNoCoinTabImageFile()
|
img = card.getType().getNoCoinTabImageFile()
|
||||||
if img:
|
if img:
|
||||||
self.canvas.drawImage(os.path.join(self.filedir, 'images', img), 1, 0,
|
self.canvas.drawImage(os.path.join(self.filedir, 'images', img), 1, 0,
|
||||||
self.tabLabelWidth - 2, self.tabLabelHeight - 1,
|
self.tabLabelWidth -
|
||||||
|
2, self.tabLabelHeight - 1,
|
||||||
preserveAspectRatio=False, anchor='n', mask='auto')
|
preserveAspectRatio=False, anchor='n', mask='auto')
|
||||||
|
|
||||||
# draw cost
|
# draw cost
|
||||||
@ -333,7 +350,7 @@ class DominionTabs:
|
|||||||
setImage = card.setImage()
|
setImage = card.setImage()
|
||||||
if setImage and 'tab' in self.options.set_icon:
|
if setImage and 'tab' in self.options.set_icon:
|
||||||
setImageHeight = 3 + card.getType().getTabTextHeightOffset()
|
setImageHeight = 3 + card.getType().getTabTextHeightOffset()
|
||||||
self.drawSetIcon(setImage, self.tabLabelWidth-20,
|
self.drawSetIcon(setImage, self.tabLabelWidth - 20,
|
||||||
setImageHeight)
|
setImageHeight)
|
||||||
textInsetRight = 20
|
textInsetRight = 20
|
||||||
else:
|
else:
|
||||||
@ -351,7 +368,7 @@ class DominionTabs:
|
|||||||
width = self.nameWidth(name, fontSize)
|
width = self.nameWidth(name, fontSize)
|
||||||
while width > textWidth and fontSize > 8:
|
while width > textWidth and fontSize > 8:
|
||||||
fontSize -= .01
|
fontSize -= .01
|
||||||
#print 'decreasing font size for tab of',name,'now',fontSize
|
# print 'decreasing font size for tab of',name,'now',fontSize
|
||||||
width = self.nameWidth(name, fontSize)
|
width = self.nameWidth(name, fontSize)
|
||||||
tooLong = width > textWidth
|
tooLong = width > textWidth
|
||||||
if tooLong:
|
if tooLong:
|
||||||
@ -362,30 +379,31 @@ class DominionTabs:
|
|||||||
name_lines = name.split(None, 1)
|
name_lines = name.split(None, 1)
|
||||||
else:
|
else:
|
||||||
name_lines = [name]
|
name_lines = [name]
|
||||||
#if tooLong:
|
# if tooLong:
|
||||||
# print name
|
# print name
|
||||||
|
|
||||||
for linenum, line in enumerate(name_lines):
|
for linenum, line in enumerate(name_lines):
|
||||||
h = textHeight
|
h = textHeight
|
||||||
if tooLong and len(name_lines) > 1:
|
if tooLong and len(name_lines) > 1:
|
||||||
if linenum == 0:
|
if linenum == 0:
|
||||||
h += h/2
|
h += h / 2
|
||||||
else:
|
else:
|
||||||
h -= h/2
|
h -= h / 2
|
||||||
|
|
||||||
words = line.split()
|
words = line.split()
|
||||||
if rightSide or not self.options.edge_align_name:
|
if rightSide or not self.options.edge_align_name:
|
||||||
w = textInset
|
w = textInset
|
||||||
|
|
||||||
def drawWordPiece(text, fontSize):
|
def drawWordPiece(text, fontSize):
|
||||||
self.canvas.setFont('MinionPro-Regular',fontSize)
|
self.canvas.setFont('MinionPro-Regular', fontSize)
|
||||||
if text != ' ':
|
if text != ' ':
|
||||||
self.canvas.drawString(w,h,text)
|
self.canvas.drawString(w, h, text)
|
||||||
return pdfmetrics.stringWidth(text,'MinionPro-Regular',fontSize)
|
return pdfmetrics.stringWidth(text, 'MinionPro-Regular', fontSize)
|
||||||
for i, word in enumerate(words):
|
for i, word in enumerate(words):
|
||||||
if i != 0:
|
if i != 0:
|
||||||
w += drawWordPiece(' ', fontSize)
|
w += drawWordPiece(' ', fontSize)
|
||||||
w += drawWordPiece(word[0], fontSize)
|
w += drawWordPiece(word[0], fontSize)
|
||||||
w += drawWordPiece(word[1:], fontSize-2)
|
w += drawWordPiece(word[1:], fontSize - 2)
|
||||||
else:
|
else:
|
||||||
# align text to the right if tab is on right side, to make
|
# align text to the right if tab is on right side, to make
|
||||||
# tabs easier to read when grouped together extra 3pt is for
|
# tabs easier to read when grouped together extra 3pt is for
|
||||||
@ -393,13 +411,14 @@ class DominionTabs:
|
|||||||
|
|
||||||
w = self.tabLabelWidth - textInsetRight - 3
|
w = self.tabLabelWidth - textInsetRight - 3
|
||||||
words.reverse()
|
words.reverse()
|
||||||
|
|
||||||
def drawWordPiece(text, fontSize):
|
def drawWordPiece(text, fontSize):
|
||||||
self.canvas.setFont('MinionPro-Regular',fontSize)
|
self.canvas.setFont('MinionPro-Regular', fontSize)
|
||||||
if text != ' ':
|
if text != ' ':
|
||||||
self.canvas.drawRightString(w,h,text)
|
self.canvas.drawRightString(w, h, text)
|
||||||
return -pdfmetrics.stringWidth(text,'MinionPro-Regular',fontSize)
|
return -pdfmetrics.stringWidth(text, 'MinionPro-Regular', fontSize)
|
||||||
for i, word in enumerate(words):
|
for i, word in enumerate(words):
|
||||||
w += drawWordPiece(word[1:], fontSize-2)
|
w += drawWordPiece(word[1:], fontSize - 2)
|
||||||
w += drawWordPiece(word[0], fontSize)
|
w += drawWordPiece(word[0], fontSize)
|
||||||
if i != len(words) - 1:
|
if i != len(words) - 1:
|
||||||
w += drawWordPiece(' ', fontSize)
|
w += drawWordPiece(' ', fontSize)
|
||||||
@ -411,42 +430,42 @@ class DominionTabs:
|
|||||||
|
|
||||||
drewTopIcon = False
|
drewTopIcon = False
|
||||||
if 'body-top' in self.options.cost and not card.isExpansion():
|
if 'body-top' in self.options.cost and not card.isExpansion():
|
||||||
self.drawCost(card, cm/4.0, totalHeight - 0.5*cm)
|
self.drawCost(card, cm / 4.0, totalHeight - 0.5 * cm)
|
||||||
drewTopIcon = True
|
drewTopIcon = True
|
||||||
|
|
||||||
if 'body-top' in self.options.set_icon and not card.isExpansion():
|
if 'body-top' in self.options.set_icon and not card.isExpansion():
|
||||||
setImage = card.setImage()
|
setImage = card.setImage()
|
||||||
if setImage:
|
if setImage:
|
||||||
self.drawSetIcon(setImage, self.tabWidth-16,
|
self.drawSetIcon(setImage, self.tabWidth - 16,
|
||||||
totalHeight-0.5*cm-3)
|
totalHeight - 0.5 * cm - 3)
|
||||||
drewTopIcon = True
|
drewTopIcon = True
|
||||||
if drewTopIcon:
|
if drewTopIcon:
|
||||||
usedHeight += 15
|
usedHeight += 15
|
||||||
|
|
||||||
#draw text
|
# draw text
|
||||||
if useExtra and card.extra:
|
if useExtra and card.extra:
|
||||||
descriptions = (card.extra,)
|
descriptions = (card.extra,)
|
||||||
else:
|
else:
|
||||||
descriptions = re.split("\n",card.description)
|
descriptions = re.split("\n", card.description)
|
||||||
|
|
||||||
s = getSampleStyleSheet()['BodyText']
|
s = getSampleStyleSheet()['BodyText']
|
||||||
s.fontName = "Times-Roman"
|
s.fontName = "Times-Roman"
|
||||||
s.alignment = TA_JUSTIFY
|
s.alignment = TA_JUSTIFY
|
||||||
|
|
||||||
textHorizontalMargin = .5*cm
|
textHorizontalMargin = .5 * cm
|
||||||
textVerticalMargin = .3*cm
|
textVerticalMargin = .3 * cm
|
||||||
textBoxWidth = self.tabWidth - 2*textHorizontalMargin
|
textBoxWidth = self.tabWidth - 2 * textHorizontalMargin
|
||||||
textBoxHeight = totalHeight - usedHeight - 2*textVerticalMargin
|
textBoxHeight = totalHeight - usedHeight - 2 * textVerticalMargin
|
||||||
spacerHeight = 0.2*cm
|
spacerHeight = 0.2 * cm
|
||||||
minSpacerHeight = 0.05*cm
|
minSpacerHeight = 0.05 * cm
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
paragraphs = []
|
paragraphs = []
|
||||||
# this accounts for the spacers we insert between paragraphs
|
# this accounts for the spacers we insert between paragraphs
|
||||||
h = (len(descriptions) - 1) * spacerHeight
|
h = (len(descriptions) - 1) * spacerHeight
|
||||||
for d in descriptions:
|
for d in descriptions:
|
||||||
dmod = self.add_inline_images(d,s.fontSize)
|
dmod = self.add_inline_images(d, s.fontSize)
|
||||||
p = Paragraph(dmod,s)
|
p = Paragraph(dmod, s)
|
||||||
h += p.wrap(textBoxWidth, textBoxHeight)[1]
|
h += p.wrap(textBoxWidth, textBoxHeight)[1]
|
||||||
paragraphs.append(p)
|
paragraphs.append(p)
|
||||||
|
|
||||||
@ -481,7 +500,8 @@ class DominionTabs:
|
|||||||
|
|
||||||
# actual drawing
|
# actual drawing
|
||||||
if not self.options.tabs_only:
|
if not self.options.tabs_only:
|
||||||
self.drawOutline(x, y, rightSide, useExtra, card.getType().getTypeNames() == ('Expansion',))
|
self.drawOutline(
|
||||||
|
x, y, rightSide, useExtra, card.getType().getTypeNames() == ('Expansion',))
|
||||||
self.drawTab(card, rightSide)
|
self.drawTab(card, rightSide)
|
||||||
if not self.options.tabs_only:
|
if not self.options.tabs_only:
|
||||||
self.drawText(card, useExtra)
|
self.drawText(card, useExtra)
|
||||||
@ -549,7 +569,8 @@ class DominionTabs:
|
|||||||
# To solve:
|
# To solve:
|
||||||
|
|
||||||
# 1)
|
# 1)
|
||||||
# try to figure out if this a 'basic action' like +X Cards or +Y Actions
|
# try to figure out if this a 'basic action' like +X Cards or +Y
|
||||||
|
# Actions
|
||||||
descriptions = [card.description]
|
descriptions = [card.description]
|
||||||
while True:
|
while True:
|
||||||
m = self.baseactionRE.match(line, re.UNICODE)
|
m = self.baseactionRE.match(line, re.UNICODE)
|
||||||
@ -585,11 +606,13 @@ class DominionTabs:
|
|||||||
potcost = 0
|
potcost = 0
|
||||||
currentCard = Card(m.groupdict()["name"].strip(),
|
currentCard = Card(m.groupdict()["name"].strip(),
|
||||||
m.groupdict()["set"].lower().strip(),
|
m.groupdict()["set"].lower().strip(),
|
||||||
tuple([t.strip() for t in m.groupdict()["type"].split("-")]),
|
tuple(
|
||||||
|
[t.strip() for t in m.groupdict()["type"].split("-")]),
|
||||||
m.groupdict()["cost"],
|
m.groupdict()["cost"],
|
||||||
'',
|
'',
|
||||||
potcost)
|
potcost)
|
||||||
self.add_definition_line(currentCard, m.groupdict()["description"])
|
self.add_definition_line(
|
||||||
|
currentCard, m.groupdict()["description"])
|
||||||
cards.append(currentCard)
|
cards.append(currentCard)
|
||||||
elif line:
|
elif line:
|
||||||
assert currentCard
|
assert currentCard
|
||||||
@ -620,7 +643,8 @@ class DominionTabs:
|
|||||||
'width': self.paperheight}]
|
'width': self.paperheight}]
|
||||||
|
|
||||||
for layout in layouts:
|
for layout in layouts:
|
||||||
availableMargin = layout['totalMarginHeight'] - layout['minMarginHeight']
|
availableMargin = layout[
|
||||||
|
'totalMarginHeight'] - layout['minMarginHeight']
|
||||||
fontsize = availableMargin / fontHeightRelative
|
fontsize = availableMargin / fontHeightRelative
|
||||||
fontsize = min(maxFontsize, fontsize)
|
fontsize = min(maxFontsize, fontsize)
|
||||||
if fontsize >= minFontsize:
|
if fontsize >= minFontsize:
|
||||||
@ -632,7 +656,7 @@ class DominionTabs:
|
|||||||
warnings.warn("Not enough space to display set names")
|
warnings.warn("Not enough space to display set names")
|
||||||
return
|
return
|
||||||
|
|
||||||
self.canvas.setFont(fontname,fontsize)
|
self.canvas.setFont(fontname, fontsize)
|
||||||
|
|
||||||
sets = []
|
sets = []
|
||||||
for c in pageCards:
|
for c in pageCards:
|
||||||
@ -647,43 +671,45 @@ class DominionTabs:
|
|||||||
self.canvas.rotate(layout['rotation'])
|
self.canvas.rotate(layout['rotation'])
|
||||||
yPos = -yPos
|
yPos = -yPos
|
||||||
|
|
||||||
self.canvas.drawCentredString(xPos,yPos,'/'.join(sets))
|
self.canvas.drawCentredString(xPos, yPos, '/'.join(sets))
|
||||||
finally:
|
finally:
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
|
|
||||||
def drawDividers(self,cards):
|
def drawDividers(self, cards):
|
||||||
#split into pages
|
# split into pages
|
||||||
cards = split(cards,self.numTabsVertical*self.numTabsHorizontal)
|
cards = split(cards, self.numTabsVertical * self.numTabsHorizontal)
|
||||||
self.odd = True
|
self.odd = True
|
||||||
for pageNum,pageCards in enumerate(cards):
|
for pageNum, pageCards in enumerate(cards):
|
||||||
#remember whether we start with odd or even divider for tab location
|
# remember whether we start with odd or even divider for tab
|
||||||
|
# location
|
||||||
pageStartOdd = self.odd
|
pageStartOdd = self.odd
|
||||||
if not self.options.tabs_only and self.options.order != "global":
|
if not self.options.tabs_only and self.options.order != "global":
|
||||||
self.drawSetNames(pageCards)
|
self.drawSetNames(pageCards)
|
||||||
for i,card in enumerate(pageCards):
|
for i, card in enumerate(pageCards):
|
||||||
#print card
|
# print card
|
||||||
x = i % self.numTabsHorizontal
|
x = i % self.numTabsHorizontal
|
||||||
y = i / self.numTabsHorizontal
|
y = i / self.numTabsHorizontal
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
self.drawDivider(card,x,self.numTabsVertical-1-y)
|
self.drawDivider(card, x, self.numTabsVertical - 1 - y)
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
self.odd = not self.odd
|
self.odd = not self.odd
|
||||||
self.canvas.showPage()
|
self.canvas.showPage()
|
||||||
if pageNum + 1 == self.options.num_pages:
|
if pageNum + 1 == self.options.num_pages:
|
||||||
break
|
break
|
||||||
if self.options.tabs_only:
|
if self.options.tabs_only:
|
||||||
#no set names or card backs for label-only sheets
|
# no set names or card backs for label-only sheets
|
||||||
continue
|
continue
|
||||||
if self.options.order != "global":
|
if self.options.order != "global":
|
||||||
self.drawSetNames(pageCards)
|
self.drawSetNames(pageCards)
|
||||||
#start at same oddness
|
# start at same oddness
|
||||||
self.odd = pageStartOdd
|
self.odd = pageStartOdd
|
||||||
for i,card in enumerate(pageCards):
|
for i, card in enumerate(pageCards):
|
||||||
#print card
|
# print card
|
||||||
x = (self.numTabsHorizontal-1-i) % self.numTabsHorizontal
|
x = (self.numTabsHorizontal - 1 - i) % self.numTabsHorizontal
|
||||||
y = i / self.numTabsHorizontal
|
y = i / self.numTabsHorizontal
|
||||||
self.canvas.saveState()
|
self.canvas.saveState()
|
||||||
self.drawDivider(card,x,self.numTabsVertical-1-y,useExtra=True)
|
self.drawDivider(
|
||||||
|
card, x, self.numTabsVertical - 1 - y, useExtra=True)
|
||||||
self.canvas.restoreState()
|
self.canvas.restoreState()
|
||||||
self.odd = not self.odd
|
self.odd = not self.odd
|
||||||
self.canvas.showPage()
|
self.canvas.showPage()
|
||||||
@ -700,7 +726,8 @@ class DominionTabs:
|
|||||||
parser.add_option("--orientation", type="choice", choices=["horizontal", "vertical"],
|
parser.add_option("--orientation", type="choice", choices=["horizontal", "vertical"],
|
||||||
dest="orientation", default="horizontal",
|
dest="orientation", default="horizontal",
|
||||||
help="horizontal or vertical, default:horizontal")
|
help="horizontal or vertical, default:horizontal")
|
||||||
parser.add_option("--sleeved", action="store_true", dest="sleeved", help="use --size=sleeved instead")
|
parser.add_option("--sleeved", action="store_true",
|
||||||
|
dest="sleeved", help="use --size=sleeved instead")
|
||||||
parser.add_option("--size", type="string", dest="size", default='normal',
|
parser.add_option("--size", type="string", dest="size", default='normal',
|
||||||
help="'<%f>x<%f>' (size in cm), or 'normal' = '9.1x5.9', or 'sleeved' = '9.4x6.15'")
|
help="'<%f>x<%f>' (size in cm), or 'normal' = '9.1x5.9', or 'sleeved' = '9.4x6.15'")
|
||||||
parser.add_option("--minmargin", type="string", dest="minmargin", default="1x1",
|
parser.add_option("--minmargin", type="string", dest="minmargin", default="1x1",
|
||||||
@ -756,9 +783,12 @@ class DominionTabs:
|
|||||||
help='centre the tabs on expansion dividers')
|
help='centre the tabs on expansion dividers')
|
||||||
parser.add_option("--num_pages", type="int", default=-1,
|
parser.add_option("--num_pages", type="int", default=-1,
|
||||||
help="stop generating after this many pages, -1 for all")
|
help="stop generating after this many pages, -1 for all")
|
||||||
parser.add_option("--language", default='en_us', help="language of card texts")
|
parser.add_option(
|
||||||
parser.add_option("--include_blanks", action="store_true", help="include a few dividers with extra text")
|
"--language", default='en_us', help="language of card texts")
|
||||||
parser.add_option("--exclude_events", action="store_true", default=False, help="exclude individual dividers for events")
|
parser.add_option("--include_blanks", action="store_true",
|
||||||
|
help="include a few dividers with extra text")
|
||||||
|
parser.add_option("--exclude_events", action="store_true",
|
||||||
|
default=False, help="exclude individual dividers for events")
|
||||||
|
|
||||||
options, args = parser.parse_args(argstring)
|
options, args = parser.parse_args(argstring)
|
||||||
if not options.cost:
|
if not options.cost:
|
||||||
@ -767,16 +797,16 @@ class DominionTabs:
|
|||||||
options.set_icon = ['tab']
|
options.set_icon = ['tab']
|
||||||
return options, args
|
return options, args
|
||||||
|
|
||||||
def main(self,argstring):
|
def main(self, argstring):
|
||||||
options,args = DominionTabs.parse_opts(argstring)
|
options, args = DominionTabs.parse_opts(argstring)
|
||||||
fname = None
|
fname = None
|
||||||
if args:
|
if args:
|
||||||
fname = args[0]
|
fname = args[0]
|
||||||
return self.generate(options,fname)
|
return self.generate(options, fname)
|
||||||
|
|
||||||
def parseDimensions(self, dimensionsStr):
|
def parseDimensions(self, dimensionsStr):
|
||||||
x, y = dimensionsStr.upper().split('X', 1)
|
x, y = dimensionsStr.upper().split('X', 1)
|
||||||
return (float (x) * cm, float (y) * cm)
|
return (float(x) * cm, float(y) * cm)
|
||||||
|
|
||||||
def generate_sample(self, options):
|
def generate_sample(self, options):
|
||||||
import cStringIO
|
import cStringIO
|
||||||
@ -788,23 +818,23 @@ class DominionTabs:
|
|||||||
sample.format = 'png'
|
sample.format = 'png'
|
||||||
sample.save(filename='sample.png')
|
sample.save(filename='sample.png')
|
||||||
|
|
||||||
def generate(self,options,f):
|
def generate(self, options, f):
|
||||||
self.options = options
|
self.options = options
|
||||||
size = self.options.size.upper()
|
size = self.options.size.upper()
|
||||||
if size == 'SLEEVED' or self.options.sleeved:
|
if size == 'SLEEVED' or self.options.sleeved:
|
||||||
dominionCardWidth, dominionCardHeight = (9.4*cm, 6.15*cm)
|
dominionCardWidth, dominionCardHeight = (9.4 * cm, 6.15 * cm)
|
||||||
print 'Using sleeved card size, %.2fcm x %.2fcm' % (dominionCardWidth/cm,dominionCardHeight/cm)
|
print 'Using sleeved card size, %.2fcm x %.2fcm' % (dominionCardWidth / cm, dominionCardHeight / cm)
|
||||||
elif size in ['NORMAL','UNSLEEVED']:
|
elif size in ['NORMAL', 'UNSLEEVED']:
|
||||||
dominionCardWidth, dominionCardHeight = (9.1*cm, 5.9*cm)
|
dominionCardWidth, dominionCardHeight = (9.1 * cm, 5.9 * cm)
|
||||||
print 'Using normal card size, %.2fcm x%.2fcm' % (dominionCardWidth/cm,dominionCardHeight/cm)
|
print 'Using normal card size, %.2fcm x%.2fcm' % (dominionCardWidth / cm, dominionCardHeight / cm)
|
||||||
else:
|
else:
|
||||||
dominionCardWidth, dominionCardHeight = self.parseDimensions(size)
|
dominionCardWidth, dominionCardHeight = self.parseDimensions(size)
|
||||||
print 'Using custom card size, %.2fcm x %.2fcm' % (dominionCardWidth/cm,dominionCardHeight/cm)
|
print 'Using custom card size, %.2fcm x %.2fcm' % (dominionCardWidth / cm, dominionCardHeight / cm)
|
||||||
|
|
||||||
papersize = None
|
papersize = None
|
||||||
if not self.options.papersize:
|
if not self.options.papersize:
|
||||||
if os.path.exists("/etc/papersize"):
|
if os.path.exists("/etc/papersize"):
|
||||||
papersize = open ("/etc/papersize").readline().upper()
|
papersize = open("/etc/papersize").readline().upper()
|
||||||
else:
|
else:
|
||||||
papersize = 'LETTER'
|
papersize = 'LETTER'
|
||||||
else:
|
else:
|
||||||
@ -818,7 +848,7 @@ class DominionTabs:
|
|||||||
self.paperwidth, self.paperheight = LETTER
|
self.paperwidth, self.paperheight = LETTER
|
||||||
else:
|
else:
|
||||||
self.paperwidth, self.paperheight = self.parseDimensions(papersize)
|
self.paperwidth, self.paperheight = self.parseDimensions(papersize)
|
||||||
print 'Using custom paper size, %.2fcm x %.2fcm' % (self.paperwidth/cm,self.paperheight/cm)
|
print 'Using custom paper size, %.2fcm x %.2fcm' % (self.paperwidth / cm, self.paperheight / cm)
|
||||||
|
|
||||||
if self.options.orientation == "vertical":
|
if self.options.orientation == "vertical":
|
||||||
self.tabWidth, self.tabBaseHeight = dominionCardHeight, dominionCardWidth
|
self.tabWidth, self.tabBaseHeight = dominionCardHeight, dominionCardWidth
|
||||||
@ -827,38 +857,44 @@ class DominionTabs:
|
|||||||
|
|
||||||
fixedMargins = False
|
fixedMargins = False
|
||||||
if self.options.tabs_only:
|
if self.options.tabs_only:
|
||||||
#fixed for Avery 8867 for now
|
# fixed for Avery 8867 for now
|
||||||
minmarginwidth=0.76*cm
|
minmarginwidth = 0.76 * cm
|
||||||
minmarginheight=1.27*cm
|
minmarginheight = 1.27 * cm
|
||||||
self.tabLabelHeight = 1.27*cm
|
self.tabLabelHeight = 1.27 * cm
|
||||||
self.tabLabelWidth = 4.44*cm
|
self.tabLabelWidth = 4.44 * cm
|
||||||
self.tabBaseHeight = 0
|
self.tabBaseHeight = 0
|
||||||
self.tabWidth = self.tabLabelWidth
|
self.tabWidth = self.tabLabelWidth
|
||||||
self.horizontalBorderSpace = 0.76*cm
|
self.horizontalBorderSpace = 0.76 * cm
|
||||||
self.verticalBorderSpace = 0.01*cm
|
self.verticalBorderSpace = 0.01 * cm
|
||||||
fixedMargins = True
|
fixedMargins = True
|
||||||
else:
|
else:
|
||||||
minmarginwidth, minmarginheight = self.parseDimensions(self.options.minmargin)
|
minmarginwidth, minmarginheight = self.parseDimensions(
|
||||||
|
self.options.minmargin)
|
||||||
self.tabLabelWidth = self.options.tabwidth * cm
|
self.tabLabelWidth = self.options.tabwidth * cm
|
||||||
self.tabLabelHeight = .9*cm
|
self.tabLabelHeight = .9 * cm
|
||||||
self.horizontalBorderSpace = 0*cm
|
self.horizontalBorderSpace = 0 * cm
|
||||||
self.verticalBorderSpace = 0*cm
|
self.verticalBorderSpace = 0 * cm
|
||||||
|
|
||||||
self.tabHeight = self.tabBaseHeight + self.tabLabelHeight
|
self.tabHeight = self.tabBaseHeight + self.tabLabelHeight
|
||||||
|
|
||||||
#note: this is convenient, but somewhat inaccurate as the border space isn't actually part of the tab width
|
# note: this is convenient, but somewhat inaccurate as the border space
|
||||||
|
# isn't actually part of the tab width
|
||||||
self.totalTabWidth = self.tabWidth + self.horizontalBorderSpace
|
self.totalTabWidth = self.tabWidth + self.horizontalBorderSpace
|
||||||
self.totalTabHeight = self.tabHeight + self.verticalBorderSpace
|
self.totalTabHeight = self.tabHeight + self.verticalBorderSpace
|
||||||
|
|
||||||
print "Paper dimensions: %fcm (w) x %fcm (h)" % (self.paperwidth / cm, self.paperheight / cm)
|
print "Paper dimensions: %fcm (w) x %fcm (h)" % (self.paperwidth / cm, self.paperheight / cm)
|
||||||
print "Tab dimensions: %fcm (w) x %fcm (h)" % (self.totalTabWidth / cm, self.totalTabHeight / cm)
|
print "Tab dimensions: %fcm (w) x %fcm (h)" % (self.totalTabWidth / cm, self.totalTabHeight / cm)
|
||||||
|
|
||||||
#as we don't draw anything in the final border, it shouldn't count towards how many tabs we can fit
|
# as we don't draw anything in the final border, it shouldn't count towards how many tabs we can fit
|
||||||
#so it gets added back in to the page size here
|
# so it gets added back in to the page size here
|
||||||
numTabsVerticalP = int ((self.paperheight - 2*minmarginheight + self.verticalBorderSpace) / self.totalTabHeight)
|
numTabsVerticalP = int(
|
||||||
numTabsHorizontalP = int ((self.paperwidth - 2*minmarginwidth + self.horizontalBorderSpace) / self.totalTabWidth)
|
(self.paperheight - 2 * minmarginheight + self.verticalBorderSpace) / self.totalTabHeight)
|
||||||
numTabsVerticalL = int ((self.paperwidth - 2*minmarginwidth + self.verticalBorderSpace) / self.totalTabHeight)
|
numTabsHorizontalP = int(
|
||||||
numTabsHorizontalL = int ((self.paperheight - 2*minmarginheight + self.horizontalBorderSpace) / self.totalTabWidth)
|
(self.paperwidth - 2 * minmarginwidth + self.horizontalBorderSpace) / self.totalTabWidth)
|
||||||
|
numTabsVerticalL = int(
|
||||||
|
(self.paperwidth - 2 * minmarginwidth + self.verticalBorderSpace) / self.totalTabHeight)
|
||||||
|
numTabsHorizontalL = int(
|
||||||
|
(self.paperheight - 2 * minmarginheight + self.horizontalBorderSpace) / self.totalTabWidth)
|
||||||
|
|
||||||
if numTabsVerticalL * numTabsHorizontalL > numTabsVerticalP * numTabsHorizontalP and not fixedMargins:
|
if numTabsVerticalL * numTabsHorizontalL > numTabsVerticalP * numTabsHorizontalP and not fixedMargins:
|
||||||
self.numTabsVertical, self.numTabsHorizontal\
|
self.numTabsVertical, self.numTabsHorizontal\
|
||||||
@ -873,9 +909,11 @@ class DominionTabs:
|
|||||||
self.minVerticalMargin = minmarginheight
|
self.minVerticalMargin = minmarginheight
|
||||||
|
|
||||||
if not fixedMargins:
|
if not fixedMargins:
|
||||||
#dynamically max margins
|
# dynamically max margins
|
||||||
self.horizontalMargin = (self.paperwidth-self.numTabsHorizontal*self.totalTabWidth)/2
|
self.horizontalMargin = (
|
||||||
self.verticalMargin = (self.paperheight-self.numTabsVertical*self.totalTabHeight)/2
|
self.paperwidth - self.numTabsHorizontal * self.totalTabWidth) / 2
|
||||||
|
self.verticalMargin = (
|
||||||
|
self.paperheight - self.numTabsVertical * self.totalTabHeight) / 2
|
||||||
else:
|
else:
|
||||||
self.horizontalMargin = minmarginwidth
|
self.horizontalMargin = minmarginwidth
|
||||||
self.verticalMargin = minmarginheight
|
self.verticalMargin = minmarginheight
|
||||||
@ -883,48 +921,58 @@ class DominionTabs:
|
|||||||
print "Margins: %fcm h, %fcm v\n" % (self.horizontalMargin / cm,
|
print "Margins: %fcm h, %fcm v\n" % (self.horizontalMargin / cm,
|
||||||
self.verticalMargin / cm)
|
self.verticalMargin / cm)
|
||||||
|
|
||||||
self.tabOutline = [(0,0,self.tabWidth,0),
|
self.tabOutline = [(0, 0, self.tabWidth, 0),
|
||||||
(self.tabWidth,0,self.tabWidth,self.tabHeight),
|
(self.tabWidth, 0, self.tabWidth, self.tabHeight),
|
||||||
(self.tabWidth,self.tabHeight,
|
(self.tabWidth, self.tabHeight,
|
||||||
self.tabWidth-self.tabLabelWidth,self.tabHeight),
|
self.tabWidth - self.tabLabelWidth, self.tabHeight),
|
||||||
(self.tabWidth-self.tabLabelWidth,
|
(self.tabWidth - self.tabLabelWidth,
|
||||||
self.tabHeight,self.tabWidth-self.tabLabelWidth,
|
self.tabHeight, self.tabWidth - self.tabLabelWidth,
|
||||||
self.tabBaseHeight),
|
self.tabBaseHeight),
|
||||||
(self.tabWidth-self.tabLabelWidth,
|
(self.tabWidth - self.tabLabelWidth,
|
||||||
self.tabBaseHeight,0,self.tabBaseHeight),
|
self.tabBaseHeight, 0, self.tabBaseHeight),
|
||||||
(0,self.tabBaseHeight,0,0)]
|
(0, self.tabBaseHeight, 0, 0)]
|
||||||
|
|
||||||
self.expansionTabOutline = [(0,0,self.tabWidth,0),
|
self.expansionTabOutline = [(0, 0, self.tabWidth, 0),
|
||||||
(self.tabWidth,0,self.tabWidth,self.tabBaseHeight),
|
(self.tabWidth, 0, self.tabWidth,
|
||||||
(self.tabWidth,self.tabBaseHeight,
|
self.tabBaseHeight),
|
||||||
self.tabWidth/2+self.tabLabelWidth/2,self.tabBaseHeight),
|
(self.tabWidth, self.tabBaseHeight,
|
||||||
(self.tabWidth/2+self.tabLabelWidth/2,self.tabBaseHeight,
|
self.tabWidth / 2 + self.tabLabelWidth / 2, self.tabBaseHeight),
|
||||||
self.tabWidth/2+self.tabLabelWidth/2,self.tabHeight),
|
(self.tabWidth / 2 + self.tabLabelWidth / 2, self.tabBaseHeight,
|
||||||
(self.tabWidth/2+self.tabLabelWidth/2,self.tabHeight,
|
self.tabWidth / 2 + self.tabLabelWidth / 2, self.tabHeight),
|
||||||
self.tabWidth/2-self.tabLabelWidth/2,self.tabHeight),
|
(self.tabWidth / 2 + self.tabLabelWidth / 2, self.tabHeight,
|
||||||
(self.tabWidth/2-self.tabLabelWidth/2,self.tabHeight,
|
self.tabWidth / 2 - self.tabLabelWidth / 2, self.tabHeight),
|
||||||
self.tabWidth/2-self.tabLabelWidth/2,self.tabBaseHeight),
|
(self.tabWidth / 2 - self.tabLabelWidth / 2, self.tabHeight,
|
||||||
(self.tabWidth/2-self.tabLabelWidth/2,self.tabBaseHeight,
|
self.tabWidth / 2 - self.tabLabelWidth / 2, self.tabBaseHeight),
|
||||||
0,self.tabBaseHeight),
|
(self.tabWidth / 2 - self.tabLabelWidth / 2, self.tabBaseHeight,
|
||||||
(0,self.tabBaseHeight,0,0)]
|
0, self.tabBaseHeight),
|
||||||
|
(0, self.tabBaseHeight, 0, 0)]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dirn = os.path.join(self.filedir,'fonts')
|
dirn = os.path.join(self.filedir, 'fonts')
|
||||||
pdfmetrics.registerFont(TTFont('MinionPro-Regular',os.path.join(dirn,'MinionPro-Regular.ttf')))
|
pdfmetrics.registerFont(
|
||||||
pdfmetrics.registerFont(TTFont('MinionPro-Bold',os.path.join(dirn,'MinionPro-Bold.ttf')))
|
TTFont('MinionPro-Regular', os.path.join(dirn, 'MinionPro-Regular.ttf')))
|
||||||
|
pdfmetrics.registerFont(
|
||||||
|
TTFont('MinionPro-Bold', os.path.join(dirn, 'MinionPro-Bold.ttf')))
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
pdfmetrics.registerFont(TTFont('MinionPro-Regular','OptimusPrincepsSemiBold.ttf'))
|
pdfmetrics.registerFont(
|
||||||
pdfmetrics.registerFont(TTFont('MinionPro-Bold','OptimusPrinceps.ttf'))
|
TTFont('MinionPro-Regular', 'OptimusPrincepsSemiBold.ttf'))
|
||||||
|
pdfmetrics.registerFont(
|
||||||
|
TTFont('MinionPro-Bold', 'OptimusPrinceps.ttf'))
|
||||||
if options.read_yaml:
|
if options.read_yaml:
|
||||||
cardfile = open(os.path.join(self.filedir, "card_db", options.language, "cards.yaml"), "r")
|
cardfile = open(
|
||||||
|
os.path.join(self.filedir, "card_db", options.language, "cards.yaml"), "r")
|
||||||
cards = yaml.load(cardfile)
|
cards = yaml.load(cardfile)
|
||||||
else:
|
else:
|
||||||
cards = self.read_card_defs(os.path.join(self.filedir, "card_db", options.language, "dominion_cards.txt"))
|
cards = self.read_card_defs(
|
||||||
self.read_card_extras(os.path.join(self.filedir, "card_db", options.language, "dominion_card_extras.txt"), cards)
|
os.path.join(self.filedir, "card_db", options.language, "dominion_cards.txt"))
|
||||||
DominionTabs.language_mapping = yaml.load(open(os.path.join(self.filedir, "card_db", options.language, "mapping.yaml")))
|
self.read_card_extras(os.path.join(
|
||||||
|
self.filedir, "card_db", options.language, "dominion_card_extras.txt"), cards)
|
||||||
|
DominionTabs.language_mapping = yaml.load(
|
||||||
|
open(os.path.join(self.filedir, "card_db", options.language, "mapping.yaml")))
|
||||||
|
|
||||||
baseCards = [card.name for card in cards if card.cardset.lower() == 'base']
|
baseCards = [
|
||||||
|
card.name for card in cards if card.cardset.lower() == 'base']
|
||||||
|
|
||||||
def isBaseExpansionCard(card):
|
def isBaseExpansionCard(card):
|
||||||
return card.cardset.lower() != 'base' and card.name in baseCards
|
return card.cardset.lower() != 'base' and card.name in baseCards
|
||||||
@ -935,9 +983,12 @@ class DominionTabs:
|
|||||||
cards = [card for card in cards if not isBaseExpansionCard(card)]
|
cards = [card for card in cards if not isBaseExpansionCard(card)]
|
||||||
|
|
||||||
if self.options.expansions:
|
if self.options.expansions:
|
||||||
self.options.expansions = [o.lower() for o in self.options.expansions]
|
self.options.expansions = [o.lower()
|
||||||
reverseMapping = {v: k for k, v in DominionTabs.language_mapping.iteritems()}
|
for o in self.options.expansions]
|
||||||
self.options.expansions = [reverseMapping.get(e, e) for e in self.options.expansions]
|
reverseMapping = {
|
||||||
|
v: k for k, v in DominionTabs.language_mapping.iteritems()}
|
||||||
|
self.options.expansions = [
|
||||||
|
reverseMapping.get(e, e) for e in self.options.expansions]
|
||||||
filteredCards = []
|
filteredCards = []
|
||||||
knownExpansions = set()
|
knownExpansions = set()
|
||||||
for c in cards:
|
for c in cards:
|
||||||
@ -959,14 +1010,17 @@ class DominionTabs:
|
|||||||
for c in cards:
|
for c in cards:
|
||||||
if isBaseExpansionCard(c):
|
if isBaseExpansionCard(c):
|
||||||
continue
|
continue
|
||||||
cardnamesByExpansion.setdefault(c.cardset, []).append(c.name.strip())
|
cardnamesByExpansion.setdefault(
|
||||||
|
c.cardset, []).append(c.name.strip())
|
||||||
for exp, names in cardnamesByExpansion.iteritems():
|
for exp, names in cardnamesByExpansion.iteritems():
|
||||||
c = Card(exp, exp, ("Expansion",), None, ' | '.join(sorted(names)))
|
c = Card(
|
||||||
|
exp, exp, ("Expansion",), None, ' | '.join(sorted(names)))
|
||||||
cards.append(c)
|
cards.append(c)
|
||||||
|
|
||||||
if options.write_yaml:
|
if options.write_yaml:
|
||||||
out = yaml.dump(cards)
|
out = yaml.dump(cards)
|
||||||
open(os.path.join(self.filedir, "card_db", options.language, "cards.yaml"), 'w').write(out)
|
open(os.path.join(
|
||||||
|
self.filedir, "card_db", options.language, "cards.yaml"), 'w').write(out)
|
||||||
|
|
||||||
# When sorting cards, want to always put "base" cards after all
|
# When sorting cards, want to always put "base" cards after all
|
||||||
# kingdom cards, and order the base cards in a set order - the
|
# kingdom cards, and order the base cards in a set order - the
|
||||||
@ -980,18 +1034,21 @@ class DominionTabs:
|
|||||||
return -1
|
return -1
|
||||||
|
|
||||||
if options.order == "global":
|
if options.order == "global":
|
||||||
sortKey = lambda x: (int(x.isExpansion()), baseIndex(x.name), x.name)
|
sortKey = lambda x: (
|
||||||
|
int(x.isExpansion()), baseIndex(x.name), x.name)
|
||||||
else:
|
else:
|
||||||
sortKey = lambda x: (x.cardset, int(x.isExpansion()), baseIndex(x.name), x.name)
|
sortKey = lambda x: (
|
||||||
|
x.cardset, int(x.isExpansion()), baseIndex(x.name), x.name)
|
||||||
cards.sort(key=sortKey)
|
cards.sort(key=sortKey)
|
||||||
|
|
||||||
if not f:
|
if not f:
|
||||||
f = "dominion_tabs.pdf"
|
f = "dominion_tabs.pdf"
|
||||||
self.canvas = canvas.Canvas(f, pagesize=(self.paperwidth, self.paperheight))
|
self.canvas = canvas.Canvas(
|
||||||
|
f, pagesize=(self.paperwidth, self.paperheight))
|
||||||
self.drawDividers(cards)
|
self.drawDividers(cards)
|
||||||
self.canvas.save()
|
self.canvas.save()
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
tabs = DominionTabs()
|
tabs = DominionTabs()
|
||||||
tabs.main(sys.argv[1:])
|
tabs.main(sys.argv[1:])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user