]> git.saurik.com Git - wxWidgets.git/commitdiff
searching for plugins in XRCEDPATH
authorRoman Rolinsky <rolinsky@femagsoft.com>
Thu, 15 Mar 2007 02:30:13 +0000 (02:30 +0000)
committerRoman Rolinsky <rolinsky@femagsoft.com>
Thu, 15 Mar 2007 02:30:13 +0000 (02:30 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44814 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/wx/tools/XRCed/tree.py
wxPython/wx/tools/XRCed/xrced.py
wxPython/wx/tools/XRCed/xxx.py

index 10169a9a6070ebe8dd12c5ec4ef8f837fc458079..f384b15da5cfb281ff27d8f942b1d0283cd85812 100644 (file)
@@ -380,16 +380,12 @@ class PullDownMenu:
             ID_NEW.HELP_BUTTON: ('wxID_HELP', '&Help'),
             ID_NEW.CONTEXT_HELP_BUTTON: ('wxID_CONTEXT_HELP', '&Help'),
             }
-        self.clearCustom()
-
-    def clearCustom(self):
-        # Custom controls
-        self.custom = [['custom', 'User-defined controls']]
+        self.custom = ['custom', 'User-defined controls']
         self.customMap = {}        
         
     def addCustom(self, klass):
-        n = len(self.custom[0])-2
-        self.custom[0].append((ID_NEW.CUSTOM + n, klass))
+        n = len(self.custom)-2
+        self.custom.append((ID_NEW.CUSTOM + n, klass))
         self.customMap[ID_NEW.CUSTOM + n] = klass
 
 
@@ -429,6 +425,7 @@ class HighLightBox:
         l4 = wx.Window(w, -1, wx.Point(pos.x, pos.y + size.height - 2), wx.Size(size.width, 2))
         l4.SetBackgroundColour(wx.RED)
         self.lines = [l1, l2, l3, l4]
+        self.size = size
     # Move highlight to a new position
     def Replace(self, pos, size):
         if size.width == -1: size.width = 0
@@ -437,6 +434,7 @@ class HighLightBox:
         self.lines[1].SetDimensions(pos.x, pos.y, 2, size.height)
         self.lines[2].SetDimensions(pos.x + size.width - 2, pos.y, 2, size.height)
         self.lines[3].SetDimensions(pos.x, pos.y + size.height - 2, size.width, 2)
+        self.size = size
     # Remove it
     def Remove(self):
         map(wx.Window.Destroy, self.lines)
@@ -785,16 +783,22 @@ class XML_Tree(wx.TreeCtrl):
         if not obj or xxx.hasStyle and xxx.params.get('hidden', False):
             if g.testWin.highLight: g.testWin.highLight.Remove()
             return
-        pos = self.FindNodePos(item, obj)
+        pos = self.FindNodePos(item, obj)         
         size = obj.GetSize()
         # Highlight
         # Negative positions are not working quite well
-        if g.testWin.highLight:
-            g.testWin.highLight.Replace(pos, size)
+        hl = g.testWin.highLight
+        # If highlight object has the same size SetDimension does not repaint it
+        # so we must remove the old HL window
+        if hl and hl.size == size:
+            hl.Remove()
+            hl = None
+        if hl:
+            hl.Replace(pos, size)
         else:
-            g.testWin.highLight = HighLightBox(pos, size)
-        g.testWin.highLight.Refresh()
-        g.testWin.highLight.item = item
+            g.testWin.highLight = hl = HighLightBox(pos, size)
+        hl.Refresh()
+        hl.item = item
 
     def ShowTestWindow(self, item):
         xxx = self.GetPyData(item)
@@ -1130,8 +1134,8 @@ class XML_Tree(wx.TreeCtrl):
                     if xxx.__class__ is not xxxFrame:
                         m.Enable(ID_NEW.MENU_BAR, False)
                 # Add custom controls menu
-                if pullDownMenu.customMap:
-                    SetMenu(m, pullDownMenu.custom)
+                if len(pullDownMenu.custom) > 2:
+                    SetMenu(m, [pullDownMenu.custom])
                 m.AppendSeparator()
                 m.Append(ID_NEW.REF, 'reference...', 'Create object_ref node')
                 m.Append(ID_NEW.COMMENT, 'comment', 'Create comment node')
