From 577a698fe3864aa59ab2427546a468faf760f221 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Thu, 26 Dec 2013 14:59:49 -0200 Subject: [PATCH] Using thread instead of a new process to verify invesalius new versions --- invesalius/gui/dialogs.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ invesalius/invesalius.py | 11 ++++++----- invesalius/utils.py | 39 ++++++++++++++++++--------------------- 3 files changed, 85 insertions(+), 26 deletions(-) diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index d6d1929..c6d7271 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -373,6 +373,67 @@ class MessageDialog(wx.Dialog): self.Centre() + +class UpdateMessageDialog(wx.Dialog): + def __init__(self, url): + msg=_("A new version of InVesalius is available. Do you want to open the download website now?") + title=_("Invesalius Update") + self.url = url + + pre = wx.PreDialog() + pre.Create(None, -1, title, size=(360, 370), pos=wx.DefaultPosition, + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) + self.PostCreate(pre) + + # Static text which contains message to user + label = wx.StaticText(self, -1, msg) + + # Buttons + btn_yes = wx.Button(self, wx.ID_YES) + btn_yes.SetHelpText("") + btn_yes.SetDefault() + + btn_no = wx.Button(self, wx.ID_NO) + btn_no.SetHelpText("") + + btnsizer = wx.StdDialogButtonSizer() + btnsizer.AddButton(btn_yes) + btnsizer.AddButton(btn_no) + btnsizer.Realize() + + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) + sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL| + wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5) + self.SetSizer(sizer) + sizer.Fit(self) + self.Centre() + + btn_yes.Bind(wx.EVT_BUTTON, self._OnYes) + btn_no.Bind(wx.EVT_BUTTON, self._OnNo) + + # Subscribing to the pubsub event which happens when InVesalius is + # closed. + Publisher.subscribe(self._OnCloseInV, 'Exit') + + def _OnYes(self, evt): + # Launches the default browser with the url to download the new + # InVesalius version. + wx.LaunchDefaultBrowser(self.url) + self.Close() + self.Destroy() + + def _OnNo(self, evt): + # Closes and destroy this dialog. + self.Close() + self.Destroy() + + def _OnCloseInV(self, pubsub_evt): + # Closes and destroy this dialog. + self.Close() + self.Destroy() + + def SaveChangesDialog__Old(filename): message = _("The project %s has been modified.\nSave changes?")%filename dlg = MessageDialog(message) diff --git a/invesalius/invesalius.py b/invesalius/invesalius.py index f79a51e..883f090 100755 --- a/invesalius/invesalius.py +++ b/invesalius/invesalius.py @@ -68,6 +68,7 @@ class InVesalius(wx.App): self.splash = SplashScreen() self.splash.Show() wx.CallLater(1000,self.Startup2) + return True def MacOpenFile(self, filename): @@ -180,6 +181,11 @@ class SplashScreen(wx.SplashScreen): self.fc = wx.FutureCall(1, self.ShowMain) wx.FutureCall(1, parse_comand_line) + # Check for updates + from threading import Thread + p = Thread(target=utils.UpdateCheck, args=()) + p.start() + def OnClose(self, evt): # Make sure the default handler runs too so this window gets # destroyed @@ -300,11 +306,6 @@ if __name__ == '__main__': # import modules as they were on root invesalius folder sys.path.append(".") - # Check for updates - from multiprocessing import Process - p = Process(target=utils.UpdateCheck, args=()) - p.daemon=True - p.start() # Init application main() diff --git a/invesalius/utils.py b/invesalius/utils.py index 308296b..7982104 100644 --- a/invesalius/utils.py +++ b/invesalius/utils.py @@ -369,20 +369,31 @@ def get_system_encoding(): def UpdateCheck(): import urllib import urllib2 + import wx + def _show_update_info(): + from gui import dialogs + msg=_("A new version of InVesalius is available. Do you want to open the download website now?") + title=_("Invesalius Update") + msgdlg = dialogs.UpdateMessageDialog(url) + #if (msgdlg.Show()==wx.ID_YES): + #wx.LaunchDefaultBrowser(url) + msgdlg.Show() + #msgdlg.Destroy() + print "Checking updates..." # Check if there is a language set - import i18n + #import i18n import session as ses session = ses.Session() install_lang = 0 if session.ReadLanguage(): lang = session.GetLanguage() - if (lang != "False"): - _ = i18n.InstallLanguage(lang) - install_lang = 1 - if (install_lang==0): - return + #if (lang != "False"): + #_ = i18n.InstallLanguage(lang) + #install_lang = 1 + #if (install_lang==0): + #return if session.ReadRandomId(): random_id = session.GetRandomId() @@ -406,18 +417,4 @@ def UpdateCheck(): url = response.readline().rstrip() if (last!=const.INVESALIUS_VERSION): print " ...New update found!!! -> version:", last #, ", url=",url - from time import sleep - sleep(2) - import wx - app=wx.App() - import i18n - _ = i18n.InstallLanguage(lang) - msg=_("A new version of InVesalius is available. Do you want to open the download website now?") - title=_("Invesalius Update") - msgdlg = wx.MessageDialog(None,msg,title, wx.YES_NO | wx.ICON_INFORMATION) - if (msgdlg.ShowModal()==wx.ID_YES): - wx.LaunchDefaultBrowser(url) - msgdlg.Destroy() - app.MainLoop() - - + wx.CallAfter(wx.CallLater, 1000, _show_update_info) -- libgit2 0.21.2