X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b1462dfa3496ba7288691376c1de4c890d90787c..85bc0351f76f6d3f00460a167fc108b900e0725c:/utils/wxPython/src/_extras.py diff --git a/utils/wxPython/src/_extras.py b/utils/wxPython/src/_extras.py index cdff6809b3..a3d76e54f5 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) @@ -146,12 +140,29 @@ def EVT_ICONIZE(win, func): def EVT_NAVIGATION_KEY(win, func): win.Connect(-1, -1, wxEVT_NAVIGATION_KEY, func) +def EVT_PALETTE_CHANGED(win, func): + win.Connect(-1, -1, wxEVT_PALETTE_CHANGED, func) + +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_CREATE, func) + +def EVT_WINDOW_DESTROY(win, func): + win.Connect(-1, -1, wxEVT_DESTROY, func) + + + def EVT_IDLE(win, func): win.Connect(-1, -1, wxEVT_IDLE, func) def EVT_UPDATE_UI(win, id, func): win.Connect(id, -1, wxEVT_UPDATE_UI, func) +def EVT_UPDATE_UI_RANGE(win, id, id2, func): + win.Connect(id, id2, wxEVT_UPDATE_UI, func) + # Mouse Events def EVT_LEFT_DOWN(win, func): @@ -213,6 +224,7 @@ def EVT_COMMAND(win, id, cmd, func): def EVT_COMMAND_RANGE(win, id1, id2, cmd, func): win.Connect(id1, id2, cmd, func) + # Scrolling def EVT_SCROLL(win, func): win.Connect(-1, -1, wxEVT_SCROLL_TOP, func) @@ -222,6 +234,7 @@ def EVT_SCROLL(win, func): win.Connect(-1, -1, wxEVT_SCROLL_PAGEUP, func) win.Connect(-1, -1, wxEVT_SCROLL_PAGEDOWN, func) win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK,func) + win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE,func) def EVT_SCROLL_TOP(win, func): win.Connect(-1, -1, wxEVT_SCROLL_TOP, func) @@ -244,6 +257,9 @@ def EVT_SCROLL_PAGEDOWN(win, func): def EVT_SCROLL_THUMBTRACK(win, func): win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK, func) +def EVT_SCROLL_THUMBRELEASE(win, func): + win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE, func) + # Scrolling, with an id @@ -255,6 +271,7 @@ def EVT_COMMAND_SCROLL(win, id, func): win.Connect(id, -1, wxEVT_SCROLL_PAGEUP, func) win.Connect(id, -1, wxEVT_SCROLL_PAGEDOWN, func) win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func) + win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE,func) def EVT_COMMAND_SCROLL_TOP(win, id, func): win.Connect(id, -1, wxEVT_SCROLL_TOP, func) @@ -277,15 +294,19 @@ def EVT_COMMAND_SCROLL_PAGEDOWN(win, id, func): def EVT_COMMAND_SCROLL_THUMBTRACK(win, id, func): win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK, func) +def EVT_COMMAND_SCROLL_THUMBRELEASE(win, id, func): + win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE, func) + #--- def EVT_SCROLLWIN(win, func): - win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func) - win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func) - win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func) - win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func) - win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func) - win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) - win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK,func) + win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func) + win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func) + win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func) + win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func) + win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func) + win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) + win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) + win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func) def EVT_SCROLLWIN_TOP(win, func): win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func) @@ -308,17 +329,21 @@ def EVT_SCROLLWIN_PAGEDOWN(win, func): def EVT_SCROLLWIN_THUMBTRACK(win, func): win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) +def EVT_SCROLLWIN_THUMBRELEASE(win, func): + win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func) + # Scrolling, with an id def EVT_COMMAND_SCROLLWIN(win, id, func): - win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func) - win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func) - win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func) - win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func) - win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func) - win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) - win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK,func) + win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func) + win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func) + win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func) + win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func) + win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func) + win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) + win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) + win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func) def EVT_COMMAND_SCROLLWIN_TOP(win, id, func): win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func) @@ -341,6 +366,10 @@ def EVT_COMMAND_SCROLLWIN_PAGEDOWN(win, id, func): def EVT_COMMAND_SCROLLWIN_THUMBTRACK(win, id, func): win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) +def EVT_COMMAND_SCROLLWIN_THUMBRELEASE(win, id, func): + win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func) + + # Convenience commands def EVT_BUTTON(win, id, func): win.Connect(id, -1, wxEVT_COMMAND_BUTTON_CLICKED, func) @@ -387,15 +416,25 @@ def EVT_COMBOBOX(win, id, func): def EVT_TOOL(win, id, func): win.Connect(id, -1, wxEVT_COMMAND_TOOL_CLICKED, func) +def EVT_TOOL_RANGE(win, id, id2, func): + win.Connect(id, id2, wxEVT_COMMAND_TOOL_CLICKED, func) + def EVT_TOOL_RCLICKED(win, id, func): win.Connect(id, -1, wxEVT_COMMAND_TOOL_RCLICKED, func) +def EVT_TOOL_RCLICKED_RANGE(win, id, id2, func): + win.Connect(id, id2, wxEVT_COMMAND_TOOL_RCLICKED, func) + def EVT_TOOL_ENTER(win, id, func): win.Connect(id, -1, wxEVT_COMMAND_TOOL_ENTER, func) def EVT_CHECKLISTBOX(win, id, func): win.Connect(id, -1, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, func) +def EVT_SPINCTRL(win, id, func): + win.Connect(id, -1, wxEVT_COMMAND_SPINCTRL_UPDATED, func) + + # Generic command events @@ -663,6 +702,8 @@ wxPyDefaultSize.Set(-1,-1) wxDefaultPosition = wxPyDefaultPosition wxDefaultSize = wxPyDefaultSize +# backwards compatibility +wxNoRefBitmap = wxBitmap #---------------------------------------------------------------------- # This helper function will take a wxPython object and convert it to @@ -692,7 +733,8 @@ def wxPyTypeCast(obj, typeStr): newPtr = ptrcast(obj, typeStr+"_p") theClass = globals()[typeStr+"Ptr"] theObj = theClass(newPtr) - theObj.thisown = obj.thisown + if hasattr(obj, "this"): + theObj.thisown = obj.thisown return theObj @@ -703,15 +745,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: @@ -723,7 +768,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 @@ -759,24 +807,34 @@ 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: self.stdioWin.close() +#---------------------------------------------------------------------------- + +class wxPySimpleApp(wxApp): + def __init__(self): + wxApp.__init__(self, 0) + def OnInit(self): + return true #----------------------------------------------------------------------------