Skip to content
7 changes: 1 addition & 6 deletions Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@
if builtins.__dict__.get('GUI_FLAG',True):
import wx

if wx.VERSION_STRING < '2.9':
from wx.lib.pubsub import Publisher
elif wx.VERSION_STRING < '4.0':
from wx.lib.pubsub import pub as Publisher
else:
from pubsub import pub as Publisher
from pubsub import pub as Publisher

import Editor

Expand Down
10 changes: 2 additions & 8 deletions Container.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@
import wx
import wx.lib.dragscroller
import wx.lib.dialogs
from wx.lib.newevent import NewEvent

_ = wx.GetTranslation

if wx.VERSION_STRING < '2.9':
from wx.lib.pubsub import Publisher
elif wx.VERSION_STRING < '4.0':
from wx.lib.pubsub import pub as Publisher
else:
from pubsub import pub as Publisher

from wx.lib.newevent import NewEvent
from pubsub import pub as Publisher

AttrUpdateEvent, EVT_ATTR_UPDATE = NewEvent()

Expand Down
38 changes: 31 additions & 7 deletions Decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import wx.lib.agw.aui.framemanager
AuiFloatingFrame = wx.lib.agw.aui.framemanager.AuiFloatingFrame

from pubsub import pub

def cond_decorator(flag, dec):
def decorate(fn):
return dec(fn) if flag else fn
Expand Down Expand Up @@ -143,21 +145,27 @@ def wrapper(*args):
return wrapper

class ThreadWithReturnValue(threading.Thread):
""" https://www.geeksforgeeks.org/python-different-ways-to-kill-a-thread/
"""
def __init__(self, *args, **kwargs):
super(ThreadWithReturnValue, self).__init__(*args, **kwargs)
self._return = None
#self._return = None
self.killed = False

self._log = ""
self._status = ""
pub.subscribe(self.my_listener, "to_progress_diag")

def start(self):
self.__run_backup = self.run
self.run = self.__run
threading.Thread.start(self)
threading.Thread.start(self)
self._status = 'alive'

def __run(self):
sys.settrace(self.globaltrace)
self._return = self.__run_backup()
self.run = self.__run_backup

def globaltrace(self, frame, event, arg):
if event == 'call':
return self.localtrace
Expand All @@ -170,6 +178,22 @@ def localtrace(self, frame, event, arg):
raise SystemExit()
return self.localtrace

def my_listener(self, message, arg2=None):
"""
Listener function
"""
self._log = message
if arg2 == 'stop':
self.kill()
elif arg2 is not None:
self._status = arg2

def getStatus(self):
return self._status

def getLog(self):
return self._log

def kill(self):
self.killed = True

Expand Down Expand Up @@ -201,13 +225,13 @@ def wrapper(*args):
thread = ThreadWithReturnValue(target = f, args = args)
thread.start()

while thread.isAlive():
while thread.isAlive():

if progress_dlg.WasCancelled() or progress_dlg.WasSkipped():
thread.kill()
break
else:
wx.MilliSleep(300)
progress_dlg.Pulse()
progress_dlg.Pulse(thread.getLog())
wx.SafeYield()

progress_dlg.Destroy()
Expand Down
7 changes: 1 addition & 6 deletions DiagramNotebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@
import sys
import builtins

# to send event
if wx.VERSION_STRING < '2.9':
from wx.lib.pubsub import Publisher as pub
else:
#from wx.lib.pubsub import pub
from pubsub import pub
from pubsub import pub

import Container
import Menu
Expand Down
25 changes: 17 additions & 8 deletions Menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
ID_HELP = wx.ID_HELP
ID_API_HELP = wx.NewIdRef()
ID_UPDATE_PIP_PACKAGE = wx.NewIdRef()
ID_UPDATE_FROM_GIT = wx.NewIdRef()
ID_UPDATE_FROM_GIT_ARCHIVE = wx.NewIdRef()
ID_UPDATE_FROM_GIT_REPO = wx.NewIdRef()
ID_CONTACT = wx.NewIdRef()
ID_ABOUT = wx.ID_ABOUT

