Skip to content

Commit b52af11

Browse files
authored
Merge pull request #101 from capocchi/version-4.0
Version 4.0
2 parents 77a0fca + b823f91 commit b52af11

7 files changed

Lines changed: 86 additions & 97 deletions

File tree

Complexity.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,6 @@
2121
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2222

2323
import os, sys
24-
ABS_HOME_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
25-
26-
import builtins
27-
### specific built-in variables. (don't modify the default value. If you want to change it, go to the PreferencesGUI from devsimpy interface.)
28-
builtin_dict = {'SPLASH_PNG': os.path.join(ABS_HOME_PATH, 'splash', 'splash.png'), # abslolute path
29-
'DEVSIMPY_PNG': 'iconDEVSimPy.png', # png file for devsimpy icon
30-
'HOME_PATH': ABS_HOME_PATH,
31-
'ICON_PATH': os.path.join(ABS_HOME_PATH, 'icons'),
32-
'ICON_PATH_16_16': os.path.join(ABS_HOME_PATH, 'icons', '16x16'),
33-
'SIMULATION_SUCCESS_SOUND_PATH': os.path.join(ABS_HOME_PATH,'sounds', 'Simulation-Success.wav'),
34-
'SIMULATION_ERROR_SOUND_PATH': os.path.join(ABS_HOME_PATH,'sounds', 'Simulation-Error.wav'),
35-
'DOMAIN_PATH': os.path.join(ABS_HOME_PATH, 'Domain'), # path of local lib directory
36-
'NB_OPENED_FILE': 5, # number of recent files
37-
'NB_HISTORY_UNDO': 5, # number of undo
38-
'OUT_DIR': 'out', # name of local output directory (composed by all .dat, .txt files)
39-
'PLUGINS_PATH': os.path.join(ABS_HOME_PATH, 'plugins'), # path of plug-ins directory
40-
'FONT_SIZE': 12, # Block font size
41-
'LOCAL_EDITOR': True, # for the use of local editor
42-
'LOG_FILE': os.devnull, # log file (null by default)
43-
'DEFAULT_SIM_STRATEGY': 'bag-based', #choose the default simulation strategy for PyDEVS
44-
'PYDEVS_SIM_STRATEGY_DICT' : {'original':'SimStrategy1', 'bag-based':'SimStrategy2', 'direct-coupling':'SimStrategy3'}, # list of available simulation strategy for PyDEVS package
45-
'PYPDEVS_SIM_STRATEGY_DICT' : {'classic':'SimStrategy4', 'distributed':'SimStrategy5', 'parallel':'SimStrategy6'}, # list of available simulation strategy for PyPDEVS package
46-
'HELP_PATH' : os.path.join('doc', 'html'), # path of help directory
47-
'NTL' : False, # No Time Limit for the simulation
48-
'DYNAMIC_STRUCTURE' : False, # Dynamic Structure for local PyPDEVS simulation
49-
'REAL_TIME': False, ### PyPDEVS threaded real time simulation
50-
'VERBOSE':False,
51-
'TRANSPARENCY' : True, # Transparancy for DetachedFrame
52-
'DEFAULT_PLOT_DYN_FREQ' : 100, # frequence of dynamic plot of QuickScope (to avoid overhead),
53-
'DEFAULT_DEVS_DIRNAME':'PyDEVS', # default DEVS Kernel directory
54-
'DEVS_DIR_PATH_DICT':{'PyDEVS':os.path.join(ABS_HOME_PATH,'DEVSKernel','PyDEVS'),
55-
'PyPDEVS_221':os.path.join(ABS_HOME_PATH,'DEVSKernel','PyPDEVS','pypdevs221' ,'src'),
56-
'PyPDEVS':os.path.join(ABS_HOME_PATH,'DEVSKernel','PyPDEVS','old')},
57-
'GUI_FLAG':False
58-
}
59-
60-
# Sets the homepath variable to the directory where your application is located (sys.argv[0]).
61-
builtins.__dict__.update(builtin_dict)
62-
6324
import inspect
6425
import Components
6526
import textwrap

Container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
### for all dsp model build with old version of DEVSimPy
110110
sys.modules['Savable'] = sys.modules['Mixins.Savable']
111111

112-
from Decorators import BuzyCursorNotification, StatusBarNotification, ProgressNotification, Pre_Undo, Post_Undo, cond_decorator
112+
from Decorators import BuzyCursorNotification, StatusBarNotification, Pre_Undo, Post_Undo, cond_decorator
113113
from Utilities import HEXToRGB, RGBToHEX, relpath, GetActiveWindow, playSound, sendEvent, getInstance, FixedList, getObjectFromString, getTopLevelWindow, printOnStatusBar
114114
from Patterns.Observer import Subject, Observer
115115

