📄 pydocview.py
字号:
"""
return self._childView
def SetView(self, view):
"""
Sets the view for this frame.
"""
self._childView = view
class DocService(wx.EvtHandler):
"""
An abstract class used to add reusable services to a docview application.
"""
def __init__(self):
"""Initializes the DocService."""
pass
def GetDocumentManager(self):
"""Returns the DocManager for the docview application."""
return self._docManager
def SetDocumentManager(self, docManager):
"""Sets the DocManager for the docview application."""
self._docManager = docManager
def InstallControls(self, frame, menuBar=None, toolBar=None, statusBar=None, document=None):
"""Called to install controls into the menubar and toolbar of a SDI or MDI window. Override this method for a particular service."""
pass
def ProcessEventBeforeWindows(self, event):
"""
Processes an event before the main window has a chance to process the window.
Override this method for a particular service.
"""
return False
def ProcessUpdateUIEventBeforeWindows(self, event):
"""
Processes a UI event before the main window has a chance to process the window.
Override this method for a particular service.
"""
return False
def ProcessEvent(self, event):
"""
Processes an event, searching event tables and calling zero or more
suitable event handler function(s). Note that the ProcessEvent
method is called from the wxPython docview framework directly since
wxPython does not have a virtual ProcessEvent function.
"""
return False
def ProcessUpdateUIEvent(self, event):
"""
Processes a UI event, searching event tables and calling zero or more
suitable event handler function(s). Note that the ProcessEvent
method is called from the wxPython docview framework directly since
wxPython does not have a virtual ProcessEvent function.
"""
return False
def OnCloseFrame(self, event):
"""
Called when the a docview frame is being closed. Override this method
so a service can either do cleanup or veto the frame being closed by
returning false.
"""
return True
def OnExit(self):
"""
Called when the the docview application is being closed. Override this method
so a service can either do cleanup or veto the frame being closed by
returning false.
"""
pass
def GetMenuItemPos(self, menu, id):
"""
Utility method used to find the position of a menu item so that services can
easily find where to insert a menu item in InstallControls.
"""
menuItems = menu.GetMenuItems()
for i, menuItem in enumerate(menuItems):
if menuItem.GetId() == id:
return i
return i
def GetView(self):
"""
Called by WindowMenuService to get views for services that don't
have dedicated documents such as the Outline Service.
"""
return None
class DocOptionsService(DocService):
"""
A service that implements an options menu item and an options dialog with
notebook tabs. New tabs can be added by other services by calling the
"AddOptionsPanel" method.
"""
def __init__(self, showGeneralOptions=True, supportedModes=wx.lib.docview.DOC_SDI & wx.lib.docview.DOC_MDI):
"""
Initializes the options service with the option of suppressing the default
general options pane that is included with the options service by setting
showGeneralOptions to False. It allowModeChanges is set to False, the
default general options pane will allow users to change the document
interface mode between SDI and MDI modes.
"""
DocService.__init__(self)
self.ClearOptionsPanels()
self._supportedModes = supportedModes
self._toolOptionsID = wx.ID_PREFERENCES
if showGeneralOptions:
self.AddOptionsPanel(GeneralOptionsPanel)
def InstallControls(self, frame, menuBar=None, toolBar=None, statusBar=None, document=None):
"""
Installs a "Tools" menu with an "Options" menu item.
"""
toolsMenuIndex = menuBar.FindMenu(_("&Tools"))
if toolsMenuIndex > -1:
toolsMenu = menuBar.GetMenu(toolsMenuIndex)
else:
toolsMenu = wx.Menu()
if toolsMenuIndex == -1:
formatMenuIndex = menuBar.FindMenu(_("&Format"))
menuBar.Insert(formatMenuIndex + 1, toolsMenu, _("&Tools"))
if toolsMenu:
if toolsMenu.GetMenuItemCount():
toolsMenu.AppendSeparator()
toolsMenu.Append(self._toolOptionsID, _("&Options..."), _("Sets options"))
wx.EVT_MENU(frame, self._toolOptionsID, frame.ProcessEvent)
def ProcessEvent(self, event):
"""
Checks to see if the "Options" menu item has been selected.
"""
id = event.GetId()
if id == self._toolOptionsID:
self.OnOptions(event)
return True
else:
return False
def GetSupportedModes(self):
"""
Return the modes supported by the application. Use docview.DOC_SDI and
docview.DOC_MDI flags to check if SDI and/or MDI modes are supported.
"""
return self._supportedModes
def SetSupportedModes(self, _supportedModessupportedModes):
"""
Sets the modes supported by the application. Use docview.DOC_SDI and
docview.DOC_MDI flags to set if SDI and/or MDI modes are supported.
"""
self._supportedModes = supportedModes
def ClearOptionsPanels(self):
"""
Clears all of the options panels that have been added into the
options dialog.
"""
self._optionsPanels = []
def AddOptionsPanel(self, optionsPanel):
"""
Adds an options panel to the options dialog.
"""
self._optionsPanels.append(optionsPanel)
def OnOptions(self, event):
"""
Shows the options dialog, called when the "Options" menu item is selected.
"""
if len(self._optionsPanels) == 0:
return
optionsDialog = OptionsDialog(wx.GetApp().GetTopWindow(), self._optionsPanels, self._docManager)
optionsDialog.CenterOnParent()
if optionsDialog.ShowModal() == wx.ID_OK:
optionsDialog.OnOK(optionsDialog) # wxBug: wxDialog should be calling this automatically but doesn't
optionsDialog.Destroy()
class OptionsDialog(wx.Dialog):
"""
A default options dialog used by the OptionsService that hosts a notebook
tab of options panels.
"""
def __init__(self, parent, optionsPanelClasses, docManager):
"""
Initializes the options dialog with a notebook page that contains new
instances of the passed optionsPanelClasses.
"""
wx.Dialog.__init__(self, parent, -1, _("Options"))
self._optionsPanels = []
self._docManager = docManager
HALF_SPACE = 5
SPACE = 10
sizer = wx.BoxSizer(wx.VERTICAL)
if wx.Platform == "__WXMAC__":
optionsNotebook = wx.Listbook(self, wx.NewId(), style=wx.LB_DEFAULT)
else:
optionsNotebook = wx.Notebook(self, wx.NewId(), style=wx.NB_MULTILINE) # NB_MULTILINE is windows platform only
sizer.Add(optionsNotebook, 0, wx.ALL | wx.EXPAND, SPACE)
if wx.Platform == "__WXMAC__":
iconList = wx.ImageList(16, 16, initialCount = len(optionsPanelClasses))
self._iconIndexLookup = []
for optionsPanelClass in optionsPanelClasses:
optionsPanel = optionsPanelClass(optionsNotebook, -1)
self._optionsPanels.append(optionsPanel)
# We need to populate the image list before setting notebook images
if hasattr(optionsPanel, "GetIcon"):
icon = optionsPanel.GetIcon()
else:
icon = None
if icon:
if icon.GetHeight() != 16 or icon.GetWidth() != 16:
icon.SetHeight(16)
icon.SetWidth(16)
if wx.GetApp().GetDebug():
print "Warning: icon for '%s' isn't 16x16, not crossplatform" % template._docTypeName
iconIndex = iconList.AddIcon(icon)
self._iconIndexLookup.append((optionsPanel, iconIndex))
else:
# use -1 to represent that this panel has no icon
self._iconIndexLookup.append((optionsPanel, -1))
optionsNotebook.AssignImageList(iconList)
# Add icons to notebook
for index in range(0, len(optionsPanelClasses)-1):
iconIndex = self._iconIndexLookup[index][1]
if iconIndex >= 0:
optionsNotebook.SetPageImage(index, iconIndex)
else:
for optionsPanelClass in optionsPanelClasses:
optionsPanel = optionsPanelClass(optionsNotebook, -1)
self._optionsPanels.append(optionsPanel)
sizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), 0, wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, HALF_SPACE)
self.SetSizer(sizer)
self.Layout()
self.Fit()
wx.CallAfter(self.DoRefresh)
def DoRefresh(self):
"""
wxBug: On Windows XP when using a multiline notebook the default page doesn't get
drawn, but it works when using a single line notebook.
"""
self.Refresh()
def GetDocManager(self):
"""
Returns the document manager passed to the OptionsDialog constructor.
"""
return self._docManager
def OnOK(self, event):
"""
Calls the OnOK method of all of the OptionDialog's embedded panels
"""
for optionsPanel in self._optionsPanels:
optionsPanel.OnOK(event)
class GeneralOptionsPanel(wx.Panel):
"""
A general options panel that is used in the OptionDialog to configure the
generic properties of a pydocview application, such as "show tips at startup"
and whether to use SDI or MDI for the application.
"""
def __i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -