]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxPython/src/_extras.py
Fixed bug in DnD. wxDragSource will now delete itself when done.
[wxWidgets.git] / utils / wxPython / src / _extras.py
index 46bea0855f86c238c14fee7f2abcc80705974c19..cdff6809b30ff810c7a7a18817c6f447a3017b08 100644 (file)
@@ -277,6 +277,69 @@ 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_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)
+
+def EVT_SCROLLWIN_TOP(win, func):
+    win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func)
+
+def EVT_SCROLLWIN_BOTTOM(win, func):
+    win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func)
+
+def EVT_SCROLLWIN_LINEUP(win, func):
+    win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func)
+
+def EVT_SCROLLWIN_LINEDOWN(win, func):
+    win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func)
+
+def EVT_SCROLLWIN_PAGEUP(win, func):
+    win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func)
+
+def EVT_SCROLLWIN_PAGEDOWN(win, func):
+    win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func)
+
+def EVT_SCROLLWIN_THUMBTRACK(win, func):
+    win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, 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)
+
+def EVT_COMMAND_SCROLLWIN_TOP(win, id, func):
+    win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func)
+
+def EVT_COMMAND_SCROLLWIN_BOTTOM(win, id, func):
+    win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func)
+
+def EVT_COMMAND_SCROLLWIN_LINEUP(win, id, func):
+    win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func)
+
+def EVT_COMMAND_SCROLLWIN_LINEDOWN(win, id, func):
+    win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func)
+
+def EVT_COMMAND_SCROLLWIN_PAGEUP(win, id, func):
+    win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func)
+
+def EVT_COMMAND_SCROLLWIN_PAGEDOWN(win, id, func):
+    win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func)
+
+def EVT_COMMAND_SCROLLWIN_THUMBTRACK(win, id, func):
+    win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func)
 
 # Convenience commands
 def EVT_BUTTON(win, id, func):
@@ -409,6 +472,15 @@ def EVT_TREE_KEY_DOWN(win, id, func):
 def EVT_TREE_DELETE_ITEM(win, id, func):
     win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
 
+def EVT_TREE_ITEM_ACTIVATED(win, id, func):
+    win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
+
+def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
+    win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
+
+def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
+    win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
+
 
 # wxSpinButton
 def EVT_SPIN_UP(win, id, func):
@@ -538,6 +610,14 @@ def EVT_LIST_INSERT_ITEM(win, id, func):
 def EVT_LIST_COL_CLICK(win, id, func):
     win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
 
+def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
+    win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
+
+def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
+    win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
+
+
+
 #wxSplitterWindow
 def EVT_SPLITTER_SASH_POS_CHANGING(win, id, func):
     win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, func)
@@ -580,22 +660,14 @@ wxPyDefaultPosition.Set(-1,-1)
 wxPyDefaultSize.Set(-1,-1)
 
 # aliases so that C++ documentation applies:
-wxDefaultPosition = wxPyDefaultPosition
-wxDefaultSize     = wxPyDefaultSize
-
+wxDefaultPosition  = wxPyDefaultPosition
+wxDefaultSize      = wxPyDefaultSize
 
-# This is to cover up a bug in SWIG.  We are redefining
-# the shadow class that is generated for wxAcceleratorTable
-# because SWIG incorrectly uses "arg0.this"
-class wxAcceleratorTable(wxAcceleratorTablePtr):
-    def __init__(self,arg0) :
-        self.this = miscc.new_wxAcceleratorTable(arg0)
-        self.thisown = 1
 
 #----------------------------------------------------------------------
 # This helper function will take a wxPython object and convert it to
 # another wxPython object type.  This will not be able to create objects
-# user that are derived from wxPython classes, only those that are
+# that are derived from wxPython classes by the user, only those that are
 # actually part of wxPython and directly corespond to C++ objects.
 #
 # This is useful in situations where some method returns a generic
@@ -626,31 +698,36 @@ def wxPyTypeCast(obj, typeStr):
 
 #----------------------------------------------------------------------
 
-##  class wxPyStdOutWindow:
-##       def __init__(self, title = "wxPython: stdout/stderr"):
-##          self.frame = None
-##          self.title = title
+class wxPyOnDemandOutputWindow:
+    def __init__(self, title = "wxPython: stdout/stderr"):
+        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
 
-##      def write(self, str):
-##          if not self.frame:
-##              self.frame = wxFrame(NULL, -1, self.title)
-##              self.text  = wxTextCtrl(self.frame, -1, "", wxPoint(0,0), wxDefaultSize,
-##                                      wxTE_MULTILINE|wxTE_READONLY)
-##              self.frame.SetSize(wxSize(450, 300))
-##              self.frame.Show(true)
-##              EVT_CLOSE(self.frame, self.OnCloseWindow)
-##          self.text.AppendText(str)
+    # this provides the file-like behaviour
+    def write(self, str):
+        if not self.frame:
+            self.frame = wxFrame(self.parent, -1, self.title)
+            self.text  = wxTextCtrl(self.frame, -1, "",
+                                    style = wxTE_MULTILINE|wxTE_READONLY)
+            self.frame.SetSize(wxSize(450, 300))
+            self.frame.Show(true)
+            EVT_CLOSE(self.frame, self.OnCloseWindow)
+        self.text.AppendText(str)
 
-##      def OnCloseWindow(self, event):
-##          wxBell()
-##          self.frame.Destroy()
-##          self.frame = None
-##          self.text  = None
+    def close(self):
+        self.frame = None
+        self.text  = None
 
 
-##      def close(self):
-##          if self.frame:
-##              self.frame.Close(true)
 
 _defRedirect = (wxPlatform == '__WXMSW__')
 
@@ -660,6 +737,7 @@ _defRedirect = (wxPlatform == '__WXMSW__')
 
 class wxApp(wxPyApp):
     error = 'wxApp.error'
+    outputWindowClass = wxPyOnDemandOutputWindow
 
     def __init__(self, redirect=_defRedirect, filename=None):
         wxPyApp.__init__(self)
@@ -667,7 +745,6 @@ class wxApp(wxPyApp):
         self.saveStdio = (sys.stdout, sys.stderr)
         if redirect:
             self.RedirectStdio(filename)
-
         # this initializes wxWindows and then calls our OnInit
         _wxStart(self.OnInit)
 
@@ -678,12 +755,22 @@ class wxApp(wxPyApp):
         except:
             pass
 
+
+    def SetTopWindow(self, frame):
+        if self.stdioWin:
+            self.stdioWin.SetParent(frame)
+            sys.stdout = self.stdioWin #sys.stderr =
+        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:
-            #raise self.error, 'wxPyStdOutWindow not yet implemented.'
-            self.stdioWin = sys.stdout = sys.stderr = wxPyStdOutWindow()
+            self.stdioWin = self.outputWindowClass() # wxPyOnDemandOutputWindow
 
     def RestoreStdio(self):
         sys.stdout, sys.stderr = self.saveStdio
@@ -691,9 +778,19 @@ class wxApp(wxPyApp):
             self.stdioWin.close()
 
 
+
 #----------------------------------------------------------------------------
 # DO NOT hold any other references to this object.  This is how we know when
-# to cleanup system resources that wxWin is holding...
+# to cleanup system resources that wxWin is holding.  When this module is
+# unloaded, the refcount on __cleanMeUp goes to zero and it calls the
+# wxApp_CleanUp function.
+
+class __wxPyCleanup:
+    def __init__(self):
+        self.cleanup = wxc.wxApp_CleanUp
+    def __del__(self):
+        self.cleanup()
+
 __cleanMeUp = __wxPyCleanup()
 #----------------------------------------------------------------------------