X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3af4e610b182d2aeb504bdeeef8b44cb1279f28e..a4bde64fd21e48073d8833de15251c7f012e9752:/utils/wxPython/src/_extras.py?ds=inline diff --git a/utils/wxPython/src/_extras.py b/utils/wxPython/src/_extras.py index 53cb1132af..24a2e61146 100644 --- a/utils/wxPython/src/_extras.py +++ b/utils/wxPython/src/_extras.py @@ -29,12 +29,6 @@ def _checkForCallback(obj, name, event, theID=-1): except: pass else: obj.Connect(theID, -1, event, cb) -## def _checkClassCallback(obj, name): -## try: cb = getattr(obj, name) -## except: pass -## else: obj._addCallback(name, cb) - - def _StdWindowCallbacks(win): _checkForCallback(win, "OnChar", wxEVT_CHAR) _checkForCallback(win, "OnSize", wxEVT_SIZE) @@ -153,10 +147,10 @@ def EVT_QUERY_NEW_PALETTE(win, func): win.Connect(-1, -1, wxEVT_QUERY_NEW_PALETTE, func) def EVT_WINDOW_CREATE(win, func): - win.Connect(-1, -1, wxEVT_WINDOW_CREATE, func) + win.Connect(-1, -1, wxEVT_CREATE, func) def EVT_WINDOW_DESTROY(win, func): - win.Connect(-1, -1, wxEVT_WINDOW_DESTROY, func) + win.Connect(-1, -1, wxEVT_DESTROY, func) @@ -733,15 +727,18 @@ class wxPyOnDemandOutputWindow: self.frame = None self.title = title + def SetParent(self, parent): self.parent = parent + def OnCloseWindow(self, event): if self.frame != None: self.frame.Destroy() self.frame = None self.text = None + # this provides the file-like behaviour def write(self, str): if not self.frame: @@ -753,7 +750,10 @@ class wxPyOnDemandOutputWindow: EVT_CLOSE(self.frame, self.OnCloseWindow) self.text.AppendText(str) + def close(self): + if self.frame != None: + self.frame.Destroy() self.frame = None self.text = None @@ -789,19 +789,22 @@ class wxApp(wxPyApp): def SetTopWindow(self, frame): if self.stdioWin: self.stdioWin.SetParent(frame) - sys.stdout = self.stdioWin #sys.stderr = + sys.stderr = sys.stdout = self.stdioWin wxPyApp.SetTopWindow(self, frame) + def MainLoop(self): wxPyApp.MainLoop(self) self.RestoreStdio() + def RedirectStdio(self, filename): if filename: sys.stdout = sys.stderr = open(filename, 'a') else: self.stdioWin = self.outputWindowClass() # wxPyOnDemandOutputWindow + def RestoreStdio(self): sys.stdout, sys.stderr = self.saveStdio if self.stdioWin != None: