From e525b14bd79c27e6675a334815f1a873c07e5560 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Mon, 4 Jan 2021 17:27:25 +0100 Subject: [PATCH 1/2] bug fixe --- ConnectDialog.py | 16 ++++++++++++---- Container.py | 32 ++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/ConnectDialog.py b/ConnectDialog.py index 121cc13c..1c1927d0 100644 --- a/ConnectDialog.py +++ b/ConnectDialog.py @@ -50,13 +50,13 @@ def __init__(self, parent, id, title, sn="Source", snL=[None,None], tn="Target", L1 = [function(snL,i) for i in range(len(snL))] L2 = [function(tnL,i) for i in range(len(tnL))] - L1.append("%s"%_('All')) - L2.append("%s"%_('All')) + L1.insert(0,"%s"%_('All')) + L2.insert(0,"%s"%_('All')) self._label_source = wx.StaticText(self, wx.NewIdRef(), '%s'%self.sn) self._label_target = wx.StaticText(self, wx.NewIdRef(), '%s'%self.tn) - self._combo_box_sn = wx.ComboBox(self, wx.NewIdRef(), choices = L1, style = wx.CB_DROPDOWN|wx.CB_READONLY|wx.CB_SORT) - self._combo_box_tn = wx.ComboBox(self, wx.NewIdRef(), choices = L2, style = wx.CB_DROPDOWN|wx.CB_READONLY|wx.CB_SORT) + self._combo_box_sn = wx.ComboBox(self, wx.NewIdRef(), choices = L1, style = wx.CB_DROPDOWN|wx.CB_READONLY) + self._combo_box_tn = wx.ComboBox(self, wx.NewIdRef(), choices = L2, style = wx.CB_DROPDOWN|wx.CB_READONLY) self._button_disconnect = wx.Button(self, wx.NewIdRef(), _("Disconnect")) self._button_connect = wx.Button(self, wx.NewIdRef(), _("Connect")) @@ -97,6 +97,14 @@ def EvtComboBox1(self,event): def EvtComboBox2(self,event): self._result[1] = event.GetSelection() + def GetSelectedIndex(self): + return self._result + + def GetLabelSource(self): + return self._label_source.GetLabel() + + def GetLabelTarget(self): + return self._label_target.GetLabel() ### ------------------------------------------------------------ class TestApp(wx.App): """ Testing application diff --git a/Container.py b/Container.py index e0dd4a8d..616ee34a 100644 --- a/Container.py +++ b/Container.py @@ -1873,9 +1873,9 @@ def OnConnectTo(self, event): sourceName = source.label # get target model from its name - for s in [m for m in self.diagram.shapes if not isinstance(m,ConnectionShape)]: + for s in [m for m in self.diagram.shapes if not isinstance(m, ConnectionShape)]: if s.label == targetName: - target=s + target = s break ### init source and taget node list @@ -1898,8 +1898,10 @@ def OnDisconnect(self, event): """ Disconnect selected ports from connectDialog. """ + label_source, label_target = self.dlgConnection.GetLabelSource(), self.dlgConnection.GetLabelTarget() + # dialog results - sp,tp = self.dlgConnection._result + sp,tp = self.dlgConnection.GetSelectedIndex() ### local variables snl = len(self.sourceNodeList) @@ -1910,14 +1912,24 @@ def OnDisconnect(self, event): ### if selected options are not 'All' if sp == tp == 0: - for connectionShapes in self.diagram.GetConnectionShapeGenerator(): - if (connectionShapes.getInput()[1] == sp-1) and (connectionShapes.getOutput()[1] == tp-1): - self.RemoveShape(connectionShapes) + for cs in list(self.diagram.GetConnectionShapeGenerator()): + if (cs.getInput()[0].label == label_source and cs.getOutput()[0].label == label_target): + self.RemoveShape(cs) + modify_flag = True + elif sp == 0: + for cs in list(self.diagram.GetConnectionShapeGenerator()): + if (cs.getInput()[0].label == label_source and cs.getOutput()[0].label == label_target and cs.getOutput()[1] == tp-1): + self.RemoveShape(cs) + modify_flag = True + elif tp == 0: + for cs in list(self.diagram.GetConnectionShapeGenerator()): + if (cs.getInput()[0].label == label_source and cs.getInput()[1] == sp-1 and cs.getOutput()[0].label == label_target): + self.RemoveShape(cs) modify_flag = True else: - for connectionShapes in self.diagram.GetConnectionShapeGenerator(): - if (connectionShapes.getInput()[1] == sp) and (connectionShapes.getOutput()[1] == tp): - self.RemoveShape(connectionShapes) + for cs in list(self.diagram.GetConnectionShapeGenerator()): + if (cs.getInput()[1] == sp-1) and (cs.getOutput()[1] == tp-1): + self.RemoveShape(cs) modify_flag = True ### shape has been modified @@ -1931,7 +1943,7 @@ def OnConnect(self, event): """ # dialog results - sp,tp = self.dlgConnection._result + sp,tp = self.dlgConnection.GetSelectedIndex() ### local variables snl = len(self.sourceNodeList) From dae2eda44bf3c41f0335fa5d447fdd7fd342e11a Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Wed, 6 Jan 2021 10:13:55 +0100 Subject: [PATCH 2/2] ntl intagration for devsimpy-nogui --- SimulationNoGUI.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/SimulationNoGUI.py b/SimulationNoGUI.py index c96b37e1..3d395fe7 100644 --- a/SimulationNoGUI.py +++ b/SimulationNoGUI.py @@ -102,20 +102,19 @@ def makeSimulation(master, T, simu_name="simu", is_remote=False, json_trace=True CPUduration = 0.0 interactionManager = None try: - if is_remote: - # Pusher service for Simulation --> User communication - simuPusher = SimuPusher(simu_name) - else: - simuPusher = PrintPusher(simu_name) + + # Pusher service for Simulation --> User communication + simuPusher = SimuPusher(simu_name) if is_remote else PrintPusher(simu_name) ### Get live stream URL if exist : - for m in [a for a in master.getComponentSet() if hasattr(a, 'plotUrl')]: - if m.plotUrl != '': - json_report['output'].append({'label':m.name, 'plotUrl':m.plotUrl}) + for m in [a for a in master.getComponentSet() if hasattr(a, 'plotUrl') and a.plotUrl != '']: + json_report['output'].append({'label':m.name, 'plotUrl':m.plotUrl}) + ### Get live stream URL if exist : for m in [a for a in master.getComponentSet() if hasattr(a, 'pusherChannel')]: m.pusherChannel = simu_name json_report['output'].append({'label':m.name, 'pusherChannel':m.pusherChannel}) + # Send to user simuPusher.push('live_streams', {'live_streams': json_report['output']}) @@ -131,21 +130,22 @@ def makeSimulation(master, T, simu_name="simu", is_remote=False, json_trace=True first_real_time = time.time() progress = 0 - while(thread.isAlive()): - new_real_time = time.time() - CPUduration = new_real_time - first_real_time - new_progress = 100.0*(thread.model.timeLast / T) - if new_progress - progress > 5: - progress = new_progress - simuPusher.push('progress', {'progress':progress}) - if not json_trace: - Printer(CPUduration) - - if interactionManager != None: - interactionManager.stop() - interactionManager.join() - - simuPusher.push('progress', {'progress':100}) + if not builtins.__dict__['NTL']: + while(thread.isAlive()): + new_real_time = time.time() + CPUduration = new_real_time - first_real_time + new_progress = 100.0*(thread.model.timeLast / T) + if new_progress - progress > 5: + progress = new_progress + simuPusher.push('progress', {'progress':progress}) + if not json_trace: + Printer(CPUduration) + + if interactionManager != None: + interactionManager.stop() + interactionManager.join() + + simuPusher.push('progress', {'progress':100}) except: json_report['summary'] += " *** EXCEPTION raised in simulation ***"