--- a/LPCBeremiz.py Thu Jun 03 17:17:51 2010 +0200
+++ b/LPCBeremiz.py Thu Jun 03 17:21:40 2010 +0200
@@ -42,23 +42,15 @@
- def AddCatalogLookupPathPrefix(self, localedir):
- self.LocaleDirs.append(localedir)
- def AddCatalog(self, domain):
- self.Domains.append(domain)
+app.SetAppName('beremiz') +wx.InitAllImageHandlers() # Import module for internationalization
-__builtin__.__dict__['loc'] = PseudoLocale()
if __name__ == '__main__':
__builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
@@ -1059,38 +1051,6 @@
if not locations_infos["root"]["expanded"]:
self.CollapseLocation(locations_infos, "root")
-def MainLoopProc(plugin_root):
- app.SetAppName('beremiz')
- wx.InitAllImageHandlers()
- # Get the english language
- langid = wx.LANGUAGE_ENGLISH
- # Import module for internationalization
- loc = wx.Locale(langid)
- for localedir in PseudoLocale.LocaleDirs:
- loc.AddCatalogLookupPathPrefix(localedir)
- for domain in PseudoLocale.Domains:
- __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
- # Install a exception handle for bug reports
- AddExceptHook(os.getcwd(),__version__)
- frame = LPCBeremiz(None, plugin_root=plugin_root, debug=True)
""" Base class for file like objects to facilitate StdOut for the Shell."""
def write(self, s, style = None):
@@ -1111,31 +1071,43 @@
if __name__ == '__main__':
- from threading import Thread, Timer
+ from threading import Thread, Timer, Semaphore + wx_eval_lock = Semaphore(0) + def wx_evaluator(callable, *args, **kwargs): + eval_res=callable(*args,**kwargs) + def evaluator(callable, *args, **kwargs): + wx.CallAfter(wx_evaluator,callable,*args,**kwargs) + # Command log for debug, for viewing from wxInspector + __builtins__.cmdlog = [] + cmdlogf=open("bmzcmdlog.txt","w") class LPCBeremiz_Cmd(cmd.Cmd):
- Log = StdoutPseudoFile()
- def __init__(self, projectOpen, buildpath):
+ def __init__(self, PluginRoot, Log): - self.PluginRoot = LPCPluginsRoot(None, self.Log)
- if projectOpen is not None and os.path.isdir(projectOpen):
- result = self.PluginRoot.LoadProject(projectOpen, buildpath)
- print "Error: Invalid project directory", result
- print "Error: No such file or directory"
- beremiz_thread=Thread(target=MainLoopProc, args=[self.PluginRoot])
+ self.PluginRoot = PluginRoot if self.RefreshTimer is not None:
self.RefreshTimer.cancel()
- self.RefreshTimer = Timer(0.1, self.Refresh)
+ self.RefreshTimer = Timer(0.1, wx.CallAfter, args = [self.Refresh]) self.RefreshTimer.start()
@@ -1151,25 +1123,25 @@
self.PluginRoot.SetAppFrame(frame, frame.Log)
- wx.CallAfter(frame.Show)
- wx.CallAfter(frame.Raise)
- wx.CallAfter(frame._Refresh, TITLE, INSTANCESTREE, FILEMENU, EDITMENU)
- wx.CallAfter(frame.RefreshEditor)
- wx.CallAfter(frame.RefreshAll)
+ frame._Refresh(TITLE, INSTANCESTREE, FILEMENU, EDITMENU) self.PluginRoot.ResetAppFrame(self.Log)
- wx.CallAfter(frame.Hide)
- wx.CallAfter(self.PluginRoot._build)
+ self.PluginRoot._build() def SetProjectProperties(self, projectname, productname, productversion, companyname):
properties = self.PluginRoot.GetProjectProperties()
@@ -1181,7 +1153,7 @@
def SetOnlineMode(self, mode, path=None):
- wx.CallAfter(self.PluginRoot.SetOnlineMode, mode, path)
+ self.PluginRoot.SetOnlineMode(mode, path) def AddBus(self, iec_channel, name, icon=None):
@@ -1217,7 +1189,7 @@
self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel),
- wx.CallAfter(self.PluginRoot.UpdateProjectVariableLocation,
+ self.PluginRoot.UpdateProjectVariableLocation( bus.BaseParams.setIEC_Channel(new_iec_channel)
@@ -1401,7 +1373,18 @@
print "Error: Invalid value for argument %d" % (num + 1)
- res = getattr(self, function)(*args)
+ cmdlogf.write(str((function,line))+'\n') + func = getattr(self, function) + res = evaluator(func,*args) + cmdlogf.write("--->"+str(res)+'\n') + cmdlog.append((function,line,res)) + if len(cmdlog) > 100: #prevent debug log to grow too much if isinstance(res, (StringType, UnicodeType)):
@@ -1409,29 +1392,49 @@
+ def CmdThreadProc(PluginRoot, Log): + for function, (arg_types, opt) in {"Exit": ([], 0), + "SetProjectProperties": ([str, str, str, str], 0), + "SetOnlineMode": ([str, str], 1), + "AddBus": ([int, str, str], 1), + "RenameBus": ([int, str], 0), + "ChangeBusIECChannel": ([int, int], 0), + "RemoveBus": ([int], 0), + "AddModule": ([location, int, str, str], 1), + "RenameModule": ([location, str], 0), + "ChangeModuleIECChannel": ([location, int], 0), + "RemoveModule": ([location, int], 0), + "StartGroup": ([location, str, str], 1), + "AddVariable": ([location, location, str, str, str, str, str, str, str], 1), + "ChangeVariableParams": ([location, location, str, str, str, str, str, str, str], 1), + "RemoveVariable": ([location, location], 0)}.iteritems(): + setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt)) + lpcberemiz_cmd = LPCBeremiz_Cmd(PluginRoot, Log) + lpcberemiz_cmd.cmdloop() + Log = StdoutPseudoFile() + PluginRoot = LPCPluginsRoot(None, Log) + if projectOpen is not None and os.path.isdir(projectOpen): + result = PluginRoot.LoadProject(projectOpen, buildpath) + print "Error: Invalid project directory", result + print "Error: No such file or directory" - for function, (arg_types, opt) in {"Exit": ([], 0),
- "SetProjectProperties": ([str, str, str, str], 0),
- "SetOnlineMode": ([str, str], 1),
- "AddBus": ([int, str, str], 1),
- "RenameBus": ([int, str], 0),
- "ChangeBusIECChannel": ([int, int], 0),
- "RemoveBus": ([int], 0),
- "AddModule": ([location, int, str, str], 1),
- "RenameModule": ([location, str], 0),
- "ChangeModuleIECChannel": ([location, int], 0),
- "RemoveModule": ([location, int], 0),
- "StartGroup": ([location, str, str], 1),
- "AddVariable": ([location, location, str, str, str, str, str, str, str], 1),
- "ChangeVariableParams": ([location, location, str, str, str, str, str, str, str], 1),
- "RemoveVariable": ([location, location], 0)}.iteritems():
- setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
+ cmd_thread=Thread(target=CmdThreadProc, args=[PluginRoot, Log]) + # Install a exception handle for bug reports + AddExceptHook(os.getcwd(),__version__) - lpcberemiz_cmd = LPCBeremiz_Cmd(projectOpen, buildpath)
- lpcberemiz_cmd.cmdloop()
+ frame = LPCBeremiz(None, plugin_root=PluginRoot, debug=True)