From daa6ab8a750fa2c052fe0a2295b0187fc640cbe0 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Wed, 25 Nov 2020 10:03:02 +0100 Subject: [PATCH] bug fix --- ConnectionThread.py | 1 - Container.py | 2 +- .../pypdevs221/src/classicDEVSWrapper.py | 2 +- LibraryTree.py | 6 ++-- Patterns/Factory.py | 3 +- Patterns/Strategy.py | 1 - PluginsGUI.py | 31 +++++++++++++++++-- SimulationGUI.py | 26 ++++++++++++++-- Utilities.py | 2 +- ZipManager.py | 24 +++++++------- 10 files changed, 72 insertions(+), 26 deletions(-) diff --git a/ConnectionThread.py b/ConnectionThread.py index 83bd3b3e..91b1ff31 100644 --- a/ConnectionThread.py +++ b/ConnectionThread.py @@ -111,7 +111,6 @@ def __init__(self, parent): self.setDaemon(True) self.start() - def LoadZip(self, url): """ """ diff --git a/Container.py b/Container.py index c32cb28f..fc2420e2 100644 --- a/Container.py +++ b/Container.py @@ -247,7 +247,7 @@ def CheckClass(m): devs = getInstance(cls, args) ### check instance error - return devs if isinstance(devs, tuple) else None + return devs if isinstance(devs, tuple) or isinstance(devs, Exception) else None ################################################################ # # diff --git a/DEVSKernel/PyPDEVS/pypdevs221/src/classicDEVSWrapper.py b/DEVSKernel/PyPDEVS/pypdevs221/src/classicDEVSWrapper.py index 84d54a88..02148f06 100644 --- a/DEVSKernel/PyPDEVS/pypdevs221/src/classicDEVSWrapper.py +++ b/DEVSKernel/PyPDEVS/pypdevs221/src/classicDEVSWrapper.py @@ -50,5 +50,5 @@ def outputFnc(self): :returns: the changed dictionary """ retval = self.model.outputFnc() - print(self.model, retval) + #print(self.model, retval) return {i: [retval[i]] for i in retval} diff --git a/LibraryTree.py b/LibraryTree.py index 234a8dac..47e014a1 100644 --- a/LibraryTree.py +++ b/LibraryTree.py @@ -215,10 +215,10 @@ def OnMotion(self, evt): module = BlockFactory.GetModule(path) info = Container.CheckClass(path) - if isinstance(info, tuple): - doc = str(info) - elif isinstance(module, tuple): + if isinstance(module, tuple) or isinstance(module, Exception): doc = str(module) + elif isinstance(info, tuple): + doc = str(info) else: doc = inspect.getdoc(module) diff --git a/Patterns/Factory.py b/Patterns/Factory.py index 2b4234ab..2d91d83c 100644 --- a/Patterns/Factory.py +++ b/Patterns/Factory.py @@ -163,7 +163,6 @@ def terminate(self, error = False, msg = None): ### error sound wx.CallAfter(playSound, SIMULATION_ERROR_SOUND_PATH) - else: for m in [a for a in list(self.model.getFlatComponentSet().values()) if hasattr(a, 'finish')]: ### call finished method @@ -187,7 +186,7 @@ def terminate(self, error = False, msg = None): wx.CallAfter(playSound, SIMULATION_SUCCESS_SOUND_PATH) self.end_flag = True - + def set_sleep(self, sleeptime): """ Set the sleep. """ diff --git a/Patterns/Strategy.py b/Patterns/Strategy.py index 537649fe..e13bd002 100644 --- a/Patterns/Strategy.py +++ b/Patterns/Strategy.py @@ -514,7 +514,6 @@ def simulate(self, T = 100000000): def terminate_never(model, clock): return False - class SimStrategy4(SimStrategy): """ classic strategy for PyPDEVS simulation setClassicDEVS is True and confTransition in disabled diff --git a/PluginsGUI.py b/PluginsGUI.py index b605367b..fcbd2a99 100644 --- a/PluginsGUI.py +++ b/PluginsGUI.py @@ -65,6 +65,13 @@ def __init__(self, *args, **kw): CheckListCtrlMixin.__init__(self) + if wx.VERSION_STRING < '4.0': + self.SetStringItem = self.SetStringItem + self.InsertStringItem = self.InsertStringItem + else: + self.SetStringItem = self.SetItem + self.InsertStringItem = self.InsertItem + self.id = -100000000 self.map = {} @@ -175,7 +182,24 @@ def isOk(self, item): return module and module.__file__ def GetPath(self,item): - return self.GetPyData(item)[0].__file__ if self.GetPyData(item) else None + """ Get the path stored as PyData of the file + """ + py_data = self.GetPyData(item) + + ### return path if the first elem of tuple (py_data) is file (can be a function for local plugin...) + if py_data: + ### is function (global plugin)? + if callable(py_data[0]): + func = py_data[0] + return func.__code__.co_filename + ### is file (local plugin) ? + elif os.path.isfile(py_data[0]): + file = py_data[0] + return file.__file__ + else: + return None + else: + return None def OnEnable(self, event): """ Ebnable the current item. @@ -440,7 +464,7 @@ class BlockPluginsList(CheckListCtrl): def __init__(self, *args, **kwargs): """ Constructor. """ - super(CheckListCtrl, self).__init__(*args, **kwargs) + CheckListCtrl.__init__(self,*args, **kwargs) self.InsertColumn(0, _('Name'), width=180) self.InsertColumn(1, _('Type'), width=180) @@ -867,7 +891,8 @@ def __init__(self, *args, **kwargs): self.CheckList.OnEdit = self.OnEdit self.CenterOnParent(wx.BOTH) - self.Fit() + self.Layout() + #self.Fit() @staticmethod def GetEditor(parent, model, filename=None): diff --git a/SimulationGUI.py b/SimulationGUI.py index daeeea48..abc8657b 100644 --- a/SimulationGUI.py +++ b/SimulationGUI.py @@ -421,7 +421,7 @@ def OnViewLog(self, event): ### def OnOk(self, event): - """ When Run button is clicked + """ When Run button is clicked. """ assert(self.master is not None) @@ -529,9 +529,31 @@ def OnStop(self, event): """ self.Interact() - if self.thread : + + if self.thread: self.thread.terminate(False) + + import os + import signal + import platform + + # get the current PID for safe terminate server if needed: + PID = os.getpid() + # if platform.system() != 'Windows': + # PGID = os.getgid(PID) + + # if platform.system() != 'Windows': + # os.killpg(PGID, signal.SIGKILL) + # else: + # os.kill(PID, signal.SIGTERM) + + main_thread = threading.currentThread() + for t in threading.enumerate(): + if t is not main_thread: + pass + self.timer.Stop() + wx.Bell() self._gauge.SetValue(0) diff --git a/Utilities.py b/Utilities.py index 7ebc02e2..4f6662f0 100644 --- a/Utilities.py +++ b/Utilities.py @@ -648,7 +648,7 @@ def getInstance(cls, args = {}): if inspect.isclass(cls): try: devs = cls(**args) - except Exception: + except Exception as info: sys.stderr.write(_("Error in getInstance: %s not instanciated with %s.\n"%(cls,str(args)))) PrintException() return sys.exc_info() diff --git a/ZipManager.py b/ZipManager.py index eb8c3844..c4065afd 100644 --- a/ZipManager.py +++ b/ZipManager.py @@ -434,18 +434,20 @@ def ImportModule(self)->types.ModuleType: module = None dial.Destroy() - finally: - if module: - module.__name__ = path_to_module(module_name) - - ### allows to import with a reference from the parent directory (like parentName.model). - ### Now import of .amd or .cmd module is composed by DomainModel (no point!). - ### Example : import CollectorMessageCollectoramd or CollectorMessageCollectorcmd - sys.modules[self.GetFullName()] = module + except Exception as e: + return e + + if module: + module.__name__ = path_to_module(module_name) + + ### allows to import with a reference from the parent directory (like parentName.model). + ### Now import of .amd or .cmd module is composed by DomainModel (no point!). + ### Example : import CollectorMessageCollectoramd or CollectorMessageCollectorcmd + sys.modules[self.GetFullName()] = module - return module - else: - return None + return module + else: + return None def ReImport(self): """ Reimport the module from zip file.