X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bbf7159c8211a398e573122c66b93722f5125c60..ea5449ae514c2eba0dae9828cbed53b902b52d89:/wxPython/samples/ide/activegrid/tool/PythonEditor.py?ds=sidebyside diff --git a/wxPython/samples/ide/activegrid/tool/PythonEditor.py b/wxPython/samples/ide/activegrid/tool/PythonEditor.py index 876f42b6bf..ea5f6b71d1 100644 --- a/wxPython/samples/ide/activegrid/tool/PythonEditor.py +++ b/wxPython/samples/ide/activegrid/tool/PythonEditor.py @@ -25,6 +25,7 @@ import keyword # for GetAutoCompleteKeywordList import sys # for GetAutoCompleteKeywordList import MessageService # for OnCheckCode import OutlineService +from UICommon import CaseInsensitiveCompare try: import checker # for pychecker _CHECKER_INSTALLED = True @@ -49,6 +50,11 @@ class PythonDocument(CodeEditor.CodeDocument): class PythonView(CodeEditor.CodeView): + def GetCtrlClass(self): + """ Used in split window to instantiate new instances """ + return PythonCtrl + + def ProcessUpdateUIEvent(self, event): if not self.GetCtrl(): return False @@ -62,15 +68,13 @@ class PythonView(CodeEditor.CodeView): return CodeEditor.CodeView.ProcessUpdateUIEvent(self, event) - def GetCtrlClass(self): - """ Used in split window to instantiate new instances """ - return PythonCtrl - - def OnActivateView(self, activate, activeView, deactiveView): STCTextEditor.TextView.OnActivateView(self, activate, activeView, deactiveView) - if activate: - wx.CallAfter(self.LoadOutline) # need CallAfter because document isn't loaded yet + if activate and self.GetCtrl(): + if self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI: + self.LoadOutline() + else: + wx.CallAfter(self.LoadOutline) # need CallAfter because document isn't loaded yet def OnClose(self, deleteWindow = True): @@ -99,7 +103,7 @@ class PythonView(CodeEditor.CodeView): filterkw = filter(lambda item: item.lower().startswith(lowerHint), kw) # remove variables and methods that don't match hint kw = filterkw - kw.sort(self.CaseInsensitiveCompare) + kw.sort(CaseInsensitiveCompare) if hint: replaceLen = len(hint) @@ -119,6 +123,7 @@ class PythonView(CodeEditor.CodeView): # pychecker only works on files, doesn't take a stream or string input if self.GetDocument().IsModified(): dlg = wx.MessageDialog(self.GetFrame(), _("'%s' has been modfied and must be saved first. Save file and check code?") % filename, _("Check Code")) + dlg.CenterOnParent() val = dlg.ShowModal() dlg.Destroy() if val == wx.ID_OK: @@ -167,7 +172,7 @@ class PythonView(CodeEditor.CodeView): break if not foundView: - doc = wx.GetApp().GetDocumentManager().CreateDocument(filename, wx.lib.docview.DOC_SILENT) + doc = wx.GetApp().GetDocumentManager().CreateDocument(filename, wx.lib.docview.DOC_SILENT|wx.lib.docview.DOC_OPEN_ONCE) foundView = doc.GetFirstView() if foundView: @@ -269,11 +274,29 @@ class PythonInterpreterView(wx.lib.docview.View): return True +class PythonInterpreterDocument(wx.lib.docview.Document): + """ Generate Unique Doc Type """ + pass + + class PythonService(CodeEditor.CodeService): def __init__(self): CodeEditor.CodeService.__init__(self) + docManager = wx.GetApp().GetDocumentManager() + pythonInterpreterTemplate = wx.lib.docview.DocTemplate(docManager, + _("Python Interpreter"), + "*.Foobar", + "Foobar", + ".Foobar", + _("Python Interpreter Document"), + _("Python Interpreter View"), + PythonInterpreterDocument, + PythonInterpreterView, + flags = wx.lib.docview.TEMPLATE_INVISIBLE, + icon = getPythonIcon()) + docManager.AssociateTemplate(pythonInterpreterTemplate) def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None): @@ -308,7 +331,7 @@ class PythonService(CodeEditor.CodeService): docManager = wx.GetApp().GetDocumentManager() event.Check(False) for doc in docManager.GetDocuments(): - if isinstance(doc.GetFirstView(), PythonInterpreterView): + if isinstance(doc, PythonInterpreterDocument): event.Check(True) break return True @@ -318,35 +341,27 @@ class PythonService(CodeEditor.CodeService): def OnViewPythonInterpreter(self, event): for doc in wx.GetApp().GetDocumentManager().GetDocuments(): - if isinstance(doc.GetFirstView(), PythonInterpreterView): - doc.GetFirstView().GetDocument().DeleteAllViews() + if isinstance(doc, PythonInterpreterDocument): + doc.DeleteAllViews() return - docManager = self.GetDocumentManager() - template = wx.lib.docview.DocTemplate(docManager, - _("Python Interpreter"), - "*.Foobar", - "Foobar", - ".Foobar", - _("Python Interpreter Document"), - _("Python Interpreter View"), - wx.lib.docview.Document, - PythonInterpreterView, - flags = wx.lib.docview.TEMPLATE_INVISIBLE) - newDoc = template.CreateDocument('', wx.lib.docview.DOC_SILENT) - if newDoc: - newDoc.SetDocumentName(template.GetDocumentName()) - newDoc.SetDocumentTemplate(template) - newDoc.OnNewDocument() - newDoc.SetWriteable(False) - newDoc.GetFirstView().GetFrame().SetTitle(_("Python Interpreter")) + for template in self.GetDocumentManager().GetTemplates(): + if template.GetDocumentType() == PythonInterpreterDocument: + newDoc = template.CreateDocument('', wx.lib.docview.DOC_SILENT|wx.lib.docview.DOC_OPEN_ONCE) + if newDoc: + newDoc.SetDocumentName(template.GetDocumentName()) + newDoc.SetDocumentTemplate(template) + newDoc.OnNewDocument() + newDoc.SetWriteable(False) + newDoc.GetFirstView().GetFrame().SetTitle(_("Python Interpreter")) + break class PythonCtrl(CodeEditor.CodeCtrl): - def __init__(self, parent, ID = -1, style = wx.NO_FULL_REPAINT_ON_RESIZE): - CodeEditor.CodeCtrl.__init__(self, parent, ID, style) + def __init__(self, parent, id=-1, style=wx.NO_FULL_REPAINT_ON_RESIZE): + CodeEditor.CodeCtrl.__init__(self, parent, id, style) self.SetProperty("tab.timmy.whinge.level", "1") self.SetProperty("fold.comment.python", "1") self.SetProperty("fold.quotes.python", "1") @@ -355,7 +370,7 @@ class PythonCtrl(CodeEditor.CodeCtrl): def SetViewDefaults(self): - CodeEditor.CodeCtrl.SetViewDefaults(self, configPrefix = "Python", hasWordWrap = False, hasTabs = True) + CodeEditor.CodeCtrl.SetViewDefaults(self, configPrefix = "Python", hasWordWrap = True, hasTabs = True) def GetFontAndColorFromConfig(self): @@ -516,6 +531,7 @@ class PythonCtrl(CodeEditor.CodeCtrl): if doExtraIndent or len(textNoTrailingSpaces) and textNoTrailingSpaces[-1] == ':': spaces = spaces + ' ' * self.GetIndent() self.AddText('\n' + spaces) + self.EnsureCaretVisible() # Callback for tokenizer in self.DoIndent @@ -543,40 +559,56 @@ class PythonOptionsPanel(wx.Panel): choosePathButton = wx.Button(self, -1, _("Browse...")) pathSizer = wx.BoxSizer(wx.HORIZONTAL) HALF_SPACE = 5 - pathSizer.Add(pathLabel, 0, wx.ALIGN_LEFT | wx.LEFT | wx.RIGHT | wx.TOP, HALF_SPACE) - pathSizer.Add(self._pathTextCtrl, 0, wx.ALIGN_LEFT | wx.EXPAND | wx.RIGHT, HALF_SPACE) - pathSizer.Add(choosePathButton, 0, wx.ALIGN_RIGHT | wx.LEFT, HALF_SPACE) + SPACE = 10 + pathSizer.Add(pathLabel, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.TOP, HALF_SPACE) + pathSizer.Add(self._pathTextCtrl, 1, wx.EXPAND|wx.LEFT|wx.TOP, HALF_SPACE) + pathSizer.Add(choosePathButton, 0, wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT|wx.TOP, HALF_SPACE) wx.EVT_BUTTON(self, choosePathButton.GetId(), self.OnChoosePath) mainSizer = wx.BoxSizer(wx.VERTICAL) - mainSizer.Add(pathSizer, 0, wx.LEFT | wx.RIGHT | wx.TOP, 10) + mainSizer.Add(pathSizer, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, SPACE) - self._otherOptions = STCTextEditor.TextOptionsPanel(self, -1, configPrefix = "Python", label = "Python", hasWordWrap = False, hasTabs = True, addPage=False) - mainSizer.Add(self._otherOptions) + self._otherOptions = STCTextEditor.TextOptionsPanel(self, -1, configPrefix = "Python", label = "Python", hasWordWrap = True, hasTabs = True, addPage=False) + mainSizer.Add(self._otherOptions, 0, wx.EXPAND|wx.BOTTOM, SPACE) self.SetSizer(mainSizer) parent.AddPage(self, _("Python")) + def OnChoosePath(self, event): + defaultDir = os.path.dirname(self._pathTextCtrl.GetValue().strip()) + defaultFile = os.path.basename(self._pathTextCtrl.GetValue().strip()) if _WINDOWS: - wildcard = _("*.exe") + wildcard = _("Executable (*.exe)|*.exe|All (*.*)|*.*") + if not defaultFile: + defaultFile = "python.exe" else: wildcard = _("*") - path = wx.FileSelector(_("Select a File"), - _(""), - _(""), - wildcard = wildcard , - flags = wx.HIDE_READONLY, - parent = wx.GetApp().GetTopWindow()) - if path: - self._pathTextCtrl.SetValue(path) - self._pathTextCtrl.SetToolTipString(self._pathTextCtrl.GetValue()) - self._pathTextCtrl.SetInsertionPointEnd() + dlg = wx.FileDialog(wx.GetApp().GetTopWindow(), + _("Select a File"), + defaultDir=defaultDir, + defaultFile=defaultFile, + wildcard=wildcard, + style=wx.OPEN|wx.FILE_MUST_EXIST|wx.HIDE_READONLY) + # dlg.CenterOnParent() # wxBug: caused crash with wx.FileDialog + if dlg.ShowModal() == wx.ID_OK: + path = dlg.GetPath() + if path: + self._pathTextCtrl.SetValue(path) + self._pathTextCtrl.SetToolTipString(self._pathTextCtrl.GetValue()) + self._pathTextCtrl.SetInsertionPointEnd() + dlg.Destroy() + def OnOK(self, optionsDialog): - if len(self._pathTextCtrl.GetValue()) > 0: - config = wx.ConfigBase_Get() - config.Write("ActiveGridPythonLocation", self._pathTextCtrl.GetValue()) + config = wx.ConfigBase_Get() + config.Write("ActiveGridPythonLocation", self._pathTextCtrl.GetValue().strip()) self._otherOptions.OnOK(optionsDialog) + + + def GetIcon(self): + return getPythonIcon() + + #---------------------------------------------------------------------------- # Icon Bitmaps - generated by encode_bitmaps.py #---------------------------------------------------------------------------- @@ -586,18 +618,28 @@ import cStringIO def getPythonData(): return \ -"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ +'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ -\x00\x00\xd5IDAT8\x8d\x8d\x93Y\x0e\xc3 \x0cD\x9fM\xcf\xddNr2.\x96\xb8\x1f\ -\x05\n\x84.#Y\x10\xa3\x19o\xb1\x99'*\xe2<\x82\x0e\xe6\xc9\xf8\x01\xef?\xa4\ -\xf7)]\x05\x970O\xcdr\xce!\x119\xe7\x00\x02\x88\xfe}i\xb5\x848\x8f\xa8\x19\ -\xcc\x19}+\xc5\xcc\xd3\x92\x18\x0f\xb8\xb7\x95a\xe9\xca\x0b:\x8e\xed\ +\xca\x01E\x1a\x00\x98\r\x89\x92\x91\xa1\xda\xd8\x87\x06ha\x1f\x1b\x80\xcd\ +\x9d%\xe0\xa5\x0f"[G\x87\x98\x8d\xde/ia\x05-\xac`\x996\xf9\\\x0b\xcb\xb4)\ +\x1bmOMn\xf7\xd5\xf0\'\\\x8b\xdces\xe7\x8d\xef\x80h\xd6\xc2\n\xf9\\\x0b]\xf5\ +\xab\xf2\xcdApR#\xf1kp4b\xc9 \xf9\\\x0b\x80\xe4\xcdE\xaf\xdeqlW\xaeVL\xaf`~\ +\xd9\x03@W\xd3\x00\xc4\x13\x0b\xc4\x92A\xcf\xd0\xf9\xe8:\x89\xebW\x01(|\xfd\ +\xe1\xbe-~F\xbas\xff\x91\xf75\x82n\x9d\x1c\xf0}\xfciw\xdd\xe7A<\xd1\x1b\xa8j\ +c\x9f\xb2\xd1F\x92\xe4\x80O\x12\xc0\xc6\xb3\x14\xf6Ta\xe0)g\x81\xba\x9a\xf6\ +\x9b(\x07\x14I@\x84lq\xb8?\xe6\xa3\xeb\x00\xdc\xba\x9d\xf4+\x10*~\xfem\xf3\ +\xf8\xe1\x06\xc7\xa7\xdb\xe8j\x9a\xf8\xdc\xa4\xb7\x1f[\\\xe5\xd2\x851/\xff\ +\x07\xac\x9b\xd1e\x12\x96\x0f\xfd\x00\x00\x00\x00IEND\xaeB`\x82' def getPythonBitmap():