@@ -591,7 +591,7 @@ def GetParent(self):
591591
def GetGrandParent(self):
592592
return self.GetParent().GetParent()
593593

594-
@cond_decorator(builtins.__dict__.get('GUI_FLAG',True), ProgressNotification("DEVSimPy open file"))
594+
@BuzyCursorNotification
595595
def LoadFile(self, fileName = None):
596596
""" Function that load diagram from a file.
597597
"""

Decorators.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ def BuzyCursorNotification(f):
102102
""" Decorator which give the buzy cursor for long process
103103
"""
104104
def wrapper(*args):
105-
wx.BeginBusyCursor()
105+
wait = wx.BusyCursor()
106106
#wx.SafeYield()
107107
r = f(*args)
108-
wx.EndBusyCursor()
108+
del wait
109109
return r
110110
return wrapper
111111

@@ -142,24 +142,45 @@ def wrapper(*args):
142142

143143
return wrapper
144144

145+
class ThreadWithReturnValue(threading.Thread):
146+
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None):
147+
threading.Thread.__init__(self, group, target, name, args, kwargs, daemon=daemon)
148+
149+
self._return = None
150+
151+
def run(self):
152+
if self._target is not None:
153+
self._return = self._target(*self._args, **self._kwargs)
154+
155+
def join(self):
156+
threading.Thread.join(self)
157+
return self._return
158+
145159
@decorator_with_args
146-
def ProgressNotification(f,arg):
160+
def ProgressNotification(f, arg):
147161
def wrapper(*args):
148-
txt = arg
149-
new_path = args[-1]
150162

151-
progress_dlg = wx.ProgressDialog(txt,
152-
"Loading %s ..."%os.path.basename(new_path), parent=None,
153-
style=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME)
154-
progress_dlg.Pulse()
163+
thread = ThreadWithReturnValue(target = f, args = args)
164+
thread.start()
155165

156-
#wx.SafeYield()
166+
title = arg
167+
new_path = args[-1]
168+
if isinstance(new_path, str) and os.path.isfile(new_path):
169+
message = _("Loading %s ...")%os.path.basename(new_path)
170+
else:
171+
message = _('Please wait..')
157172

158-
r = f(*args)
173+
progress_dlg = wx.ProgressDialog(title, message, style=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME)
174+
175+
while thread.isAlive():
176+
wx.MilliSleep(300)
177+
progress_dlg.Pulse()
178+
wx.SafeYield()
159179

160180
progress_dlg.Destroy()
181+
182+
return thread.join()
161183

162-
return r
163184
return wrapper
164185

165186
def print_timing(func):

LibraryTree.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,12 +1092,15 @@ def OnItemDocumentation(self, evt):
10921092
else:
10931093
doc = inspect.getdoc(module)
10941094

