From 8fbc96af8e85184480914ae7f72beae2b0b8bf49 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Fri, 13 Mar 2020 16:58:36 +0100 Subject: [PATCH 1/3] update of printOnStatusBar --- devsimpy.py | 52 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/devsimpy.py b/devsimpy.py index a0dd7cf3..d60f472d 100644 --- a/devsimpy.py +++ b/devsimpy.py @@ -150,8 +150,7 @@ 'DYNAMIC_STRUCTURE' : False, # Dynamic Structure for local PyPDEVS simulation 'REAL_TIME': False, ### PyPDEVS threaded real time simulation 'VERBOSE':False, - 'TRANSPARENCY' : True, # Transparancy for DetachedFrame activated - 'NOTIFICATION' : True, # Notification message activated + 'TRANSPARENCY' : True, # Transparancy for DetachedFrame 'DEFAULT_PLOT_DYN_FREQ' : 100, # frequence of dynamic plot of QuickScope (to avoid overhead), 'DEFAULT_DEVS_DIRNAME':'PyDEVS', # default DEVS Kernel directory 'DEVS_DIR_PATH_DICT':{'PyDEVS':os.path.join(ABS_HOME_PATH,'DEVSKernel','PyDEVS'), @@ -187,7 +186,7 @@ from PreferencesGUI import PreferencesGUI from pluginmanager import load_plugins, enable_plugin from which import which -from Utilities import GetUserConfigDir, install_and_import, printOnStatusBar, NotificationMessage, updatePackageWithPiP +from Utilities import GetUserConfigDir, install_and_import from Decorators import redirectStdout, BuzyCursorNotification from DetachedFrame import DetachedFrame from LibraryTree import LibraryTree @@ -772,30 +771,20 @@ def EnableAbstractionButton(self): ### update text filed level = self.spin.GetValue() - tb = self.GetToolBar() - ### update doward and upward button - tb.EnableTool(self.toggle_list[4], level != 0) - tb.EnableTool(self.toggle_list[5], level != 0) + self.tb.EnableTool(self.toggle_list[4], level != 0) + self.tb.EnableTool(self.toggle_list[5], level != 0) def OnDeleteRecentFiles(self, event): """ Delete the recent files list """ - dial = wx.MessageDialog(self, _('Do you want to clear the list of recent opened files?'), 'Clean Recent Opened Files List', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) - - ### if local editor - if dial.ShowModal() == wx.ID_YES: - # update openFileList variable - self.openFileList = ['']*NB_OPENED_FILE - - # update config file - self.cfg.Write("openFileList", str(eval("self.openFileList"))) - self.cfg.Flush() - - NotificationMessage(_("Information"), _("Recent opened files list has been deleted!"), self, timeout=5) + # update openFileList variable + self.openFileList = ['']*NB_OPENED_FILE - dial.Destroy() + # update config file + self.cfg.Write("openFileList", str(eval("self.openFileList"))) + self.cfg.Flush() def OnCreatePerspective(self, event): """ @@ -1057,7 +1046,7 @@ def OnZoom(self, event): currentPage.scaley=max(currentPage.scaley+.05,.3) currentPage.Refresh() - printOnStatusBar(self.statusbar,{0:_('Zoom In')}) + self.statusbar.SetStatusText(_('Zoom In')) ### def OnUnZoom(self, event): @@ -1074,7 +1063,7 @@ def OnUnZoom(self, event): currentPage.scaley=currentPage.scaley-.05 currentPage.Refresh() - printOnStatusBar(self.statusbar,{0:_('Zoom Out')}) + self.statusbar.SetStatusText(_('Zoom Out')) ### def AnnuleZoom(self, event): @@ -1091,7 +1080,7 @@ def AnnuleZoom(self, event): currentPage.scaley = 1.0 currentPage.Refresh() - printOnStatusBar(self.statusbar,{0:_('No Zoom')}) + self.statusbar.SetStatusText(_('No Zoom')) ### def OnNew(self, event): @@ -1296,9 +1285,10 @@ def OnSaveFile(self, event): # Refresh canvas currentPage.Refresh() - tb = self.GetToolBar() ### enable save button on status bar - tb.EnableTool(Menu.ID_SAVE, diagram.modify) + self.tb.EnableTool(Menu.ID_SAVE, diagram.modify) + + #self.statusbar.SetStatusText(_('%s saved')%diagram.last_name_saved) else: wx.MessageBox( _('Error saving file.') ,_('Error'), wx.OK | wx.ICON_ERROR) else: @@ -1372,9 +1362,8 @@ def OnSaveAsFile(self, event): else: self.nb2.AddEditPage(label, diagram) - tb = self.GetToolBar() ### enable save button on status bar - tb.EnableTool(Menu.ID_SAVE, diagram.modify) + self.tb.EnableTool(Menu.ID_SAVE, diagram.modify) else: wx.MessageBox(_('Error saving file.'), _('Error'), wx.OK | wx.ICON_ERROR) @@ -2009,11 +1998,6 @@ def OnAPI(self, event): #webbrowser.open_new(opj(self.installDir + "/docs/api/index.html")) wx.MessageBox(_("This option has not been implemented yet."), _('Info'), wx.OK|wx.ICON_INFORMATION) - def OnUpdatePiPPackage(self, event): - """ Update all pip package - """ - updatePackageWithPiP() - @BuzyCursorNotification def OnAbout(self, event): """ About menu has been pressed. @@ -2054,7 +2038,7 @@ def OnAbout(self, event): def OnContact(self, event): """ Launches the mail program to contact the DEVSimPy author. """ - frame = SendMailWx(None) + frame = SendMailWx() frame.Show() ##------------------------------------------------------------------- @@ -2179,7 +2163,7 @@ def ShowMain(self): self.app.frame = MainApplication(None, wx.NewIdRef(), 'DEVSimPy %s'%__version__) - printOnStatusBar(self.app.frame.statusbar,{1:_('wxPython %s - python %s'%(wx.version(),platform.python_version()))}) + self.app.frame.statusbar.SetStatusText(_('wxPython %s - python %s'%(wx.version(),platform.python_version())),1) # keep in a attribute of stdio which is invisible until now self.app.frame.stdioWin = self.app.stdioWin From 974f4c67b3aa496e631d928de81aa7959f26f707 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Fri, 13 Mar 2020 18:02:57 +0100 Subject: [PATCH 2/3] bug fix --- AttributeEditor.py | 1 - devsimpy.py | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/AttributeEditor.py b/AttributeEditor.py index bd2c365f..6628c719 100644 --- a/AttributeEditor.py +++ b/AttributeEditor.py @@ -171,7 +171,6 @@ class AttributeEditorPanel(AttributeBase, wx.Panel): def __init__(self, parent, ID, model, canvas): """ Constructor. - """ # pour gerer l'affichage dans la page de gauche dans le notebook wx.Panel.__init__(self, parent, ID) diff --git a/devsimpy.py b/devsimpy.py index d60f472d..4ab17882 100644 --- a/devsimpy.py +++ b/devsimpy.py @@ -64,7 +64,7 @@ __date__ = str(datetime.datetime.now()) __version__ = '4.0' __docformat__ = 'epytext' -__min_wx_version__ = ['4.0'] +__min_wx_version__ = '4.0' ABS_HOME_PATH = os.path.abspath(os.path.dirname(sys.argv[0])) @@ -186,7 +186,7 @@ from PreferencesGUI import PreferencesGUI from pluginmanager import load_plugins, enable_plugin from which import which -from Utilities import GetUserConfigDir, install_and_import +from Utilities import GetUserConfigDir, install_and_import, updatePackageWithPiP from Decorators import redirectStdout, BuzyCursorNotification from DetachedFrame import DetachedFrame from LibraryTree import LibraryTree @@ -1992,6 +1992,9 @@ def OnHelp(self, event): else: self.help.Display(os.path.join('html','toc.html')) + def OnUpdatePiPPackage(self, event): + updatePackageWithPiP() + def OnAPI(self, event): """ Shows the DEVSimPy API help file. """ @@ -2331,10 +2334,23 @@ def OnInit(self): the main frame when it is time to do so. """ + # Check runtime version + if wx.VERSION_STRING < __min_wx_version__: + wx.MessageBox(caption=_("Warning"), + message=_("You're using version %s of wxPython, but DEVSimPy was written for min version %s.\n" + "There may be some version incompatibilities...") + % (wx.VERSION_STRING, __min_wx_version__)) + # For debugging + #self.SetAssertMode(wx.PYAPP_ASSERT_DIALOG|wx.PYAPP_ASSERT_EXCEPTION) + + wx.SystemOptions.SetOption("mac.window-plain-transition", 1) + self.SetAppName("DEVSimPy") + # start our application with splash splash = AdvancedSplashScreen(self) splash.Show() + return True def SetExceptionHook(self): From 148284d6ba49542f4e9a7c7a4b307816c31540a8 Mon Sep 17 00:00:00 2001 From: lcapocchi Date: Fri, 13 Mar 2020 13:22:01 -0400 Subject: [PATCH 3/3] maintainability improved --- Components.py | 4 ++-- Container.py | 14 +++++++------- Decorators.py | 2 +- ImportLibrary.py | 10 +++++----- Mixins/Savable.py | 6 +++--- SimulationGUI.py | 2 +- Utilities.py | 2 +- devsimpy.py | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Components.py b/Components.py index 1dbc95d6..8d149cbc 100644 --- a/Components.py +++ b/Components.py @@ -32,7 +32,7 @@ from tempfile import gettempdir -if builtins.__dict__['GUI_FLAG']: +if builtins.__dict__.get('GUI_FLAG',True): import wx if wx.VERSION_STRING < '2.9': @@ -531,7 +531,7 @@ def setBlock(self, devs): if not hasattr(devs, 'debugger'): setattr(devs.__class__, DEVSComponent.debugger.__name__, DEVSComponent.debugger) - if builtins.__dict__['GUI_FLAG']: + if builtins.__dict__.get('GUI_FLAG',True): ### to execute finish method of devs model (look at the SimulationGUI for message interception) if hasattr(devs, 'finish'): Publisher.subscribe(devs.finish, "%d.finished"%(id(devs))) diff --git a/Container.py b/Container.py index 6c3ea8a7..4c4a9d8c 100644 --- a/Container.py +++ b/Container.py @@ -24,7 +24,7 @@ import builtins -if builtins.__dict__['GUI_FLAG']: +if builtins.__dict__.get('GUI_FLAG',True): import wx import wx.lib.dragscroller import wx.lib.dialogs @@ -72,7 +72,7 @@ import DomainInterface.MasterModel -if builtins.__dict__['GUI_FLAG']: +if builtins.__dict__.get('GUI_FLAG',True): import ConnectDialog import DiagramConstantsDialog import SpreadSheet @@ -89,7 +89,7 @@ import Components -if builtins.__dict__['GUI_FLAG']: +if builtins.__dict__.get('GUI_FLAG',True): import Menu #import ReloadModule @@ -113,7 +113,7 @@ from Utilities import HEXToRGB, RGBToHEX, relpath, GetActiveWindow, playSound, sendEvent, getInstance, FixedList, getObjectFromString, getTopLevelWindow, printOnStatusBar from Patterns.Observer import Subject, Observer -if builtins.__dict__['GUI_FLAG']: +if builtins.__dict__.get('GUI_FLAG',True): from DetachedFrame import DetachedFrame from AttributeEditor import AttributeEditor, QuickAttributeEditor from PropertiesGridCtrl import PropertiesGridCtrl @@ -591,7 +591,7 @@ def GetParent(self): def GetGrandParent(self): return self.GetParent().GetParent() - @cond_decorator(builtins.__dict__['GUI_FLAG'], ProgressNotification("DEVSimPy open file")) + @cond_decorator(builtins.__dict__.get('GUI_FLAG',True), ProgressNotification("DEVSimPy open file")) def LoadFile(self, fileName = None): """ Function that load diagram from a file. """ @@ -613,7 +613,7 @@ def LoadFile(self, fileName = None): return True - #@cond_decorator(builtins.__dict__['GUI_FLAG'], StatusBarNotification('Load')) + #@cond_decorator(builtins.__dict__.get('GUI_FLAG',True), StatusBarNotification('Load')) def LoadConstants(self, label): """ Load Constants to general builtin. """ @@ -1483,7 +1483,7 @@ def draw(self,dc): self.graphic.fill = self.fill self.graphic.draw(dc) -if builtins.__dict__['GUI_FLAG']: +if builtins.__dict__.get('GUI_FLAG',True): #------------------------------------------------------------------------------- class ShapeCanvas(wx.ScrolledWindow, Abstractable, Subject): """ ShapeCanvas class. diff --git a/Decorators.py b/Decorators.py index 908fc4cb..daf2a7eb 100644 --- a/Decorators.py +++ b/Decorators.py @@ -13,7 +13,7 @@ import pickle import cProfile, pstats, io -if builtins.__dict__['GUI_FLAG']: +if builtins.__dict__.get('GUI_FLAG',True): import wx if wx.VERSION_STRING < '4.0': import wx.aui diff --git a/ImportLibrary.py b/ImportLibrary.py index d93cb23f..e1c3bd02 100644 --- a/ImportLibrary.py +++ b/ImportLibrary.py @@ -157,7 +157,7 @@ def InitUI(self): #------------------------------------------------------------------- class ImportLibrary(wx.Dialog): def __init__(self, *args, **kwargs): - wx.Dialog.__init__(self, *args, **kwargs) + super(ImportLibrary, self).__init__(*args, **kwargs) ### local copy self.parent = args[0] @@ -238,11 +238,11 @@ def __init__(self, *args, **kwargs): apply = wx.Button(rightPanel, id=wx.ID_OK, size=(100, -1)) cancel = wx.Button(rightPanel, id=wx.ID_CANCEL, size=(100, -1)) - vbox2.Add(new, 0, wx.TOP, 2) - vbox2.Add(imp, 0, wx.TOP, 2) + vbox2.Add(new, 0, wx.TOP|wx.LEFT, 6) + vbox2.Add(imp, 0, wx.TOP|wx.LEFT, 6) #vbox2.Add((-1, 5)) - vbox2.Add(sel, 0, wx.TOP, 2) - vbox2.Add(des, 0, wx.TOP, 2) + vbox2.Add(sel, 0, wx.TOP|wx.LEFT, 6) + vbox2.Add(des, 0, wx.TOP|wx.LEFT, 6) hbox1.Add(cancel, 1, wx.ALL|wx.ALIGN_CENTER, 2) hbox1.Add(apply, 1, wx.ALL|wx.ALIGN_CENTER, 2) diff --git a/Mixins/Savable.py b/Mixins/Savable.py index 5e735190..77973989 100644 --- a/Mixins/Savable.py +++ b/Mixins/Savable.py @@ -538,8 +538,8 @@ class Savable(object): ### static attribut to store le extention/class available DB = DumpBase.PopulateDB() - @cond_decorator(builtins.__dict__['GUI_FLAG'], BuzyCursorNotification) - @cond_decorator(builtins.__dict__['GUI_FLAG'], StatusBarNotification('Sav')) + @cond_decorator(builtins.__dict__.get('GUI_FLAG',True), BuzyCursorNotification) + @cond_decorator(builtins.__dict__.get('GUI_FLAG',True), StatusBarNotification('Sav')) def SaveFile(self, fileName = None): """ Save object in fileName """ @@ -561,7 +561,7 @@ def SaveFile(self, fileName = None): sys.stdout.write(_("\nUnknown extension: %s")%fileName) return False - @cond_decorator(builtins.__dict__['GUI_FLAG'], StatusBarNotification('Load')) + @cond_decorator(builtins.__dict__.get('GUI_FLAG',True), StatusBarNotification('Load')) def LoadFile(self, fileName = None): """ Load object from fileName """ diff --git a/SimulationGUI.py b/SimulationGUI.py index 03a9b01c..c027e60d 100644 --- a/SimulationGUI.py +++ b/SimulationGUI.py @@ -975,7 +975,7 @@ def terminate(self, error = False, msg = None): else: for m in [a for a in list(self.model.getFlatComponentSet().values()) if hasattr(a, 'finish')]: ### call finished method - if builtins.__dict__['GUI_FLAG']: + if builtins.__dict__.get('GUI_FLAG',True): #if wx.VERSION_STRING < '2.9': try: pub.sendMessage('%d.finished'%(id(m))) diff --git a/Utilities.py b/Utilities.py index 8179cd04..c7eeff45 100644 --- a/Utilities.py +++ b/Utilities.py @@ -23,7 +23,7 @@ from io import StringIO -if builtins.__dict__['GUI_FLAG']: +if builtins.__dict__.get('GUI_FLAG',True): import wx ### for Phoenix diff --git a/devsimpy.py b/devsimpy.py index 4ab17882..80d3183b 100644 --- a/devsimpy.py +++ b/devsimpy.py @@ -2257,7 +2257,7 @@ def __init__(self, redirect=False, filename=None): wx.App.__init__(self, redirect, filename) # make sure we can create a GUI - if not self.IsDisplayAvailable() and not builtins.__dict__['GUI_FLAG']: + if not self.IsDisplayAvailable() and not builtins.__dict__.get('GUI_FLAG',True): if wx.Platform == '__WXMAC__': msg = """This program needs access to the screen.