From 44fa4150b18d27e417794f0170ffef851fd21648 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Thu, 19 Nov 2020 17:11:37 +0100 Subject: [PATCH 1/2] bug fix on _() --- AttributeEditor.py | 3 +++ CheckerGUI.py | 3 ++- ConnectDialog.py | 9 +++++++++ ConnectionThread.py | 7 ++++++- ControlNotebook.py | 6 ++++++ DSV.py | 2 ++ Decorators.py | 3 +++ DetachedFrame.py | 3 +++ Editor.py | 1 - ExperimentGenerator.py | 3 +++ ImportLibrary.py | 5 ++++- LibraryTree.py | 22 ++++++++++++++++------ Menu.py | 3 ++- Mixins/Abstractable.py | 3 +++ Patterns/Factory.py | 3 +++ PrintOut.py | 3 +++ SpreadSheet.py | 4 ++++ XMLModule.py | 3 +++ devsimpy.py | 11 ++++++----- plugins/blink.py | 3 +++ plugins/state_trajectory.py | 3 +++ plugins/verbose.py | 3 +++ 22 files changed, 90 insertions(+), 16 deletions(-) diff --git a/AttributeEditor.py b/AttributeEditor.py index ba13b175..cf00f330 100644 --- a/AttributeEditor.py +++ b/AttributeEditor.py @@ -26,6 +26,9 @@ import wx +import gettext +_ = gettext.gettext + import DiagramNotebook from PropertiesGridCtrl import PropertiesGridCtrl, CodeCB diff --git a/CheckerGUI.py b/CheckerGUI.py index 780509e2..71a685a8 100644 --- a/CheckerGUI.py +++ b/CheckerGUI.py @@ -32,7 +32,8 @@ from traceback import format_exception -_ = wx.GetTranslation +import gettext +_ = gettext.gettext if __name__ == '__main__': import builtins diff --git a/ConnectDialog.py b/ConnectDialog.py index 32201112..3f28826e 100644 --- a/ConnectDialog.py +++ b/ConnectDialog.py @@ -23,9 +23,18 @@ import wx import os +import gettext +_ = gettext.gettext + def function(obj, i): return 'iPort %d'%i if obj[i].__class__.__name__ == "INode" else 'oPort %d'%i +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +# +# CLASSES DEFINITION +# +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + ### class ConnectDialog(wx.Frame): def __init__(self, parent, id, title, sn="Source", snL=[None,None], tn="Target", tnL=[None,None]): diff --git a/ConnectionThread.py b/ConnectionThread.py index 30d20f86..83bd3b3e 100644 --- a/ConnectionThread.py +++ b/ConnectionThread.py @@ -29,6 +29,9 @@ import tempfile import zipfile +import gettext +_ = gettext.gettext + __version_lib__ = 0.2 class unzip: @@ -120,7 +123,9 @@ def LoadZip(self, url): temp.seek(0) finally: - dlg = wx.MessageDialog(None, _("Are you sure to upgrade librairies from new version ?"), _("Upgrade Manager"), wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION) + dlg = wx.MessageDialog(None, _("Are you sure to upgrade librairies from new version ?"), + _("Upgrade Manager"), + wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION) if dlg.ShowModal() == wx.ID_YES: unzipper = unzip() diff --git a/ControlNotebook.py b/ControlNotebook.py index 0d544ea3..36ef6424 100644 --- a/ControlNotebook.py +++ b/ControlNotebook.py @@ -32,6 +32,12 @@ from AttributeEditor import AttributeEditor from Mixins.Attributable import Attributable +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +# +# CLASSES DEFINITION +# +## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## + ### -------------------------------------------------------------------------- class GeneralNotebook(Observer): def __init__(self, *args, **kwargs): diff --git a/DSV.py b/DSV.py index ec948970..116629d0 100644 --- a/DSV.py +++ b/DSV.py @@ -125,6 +125,8 @@ from functools import reduce os.putenv('LANG', 'C') +import gettext +_ = gettext.gettext import wx import wx.grid diff --git a/Decorators.py b/Decorators.py index 879a6347..f2baa0eb 100644 --- a/Decorators.py +++ b/Decorators.py @@ -33,6 +33,9 @@ import pickle import cProfile, pstats, io +import gettext +_ = gettext.gettext + if builtins.__dict__.get('GUI_FLAG',True): import wx if wx.VERSION_STRING < '4.0': diff --git a/DetachedFrame.py b/DetachedFrame.py index 660de9ad..4ed5a318 100644 --- a/DetachedFrame.py +++ b/DetachedFrame.py @@ -25,6 +25,9 @@ import wx import builtins +import gettext +_ = gettext.gettext + if wx.VERSION_STRING >= '4.0': wx.ST_SIZEGRIP = wx.STB_SIZEGRIP diff --git a/Editor.py b/Editor.py index 11ddb8d4..aab30a2b 100644 --- a/Editor.py +++ b/Editor.py @@ -20,7 +20,6 @@ # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## - import wx import os import sys diff --git a/ExperimentGenerator.py b/ExperimentGenerator.py index c41001be..92bb9d8b 100644 --- a/ExperimentGenerator.py +++ b/ExperimentGenerator.py @@ -6,6 +6,9 @@ import Container import DetachedFrame +import gettext +_ = gettext.gettext + class ExperimentGenerator: """ """ diff --git a/ImportLibrary.py b/ImportLibrary.py index b77b2279..d24f4280 100644 --- a/ImportLibrary.py +++ b/ImportLibrary.py @@ -27,6 +27,9 @@ from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin import wx.lib.dialogs from concurrent.futures import ThreadPoolExecutor + +import gettext +_ = gettext.gettext from Utilities import checkURL, getDirectorySize, RecurseSubDirs, getPYFileListFromInit, NotificationMessage from Decorators import BuzyCursorNotification @@ -417,7 +420,7 @@ def OnDelete(self, evt): ### delete files if db.rb2.GetValue(): - dial = wx.MessageDialog(None, _('Are you sure to delete python files into the %s directory?')%(label), label, wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) + dial = wx.MessageDialog(None, _('Are you sure to delete python files into the %s directory?')%(label), _("Delete Directory"), wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if dial.ShowModal() == wx.ID_YES: try: diff --git a/LibraryTree.py b/LibraryTree.py index 27aefc22..234a8dac 100644 --- a/LibraryTree.py +++ b/LibraryTree.py @@ -39,7 +39,8 @@ from pubsub import pub -_ = wx.GetTranslation +import gettext +_ = gettext.gettext ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## # @@ -199,12 +200,15 @@ def OnMotion(self, evt): if model_list: tip = _("Models:\n -") tip += '\n -'.join(model_list) - tip += '\n' else: tip = "" - tip += _("\nSub-Domains:\n") - tip += '\n -'.join(domain_list) + if len(domain_list) > 0: + tip += _("\n\nSub-Domains:") + if len(domain_list) == 1: + tip += " "+domain_list[0] + else: + tip += '\n -'.join(domain_list) ### is last item else: @@ -323,7 +327,10 @@ def OnDelete(self, evt): if os.path.isdir(path): - dial = wx.MessageDialog(None, _('Are you sure to delete from disk the librairie %s ?')%(label), label, wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) + dial = wx.MessageDialog(None, + _('Are you sure to delete from disk the librairie %s ?')%(label), + _("Delete Directory"), + wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if dial.ShowModal() == wx.ID_YES: try: ### delete directory @@ -339,7 +346,10 @@ def OnDelete(self, evt): else: - dial = wx.MessageDialog(None, _('Are you sure to delete from disk the python file %s ?')%(label), label, wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) + dial = wx.MessageDialog(None, + _('Are you sure to delete from disk the python file %s ?')%(label), + _("Delete File"), + wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if dial.ShowModal() == wx.ID_YES: try: ### delete file diff --git a/Menu.py b/Menu.py index 6da57a29..20992078 100644 --- a/Menu.py +++ b/Menu.py @@ -34,7 +34,8 @@ from PluginManager import PluginManager from ExperimentGenerator import ExperimentGenerator -_ = wx.GetTranslation +import gettext +_ = gettext.gettext if wx.VERSION_STRING > '4.0.1': wx.NewId = wx.NewIdRef diff --git a/Mixins/Abstractable.py b/Mixins/Abstractable.py index a35561dd..2484bddd 100644 --- a/Mixins/Abstractable.py +++ b/Mixins/Abstractable.py @@ -22,6 +22,9 @@ import sys +import gettext +_ = gettext.gettext + from Mixins.Attributable import Attributable import Container diff --git a/Patterns/Factory.py b/Patterns/Factory.py index 797cdb7f..2b4234ab 100644 --- a/Patterns/Factory.py +++ b/Patterns/Factory.py @@ -22,6 +22,9 @@ import builtins +import gettext +_ = gettext.gettext + if builtins.__dict__.get('GUI_FLAG',True): import wx diff --git a/PrintOut.py b/PrintOut.py index 21bd8a86..ff8f1ea0 100644 --- a/PrintOut.py +++ b/PrintOut.py @@ -7,6 +7,9 @@ import sys import copy +import gettext +_ = gettext.gettext + class Printout(wx.Printout): def __init__(self, canvas, title = "", size=(800, 800)): diff --git a/SpreadSheet.py b/SpreadSheet.py index 3753d0dd..7d7bcf6e 100644 --- a/SpreadSheet.py +++ b/SpreadSheet.py @@ -32,6 +32,9 @@ from PlotGUI import * from Utilities import printOnStatusBar +import gettext +_ = gettext.gettext + ### class MySheet(sheet.CSheet): """ @@ -142,6 +145,7 @@ def __init__(self, parent, id, title, aDEVS, separator=" "): toolbar.AddSeparator() self.chart = toolbar.AddTool(wx.NewIdRef(), wx.Bitmap(os.path.join(ICON_PATH,'graph_guru.png')), _('Chart'), '') else: + new = toolbar.AddTool(wx.NewIdRef(), "", wx.Bitmap(os.path.join(ICON_PATH,'new.png')), _('New')) open_file = toolbar.AddTool(wx.NewIdRef(), "", wx.Bitmap(os.path.join(ICON_PATH,'open.png')), _('Open')) saveas = toolbar.AddTool(wx.NewIdRef(), "", wx.Bitmap(os.path.join(ICON_PATH,'save.png')), _('SaveAs')) diff --git a/XMLModule.py b/XMLModule.py index 3953a900..2041872f 100644 --- a/XMLModule.py +++ b/XMLModule.py @@ -18,6 +18,9 @@ import tempfile import wx +import gettext +_ = gettext.gettext + import xml.etree.ElementTree as ET from xml.dom import minidom diff --git a/devsimpy.py b/devsimpy.py index 7bf38d6d..0713fcda 100644 --- a/devsimpy.py +++ b/devsimpy.py @@ -91,7 +91,8 @@ ### check if an upgrade of wxpython is possible from pip ! sys.stdout.write("Importing wxPython %s%s for python %s on %s (%s) platform...\n"%(wx.version(), " from devsimpy.ini" if ini_exist else '', platform.python_version(), platform.system(), platform.version())) -_ = wx.GetTranslation +import gettext +_ = gettext.gettext try: import wx.aui as aui @@ -978,7 +979,7 @@ def OnCloseWindow(self, event): self._mgr.UnInit() del self._mgr self.Destroy() - + #win = wx.Window_FindFocus() #if win != None: ## Note: you really have to use wx.wxEVT_KILL_FOCUS @@ -2177,7 +2178,7 @@ def OnAbout(self, event): info.SetName("""DEVSimPy""") info.SetVersion(self.GetVersion()) info.SetDescription(description) - info.SetCopyright(_("""(C) 2019 SISU Project - UMR CNRS 6134 SPE Lab.""")) + info.SetCopyright(_("""(C) 2020 SISU Project - UMR CNRS 6134 SPE Lab.""")) info.SetWebSite("""http://spe.univ-corse.fr""") info.SetLicence(licence) info.AddDeveloper(_("""\nL. Capocchi (capocchi@univ-corse.fr)\n""")) @@ -2303,7 +2304,7 @@ def OnClose(self, event): self.ShowMain() self.app.SetExceptionHook() - + # Call after the loading diagram method which depends on the invocked command line try: wx.CallAfter(self.app.frame.OnLoadDiagram) @@ -2415,7 +2416,7 @@ def __init__(self, redirect=False, filename=None): in on the main display of your Mac.""" elif wx.Platform == '__WXGTK__': - msg ="Unable to access the X Display, is $DISPLAY set properly?" + msg = "Unable to access the X Display, is $DISPLAY set properly?" else: msg = 'Unable to create GUI' diff --git a/plugins/blink.py b/plugins/blink.py index 40024176..75fcb6dc 100644 --- a/plugins/blink.py +++ b/plugins/blink.py @@ -14,6 +14,9 @@ import os import builtins +import gettext +_ = gettext.gettext + from types import MethodType from PluginManager import PluginManager diff --git a/plugins/state_trajectory.py b/plugins/state_trajectory.py index d880e80b..9509e5b0 100644 --- a/plugins/state_trajectory.py +++ b/plugins/state_trajectory.py @@ -23,6 +23,9 @@ import subprocess import importlib +import gettext +_ = gettext.gettext + import wx.lib.agw.aui as aui import matplotlib as mpl diff --git a/plugins/verbose.py b/plugins/verbose.py index 9e49f0b6..396e9bc6 100644 --- a/plugins/verbose.py +++ b/plugins/verbose.py @@ -15,6 +15,9 @@ import sys import os +import gettext +_ = gettext.gettext + from PluginManager import PluginManager global show_ext_trans From a5d7f39dabf3e258e33b74280888d800539f7ca0 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Thu, 19 Nov 2020 18:58:38 +0100 Subject: [PATCH 2/2] Add real time option (-rt) to devsimpy-nogui --- Container.py | 13 +++++++------ DomainInterface/DomainBehavior.py | 8 +++++--- SimulationGUI.py | 3 +-- SimulationNoGUI.py | 3 ++- Utilities.py | 4 +++- devsimpy-nogui.py | 9 ++++++++- simu.report | 2 +- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Container.py b/Container.py index 7a725040..c32cb28f 100644 --- a/Container.py +++ b/Container.py @@ -61,7 +61,7 @@ from traceback import format_exception from math import * ### for eval -if builtins.__dict__.get('GUI_FLAG',True): +if builtins.__dict__.get('GUI_FLAG', True): import ConnectDialog import DiagramConstantsDialog import SpreadSheet @@ -75,14 +75,15 @@ import WizardGUI import LabelGUI - RED = '#d91e1e' - GREEN = '#90ee90' - BLACK = '#000000' - BLUE = '#add8e6' +### Color definition +RED = '#d91e1e' +GREEN = '#90ee90' +BLACK = '#000000' +BLUE = '#add8e6' import Components -if builtins.__dict__.get('GUI_FLAG',True): +if builtins.__dict__.get('GUI_FLAG', True): import Menu #import ReloadModule diff --git a/DomainInterface/DomainBehavior.py b/DomainInterface/DomainBehavior.py index 12e30d7d..3cca77eb 100644 --- a/DomainInterface/DomainBehavior.py +++ b/DomainInterface/DomainBehavior.py @@ -97,10 +97,10 @@ def phaseIs(self, phase:str)->bool: return phase == self.state['status'] def passivate(self)->None: - self.passivateIn('passive') + return self.passivateIn('passive') def passivateIn(self, phase:str="")->None: - self.holdIn(phase, sigma=INFINITY) + return self.holdIn(phase, sigma=INFINITY) def holdIn(self, phase:str="", sigma:float=0.0)->None: ''' "Holding in phase " + phase + " for time " + sigma @@ -108,6 +108,8 @@ def holdIn(self, phase:str="", sigma:float=0.0)->None: self.state['status'] = phase self.state['sigma'] = sigma + return self.state + ### def pokePyPDEVS(self, p, v)->dict: ### adapted with PyPDEVS @@ -143,7 +145,7 @@ def getMsgPyDEVSTime(self, msg): def getMsgPyPDEVSTime(self, msg): return msg[1][0] - def getFlatComponentSet (self): + def getFlatComponentSet(self): return {self.name : self} def getSigma(self)->float: diff --git a/SimulationGUI.py b/SimulationGUI.py index 292ff596..daeeea48 100644 --- a/SimulationGUI.py +++ b/SimulationGUI.py @@ -55,7 +55,7 @@ def timer(): last = time.time() delta = 0 - time.clock() + time.time() while True: now = time.time() delta += now - last @@ -753,7 +753,6 @@ def ErrorManager(self, msg): ### if user want to correct error through an editor, we stop simulation process for trying again after the error is corrected. self.OnStop(event) else: - print(msg) raise MyBad(msg) class SimulationDialogPanel(Base, wx.Panel): diff --git a/SimulationNoGUI.py b/SimulationNoGUI.py index 28f7956f..c96b37e1 100644 --- a/SimulationNoGUI.py +++ b/SimulationNoGUI.py @@ -209,7 +209,7 @@ def __init__(self, master, time): ### def Run(self): - """ run simulation + """ run simulation. """ assert(self.master is not None) @@ -231,6 +231,7 @@ def Run(self): from SimulationGUI import simulator_factory if not self.ntl: self.master.FINAL_TIME = float(self.time) + self.thread = simulator_factory(self.master, self.selected_strategy, self.prof, self.ntl, self.verbose, self.dynamic_structure_flag, self.real_time_flag) return self.thread diff --git a/Utilities.py b/Utilities.py index 24f541e2..7ebc02e2 100644 --- a/Utilities.py +++ b/Utilities.py @@ -123,7 +123,9 @@ def printOnStatusBar(statusbar, data={}): for k,v in list(data.items()): statusbar.SetStatusText(v, k) -def NotificationMessage(title,message,parent,flag=wx.ICON_INFORMATION, timeout=False): +def NotificationMessage(title,message,parent, flag=2048, timeout=False): + """ 2048 is wx.ICON_INFORMATION + """ if builtins.__dict__['NOTIFICATION']: notify = wx.adv.NotificationMessage( title=title, diff --git a/devsimpy-nogui.py b/devsimpy-nogui.py index 0c5a0083..e15541c6 100644 --- a/devsimpy-nogui.py +++ b/devsimpy-nogui.py @@ -49,7 +49,8 @@ 'LOG_FILE': os.devnull, # log file (null by default) 'DEFAULT_SIM_STRATEGY': 'bag-based', #choose the default simulation strategy for PyDEVS 'PYDEVS_SIM_STRATEGY_DICT' : {'original':'SimStrategy1', 'bag-based':'SimStrategy2', 'direct-coupling':'SimStrategy3'}, # list of available simulation strategy for PyDEVS package - 'PYPDEVS_SIM_STRATEGY_DICT' : {'classic':'SimStrategy4', 'distributed':'SimStrategy5', 'parallel':'SimStrategy6'}, # list of available simulation strategy for PyPDEVS package + 'PYPDEVS_SIM_STRATEGY_DICT' : {'classic':'SimStrategy4', 'parallel':'SimStrategy5'}, # list of available simulation strategy for PyPDEVS package + 'PYPDEVS_221_SIM_STRATEGY_DICT' : {'classic':'SimStrategy4', 'parallel':'SimStrategy5'}, # list of available simulation strategy for PyPDEVS package 'HELP_PATH' : os.path.join('doc', 'html'), # path of help directory 'NTL' : False, # No Time Limit for the simulation 'DYNAMIC_STRUCTURE' : False, #Dynamic structure for PyPDEVS simulation @@ -101,6 +102,8 @@ def simulate(devs, duration, simu_name, is_remote): parser.add_argument("-name", help="simulation name", type=str, default="simu") # optional kernel for simulation kernel parser.add_argument("-kernel", help="simulation kernel [pyDEVS|PyPDEVS]", type=str, default="pyDEVS") + # optional real time + parser.add_argument("-rt", help="real time simulation (only for PyPDEVS)", action="store_true") # non-simulation options group = parser.add_mutually_exclusive_group() group.add_argument("-js", "--javascript",help="generate JS file", action="store_true") @@ -114,6 +117,10 @@ def simulate(devs, duration, simu_name, is_remote): if 'PyPDEVS' in args.kernel: builtins.__dict__['DEFAULT_DEVS_DIRNAME'] = 'PyPDEVS_221' builtins.__dict__['DEFAULT_SIM_STRATEGY'] = 'parallel' + + ### Real time only for PyPDEVS... + if args.rt: + builtins.__dict__['REAL_TIME'] = True filename = args.filename diff --git a/simu.report b/simu.report index 3c862ec2..53fd1ba9 100644 --- a/simu.report +++ b/simu.report @@ -1 +1 @@ -{"date": "Mon Oct 12 14:01:06 2020", "summary": "Simulation in batch mode with PyDEVS...DEVS instance created...Performing DEVS simulation...DEVS simulation completed!", "mode": "no-gui", "time": 10, "success": true, "output": [{"label": "QMeanAgents_port_0", "filename": "result550.dat"}], "devs_instance": "Master", "duration": 0.518989086151123} \ No newline at end of file +{"date": "Thu Nov 19 18:57:56 2020", "summary": "Simulation in batch mode with PyDEVS...DEVS instance created...Performing DEVS simulation...DEVS simulation completed!", "mode": "no-gui", "time": 10.0, "success": true, "output": [{"label": "MessagesCollector_7_port_0", "filename": "result10.dat"}, {"label": "MessagesCollector_5_port_0", "filename": "result80.dat"}, {"label": "MessagesCollector_3_port_0", "filename": "result390.dat"}, {"label": "MessagesCollector_1_port_0", "filename": "result450.dat"}], "devs_instance": "Master", "duration": 0.8519995212554932} \ No newline at end of file