本文整理汇总了Python中metrics.size函数的典型用法代码示例。如果您正苦于以下问题:Python size函数的具体用法?Python size怎么用?Python size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了size函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadPrefs
def loadPrefs (self):
"""Loads user preferences into self.config, setting up defaults if none are set."""
self.config = wx.Config('Twine')
monoFont = wx.SystemSettings.GetFont(wx.SYS_ANSI_FIXED_FONT)
if not self.config.HasEntry('savePath'):
self.config.Write('savePath', os.path.expanduser('~'))
if not self.config.HasEntry('fsTextColor'):
self.config.Write('fsTextColor', '#afcdff')
if not self.config.HasEntry('fsBgColor'):
self.config.Write('fsBgColor', '#100088')
if not self.config.HasEntry('fsFontFace'):
self.config.Write('fsFontFace', metrics.face('mono'))
if not self.config.HasEntry('fsFontSize'):
self.config.WriteInt('fsFontSize', metrics.size('fsEditorBody'))
if not self.config.HasEntry('fsLineHeight'):
self.config.WriteInt('fsLineHeight', 120)
if not self.config.HasEntry('windowedFontFace'):
self.config.Write('windowedFontFace', metrics.face('mono'))
if not self.config.HasEntry('windowedFontSize'):
self.config.WriteInt('windowedFontSize', metrics.size('editorBody'))
if not self.config.HasEntry('storyFrameToolbar'):
self.config.WriteBool('storyFrameToolbar', True)
if not self.config.HasEntry('storyPanelSnap'):
self.config.WriteBool('storyPanelSnap', False)
示例2: loadPrefs
def loadPrefs(self):
"""Loads user preferences into self.config, setting up defaults if none are set."""
sc = self.config = wx.Config('Twine')
monoFont = wx.SystemSettings.GetFont(wx.SYS_ANSI_FIXED_FONT)
for k,v in {
'savePath' : os.path.expanduser('~'),
'fsTextColor' : '#afcdff',
'fsBgColor' : '#100088',
'fsFontFace' : metrics.face('mono'),
'fsFontSize' : metrics.size('fsEditorBody'),
'fsLineHeight' : 120,
'windowedFontFace' : metrics.face('mono'),
'monospaceFontFace' : metrics.face('mono2'),
'windowedFontSize' : metrics.size('editorBody'),
'monospaceFontSize' : metrics.size('editorBody'),
'flatDesign' : False,
'storyFrameToolbar' : True,
'storyPanelSnap' : False,
'fastStoryPanel' : False,
'imageArrows' : True,
'displayArrows' : True,
'createPassagePrompt' : True,
'importImagePrompt' : True,
'passageWarnings' : True
}.iteritems():
if not sc.HasEntry(k):
if type(v) == str:
sc.Write(k,v)
elif type(v) == int:
sc.WriteInt(k,v)
elif type(v) == bool:
sc.WriteBool(k,v)
示例3: __init__
def __init__ (self, app, parent = None):
self.app = app
wx.Frame.__init__(self, parent, wx.ID_ANY, title = self.app.NAME + ' Preferences', \
style = wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.CAPTION | wx.SYSTEM_MENU)
panel = wx.Panel(parent = self, id = wx.ID_ANY)
borderSizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(borderSizer)
panelSizer = wx.FlexGridSizer(5, 2, metrics.size('relatedControls'), metrics.size('relatedControls'))
borderSizer.Add(panelSizer, flag = wx.ALL, border = metrics.size('windowBorder'))
self.editorFont = wx.FontPickerCtrl(panel, style = wx.FNTP_FONTDESC_AS_LABEL)
self.editorFont.SetSelectedFont(self.getPrefFont('windowed'))
self.editorFont.Bind(wx.EVT_FONTPICKER_CHANGED, lambda e: self.saveFontPref('windowed', \
self.editorFont.GetSelectedFont()))
self.fsFont = wx.FontPickerCtrl(panel, style = wx.FNTP_FONTDESC_AS_LABEL)
self.fsFont.SetSelectedFont(self.getPrefFont('fs'))
self.fsFont.Bind(wx.EVT_FONTPICKER_CHANGED, lambda e: self.saveFontPref('fs', \
self.fsFont.GetSelectedFont()))
self.fsTextColor = wx.ColourPickerCtrl(panel)
self.fsTextColor.SetColour(self.app.config.Read('fsTextColor'))
self.fsTextColor.Bind(wx.EVT_COLOURPICKER_CHANGED, lambda e: self.savePref('fsTextColor', \
self.fsTextColor.GetColour()))
self.fsBgColor = wx.ColourPickerCtrl(panel)
self.fsBgColor.SetColour(self.app.config.Read('fsBgColor'))
self.fsBgColor.Bind(wx.EVT_COLOURPICKER_CHANGED, lambda e: self.savePref('fsBgColor', \
self.fsBgColor.GetColour()))
fsLineHeightPanel = wx.Panel(panel)
fsLineHeightSizer = wx.BoxSizer(wx.HORIZONTAL)
fsLineHeightPanel.SetSizer(fsLineHeightSizer)
self.fsLineHeight = wx.ComboBox(fsLineHeightPanel, choices = ('100', '125', '150', '175', '200'))
self.fsLineHeight.Bind(wx.EVT_TEXT, lambda e: self.savePref('fsLineHeight', int(self.fsLineHeight.GetValue())))
self.fsLineHeight.SetValue(str(self.app.config.ReadInt('fslineHeight')))
fsLineHeightSizer.Add(self.fsLineHeight, flag = wx.ALIGN_CENTER_VERTICAL)
fsLineHeightSizer.Add(wx.StaticText(fsLineHeightPanel, label = '%'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(wx.StaticText(panel, label = 'Windowed Editor Font'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.editorFont)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Font'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsFont)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Text Color'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsTextColor)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Background Color'), \
flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsBgColor)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Line Spacing'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(fsLineHeightPanel, flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Fit(self)
borderSizer.Fit(self)
self.SetIcon(self.app.icon)
self.Show()
示例4: __init__
def __init__(self, parent, storyPanel, app, id = wx.ID_ANY):
wx.Dialog.__init__(self, parent, id, title = 'Story Statistics')
self.storyPanel = storyPanel
# layout
panel = wx.Panel(parent = self)
self.panelSizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(self.panelSizer)
# count controls
countPanel = wx.Panel(parent = panel)
countPanelSizer = wx.FlexGridSizer(6, 2, metrics.size('relatedControls'), metrics.size('relatedControls'))
countPanel.SetSizer(countPanelSizer)
self.characters = wx.StaticText(countPanel)
countPanelSizer.Add(self.characters, flag = wx.ALIGN_RIGHT)
countPanelSizer.Add(wx.StaticText(countPanel, label = 'Characters'))
self.words = wx.StaticText(countPanel)
countPanelSizer.Add(self.words, flag = wx.ALIGN_RIGHT)
countPanelSizer.Add(wx.StaticText(countPanel, label = 'Words'))
self.passages = wx.StaticText(countPanel)
countPanelSizer.Add(self.passages, flag = wx.ALIGN_RIGHT)
countPanelSizer.Add(wx.StaticText(countPanel, label = 'Passages'))
self.links = wx.StaticText(countPanel)
countPanelSizer.Add(self.links, flag = wx.ALIGN_RIGHT)
countPanelSizer.Add(wx.StaticText(countPanel, label = 'Links'))
self.brokenLinks = wx.StaticText(countPanel)
countPanelSizer.Add(self.brokenLinks, flag = wx.ALIGN_RIGHT)
countPanelSizer.Add(wx.StaticText(countPanel, label = 'Broken Links'))
self.variablesCount = wx.StaticText(countPanel)
countPanelSizer.Add(self.variablesCount, flag = wx.ALIGN_RIGHT)
countPanelSizer.Add(wx.StaticText(countPanel, label = 'Variables Used'))
self.panelSizer.Add(countPanel, flag = wx.ALL | wx.ALIGN_CENTER, border = metrics.size('relatedControls'))
self.count(panel)
okButton = wx.Button(parent = panel, label = 'OK')
okButton.Bind(wx.EVT_BUTTON, lambda e: self.Close())
self.panelSizer.Add(okButton, flag = wx.ALL | wx.ALIGN_CENTER, border = metrics.size('relatedControls'))
self.panelSizer.Fit(self)
size = self.GetSize()
if size.width < StatisticsDialog.MIN_WIDTH:
size.width = StatisticsDialog.MIN_WIDTH
self.SetSize(size)
self.panelSizer.Layout()
self.SetIcon(app.icon)
self.Show()
示例5: __init__
def __init__ (self, parent, onFind = None, onClose = None):
self.findCallback = onFind
self.closeCallback = onClose
wx.Panel.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
# find text and label
findSizer = wx.BoxSizer(wx.HORIZONTAL)
findSizer.Add(wx.StaticText(self, label = 'Find'), flag = wx.BOTTOM | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, \
border = metrics.size('relatedControls'), proportion = 0)
self.findField = wx.TextCtrl(self)
findSizer.Add(self.findField, proportion = 1, flag = wx.BOTTOM | wx.EXPAND, \
border = metrics.size('relatedControls'))
sizer.Add(findSizer, flag = wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, border = metrics.size('windowBorder'))
# option checkboxes
optionSizer = wx.BoxSizer(wx.HORIZONTAL)
self.caseCheckbox = wx.CheckBox(self, label = 'Match Case')
self.wholeWordCheckbox = wx.CheckBox(self, label = 'Whole Word')
self.regexpCheckbox = wx.CheckBox(self, label = 'Regular Expression')
optionSizer.Add(self.caseCheckbox, flag = wx.BOTTOM | wx.RIGHT, border = metrics.size('relatedControls'))
optionSizer.Add(self.wholeWordCheckbox, flag = wx.BOTTOM | wx.LEFT | wx.RIGHT, \
border = metrics.size('relatedControls'))
optionSizer.Add(self.regexpCheckbox, flag = wx.BOTTOM | wx.LEFT, \
border = metrics.size('relatedControls'))
sizer.Add(optionSizer, flag = wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, \
border = metrics.size('windowBorder'))
# find and close buttons
buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
self.closeButton = wx.Button(self, label = 'Close')
self.closeButton.Bind(wx.EVT_BUTTON, self.onClose)
self.findButton = wx.Button(self, label = 'Find Next')
self.findButton.Bind(wx.EVT_BUTTON, self.onFind)
buttonSizer.Add(self.closeButton, flag = wx.TOP | wx.RIGHT, border = metrics.size('buttonSpace'))
buttonSizer.Add(self.findButton, flag = wx.TOP, border = metrics.size('buttonSpace'))
sizer.Add(buttonSizer, flag = wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT, \
border = metrics.size('windowBorder'))
sizer.Fit(self)
示例6: __init__
def __init__(self, app, parent = None):
self.app = app
self.parent = parent
wx.Frame.__init__(self, parent, wx.ID_ANY, title = parent.title + ' Metadata', \
style = wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.CAPTION | wx.SYSTEM_MENU)
panel = wx.Panel(parent = self, id = wx.ID_ANY)
borderSizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(borderSizer)
panelSizer = wx.FlexGridSizer(8, 1, metrics.size('relatedControls'), metrics.size('relatedControls'))
borderSizer.Add(panelSizer, flag = wx.ALL, border = metrics.size('windowBorder'))
ctrlset = {}
for name, desc in \
[
("identity", ("What your work identifies as:",
"Is it a game, a story, a poem, or something else?\n(This is used for dialogs and error messages only.)",
False)),
("description", ("A short description of your work:",
"This is inserted in the HTML file's <meta> description tag, used by\nsearch engines and other automated tools.",
True))
]:
textlabel = wx.StaticText(panel, label = desc[0])
if desc[2]:
textctrl = wx.TextCtrl(panel, size=(200,60), style=wx.TE_MULTILINE)
else:
textctrl = wx.TextCtrl(panel, size=(200,-1))
textctrl.SetValue(parent.metadata.get(name, ''))
textctrl.Bind(wx.EVT_TEXT, lambda e, name=name, textctrl=textctrl:
self.saveSetting(name,textctrl.GetValue()))
hSizer = wx.BoxSizer(wx.HORIZONTAL)
hSizer.Add(textlabel,1,wx.ALIGN_LEFT|wx.ALIGN_TOP)
hSizer.Add(textctrl,1,wx.EXPAND)
panelSizer.Add(hSizer,flag=wx.ALL|wx.EXPAND)
panelSizer.Add(wx.StaticText(panel, label = desc[1]))
panelSizer.Add((1,2))
panelSizer.Fit(self)
borderSizer.Fit(self)
self.SetIcon(self.app.icon)
self.Show()
self.panelSizer = panelSizer
self.borderSizer = borderSizer
示例7: __init__
def __init__(self, parent, widget, app):
self.widget = widget
self.app = app
self.syncTimer = None
self.image = None
self.gif = None
wx.Frame.__init__(self, parent, wx.ID_ANY, title = 'Untitled Passage - ' + self.app.NAME + ' ' + versionString, \
size = PassageFrame.DEFAULT_SIZE, style=wx.DEFAULT_FRAME_STYLE)
# controls
self.panel = wx.Panel(self)
allSizer = wx.BoxSizer(wx.VERTICAL)
self.panel.SetSizer(allSizer)
# title control
self.topControls = wx.Panel(self.panel)
topSizer = wx.FlexGridSizer(3, 2, metrics.size('relatedControls'), metrics.size('relatedControls'))
titleLabel = wx.StaticText(self.topControls, style = wx.ALIGN_RIGHT, label = PassageFrame.TITLE_LABEL)
self.titleInput = wx.TextCtrl(self.topControls)
self.titleInput.SetValue(self.widget.passage.title)
self.SetTitle(self.title())
topSizer.Add(titleLabel, 0, flag = wx.ALL, border = metrics.size('focusRing'))
topSizer.Add(self.titleInput, 1, flag = wx.EXPAND | wx.ALL, border = metrics.size('focusRing'))
topSizer.AddGrowableCol(1, 1)
self.topControls.SetSizer(topSizer)
# image pane
self.imageScroller = wx.ScrolledWindow(self.panel)
self.imageSizer = wx.GridSizer(1,1)
self.imageScroller.SetSizer(self.imageSizer)
# image menu
passageMenu = wx.Menu()
passageMenu.Append(self.IMPORT_IMAGE, '&Replace Image...\tCtrl-O')
self.Bind(wx.EVT_MENU, self.replaceImage, id = self.IMPORT_IMAGE)
passageMenu.Append(self.SAVE_IMAGE, '&Save Image...')
self.Bind(wx.EVT_MENU, self.saveImage, id = self.SAVE_IMAGE)
passageMenu.AppendSeparator()
passageMenu.Append(wx.ID_SAVE, '&Save Story\tCtrl-S')
self.Bind(wx.EVT_MENU, self.widget.parent.parent.save, id = wx.ID_SAVE)
passageMenu.Append(PassageFrame.PASSAGE_REBUILD_STORY, '&Rebuild Story\tCtrl-R')
self.Bind(wx.EVT_MENU, self.widget.parent.parent.rebuild, id = PassageFrame.PASSAGE_REBUILD_STORY)
passageMenu.AppendSeparator()
passageMenu.Append(wx.ID_CLOSE, '&Close Image\tCtrl-W')
self.Bind(wx.EVT_MENU, lambda e: self.Destroy(), id = wx.ID_CLOSE)
# edit menu
editMenu = wx.Menu()
editMenu.Append(wx.ID_COPY, '&Copy\tCtrl-C')
self.Bind(wx.EVT_MENU, self.copyImage, id = wx.ID_COPY)
editMenu.Append(wx.ID_PASTE, '&Paste\tCtrl-V')
self.Bind(wx.EVT_MENU, self.pasteImage, id = wx.ID_PASTE)
# menu bar
self.menus = wx.MenuBar()
self.menus.Append(passageMenu, '&Image')
self.menus.Append(editMenu, '&Edit')
self.SetMenuBar(self.menus)
# finish
allSizer.Add(self.topControls, flag = wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, border = metrics.size('windowBorder'))
allSizer.Add(self.imageScroller, proportion = 1, flag = wx.TOP | wx.EXPAND, border = metrics.size('relatedControls'))
# bindings
self.titleInput.Bind(wx.EVT_TEXT, self.syncPassage)
self.SetIcon(self.app.icon)
self.updateImage()
self.Show(True)
示例8: cachePaint
def cachePaint(self, size):
"""
Caches the widget so self.paintBuffer is up-to-date.
"""
def wordWrap(text, lineWidth, gc, lineBreaks = False):
"""
Returns a list of lines from a string
This is somewhat based on the wordwrap function built into wx.lib.
(For some reason, GraphicsContext.GetPartialTextExtents()
is returning totally wrong numbers but GetTextExtent() works fine.)
This assumes that you've already set up the font you want on the GC.
It gloms multiple spaces together, but for our purposes that's ok.
"""
words = re.finditer('\S+\s*', text.replace('\r',''))
lines = ''
currentLine = ''
for w in words:
word = w.group(0)
wordWidth = gc.GetTextExtent(currentLine + word)[0]
if wordWidth < lineWidth:
currentLine += word
if '\n' in word:
lines += currentLine
currentLine = ''
else:
lines += currentLine + '\n'
currentLine = word
lines += currentLine
return lines.split('\n')
def dim(c, dim):
"""Lowers a color's alpha if dim is true."""
if isinstance(c, wx.Colour): c = list(c.Get(includeAlpha = True))
if len(c) < 4:
c = list(c)
c.append(255)
if dim:
a = PassageWidget.DIMMED_ALPHA
if not self.app.config.ReadBool('fastStoryPanel'):
c[3] *= a
else:
c[0] *= a
c[1] *= a
c[2] *= a
return wx.Colour(*c)
# set up our buffer
bitmap = wx.EmptyBitmap(size.width, size.height)
self.paintBuffer.SelectObject(bitmap)
# switch to a GraphicsContext as necessary
if self.app.config.ReadBool('fastStoryPanel'):
gc = self.paintBuffer
else:
gc = wx.GraphicsContext.Create(self.paintBuffer)
# text font sizes
# wxWindows works with points, so we need to doublecheck on actual pixels
titleFontSize = self.parent.toPixels((metrics.size('widgetTitle'), -1), scaleOnly = True)[0]
titleFontSize = min(titleFontSize, metrics.size('fontMax'))
titleFontSize = max(titleFontSize, metrics.size('fontMin'))
excerptFontSize = min(titleFontSize * 0.9, metrics.size('fontMax'))
excerptFontSize = max(excerptFontSize, metrics.size('fontMin'))
titleFont = wx.Font(titleFontSize, wx.SWISS, wx.NORMAL, wx.BOLD, False, 'Arial')
excerptFont = wx.Font(excerptFontSize, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')
titleFontHeight = math.fabs(titleFont.GetPixelSize()[1])
excerptFontHeight = math.fabs(excerptFont.GetPixelSize()[1])
tagBarColor = dim( tuple(i*256 for i in colorsys.hsv_to_rgb(0.14 + math.sin(hash("".join(self.passage.tags)))*0.08, 0.28, 0.88)), self.dimmed)
# inset for text (we need to know this for layout purposes)
inset = titleFontHeight / 3
# frame
if self.passage.isAnnotation():
frameColor = PassageWidget.COLORS['frame']
c = wx.Colour(*PassageWidget.COLORS['annotation'])
frameInterior = (c,c)
else:
frameColor = dim(PassageWidget.COLORS['frame'], self.dimmed)
frameInterior = (dim(PassageWidget.COLORS['bodyStart'], self.dimmed), \
dim(PassageWidget.COLORS['bodyEnd'], self.dimmed))
gc.SetPen(wx.Pen(frameColor, 1))
if isinstance(gc, wx.GraphicsContext):
gc.SetBrush(gc.CreateLinearGradientBrush(0, 0, 0, size.height, \
frameInterior[0], frameInterior[1]))
else:
gc.GradientFillLinear(wx.Rect(0, 0, size.width - 1, size.height - 1), \
frameInterior[0], frameInterior[1], wx.SOUTH)
gc.SetBrush(wx.TRANSPARENT_BRUSH)
#.........这里部分代码省略.........
示例9: __init__
def __init__(self, app, parent = None):
self.app = app
wx.Frame.__init__(self, parent, wx.ID_ANY, title = self.app.NAME + ' Preferences', \
style = wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.CAPTION | wx.SYSTEM_MENU)
panel = wx.Panel(parent = self, id = wx.ID_ANY)
borderSizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(borderSizer)
panelSizer = wx.FlexGridSizer(8, 2, metrics.size('relatedControls'), metrics.size('relatedControls'))
borderSizer.Add(panelSizer, flag = wx.ALL, border = metrics.size('windowBorder'))
self.editorFont = wx.FontPickerCtrl(panel, style = wx.FNTP_FONTDESC_AS_LABEL)
self.editorFont.SetSelectedFont(self.getPrefFont('windowed'))
self.editorFont.Bind(wx.EVT_FONTPICKER_CHANGED, lambda e: self.saveFontPref('windowed', \
self.editorFont.GetSelectedFont()))
self.monoFont = wx.FontPickerCtrl(panel, style = wx.FNTP_FONTDESC_AS_LABEL)
self.monoFont.SetSelectedFont(self.getPrefFont('monospace'))
self.monoFont.Bind(wx.EVT_FONTPICKER_CHANGED, lambda e: self.saveFontPref('monospace', \
self.monoFont.GetSelectedFont()))
self.fsFont = wx.FontPickerCtrl(panel, style = wx.FNTP_FONTDESC_AS_LABEL)
self.fsFont.SetSelectedFont(self.getPrefFont('fs'))
self.fsFont.Bind(wx.EVT_FONTPICKER_CHANGED, lambda e: self.saveFontPref('fs', \
self.fsFont.GetSelectedFont()))
self.fsTextColor = wx.ColourPickerCtrl(panel)
self.fsTextColor.SetColour(self.app.config.Read('fsTextColor'))
self.fsTextColor.Bind(wx.EVT_COLOURPICKER_CHANGED, lambda e: self.savePref('fsTextColor', \
self.fsTextColor.GetColour()))
self.fsBgColor = wx.ColourPickerCtrl(panel)
self.fsBgColor.SetColour(self.app.config.Read('fsBgColor'))
self.fsBgColor.Bind(wx.EVT_COLOURPICKER_CHANGED, lambda e: self.savePref('fsBgColor', \
self.fsBgColor.GetColour()))
fsLineHeightPanel = wx.Panel(panel)
fsLineHeightSizer = wx.BoxSizer(wx.HORIZONTAL)
fsLineHeightPanel.SetSizer(fsLineHeightSizer)
self.fsLineHeight = wx.ComboBox(fsLineHeightPanel, choices = ('100', '125', '150', '175', '200'))
self.fsLineHeight.Bind(wx.EVT_TEXT, lambda e: self.savePref('fsLineHeight', int(self.fsLineHeight.GetValue())))
self.fsLineHeight.SetValue(str(self.app.config.ReadInt('fslineHeight')))
fsLineHeightSizer.Add(self.fsLineHeight, flag = wx.ALIGN_CENTER_VERTICAL)
fsLineHeightSizer.Add(wx.StaticText(fsLineHeightPanel, label = '%'), flag = wx.ALIGN_CENTER_VERTICAL)
self.fastStoryPanel = wx.CheckBox(panel, label = 'Faster but rougher story map display')
self.fastStoryPanel.Bind(wx.EVT_CHECKBOX, lambda e: self.savePref('fastStoryPanel', \
self.fastStoryPanel.GetValue()))
self.fastStoryPanel.SetValue(self.app.config.ReadBool('fastStoryPanel'))
self.imageArrows = wx.CheckBox(panel, label = 'Connector arrows for images and stylesheets')
self.imageArrows.Bind(wx.EVT_CHECKBOX, lambda e: self.savePref('imageArrows', \
self.imageArrows.GetValue()))
self.imageArrows.SetValue(self.app.config.ReadBool('imageArrows'))
panelSizer.Add(wx.StaticText(panel, label = 'Normal Font'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.editorFont)
panelSizer.Add(wx.StaticText(panel, label = 'Monospace Font'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.monoFont)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Font'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsFont)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Text Color'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsTextColor)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Background Color'), \
flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsBgColor)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Line Spacing'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(fsLineHeightPanel, flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fastStoryPanel)
panelSizer.Add((1,2))
panelSizer.Add(self.imageArrows)
panelSizer.Fit(self)
borderSizer.Fit(self)
self.SetIcon(self.app.icon)
self.Show()
self.panelSizer = panelSizer
self.borderSizer = borderSizer
示例10: __init__
def __init__ (self, parent, widget, app):
self.widget = widget
self.app = app
self.syncTimer = None
self.lastFindRegexp = None
self.lastFindFlags = None
self.usingLexer = True
wx.Frame.__init__(self, parent, wx.ID_ANY, title = 'Untitled Passage - ' + self.app.NAME, \
size = PassageFrame.DEFAULT_SIZE)
# Passage menu
passageMenu = wx.Menu()
passageMenu.Append(PassageFrame.PASSAGE_EDIT_SELECTION, 'Create &Link From Selection\tCtrl-L')
self.Bind(wx.EVT_MENU, self.editSelection, id = PassageFrame.PASSAGE_EDIT_SELECTION)
self.outLinksMenu = wx.Menu()
self.outLinksMenuTitle = passageMenu.AppendMenu(wx.ID_ANY, 'Outgoing Links', self.outLinksMenu)
self.inLinksMenu = wx.Menu()
self.inLinksMenuTitle = passageMenu.AppendMenu(wx.ID_ANY, 'Incoming Links', self.inLinksMenu)
self.brokenLinksMenu = wx.Menu()
self.brokenLinksMenuTitle = passageMenu.AppendMenu(wx.ID_ANY, 'Broken Links', self.brokenLinksMenu)
passageMenu.AppendSeparator()
passageMenu.Append(wx.ID_SAVE, '&Save Story\tCtrl-S')
self.Bind(wx.EVT_MENU, self.widget.parent.parent.save, id = wx.ID_SAVE)
passageMenu.Append(PassageFrame.PASSAGE_REBUILD_STORY, '&Rebuild Story\tCtrl-R')
self.Bind(wx.EVT_MENU, self.widget.parent.parent.rebuild, id = PassageFrame.PASSAGE_REBUILD_STORY)
passageMenu.AppendSeparator()
passageMenu.Append(PassageFrame.PASSAGE_FULLSCREEN, '&Fullscreen View\tF12')
self.Bind(wx.EVT_MENU, self.openFullscreen, id = PassageFrame.PASSAGE_FULLSCREEN)
passageMenu.Append(wx.ID_CLOSE, '&Close Passage\tCtrl-W')
self.Bind(wx.EVT_MENU, lambda e: self.Destroy(), id = wx.ID_CLOSE)
# Edit menu
editMenu = wx.Menu()
editMenu.Append(wx.ID_UNDO, '&Undo\tCtrl-Z')
self.Bind(wx.EVT_MENU, lambda e: self.bodyInput.Undo(), id = wx.ID_UNDO)
editMenu.Append(wx.ID_REDO, '&Redo\tCtrl-Y')
self.Bind(wx.EVT_MENU, lambda e: self.bodyInput.Redo(), id = wx.ID_REDO)
editMenu.AppendSeparator()
editMenu.Append(wx.ID_CUT, 'Cu&t\tCtrl-X')
self.Bind(wx.EVT_MENU, lambda e: self.bodyInput.Cut(), id = wx.ID_CUT)
editMenu.Append(wx.ID_COPY, '&Copy\tCtrl-C')
self.Bind(wx.EVT_MENU, lambda e: self.bodyInput.Copy(), id = wx.ID_COPY)
editMenu.Append(wx.ID_PASTE, '&Paste\tCtrl-V')
self.Bind(wx.EVT_MENU, lambda e: self.bodyInput.Paste(), id = wx.ID_PASTE)
editMenu.Append(wx.ID_SELECTALL, 'Select &All\tCtrl-A')
self.Bind(wx.EVT_MENU, lambda e: self.bodyInput.SelectAll(), id = wx.ID_SELECTALL)
editMenu.AppendSeparator()
editMenu.Append(wx.ID_FIND, '&Find...\tCtrl-F')
self.Bind(wx.EVT_MENU, lambda e: self.showSearchFrame(PassageSearchFrame.FIND_TAB), id = wx.ID_FIND)
editMenu.Append(PassageFrame.EDIT_FIND_NEXT, 'Find &Next\tCtrl-G')
self.Bind(wx.EVT_MENU, self.findNextRegexp, id = PassageFrame.EDIT_FIND_NEXT)
if sys.platform == 'darwin':
shortcut = 'Ctrl-Shift-H'
else:
shortcut = 'Ctrl-H'
editMenu.Append(wx.ID_REPLACE, '&Replace...\t' + shortcut)
self.Bind(wx.EVT_MENU, lambda e: self.showSearchFrame(PassageSearchFrame.REPLACE_TAB), id = wx.ID_REPLACE)
# menus
self.menus = wx.MenuBar()
self.menus.Append(passageMenu, '&Passage')
self.menus.Append(editMenu, '&Edit')
self.SetMenuBar(self.menus)
# controls
self.panel = wx.Panel(self)
allSizer = wx.BoxSizer(wx.VERTICAL)
self.panel.SetSizer(allSizer)
# title/tag controls
self.topControls = wx.Panel(self.panel)
topSizer = wx.FlexGridSizer(3, 2, metrics.size('relatedControls'), metrics.size('relatedControls'))
titleLabel = wx.StaticText(self.topControls, style = wx.ALIGN_RIGHT, label = PassageFrame.TITLE_LABEL)
#.........这里部分代码省略.........
示例11: __init__
def __init__(self, app, parent = None):
self.app = app
wx.Frame.__init__(self, parent, wx.ID_ANY, title = self.app.NAME + ' Preferences', \
style = wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.CAPTION | wx.SYSTEM_MENU)
panel = wx.Panel(parent = self, id = wx.ID_ANY)
borderSizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(borderSizer)
panelSizer = wx.FlexGridSizer(14, 2, metrics.size('relatedControls'), metrics.size('relatedControls'))
borderSizer.Add(panelSizer, flag = wx.ALL, border = metrics.size('windowBorder'))
self.editorFont = wx.FontPickerCtrl(panel, style = wx.FNTP_FONTDESC_AS_LABEL)
self.editorFont.SetSelectedFont(self.getPrefFont('windowed'))
self.editorFont.Bind(wx.EVT_FONTPICKER_CHANGED, lambda e: self.saveFontPref('windowed', \
self.editorFont.GetSelectedFont()))
self.monoFont = wx.FontPickerCtrl(panel, style = wx.FNTP_FONTDESC_AS_LABEL)
self.monoFont.SetSelectedFont(self.getPrefFont('monospace'))
self.monoFont.Bind(wx.EVT_FONTPICKER_CHANGED, lambda e: self.saveFontPref('monospace', \
self.monoFont.GetSelectedFont()))
self.fsFont = wx.FontPickerCtrl(panel, style = wx.FNTP_FONTDESC_AS_LABEL)
self.fsFont.SetSelectedFont(self.getPrefFont('fs'))
self.fsFont.Bind(wx.EVT_FONTPICKER_CHANGED, lambda e: self.saveFontPref('fs', \
self.fsFont.GetSelectedFont()))
self.fsTextColor = wx.ColourPickerCtrl(panel)
self.fsTextColor.SetColour(self.app.config.Read('fsTextColor'))
self.fsTextColor.Bind(wx.EVT_COLOURPICKER_CHANGED, lambda e: self.savePref('fsTextColor', \
self.fsTextColor.GetColour()))
self.fsBgColor = wx.ColourPickerCtrl(panel)
self.fsBgColor.SetColour(self.app.config.Read('fsBgColor'))
self.fsBgColor.Bind(wx.EVT_COLOURPICKER_CHANGED, lambda e: self.savePref('fsBgColor', \
self.fsBgColor.GetColour()))
fsLineHeightPanel = wx.Panel(panel)
fsLineHeightSizer = wx.BoxSizer(wx.HORIZONTAL)
fsLineHeightPanel.SetSizer(fsLineHeightSizer)
self.fsLineHeight = wx.ComboBox(fsLineHeightPanel, choices = ('100', '125', '150', '175', '200'))
self.fsLineHeight.Bind(wx.EVT_TEXT, lambda e: self.savePref('fsLineHeight', int(self.fsLineHeight.GetValue())))
self.fsLineHeight.SetValue(str(self.app.config.ReadInt('fslineHeight')))
fsLineHeightSizer.Add(self.fsLineHeight, flag = wx.ALIGN_CENTER_VERTICAL)
fsLineHeightSizer.Add(wx.StaticText(fsLineHeightPanel, label = '%'), flag = wx.ALIGN_CENTER_VERTICAL)
def checkbox(self, name, label, panel=panel):
setattr(self, name, wx.CheckBox(panel, label=label))
attr = getattr(self, name)
attr.Bind(wx.EVT_CHECKBOX, lambda e, name=name, attr=attr: self.savePref(name, attr.GetValue()))
attr.SetValue(self.app.config.ReadBool(name))
checkbox(self, "fastStoryPanel", 'Faster but rougher story map display')
checkbox(self, "flatDesign", 'Flat Design(TM) mode')
checkbox(self, "imageArrows", 'Connector arrows for images and stylesheets')
checkbox(self, "displayArrows", 'Connector arrows for <<display>>ed passages')
checkbox(self, "createPassagePrompt", 'Offer to create new passages for broken links')
checkbox(self, "importImagePrompt", 'Offer to import externally linked images')
checkbox(self, "passageWarnings", 'Warn about possible passage code errors')
panelSizer.Add(wx.StaticText(panel, label = 'Normal Font'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.editorFont)
panelSizer.Add(wx.StaticText(panel, label = 'Monospace Font'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.monoFont)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Font'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsFont)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Text Color'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsTextColor)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Background Color'), \
flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fsBgColor)
panelSizer.Add(wx.StaticText(panel, label = 'Fullscreen Editor Line Spacing'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(fsLineHeightPanel, flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add(self.fastStoryPanel)
panelSizer.Add((1,2))
panelSizer.Add(self.flatDesign)
panelSizer.Add((1,2))
panelSizer.Add(self.imageArrows)
panelSizer.Add((1,2))
panelSizer.Add(self.displayArrows)
panelSizer.Add((1,2))
panelSizer.Add(wx.StaticText(panel, label = 'When closing a passage:'), flag = wx.ALIGN_CENTER_VERTICAL)
panelSizer.Add((1,2))
panelSizer.Add(self.createPassagePrompt)
panelSizer.Add((1,2))
panelSizer.Add(self.importImagePrompt)
panelSizer.Add((1,2))
panelSizer.Add(self.passageWarnings)
panelSizer.Fit(self)
borderSizer.Fit(self)
self.SetIcon(self.app.icon)
self.Show()
self.panelSizer = panelSizer
self.borderSizer = borderSizer
示例12: paint
def paint (self, gc):
"""
Paints widget to the graphics context passed. You may give it
either a wx.GraphicsContext (anti-aliased drawing) or a wx.PaintDC.
"""
def wordWrap (text, lineWidth, gc):
"""
Returns a list of lines from a string
This is somewhat based on the wordwrap function built into wx.lib.
(For some reason, GraphicsContext.GetPartialTextExtents()
is returning totally wrong numbers but GetTextExtent() works fine.)
This assumes that you've already set up the font you want on the GC.
It gloms multiple spaces together, but for our purposes that's ok.
"""
words = text.split()
lines = []
currentWidth = 0
currentLine = ''
for word in words:
wordWidth = gc.GetTextExtent(word + ' ')[0]
if currentWidth + wordWidth < lineWidth:
currentLine += word + ' '
currentWidth += wordWidth
else:
lines.append(currentLine)
currentLine = word + ' '
currentWidth = wordWidth
lines.append(currentLine)
return lines
def dim (c, dim):
"""Lowers a color's alpha if dim is true."""
if isinstance(c, wx.Color): c = list(c.Get(includeAlpha = True))
if len(c) < 4:
c = list(c)
c.append(255)
if dim: c[3] *= PassageWidget.DIMMED_ALPHA
return wx.Color(c[0], c[1], c[2], c[3])
pixPos = self.parent.toPixels(self.pos)
pixSize = self.parent.toPixels(self.getSize(), scaleOnly = True)
# text font sizes
# wxWindows works with points, so we need to doublecheck on actual pixels
titleFontSize = self.parent.toPixels((metrics.size('widgetTitle'), -1), scaleOnly = True)[0]
titleFontSize = min(titleFontSize, metrics.size('fontMax'))
titleFontSize = max(titleFontSize, metrics.size('fontMin'))
excerptFontSize = min(titleFontSize * 0.9, metrics.size('fontMax'))
excerptFontSize = max(excerptFontSize, metrics.size('fontMin'))
titleFont = wx.Font(titleFontSize, wx.SWISS, wx.NORMAL, wx.BOLD, False, 'Arial')
excerptFont = wx.Font(excerptFontSize, wx.SWISS, wx.NORMAL, wx.NORMAL, False, 'Arial')
titleFontHeight = math.fabs(titleFont.GetPixelSize()[1])
excerptFontHeight = math.fabs(excerptFont.GetPixelSize()[1])
# inset for text (we need to know this for layout purposes)
inset = titleFontHeight / 3
# frame
frameColor = dim(PassageWidget.COLORS['frame'], self.dimmed)
frameInterior = (dim(PassageWidget.COLORS['bodyStart'], self.dimmed), \
dim(PassageWidget.COLORS['bodyEnd'], self.dimmed))
gc.SetPen(wx.Pen(frameColor, 1))
if isinstance(gc, wx.GraphicsContext):
gc.SetBrush(gc.CreateLinearGradientBrush(pixPos[0], pixPos[1], \
pixPos[0], pixPos[1] + pixSize[1], \
frameInterior[0], frameInterior[1]))
else:
gc.GradientFillLinear(wx.Rect(pixPos[0], pixPos[1], pixSize[0] - 1, pixSize[1] - 1), \
frameInterior[0], frameInterior[1], wx.SOUTH)
gc.SetBrush(wx.TRANSPARENT_BRUSH)
gc.DrawRectangle(pixPos[0], pixPos[1], pixSize[0] - 1, pixSize[1] - 1)
if pixSize[0] > PassageWidget.MIN_GREEKING_SIZE:
# title bar
titleBarHeight = titleFontHeight + (2 * inset)
titleBarColor = dim(PassageWidget.COLORS['titleBar'], self.dimmed)
gc.SetPen(wx.Pen(titleBarColor, 1))
gc.SetBrush(wx.Brush(titleBarColor))
gc.DrawRectangle(pixPos[0] + 1, pixPos[1] + 1, pixSize[0] - 3, titleBarHeight)
# draw title
# we let clipping prevent writing over the frame
if isinstance(gc, wx.GraphicsContext):
gc.ResetClip()
gc.Clip(pixPos[0] + inset, pixPos[1] + inset, pixSize[0] - (inset * 2), titleBarHeight - 2)
else:
gc.DestroyClippingRegion()
gc.SetClippingRect(wx.Rect(pixPos[0] + inset, pixPos[1] + inset, pixSize[0] - (inset * 2), titleBarHeight - 2))
#.........这里部分代码省略.........