diff --git a/Menu.py b/Menu.py index 6df9d569..d2efd39d 100644 --- a/Menu.py +++ b/Menu.py @@ -96,6 +96,7 @@ # Help menu identifiers ID_HELP = wx.ID_HELP ID_API_HELP = wx.NewIdRef() +ID_UPDATE_PIP_PACKAGE = wx.NewIdRef() ID_CONTACT = wx.NewIdRef() ID_ABOUT = wx.ID_ABOUT @@ -475,10 +476,12 @@ def __init__(self, parent): helpModel = wx.MenuItem(self, ID_HELP, _('&DEVSimPy Help\tF1'), _("Help for DEVSimPy user")) apiModel = wx.MenuItem(self, ID_API_HELP, _('&DEVSimPy API\tF2'), _("API for DEVSimPy user")) + updatePipPackage = wx.MenuItem(self, ID_UPDATE_PIP_PACKAGE, _('Update PIP Packages\tF3'), _("Update pip packages")) contactModel = wx.MenuItem(self, ID_CONTACT, _('Contact the Author...'), _("Send mail to the author")) aboutModel = wx.MenuItem(self, ID_ABOUT, _('About DEVSimPy...'), _("About DEVSimPy")) helpModel.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH,'search.png'))) + updatePipPackage.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH,'update.png'))) apiModel.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH,'api.png'))) contactModel.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH,'mail.png'))) aboutModel.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH,'info.png'))) @@ -488,11 +491,14 @@ def __init__(self, parent): AppendItem(helpModel) AppendItem(apiModel) self.AppendSeparator() + AppendItem(updatePipPackage) + self.AppendSeparator() AppendItem(aboutModel) AppendItem(contactModel) parent.Bind(wx.EVT_MENU, parent.OnHelp, id=ID_HELP) parent.Bind(wx.EVT_MENU, parent.OnAPI, id=ID_API_HELP) + parent.Bind(wx.EVT_MENU, parent.OnUpdatePiPPackage, id=ID_UPDATE_PIP_PACKAGE) parent.Bind(wx.EVT_MENU, parent.OnAbout, id=ID_ABOUT) parent.Bind(wx.EVT_MENU, parent.OnContact, id=ID_CONTACT) diff --git a/PreferencesGUI.py b/PreferencesGUI.py index 05b7e110..2bfb1c17 100644 --- a/PreferencesGUI.py +++ b/PreferencesGUI.py @@ -82,12 +82,18 @@ def __init__(self, parent): self.nb_history_undo.SetRange(2, 100) self.nb_history_undo.SetValue(NB_HISTORY_UNDO) - ### CheckBox + ### CheckBox for transparancy self.cb1 = wx.CheckBox(self, wx.NewIdRef(), _('Transparency')) if wx.VERSION_STRING >= '4.0': self.cb1.SetToolTipString = self.cb1.SetToolTip self.cb1.SetToolTipString(_("Transparency for the detached frame of diagrams")) self.cb1.SetValue(builtins.__dict__['TRANSPARENCY']) + ### CheckBox for notification + self.cb11 = wx.CheckBox(self, wx.NewIdRef(), _('Notififcations')) + if wx.VERSION_STRING >= '4.0': self.cb11.SetToolTipString = self.cb11.SetToolTip + self.cb1.SetToolTipString(_("Enable the notification messages")) + self.cb11.SetValue(builtins.__dict__['NOTIFICATION']) + ### wxPython version wxv = [wx.VERSION_STRING] @@ -115,6 +121,7 @@ def __init__(self, parent): vsizer.Add(self.out_dir, 1, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) vsizer.Add(hsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) vsizer.Add(self.cb1, 1, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) + vsizer.Add(self.cb11, 1, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) box1.Add(vsizer, 1, wx.EXPAND) ### Set sizer @@ -135,6 +142,7 @@ def OnApply(self, event): self.OnPluginsDirChanged(event) self.OnOutDirChanged(event) self.OnTransparancyChanged(event) + self.OnNotificationChanged(event) self.OnwxPythonVersionChanged(event) ### if the version of wx has been changed in OnwxPythonVersionChanged, we inform the user. @@ -196,6 +204,10 @@ def OnOutDirChanged(self, event): def OnTransparancyChanged(self, event): builtins.__dict__['TRANSPARENCY'] = self.cb1.GetValue() + ### + def OnNotificationChanged(self, event): + builtins.__dict__['NOTIFICATION'] = self.cb11.GetValue() + def OnwxPythonVersionChanged(self, event): """ """ @@ -705,7 +717,7 @@ def __init__(self, parent, title): hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer.Add(self.cancel,0) - hsizer.Add(self.apply,0) + hsizer.Add(self.apply,0, wx.EXPAND|wx.LEFT, 5) vsizer.Add(self.pref, 1, wx.ALL|wx.EXPAND, 5) vsizer.Add(hsizer, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) diff --git a/Utilities.py b/Utilities.py index 27b8908d..8179cd04 100644 --- a/Utilities.py +++ b/Utilities.py @@ -47,6 +47,8 @@ import pip import importlib +from subprocess import call + # Used for smooth (spectrum) try: from numpy import * @@ -79,23 +81,24 @@ def printOnStatusBar(statusbar, data={}): statusbar.SetStatusText(v, k) def NotificationMessage(title,message,parent,flag=wx.ICON_INFORMATION, timeout=False): - notify = wx.adv.NotificationMessage( - title=title, - message=message, - parent=parent, flags=flag) - - # Various options can be set after the message is created if desired. - # notify.SetFlags(# wx.ICON_INFORMATION - # wx.ICON_WARNING - # # wx.ICON_ERROR - # ) - # notify.SetTitle("Wooot") - # notify.SetMessage("It's a message!") - # notify.SetParent(self) - if timeout: - notify.Show(timeout=timeout) # 1 for short timeout, 100 for long timeout - else: - notify.Show() + if builtins.__dict__['NOTIFICATION']: + notify = wx.adv.NotificationMessage( + title=title, + message=message, + parent=parent, flags=flag) + + # Various options can be set after the message is created if desired. + # notify.SetFlags(# wx.ICON_INFORMATION + # wx.ICON_WARNING + # # wx.ICON_ERROR + # ) + # notify.SetTitle("Wooot") + # notify.SetMessage("It's a message!") + # notify.SetParent(self) + if timeout: + notify.Show(timeout=timeout) # 1 for short timeout, 100 for long timeout + else: + notify.Show() def now(): """ Returns the current time formatted. """ @@ -151,6 +154,23 @@ def PyBuzyInfo(msg, time): del busy +def updatePiP(): + call("python -m pip install --upgrade pip", shell=True) + +def updatePackageWithPiP(): + """ Update all installed package using pip + """ + + if pip.__version__ > '10.0.1': + import pkg_resources + packages = [dist.project_name for dist in pkg_resources.working_set if 'PyPubSub' not in dist.project_name] + call("pip install --upgrade -r requirements.txt", shell=True) + else: + packages = [dist.project_name for dist in pip.get_installed_distributions() if 'PyPubSub' not in dist.project_name] + call("pip install --upgrade " + ' '.join(packages), shell=True) + + NotificationMessage(_('Information'), 'All pip packages have been updated!', None, timeout=5) + def install_and_import(package): try: importlib.import_module(package) diff --git a/devsimpy.py b/devsimpy.py index 2f731931..a0dd7cf3 100644 --- a/devsimpy.py +++ b/devsimpy.py @@ -150,7 +150,8 @@ 'DYNAMIC_STRUCTURE' : False, # Dynamic Structure for local PyPDEVS simulation 'REAL_TIME': False, ### PyPDEVS threaded real time simulation 'VERBOSE':False, - 'TRANSPARENCY' : True, # Transparancy for DetachedFrame + 'TRANSPARENCY' : True, # Transparancy for DetachedFrame activated + 'NOTIFICATION' : True, # Notification message activated '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'), @@ -186,7 +187,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 +from Utilities import GetUserConfigDir, install_and_import, printOnStatusBar, NotificationMessage, updatePackageWithPiP from Decorators import redirectStdout, BuzyCursorNotification from DetachedFrame import DetachedFrame from LibraryTree import LibraryTree @@ -2008,6 +2009,11 @@ 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. diff --git a/icons/update.png b/icons/update.png new file mode 100644 index 00000000..2f18e972 Binary files /dev/null and b/icons/update.png differ