From 6f1a3f9c1a056e5ae063f020d38a5f40cc5e85ef Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 19 May 2005 00:21:49 +0000 Subject: [PATCH] More updates to the docview library modules and sample apps from the ActiveGrid folks. Their sample IDE is now able to integrate with Subversion. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34158 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/docs/CHANGES.txt | 4 + .../ide/activegrid/tool/AboutDialog.py | 1 + .../ide/activegrid/tool/AbstractEditor.py | 27 +- .../ide/activegrid/tool/DebuggerHarness.py | 193 +++-- .../ide/activegrid/tool/DebuggerService.py | 336 +++++--- .../ide/activegrid/tool/FindInDirService.py | 2 +- wxPython/samples/ide/activegrid/tool/IDE.py | 27 +- .../ide/activegrid/tool/OutlineService.py | 1 + .../samples/ide/activegrid/tool/PHPEditor.py | 2 +- .../ide/activegrid/tool/ProjectEditor.py | 43 +- .../ide/activegrid/tool/STCTextEditor.py | 11 +- .../samples/ide/activegrid/tool/SVNService.py | 736 ++++++++++++++++++ .../samples/ide/activegrid/util/__init__.py | 78 +- .../samples/ide/activegrid/util/objutils.py | 93 +++ .../ide/activegrid/util/xmlmarshaller.py | 308 +++----- .../ide/activegrid/util/xmlmarshallertests.py | 183 ----- wxPython/samples/pydocview/PyDocViewDemo.py | 2 +- wxPython/wx/lib/docview.py | 650 ++++++++-------- wxPython/wx/lib/pydocview.py | 120 ++- 19 files changed, 1772 insertions(+), 1045 deletions(-) create mode 100644 wxPython/samples/ide/activegrid/tool/SVNService.py create mode 100644 wxPython/samples/ide/activegrid/util/objutils.py delete mode 100644 wxPython/samples/ide/activegrid/util/xmlmarshallertests.py diff --git a/wxPython/docs/CHANGES.txt b/wxPython/docs/CHANGES.txt index 47344750b7..a9c6434461 100644 --- a/wxPython/docs/CHANGES.txt +++ b/wxPython/docs/CHANGES.txt @@ -98,6 +98,10 @@ optionally specify where the new control point has to be drawn. wxMSW: setting foreground colour for wx.CheckBox now works when using XP themes. +More updates to the docview library modules and sample apps from the +ActiveGrid folks. Their sample IDE is now able to integrate with +Subversion. + diff --git a/wxPython/samples/ide/activegrid/tool/AboutDialog.py b/wxPython/samples/ide/activegrid/tool/AboutDialog.py index ce1e0cdfa5..3a7be9fa74 100644 --- a/wxPython/samples/ide/activegrid/tool/AboutDialog.py +++ b/wxPython/samples/ide/activegrid/tool/AboutDialog.py @@ -28,6 +28,7 @@ licenseData = [ ("wxWidgets", "wxWindows Library License 3", "http://www.wxwidgets.org/manuals/2.5.4/wx_wxlicense.html"), ("pychecker", "MetaSlash - BSD", "http://pychecker.sourceforge.net/COPYRIGHT"), ("process.py", "See file", "http://starship.python.net/~tmick/"), + ("pysvn", "Apache License", "http://pysvn.tigris.org/"), ] if not ACTIVEGRID_BASE_IDE: # add licenses for database connections only if not the base IDE diff --git a/wxPython/samples/ide/activegrid/tool/AbstractEditor.py b/wxPython/samples/ide/activegrid/tool/AbstractEditor.py index 1361b422e8..8369738428 100644 --- a/wxPython/samples/ide/activegrid/tool/AbstractEditor.py +++ b/wxPython/samples/ide/activegrid/tool/AbstractEditor.py @@ -66,13 +66,18 @@ class CanvasView(wx.lib.docview.View): if activate and self._canvas: # In MDI mode just calling set focus doesn't work and in SDI mode using CallAfter causes an endless loop if self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI: - self._canvas.SetFocus() + self.SetFocus() else: - wx.CallAfter(self._canvas.SetFocus) + wx.CallAfter(self.SetFocus) + + + def SetFocus(self): + if self._canvas: + self._canvas.SetFocus() def OnFocus(self, event): - self._canvas.SetFocus() + self.SetFocus() self.FocusColorPropertyShape(True) event.Skip() @@ -82,6 +87,17 @@ class CanvasView(wx.lib.docview.View): event.Skip() + def HasFocus(self): + winWithFocus = wx.Window.FindFocus() + if not winWithFocus: + return False + while winWithFocus: + if winWithFocus == self._canvas: + return True + winWithFocus = winWithFocus.GetParent() + return False + + def OnClose(self, deleteWindow = True): statusC = wx.GetApp().CloseChildDocuments(self.GetDocument()) statusP = wx.lib.docview.View.OnClose(self, deleteWindow = deleteWindow) @@ -528,7 +544,10 @@ class CanvasView(wx.lib.docview.View): # draw new selection if self._propShape and self._propShape in self._diagram.GetShapeList(): - self._propShape.SetBrush(SELECT_BRUSH) + if self.HasFocus(): + self._propShape.SetBrush(SELECT_BRUSH) + else: + self._propShape.SetBrush(INACTIVE_SELECT_BRUSH) if (self._propShape._textColourName in ["BLACK", "WHITE"]): # Would use GetTextColour() but it is broken self._propShape.SetTextColour("WHITE", 0) self._propShape.Draw(dc) diff --git a/wxPython/samples/ide/activegrid/tool/DebuggerHarness.py b/wxPython/samples/ide/activegrid/tool/DebuggerHarness.py index a12b8e579b..19b2fbf597 100644 --- a/wxPython/samples/ide/activegrid/tool/DebuggerHarness.py +++ b/wxPython/samples/ide/activegrid/tool/DebuggerHarness.py @@ -190,6 +190,7 @@ class Adb(bdb.Bdb): def stop_here(self, frame): if( self._userBreak ): + self._userBreak = False return True @@ -446,11 +447,22 @@ class DebuggerHarness(object): item_node.setAttribute('value', wholeStack) item_node.setAttribute('name', str(name)) top_element.appendChild(item_node) + + cantIntro = [types.FunctionType, + types.LambdaType, + types.UnicodeType, + types.StringType, + types.NoneType, + types.IntType, + types.LongType, + types.FloatType, + types.BooleanType] def addAny(self, top_element, name, item, doc, ply): tp = type(item) - if ply < 1: - self.addNode(top_element,name, self.saferepr(item), doc) + + if tp in DebuggerHarness.cantIntro or ply < 1: + self.addNode(top_element,name, item, doc) elif tp is types.TupleType or tp is types.ListType: self.addTupleOrList(top_element, name, item, doc, ply - 1) elif tp is types.DictType or tp is types.DictProxyType: @@ -459,108 +471,95 @@ class DebuggerHarness(object): self.addModule(top_element, name, item, doc, ply -1) elif inspect.isclass(item) or tp is types.InstanceType: self.addClass(top_element, name, item, doc, ply -1) - #elif hasattr(item, '__dict__'): - # self.addDictAttr(top_element, name, item, doc, ply -1) elif hasattr(item, '__dict__'): - self.addDict(top_element, name, item.__dict__, doc, ply -1) + self.addDictAttr(top_element, name, item, doc, ply -1) else: - self.addNode(top_element,name, self.saferepr(item), doc) + self.addNode(top_element,name, item, doc) + + def canIntrospect(self, item): + tp = type(item) + if tp in DebuggerHarness.cantIntro: + return False + elif tp is types.TupleType or tp is types.ListType: + return len(item) > 0 + elif tp is types.DictType or tp is types.DictProxyType: + return len(item) > 0 + elif inspect.ismodule(item): + return True + elif inspect.isclass(item) or tp is types.InstanceType: + if hasattr(item, '__dict__'): + return True + elif hasattr(item, '__name__'): + return True + elif hasattr(item, '__module__'): + return True + elif hasattr(item, '__doc__'): + return True + else: + return False + elif hasattr(item, '__dict__'): + return len(item.__dict__) > 0 + else: + return False + + def addNode(self, parent_node, name, item, document): + item_node = document.createElement("dict_nv_element") + item_node.setAttribute('value', self.saferepr(item)) + item_node.setAttribute('name', str(name)) + introVal = str(self.canIntrospect(item)) + item_node.setAttribute('intro', str(introVal)) + parent_node.appendChild(item_node) + + def addTupleOrList(self, top_node, name, tupple, doc, ply): tupleNode = doc.createElement('tuple') tupleNode.setAttribute('name', str(name)) - tupleNode.setAttribute('value', str(type(tupple))) + tupleNode.setAttribute('value', self.saferepr(tupple)) top_node.appendChild(tupleNode) count = 0 for item in tupple: self.addAny(tupleNode, name +'[' + str(count) + ']',item, doc, ply -1) count += 1 - - def getFrameXML(self, base_frame): - doc = getDOMImplementation().createDocument(None, "stack", None) - top_element = doc.documentElement - - stack = [] - frame = base_frame - while frame is not None: - if((frame.f_code.co_filename.count('DebuggerHarness.py') == 0) or _DEBUG_DEBUGGER): - stack.append(frame) - frame = frame.f_back - stack.reverse() - self.message_frame_dict = {} - for f in stack: - self.addFrame(f,top_element, doc) - return doc.toxml() - - def addFrame(self, frame, root_element, document): - frameNode = document.createElement('frame') - root_element.appendChild(frameNode) - - code = frame.f_code - filename = code.co_filename - frameNode.setAttribute('file', str(filename)) - frameNode.setAttribute('line', str(frame.f_lineno)) - message = self._adb.frame2message(frame) - frameNode.setAttribute('message', message) - #print "Frame: %s %s %s" %(message, frame.f_lineno, filename) - self.message_frame_dict[message] = frame - self.addDict(frameNode, "locals", frame.f_locals, document, 2) - self.addNode(frameNode, "globals", "", document) - - def getRepr(self, varName, globals, locals): - try: - return repr(eval(varName, globals, locals)) - except: - return 'Error: Could not recover value.' - - def addNode(self, parent_node, name, value, document): - item_node = document.createElement("dict_nv_element") - item_node.setAttribute('value', self.saferepr(value)) - item_node.setAttribute('name', str(name)) - parent_node.appendChild(item_node) - def addDictAttr(self, root_node, name, thing, document, ply): dict_node = document.createElement('thing') - root_node.setAttribute('name', name) - root_node.setAttribute('value', str(type(dict)) + " add attr") - self.addDict(root_node, name, thing.__dict__, document, ply) # Not decreminting ply - - def saferepr(self, thing): - try: - return repr(thing) - except: - tp, val, tb = sys.exc_info() - return repr(val) - - def addDict(self, root_node, name, dict, document, ply): - dict_node = document.createElement('dict') dict_node.setAttribute('name', name) - dict_node.setAttribute('value', str(type(dict)) + " add dict") + dict_node.setAttribute('value', self.saferepr(thing)) root_node.appendChild(dict_node) + self.addDict(dict_node, '', thing.__dict__, document, ply) # Not decreminting ply + + def addDict(self, root_node, name, dict, document, ply): + if name != '': + dict_node = document.createElement('dict') + dict_node.setAttribute('name', name) + dict_node.setAttribute('value', self.saferepr(dict)) + root_node.appendChild(dict_node) + else: + dict_node = root_node for key in dict.keys(): strkey = str(key) try: - self.addAny(dict_node, strkey, dict[key], document, ply-1) + value = dict[key] + self.addAny(dict_node, strkey, value, document, ply-1) except: - tp,val,tb=sys.exc_info() if _VERBOSE: + tp,val,tb=sys.exc_info() print "Error recovering key: ", str(key), " from node ", str(name), " Val = ", str(val) traceback.print_exception(tp, val, tb) - self.addAny(dict_node, strkey, "Exception getting " + str(name) + "[" + strkey + "]: " + str(val), document, ply -1) def addClass(self, root_node, name, class_item, document, ply): item_node = document.createElement('class') item_node.setAttribute('name', str(name)) + item_node.setAttribute('value', self.saferepr(class_item)) root_node.appendChild(item_node) try: if hasattr(class_item, '__dict__'): - self.addAny(item_node, '__dict__', class_item.__dict__, document, ply -1) + self.addDict(item_node, '', class_item.__dict__, document, ply -1) except: tp,val,tb=sys.exc_info() if _VERBOSE: traceback.print_exception(tp, val, tb) - self.addAny(item_node, '__dict__', "Exception getting __dict__: " + str(val), document, ply -1) try: if hasattr(class_item, '__name__'): self.addAny(item_node,'__name__',class_item.__name__, document, ply -1) @@ -568,7 +567,6 @@ class DebuggerHarness(object): tp,val,tb=sys.exc_info() if _VERBOSE: traceback.print_exception(tp, val, tb) - self.addAny(item_node,'__name__',"Exception getting class.__name__: " + val, document, ply -1) try: if hasattr(class_item, '__module__'): self.addAny(item_node, '__module__', class_item.__module__, document, ply -1) @@ -576,7 +574,6 @@ class DebuggerHarness(object): tp,val,tb=sys.exc_info() if _VERBOSE: traceback.print_exception(tp, val, tb) - self.addAny(item_node, '__module__', "Exception getting class.__module__: " + val, document, ply -1) try: if hasattr(class_item, '__doc__'): self.addAny(item_node, '__doc__', class_item.__doc__, document, ply -1) @@ -584,7 +581,6 @@ class DebuggerHarness(object): tp,val,tb=sys.exc_info() if _VERBOSE: traceback.print_exception(tp, val, tb) - self.addAny(item_node, '__doc__', "Exception getting class.__doc__: " + val, document, ply -1) try: if hasattr(class_item, '__bases__'): self.addAny(item_node, '__bases__', class_item.__bases__, document, ply -1) @@ -592,11 +588,11 @@ class DebuggerHarness(object): tp,val,tb=sys.exc_info() if _VERBOSE: traceback.print_exception(tp, val, tb) - self.addAny(item_node, '__bases__', "Exception getting class.__bases__: " + val, document, ply -1) def addModule(self, root_node, name, module_item, document, ply): item_node = document.createElement('module') item_node.setAttribute('name', str(name)) + item_node.setAttribute('value', self.saferepr(module_item)) root_node.appendChild(item_node) try: if hasattr(module_item, '__file__'): @@ -609,6 +605,54 @@ class DebuggerHarness(object): except: pass + + + def getFrameXML(self, base_frame): + doc = getDOMImplementation().createDocument(None, "stack", None) + top_element = doc.documentElement + + stack = [] + frame = base_frame + while frame is not None: + if((frame.f_code.co_filename.count('DebuggerHarness.py') == 0) or _DEBUG_DEBUGGER): + stack.append(frame) + frame = frame.f_back + stack.reverse() + self.message_frame_dict = {} + for f in stack: + self.addFrame(f,top_element, doc) + return doc.toxml() + + def addFrame(self, frame, root_element, document): + frameNode = document.createElement('frame') + root_element.appendChild(frameNode) + + code = frame.f_code + filename = code.co_filename + frameNode.setAttribute('file', str(filename)) + frameNode.setAttribute('line', str(frame.f_lineno)) + message = self._adb.frame2message(frame) + frameNode.setAttribute('message', message) + #print "Frame: %s %s %s" %(message, frame.f_lineno, filename) + self.message_frame_dict[message] = frame + self.addDict(frameNode, "locals", frame.f_locals, document, 2) + self.addNode(frameNode, "globals", frame.f_globals, document) + + def getRepr(self, varName, globals, locals): + try: + return repr(eval(varName, globals, locals)) + except: + return 'Error: Could not recover value.' + + + def saferepr(self, thing): + try: + return repr(thing) + except: + tp, val, tb = sys.exc_info() + traceback.print_exception(tp, val, tb) + return repr(val) + # The debugger calls this method when it reaches a breakpoint. def interaction(self, message, frame, info): if _VERBOSE: @@ -683,6 +727,7 @@ if __name__ == '__main__': try: harness = DebuggerHarness() harness.run() + harness.do_exit(kill=True) except SystemExit: print "Exiting..." except: diff --git a/wxPython/samples/ide/activegrid/tool/DebuggerService.py b/wxPython/samples/ide/activegrid/tool/DebuggerService.py index ae8f60cfe6..79e78e0466 100644 --- a/wxPython/samples/ide/activegrid/tool/DebuggerService.py +++ b/wxPython/samples/ide/activegrid/tool/DebuggerService.py @@ -103,6 +103,8 @@ class OutputReaderThread(threading.Thread): self._keepGoing = False start = time.time() output = "" + except TypeError: + pass except: tp, val, tb = sys.exc_info() print "Exception in OutputReaderThread.run():", tp, val @@ -163,6 +165,7 @@ class Executor: self._stdOutReader = None self._stdErrReader = None self._process = None + DebuggerService.executors.append(self) def OutCall(self, text): evt = UpdateTextEvent(value = text) @@ -197,6 +200,7 @@ class Executor: self._stdOutReader.AskToStop() if(self._stdErrReader != None): self._stdErrReader.AskToStop() + DebuggerService.executors.remove(self) class RunCommandUI(wx.Panel): @@ -371,10 +375,10 @@ class DebugCommandUI(wx.Panel): def ShutdownAllDebuggers(): for debugger in DebugCommandUI.debuggers: - debugger.StopExecution() + debugger.StopExecution(None) ShutdownAllDebuggers = staticmethod(ShutdownAllDebuggers) - + def GetAvailablePort(): for index in range( 0, len(DebugCommandUI.debuggerPortList)): port = DebugCommandUI.debuggerPortList[index] @@ -428,7 +432,6 @@ class DebugCommandUI(wx.Panel): self._parentNoteBook = parent self._command = command - self._textCtrl = None self._service = service self._executor = None self.STEP_ID = wx.NewId() @@ -490,18 +493,10 @@ class DebugCommandUI(wx.Panel): tb.AddSimpleTool(self.CLEAR_ID, clear_bmp, _("Clear output pane")) wx.EVT_TOOL(self, self.CLEAR_ID, self.OnClearOutput) - tb.Realize() self.framesTab = None self.DisableWhileDebuggerRunning() - self._notebook = wx.Notebook(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.LB_DEFAULT, "Debugger") - sizer.Add(self._notebook, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) - self.consoleTab = self.MakeConsoleTab(self._notebook, wx.NewId(), None) - self.framesTab = self.MakeFramesTab(self._notebook, wx.NewId(), None) - self.breakPointsTab = self.MakeBreakPointsTab(self._notebook, wx.NewId(), None) - self._notebook.AddPage(self.consoleTab, "Output") - self._notebook.AddPage(self.framesTab, "Frames") - self._notebook.AddPage(self.breakPointsTab, "Break Points") - + self.framesTab = self.MakeFramesUI(self, wx.NewId(), None) + sizer.Add(self.framesTab, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) self._statusBar = wx.StatusBar( self, -1) self._statusBar.SetFieldsCount(1) sizer.Add(self._statusBar, 0, wx.EXPAND |wx.ALIGN_LEFT|wx.ALL, 1) @@ -509,6 +504,7 @@ class DebugCommandUI(wx.Panel): self.SetStatusText("Starting debug...") self.SetSizer(sizer) + tb.Realize() sizer.Fit(self) config = wx.ConfigBase_Get() self._debuggerHost = self._guiHost = config.Read("DebuggerHostName", DEFAULT_HOST) @@ -550,14 +546,12 @@ class DebugCommandUI(wx.Panel): def BreakPointChange(self): if not self._stopped: self._callback.pushBreakpoints() - self.breakPointsTab.PopulateBPList() + self.framesTab.PopulateBPList() def __del__(self): if self in DebugCommandUI.debuggers: DebugCommandUI.debuggers.remove(self) - def SwitchToOutputTab(self): - self._notebook.SetSelection(0) def DisableWhileDebuggerRunning(self): self._tb.EnableTool(self.STEP_ID, False) @@ -573,7 +567,6 @@ class DebugCommandUI(wx.Panel): openDoc.GetFirstView().GetCtrl().ClearCurrentLineMarkers() if self.framesTab: self.framesTab.ClearWhileRunning() - #wx.GetApp().ProcessPendingEvents() #Yield(True) def EnableWhileDebuggerStopped(self): self._tb.EnableTool(self.STEP_ID, True) @@ -583,8 +576,6 @@ class DebugCommandUI(wx.Panel): if _WATCHES_ON: self._tb.EnableTool(self.ADD_WATCH_ID, True) self._tb.EnableTool(self.BREAK_INTO_DEBUGGER_ID, False) - #if _WINDOWS: - # wx.GetApp().GetTopWindow().RequestUserAttention() def ExecutorFinished(self): if _VERBOSE: print "In ExectorFinished" @@ -687,62 +678,27 @@ class DebugCommandUI(wx.Panel): DebugCommandUI.debuggers.remove(self) index = self._parentNoteBook.GetSelection() self._parentNoteBook.GetPage(index).Show(False) - self._parentNoteBook.RemovePage(index) - - def GetConsoleTextControl(self): - return self._textCtrl - - def OnClearOutput(self, event): - self._textCtrl.SetReadOnly(False) - self._textCtrl.ClearAll() - self._textCtrl.SetReadOnly(True) + self._parentNoteBook.RemovePage(index) def OnAddWatch(self, event): if self.framesTab: self.framesTab.OnWatch(event) - - def MakeConsoleTab(self, parent, id, debugger): - panel = wx.Panel(parent, id) - sizer = wx.BoxSizer(wx.HORIZONTAL) - self._textCtrl = STCTextEditor.TextCtrl(panel, wx.NewId()) - sizer.Add(self._textCtrl, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) - self._textCtrl.SetViewLineNumbers(False) - self._textCtrl.SetReadOnly(True) - if wx.Platform == '__WXMSW__': - font = "Courier New" - else: - font = "Courier" - self._textCtrl.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = font)) - self._textCtrl.SetFontColor(wx.BLACK) - self._textCtrl.StyleClearAll() - panel.SetSizer(sizer) - sizer.Fit(panel) - - return panel - - def MakeFramesTab(self, parent, id, debugger): + + def MakeFramesUI(self, parent, id, debugger): panel = FramesUI(parent, id, self) return panel - def MakeBreakPointsTab(self, parent, id, debugger): - panel = BreakpointsUI(parent, id, self) - return panel - def AppendText(self, event): - self._textCtrl.SetReadOnly(False) - self._textCtrl.AddText(event.value) - self._textCtrl.ScrollToLine(self._textCtrl.GetLineCount()) - self._textCtrl.SetReadOnly(True) + self.framesTab.AppendText(event.value) def AppendErrorText(self, event): - self._textCtrl.SetReadOnly(False) - self._textCtrl.SetFontColor(wx.RED) - self._textCtrl.StyleClearAll() - self._textCtrl.AddText(event.value) - self._textCtrl.ScrollToLine(self._textCtrl.GetLineCount()) - self._textCtrl.SetFontColor(wx.BLACK) - self._textCtrl.StyleClearAll() - self._textCtrl.SetReadOnly(True) + self.framesTab.AppendErrorText(event.value) + + def OnClearOutput(self, event): + self.framesTab.ClearOutput() + + def SwitchToOutputTab(self): + self.framesTab.SwitchToOutputTab() class BreakpointsUI(wx.Panel): def __init__(self, parent, id, ui): @@ -753,7 +709,6 @@ class BreakpointsUI(wx.Panel): self.Bind(wx.EVT_MENU, self.ClearBreakPoint, id=self.clearBPID) self.syncLineID = wx.NewId() self.Bind(wx.EVT_MENU, self.SyncBPLine, id=self.syncLineID) - sizer = wx.BoxSizer(wx.VERTICAL) p1 = self self._bpListCtrl = wx.ListCtrl(p1, -1, pos=wx.DefaultPosition, size=(1000,1000), style=wx.LC_REPORT) @@ -767,6 +722,11 @@ class BreakpointsUI(wx.Panel): self._bpListCtrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnListRightClick) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.ListItemSelected, self._bpListCtrl) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.ListItemDeselected, self._bpListCtrl) + + def OnLeftDoubleClick(event): + self.SyncBPLine(event) + + wx.EVT_LEFT_DCLICK(self._bpListCtrl, OnLeftDoubleClick) self.PopulateBPList() @@ -903,25 +863,24 @@ class FramesUI(wx.SplitterWindow): def __init__(self, parent, id, ui): wx.SplitterWindow.__init__(self, parent, id, style = wx.SP_3D) self._ui = ui - sizer = wx.BoxSizer(wx.VERTICAL) self._p1 = p1 = wx.ScrolledWindow(self, -1) - p1.Bind(wx.EVT_SIZE, self.OnSize) - self._framesListCtrl = wx.ListCtrl(p1, -1, pos=wx.DefaultPosition, size=(250,150), style=wx.LC_REPORT) - sizer.Add(self._framesListCtrl, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) - self._framesListCtrl.InsertColumn(0, "Frame") - self._framesListCtrl.SetColumnWidth(0, 250) - self._framesListCtrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnListRightClick) - self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.ListItemSelected, self._framesListCtrl) - self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.ListItemDeselected, self._framesListCtrl) + sizer = wx.BoxSizer(wx.HORIZONTAL) + framesLabel = wx.StaticText(self, -1, "Stack Frame:") + sizer.Add(framesLabel, 0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.LEFT, border=2) + + self._framesChoiceCtrl = wx.Choice(p1, -1, choices=[" "]) + sizer.Add(self._framesChoiceCtrl, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) + self._framesChoiceCtrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnListRightClick) + self.Bind(wx.EVT_CHOICE, self.ListItemSelected, self._framesChoiceCtrl) sizer2 = wx.BoxSizer(wx.VERTICAL) - self._p2 = p2 = wx.ScrolledWindow(self, -1) - p2.Bind(wx.EVT_SIZE, self.OnSize) - - self._treeCtrl = wx.gizmos.TreeListCtrl(p2, -1, size=(530,250), style=wx.TR_DEFAULT_STYLE| wx.TR_FULL_ROW_HIGHLIGHT) + p1.SetSizer(sizer2) + + self._treeCtrl = wx.gizmos.TreeListCtrl(p1, -1, style=wx.TR_DEFAULT_STYLE| wx.TR_FULL_ROW_HIGHLIGHT) self._treeCtrl.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnRightClick) - sizer2.Add(self._framesListCtrl, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) + sizer2.Add(sizer, 0, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) + sizer2.Add(self._treeCtrl,1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) tree = self._treeCtrl tree.AddColumn("Thing") tree.AddColumn("Value") @@ -930,11 +889,80 @@ class FramesUI(wx.SplitterWindow): tree.SetColumnWidth(1, 355) self._root = tree.AddRoot("Frame") tree.SetItemText(self._root, "", 1) + tree.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.IntrospectCallback) + + self._p2 = p2 = wx.Window(self, -1) + sizer3 = wx.BoxSizer(wx.HORIZONTAL) + p2.SetSizer(sizer3) + p2.Bind(wx.EVT_SIZE, self.OnSize) + self._notebook = wx.Notebook(p2, -1, size=(20,20)) + self._notebook.Hide() + sizer3.Add(self._notebook, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 1) + self.consoleTab = self.MakeConsoleTab(self._notebook, wx.NewId()) + #self.inspectConsoleTab = self.MakeInspectConsoleTab(self._notebook, wx.NewId()) + self.breakPointsTab = self.MakeBreakPointsTab(self._notebook, wx.NewId()) + self._notebook.AddPage(self.consoleTab, "Output") + #self._notebook.AddPage(self.inspectConsoleTab, "Interact") + self._notebook.AddPage(self.breakPointsTab, "Break Points") self.SetMinimumPaneSize(20) - self.SplitVertically(p1, p2, 250) + self.SplitVertically(p1, p2, 550) self.currentItem = None - self.Layout() + self._notebook.Show(True) + + def PopulateBPList(self): + self.breakPointsTab.PopulateBPList() + + def OnSize(self, event): + self._notebook.SetSize(self._p2.GetSize()) + + def MakeConsoleTab(self, parent, id): + panel = wx.Panel(parent, id) + sizer = wx.BoxSizer(wx.HORIZONTAL) + self._textCtrl = STCTextEditor.TextCtrl(panel, wx.NewId()) + sizer.Add(self._textCtrl, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 2) + self._textCtrl.SetViewLineNumbers(False) + self._textCtrl.SetReadOnly(True) + if wx.Platform == '__WXMSW__': + font = "Courier New" + else: + font = "Courier" + self._textCtrl.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = font)) + self._textCtrl.SetFontColor(wx.BLACK) + self._textCtrl.StyleClearAll() + panel.SetSizer(sizer) + #sizer.Fit(panel) + + return panel + + def MakeInspectConsoleTab(self, parent, id): + def OnEnterPressed(event): + print "Enter text was %s" % event.GetString() + def OnText(event): + print "Command was %s" % event.GetString() + + panel = wx.Panel(parent, id) + try: + sizer = wx.BoxSizer(wx.HORIZONTAL) + self._ictextCtrl = wx.TextCtrl(panel, wx.NewId(), style=wx.TE_MULTILINE|wx.TE_RICH|wx.HSCROLL) + sizer.Add(self._ictextCtrl, 1, wx.ALIGN_LEFT|wx.ALL|wx.EXPAND, 2) + self._ictextCtrl.Bind(wx.EVT_TEXT_ENTER, OnEnterPressed) + self._ictextCtrl.Bind(wx.EVT_TEXT, OnText) + if wx.Platform == '__WXMSW__': + font = "Courier New" + else: + font = "Courier" + self._ictextCtrl.SetDefaultStyle(wx.TextAttr(font=wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = font))) + panel.SetSizer(sizer) + except: + tp, val, tb = sys.exc_info() + traceback.print_exception(tp, val, tb) + + return panel + + def MakeBreakPointsTab(self, parent, id): + panel = BreakpointsUI(parent, id, self._ui) + return panel def OnRightClick(self, event): #Refactor this... @@ -944,13 +972,6 @@ class FramesUI(wx.SplitterWindow): if not _WATCHES_ON and watchOnly: return menu = wx.Menu() - if not watchOnly: - if not hasattr(self, "introspectID"): - self.introspectID = wx.NewId() - self.Bind(wx.EVT_MENU, self.OnIntrospect, id=self.introspectID) - item = wx.MenuItem(menu, self.introspectID, "Attempt Introspection") - menu.AppendItem(item) - menu.AppendSeparator() if _WATCHES_ON: if not hasattr(self, "watchID"): self.watchID = wx.NewId() @@ -1016,13 +1037,13 @@ class FramesUI(wx.SplitterWindow): wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) try: - list = self._framesListCtrl + list = self._framesChoiceCtrl frameNode = self._stack[int(self.currentItem)] message = frameNode.getAttribute("message") binType = self._ui._callback._debuggerServer.attempt_introspection(message, self._parentChain) xmldoc = bz2.decompress(binType.data) - domDoc = parseString(xmldoc) + #wx.MessageBox(xmldoc, "result of introspection") nodeList = domDoc.getElementsByTagName('replacement') replacementNode = nodeList.item(0) if len(replacementNode.childNodes): @@ -1030,6 +1051,7 @@ class FramesUI(wx.SplitterWindow): tree = self._treeCtrl parent = tree.GetItemParent(self._introspectItem) treeNode = self.AppendSubTreeFromNode(thingToWalk, thingToWalk.getAttribute('name'), parent, insertBefore=self._introspectItem) + self._treeCtrl.Expand(treeNode) tree.Delete(self._introspectItem) except: tp,val,tb = sys.exc_info() @@ -1037,16 +1059,15 @@ class FramesUI(wx.SplitterWindow): wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) - def OnSize(self, event): - self._treeCtrl.SetSize(self._p2.GetSize()) - w,h = self._p1.GetClientSizeTuple() - self._framesListCtrl.SetDimensions(0, 0, w, h) - def ClearWhileRunning(self): - list = self._framesListCtrl - list.DeleteAllItems() - tree = self._treeCtrl - tree.Hide() + list = self._framesChoiceCtrl + list.Clear() + list.Enable(False) + tree = self._treeCtrl + root = self._root + tree.DeleteChildren(root) + + #tree.Hide() def OnListRightClick(self, event): if not hasattr(self, "syncFrameID"): @@ -1059,7 +1080,7 @@ class FramesUI(wx.SplitterWindow): menu.Destroy() def OnSyncFrame(self, event): - list = self._framesListCtrl + list = self._framesChoiceCtrl frameNode = self._stack[int(self.currentItem)] file = frameNode.getAttribute("file") line = frameNode.getAttribute("line") @@ -1069,18 +1090,24 @@ class FramesUI(wx.SplitterWindow): wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) try: domDoc = parseString(framesXML) - list = self._framesListCtrl - list.DeleteAllItems() + list = self._framesChoiceCtrl + list.Clear() self._stack = [] nodeList = domDoc.getElementsByTagName('frame') frame_count = -1 for index in range(0, nodeList.length): frameNode = nodeList.item(index) message = frameNode.getAttribute("message") - list.InsertStringItem(index, message) + list.Append(message) self._stack.append(frameNode) frame_count += 1 - list.Select(frame_count) + index = len(self._stack) - 1 + list.SetSelection(index) + node = self._stack[index] + self.currentItem = index + self.PopulateTreeFromFrameNode(node) + self.OnSyncFrame(None) + self._p1.FitInside() frameNode = nodeList.item(index) file = frameNode.getAttribute("file") @@ -1092,19 +1119,23 @@ class FramesUI(wx.SplitterWindow): wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) - def ListItemDeselected(self, event): - pass def ListItemSelected(self, event): - self.currentItem = event.m_itemIndex - frameNode = self._stack[int(self.currentItem)] - self.PopulateTreeFromFrameNode(frameNode) - # Temporarily doing this to test out automatically swicting to source line. - self.OnSyncFrame(None) - + message = event.GetString() + index = 0 + for node in self._stack: + if node.getAttribute("message") == message: + self.currentItem = index + self.PopulateTreeFromFrameNode(node) + self.OnSyncFrame(None) + return + index = index + 1 + def PopulateTreeFromFrameNode(self, frameNode): + list = self._framesChoiceCtrl + list.Enable(True) tree = self._treeCtrl - tree.Show(True) + #tree.Show(True) root = self._root tree.DeleteChildren(root) children = frameNode.childNodes @@ -1117,6 +1148,19 @@ class FramesUI(wx.SplitterWindow): tree.Expand(root) tree.Expand(firstChild) self._p2.FitInside() + + def IntrospectCallback(self, event): + tree = self._treeCtrl + item = event.GetItem() + if _VERBOSE: + print "In introspectCallback item is %s, pydata is %s" % (event.GetItem(), tree.GetPyData(item)) + if tree.GetPyData(item) != "Introspect": + event.Skip() + return + self._introspectItem = item + self._parentChain = self.GetItemChain(item) + self.OnIntrospect(event) + event.Skip() def AppendSubTreeFromNode(self, node, name, parent, insertBefore=None): tree = self._treeCtrl @@ -1125,7 +1169,12 @@ class FramesUI(wx.SplitterWindow): else: treeNode = tree.AppendItem(parent, name) children = node.childNodes - if children.length == 0: + intro = node.getAttribute('intro') + + if intro == "True": + tree.SetItemHasChildren(treeNode, True) + tree.SetPyData(treeNode, "Introspect") + if node.getAttribute("value"): tree.SetItemText(treeNode, self.StripOuterSingleQuotes(node.getAttribute("value")), 1) for index in range(0, children.length): subNode = children.item(index) @@ -1136,15 +1185,23 @@ class FramesUI(wx.SplitterWindow): value = self.StripOuterSingleQuotes(subNode.getAttribute("value")) n = tree.AppendItem(treeNode, name) tree.SetItemText(n, value, 1) + intro = subNode.getAttribute('intro') + if intro == "True": + tree.SetItemHasChildren(n, True) + tree.SetPyData(n, "Introspect") + return treeNode def StripOuterSingleQuotes(self, string): if string.startswith("'") and string.endswith("'"): - return string[1:-1] - elif type(string) == types.UnicodeType: - return string[1:-1] + retval = string[1:-1] + elif string.startswith("\"") and string.endswith("\""): + retval = string[1:-1] else: - return string + retval = string + if retval.startswith("u'") and retval.endswith("'"): + retval = retval[1:] + return retval def HasChildren(self, node): try: @@ -1152,7 +1209,31 @@ class FramesUI(wx.SplitterWindow): except: tp,val,tb=sys.exc_info() return False - + + def AppendText(self, text): + self._textCtrl.SetReadOnly(False) + self._textCtrl.AddText(text) + self._textCtrl.ScrollToLine(self._textCtrl.GetLineCount()) + self._textCtrl.SetReadOnly(True) + + def AppendErrorText(self, text): + self._textCtrl.SetReadOnly(False) + self._textCtrl.SetFontColor(wx.RED) + self._textCtrl.StyleClearAll() + self._textCtrl.AddText(text) + self._textCtrl.ScrollToLine(self._textCtrl.GetLineCount()) + self._textCtrl.SetFontColor(wx.BLACK) + self._textCtrl.StyleClearAll() + self._textCtrl.SetReadOnly(True) + + def ClearOutput(self, event): + self._textCtrl.SetReadOnly(False) + self._textCtrl.ClearAll() + self._textCtrl.SetReadOnly(True) + + def SwitchToOutputTab(self): + self._notebook.SetSelection(0) + class DebuggerView(Service.ServiceView): #---------------------------------------------------------------------------- @@ -1417,6 +1498,7 @@ class DebuggerCallback: if _VERBOSE: print "+"*40 class DebuggerService(Service.Service): + executors = [] #---------------------------------------------------------------------------- # Constants @@ -1427,6 +1509,12 @@ class DebuggerService(Service.Service): DEBUG_ID = wx.NewId() DEBUG_WEBSERVER_ID = wx.NewId() + def KillAllRunningProcesses(): + execs = DebuggerService.executors + for executor in execs: + executor.DoStopExecution() + KillAllRunningProcesses = staticmethod(KillAllRunningProcesses) + def ComparePaths(first, second): one = DebuggerService.ExpandPath(first) two = DebuggerService.ExpandPath(second) @@ -1614,6 +1702,14 @@ class DebuggerService(Service.Service): pass def OnDebugWebServer(self, event): + if _WINDOWS and not _PYWIN32_INSTALLED: + wx.MessageBox(_("Python for Windows extensions (pywin32) is required to debug on Windows machines. Please go to http://sourceforge.net/projects/pywin32/, download and install pywin32.")) + return + if not Executor.GetPythonExecutablePath(): + return + if DebugCommandUI.DebuggerRunning(): + wx.MessageBox(_("A debugger is already running. Please shut down the other debugger first."), _("Debugger Running")) + return import WebServerService wsService = wx.GetApp().GetService(WebServerService.WebServerService) fileName, args = wsService.StopAndPrepareToDebug() diff --git a/wxPython/samples/ide/activegrid/tool/FindInDirService.py b/wxPython/samples/ide/activegrid/tool/FindInDirService.py index b52287a4fe..63eea49a13 100644 --- a/wxPython/samples/ide/activegrid/tool/FindInDirService.py +++ b/wxPython/samples/ide/activegrid/tool/FindInDirService.py @@ -103,7 +103,7 @@ class FindInDirService(FindService.FindService): dirCtrl = wx.TextCtrl(frame, -1, config.Read(FIND_MATCHDIR, ""), size=(200,-1)) dirCtrl.SetToolTipString(dirCtrl.GetValue()) lineSizer.Add(dirCtrl, 0, wx.LEFT, HALF_SPACE) - findDirButton = wx.Button(frame, -1, "Browse...") + findDirButton = wx.Button(frame, -1, _("Browse...")) lineSizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE) contentSizer.Add(lineSizer, 0, wx.BOTTOM, SPACE) diff --git a/wxPython/samples/ide/activegrid/tool/IDE.py b/wxPython/samples/ide/activegrid/tool/IDE.py index 995cfbf9e9..7767890fcc 100644 --- a/wxPython/samples/ide/activegrid/tool/IDE.py +++ b/wxPython/samples/ide/activegrid/tool/IDE.py @@ -16,6 +16,8 @@ import wx.lib.pydocview import sys import wx.grid import os.path +import activegrid.util + _ = wx.GetTranslation ACTIVEGRID_BASE_IDE = False @@ -77,7 +79,11 @@ class IDEApplication(wx.lib.pydocview.DocApp): import PHPEditor import wx.lib.ogl as ogl import DebuggerService + import atexit + atexit.register(DebuggerService.DebuggerService.KillAllRunningProcesses) import AboutDialog + import SVNService + if not ACTIVEGRID_BASE_IDE: import DataModelEditor import ProcessModelEditor @@ -87,7 +93,7 @@ class IDEApplication(wx.lib.pydocview.DocApp): import WelcomeService import ViewEditor import PropertyService - + # This creates some pens and brushes that the OGL library uses. # It should be called after the app object has been created, but @@ -287,8 +293,9 @@ class IDEApplication(wx.lib.pydocview.DocApp): deploymentService = self.InstallService(DeploymentService.DeploymentService()) dataModelService = self.InstallService(DataModelEditor.DataModelService()) welcomeService = self.InstallService(WelcomeService.WelcomeService()) - optionsService = self.InstallService(wx.lib.pydocview.DocOptionsService(allowModeChanges=False)) + optionsService = self.InstallService(wx.lib.pydocview.DocOptionsService(supportedModes=wx.lib.docview.DOC_MDI)) aboutService = self.InstallService(wx.lib.pydocview.AboutService(AboutDialog.AboutDialog)) + svnService = self.InstallService(SVNService.SVNService()) if not ACTIVEGRID_BASE_IDE: projectService.AddRunHandler(processModelService) @@ -307,6 +314,7 @@ class IDEApplication(wx.lib.pydocview.DocApp): optionsService.AddOptionsPanel(PHPEditor.PHPOptionsPanel) optionsService.AddOptionsPanel(STCTextEditor.TextOptionsPanel) optionsService.AddOptionsPanel(HtmlEditor.HtmlOptionsPanel) + optionsService.AddOptionsPanel(SVNService.SVNOptionsPanel) filePropertiesService.AddCustomEventHandler(projectService) @@ -326,7 +334,6 @@ class IDEApplication(wx.lib.pydocview.DocApp): propertyService.StartBackgroundTimer() self.SetDefaultIcon(getActiveGridIcon()) - self.SetUseTabbedMDI(True) if not ACTIVEGRID_BASE_IDE: embeddedWindows = wx.lib.pydocview.EMBEDDED_WINDOW_TOPLEFT | wx.lib.pydocview.EMBEDDED_WINDOW_BOTTOMLEFT |wx.lib.pydocview.EMBEDDED_WINDOW_BOTTOM | wx.lib.pydocview.EMBEDDED_WINDOW_RIGHT else: @@ -343,14 +350,18 @@ class IDEApplication(wx.lib.pydocview.DocApp): if not projectService.OpenSavedProjects() and not docManager.GetDocuments() and self.IsSDI(): # Have to open something if it's SDI and there are no projects... projectTemplate.CreateDocument('', wx.lib.docview.DOC_NEW).OnNewDocument() - + + TIPS_FILE_PARTS = ("activegrid", "tool", "data", "tips.txt") + tips_path = activegrid.util.mainModuleDir + for segment in TIPS_FILE_PARTS: + tips_path = os.path.join(tips_path, segment) if not ACTIVEGRID_BASE_IDE: if not welcomeService.RunWelcomeIfFirstTime(): - if os.path.exists("activegrid/tool/data/tips.txt"): - wx.CallAfter(self.ShowTip, docManager.FindSuitableParent(), wx.CreateFileTipProvider("activegrid/tool/data/tips.txt", 0)) + if os.path.exists(tips_path): + wx.CallAfter(self.ShowTip, docManager.FindSuitableParent(), wx.CreateFileTipProvider(tips_path, 0)) else: - if os.path.exists("activegrid/tool/data/tips.txt"): - wx.CallAfter(self.ShowTip, docManager.FindSuitableParent(), wx.CreateFileTipProvider("activegrid/tool/data/tips.txt", 0)) + if os.path.exists(tips_path): + wx.CallAfter(self.ShowTip, docManager.FindSuitableParent(), wx.CreateFileTipProvider(tips_path, 0)) wx.UpdateUIEvent.SetUpdateInterval(200) # Overhead of updating menus was too much. Change to update every 200 milliseconds. diff --git a/wxPython/samples/ide/activegrid/tool/OutlineService.py b/wxPython/samples/ide/activegrid/tool/OutlineService.py index c04f1ecc1f..573327db89 100644 --- a/wxPython/samples/ide/activegrid/tool/OutlineService.py +++ b/wxPython/samples/ide/activegrid/tool/OutlineService.py @@ -84,6 +84,7 @@ class OutlineView(Service.ServiceView): item = self.GetControl().GetSelection() if item: self.GetControl().CallDoSelectCallback(item) + event.Skip() def ResumeActionOnSelect(self): diff --git a/wxPython/samples/ide/activegrid/tool/PHPEditor.py b/wxPython/samples/ide/activegrid/tool/PHPEditor.py index 6faacd4839..fba7b6c029 100644 --- a/wxPython/samples/ide/activegrid/tool/PHPEditor.py +++ b/wxPython/samples/ide/activegrid/tool/PHPEditor.py @@ -153,7 +153,7 @@ class PHPCtrl(CodeEditor.CodeCtrl): def __init__(self, parent, ID = -1, style = wx.NO_FULL_REPAINT_ON_RESIZE): CodeEditor.CodeCtrl.__init__(self, parent, ID, style) - self.SetLexer(wx.stc.STC_LEX_HTML) + self.SetLexer(wx.stc.STC_LEX_PHP) self.SetStyleBits(7) self.SetKeyWords(4, string.join(PHPKEYWORDS)) self.SetProperty("fold.html", "1") diff --git a/wxPython/samples/ide/activegrid/tool/ProjectEditor.py b/wxPython/samples/ide/activegrid/tool/ProjectEditor.py index 46b5889670..56331050ec 100644 --- a/wxPython/samples/ide/activegrid/tool/ProjectEditor.py +++ b/wxPython/samples/ide/activegrid/tool/ProjectEditor.py @@ -23,9 +23,11 @@ import sys import activegrid.util.xmlmarshaller import UICommon import Wizard +import SVNService from IDE import ACTIVEGRID_BASE_IDE if not ACTIVEGRID_BASE_IDE: import ProcessModelEditor +from SVNService import SVN_INSTALLED _ = wx.GetTranslation @@ -127,6 +129,8 @@ class ProjectDocument(wx.lib.docview.Document): for path in paths: if path.startswith(curPath): path = "." + path[curPathLen:] # use relative path + if os.sep != '/': + path = path.replace(os.sep, '/', -1) # always save out with '/' as path separator for cross-platform compatibility. else: pass # use absolute path newFilePaths.append(path) @@ -909,7 +913,16 @@ class ProjectView(wx.lib.docview.View): def GetSelectedFile(self): for item in self._treeCtrl.GetSelections(): return self._GetItemFile(item) + + def GetSelectedFiles(self): + filenames = [] + for item in self._treeCtrl.GetSelections(): + filename = self._GetItemFile(item) + if filename and filename not in filenames: + filenames.append(filename) + return filenames + def AddProjectToView(self, document): rootItem = self._treeCtrl.GetRootItem() @@ -927,6 +940,17 @@ class ProjectView(wx.lib.docview.View): document.GetCommandProcessor().SetEditMenu(wx.GetApp().GetEditMenu(self._GetParentFrame())) + def HasFocus(self): + winWithFocus = wx.Window.FindFocus() + if not winWithFocus: + return False + while winWithFocus: + if winWithFocus == self._treeCtrl: + return True + winWithFocus = winWithFocus.GetParent() + return False + + #---------------------------------------------------------------------------- # Control events #---------------------------------------------------------------------------- @@ -980,7 +1004,7 @@ class ProjectView(wx.lib.docview.View): def OnAddDirToProject(self, event): - frame = wx.Dialog(None, -1, _("Add All Files from Directory to Project"), size= (320,200)) + frame = wx.Dialog(None, -1, _("Add Directory Files to Project"), size= (320,200)) contentSizer = wx.BoxSizer(wx.VERTICAL) flexGridSizer = wx.FlexGridSizer(cols = 2, vgap=HALF_SPACE, hgap=HALF_SPACE) @@ -989,7 +1013,7 @@ class ProjectView(wx.lib.docview.View): dirCtrl = wx.TextCtrl(frame, -1, os.path.dirname(self.GetDocument().GetFilename()), size=(250,-1)) dirCtrl.SetToolTipString(dirCtrl.GetValue()) lineSizer.Add(dirCtrl, 1, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) - findDirButton = wx.Button(frame, -1, "Browse...") + findDirButton = wx.Button(frame, -1, _("Browse...")) lineSizer.Add(findDirButton, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, HALF_SPACE) flexGridSizer.Add(lineSizer, 1, wx.EXPAND) @@ -1178,7 +1202,10 @@ class ProjectView(wx.lib.docview.View): else: # Project context itemIDs = [wx.ID_CLOSE, wx.ID_SAVE, wx.ID_SAVEAS, None] menuBar = self._GetParentFrame().GetMenuBar() - itemIDs = itemIDs + [ProjectService.ADD_FILES_TO_PROJECT_ID, ProjectService.ADD_ALL_FILES_TO_PROJECT_ID, ProjectService.REMOVE_FROM_PROJECT, None, wx.ID_UNDO, wx.ID_REDO, None, wx.ID_CUT, wx.ID_COPY, wx.ID_PASTE, wx.ID_CLEAR, None, wx.ID_SELECTALL, ProjectService.RENAME_ID, ProjectService.DELETE_FILE_ID, None, wx.lib.pydocview.FilePropertiesService.PROPERTIES_ID] + itemIDs = itemIDs + [ProjectService.ADD_FILES_TO_PROJECT_ID, ProjectService.ADD_ALL_FILES_TO_PROJECT_ID, ProjectService.REMOVE_FROM_PROJECT] + if SVN_INSTALLED: + itemIDs = itemIDs + [None, SVNService.SVNService.SVN_UPDATE_ID, SVNService.SVNService.SVN_CHECKIN_ID, SVNService.SVNService.SVN_REVERT_ID] + itemIDs = itemIDs + [None, wx.ID_UNDO, wx.ID_REDO, None, wx.ID_CUT, wx.ID_COPY, wx.ID_PASTE, wx.ID_CLEAR, None, wx.ID_SELECTALL, ProjectService.RENAME_ID, ProjectService.DELETE_FILE_ID, None, wx.lib.pydocview.FilePropertiesService.PROPERTIES_ID] for itemID in itemIDs: if not itemID: menu.AppendSeparator() @@ -1384,8 +1411,9 @@ class ProjectView(wx.lib.docview.View): findFile.Destroy() if newpath: # update Project Model with new location - self.GetDocument().RemoveFile(filepath) - self.GetDocument().AddFile(newpath) + project = self._GetItemProject(item) + project.RemoveFile(filepath) + project.AddFile(newpath) filepath = newpath doc = self.GetDocumentManager().CreateDocument(filepath, wx.lib.docview.DOC_SILENT) @@ -1614,9 +1642,8 @@ class ProjectPropertiesDialog(wx.Dialog): sizer.Add(notebook, 0, wx.ALL | wx.EXPAND, SPACE) sizer.Add(self.CreateButtonSizer(wx.OK), 0, wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, HALF_SPACE) - sizer.Fit(self) - self.SetDimensions(-1, -1, 310, -1, wx.SIZE_USE_EXISTING) self.SetSizer(sizer) + sizer.Fit(self) self.Layout() @@ -1742,7 +1769,7 @@ class ProjectService(Service.Service): wx.EVT_MENU(frame, ProjectService.ADD_FILES_TO_PROJECT_ID, frame.ProcessEvent) wx.EVT_UPDATE_UI(frame, ProjectService.ADD_FILES_TO_PROJECT_ID, frame.ProcessUpdateUIEvent) if not menuBar.FindItemById(ProjectService.ADD_ALL_FILES_TO_PROJECT_ID): - projectMenu.Append(ProjectService.ADD_ALL_FILES_TO_PROJECT_ID, _("Add All Files to Project..."), _("Adds a directory's documents to the current project")) + projectMenu.Append(ProjectService.ADD_ALL_FILES_TO_PROJECT_ID, _("Add Directory Files to Project..."), _("Adds a directory's documents to the current project")) wx.EVT_MENU(frame, ProjectService.ADD_ALL_FILES_TO_PROJECT_ID, frame.ProcessEvent) wx.EVT_UPDATE_UI(frame, ProjectService.ADD_ALL_FILES_TO_PROJECT_ID, frame.ProcessUpdateUIEvent) if not menuBar.FindItemById(ProjectService.ADD_CURRENT_FILE_TO_PROJECT_ID): diff --git a/wxPython/samples/ide/activegrid/tool/STCTextEditor.py b/wxPython/samples/ide/activegrid/tool/STCTextEditor.py index 8d27a19d24..113721029a 100644 --- a/wxPython/samples/ide/activegrid/tool/STCTextEditor.py +++ b/wxPython/samples/ide/activegrid/tool/STCTextEditor.py @@ -194,10 +194,15 @@ class TextView(wx.lib.docview.View): if activate and self.GetCtrl(): # In MDI mode just calling set focus doesn't work and in SDI mode using CallAfter causes an endless loop if self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI: - self.GetCtrl().SetFocus() + self.SetFocus() else: - wx.CallAfter(self.GetCtrl().SetFocus) - + wx.CallAfter(self.SetFocus) + + + def SetFocus(self): + if self.GetCtrl(): + self.GetCtrl().SetFocus() + def OnClose(self, deleteWindow = True): if not wx.lib.docview.View.OnClose(self, deleteWindow): diff --git a/wxPython/samples/ide/activegrid/tool/SVNService.py b/wxPython/samples/ide/activegrid/tool/SVNService.py new file mode 100644 index 0000000000..97206c5d9f --- /dev/null +++ b/wxPython/samples/ide/activegrid/tool/SVNService.py @@ -0,0 +1,736 @@ +#---------------------------------------------------------------------------- +# Name: SVNService.py +# Purpose: Subversion Service for pydocview +# +# Author: Morgan Hua +# +# Created: 5/13/05 +# CVS-ID: $Id$ +# Copyright: (c) 2005 ActiveGrid, Inc. +# License: wxWindows License +#---------------------------------------------------------------------------- + +import wx +import os.path +import ProjectEditor +import MessageService + +import sys # for errors +import traceback # for errors + +try: + import pysvn # python-subversion integration + SVN_INSTALLED = True +except ImportError: + SVN_INSTALLED = False + +_ = wx.GetTranslation + + +#---------------------------------------------------------------------------- +# Constants +#---------------------------------------------------------------------------- +SVN_CONFIG_DIR = "SVNConfigDir" +SVN_REPOSITORY_URL = "SVNRepositoryURL" + +SPACE = 10 +HALF_SPACE = 5 + + +#---------------------------------------------------------------------------- +# Classes +#---------------------------------------------------------------------------- + +class SVNService(wx.lib.pydocview.DocService): + SVN_UPDATE_ID = wx.NewId() + SVN_CHECKIN_ID = wx.NewId() + SVN_CHECKOUT_ID = wx.NewId() + SVN_REVERT_ID = wx.NewId() + SVN_ADD_ID = wx.NewId() + SVN_DELETE_ID = wx.NewId() + SVN_COMMAND_LIST = [SVN_UPDATE_ID, SVN_CHECKIN_ID, SVN_CHECKOUT_ID, SVN_REVERT_ID, SVN_ADD_ID, SVN_DELETE_ID] + + + def __init__(self): + self._defaultURL = "svn://" + + global SVN_INSTALLED + if SVN_INSTALLED: + config = wx.ConfigBase_Get() + configDir = config.Read(SVN_CONFIG_DIR, "") + + self._client = pysvn.Client(configDir) + try: + self._defaultURL = self._client.info('.').url + except: + pass + self._client.callback_cancel = self.IfCancel + self._client.callback_notify = self.UpdateStatus + self._client.callback_get_log_message = self.GetLogMessage + self._client.callback_get_login = self.GetLogin + self._client.callback_ssl_server_trust_prompt = self.GetSSLServerTrust + self._client.callback_ssl_client_cert_password_prompt = self.SSLClientPassword + self._client.callback_ssl_client_cert_prompt = self.SSLClientCert + self._client.callback_ssl_server_prompt = self.SSLServerPrompt + + #---------------------------------------------------------------------------- + # pysvn.Client() Callback Methods + #---------------------------------------------------------------------------- + + def IfCancel(self): + """ return True if user wants to cancel current command """ + return False + + + def UpdateStatus(self, eventDict): + messageService = wx.GetApp().GetService(MessageService.MessageService) + messageService.ShowWindow() + + view = messageService.GetView() + view.AddLines(_("%s %s\n") % (eventDict['action'], eventDict['path'])) + + + def GetLogMessage(self): + dlg = wx.TextEntryDialog(wx.GetApp().GetTopWindow(), + _("Comment"), + _("SVN Log Message")) + + if dlg.ShowModal() == wx.ID_OK: + retcode = True + message = dlg.GetValue() + else: + retcode = False + message = _("Cancel Action") + + dlg.Destroy() + + return retcode, message + + + def GetLogin(self, realm, username, maySave): + dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SVN Login")) + + sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5) + sizer.Add(wx.StaticText(dlg, -1, _("Username:")), 0, wx.ALIGN_CENTER_VERTICAL) + usernameTxt = wx.TextCtrl(dlg, -1, username, size = (200, -1)) + sizer.Add(usernameTxt, 0, wx.ALIGN_CENTER_VERTICAL) + sizer.Add(wx.StaticText(dlg, -1, _("Password:")), 0, wx.ALIGN_CENTER_VERTICAL) + passwordTxt = wx.TextCtrl(dlg, -1, size=(200, -1), style=wx.TE_PASSWORD) + sizer.Add(passwordTxt, 0, wx.ALIGN_CENTER_VERTICAL) + + savePasswordCheckbox = wx.CheckBox(dlg, -1, _("Remember Username and Password")) + if not maySave: + savePasswordCheckbox.Enable(False) + + buttonSizer = wx.BoxSizer(wx.HORIZONTAL) + okBtn = wx.Button(dlg, wx.ID_OK) + okBtn.SetDefault() + buttonSizer.Add(okBtn, 0, wx.RIGHT, HALF_SPACE) + buttonSizer.Add(wx.Button(dlg, wx.ID_CANCEL), 0) + + contentSizer = wx.BoxSizer(wx.VERTICAL) + contentSizer.Add(sizer, 0, wx.LEFT|wx.TOP|wx.RIGHT, SPACE) + contentSizer.Add(savePasswordCheckbox, 0, wx.TOP|wx.LEFT|wx.BOTTOM, SPACE) + contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE) + + dlg.SetSizer(contentSizer) + dlg.Fit() + dlg.Layout() + + if dlg.ShowModal() == wx.ID_OK: + retcode = True + username = usernameTxt.GetValue().strip() + password = passwordTxt.GetValue() + save = savePasswordCheckBox.IsChecked() + else: + retcode = False + username = None + password = None + save = False + + dlg.Destroy() + return retcode, username, password, save + + + def SSLServerPrompt(self): + """ Not implemented, as per pysvn documentation """ + return + + + def GetSSLServerTrust(self, trustDict): + dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SSL Server Certificate")) + + sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5) + for k in ['hostname', 'valid_from', 'valid_to', 'issuer_dname', 'realm']: + if trustDict.has_key(k): + sizer.Add(wx.StaticText(dlg, -1, "%s:" % k), 0, wx.ALIGN_CENTER_VERTICAL) + sizer.Add(wx.StaticText(dlg, -1, "%s" % trustDict[k]), 0, wx.ALIGN_CENTER_VERTICAL) + + box = wx.StaticBoxSizer(wx.StaticBox(dlg, -1, _("Certificate Info")), wx.VERTICAL) + box.Add(sizer, 0, wx.EXPAND) + + certRadio = wx.RadioBox(dlg, -1, _("Certificate"), choices=[_("Accept Always"), _("Accept Once"), _("Reject")], majorDimension=1, style=wx.RA_SPECIFY_COLS) + + buttonSizer = wx.BoxSizer(wx.HORIZONTAL) + okBtn = wx.Button(dlg, wx.ID_OK) + okBtn.SetDefault() + buttonSizer.Add(okBtn, 0, wx.RIGHT, HALF_SPACE) + buttonSizer.Add(wx.Button(dlg, wx.ID_CANCEL), 0) + + contentSizer = wx.BoxSizer(wx.VERTICAL) + contentSizer.Add(box, 0, wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND, SPACE) + contentSizer.Add(certRadio, 0, wx.TOP|wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, SPACE) + contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE) + + dlg.SetSizer(contentSizer) + dlg.Fit() + dlg.Layout() + + # default values for reject + retcode = False + acceptedFailures = 0 + save = False + + if dlg.ShowModal() == wx.ID_OK: + cert = certRadio.GetStringSelection() + if cert == _("Accept Always"): + retcode = True + acceptedFailures = trustDict.get('failures') + save = True + elif cert == _("Accept Once"): + retcode = True + acceptedFailures = trustDict.get('failures') + save = False + + return retcode, acceptedFailures, save + + + def SSLClientPassword(self, realm, maySave): + dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SSL Client Certificate Login")) + + sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5) + sizer.Add(wx.StaticText(dlg, -1, _("Realm:")), 0, wx.ALIGN_CENTER_VERTICAL) + sizer.Add(wx.StaticText(dlg, -1, realm), 0, wx.ALIGN_CENTER_VERTICAL) + sizer.Add(wx.StaticText(dlg, -1, _("Password:")), 0, wx.ALIGN_CENTER_VERTICAL) + passwordTxt = wx.TextCtrl(dlg, -1, size=(200, -1), style=wx.TE_PASSWORD) + sizer.Add(passwordTxt, 0, wx.ALIGN_CENTER_VERTICAL) + + savePasswordCheckbox = wx.CheckBox(dlg, -1, _("Remember Password")) + if not maySave: + savePasswordCheckbox.Enable(False) + + buttonSizer = wx.BoxSizer(wx.HORIZONTAL) + okBtn = wx.Button(dlg, wx.ID_OK) + okBtn.SetDefault() + buttonSizer.Add(okBtn, 0, wx.RIGHT, HALF_SPACE) + buttonSizer.Add(wx.Button(dlg, wx.ID_CANCEL), 0) + + contentSizer = wx.BoxSizer(wx.VERTICAL) + contentSizer.Add(sizer, 0, wx.LEFT|wx.TOP|wx.RIGHT, SPACE) + contentSizer.Add(savePasswordCheckbox, 0, wx.TOP|wx.LEFT|wx.BOTTOM, SPACE) + contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE) + + dlg.SetSizer(contentSizer) + dlg.Fit() + dlg.Layout() + + if dlg.ShowModal() == wx.ID_OK: + retcode = True + password = passwordTxt.GetValue() + save = savePasswordCheckBox.IsChecked() + else: + retcode = False + password = None + save = False + + dlg.Destroy() + return retcode, password, save + + + def SSLClientCert(self): + dlg = wx.FileDialog(wx.GetApp().GetTopWindow(), + message="Choose certificate", defaultDir=os.getcwd(), + style=wx.OPEN|wx.CHANGE_DIR + ) + + if dlg.ShowModal() == wx.ID_OK: + retcode = True + certfile = dlg.GetPath() + else: + retcode = False + certfile = None + + dlg.Destroy() + return retcode, certfile + + + + #---------------------------------------------------------------------------- + # Service Methods + #---------------------------------------------------------------------------- + + def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None): + menu = menuBar.GetMenu(menuBar.FindMenu(_("Project"))) + + menu.AppendSeparator() + + wx.EVT_MENU(frame, SVNService.SVN_UPDATE_ID, self.ProcessEvent) + wx.EVT_UPDATE_UI(frame, SVNService.SVN_UPDATE_ID, self.ProcessUpdateUIEvent) + menu.Append(SVNService.SVN_UPDATE_ID, _("SVN Update"), _("Update file from Subversion")) + wx.EVT_MENU(frame, SVNService.SVN_CHECKIN_ID, self.ProcessEvent) + wx.EVT_UPDATE_UI(frame, SVNService.SVN_CHECKIN_ID, self.ProcessUpdateUIEvent) + menu.Append(SVNService.SVN_CHECKIN_ID, _("SVN Commit..."), _("Commit file changes to Subversion")) + wx.EVT_MENU(frame, SVNService.SVN_CHECKOUT_ID, self.ProcessEvent) + wx.EVT_UPDATE_UI(frame, SVNService.SVN_CHECKOUT_ID, self.ProcessUpdateUIEvent) + menu.Append(SVNService.SVN_CHECKOUT_ID, _("SVN Checkout..."), _("Checkout file from Subversion")) + wx.EVT_MENU(frame, SVNService.SVN_REVERT_ID, self.ProcessEvent) + wx.EVT_UPDATE_UI(frame, SVNService.SVN_REVERT_ID, self.ProcessUpdateUIEvent) + menu.Append(SVNService.SVN_REVERT_ID, _("SVN Revert"), _("Revert file from Subversion")) + + menu.AppendSeparator() + + wx.EVT_MENU(frame, SVNService.SVN_ADD_ID, self.ProcessEvent) + wx.EVT_UPDATE_UI(frame, SVNService.SVN_ADD_ID, self.ProcessUpdateUIEvent) + menu.Append(SVNService.SVN_ADD_ID, _("SVN Add"), _("Add file to Subversion")) + wx.EVT_MENU(frame, SVNService.SVN_DELETE_ID, self.ProcessEvent) + wx.EVT_UPDATE_UI(frame, SVNService.SVN_DELETE_ID, self.ProcessUpdateUIEvent) + menu.Append(SVNService.SVN_DELETE_ID, _("SVN Delete"), _("Delete file from Subversion")) + + + def ProcessEvent(self, event): + + id = event.GetId() + + if not SVN_INSTALLED: + if id in SVNService.SVN_COMMAND_LIST: + wx.MessageBox(_("pysvn not found. Please install pysvn"), _("Python Subversion")) + return True + return False + + + if id == SVNService.SVN_UPDATE_ID: + filenames = self.GetCurrentDocuments() + + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) + + messageService = wx.GetApp().GetService(MessageService.MessageService) + messageService.ShowWindow() + + view = messageService.GetView() + view.ClearLines() + view.AddLines(_("SVN Update:\n")) + + for filename in filenames: + view.AddLines("%s\n" % filename) + try: + status = self._client.update(filename) + + if status.number > 0: + view.AddLines(_("Updated to revision %s\n") % status.number) + + openDocs = wx.GetApp().GetDocumentManager().GetDocuments() + for doc in openDocs: + if doc.GetFilename() == filename: + yesNoMsg = wx.MessageDialog(wx.GetApp().GetTopWindow(), + _("Updated file '%s' is currently open. Close it?") % os.path.basename(filename), + _("Close File"), + wx.YES_NO|wx.ICON_QUESTION) + if yesNoMsg.ShowModal() == wx.ID_YES: + doc.DeleteAllViews() + break + else: + view.AddLines(_("Update failed.\n")) + + except pysvn.ClientError, e: + view.AddLines("%s\n" % str(e)) + wx.MessageBox(str(e), _("SVN Update"), wx.OK | wx.ICON_EXCLAMATION) + except: + extype, ex, tb = sys.exc_info() + view.AddLines("Update failed: (%s) %s\n" % (extype, str(ex))) + for line in traceback.format_tb(tb): + view.AddLines(line) + + wx.MessageBox(_("Update failed."), _("SVN Update"), wx.OK | wx.ICON_EXCLAMATION) + + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) + + return True + + elif id == SVNService.SVN_CHECKIN_ID: + filenames = self.GetCurrentDocuments() + + # ask user if dirty files should be saved first + openDocs = wx.GetApp().GetDocumentManager().GetDocuments() + for filename in filenames: + for doc in openDocs: + if doc.GetFilename() == filename and doc.IsModified(): + yesNoMsg = wx.MessageDialog(wx.GetApp().GetTopWindow(), + _("'%s' has unsaved modifications. Save it before commit?") % os.path.basename(filename), + _("SVN Commit"), + wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) + status = yesNoMsg.ShowModal() + if status == wx.ID_YES: + doc.Save() + elif status == wx.ID_NO: + pass + else: # elif status == wx.CANCEL: + return True + break + + shortFilenames = [] + for i, filename in enumerate(filenames): + shortFilename = os.path.basename(filename) + shortFilenames.append(shortFilename) + + dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SVN Commit")) + + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(wx.StaticText(dlg, -1, _("Comment:")), 0, wx.ALIGN_CENTER_VERTICAL) + commentText = wx.TextCtrl(dlg, -1, size=(250,-1), style=wx.TE_MULTILINE) + sizer.Add(commentText, 1, wx.EXPAND|wx.TOP, HALF_SPACE) + + sizer.Add(wx.StaticText(dlg, -1, _("Files:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.TOP, SPACE) + fileList = wx.CheckListBox(dlg, -1, choices = shortFilenames) + for i in range(fileList.GetCount()): + fileList.Check(i, True) + sizer.Add(fileList, 0, wx.EXPAND|wx.TOP, HALF_SPACE) + + buttonSizer = wx.BoxSizer(wx.HORIZONTAL) + okBtn = wx.Button(dlg, wx.ID_OK) + okBtn.SetDefault() + buttonSizer.Add(okBtn, 0, wx.RIGHT, HALF_SPACE) + buttonSizer.Add(wx.Button(dlg, wx.ID_CANCEL), 0) + + contentSizer = wx.BoxSizer(wx.VERTICAL) + contentSizer.Add(sizer, 0, wx.ALL, SPACE) + contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE) + + dlg.SetSizer(contentSizer) + dlg.Fit() + dlg.Layout() + + if dlg.ShowModal() == wx.ID_OK: + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) + + messageService = wx.GetApp().GetService(MessageService.MessageService) + messageService.ShowWindow() + + view = messageService.GetView() + view.ClearLines() + view.AddLines(_("SVN Commit:\n")) + + try: + selFilenames = [] + for i in range(fileList.GetCount()): + if fileList.IsChecked(i): + selFilenames.append(filenames[i]) + view.AddLines("%s\n" % filenames[i]) + + if len(selFilenames): + comment = commentText.GetValue() + status = self._client.checkin(selFilenames, comment) + + if status is None: + view.AddLines(_("Nothing to commit.\n")) + elif status.number > 0: + view.AddLines(_("Committed as revision %s.\n") % status.number) + else: + view.AddLines(_("Commit failed.\n")) + + except pysvn.ClientError, e: + view.AddLines("%s\n" % str(e)) + wx.MessageBox(str(e), _("SVN Commit"), wx.OK | wx.ICON_EXCLAMATION) + except: + extype, ex, tb = sys.exc_info() + view.AddLines("Commit failed: (%s) %s\n" % (extype, str(ex))) + for line in traceback.format_tb(tb): + view.AddLines(line) + wx.MessageBox(_("Commit failed."), _("SVN Commit"), wx.OK | wx.ICON_EXCLAMATION) + + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) + dlg.Destroy() + return True + + elif id == SVNService.SVN_CHECKOUT_ID: + config = wx.ConfigBase_Get() + svnUrl = config.Read(SVN_REPOSITORY_URL, self._defaultURL) + + dlg = wx.Dialog(wx.GetApp().GetTopWindow(), -1, _("SVN Checkout")) + + gridSizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5) + gridSizer.Add(wx.StaticText(dlg, -1, _("Repository URL:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, HALF_SPACE) + svnURLText = wx.TextCtrl(dlg, -1, svnUrl, size = (200, -1)) + svnURLText.SetToolTipString(svnUrl) + gridSizer.Add(svnURLText, 0) + + gridSizer.Add(wx.StaticText(dlg, -1, _("Checkout to dir:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, HALF_SPACE) + localPath = wx.TextCtrl(dlg, -1, size = (200, -1)) + localPath.SetToolTipString(_("Path in local file system where files will be located.")) + findDirButton = wx.Button(dlg, -1, _("Browse...")) + + def OnBrowseButton(event): + dirDlg = wx.DirDialog(wx.GetApp().GetTopWindow(), _("Choose a directory:"), style=wx.DD_DEFAULT_STYLE) + dir = localPath.GetValue() + if len(dir): + dirDlg.SetPath(dir) + if dirDlg.ShowModal() == wx.ID_OK: + localPath.SetValue(dirDlg.GetPath()) + localPath.SetToolTipString(localPath.GetValue()) + localPath.SetInsertionPointEnd() + + dirDlg.Destroy() + wx.EVT_BUTTON(findDirButton, -1, OnBrowseButton) + + sizer = wx.BoxSizer(wx.HORIZONTAL) + sizer.Add(localPath, 1, wx.EXPAND) + sizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE) + gridSizer.Add(sizer, 0) + + buttonSizer = wx.BoxSizer(wx.HORIZONTAL) + okBtn = wx.Button(dlg, wx.ID_OK) + okBtn.SetDefault() + buttonSizer.Add(okBtn, 0, wx.RIGHT, HALF_SPACE) + buttonSizer.Add(wx.Button(dlg, wx.ID_CANCEL), 0) + + contentSizer = wx.BoxSizer(wx.VERTICAL) + contentSizer.Add(gridSizer, 0, wx.ALL, SPACE) + contentSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, SPACE) + + dlg.SetSizer(contentSizer) + dlg.Fit() + dlg.Layout() + + if dlg.ShowModal() == wx.ID_OK: + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) + + messageService = wx.GetApp().GetService(MessageService.MessageService) + messageService.ShowWindow() + + view = messageService.GetView() + view.ClearLines() + view.AddLines(_("SVN Checkout:\n")) + + svnUrl = svnURLText.GetValue() + toLocation = localPath.GetValue() + try: + self._client.checkout(svnUrl, toLocation) + view.AddLines(_("Checkout completed.\n")) + except pysvn.ClientError, e: + view.AddLines(_("Checkout failed. %s\n") % str(e)) + wx.MessageBox(_("Checkout failed. %s") % str(e), _("SVN Checkout"), wx.OK | wx.ICON_EXCLAMATION) + except: + extype, ex, tb = sys.exc_info() + view.AddLines("Checkout failed: (%s) %s\n" % (extype, str(ex))) + for line in traceback.format_tb(tb): + view.AddLines(line) + wx.MessageBox(_("Checkout failed."), _("SVN Checkout"), wx.OK | wx.ICON_EXCLAMATION) + + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) + dlg.Destroy() + return True + + elif id == SVNService.SVN_REVERT_ID: + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) + + filenames = self.GetCurrentDocuments() + + messageService = wx.GetApp().GetService(MessageService.MessageService) + messageService.ShowWindow() + + view = messageService.GetView() + view.ClearLines() + view.AddLines(_("SVN Revert:\n")) + for filename in filenames: + view.AddLines("%s\n" % filename) + + try: + self._client.revert(filenames) + view.AddLines(_("Revert completed.\n")) + + openDocs = wx.GetApp().GetDocumentManager().GetDocuments() + for doc in openDocs[:]: # need to make a copy of the list otherwise ordinality changes as we close the files + if doc.GetFilename() in filenames: + yesNoMsg = wx.MessageDialog(wx.GetApp().GetTopWindow(), + _("Reverted file '%s' is currently open. Close it?") % os.path.basename(doc.GetFilename()), + _("Close File"), + wx.YES_NO|wx.ICON_QUESTION) + if yesNoMsg.ShowModal() == wx.ID_YES: + doc.DeleteAllViews() + + except pysvn.ClientError, e: + view.AddLines("%s\n" % str(e)) + wx.MessageBox(str(e), _("SVN Revert"), wx.OK | wx.ICON_EXCLAMATION) + except: + extype, ex, tb = sys.exc_info() + view.AddLines("Revert failed: (%s) %s\n" % (extype, str(ex))) + for line in traceback.format_tb(tb): + view.AddLines(line) + wx.MessageBox(_("Revert failed."), _("SVN Revert"), wx.OK | wx.ICON_EXCLAMATION) + + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) + return True + + elif id == SVNService.SVN_ADD_ID: + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) + + filenames = self.GetCurrentDocuments() + + messageService = wx.GetApp().GetService(MessageService.MessageService) + messageService.ShowWindow() + + view = messageService.GetView() + view.ClearLines() + view.AddLines(_("SVN Add:\n")) + for filename in filenames: + view.AddLines("%s\n" % filename) + + try: + self._client.add(filenames) + view.AddLines(_("Add completed.\n")) + except pysvn.ClientError, e: + view.AddLines("%s\n" % str(e)) + wx.MessageBox(str(e), _("SVN Add"), wx.OK | wx.ICON_EXCLAMATION) + except: + extype, ex, tb = sys.exc_info() + view.AddLines("Add failed: (%s) %s\n" % (extype, str(ex))) + for line in traceback.format_tb(tb): + view.AddLines(line) + wx.MessageBox(_("Add failed."), _("SVN Add"), wx.OK | wx.ICON_EXCLAMATION) + + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) + return True + + elif id == SVNService.SVN_DELETE_ID: + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) + + filenames = self.GetCurrentDocuments() + + messageService = wx.GetApp().GetService(MessageService.MessageService) + messageService.ShowWindow() + + view = messageService.GetView() + view.ClearLines() + view.AddLines(_("SVN Delete:\n")) + for filename in filenames: + view.AddLines("%s\n" % filename) + + try: + self._client.remove(filenames) + view.AddLines(_("Delete completed.\n")) + except pysvn.ClientError, e: + view.AddLines("%s\n" % str(e)) + wx.MessageBox(str(e), _("SVN Delete"), wx.OK | wx.ICON_EXCLAMATION) + except: + extype, ex, tb = sys.exc_info() + view.AddLines("Delete failed: (%s) %s\n" % (extype, str(ex))) + for line in traceback.format_tb(tb): + view.AddLines(line) + wx.MessageBox(_("Delete failed."), _("SVN Delete"), wx.OK | wx.ICON_EXCLAMATION) + + wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) + return True + + return False + + + def ProcessUpdateUIEvent(self, event): + id = event.GetId() + + if id in [SVNService.SVN_UPDATE_ID, + SVNService.SVN_CHECKIN_ID, + SVNService.SVN_REVERT_ID, + SVNService.SVN_ADD_ID, + SVNService.SVN_DELETE_ID]: + if self.GetCurrentDocuments(): + event.Enable(True) + else: + event.Enable(False) + return True + + elif id == SVNService.SVN_CHECKOUT_ID: + event.Enable(True) + return True + + return False + + + def GetCurrentDocuments(self): + + projectService = wx.GetApp().GetService(ProjectEditor.ProjectService) + if projectService: + projView = projectService.GetView() + + if projView.HasFocus(): + filenames = projView.GetSelectedFiles() + if len(filenames): + return filenames + else: + return None + + doc = wx.GetApp().GetTopWindow().GetDocumentManager().GetCurrentDocument() + if doc: + filenames = [doc.GetFilename()] + else: + filenames = None + + return filenames + + +class SVNOptionsPanel(wx.Panel): + + + def __init__(self, parent, id): + wx.Panel.__init__(self, parent, id) + + config = wx.ConfigBase_Get() + svnService = wx.GetApp().GetService(SVNService) + svnUrl = config.Read(SVN_REPOSITORY_URL, svnService._defaultURL) + configDir = config.Read(SVN_CONFIG_DIR, "") + + borderSizer = wx.BoxSizer(wx.VERTICAL) + sizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5) + + sizer.Add(wx.StaticText(self, -1, _("SVN Config Dir:")), 0, wx.ALIGN_CENTER_VERTICAL) + + self._svnConfigDir = wx.TextCtrl(self, -1, configDir, size = (200, -1)) + if configDir == "": + self._svnConfigDir.SetToolTipString(_("Path Subversion configuration directory.")) + else: + self._svnConfigDir.SetToolTipString(configDir) + + findDirButton = wx.Button(self, -1, _("Browse...")) + + def OnBrowseButton(event): + dirDlg = wx.DirDialog(self, _("Choose a directory:"), style=wx.DD_DEFAULT_STYLE) + dir = self._svnConfigDir.GetValue() + if len(dir): + dirDlg.SetPath(dir) + if dirDlg.ShowModal() == wx.ID_OK: + self._svnConfigDir.SetValue(dirDlg.GetPath()) + self._svnConfigDir.SetToolTipString(self._svnConfigDir.GetValue()) + self._svnConfigDir.SetInsertionPointEnd() + + dirDlg.Destroy() + wx.EVT_BUTTON(findDirButton, -1, OnBrowseButton) + + hsizer = wx.BoxSizer(wx.HORIZONTAL) + hsizer.Add(self._svnConfigDir, 1, wx.EXPAND) + hsizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE) + sizer.Add(hsizer, 0) + + sizer.Add(wx.StaticText(self, -1, _("SVN URL:")), 0, wx.ALIGN_CENTER_VERTICAL) + self._svnURLText = wx.TextCtrl(self, -1, svnUrl, size = (200, -1)) + self._svnURLText.SetToolTipString(svnUrl) + sizer.Add(self._svnURLText, 0) + + borderSizer.Add(sizer, 0, wx.ALL, SPACE) + self.SetSizer(borderSizer) + self.Layout() + parent.AddPage(self, _("SVN")) + + + def OnOK(self, optionsDialog): + config = wx.ConfigBase_Get() + config.Write(SVN_CONFIG_DIR, self._svnConfigDir.GetValue()) + config.Write(SVN_REPOSITORY_URL, self._svnURLText.GetValue()) + diff --git a/wxPython/samples/ide/activegrid/util/__init__.py b/wxPython/samples/ide/activegrid/util/__init__.py index b5380e6b13..edcfb1ca95 100644 --- a/wxPython/samples/ide/activegrid/util/__init__.py +++ b/wxPython/samples/ide/activegrid/util/__init__.py @@ -10,75 +10,19 @@ # License: wxWindows License #---------------------------------------------------------------------------- -import logging -import cStringIO import traceback import sys -import string import os -def classForName(className): - pathList = className.split('.') - moduleName = string.join(pathList[:-1], '.') - code = __import__(moduleName) - for name in pathList[1:]: - code = code.__dict__[name] - return code - -def hasattrignorecase(object, name): - for attr in dir(object): - if attr.lower() == name.lower(): - return True - for attr in dir(object): - if attr.lower() == '_' + name.lower(): - return True - return False - - -def setattrignorecase(object, name, value): - for attr in object.__dict__: - if attr.lower() == name.lower(): - object.__dict__[attr] = value - return -## for attr in dir(object): -## if attr.lower() == '_' + name.lower(): -## object.__dict__[attr] = value -## return - object.__dict__[name] = value - -def getattrignorecase(object, name): - for attr in object.__dict__: - if attr.lower() == name.lower(): - return object.__dict__[attr] -## for attr in dir(object): -## if attr.lower() == '_' + name.lower(): -## return object.__dict__[attr] - return object.__dict__[name] - - -def defaultLoad(fileObject, knownTypes=None): - xml = fileObject.read() - loadedObject = xmlmarshaller.unmarshal(xml, knownTypes=knownTypes) - if hasattr(fileObject, 'name'): - loadedObject.fileName = os.path.abspath(fileObject.name) - loadedObject.initialize() - return loadedObject - -def defaultSave(fileObject, objectToSave, knownTypes=None): - xml = xmlmarshaller.marshal(objectToSave, prettyPrint=True, knownTypes=knownTypes) - fileObject.write(xml) - fileObject.close() - -def clone(objectToClone): - xml = xmlmarshaller.marshal(objectToClone, prettyPrint=True) - clonedObject = xmlmarshaller.unmarshal(xml) - if hasattr(objectToClone, 'fileName'): - clonedObject.fileName = objectToClone.fileName - clonedObject.initialize() - return clonedObject - -def exceptionToString(e): - sio = cStringIO.StringIO() - traceback.print_exception(e.__class__, e, sys.exc_traceback, file=sio) - return sio.getvalue() +def _registerMainModuleDir(): + global mainModuleDir + if sys.executable.find('python') != -1: + utilModuleDir = os.path.dirname(__file__) + if not os.path.isabs(utilModuleDir): + utilModuleDir = os.path.join(os.getcwd(), utilModuleDir) + mainModuleDir = os.path.normpath(os.path.join(utilModuleDir, os.path.join(os.path.pardir, os.path.pardir))) + else: + mainModuleDir = os.path.dirname(sys.executable) + +_registerMainModuleDir() diff --git a/wxPython/samples/ide/activegrid/util/objutils.py b/wxPython/samples/ide/activegrid/util/objutils.py new file mode 100644 index 0000000000..3b2935f1e5 --- /dev/null +++ b/wxPython/samples/ide/activegrid/util/objutils.py @@ -0,0 +1,93 @@ +#---------------------------------------------------------------------------- +# Name: objutils.py +# Purpose: Object Utilities +# +# Author: Alan Mullendore +# +# Created: 5/10/05 +# CVS-ID: $Id$ +# Copyright: (c) 2004-2005 ActiveGrid, Inc. +# License: wxWindows License +#---------------------------------------------------------------------------- + +import logging +import traceback +import sys +import os + +import xmlmarshaller + +def defaultLoad(fileObject, knownTypes=None): + xml = fileObject.read() + loadedObject = xmlmarshaller.unmarshal(xml, knownTypes=knownTypes) + if hasattr(fileObject, 'name'): + loadedObject.fileName = os.path.abspath(fileObject.name) + loadedObject.initialize() + return loadedObject + +def defaultSave(fileObject, objectToSave, knownTypes=None, withEncoding=1, encoding='utf-8'): + xml = xmlmarshaller.marshal(objectToSave, prettyPrint=True, knownTypes=knownTypes, withEncoding=withEncoding, encoding=encoding) + fileObject.write(xml) + fileObject.flush() + +def clone(objectToClone, knownTypes=None, encoding='utf-8'): + xml = xmlmarshaller.marshal(objectToClone, prettyPrint=True, knownTypes=knownTypes, encoding=encoding) + clonedObject = xmlmarshaller.unmarshal(xml, knownTypes=knownTypes) + if hasattr(objectToClone, 'fileName'): + clonedObject.fileName = objectToClone.fileName + try: + clonedObject.initialize() + except AttributeError: + pass + return clonedObject + +def classForName(className): + pathList = className.split('.') + moduleName = '.'.join(pathList[:-1]) + code = __import__(moduleName) + for name in pathList[1:]: + code = code.__dict__[name] + return code + +def hasattrignorecase(object, name): + namelow = name.lower() + for attr in dir(object): + if attr.lower() == namelow: + return True + for attr in dir(object): + if attr.lower() == '_' + namelow: + return True + return False + +def setattrignorecase(object, name, value): + namelow = name.lower() + for attr in object.__dict__: + if attr.lower() == namelow: + object.__dict__[attr] = value + return + object.__dict__[name] = value + +def getattrignorecase(object, name): + namelow = name.lower() + for attr in object.__dict__: + if attr.lower() == namelow: + return object.__dict__[attr] + return object.__dict__[name] + +def hasPropertyValue(obj, attr): + hasProp = False + try: + prop = obj.__class__.__dict__[attr] + if (isinstance(prop, property)): + hasProp = hasattr(obj, attr) + if (hasProp): + # It's a property and it has a value but sometimes we don't want it. + # If there is a _hasattr method execute it and the + # result will tell us whether to include this value + try: + hasProp = obj._hasattr(attr) + except: + pass + except KeyError: + pass + return hasProp diff --git a/wxPython/samples/ide/activegrid/util/xmlmarshaller.py b/wxPython/samples/ide/activegrid/util/xmlmarshaller.py index 9d101efd31..1dcf3699e1 100644 --- a/wxPython/samples/ide/activegrid/util/xmlmarshaller.py +++ b/wxPython/samples/ide/activegrid/util/xmlmarshaller.py @@ -9,14 +9,17 @@ # Copyright: (c) 2004-2005 ActiveGrid, Inc. # License: wxWindows License #---------------------------------------------------------------------------- -from activegrid import util -import inspect +import __builtin__ +import sys from types import * import xml.sax import xml.sax.handler -import __builtin__ from xml.sax import saxutils +import objutils + +MODULE_PATH = "__main__" + ### ToDO remove maxOccurs "unbounded" resolves to -1 hacks after bug 177 is fixed """ @@ -147,52 +150,6 @@ MEMBERS_TO_SKIP = ('__module__', '__doc__', '__xmlname__', '__xmlattributes__', '__xmldefaultnamespace__', '__xmlattrnamespaces__', '__xmlattrgroups__') -#WELL_KNOWN_OBJECTS = { #"xs:element" : "activegrid.model.schema.XsdElement", - #"xs:complexType" : "activegrid.model.schema.XsdComplexType", - #"xs:sequence" : "activegrid.model.schema.XsdSequence", - #"xs:element" : "activegrid.model.schema.XsdElement", - #"xs:key" : "activegrid.model.schema.XsdKey", - #"xs:field" : "activegrid.model.schema.XsdKeyField", - #"xs:keyref" : "activegrid.model.schema.XsdKeyRef", - #"xs:selector" : "activegrid.model.schema.XsdKeySelector", - #"xs:schema" : "activegrid.model.schema.Schema", - #"ag:schemaOptions":"activegrid.model.schema.SchemaOptions", - #"ag:debug" : "activegrid.model.processmodel.DebugOperation", - #"ag:body" : "activegrid.model.processmodel.Body", # alan (start) - #"ag:cssRule" : "activegrid.model.processmodel.CssRule", - #"ag:datasource" : "activegrid.data.dataservice.DataSource", - #"ag:deployment" : "activegrid.server.deployment.Deployment", - #"ag:glue" : "activegrid.model.processmodel.Glue", - #"ag:hr" : "activegrid.model.processmodel.HorizontalRow", - #"ag:image" : "activegrid.model.processmodel.Image", - #"ag:inputs" : "activegrid.model.processmodel.Inputs", - #"ag:label" : "activegrid.model.processmodel.Label", - #"ag:processmodel" : "activegrid.model.processmodel.ProcessModel", - #"ag:processmodelref" : "activegrid.server.deployment.ProcessModelRef", - #"ag:query" : "activegrid.model.processmodel.Query", - #"ag:schemaref" : "activegrid.server.deployment.SchemaRef", - #"ag:set" : "activegrid.model.processmodel.SetOperation", - #"ag:text" : "activegrid.model.processmodel.Text", - #"ag:title" : "activegrid.model.processmodel.Title", - #"ag:view" : "activegrid.model.processmodel.View", - #"bpws:case" : "activegrid.model.processmodel.BPELCase", - #"bpws:invoke" : "activegrid.model.processmodel.BPELInvoke", - #"bpws:otherwise" : "activegrid.model.processmodel.BPELOtherwise", - #"bpws:process" : "activegrid.model.processmodel.BPELProcess", - #"bpws:reply" : "activegrid.model.processmodel.BPELReply", - #"bpws:switch" : "activegrid.model.processmodel.BPELSwitch", - #"bpws:variable" : "activegrid.model.processmodel.BPELVariable", - #"projectmodel" : "activegrid.tool.ProjectEditor.ProjectModel", - #"wsdl:message" : "activegrid.model.processmodel.WSDLMessage", - #"wsdl:part" : "activegrid.model.processmodel.WSDLPart", - #"xforms:group" : "activegrid.model.processmodel.XFormsGroup", - #"xforms:input" : "activegrid.model.processmodel.XFormsInput", - #"xforms:label" : "activegrid.model.processmodel.XFormsLabel", - #"xforms:output" : "activegrid.model.processmodel.XFormsOutput", - #"xforms:secret" : "activegrid.model.processmodel.XFormsSecret", - #"xforms:submit" : "activegrid.model.processmodel.XFormsSubmit"} # alan(end) - - ################################################################################ # # classes and functions @@ -200,45 +157,42 @@ MEMBERS_TO_SKIP = ('__module__', '__doc__', '__xmlname__', '__xmlattributes__', ################################################################################ def _objectfactory(objname, objargs=None, xsname=None): - try: - '''dynamically create an object based on the objname and return - it. look it up in the BASETYPE_ELEMENT_MAP first. - ''' - # split the objname into the typename and module path, - # importing the module if need be. - if not isinstance(objargs, list): - objargs = [objargs] + '''dynamically create an object based on the objname and return + it. look it up in the BASETYPE_ELEMENT_MAP first. + ''' + # split the objname into the typename and module path, + # importing the module if need be. + if not isinstance(objargs, list): + objargs = [objargs] - if (xsname): - try: - objname = knownGlobalTypes[xsname] - except KeyError: - pass + if (xsname): + try: + objname = knownGlobalTypes[xsname] + except KeyError: + pass -## print "[objectfactory] creating an object of type %s and value %s, xsname=%s" % (objname, objargs, xsname) - objtype = objname.split('.')[-1] - pathlist = objname.split('.') - modulename = '.'.join(pathlist[0:-1]) - -## print "[objectfactory] objtype is %s" % objtype -## print "[objectfactory] objargs is %s" % `objargs` - - ## since the bool constructor will turn a string of non-zero - ## length into True, we call it with no argument (yielding a - ## False) if the string contains 'false' - if objtype == 'bool' and objargs[0].lower() == 'false': - objargs = None - -## if objtype == 'str': -## print type(objargs) -## print "string we're unescaping: '%s'" % objargs[0] -## objargs = saxutils.unescape(objargs[0]) - if objtype in ('float', 'int', 'str', 'long'): +## print "[objectfactory] creating an object of type %s and value %s, xsname=%s" % (objname, objargs, xsname) + objtype = objname.split('.')[-1] + pathlist = objname.split('.') + modulename = '.'.join(pathlist[0:-1]) + +## print "[objectfactory] object [%s] %s(%r)" % (objname, objtype, objargs) + if objname == 'bool': + return not objargs[0].lower() == 'false' + elif objname == 'str': # don't strip strings - blanks are significant !!! + if len(objargs) > 0: + return saxutils.unescape(objargs[0]).encode() + else: + return '' + elif objname == 'unicode': # don't strip strings - blanks are significant !!! + if len(objargs) > 0: + return saxutils.unescape(objargs[0]).encode() + else: + return '' + elif objtype in ('float', 'int', 'str', 'long'): objargs = [x.strip() for x in objargs] - if objtype == 'str': - objargs = [saxutils.unescape(x) for x in objargs] - + try: if __builtin__.__dict__.has_key(objname): module = __builtin__ else: @@ -379,7 +333,7 @@ class XMLObjectFactory(xml.sax.ContentHandler): if attrname == "maxOccurs" and attr == "unbounded": attr = "-1" attr = _objectfactory(type, attr) - util.setattrignorecase(obj, _toAttrName(obj, attrname), attr) + objutils.setattrignorecase(obj, _toAttrName(obj, attrname), attr) ## obj.__dict__[_toAttrName(obj, attrname)] = attr # stuff any child attributes meant to be in a sequence via the __xmlflattensequence__ flattenDict = {} @@ -407,9 +361,7 @@ class XMLObjectFactory(xml.sax.ContentHandler): try: ## print "[endElement] obj.__dict__ is: ", obj.__dict__ sequencevalue = obj.__dict__[sequencename] - except AttributeError: - sequencevalue = None - except KeyError: + except (AttributeError, KeyError): sequencevalue = None if sequencevalue == None: sequencevalue = [] @@ -420,7 +372,7 @@ class XMLObjectFactory(xml.sax.ContentHandler): obj.append(child) else: ## print "childname = %s, obj = %s, child = %s" % (childname, repr(obj), repr(child)) - util.setattrignorecase(obj, _toAttrName(obj, childname), child) + objutils.setattrignorecase(obj, _toAttrName(obj, childname), child) obj.__dict__[_toAttrName(obj, childname)] = child if complexType: @@ -474,6 +426,8 @@ def xsdToPythonType(xsdType): def _getXmlValue(pythonValue): if (isinstance(pythonValue, bool)): return str(pythonValue).lower() + elif (isinstance(pythonValue, unicode)): + return pythonValue.encode() else: return str(pythonValue) @@ -488,7 +442,17 @@ def unmarshal(xmlstr, knownTypes=None): return objectfactory.getRootObject() -def marshal(obj, elementName=None, nameSpacePrefix='', nameSpaces=None, prettyPrint=False, indent=0, knownTypes=None): +def marshal(obj, elementName=None, prettyPrint=False, indent=0, knownTypes=None, withEncoding=True, encoding=None): + xmlstr = ''.join(_marshal(obj, elementName, prettyPrint=prettyPrint, indent=indent, knownTypes=knownTypes)) + if withEncoding: + if encoding is None: + return '\n%s' % (sys.getdefaultencoding(), xmlstr) + else: + return '\n%s' % (encoding, xmlstr.encode(encoding)) + else: + return xmlstr + +def _marshal(obj, elementName=None, nameSpacePrefix='', nameSpaces=None, prettyPrint=False, indent=0, knownTypes=None): if prettyPrint or indent: prefix = ' '*indent newline = '\n' @@ -563,7 +527,7 @@ def marshal(obj, elementName=None, nameSpacePrefix='', nameSpaces=None, prettyPr except KeyError: continue ## # But, check and see if it is a property first: -## if (hasPropertyValue(obj, attr)): +## if (objutils.hasPropertyValue(obj, attr)): ## value = getattr(obj, attr) ## else: ## continue @@ -593,7 +557,7 @@ def marshal(obj, elementName=None, nameSpacePrefix='', nameSpaces=None, prettyPr if hasattr(obj, '__xmlattrnamespaces__'): ## print "marshal: found __xmlattrnamespaces__" for nameSpaceKey, nameSpaceAttributes in getattr(obj, '__xmlattrnamespaces__').items(): - if nameSpaceKey == nameSpacePrefix[:-1]: # Don't need to specify attribute namespace if it is the same as it selement + if nameSpaceKey == nameSpacePrefix[:-1]: # Don't need to specify attribute namespace if it is the same as it's element continue if attr in nameSpaceAttributes: attrNameSpacePrefix = nameSpaceKey + ':' @@ -607,95 +571,76 @@ def marshal(obj, elementName=None, nameSpacePrefix='', nameSpaces=None, prettyPr objattrs += ' %s%s="%s"' % (attrNameSpacePrefix, attr, value) ## print "marshal: new objattrs is: ", objattrs - objtype = type(obj) if isinstance(obj, NoneType): - #print "marshal: skipping an element with no type" return '' -# return '%s<%s objtype="None"/>%s' % (prefix, elementName, newline) elif isinstance(obj, bool): - xmlString = '%s<%s objtype="bool">%s%s' % (prefix, elementName, obj, elementName, newline) - #print "marshal: returning a bool element: \n", xmlString - return xmlString + return ['%s<%s objtype="bool">%s%s' % (prefix, elementName, obj, elementName, newline)] elif isinstance(obj, int): - xmlString = '''%s<%s objtype="int">%s%s''' % (prefix, elementName, str(obj), elementName, newline) - #print "marshal: returning a int element: \n", xmlString - return xmlString + return ['''%s<%s objtype="int">%s%s''' % (prefix, elementName, str(obj), elementName, newline)] elif isinstance(obj, long): - xmlString = '%s<%s objtype="long">%s%s' % (prefix, elementName, str(obj), elementName, newline) - #print "marshal: returning a long element: \n", xmlString - return xmlString + return ['%s<%s objtype="long">%s%s' % (prefix, elementName, str(obj), elementName, newline)] elif isinstance(obj, float): - xmlString = '%s<%s objtype="float">%s%s' % (prefix, elementName, str(obj), elementName, newline) - #print "marshal: returning a float element: \n", xmlString - return xmlString + return ['%s<%s objtype="float">%s%s' % (prefix, elementName, str(obj), elementName, newline)] + elif isinstance(obj, unicode): # have to check before basestring - unicode is instance of base string + return ['''%s<%s>%s%s''' % (prefix, elementName, saxutils.escape(obj.encode()), elementName, newline)] elif isinstance(obj, basestring): - xmlString = '''%s<%s>%s%s''' % (prefix, elementName, saxutils.escape(obj), elementName, newline) - #print "marshal: returning a str element: \n", xmlString - return xmlString -## elif isinstance(obj, unicode): -## return '''%s<%s>%s%s''' % (prefix, elementName, obj, elementName, newline) + return ['''%s<%s>%s%s''' % (prefix, elementName, saxutils.escape(obj), elementName, newline)] elif isinstance(obj, list): if len(obj) < 1: - #print "marshal: skipping an empty list" return '' - xmlString = '%s<%s objtype="list">%s' % (prefix, elementName, newline) + xmlString = ['%s<%s objtype="list">%s' % (prefix, elementName, newline)] for item in obj: - xmlString += marshal(item, nameSpaces=nameSpaces, indent=indent+increment, knownTypes=knownTypes) - xmlString += '%s%s' % (prefix, elementName, newline) - #print "marshal: returning a list element: \n", xmlString + xmlString.extend(_marshal(item, nameSpaces=nameSpaces, indent=indent+increment, knownTypes=knownTypes)) + xmlString.append('%s%s' % (prefix, elementName, newline)) return xmlString elif isinstance(obj, tuple): if len(obj) < 1: - #print "marshal: skipping an empty tuple" return '' - xmlString = '%s<%s objtype="list" mutable="false">%s' % (prefix, elementName, newline) + xmlString = ['%s<%s objtype="list" mutable="false">%s' % (prefix, elementName, newline)] for item in obj: - xmlString += marshal(item, nameSpaces=nameSpaces, indent=indent+increment, knownTypes=knownTypes) - xmlString += '%s%s' % (prefix, elementName, newline) - #print "marshal: returning a tuple element: \n", xmlString + xmlString.extend(_marshal(item, nameSpaces=nameSpaces, indent=indent+increment, knownTypes=knownTypes)) + xmlString.append('%s%s' % (prefix, elementName, newline)) return xmlString elif isinstance(obj, dict): - xmlString = '%s<%s objtype="dict">%s' % (prefix, elementName, newline) + xmlString = ['%s<%s objtype="dict">%s' % (prefix, elementName, newline)] subprefix = prefix + ' '*increment subindent = indent + 2*increment for key, val in obj.iteritems(): - xmlString += "%s%s%s%s%s%s%s%s%s%s" \ - % (subprefix, newline, marshal(key, indent=subindent, knownTypes=knownTypes), subprefix, newline, subprefix, newline, marshal(val, nameSpaces=nameSpaces, indent=subindent, knownTypes=knownTypes), subprefix, newline) - xmlString += '%s%s' % (prefix, elementName, newline) - #print "marshal: returning a dict element: \n", xmlString + xmlString.append("%s%s" % (subprefix, newline)) + xmlString.extend(_marshal(key, indent=subindent, knownTypes=knownTypes)) + xmlString.append("%s%s%s%s" % (subprefix, newline, subprefix, newline)) + xmlString.extend(_marshal(val, nameSpaces=nameSpaces, indent=subindent, knownTypes=knownTypes)) + xmlString.append("%s%s" % (subprefix, newline)) + xmlString.append('%s%s' % (prefix, elementName, newline)) return xmlString else: moduleName = obj.__class__.__module__ if (moduleName == "activegrid.model.schema"): -## print "marshal: found an activegrid.model.schema class element" - xmlString = '%s<%s%s%s' % (prefix, elementName, nameSpaceAttrs, objattrs) + xmlString = ['%s<%s%s%s' % (prefix, elementName, nameSpaceAttrs, objattrs)] else: -## print "marshal: found a ", moduleName, " class element" # Only add the objtype if the element tag is unknown to us. try: objname = knownTypes[elementName] -## print "successfully mapped ", elementName, " to known-objtype ", objname - xmlString = '%s<%s%s%s' % (prefix, elementName, nameSpaceAttrs, objattrs) + xmlString = ['%s<%s%s%s' % (prefix, elementName, nameSpaceAttrs, objattrs)] except KeyError: -## print "failed to map elementName: ", elementName, "; knownTypes: ", knownTypes - xmlString = '%s<%s%s%s objtype="%s.%s"' % (prefix, elementName, nameSpaceAttrs, objattrs, moduleName, className) + xmlString = ['%s<%s%s%s objtype="%s.%s"' % (prefix, elementName, nameSpaceAttrs, objattrs, moduleName, className)] ## print "UnknownTypeException: Unknown type (%s.%s) passed to marshaller" % (moduleName, className) - # get the member, value pairs for the object, filtering out - # the types we don't support. -## print "marshal: elementString: \n", xmlString + # get the member, value pairs for the object, filtering out the types we don't support if (elementAdd != None): prefix += increment*' ' indent += increment - xmlMemberString = '' + xmlMemberString = [] if hasattr(obj, '__xmlbody__'): - xmlMemberString = getattr(obj, obj.__xmlbody__) + xmlbody = getattr(obj, obj.__xmlbody__) + if xmlbody != None: + xmlMemberString.append(xmlbody) else: entryList = obj.__dict__.items() ## # Add in properties ## for key in obj.__class__.__dict__.iterkeys(): ## if (key not in members_to_skip and key not in obj.__dict__ -## and hasPropertyValue(obj, key)): +## and objutils.hasPropertyValue(obj, key)): ## value = getattr(obj, key) ## entryList.append((key, value)) entryList.sort() @@ -719,7 +664,7 @@ def marshal(obj, elementName=None, nameSpacePrefix='', nameSpaces=None, prettyPr if (eName != '__nogroup__'): prefix += increment*' ' indent += increment - xmlMemberString += '%s<%s objtype="None">%s' % (prefix, eName, newline) + xmlMemberString.append('%s<%s objtype="None">%s' % (prefix, eName, newline)) for name in eList: value = obj.__dict__[name] ## print " ", name, " = ", value @@ -754,91 +699,38 @@ def marshal(obj, elementName=None, nameSpacePrefix='', nameSpaces=None, prettyPr xmlname = name ## xmlname = name.lower() for seqitem in value: - xmlMemberString += marshal(seqitem, xmlname, subElementNameSpacePrefix, nameSpaces=nameSpaces, indent=indent+increment, knownTypes=knownTypes) + xmlMemberString.extend(_marshal(seqitem, xmlname, subElementNameSpacePrefix, nameSpaces=nameSpaces, indent=indent+increment, knownTypes=knownTypes)) else: if (hasattr(obj, "__xmlrename__") and name in obj.__xmlrename__): xmlname = obj.__xmlrename__[name] else: xmlname = name -## xmlname = name.lower() -## # skip -## if xmlname.startswith('_') and not xmlname.startswith('__'): -## xmlname = xmlname[1:] ## if (indent > 30): ## print "getting pretty deep, xmlname = ", xmlname -## print "marshal: marshalling ", xmlname - xmlMemberString += marshal(value, xmlname, subElementNameSpacePrefix, nameSpaces=nameSpaces, indent=indent+increment, knownTypes=knownTypes) -## print "marshal: back with new xmlMemberString: \n", xmlMemberString + xmlMemberString.extend(_marshal(value, xmlname, subElementNameSpacePrefix, nameSpaces=nameSpaces, indent=indent+increment, knownTypes=knownTypes)) if (eName != '__nogroup__'): ## print "marshal: Completing attrGroup ", eName - xmlMemberString += '%s%s' % (prefix, eName, newline) + xmlMemberString.append('%s%s' % (prefix, eName, newline)) prefix = prefix[:-increment] indent -= increment # if we have nested elements, add them here, otherwise close the element tag immediately. - if xmlMemberString: - xmlString += '>' + xmlMemberString = filter(lambda x: len(x)>0, xmlMemberString) + if len(xmlMemberString) > 0: + xmlString.append('>') if hasattr(obj, '__xmlbody__'): - xmlString += xmlMemberString - xmlString += '%s' % (elementName, newline) + xmlString.extend(xmlMemberString) + xmlString.append('%s' % (elementName, newline)) else: - xmlString += newline + xmlString.append(newline) if (elementAdd != None): - xmlString += '%s<%s>%s' % (prefix, elementAdd, newline) - xmlString += xmlMemberString + xmlString.append('%s<%s>%s' % (prefix, elementAdd, newline)) + xmlString.extend(xmlMemberString) if (elementAdd != None): - xmlString += '%s%s' % (prefix, elementAdd, newline) + xmlString.append('%s%s' % (prefix, elementAdd, newline)) prefix = prefix[:-increment] indent -= increment - xmlString += '%s%s' % (prefix, elementName, newline) + xmlString.append('%s%s' % (prefix, elementName, newline)) else: - xmlString = xmlString + '/>%s' % newline + xmlString.append('/>%s' % newline) return xmlString - -# We don't use this anymore but in case we want to get properties this is how -# you do it -def hasPropertyValue(obj, attr): - hasProp = False - try: - prop = obj.__class__.__dict__[attr] - if (isinstance(prop, property)): - hasProp = hasattr(obj, attr) - if (hasProp): - # It's a property and it has a value but sometimes we don't want it. - # If there is a _hasattr method execute it and the - # result will tell us whether to include this value - try: - hasProp = obj._hasattr(attr) - except: - pass - except KeyError: - pass - return hasProp - -if __name__ == '__main__': - from xmlmarshallertests import Person, marshalledint, marshalledlist - - l = [1, 2, 3] - d = {'1': 1, '2': 2} - outerlist = [l] - xmlstr = marshal(d, "d", prettyPrint=True) - print xmlstr - - person = Person() - person.firstName = "Albert" - person.lastName = "Camus" - person.addressLine1 = "23 Absurd St." - person.city = "Ennui" - person.state = "MO" - person.zip = "54321" - person._phoneNumber = "808-303-2323" - person.favoriteWords = ['angst', 'ennui', 'existence'] - person.weight = 150 - - xmlstring = marshal(person, 'person', prettyPrint=True) - print xmlstring - - obj = unmarshal(marshalledlist) - print "obj has type %s and value %s" % (type(obj), str(obj)) - for item in obj: - print "item: %s" % str(item) diff --git a/wxPython/samples/ide/activegrid/util/xmlmarshallertests.py b/wxPython/samples/ide/activegrid/util/xmlmarshallertests.py deleted file mode 100644 index b02b0fb097..0000000000 --- a/wxPython/samples/ide/activegrid/util/xmlmarshallertests.py +++ /dev/null @@ -1,183 +0,0 @@ -#---------------------------------------------------------------------------- -# Name: xmlmarshallertests.py -# Purpose: -# -# Author: John Spurling -# -# Created: 8/16/04 -# CVS-ID: $Id$ -# Copyright: (c) 2004-2005 ActiveGrid, Inc. -# License: wxWindows License -#---------------------------------------------------------------------------- - -import unittest -import xmlmarshaller -from xmlprettyprinter import xmlprettyprint - -marshalledPersonObject = """ - - Albert - Camus -
23 Absurd St.
- Ennui - MO - 54321 - <_phoneNumber>808-303-2323 - - angst - ennui - existence - - 150 -
-""" - -marshalledint = ''' -23 -''' - -marshalledlist = ''' - - foo - bar - -''' - -## a dummy class taken from the old XmlMarshaller module. -## class Person: -## def __init__(self): -## # These are not necessary but are nice if you want to tailor -## # the Python object <-> XML binding - -## # The xml element name to use for this object, otherwise it -## # will use a fully qualified Python name like __main__.Person -## # which can be ugly. -## self.__xmlname__ = "person" -## self.firstName = None -## self.lastName = None -## self.addressLine1 = None -## self.addressLine2 = None -## self.city = None -## self.state = None -## self.zip = None -## self._phoneNumber = None -## self.favoriteWords = None -## self.weight = None -class Person: - __xmlflattensequence__ = {'asequence': ('the_earth_is_flat',)} - -class XmlMarshallerTestFunctions(unittest.TestCase): - - def setUp(self): - '''common setup code goes here.''' - pass - - def testInt(self): - xml = xmlmarshaller.marshal(1) - print "\n#########################################" - print "# testString test case #" - print "#########################################" - print "marshalled int object:\n" - print xmlprettyprint(xml) - - def testDict(self): - xml = xmlmarshaller.marshal({'one': 1, - 'two': 2, - 'three': 3}) - print "\n#########################################" - print "# testString test case #" - print "#########################################" - print "marshalled dict object:\n" - print xmlprettyprint(xml) - - def testBool(self): - xmltrue = xmlmarshaller.marshal(True) - xmlfalse = xmlmarshaller.marshal(False) - print "\n#########################################" - print "# testBool test case #" - print "#########################################" - print "marshalled boolean true object:\n" - print xmlprettyprint(xmltrue) - print "\nmarshalled boolean false object:\n" - print xmlprettyprint(xmlfalse) - pytrue = xmlmarshaller.unmarshal(xmltrue) - assert pytrue is True - pyfalse = xmlmarshaller.unmarshal(xmlfalse) - assert pyfalse is False - - def testString(self): - xml = xmlmarshaller.marshal( - "all your marshalled objects are belong to us") - print "\n#########################################" - print "# testString test case #" - print "#########################################" - print xmlprettyprint(xml) - - def testEmptyElement(self): - person = Person() - person.firstName = "Albert" - person.__xmlattributes__ = ('firstName',) - xml = xmlmarshaller.marshal(person, 'person') - print "\n#########################################" - print "# testEmptyElement test case #" - print "#########################################" - print xml - assert (xml == """""") - - def testXMLFlattenSequence(self): - person = Person() - person.asequence = ('one', 'two') - xml = xmlmarshaller.marshal(person, 'person') - print "\n#########################################" - print "# testXMLFlattenSequence test case #" - print "#########################################" - print xml - assert (xml == """onetwo""") - unmarshalledperson = xmlmarshaller.unmarshal(xml) - assert(hasattr(unmarshalledperson, 'asequence')) - assert(len(unmarshalledperson.asequence) == 2) - - def testInstance(self): - print "\n#########################################" - print "# testInstance test case #" - print "#########################################" - class Foo: - def __init__(self): - self.alist = [1,2] - self.astring = 'f00' - f = Foo() - xml = xmlmarshaller.marshal(f, 'foo') - print xml - - def testPerson(self): - person = Person() - person.firstName = "Albert" - person.lastName = "Camus" - person.addressLine1 = "23 Absurd St." - person.city = "Ennui" - person.state = "MO" - person.zip = "54321" - person._phoneNumber = "808-303-2323" - person.favoriteWords = ['angst', 'ennui', 'existence'] - person.weight = 150 -# __xmlattributes__ = ('fabulousness',) - person.fabulousness = "tres tres" - xml = xmlmarshaller.marshal(person) - print "\n#########################################" - print "# testPerson test case #" - print "#########################################" - print "Person object marshalled into XML:\n" - print xml - # When encountering a "person" element, use the Person class -## elementMappings = { "person" : Person } -## obj = unmarshal(xml, elementMappings = elementMappings) -## print "Person object recreated from XML with attribute types indicated:" -## print obj.person.__class__ -## for (attr, value) in obj.person.__dict__.items(): -## if not attr.startswith("__"): -## print attr, "=", value, type(value) -## print - - -if __name__ == "__main__": - unittest.main() diff --git a/wxPython/samples/pydocview/PyDocViewDemo.py b/wxPython/samples/pydocview/PyDocViewDemo.py index 7f7790d145..dcd3c189a1 100644 --- a/wxPython/samples/pydocview/PyDocViewDemo.py +++ b/wxPython/samples/pydocview/PyDocViewDemo.py @@ -60,7 +60,7 @@ class TextEditorApplication(pydocview.DocApp): # Install services - these can install menu and toolbar items textService = self.InstallService(TextEditor.TextService()) findService = self.InstallService(FindService.FindService()) - optionsService = self.InstallService(pydocview.DocOptionsService()) + optionsService = self.InstallService(pydocview.DocOptionsService(supportedModes=wx.lib.docview.DOC_MDI)) windowMenuService = self.InstallService(pydocview.WindowMenuService()) filePropertiesService = self.InstallService(pydocview.FilePropertiesService()) if os.path.exists("splash.jpg"): diff --git a/wxPython/wx/lib/docview.py b/wxPython/wx/lib/docview.py index 9512cf5226..2dd76d012a 100644 --- a/wxPython/wx/lib/docview.py +++ b/wxPython/wx/lib/docview.py @@ -1,6 +1,6 @@ #---------------------------------------------------------------------------- # Name: docview.py -# Purpose: Port of the wxWidgets docview classes +# Purpose: Port of the wxWindows docview classes # # Author: Peter Yared # @@ -10,11 +10,6 @@ # License: wxWindows license #---------------------------------------------------------------------------- -""" -A port of the wxWidgets doc/view classes to Python. - -:see: `pydocview` -""" import os import os.path @@ -78,10 +73,9 @@ def PathOnly(path): 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, and - cooperates with the `View`, `DocTemplate` and `DocManager` - classes. + 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 @@ -89,7 +83,7 @@ class Document(wx.EvtHandler): """ - def __init__(self, parent = None): + def __init__(self, parent=None): """ Constructor. Define your own default constructor to initialize application-specific data. @@ -148,10 +142,10 @@ class Document(wx.EvtHandler): def GetDocumentName(self): """ - The document type name given to the `DocTemplate` constructor, + The document type name given to the wxDocTemplate constructor, copied to this document when the document is created. If several document templates are created that use the same document type, this - variable is used in `DocManager.CreateView` to collate a list of + variable is used in wxDocManager::CreateView to collate a list of alternative view types that can be used on this kind of document. """ return self._documentTypeName @@ -159,10 +153,10 @@ class Document(wx.EvtHandler): def SetDocumentName(self, name): """ - Sets the document type name given to the `DocTemplate` constructor, + Sets he document type name given to the wxDocTemplate constructor, copied to this document when the document is created. If several document templates are created that use the same document type, this - variable is used in `DocManager.CreateView` to collate a list of + variable is used in wxDocManager::CreateView to collate a list of alternative view types that can be used on this kind of document. Do not change the value of this variable. """ @@ -171,14 +165,16 @@ class Document(wx.EvtHandler): def GetDocumentSaved(self): """ - Returns True if the document has been saved. + Returns True if the document has been saved. This method has been + added to wxPython and is not in wxWindows. """ return self._savedYet - def SetDocumentSaved(self, saved = True): + def SetDocumentSaved(self, saved=True): """ - Sets whether the document has been saved. + Sets whether the document has been saved. This method has been + added to wxPython and is not in wxWindows. """ self._savedYet = saved @@ -194,7 +190,7 @@ class Document(wx.EvtHandler): """ Sets the command processor to be used for this document. The document will then be responsible for its deletion. Normally you should not - call this; override `OnCreateCommandProcessor` instead. + call this; override OnCreateCommandProcessor instead. """ self._commandProcessor = processor @@ -214,7 +210,7 @@ class Document(wx.EvtHandler): Call with true to mark the document as modified since the last save, false otherwise. You may need to override this if your document view maintains its own record of being modified (for example if using - `wx.TextCtrl` to view and edit the document). + xTextWindow to view and edit the document). """ self._documentModified = modify @@ -223,6 +219,7 @@ class Document(wx.EvtHandler): """ 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. """ self._documentModificationDate = os.path.getmtime(self.GetFilename()) @@ -231,6 +228,7 @@ class Document(wx.EvtHandler): """ 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 @@ -277,10 +275,9 @@ class Document(wx.EvtHandler): def Close(self): """ - Closes the document, by calling `OnSaveModified` and then (if - this returns True) `OnCloseDocument`. This does not normally - delete the document object: use DeleteAllViews to do this - implicitly. + Closes the document, by calling OnSaveModified and then (if this true) + OnCloseDocument. This does not normally delete the document object: + use DeleteAllViews to do this implicitly. """ if self.OnSaveModified(): if self.OnCloseDocument(): @@ -293,10 +290,9 @@ class Document(wx.EvtHandler): def OnCloseDocument(self): """ - The default implementation calls `DeleteContents` (an empty - implementation) sets the modified flag to false. Override this - to supply additional behaviour when the document is closed - with `Close`. + The default implementation calls DeleteContents (an empty + implementation) sets the modified flag to false. Override this to + supply additional behaviour when the document is closed with Close. """ self.NotifyClosing() self.DeleteContents() @@ -306,9 +302,9 @@ class Document(wx.EvtHandler): def DeleteAllViews(self): """ - Calls `View.Close` and deletes each view. Deleting the final view will - implicitly delete the document itself, because the `View` destructor - calls `RemoveView`. This in turns calls `Document.OnChangedViewList`, + Calls wxView.Close and deletes each view. Deleting the final view will + implicitly delete the document itself, because the wxView destructor + calls RemoveView. This in turns calls wxDocument::OnChangedViewList, whose default implemention is to save and delete the document if no views exist. """ @@ -342,10 +338,9 @@ class Document(wx.EvtHandler): def OnNewDocument(self): """ - The default implementation calls `OnSaveModified` and - `DeleteContents`, makes a default title for the document, and - notifies the views that the filename (in fact, the title) has - changed. + The default implementation calls OnSaveModified and DeleteContents, + makes a default title for the document, and notifies the views that + the filename (in fact, the title) has changed. """ if not self.OnSaveModified() or not self.OnCloseDocument(): return False @@ -359,8 +354,8 @@ class Document(wx.EvtHandler): def Save(self): """ - Saves the document by calling `OnSaveDocument` if there is an - associated filename, or `SaveAs` if there is no filename. + Saves the document by calling OnSaveDocument if there is an associated + filename, or SaveAs if there is no filename. """ 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 @@ -389,7 +384,7 @@ class Document(wx.EvtHandler): def SaveAs(self): """ - Prompts the user for a file to save to, and then calls `OnSaveDocument`. + Prompts the user for a file to save to, and then calls OnSaveDocument. """ docTemplate = self.GetDocumentTemplate() if not docTemplate: @@ -428,9 +423,9 @@ class Document(wx.EvtHandler): def OnSaveDocument(self, filename): """ Constructs an output file for the given filename (which must - not be empty), and calls `SaveObject`. If `SaveObject` returns - true, the document is set to unmodified; otherwise, an error - message box is displayed. + not be empty), and calls SaveObject. If SaveObject returns true, the + document is set to unmodified; otherwise, an error message box is + displayed. """ if not filename: return False @@ -461,6 +456,7 @@ class Document(wx.EvtHandler): fileObject = file(filename, 'w') self.SaveObject(fileObject) + fileObject.close() if backupFilename: os.remove(backupFilename) @@ -489,7 +485,7 @@ class Document(wx.EvtHandler): def OnOpenDocument(self, filename): """ Constructs an input file for the given filename (which must not - be empty), and calls `LoadObject`. If `LoadObject` returns true, the + be empty), and calls LoadObject. If LoadObject returns true, the document is set to unmodified; otherwise, an error message box is displayed. The document's views are notified that the filename has changed, to give windows an opportunity to update their titles. All of @@ -522,26 +518,24 @@ class Document(wx.EvtHandler): def LoadObject(self, file): """ - Override this function and call it from your own `LoadObject` - before loading your own data. `LoadObject` is called by the - framework automatically when the document contents need to be - loaded. + Override this function and call it from your own LoadObject before + loading your own data. LoadObject is called by the framework + automatically when the document contents need to be loaded. - Note that the wxPython version simply sends you a Python file - object, so you can use pickle. + Note that the wxPython version simply sends you a Python file object, + so you can use pickle. """ return True def SaveObject(self, file): """ - Override this function and call it from your own `SaveObject` - before saving your own data. `SaveObject` is called by the - framework automatically when the document contents need to be - saved. + Override this function and call it from your own SaveObject before + saving your own data. SaveObject is called by the framework + automatically when the document contents need to be saved. - Note that the wxPython version simply sends you a Python file - object, so you can use pickle. + Note that the wxPython version simply sends you a Python file object, + so you can use pickle. """ return True @@ -582,19 +576,18 @@ class Document(wx.EvtHandler): def OnCreateCommandProcessor(self): """ Override this function if you want a different (or no) command - processor to be created when the document is created. By - default, it returns an instance of `CommandProcessor`. + processor to be created when the document is created. By default, it + returns an instance of wxCommandProcessor. """ return CommandProcessor() def OnSaveModified(self): """ - If the document has been modified, prompts the user to ask if - the changes should be changed. If the user replies Yes, the - `Save` function is called. If No, the document is marked as - unmodified and the function succeeds. If Cancel, the function - fails. + If the document has been modified, prompts the user to ask if the + changes should be changed. If the user replies Yes, the Save function + is called. If No, the document is marked as unmodified and the + function succeeds. If Cancel, the function fails. """ if not self.IsModified(): return True @@ -645,7 +638,7 @@ class Document(wx.EvtHandler): def AddView(self, view): """ If the view is not already in the list of views, adds the view and - calls `OnChangedViewList`. + calls OnChangedViewList. """ if not view in self._documentViews: self._documentViews.append(view) @@ -656,7 +649,7 @@ class Document(wx.EvtHandler): def RemoveView(self, view): """ Removes the view from the document's list of views, and calls - `OnChangedViewList`. + OnChangedViewList. """ if view in self._documentViews: self._documentViews.remove(view) @@ -666,7 +659,7 @@ class Document(wx.EvtHandler): def OnCreate(self, path, flags): """ - The default implementation calls `DeleteContents` (an empty + The default implementation calls DeleteContents (an empty implementation) sets the modified flag to false. Override this to supply additional behaviour when the document is closed with Close. """ @@ -686,7 +679,7 @@ class Document(wx.EvtHandler): def UpdateAllViews(self, sender = None, hint = None): """ - Updates all views. If sender is non-None, does not update this view. + Updates all views. If sender is non-NULL, does not update this view. hint represents optional information to allow a view to optimize its update. """ @@ -706,7 +699,7 @@ class Document(wx.EvtHandler): def SetFilename(self, filename, notifyViews = False): """ Sets the filename for this document. Usually called by the framework. - If notifyViews is true, `View.OnChangeFilename` is called for all + If notifyViews is true, wxView.OnChangeFilename is called for all views. """ self._documentFile = filename @@ -730,19 +723,20 @@ class Document(wx.EvtHandler): def SetWriteable(self, writeable): """ - Set to False if the document can not be saved. This will - disable the ID_SAVE_AS event and is useful for custom - documents that should not be saveable. The ID_SAVE event can - be disabled by never modifying the document. + Set to False if the document can not be saved. This will disable the ID_SAVE_AS + event and is useful for custom documents that should not be saveable. The ID_SAVE + event can be disabled by never Modifying the document. This method has been added + to wxPython and is not in wxWindows. """ self._writeable = writeable class View(wx.EvtHandler): """ - The view class can be used to model the viewing and editing - component of an application's file-based data. It cooperates - with the `Document`, `DocTemplate` and `DocManager` classes. + The view class can be used to model the viewing and editing component of + an application's file-based data. It is part of the document/view + framework supported by wxWindows, and cooperates with the wxDocument, + wxDocTemplate and wxDocManager classes. """ def __init__(self): @@ -789,7 +783,7 @@ class View(wx.EvtHandler): def OnActivateView(self, activate, activeView, deactiveView): """ - Called when a view is activated by means of `View.Activate`. The + Called when a view is activated by means of wxView::Activate. The default implementation does nothing. """ pass @@ -814,15 +808,15 @@ class View(wx.EvtHandler): def OnPrint(self, dc, info): """ Override this to print the view for the printing framework. The - default implementation calls `View.OnDraw`. + default implementation calls View.OnDraw. """ self.OnDraw(dc) def OnUpdate(self, sender, hint): """ - Called when the view should be updated. sender is a reference to the - view that sent the update request, or None if no single view requested + Called when the view should be updated. sender is a pointer to the + view that sent the update request, or NULL if no single view requested the update (for instance, when the document is opened). hint is as yet unused but may in future contain application-specific information for making updating more efficient. @@ -870,7 +864,7 @@ class View(wx.EvtHandler): def GetViewName(self): """ - Gets the name associated with the view (passed to the `DocTemplate` + Gets the name associated with the view (passed to the wxDocTemplate constructor). Not currently used by the framework. """ return self._viewTypeName @@ -883,9 +877,9 @@ class View(wx.EvtHandler): self._viewTypeName = name - def Close(self, deleteWindow = True): + def Close(self, deleteWindow=True): """ - Closes the view by calling `OnClose`. If deleteWindow is true, this + Closes the view by calling OnClose. If deleteWindow is true, this function should delete the window associated with the view. """ if self.OnClose(deleteWindow = deleteWindow): @@ -894,28 +888,28 @@ class View(wx.EvtHandler): return False - def Activate(self, activate = True): + def Activate(self, activate=True): """ - Call this from your view frame's EVT_ACTIVATE handler to tell - the framework which view is currently active. If your - windowing system doesn't support EVT_ACTIVATE, you may need to - call this function from an EVT_MENU handler, or any place - where you know the view must be active, and the framework will - need to get the current view. + Call this from your view frame's OnActivate member to tell the + framework which view is currently active. If your windowing system + doesn't call OnActivate, you may need to call this function from + OnMenuCommand or any place where you know the view must be active, and + the framework will need to get the current view. + + The prepackaged view frame wxDocChildFrame calls wxView.Activate from + its OnActivate member and from its OnMenuCommand member. """ if self.GetDocument() and self.GetDocumentManager(): - self.OnActivateView(activate, - self, - self.GetDocumentManager().GetCurrentView()) + self.OnActivateView(activate, self, self.GetDocumentManager().GetCurrentView()) self.GetDocumentManager().ActivateView(self, activate) - def OnClose(self, deleteWindow = True): + def OnClose(self, deleteWindow=True): """ Implements closing behaviour. The default implementation calls - `Document.Close` to close the associated document. Does not delete the + wxDocument.Close to close the associated document. Does not delete the view. The application may wish to do some cleaning up operations in - this function, if a call to `Document.Close` succeeded. For example, + this function, if a call to wxDocument::Close succeeded. For example, if your application's all share the same window, you need to disassociate the window from the view and perhaps clear the window. If deleteWindow is true, delete the frame associated with the view. @@ -928,11 +922,11 @@ class View(wx.EvtHandler): def OnCreate(self, doc, flags): """ - `DocManager` or `Document` creates a `View` via a `DocTemplate`. Just - after the `DocTemplate` creates the `View`, it calls `View.OnCreate`. - In its `OnCreate` member function, the `View` can create a - `DocChildFrame` or a derived class. This `DocChildFrame` provides user - interface elements to view and/or edit the contents of the `Document`. + wxDocManager or wxDocument creates a wxView via a wxDocTemplate. Just + after the wxDocTemplate creates the wxView, it calls wxView::OnCreate. + In its OnCreate member function, the wxView can create a + wxDocChildFrame or a derived class. This wxDocChildFrame provides user + interface elements to view and/or edit the contents of the wxDocument. By default, simply returns true. If the function returns false, the view will be deleted. @@ -942,14 +936,14 @@ class View(wx.EvtHandler): def OnCreatePrintout(self): """ - Returns a `wx.Printout` object for the purposes of printing. It should + Returns a wxPrintout object for the purposes of printing. It should create a new object every time it is called; the framework will delete objects it creates. - By default, this function returns an instance of `DocPrintout`, which - prints and previews one page by calling `View.OnDraw`. + By default, this function returns an instance of wxDocPrintout, which + prints and previews one page by calling wxView.OnDraw. - Override to return an instance of a class other than `DocPrintout`. + Override to return an instance of a class other than wxDocPrintout. """ return DocPrintout(self) @@ -957,8 +951,9 @@ class View(wx.EvtHandler): def GetFrame(self): """ Gets the frame associated with the view (if any). Note that this - "frame" is not a `wx.Frame` at all in the generic MDI implementation - which uses the notebook pages instead of the frames. + "frame" is not a wxFrame at all in the generic MDI implementation + which uses the notebook pages instead of the frames and this is why + this method returns a wxWindow and not a wxFrame. """ return self._viewFrame @@ -966,7 +961,9 @@ class View(wx.EvtHandler): def SetFrame(self, frame): """ Sets the frame associated with this view. The application should call - this if possible, to tell the view about the frame. + this if possible, to tell the view about the frame. See GetFrame for + the explanation about the mismatch between the "Frame" in the method + name and the type of its parameter. """ self._viewFrame = frame @@ -983,57 +980,51 @@ class View(wx.EvtHandler): class DocTemplate(wx.Object): """ - The `DocTemplate` class is used to model the relationship between - a document class and a view class. + The wxDocTemplate class is used to model the relationship between a + document class and a view class. """ - 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 `DocManager` instance, and before doing + application after creating a wxDocManager instance, and before doing any document or view operations. - :param manager: the document manager object which manages this template. + manager is the document manager object which manages this template. - :param description: a short description of what the template - is for. This string will be displayed in the file filter - list of Windows file selectors. + description is a short description of what the template is for. This + string will be displayed in the file filter list of Windows file + selectors. - :param filter: an appropriate file filter such as \*.txt. + filter is an appropriate file filter such as *.txt. - :param dir: the default directory to use for file selectors. + dir is the default directory to use for file selectors. - :param ext: the default file extension (such as txt). + ext is the default file extension (such as txt). - :param docTypeName: a name that should be unique for a given - type of document, used for gathering a list of views - relevant to a particular document. + docTypeName is a name that should be unique for a given type of + document, used for gathering a list of views relevant to a + particular document. - :param viewTypeName: a name that should be unique for a given view. + viewTypeName is a name that should be unique for a given view. - :param docType: a Python class. If this is not supplied, you - will need to derive a new `DocTemplate` class and override - the `CreateDocument` member to return a new document - instance on demand. + docClass is a Python class. If this is not supplied, you will need to + derive a new wxDocTemplate class and override the CreateDocument + member to return a new document instance on demand. - :param viewType: a Python class. If this is not supplied, you - will need to derive a new `DocTemplate` class and override - the `CreateView` member to return a new view instance on - demand. + viewClass is a Python class. If this is not supplied, you will need to + derive a new wxDocTemplate class and override the CreateView member to + return a new view instance on demand. - :param flags: a bit list of the following - - * TEMPLATE_VISIBLE: The template may be displayed to the - user in dialogs. + flags is a bit list of the following: + wx.TEMPLATE_VISIBLE The template may be displayed to the user in + dialogs. - * TEMPLATE_INVISIBLE: The template may not be displayed - to the user in dialogs. + wx.TEMPLATE_INVISIBLE The template may not be displayed to the user in + dialogs. - * DEFAULT_TEMPLATE_FLAGS: Defined as TEMPLATE_VISIBLE. - + wx.DEFAULT_TEMPLATE_FLAGS Defined as wxTEMPLATE_VISIBLE. """ self._docManager = manager self._description = description @@ -1052,8 +1043,8 @@ class DocTemplate(wx.Object): def GetDefaultExtension(self): """ - Returns the default file extension for the document data, as - passed to the document template constructor. + Returns the default file extension for the document data, as passed to + the document template constructor. """ return self._defaultExt @@ -1067,8 +1058,8 @@ class DocTemplate(wx.Object): def GetDescription(self): """ - Returns the text description of this template, as passed to - the document template constructor. + Returns the text description of this template, as passed to the + document template constructor. """ return self._description @@ -1082,8 +1073,8 @@ class DocTemplate(wx.Object): def GetDirectory(self): """ - Returns the default directory, as passed to the document - template constructor. + Returns the default directory, as passed to the document template + constructor. """ return self._directory @@ -1097,8 +1088,8 @@ class DocTemplate(wx.Object): def GetDocumentManager(self): """ - Returns the document manager instance for which this template - was created. + Returns the document manager instance for which this template was + created. """ return self._docManager @@ -1145,14 +1136,16 @@ class DocTemplate(wx.Object): def GetIcon(self): """ Returns the icon, as passed to the document template - constructor. + constructor. This method has been added to wxPython and is + not in wxWindows. """ return self._icon def SetIcon(self, flags): """ - Sets the icon. + Sets the icon. This method has been added to wxPython and is not + in wxWindows. """ self._icon = icon @@ -1218,10 +1211,9 @@ class DocTemplate(wx.Object): def CreateView(self, doc, flags): """ - Creates a new instance of the associated document view. If you - have not supplied a class to the template constructor, you - will need to override this function to return an appropriate - view instance. + Creates a new instance of the associated document view. If you have + not supplied a class to the template constructor, you will need to + override this function to return an appropriate view instance. """ view = self._viewType() view.SetDocument(doc) @@ -1245,25 +1237,24 @@ class DocTemplate(wx.Object): class DocManager(wx.EvtHandler): """ - The `DocManager` class is part of the document/view framework and - cooperates with the `View`, `Document` and `DocTemplate` classes. + The wxDocManager class is part of the document/view framework supported by + wxWindows, and cooperates with the wxView, wxDocument and wxDocTemplate + 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. + Constructor. Create a document manager instance dynamically near the + start of your application before doing any document or view operations. - :param flags: used to indicate whether the document manager is - in DOC_SDI or DOC_MDI mode. + flags is used in the Python version to indicate whether the document + manager is in DOC_SDI or DOC_MDI mode. - :param initialize: if true, the `Initialize` function will be - called to create a default history list object. If you - derive from DocManager, you may wish to call the base - constructor with false, and then call `Initialize` in your - own constructor, to allow your own `Initialize` or - `OnCreateFileHistory` functions to be called. + If initialize is true, the Initialize function will be called to + create a default history list object. If you derive from wxDocManager, + you may wish to call the base constructor with false, and then call + Initialize in your own constructor, to allow your own Initialize or + OnCreateFileHistory functions to be called. """ wx.EvtHandler.__init__(self) @@ -1318,12 +1309,13 @@ class DocManager(wx.EvtHandler): def GetFlags(self): """ - Returns the document manager's flags. + Returns the document manager's flags. This method has been + added to wxPython and is not in wxWindows. """ return self._flags - def CloseDocument(self, doc, force = True): + def CloseDocument(self, doc, force=True): """ Closes the specified document. """ @@ -1335,7 +1327,7 @@ class DocManager(wx.EvtHandler): return False - def CloseDocuments(self, force = True): + def CloseDocuments(self, force=True): """ Closes all currently opened documents. """ @@ -1346,9 +1338,9 @@ class DocManager(wx.EvtHandler): return True - def Clear(self, force = True): + def Clear(self, force=True): """ - Closes all currently opened document by calling `CloseDocuments` and + Closes all currently opened document by callling CloseDocuments and clears the document manager's templates. """ if not self.CloseDocuments(force): @@ -1359,13 +1351,16 @@ class DocManager(wx.EvtHandler): def Initialize(self): """ - Initializes data; currently just calls `OnCreateFileHistory`. Some data + Initializes data; currently just calls OnCreateFileHistory. Some data cannot always be initialized in the constructor because the programmer must be given the opportunity to override functionality. In fact - Initialize is called from the `DocManager` constructor, but this can - be prevented by passing false to the second argument, allowing the + Initialize is called from the wxDocManager constructor, but this can + be vetoed by passing false to the second argument, allowing the derived class's constructor to call Initialize, possibly calling a - different `OnCreateFileHistory` from the default. + different OnCreateFileHistory from the default. + + The bottom line: if you're not deriving from Initialize, forget it and + construct wxDocManager with no arguments. """ self.OnCreateFileHistory() return True @@ -1374,7 +1369,7 @@ class DocManager(wx.EvtHandler): def OnCreateFileHistory(self): """ A hook to allow a derived class to create a different type of file - history. Called from `Initialize`. + history. Called from Initialize. """ self._fileHistory = wx.FileHistory() @@ -1396,7 +1391,7 @@ class DocManager(wx.EvtHandler): """ return self.CloseDocuments(force = False) - + def OnFileNew(self, event): """ Creates a new document and reads in the selected file. @@ -1414,8 +1409,8 @@ class DocManager(wx.EvtHandler): def OnFileRevert(self, event): """ - Reverts the current document by calling `Document.Save` for - the current document. + Reverts the current document by calling wxDocument.Save for the current + document. """ doc = self.GetCurrentDocument() if not doc: @@ -1425,8 +1420,8 @@ class DocManager(wx.EvtHandler): def OnFileSave(self, event): """ - Saves the current document by calling `Document.Save` for the - current document. + Saves the current document by calling wxDocument.Save for the current + document. """ doc = self.GetCurrentDocument() if not doc: @@ -1436,7 +1431,7 @@ class DocManager(wx.EvtHandler): def OnFileSaveAs(self, event): """ - Calls `Document.SaveAs` for the current document. + Calls wxDocument.SaveAs for the current document. """ doc = self.GetCurrentDocument() if not doc: @@ -1446,8 +1441,8 @@ class DocManager(wx.EvtHandler): def OnPrint(self, event): """ - Prints the current document by calling its - `View.OnCreatePrintout` method. + Prints the current document by calling its View's OnCreatePrintout + method. """ view = self.GetCurrentView() if not view: @@ -1479,7 +1474,7 @@ class DocManager(wx.EvtHandler): def OnPreview(self, event): """ - Previews the current document by calling its `View.OnCreatePrintout` + Previews the current document by calling its View's OnCreatePrintout method. """ view = self.GetCurrentView() @@ -1629,11 +1624,9 @@ class DocManager(wx.EvtHandler): def GetLastActiveView(self): """ - Returns the last active view. This is used in the SDI - framework where dialogs can be mistaken for a view and causes - the framework to deactivete the current view. This happens - when something like a custom dialog box used to operate on the - current view is shown. + Returns the last active view. This is used in the SDI framework where dialogs can be mistaken for a view + and causes the framework to deactivete the current view. This happens when something like a custom dialog box used + to operate on the current view is shown. """ if len(self._docs) >= 1: return self._lastActiveView @@ -1643,11 +1636,10 @@ class DocManager(wx.EvtHandler): 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. + 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. """ view = self.GetCurrentView() if view: @@ -1696,11 +1688,10 @@ class DocManager(wx.EvtHandler): 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. + 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. """ id = event.GetId() view = self.GetCurrentView() @@ -1747,30 +1738,28 @@ class DocManager(wx.EvtHandler): 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: - * DOC_NEW: Creates a fresh document. - * DOC_SILENT: Silently loads the given document file. - - If DOC_NEW is present, a new document will be created and - returned, possibly after asking the user for a template to use - if there is more than one document template. If DOC_SILENT is - present, a new document will be created and the given file - loaded into it. If neither of these flags is present, the user - will be presented with a file selector for the file to load, - and the template to use will be determined by the extension - (Windows) or by popping up a template choice list (other + wx.lib.docview.DOC_NEW Creates a fresh document. + wx.lib.docview.DOC_SILENT Silently loads the given document file. + + If wx.lib.docview.DOC_NEW is present, a new document will be created and returned, + possibly after asking the user for a template to use if there is more + than one document template. If wx.lib.docview.DOC_SILENT is present, a new document + will be created and the given file loaded into it. If neither of these + flags is present, the user will be presented with a file selector for + the file to load, and the template to use will be determined by the + extension (Windows) or by popping up a template choice list (other platforms). - If the maximum number of documents has been reached, this - function will delete the oldest currently loaded document - before creating a new one. + If the maximum number of documents has been reached, this function + will delete the oldest currently loaded document before creating a new + one. - wxPython version supports the document manager's DOC_OPEN_ONCE - flag. + wxPython version supports the document manager's wx.lib.docview.DOC_OPEN_ONCE flag. """ templates = [] for temp in self._templates: @@ -1814,6 +1803,24 @@ class DocManager(wx.EvtHandler): 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 @@ -1836,7 +1843,7 @@ class DocManager(wx.EvtHandler): 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 @@ -1869,21 +1876,21 @@ class DocManager(wx.EvtHandler): def DeleteTemplate(self, template, flags): """ - Placeholder, not yet implemented + Placeholder, not yet implemented in wxWindows. """ pass def FlushDoc(self, doc): """ - Placeholder, not yet implemented + Placeholder, not yet implemented in wxWindows. """ return False def MatchTemplate(self, path): """ - Placeholder, not yet implemented + Placeholder, not yet implemented in wxWindows. """ return None @@ -1997,7 +2004,7 @@ class DocManager(wx.EvtHandler): 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. @@ -2058,7 +2065,7 @@ class DocManager(wx.EvtHandler): On other platforms, if there is more than one document template a choice list is popped up, followed by a file selector. - This function is used in `DocManager.CreateDocument`. + This function is used in wxDocManager.CreateDocument. """ if wx.Platform == "__WXMSW__" or wx.Platform == "__WXGTK__" or wx.Platform == "__WXMAC__": allfilter = '' @@ -2105,18 +2112,19 @@ class DocManager(wx.EvtHandler): 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 `DocManager.CreateDocument`. + one template). This function is used in wxDocManager.CreateDocument. + + Parameters - :param temps: list of templates from which to choose a desired template. + templates - list of templates from which to choose a desired template. - :param sort: If more than one template is passed in in - templates, then this parameter indicates whether the list - of templates that the user will have to choose from is - sorted or not when shown the choice box dialog. Default - is false. + sort - If more than one template is passed in in templates, then this + parameter indicates whether the list of templates that the user will + have to choose from is sorted or not when shown the choice box dialog. + Default is false. """ templates = [] for temp in temps: @@ -2152,14 +2160,9 @@ class DocManager(wx.EvtHandler): 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 `DocManager.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. + 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. """ templates = [] strings = [] @@ -2190,7 +2193,8 @@ class DocManager(wx.EvtHandler): def GetTemplates(self): """ - Returns the document manager's template list. + Returns the document manager's template list. This method has been added to + wxPython and is not in wxWindows. """ return self._templates @@ -2226,7 +2230,7 @@ class DocManager(wx.EvtHandler): self._docs.remove(doc) - def ActivateView(self, view, activate = True, deleting = False): + def ActivateView(self, view, activate=True, deleting=False): """ Sets the current view. """ @@ -2265,19 +2269,15 @@ class DocManager(wx.EvtHandler): class DocParentFrame(wx.Frame): """ - The DocParentFrame class provides a default top-level frame for - applications using the document/view framework. This class can - only be used for SDI (not MDI) parent frames. + The wxDocParentFrame class provides a default top-level frame for + applications using the document/view framework. This class can only be + used for SDI (not MDI) parent frames. - It cooperates with the `View`, `Document`, `DocManager` and - `DocTemplate` classes. + It cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplates + 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. @@ -2377,17 +2377,17 @@ class DocParentFrame(wx.Frame): class DocChildFrame(wx.Frame): """ - The `DocChildFrame` class provides a default frame for displaying - documents on separate windows. This class can only be used for SDI - (not MDI) child frames. + The wxDocChildFrame class provides a default frame for displaying + documents on separate windows. This class can only be used for SDI (not + MDI) child frames. - The class is part of the document/view framework and cooperates - with the `View`, `Document`, `DocManager` and `DocTemplate` + The class is part of the document/view framework supported by wxWindows, + and cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate classes. """ - 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. @@ -2524,16 +2524,16 @@ class DocChildFrame(wx.Frame): class DocMDIParentFrame(wx.MDIParentFrame): """ - The `DocMDIParentFrame` class provides a default top-level frame - for applications using the document/view framework. This class can - only be used for MDI parent frames. + The wxDocMDIParentFrame class provides a default top-level frame for + applications using the document/view framework. This class can only be + used for MDI parent frames. - It cooperates with the `View`, `Document`, `DocManager` and - `DocTemplate` classes. + It cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate + 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. @@ -2633,17 +2633,17 @@ class DocMDIParentFrame(wx.MDIParentFrame): class DocMDIChildFrame(wx.MDIChildFrame): """ - The `DocMDIChildFrame` class provides a default frame for - displaying documents on separate windows. This class can only be - used for MDI child frames. + The wxDocMDIChildFrame class provides a default frame for displaying + documents on separate windows. This class can only be used for MDI child + frames. - The class is part of the document/view framework and cooperates - with the `View`, `Document`, `DocManager` and `DocTemplate` + The class is part of the document/view framework supported by wxWindows, + and cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate classes. """ - 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. @@ -2781,12 +2781,12 @@ class DocMDIChildFrame(wx.MDIChildFrame): class DocPrintout(wx.Printout): """ - `DocPrintout` is a default Printout that prints the first page of - a document view. + DocPrintout is a default Printout that prints the first page of a document + view. """ - def __init__(self, view, title = "Printout"): + def __init__(self, view, title="Printout"): """ Constructor. """ @@ -2851,28 +2851,25 @@ class DocPrintout(wx.Printout): class Command(wx.Object): """ - `Command` is a base class for modelling an application command, - which is an action usually performed by selecting a menu item, - pressing a toolbar button or any other means provided by the - application to change the data or view. + wxCommand is a base class for modelling an application command, which is + an action usually performed by selecting a menu item, pressing a toolbar + button or any other means provided by the application to change the data + or view. """ def __init__(self, canUndo = False, name = None): """ - Constructor. Command is an abstract class, so you will need to - derive a new class and call this constructor from your own - constructor. + Constructor. wxCommand is an abstract class, so you will need to + derive a new class and call this constructor from your own constructor. - :param canUndo: tells the command processor whether this - command is undo-able. You can achieve the same - functionality by overriding the `CanUndo` member function - (if for example the criteria for undoability is context- - dependent). + canUndo tells the command processor whether this command is undo-able. + You can achieve the same functionality by overriding the CanUndo member + function (if for example the criteria for undoability is context- + dependent). - :param name: must be supplied for the command processor to - display the command name in the application's edit menu. - + name must be supplied for the command processor to display the command + name in the application's edit menu. """ self._canUndo = canUndo self._name = name @@ -2894,52 +2891,48 @@ class Command(wx.Object): def Do(self): """ - Override this member function to execute the appropriate - action when called. Return true to indicate that the action - has taken place, false otherwise. Returning false will - indicate to the command processor that the action is not - undoable and should not be added to the command history. + Override this member function to execute the appropriate action when + called. Return true to indicate that the action has taken place, false + otherwise. Returning false will indicate to the command processor that + the action is not undoable and should not be added to the command + history. """ return True def Undo(self): """ - Override this member function to un-execute a previous - `Do`. Return true to indicate that the action has taken place, - false otherwise. Returning false will indicate to the command - processor that the action is not redoable and no change should - be made to the command history. + Override this member function to un-execute a previous Do. Return true + to indicate that the action has taken place, false otherwise. Returning + false will indicate to the command processor that the action is not + redoable and no change should be made to the command history. - How you implement this command is totally application - dependent, but typical strategies include: + How you implement this command is totally application dependent, but + typical strategies include: - * Perform an inverse operation on the last modified piece - of data in the document. When redone, a copy of data - stored in command is pasted back or some operation - reapplied. This relies on the fact that you know the - ordering of Undos; the user can never Undo at an - arbitrary position in he command history. + Perform an inverse operation on the last modified piece of data in the + document. When redone, a copy of data stored in command is pasted back + or some operation reapplied. This relies on the fact that you know the + ordering of Undos; the user can never Undo at an arbitrary position in + he command history. - * Restore the entire document state (perhaps using - document transactioning). Potentially very inefficient, - but possibly easier to code if the user interface and - data are complex, and an 'inverse execute' operation is - hard to write. + Restore the entire document state (perhaps using document + transactioning). Potentially very inefficient, but possibly easier to + code if the user interface and data are complex, and an 'inverse + execute' operation is hard to write. """ return True class CommandProcessor(wx.Object): """ - `CommandProcessor` is a class that maintains a history of - `Command` instancess, with undo/redo functionality - built-in. Derive a new class from this if you want different - behaviour. + wxCommandProcessor is a class that maintains a history of wxCommands, with + undo/redo functionality built-in. Derive a new class from this if you want + different behaviour. """ - 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 @@ -3000,11 +2993,10 @@ class CommandProcessor(wx.Object): def SetEditMenu(self, menu): """ - Tells the command processor to update the Undo and Redo items - on this menu as appropriate. Set this to None if the menu is - about to be destroyed and command operations may still be - performed, or the command processor may try to access an - invalid pointer. + Tells the command processor to update the Undo and Redo items on this + menu as appropriate. Set this to NULL if the menu is about to be + destroyed and command operations may still be performed, or the + command processor may try to access an invalid pointer. """ self._editMenu = menu @@ -3037,10 +3029,20 @@ class CommandProcessor(wx.Object): self._redoAccelerator = accel + def SetEditMenu(self, menu): + """ + Tells the command processor to update the Undo and Redo items on this + menu as appropriate. Set this to NULL if the menu is about to be + destroyed and command operations may still be performed, or the + command processor may try to access an invalid pointer. + """ + self._editMenu = menu + + def SetMenuStrings(self): """ - Sets the menu labels according to the currently set menu and - the current command state. + Sets the menu labels according to the currently set menu and the + current command state. """ if self.GetEditMenu() != None: undoCommand = self._GetCurrentCommand() @@ -3085,13 +3087,13 @@ class CommandProcessor(wx.Object): 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 `Command.Do` to execute the command; if it succeeds, the + calls wxCommand::Do to execute the command; if it succeeds, the command is stored in the history list, and the associated edit menu (if any) updated appropriately. If it fails, the command is deleted - immediately. Once `Submit` has been called, the passed command should + immediately. Once Submit has been called, the passed command should not be deleted directly by the application. storeIt indicates whether the successful command should be stored in diff --git a/wxPython/wx/lib/pydocview.py b/wxPython/wx/lib/pydocview.py index e35c564548..90c49aefd0 100644 --- a/wxPython/wx/lib/pydocview.py +++ b/wxPython/wx/lib/pydocview.py @@ -366,7 +366,7 @@ class DocMDIParentFrameMixIn: return wx.GetApp().ProcessUpdateUIEvent(event) - def CreateEmbeddedWindows(self, windows = 0): + def CreateEmbeddedWindows(self, windows=0): """ Create the specified embedded windows around the edges of the frame. """ @@ -488,7 +488,7 @@ class DocMDIParentFrameMixIn: return None - def _CreateEmbeddedWindow(self, parent, size, orientation, alignment, visible = True, sash = None): + def _CreateEmbeddedWindow(self, parent, size, orientation, alignment, visible=True, sash=None): """ Creates the embedded window with the specified size, orientation, and alignment. If the window is not visible it will retain the size with which it was last viewed. @@ -527,7 +527,7 @@ class DocMDIParentFrameMixIn: return window - def ShowEmbeddedWindow(self, window, show = True): + def ShowEmbeddedWindow(self, window, show=True): """ Shows or hides the embedded window specified by the embedded window location constant. """ @@ -591,7 +591,7 @@ class DocTabbedChildFrame(wx.Panel): """ - 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. @@ -773,6 +773,7 @@ class DocTabbedParentFrame(wx.Frame, DocFrameMixIn, DocMDIParentFrameMixIn): # self._notebook.SetSizer(wx.NotebookSizer(self._notebook)) wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self._notebook.GetId(), self.OnNotebookPageChanged) wx.EVT_RIGHT_DOWN(self._notebook, self.OnNotebookRightClick) + wx.EVT_MOTION(self._notebook, self.OnNotebookMouseOver) templates = wx.GetApp().GetDocumentManager().GetTemplates() iconList = wx.ImageList(16, 16, initialCount = len(templates)) @@ -825,6 +826,17 @@ class DocTabbedParentFrame(wx.Frame, DocFrameMixIn, DocMDIParentFrameMixIn): self._notebook.GetPage(index).GetView().Activate() + def OnNotebookMouseOver(self, event): + # wxBug: On Windows XP the tooltips don't automatically disappear when you move the mouse and it is on a notebook tab, has nothing to do with this code!!! + index, type = self._notebook.HitTest(event.GetPosition()) + if index > -1: + doc = self._notebook.GetPage(index).GetView().GetDocument() + self._notebook.SetToolTip(wx.ToolTip(doc.GetFilename())) + else: + self._notebook.SetToolTip(wx.ToolTip("")) + event.Skip() + + def OnNotebookRightClick(self, event): """ Handles right clicks for the notebook, enabling users to either close @@ -842,6 +854,15 @@ class DocTabbedParentFrame(wx.Frame, DocFrameMixIn, DocMDIParentFrameMixIn): doc.DeleteAllViews() wx.EVT_MENU(self, id, OnRightMenuSelect) if self._notebook.GetPageCount() > 1: + id = wx.NewId() + menu.Append(id, _("Close All but \"%s\"" % doc.GetPrintableName())) + def OnRightMenuSelect(event): + for i in range(self._notebook.GetPageCount()-1, -1, -1): # Go from len-1 to 0 + if i != index: + doc = self._notebook.GetPage(i).GetView().GetDocument() + if not self.GetDocumentManager().CloseDocument(doc, False): + return + wx.EVT_MENU(self, id, OnRightMenuSelect) menu.AppendSeparator() tabsMenu = wx.Menu() menu.AppendMenu(wx.NewId(), _("Select Tab"), tabsMenu) @@ -899,6 +920,7 @@ class DocTabbedParentFrame(wx.Frame, DocFrameMixIn, DocMDIParentFrameMixIn): """ index = self.GetNotebookPageIndex(panel) if index > -1: + self._notebook.SetFocus() self._notebook.SetSelection(index) @@ -1015,7 +1037,7 @@ class DocMDIChildFrame(wx.MDIChildFrame): """ - 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. @@ -1176,7 +1198,7 @@ class DocService(wx.EvtHandler): self._docManager = docManager - def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None): + 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 @@ -1263,7 +1285,7 @@ class DocOptionsService(DocService): """ - def __init__(self, showGeneralOptions=True, allowModeChanges=True): + 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 @@ -1273,13 +1295,13 @@ class DocOptionsService(DocService): """ DocService.__init__(self) self.ClearOptionsPanels() - self._allowModeChanges = allowModeChanges + self._supportedModes = supportedModes self._toolOptionsID = wx.NewId() if showGeneralOptions: self.AddOptionsPanel(GeneralOptionsPanel) - def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None): + def InstallControls(self, frame, menuBar=None, toolBar=None, statusBar=None, document=None): """ Installs a "Tools" menu with an "Options" menu item. """ @@ -1310,20 +1332,20 @@ class DocOptionsService(DocService): return False - def GetAllowModeChanges(self): + def GetSupportedModes(self): """ - Return true if the default general options pane should allow users to - change the document interface mode between SDI and MDI modes. + 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._allowModeChanges + return self._supportedModes - def SetAllowModeChanges(self, allowModeChanges): + def SetSupportedModes(self, _supportedModessupportedModes): """ - Set to true if the default general options pane should allow users to - change the document interface mode between SDI and MDI modes. + 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._allowModeChanges = allowModeChanges + self._supportedModes = supportedModes def ClearOptionsPanels(self): @@ -1375,7 +1397,7 @@ class OptionsDialog(wx.Dialog): sizer = wx.BoxSizer(wx.VERTICAL) - optionsNotebook = wx.Notebook(self, -1, size = (560, 325)) + 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) @@ -1430,20 +1452,27 @@ class GeneralOptionsPanel(wx.Panel): config = wx.ConfigBase_Get() self._showTipsCheckBox = wx.CheckBox(self, -1, _("Show tips at start up")) self._showTipsCheckBox.SetValue(config.ReadInt("ShowTipAtStartup", True)) - if wx.GetApp().GetService(DocOptionsService).GetAllowModeChanges(): - choices = [_("Show each document in its own window"), _("Show all documents in a single window with tabs")] + if self._AllowModeChanges(): + supportedModes = wx.GetApp().GetService(DocOptionsService).GetSupportedModes() + choices = [] + self._sdiChoice = _("Show each document in its own window") + self._mdiChoice = _("Show all documents in a single window with tabs") + self._winMdiChoice = _("Show all documents in a single window with child windows") + if supportedModes & wx.lib.docview.DOC_SDI: + choices.append(self._sdiChoice) + choices.append(self._mdiChoice) if wx.Platform == "__WXMSW__": - choices.append(_("Show all documents in a single window with child windows")) + choices.append(self._winMdiChoice) self._documentRadioBox = wx.RadioBox(self, -1, _("Document Interface"), choices = choices, majorDimension=1, ) if config.ReadInt("UseWinMDI", False): - self._documentRadioBox.SetSelection(2) + self._documentRadioBox.SetStringSelection(self._winMdiChoice) elif config.ReadInt("UseMDI", True): - self._documentRadioBox.SetSelection(1) + self._documentRadioBox.SetStringSelection(self._mdiChoice) else: - self._documentRadioBox.SetSelection(0) + self._documentRadioBox.SetStringSelection(self._sdiChoice) def OnDocumentInterfaceSelect(event): if not self._documentInterfaceMessageShown: msgTitle = wx.GetApp().GetAppName() @@ -1457,7 +1486,7 @@ class GeneralOptionsPanel(wx.Panel): wx.EVT_RADIOBOX(self, self._documentRadioBox.GetId(), OnDocumentInterfaceSelect) optionsBorderSizer = wx.BoxSizer(wx.VERTICAL) optionsSizer = wx.BoxSizer(wx.VERTICAL) - if wx.GetApp().GetService(DocOptionsService).GetAllowModeChanges(): + if self._AllowModeChanges(): optionsSizer.Add(self._documentRadioBox, 0, wx.ALL, HALF_SPACE) optionsSizer.Add(self._showTipsCheckBox, 0, wx.ALL, HALF_SPACE) optionsBorderSizer.Add(optionsSizer, 0, wx.ALL, SPACE) @@ -1467,15 +1496,20 @@ class GeneralOptionsPanel(wx.Panel): parent.AddPage(self, _("Options")) + def _AllowModeChanges(self): + supportedModes = wx.GetApp().GetService(DocOptionsService).GetSupportedModes() + return supportedModes & wx.lib.docview.DOC_SDI and supportedModes & wx.lib.docview.DOC_MDI or wx.Platform == "__WXMSW__" and supportedModes & wx.lib.docview.DOC_MDI # More than one mode is supported, allow selection + + def OnOK(self, optionsDialog): """ Updates the config based on the selections in the options panel. """ config = wx.ConfigBase_Get() config.WriteInt("ShowTipAtStartup", self._showTipsCheckBox.GetValue()) - if wx.GetApp().GetService(DocOptionsService).GetAllowModeChanges(): - config.WriteInt("UseMDI", (self._documentRadioBox.GetSelection() == 1)) - config.WriteInt("UseWinMDI", (self._documentRadioBox.GetSelection() == 2)) + if self._AllowModeChanges(): + config.WriteInt("UseMDI", (self._documentRadioBox.GetStringSelection() == self._mdiChoice)) + config.WriteInt("UseWinMDI", (self._documentRadioBox.GetStringSelection() == self._winMdiChoice)) class DocApp(wx.PySimpleApp): @@ -1793,7 +1827,7 @@ class DocApp(wx.PySimpleApp): return frame - def CreateSDIDocumentFrame(self, doc, view, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE): + def CreateSDIDocumentFrame(self, doc, view, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): """ Creates and returns an SDI Document Frame. """ @@ -1801,7 +1835,7 @@ class DocApp(wx.PySimpleApp): return frame - def CreateTabbedDocumentFrame(self, doc, view, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE): + def CreateTabbedDocumentFrame(self, doc, view, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): """ Creates and returns an MDI Document Frame for a Tabbed MDI view """ @@ -1809,7 +1843,7 @@ class DocApp(wx.PySimpleApp): return frame - def CreateMDIDocumentFrame(self, doc, view, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE): + def CreateMDIDocumentFrame(self, doc, view, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): """ Creates and returns an MDI Document Frame. """ @@ -1924,7 +1958,7 @@ class DocApp(wx.PySimpleApp): - def CreateChildDocument(self, parentDocument, documentType, objectToEdit, path = ''): + def CreateChildDocument(self, parentDocument, documentType, objectToEdit, path=''): """ Creates a child window of a document that edits an object. The child window is managed by the parent document frame, so it will be prompted to close if its @@ -2043,7 +2077,7 @@ class DocMDIParentFrame(wx.lib.docview.DocMDIParentFrame, DocFrameMixIn, DocMDIP """ - def __init__(self, docManager, parent, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "DocMDIFrame", embeddedWindows = 0): + def __init__(self, docManager, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="DocMDIFrame", embeddedWindows=0): """ Initializes the DocMDIParentFrame with the default menubar, toolbar, and status bar. Use the optional embeddedWindows parameter with the embedded window constants to create embedded @@ -2148,7 +2182,7 @@ class DocSDIFrame(wx.lib.docview.DocChildFrame, DocFrameMixIn): """ - def __init__(self, doc, view, parent, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "DocSDIFrame"): + def __init__(self, doc, view, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="DocSDIFrame"): """ Initializes the DocSDIFrame with the default menubar, toolbar, and status bar. """ @@ -2374,7 +2408,7 @@ class FilePropertiesService(DocService): self._customEventHandlers = [] - def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None): + def InstallControls(self, frame, menuBar=None, toolBar=None, statusBar=None, document=None): """ Installs a File/Properties menu item. """ @@ -2418,7 +2452,7 @@ class FilePropertiesService(DocService): return False - def ShowPropertiesDialog(self, filename = None): + def ShowPropertiesDialog(self, filename=None): """ Shows the PropertiesDialog for the specified file. """ @@ -2453,7 +2487,7 @@ class FilePropertiesService(DocService): self._customEventHandlers.remove(handler) - def chopPath(self, text, length = 36): + def chopPath(self, text, length=36): """ Simple version of textwrap. textwrap.fill() unfortunately chops lines at spaces and creates odd word boundaries. Instead, we will chop the path without regard to @@ -2494,7 +2528,7 @@ class FilePropertiesDialog(wx.Dialog): """ Initializes the properties dialog. """ - wx.Dialog.__init__(self, parent, -1, _("File Properties"), size = (310, 330)) + wx.Dialog.__init__(self, parent, -1, _("File Properties"), size=(310, 330)) HALF_SPACE = 5 SPACE = 10 @@ -2635,14 +2669,14 @@ class ChildDocTemplate(wx.lib.docview.DocTemplate): """ - def __init__(self, manager, description, filter, dir, ext, docTypeName, viewTypeName, docType, viewType, flags = wx.lib.docview.TEMPLATE_INVISIBLE, icon = None): + def __init__(self, manager, description, filter, dir, ext, docTypeName, viewTypeName, docType, viewType, flags=wx.lib.docview.TEMPLATE_INVISIBLE, icon=None): """ Initializes the ChildDocTemplate. """ - wx.lib.docview.DocTemplate.__init__(self, manager, description, filter, dir, ext, docTypeName, viewTypeName, docType, viewType, flags = flags, icon = icon) + wx.lib.docview.DocTemplate.__init__(self, manager, description, filter, dir, ext, docTypeName, viewTypeName, docType, viewType, flags=flags, icon=icon) - def CreateDocument(self, path, flags, data = None, parentDocument = None): + def CreateDocument(self, path, flags, data=None, parentDocument=None): """ Called when a ChildDocument is to be created and does the minimum such that the ChildDocument looks like a real Document to the framework. @@ -2687,7 +2721,7 @@ class WindowMenuService(DocService): self.SELECT_MORE_WINDOWS_ID = wx.NewId() - def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None): + def InstallControls(self, frame, menuBar=None, toolBar=None, statusBar=None, document=None): """ Installs the Window menu. """ @@ -2796,7 +2830,7 @@ class WindowMenuService(DocService): return [self.SELECT_WINDOW_1_ID, self.SELECT_WINDOW_2_ID, self.SELECT_WINDOW_3_ID, self.SELECT_WINDOW_4_ID, self.SELECT_WINDOW_5_ID, self.SELECT_WINDOW_6_ID, self.SELECT_WINDOW_7_ID, self.SELECT_WINDOW_8_ID, self.SELECT_WINDOW_9_ID] - def _GetWindowMenuFrameList(self, currentFrame = None): + def _GetWindowMenuFrameList(self, currentFrame=None): """ Returns the Frame associated with each menu item in the Window menu. """ -- 2.45.2