index c68015a2ee9db8c66ea4e1510c9e0def54a6793f..23cce5040b76369fbb12b5c15448179b7c9e4a43 100644 (file)
@@ -339,12 +339,6 @@ class Frame(wx.Frame):
         self.SetAutoLayout(True)
         self.SetSizer(sizer)
 
-        # Save sys.modules names
-        self.modules = set(sys.modules.keys())
-        
-        # Initialize
-        self.Clear()
-
         # Other events
         wx.EVT_IDLE(self, self.OnIdle)
         wx.EVT_CLOSE(self, self.OnCloseWindow)
@@ -1358,13 +1352,11 @@ Homepage: http://xrced.sourceforge.net\
                 conf.panelWidth, conf.panelHeight = self.miniFrame.GetSize()
         evt.Skip()
 
-
     def CreateLocalConf(self, path):
         name = os.path.splitext(path)[0]
         name += '.xcfg'
         return wx.FileConfig(localFilename=name)
 
-
     def Clear(self):
         self.dataFile = ''
         conf.localconf = None
@@ -1381,10 +1373,10 @@ Homepage: http://xrced.sourceforge.net\
                    xxxMenuBar, xxxMenu, xxxToolBar,
                    xxxWizard, xxxBitmap, xxxIcon]:
             self.maxIDs[cl] = 0
-        # Handlers
-        clearHandlers()
-        g.pullDownMenu.clearCustom()
-        # Delete modules imported from comment directives
+        # Restore handlers, menu, etc. to initial
+        setHandlers(self.handlers[:])
+        g.pullDownMenu.custom = self.custom[:]
+        # Remove modules imported from comment directives
         map(sys.modules.pop, [m for m in sys.modules if m not in self.modules])
 
     def SetModified(self, state=True):
@@ -1636,6 +1628,31 @@ Please upgrade wxWidgets to %d.%d.%d or higher.''' % MinWxVersion)
         # Create main frame
         frame = Frame(pos, size)
         frame.Show(True)
+        
+        # Load plugins
+        plugins = os.getenv('XRCEDPATH')
+        if plugins:
+            cwd = os.getcwd()
+            try:
+                for dir in plugins.split(':'):
+                    if os.path.isdir(dir):
+                        # Normalize
+                        dir = os.path.abspath(os.path.normpath(dir))
+                        sys.path = sys_path + [os.path.dirname(dir)]
+                        try:
+                            os.chdir(dir)
+                            __import__(os.path.basename(dir), globals(), locals(), ['*'])
+                        except:
+                            print traceback.print_exc()
+            finally:
+                os.chdir(cwd)
+        # Store important data
+        frame.handlers = getHandlers()[:]
+        frame.custom = g.pullDownMenu.custom[:]
+        frame.modules = set(sys.modules.keys())
+
+        # Initialize
+        frame.Clear()
 
         # Load file after showing
         if args:
index ecae28d752501c004970fff5c57dc020b2c7e09e..cdbc54c0307f7d8166e83a75beefb7706709fa61 100644 (file)
@@ -920,6 +920,11 @@ class xxxUnknown(xxxObject):
 # Comment
 
 _handlers = []                          # custom handler classes/funcs
+def getHandlers():
+    return _handlers
+def setHandlers(handlers):
+    global _handlers
+    _handlers = handlers
 _CFuncPtr = None                        # ctypes function type
 
 def register(hndlr):
@@ -935,13 +940,18 @@ def register(hndlr):
         _handlers.append(hndlr)
 
 def load_dl(path, localname=''):
-    """Load shared/dynamic library into xxx namespace."""
+    """Load shared/dynamic library into xxx namespace.
+
+    If path is not absolute or relative, try to find in the module's directory.
+    """
     if not localname:
         localname = os.path.basename(os.path.splitext(path)[0])
     try:
         import ctypes
         global _CFuncPtr
-        _CFuncPtr = ctypes._CFuncPtr
+        _CFuncPtr = ctypes._CFuncPtr    # use as a flag of loaded ctypes
+        #if not os.path.dirname(path) and os.path.isfile(path):
+            
     except ImportError:
         wx.LogError('ctypes module not found')
         globals()[localname] = None
@@ -974,10 +984,6 @@ def addHandlers():
                 wx.LogError('error adding XmlHandler: "%s"' % h)
                 print traceback.print_exc()
 
-def clearHandlers():
-    global _handlers
-    _handlers = []
-
 def custom(klassName, klass='unknown'):
     """Define custom control based on xrcClass.