1095+
### Add maccabe complexity measure
1096+
doc += "".join([_("\n\n MacCabe Complexity: %d")%elf.MetricDico[item]['mcc']])
1097+
10951098
if doc:
1096-
dlg = wx.lib.dialogs.ScrolledMessageDialog(self, doc, name, style=wx.OK|wx.ICON_EXCLAMATION|wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
1099+
dlg = wx.lib.dialogs.ScrolledMessageDialog(self, doc, _("%s Documentation")%name, style=wx.OK|wx.ICON_EXCLAMATION|wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
10971100
dlg.CenterOnParent(wx.BOTH)
10981101
dlg.ShowModal()
10991102
else:
1100-
wx.MessageBox(_('No documentation'), name, wx.OK|wx.ICON_INFORMATION)
1103+
wx.MessageBox(_("No documentation! \n Please define the documentation of the model %s in the header of its python file.")%name, _("%s Documentation")%name, wx.OK|wx.ICON_INFORMATION)
11011104

11021105
###
11031106
def OnInfo(self, event):

Menu.py

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -527,48 +527,49 @@ def OnOpenMenu(self, event):
527527

528528
menu = event.GetMenu()
529529

530-
posm = self.FindMenu(menu.GetTitle())
531-
532-
### if the opened menu is the File menu
533-
if isinstance(menu, FileMenu):
534-
535-
if wx.VERSION_STRING < '4.0':
536-
### Before Phoenix Transition
537-
### if item exist, we delete him
538-
if menu.FindItemById(ID_RECENT):menu.Delete(ID_RECENT)
539-
540-
### we insert the recent files menu
541-
menu.InsertMenu(1, ID_RECENT, _("Recent files"), RecentFileMenu(self))
542-
else:
543-
if platform.system() == 'Windows':
544-
### After Pnoenix Transition
545-
self.Replace(posm, FileMenu(self), _("&File"))
530+
if menu:
531+
posm = self.FindMenu(menu.GetTitle())
532+
533+
### if the opened menu is the File menu
534+
if isinstance(menu, FileMenu):
535+
536+
if wx.VERSION_STRING < '4.0':
537+
### Before Phoenix Transition
538+
### if item exist, we delete him
539+
if menu.FindItemById(ID_RECENT):menu.Delete(ID_RECENT)
540+
541+
### we insert the recent files menu
542+
menu.InsertMenu(1, ID_RECENT, _("Recent files"), RecentFileMenu(self))
546543
else:
547-
label = _("Recent files")
548-
ID = menu.FindItem(label)
549-
item, pos = menu.FindChildItem(ID)
550-
menu.Remove(ID)
551-
menu.Insert(pos, ID, label, RecentFileMenu(self))
552-
553-
elif isinstance(menu, SettingsMenu):
554-
555-
if wx.VERSION_STRING < '4.0':
556-
### Before Pnoenix Transition
557-
### if item exist, we delete him
558-
if menu.FindItemById(ID_PROFILE): menu.Delete(ID_PROFILE)
544+
if platform.system() == 'Windows':
545+
### After Pnoenix Transition
546+
self.Replace(posm, FileMenu(self), _("&File"))
547+
else:
548+
label = _("Recent files")
549+
ID = menu.FindItem(label)
550+
item, pos = menu.FindChildItem(ID)
551+
menu.Remove(ID)
552+
menu.Insert(pos, ID, label, RecentFileMenu(self))
553+
554+
elif isinstance(menu, SettingsMenu):
559555

560-
### we insert the profile files menu
561-
menu.InsertMenu(1, ID_PROFILE, _('Profile'), ProfileFileMenu(self))
562-
else:
563-
### After Pnoenix Transition
564-
if platform.system() == 'Windows':
565-
self.Replace(posm, SettingsMenu(self), _("&Options"))
556+
if wx.VERSION_STRING < '4.0':
557+
### Before Pnoenix Transition
558+
### if item exist, we delete him
559+
if menu.FindItemById(ID_PROFILE): menu.Delete(ID_PROFILE)
560+
561+
### we insert the profile files menu
562+
menu.InsertMenu(1, ID_PROFILE, _('Profile'), ProfileFileMenu(self))
566563
else:
567-
label = _('Profile')
568-
ID = menu.FindItem(label)
569-
item, pos = menu.FindChildItem(ID)
570-
menu.Remove(ID)
571-
menu.Insert(pos, ID, label, ProfileFileMenu(self))
564+
### After Pnoenix Transition
565+
if platform.system() == 'Windows':
566+
self.Replace(posm, SettingsMenu(self), _("&Options"))
567+
else:
568+
label = _('Profile')
569+
ID = menu.FindItem(label)
570+
item, pos = menu.FindChildItem(ID)
571+
menu.Remove(ID)
572+
menu.Insert(pos, ID, label, ProfileFileMenu(self))
572573

573574

574575
#def OnCloseMenu(self, event):

Utilities.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,15 @@ def updatePackageWithPiP():
181181
""" Update all installed package using pip
182182
"""
183183

184+
updatePiP()
185+
184186
if pip.__version__ > '10.0.1':
185187
import pkg_resources
186188
packages = [dist.project_name for dist in pkg_resources.working_set if 'PyPubSub' not in dist.project_name]
187-
call("pip install --upgrade -r requirements.txt", shell=True)
189+
call("pip install --user --upgrade -r requirements.txt", shell=True)
188190
else:
189191
packages = [dist.project_name for dist in pip.get_installed_distributions() if 'PyPubSub' not in dist.project_name]
190-
call("pip install --upgrade " + ' '.join(packages), shell=True)
192+
call("pip install --user --upgrade " + ' '.join(packages), shell=True)
191193

192194
NotificationMessage(_('Information'), 'All pip packages have been updated!', None, timeout=5)
193195

devsimpy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
from pluginmanager import load_plugins, enable_plugin
189189
from which import which
190190
from Utilities import GetUserConfigDir, install_and_import, updatePackageWithPiP
191-
from Decorators import redirectStdout, BuzyCursorNotification
191+
from Decorators import redirectStdout, BuzyCursorNotification, ProgressNotification, cond_decorator
192192
from DetachedFrame import DetachedFrame
193193
from LibraryTree import LibraryTree
194194
from LibPanel import LibPanel
@@ -1998,6 +1998,7 @@ def OnHelp(self, event):
19981998
else:
19991999
self.help.Display(os.path.join('html','toc.html'))
20002000

2001+
@cond_decorator(builtins.__dict__.get('GUI_FLAG',True), ProgressNotification("DEVSimPy Update pip packages"))
20012002
def OnUpdatePiPPackage(self, event):
20022003
updatePackageWithPiP()
20032004

0 commit comments

Comments
 (0)