Updates to doc/view modules and sample apps from ActiveGrid.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33904 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -76,6 +76,10 @@ class Document(wx.EvtHandler):
|
||||
The document class can be used to model an application's file-based data. It
|
||||
is part of the document/view framework supported by wxWindows, and cooperates
|
||||
with the wxView, wxDocTemplate and wxDocManager classes.
|
||||
|
||||
Note this wxPython version also keeps track of the modification date of the
|
||||
document and if it changes on disk outside of the application, we will warn the
|
||||
user before saving to avoid clobbering the file.
|
||||
"""
|
||||
|
||||
|
||||
@@ -86,7 +90,6 @@ class Document(wx.EvtHandler):
|
||||
"""
|
||||
wx.EvtHandler.__init__(self)
|
||||
|
||||
self._documentModified = False
|
||||
self._documentParent = parent
|
||||
self._documentTemplate = None
|
||||
self._commandProcessor = None
|
||||
@@ -97,6 +100,7 @@ class Document(wx.EvtHandler):
|
||||
self._documentFile = None
|
||||
self._documentTypeName = None
|
||||
self._documentModified = False
|
||||
self._documentModificationDate = None
|
||||
self._documentViews = []
|
||||
|
||||
|
||||
@@ -211,6 +215,27 @@ class Document(wx.EvtHandler):
|
||||
self._documentModified = modify
|
||||
|
||||
|
||||
def SetDocumentModificationDate(self, filename=None):
|
||||
"""
|
||||
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)
|
||||
|
||||
|
||||
def GetDocumentModificationDate(self):
|
||||
"""
|
||||
Returns the file's modification date when it was loaded from disk.
|
||||
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.
|
||||
"""
|
||||
return self._documentModificationDate
|
||||
|
||||
|
||||
def GetViews(self):
|
||||
"""
|
||||
Returns the list whose elements are the views on the document.
|
||||
@@ -338,6 +363,24 @@ class Document(wx.EvtHandler):
|
||||
if not self.IsModified(): # and self._savedYet: This was here, but if it is not modified who cares if it hasn't been saved yet?
|
||||
return True
|
||||
|
||||
""" 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")
|
||||
res = wx.MessageBox(_("'%s' has been modified outside of %s. Overwrite '%s' with current changes?") % (self.GetPrintableName(), msgTitle, self.GetPrintableName()),
|
||||
msgTitle,
|
||||
wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION,
|
||||
self.GetDocumentWindow())
|
||||
|
||||
if res == wx.NO:
|
||||
return True
|
||||
elif res == wx.YES:
|
||||
pass
|
||||
else: # elif res == wx.CANCEL:
|
||||
return False
|
||||
|
||||
if not self._documentFile or not self._savedYet:
|
||||
return self.SaveAs()
|
||||
return self.OnSaveDocument(self._documentFile)
|
||||
@@ -434,6 +477,7 @@ class Document(wx.EvtHandler):
|
||||
|
||||
self.SetFilename(filename, True)
|
||||
self.Modify(False)
|
||||
self.SetDocumentModificationDate()
|
||||
self.SetDocumentSaved(True)
|
||||
#if wx.Platform == '__WXMAC__': # Not yet implemented in wxPython
|
||||
# wx.FileName(file).MacSetDefaultTypeAndCreator()
|
||||
@@ -468,6 +512,7 @@ class Document(wx.EvtHandler):
|
||||
|
||||
self.SetFilename(filename, True)
|
||||
self.Modify(False)
|
||||
self.SetDocumentModificationDate()
|
||||
self.SetDocumentSaved(True)
|
||||
self.UpdateAllViews()
|
||||
return True
|
||||
@@ -549,6 +594,25 @@ class Document(wx.EvtHandler):
|
||||
if not self.IsModified():
|
||||
return True
|
||||
|
||||
""" 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")
|
||||
res = wx.MessageBox(_("'%s' has been modified outside of %s. Overwrite '%s' with current changes?") % (self.GetPrintableName(), msgTitle, self.GetPrintableName()),
|
||||
msgTitle,
|
||||
wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION,
|
||||
self.GetDocumentWindow())
|
||||
|
||||
if res == wx.NO:
|
||||
self.Modify(False)
|
||||
return True
|
||||
elif res == wx.YES:
|
||||
return wx.lib.docview.Document.Save(self)
|
||||
else: # elif res == wx.CANCEL:
|
||||
return False
|
||||
|
||||
msgTitle = wx.GetApp().GetAppName()
|
||||
if not msgTitle:
|
||||
msgTitle = _("Warning")
|
||||
|
@@ -121,7 +121,7 @@ class DocFrameMixIn:
|
||||
editMenu.Append(wx.ID_PASTE, _("&Paste\tCtrl+V"), _("Inserts Clipboard contents"))
|
||||
wx.EVT_MENU(self, wx.ID_PASTE, self.ProcessEvent)
|
||||
wx.EVT_UPDATE_UI(self, wx.ID_PASTE, self.ProcessUpdateUIEvent)
|
||||
editMenu.Append(wx.ID_CLEAR, _("Cle&ar"), _("Erases the selection"))
|
||||
editMenu.Append(wx.ID_CLEAR, _("&Delete"), _("Erases the selection"))
|
||||
wx.EVT_MENU(self, wx.ID_CLEAR, self.ProcessEvent)
|
||||
wx.EVT_UPDATE_UI(self, wx.ID_CLEAR, self.ProcessUpdateUIEvent)
|
||||
editMenu.AppendSeparator()
|
||||
@@ -144,9 +144,9 @@ class DocFrameMixIn:
|
||||
|
||||
helpMenu = wx.Menu()
|
||||
helpMenu.Append(wx.ID_ABOUT, _("&About" + " " + wx.GetApp().GetAppName()), _("Displays program information, version number, and copyright"))
|
||||
wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
|
||||
menuBar.Append(helpMenu, _("&Help"))
|
||||
|
||||
wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
|
||||
wx.EVT_UPDATE_UI(self, wx.ID_ABOUT, self.ProcessUpdateUIEvent) # Using ID_ABOUT to update the window menu, the window menu items are not triggering
|
||||
|
||||
if sdi: # TODO: Is this really needed?
|
||||
@@ -301,13 +301,17 @@ class DocMDIParentFrameMixIn:
|
||||
self.CreateEmbeddedWindows(embeddedWindows)
|
||||
self._LayoutFrame()
|
||||
|
||||
if wx.Platform == '__WXMAC__':
|
||||
self.SetMenuBar(menuBar) # wxBug: Have to set the menubar at the very end or the automatic MDI "window" menu doesn't get put in the right place when the services add new menus to the menubar
|
||||
|
||||
wx.GetApp().SetTopWindow(self) # Need to do this here in case the services are looking for wx.GetApp().GetTopWindow()
|
||||
for service in wx.GetApp().GetServices():
|
||||
service.InstallControls(self, menuBar = menuBar, toolBar = toolBar, statusBar = statusBar)
|
||||
if hasattr(service, "ShowWindow"):
|
||||
service.ShowWindow() # instantiate service windows for correct positioning, we'll hide/show them later based on user preference
|
||||
|
||||
self.SetMenuBar(menuBar) # wxBug: Have to set the menubar at the very end or the automatic MDI "window" menu doesn't get put in the right place when the services add new menus to the menubar
|
||||
if wx.Platform != '__WXMAC__':
|
||||
self.SetMenuBar(menuBar) # wxBug: Have to set the menubar at the very end or the automatic MDI "window" menu doesn't get put in the right place when the services add new menus to the menubar
|
||||
|
||||
|
||||
def ProcessEvent(self, event):
|
||||
@@ -1359,7 +1363,7 @@ class OptionsDialog(wx.Dialog):
|
||||
Initializes the options dialog with a notebook page that contains new
|
||||
instances of the passed optionsPanelClasses.
|
||||
"""
|
||||
wx.Dialog.__init__(self, parent, -1, _("Options"), size = (310, 400))
|
||||
wx.Dialog.__init__(self, parent, -1, _("Options"), size = (570, 365))
|
||||
|
||||
self._optionsPanels = []
|
||||
self._docManager = docManager
|
||||
@@ -1369,7 +1373,7 @@ class OptionsDialog(wx.Dialog):
|
||||
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
optionsNotebook = wx.Notebook(self, -1, size = (310, 375))
|
||||
optionsNotebook = wx.Notebook(self, -1, size = (560, 325))
|
||||
sizer.Add(optionsNotebook, 0, wx.ALL | wx.EXPAND, SPACE)
|
||||
for optionsPanelClass in optionsPanelClasses:
|
||||
optionsPanel = optionsPanelClass(optionsNotebook, -1)
|
||||
@@ -1377,7 +1381,8 @@ class OptionsDialog(wx.Dialog):
|
||||
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()
|
||||
if wx.Platform != '__WXMAC__' or len(optionsPanelClasses) < 6: # wxBug: Notebook tabs are truncated and user can't get to them on the Mac
|
||||
self.Fit()
|
||||
wx.CallAfter(self.DoRefresh)
|
||||
|
||||
|
||||
@@ -2885,7 +2890,6 @@ class WindowMenuService(DocService):
|
||||
# File generated by encode_bitmaps.py
|
||||
#----------------------------------------------------------------------------
|
||||
from wx import ImageFromStream, BitmapFromImage
|
||||
from wx import EmptyIcon
|
||||
import cStringIO
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@@ -3110,14 +3114,13 @@ def getRedoImage():
|
||||
|
||||
def getBlankData():
|
||||
return \
|
||||
"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
|
||||
\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00\
|
||||
\x85IDATX\x85\xed\x97\xc9\n\xc0 \x0cD3\xda\xff\xffcMo\x96Z\xc4\xa5\x91\x14:9\
|
||||
\x8a\xe8\xcb\xd3\xb8\x00!\x8ag\x04\xd7\xd9E\xe4\xa8\x1b4'}3 B\xc4L\x7fs\x03\
|
||||
\xb3\t<\x0c\x94\x81tN\x04p%\xae9\xe9\xa8\x89m{`\xd4\x84\xfd\x12\xa8\x16{#\
|
||||
\x10\xdb\xab\xa0\x07a\x0e\x00\xe0\xb6\x1fz\x10\xdf;\x07V\xa3U5\xb5\x8d:\xdc\
|
||||
\r\x10\x80\x00\x04 \x00\x01\x08@\x80\xe6{\xa0w\x8f[\x85\xbb\x01\xfc\xfeoH\
|
||||
\x80\x13>\xf9(3zH\x1e\xfb\x00\x00\x00\x00IEND\xaeB`\x82"
|
||||
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
|
||||
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
|
||||
\x00\x00]IDAT8\x8d\xed\x931\x0e\xc00\x08\x03m\x92\xff\xff8q\x87\xb6C\x11\x89\
|
||||
\xa8X:\xd4\x13\x03:\x1b\x01\xa45T\xd4\xefBsh\xd7Hk\xdc\x02\x00@\x8a\x19$\xa1\
|
||||
9\x14A,\x95\xf3\x82G)\xd3\x00\xf24\xf7\x90\x1ev\x07\xee\x1e\xf4:\xc1J?\xe0\
|
||||
\x0b\x80\xc7\x1d\xf8\x1dg\xc4\xea7\x96G8\x00\xa8\x91\x19(\x85#P\x7f\x00\x00\
|
||||
\x00\x00IEND\xaeB`\x82'
|
||||
|
||||
|
||||
def getBlankBitmap():
|
||||
@@ -3128,8 +3131,6 @@ def getBlankImage():
|
||||
return ImageFromStream(stream)
|
||||
|
||||
def getBlankIcon():
|
||||
icon = EmptyIcon()
|
||||
icon.CopyFromBitmap(getBlankBitmap())
|
||||
return icon
|
||||
return wx.IconFromBitmap(getBlankBitmap())
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user