Expand Down Expand Up @@ -478,16 +479,20 @@ def __init__(self, parent):

parent = parent.GetParent()

update_subMenu = wx.Menu()

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 of dependant pip packages"))
updateFromGit = wx.MenuItem(self, ID_UPDATE_FROM_GIT, _('Update From Git'), _("Update of DEVSimPy from Git archive"))
apiModel = wx.MenuItem(self, ID_API_HELP, _('&DEVSimPy API\tF2'), _("API for DEVSimPy user"))
updatePipPackage = wx.MenuItem(self, ID_UPDATE_PIP_PACKAGE, _('Dependencies (PIP Packages)\tF3'), _("Update of dependant pip packages"))
updateFromGitArchive = wx.MenuItem(self, ID_UPDATE_FROM_GIT_ARCHIVE, _('From Git Archive (zip)'), _("Update of DEVSimPy from Git archive"))
updateFromGitRepo = wx.MenuItem(self, ID_UPDATE_FROM_GIT_REPO, _('From Git Repository (Pull)'), _("Update of DEVSimPy from its Git repo"))
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')))
updateFromGit.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH,'update.png')))
updateFromGitArchive.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH,'update.png')))
updateFromGitRepo.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')))
Expand All @@ -497,16 +502,20 @@ def __init__(self, parent):
AppendItem(helpModel)
AppendItem(apiModel)
self.AppendSeparator()
AppendItem(updatePipPackage)
AppendItem(updateFromGit)
Update_menu = AppendMenu(self, -1, _("Update"), update_subMenu)
Update_SubMenu0 = update_subMenu.Append(updatePipPackage)
update_subMenu.AppendSeparator()
Update_SubMenu1 = update_subMenu.Append(updateFromGitArchive)
Update_SubMenu2 = update_subMenu.Append(updateFromGitRepo)
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.OnUpdatPiPPackage, id=ID_UPDATE_PIP_PACKAGE)
parent.Bind(wx.EVT_MENU, parent.OnUpdatFromGit, id=ID_UPDATE_FROM_GIT)
parent.Bind(wx.EVT_MENU, parent.OnUpdatFromGitRepo, id=ID_UPDATE_FROM_GIT_REPO)
parent.Bind(wx.EVT_MENU, parent.OnUpdatFromGitArchive, id=ID_UPDATE_FROM_GIT_ARCHIVE)
parent.Bind(wx.EVT_MENU, parent.OnAbout, id=ID_ABOUT)
parent.Bind(wx.EVT_MENU, parent.OnContact, id=ID_CONTACT)

Expand Down
7 changes: 1 addition & 6 deletions SimulationGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
import threading

# to send event
if wx.VERSION_STRING < '2.9':
from wx.lib.pubsub import Publisher as pub
elif wx.VERSION_STRING < '4.0':
from wx.lib.pubsub import pub
else:
from pubsub import pub
from pubsub import pub

from tempfile import gettempdir

Expand Down
9 changes: 2 additions & 7 deletions SpreadSheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@
from wx.lib import sheet

# to send event
if wx.VERSION_STRING < '2.9':
from wx.lib.pubsub import Publisher
elif wx.VERSION_STRING < '4.0':
from wx.lib.pubsub import pub as Publisher
else:
from pubsub import pub as Publisher
from pubsub import pub as Publisher

#from Container import *
from PlotGUI import *
Expand Down Expand Up @@ -90,7 +85,7 @@ def Populate(self, data):
try:
### inform Frame that table us full for graph icon enabling
Publisher.sendMessage("isfull", msg=self._full_flag)
except wx.lib.pubsub.core.topicargspecimpl.SenderMissingReqdMsgDataError as info:
except pubsub.pub.SenderMissingReqdMsgDataError as info:
pass

self.AutoSize()
Expand Down
Loading