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
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
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)
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)
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')
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)
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
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):
# 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:
# 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):
_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
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.