Skip to content

Commit 191a3ab

Browse files
authored
Merge pull request #394 from capocchi/version-5.1
Version 5.1
2 parents 1585c6e + 07a15b0 commit 191a3ab

File tree

5 files changed

+347
-54
lines changed

5 files changed

+347
-54
lines changed

devsimpy/Container.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,7 @@ def OnNewModel(self, event):
23852385
gmwiz = self.OnStartWizard(event)
23862386

23872387
# if wizard is finished witout closing
2388-
if gmwiz :
2388+
if gmwiz:
23892389

23902390
m = Components.BlockFactory.CreateBlock( canvas = self,
23912391
x = xm,
@@ -2420,8 +2420,7 @@ def OnNewModel(self, event):
24202420
# focus
24212421
#wx.CallAfter(self.SetFocus)
24222422

2423-
# Cleanup
2424-
gmwiz.Destroy()
2423+
# gmwiz.Destroy()
24252424

24262425
@BuzyCursorNotification
24272426
def OnPaste(self, event):

devsimpy/SimulationGUI.py

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def MakePaneContent(self, pane):
276276
# Set initial values and enable/disable based on package
277277
if DEFAULT_DEVS_DIRNAME == 'PyDEVS':
278278
self.cb2.SetValue(NTL)
279-
self.cb3.Enable(False)
279+
self.cb3.SetValue(VERBOSE)
280280
cb4.Enable(False)
281281
cb5.Enable(False)
282282
elif DEFAULT_DEVS_DIRNAME == 'BrokerDEVS':
@@ -292,6 +292,11 @@ def MakePaneContent(self, pane):
292292
cb4.SetValue(DYNAMIC_STRUCTURE)
293293
cb5.SetValue(REAL_TIME and not NTL)
294294

295+
# Disable and uncheck verbose if plugin is not enabled
296+
if not PluginManager.is_enable('verbose'):
297+
self.cb3.SetValue(False)
298+
self.cb3.Enable(False)
299+
295300
pane.SetSizer(main_sizer)
296301

297302
# Bind events
@@ -606,8 +611,9 @@ def OnText(self, event):
606611
def OnViewLog(self, event):
607612
""" When View button is clicked
608613
"""
609-
# The simulation verbose event occurs
610-
PluginManager.trigger_event('START_SIM_VERBOSE', parent=self)
614+
# The simulation verbose event occurs only if verbose is enabled
615+
if self.verbose:
616+
PluginManager.trigger_event('START_SIM_VERBOSE', parent=self)
611617

612618
# The activity tracking event occurs
613619
PluginManager.trigger_event('VIEW_ACTIVITY_REPORT', parent=self, master=self.current_master)
@@ -947,39 +953,55 @@ def ErrorManager(self, msg):
947953

948954
### try to find the file which have the error from traceback
949955
devs_error = False
956+
# the pubsub call may pass whatever it likes; the original code assumed a
957+
# (type, value, traceback) tuple and would crash if msg was anything else.
958+
# be defensive: if unpacking fails treat it as a non‑devs error and fall
959+
# through to the generic handler below.
950960
try:
951-
typ, val, tb = msg
952-
trace = traceback.format_exception(typ, val, tb)
953-
954-
### paths in traceback
955-
paths = [a for a in trace if a.split(',')[0].strip().startswith('File')]
956-
957-
### find if DOMAIN_PATH is in the first file path of the trace
958-
path = paths[-1]
959-
devs_error = DOMAIN_PATH in path or DEVSIMPY_PACKAGE_PATH not in path
960-
961+
if isinstance(msg, tuple) and len(msg) == 3:
962+
typ, val, tb = msg
963+
trace = traceback.format_exception(typ, val, tb)
964+
965+
### paths in traceback
966+
paths = [a for a in trace if a.split(',')[0].strip().startswith('File')]
967+
if paths:
968+
# find if DOMAIN_PATH is in the last file path of the trace
969+
p = paths[-1]
970+
devs_error = DOMAIN_PATH in p or DEVSIMPY_PACKAGE_PATH not in p
971+
else:
972+
# msg didnt look like a tuple, maybe pubsub gave keyword args
973+
sys.stdout.write(_("ErrorManager received unexpected message type %r\n") % (msg,))
961974
except Exception as info:
962-
sys.stdout.write(_("Error in ErrorManager: %s"%info))
963-
975+
sys.stdout.write(_("Error in ErrorManager: %s" % info))
976+
964977
### if error come from devs python file
965978
if devs_error:
966979

967980
try:
968981
### simulate event button for the code editor
969982
event = wx.PyCommandEvent(wx.EVT_BUTTON.typeId, self._btn1.GetId())
970-
except:
983+
except Exception:
971984
pass
972985
else:
973986
### Error dialog
974-
if not Container.MsgBoxError(event, self.parent, msg):
975-
### if user dont want correct the error, we destroy the simulation windows
987+
if not Container.MsgBoxError(event, getattr(self, 'parent', None), msg):
988+
### if user dont want correct the error, we destroy the simulation windows
976989
self.PrepareDestroyWin()
977990
self.Destroy()
978991
else:
979-
### if user want to correct error through an editor, we stop simulation process for trying again after the error is corrected.
992+
### if user want to correct error through an editor, we stop simulation process for trying again after the error is corrected.
980993
self.OnStop(event)
981994
else:
982-
raise MyBad(msg)
995+
# treat any other error the same way instead of raising; on real
996+
# non‑devs errors we simply show a message box and tear down the
997+
# simulation so the program can continue gracefully.
998+
try:
999+
Container.MsgBoxError(None, getattr(self, 'parent', None), msg)
1000+
except Exception as info2:
1001+
sys.stdout.write(_("Error displaying error dialog: %s\nOriginal: %r") % (info2, msg))
1002+
# ensure simulation windows are cleaned up
1003+
self.PrepareDestroyWin()
1004+
self.Destroy()
9831005

9841006
class SimulationDialogPanel(Base, wx.Panel):
9851007
""" Simulation Dialog Panel

devsimpy/WizardGUI.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ def on_finished(self, evt):
332332
def on_close(self, evt):
333333
""" Close button has been pressed. Destroy the wizard.
334334
"""
335-
wx.CallAfter(self.Destroy)
335+
# wx.CallAfter(self.Destroy)
336+
self.canceled_flag = True
337+
evt.Skip()
336338

337339

338340
class ModelGeneratorWizard(Wizard):
@@ -905,7 +907,7 @@ def on_finished(self, evt):
905907
self.inputs = in_SpinCtrl.GetValue()
906908
self.outputs = out_SpinCtrl.GetValue()
907909

908-
print("the path : %s\nthe name : %s\nThe inputs ports:%s\n the ouputports%s\n"%(self.model_path, self.label, self.inputs, self.outputs))
910+
# print("the path : %s\nthe name: %s\nThe inputs ports:%s\n the ouputports:%s\n"%(self.model_path, self.label, self.inputs, self.outputs))
909911

910912
### model path exist ?
911913
if os.path.exists(self.model_path):
-74.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)