"""
- def __init__(self, parent = None):
+ def __init__(self, parent=None):
"""
Constructor. Define your own default constructor to initialize
application-specific data.
return self._savedYet
- def SetDocumentSaved(self, saved = True):
+ def SetDocumentSaved(self, saved=True):
"""
Sets whether the document has been saved. This method has been
added to wxPython and is not in wxWindows.
self._documentModified = modify
- def SetDocumentModificationDate(self, filename=None):
+ def SetDocumentModificationDate(self):
"""
Saves the file's last modification date.
This is used to check if the file has been modified outside of the application.
This method has been added to wxPython and is not in wxWindows.
"""
- if not filename:
- filename = self.GetFilename()
- self._documentModificationDate = os.path.getmtime(filename)
- print "debug print, file: %s set modification date to %s" % (filename, self._documentModificationDate)
+ self._documentModificationDate = os.path.getmtime(self.GetFilename())
def GetDocumentModificationDate(self):
""" check for file modification outside of application """
if os.path.exists(self.GetFilename()) and os.path.getmtime(self.GetFilename()) != self.GetDocumentModificationDate():
- print "debug print, File %s: new mod date %s, original mod date %s" % (self.GetFilename(), os.path.getmtime(self.GetFilename()), self.GetDocumentModificationDate())
msgTitle = wx.GetApp().GetAppName()
if not msgTitle:
msgTitle = _("Application")
fileObject = file(filename, 'w')
self.SaveObject(fileObject)
+ fileObject.close()
if backupFilename:
os.remove(backupFilename)
if backupFilename:
os.remove(filename)
os.rename(backupFilename, filename)
+ self.SetDocumentModificationDate()
wx.MessageBox("Could not save '%s'. %s" % (FileNameFromPath(filename), sys.exc_value),
msgTitle,
""" check for file modification outside of application """
if os.path.exists(self.GetFilename()) and os.path.getmtime(self.GetFilename()) != self.GetDocumentModificationDate():
- print "debug print, File %s: new mod date %s, original mod date %s" % (self.GetFilename(), os.path.getmtime(self.GetFilename()), self.GetDocumentModificationDate())
msgTitle = wx.GetApp().GetAppName()
if not msgTitle:
msgTitle = _("Warning")
self._viewTypeName = name
- def Close(self, deleteWindow = True):
+ def Close(self, deleteWindow=True):
"""
Closes the view by calling OnClose. If deleteWindow is true, this
function should delete the window associated with the view.
return False
- def Activate(self, activate = True):
+ def Activate(self, activate=True):
"""
Call this from your view frame's OnActivate member to tell the
framework which view is currently active. If your windowing system
self.GetDocumentManager().ActivateView(self, activate)
- def OnClose(self, deleteWindow = True):
+ def OnClose(self, deleteWindow=True):
"""
Implements closing behaviour. The default implementation calls
wxDocument.Close to close the associated document. Does not delete the
"""
- def __init__(self, manager, description, filter, dir, ext, docTypeName, viewTypeName, docType, viewType, flags = DEFAULT_TEMPLATE_FLAGS, icon = None):
+ def __init__(self, manager, description, filter, dir, ext, docTypeName, viewTypeName, docType, viewType, flags=DEFAULT_TEMPLATE_FLAGS, icon=None):
"""
Constructor. Create instances dynamically near the start of your
application after creating a wxDocManager instance, and before doing
classes.
"""
- def __init__(self, flags = DEFAULT_DOCMAN_FLAGS, initialize = True):
+ def __init__(self, flags=DEFAULT_DOCMAN_FLAGS, initialize=True):
"""
Constructor. Create a document manager instance dynamically near the
start of your application before doing any document or view operations.
return self._flags
- def CloseDocument(self, doc, force = True):
+ def CloseDocument(self, doc, force=True):
"""
Closes the specified document.
"""
return False
- def CloseDocuments(self, force = True):
+ def CloseDocuments(self, force=True):
"""
Closes all currently opened documents.
"""
return True
- def Clear(self, force = True):
+ def Clear(self, force=True):
"""
Closes all currently opened document by callling CloseDocuments and
clears the document manager's templates.
"""
return self.CloseDocuments(force = False)
-
+
def OnFileNew(self, event):
"""
Creates a new document and reads in the selected file.
return False
- def CreateDocument(self, path, flags = 0):
+ def CreateDocument(self, path, flags=0):
"""
Creates a new document in a manner determined by the flags parameter,
which can be:
if self.GetFlags() & DOC_OPEN_ONCE:
for document in self._docs:
if document.GetFilename() == path:
+ """ check for file modification outside of application """
+ if os.path.exists(path) and os.path.getmtime(path) != document.GetDocumentModificationDate():
+ msgTitle = wx.GetApp().GetAppName()
+ if not msgTitle:
+ msgTitle = _("Warning")
+ shortName = document.GetPrintableName()
+ res = wx.MessageBox(_("'%s' has been modified outside of %s. Reload '%s' from file system?") % (shortName, msgTitle, shortName),
+ msgTitle,
+ wx.YES_NO | wx.ICON_QUESTION,
+ self.FindSuitableParent())
+ if res == wx.YES:
+ if not self.CloseDocument(document, False):
+ wx.MessageBox(_("Couldn't reload '%s'. Unable to close current '%s'.") % (shortName, shortName))
+ return None
+ return self.CreateDocument(path, flags)
+ elif res == wx.NO: # don't ask again
+ document.SetDocumentModificationDate()
+
firstView = document.GetFirstView()
if firstView and firstView.GetFrame():
firstView.GetFrame().SetFocus() # Not in wxWindows code but useful nonetheless
return None
- def CreateView(self, document, flags = 0):
+ def CreateView(self, document, flags=0):
"""
Creates a new view for the given document. If more than one view is
allowed for the document (by virtue of multiple templates mentioning
self._fileHistory.Save(config)
- def FileHistoryAddFilesToMenu(self, menu = None):
+ def FileHistoryAddFilesToMenu(self, menu=None):
"""
Appends the files in the history list, to all menus managed by the
file history object.
pass
- def SelectDocumentType(self, temps, sort = False):
+ def SelectDocumentType(self, temps, sort=False):
"""
Returns a document template by asking the user (if there is more than
one template). This function is used in wxDocManager.CreateDocument.
return templates[res]
- def SelectViewType(self, temps, sort = False):
+ def SelectViewType(self, temps, sort=False):
"""
Returns a document template by asking the user (if there is more than one template), displaying a list of valid views. This function is used in wxDocManager::CreateView. The dialog normally will not appear because the array of templates only contains those relevant to the document in question, and often there will only be one such.
"""
self._docs.remove(doc)
- def ActivateView(self, view, activate = True, deleting = False):
+ def ActivateView(self, view, activate=True, deleting=False):
"""
Sets the current view.
"""
classes.
"""
- def __init__(self, manager, frame, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "frame"):
+ def __init__(self, manager, frame, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="frame"):
"""
Constructor. Note that the event table must be rebuilt for the
frame since the EvtHandler is not virtual.
"""
- def __init__(self, doc, view, frame, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "frame"):
+ def __init__(self, doc, view, frame, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="frame"):
"""
Constructor. Note that the event table must be rebuilt for the
frame since the EvtHandler is not virtual.
"""
- def __init__(self, manager, frame, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "frame"):
+ def __init__(self, manager, frame, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="frame"):
"""
Constructor. Note that the event table must be rebuilt for the
frame since the EvtHandler is not virtual.
"""
- def __init__(self, doc, view, frame, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "frame"):
+ def __init__(self, doc, view, frame, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="frame"):
"""
Constructor. Note that the event table must be rebuilt for the
frame since the EvtHandler is not virtual.
"""
- def __init__(self, view, title = "Printout"):
+ def __init__(self, view, title="Printout"):
"""
Constructor.
"""
"""
- def __init__(self, maxCommands = -1):
+ def __init__(self, maxCommands=-1):
"""
Constructor. maxCommands may be set to a positive integer to limit
the number of commands stored to it, otherwise (and by default) the
return self._GetCurrentRedoCommand() != None
- def Submit(self, command, storeIt = True):
+ def Submit(self, command, storeIt=True):
"""
Submits a new command to the command processor. The command processor
calls wxCommand::Do to execute the command; if it succeeds, the