Commit 577a698fe3864aa59ab2427546a468faf760f221
1 parent
a26fd3c8
Exists in
master
and in
54 other branches
Using thread instead of a new process to verify invesalius new versions
Showing
3 changed files
with
85 additions
and
26 deletions
Show diff stats
invesalius/gui/dialogs.py
@@ -373,6 +373,67 @@ class MessageDialog(wx.Dialog): | @@ -373,6 +373,67 @@ class MessageDialog(wx.Dialog): | ||
373 | 373 | ||
374 | self.Centre() | 374 | self.Centre() |
375 | 375 | ||
376 | + | ||
377 | +class UpdateMessageDialog(wx.Dialog): | ||
378 | + def __init__(self, url): | ||
379 | + msg=_("A new version of InVesalius is available. Do you want to open the download website now?") | ||
380 | + title=_("Invesalius Update") | ||
381 | + self.url = url | ||
382 | + | ||
383 | + pre = wx.PreDialog() | ||
384 | + pre.Create(None, -1, title, size=(360, 370), pos=wx.DefaultPosition, | ||
385 | + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION) | ||
386 | + self.PostCreate(pre) | ||
387 | + | ||
388 | + # Static text which contains message to user | ||
389 | + label = wx.StaticText(self, -1, msg) | ||
390 | + | ||
391 | + # Buttons | ||
392 | + btn_yes = wx.Button(self, wx.ID_YES) | ||
393 | + btn_yes.SetHelpText("") | ||
394 | + btn_yes.SetDefault() | ||
395 | + | ||
396 | + btn_no = wx.Button(self, wx.ID_NO) | ||
397 | + btn_no.SetHelpText("") | ||
398 | + | ||
399 | + btnsizer = wx.StdDialogButtonSizer() | ||
400 | + btnsizer.AddButton(btn_yes) | ||
401 | + btnsizer.AddButton(btn_no) | ||
402 | + btnsizer.Realize() | ||
403 | + | ||
404 | + sizer = wx.BoxSizer(wx.VERTICAL) | ||
405 | + sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) | ||
406 | + sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL| | ||
407 | + wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5) | ||
408 | + self.SetSizer(sizer) | ||
409 | + sizer.Fit(self) | ||
410 | + self.Centre() | ||
411 | + | ||
412 | + btn_yes.Bind(wx.EVT_BUTTON, self._OnYes) | ||
413 | + btn_no.Bind(wx.EVT_BUTTON, self._OnNo) | ||
414 | + | ||
415 | + # Subscribing to the pubsub event which happens when InVesalius is | ||
416 | + # closed. | ||
417 | + Publisher.subscribe(self._OnCloseInV, 'Exit') | ||
418 | + | ||
419 | + def _OnYes(self, evt): | ||
420 | + # Launches the default browser with the url to download the new | ||
421 | + # InVesalius version. | ||
422 | + wx.LaunchDefaultBrowser(self.url) | ||
423 | + self.Close() | ||
424 | + self.Destroy() | ||
425 | + | ||
426 | + def _OnNo(self, evt): | ||
427 | + # Closes and destroy this dialog. | ||
428 | + self.Close() | ||
429 | + self.Destroy() | ||
430 | + | ||
431 | + def _OnCloseInV(self, pubsub_evt): | ||
432 | + # Closes and destroy this dialog. | ||
433 | + self.Close() | ||
434 | + self.Destroy() | ||
435 | + | ||
436 | + | ||
376 | def SaveChangesDialog__Old(filename): | 437 | def SaveChangesDialog__Old(filename): |
377 | message = _("The project %s has been modified.\nSave changes?")%filename | 438 | message = _("The project %s has been modified.\nSave changes?")%filename |
378 | dlg = MessageDialog(message) | 439 | dlg = MessageDialog(message) |
invesalius/invesalius.py
@@ -68,6 +68,7 @@ class InVesalius(wx.App): | @@ -68,6 +68,7 @@ class InVesalius(wx.App): | ||
68 | self.splash = SplashScreen() | 68 | self.splash = SplashScreen() |
69 | self.splash.Show() | 69 | self.splash.Show() |
70 | wx.CallLater(1000,self.Startup2) | 70 | wx.CallLater(1000,self.Startup2) |
71 | + | ||
71 | return True | 72 | return True |
72 | 73 | ||
73 | def MacOpenFile(self, filename): | 74 | def MacOpenFile(self, filename): |
@@ -180,6 +181,11 @@ class SplashScreen(wx.SplashScreen): | @@ -180,6 +181,11 @@ class SplashScreen(wx.SplashScreen): | ||
180 | self.fc = wx.FutureCall(1, self.ShowMain) | 181 | self.fc = wx.FutureCall(1, self.ShowMain) |
181 | wx.FutureCall(1, parse_comand_line) | 182 | wx.FutureCall(1, parse_comand_line) |
182 | 183 | ||
184 | + # Check for updates | ||
185 | + from threading import Thread | ||
186 | + p = Thread(target=utils.UpdateCheck, args=()) | ||
187 | + p.start() | ||
188 | + | ||
183 | def OnClose(self, evt): | 189 | def OnClose(self, evt): |
184 | # Make sure the default handler runs too so this window gets | 190 | # Make sure the default handler runs too so this window gets |
185 | # destroyed | 191 | # destroyed |
@@ -300,11 +306,6 @@ if __name__ == '__main__': | @@ -300,11 +306,6 @@ if __name__ == '__main__': | ||
300 | # import modules as they were on root invesalius folder | 306 | # import modules as they were on root invesalius folder |
301 | sys.path.append(".") | 307 | sys.path.append(".") |
302 | 308 | ||
303 | - # Check for updates | ||
304 | - from multiprocessing import Process | ||
305 | - p = Process(target=utils.UpdateCheck, args=()) | ||
306 | - p.daemon=True | ||
307 | - p.start() | ||
308 | 309 | ||
309 | # Init application | 310 | # Init application |
310 | main() | 311 | main() |
invesalius/utils.py
@@ -369,20 +369,31 @@ def get_system_encoding(): | @@ -369,20 +369,31 @@ def get_system_encoding(): | ||
369 | def UpdateCheck(): | 369 | def UpdateCheck(): |
370 | import urllib | 370 | import urllib |
371 | import urllib2 | 371 | import urllib2 |
372 | + import wx | ||
373 | + def _show_update_info(): | ||
374 | + from gui import dialogs | ||
375 | + msg=_("A new version of InVesalius is available. Do you want to open the download website now?") | ||
376 | + title=_("Invesalius Update") | ||
377 | + msgdlg = dialogs.UpdateMessageDialog(url) | ||
378 | + #if (msgdlg.Show()==wx.ID_YES): | ||
379 | + #wx.LaunchDefaultBrowser(url) | ||
380 | + msgdlg.Show() | ||
381 | + #msgdlg.Destroy() | ||
382 | + | ||
372 | print "Checking updates..." | 383 | print "Checking updates..." |
373 | 384 | ||
374 | # Check if there is a language set | 385 | # Check if there is a language set |
375 | - import i18n | 386 | + #import i18n |
376 | import session as ses | 387 | import session as ses |
377 | session = ses.Session() | 388 | session = ses.Session() |
378 | install_lang = 0 | 389 | install_lang = 0 |
379 | if session.ReadLanguage(): | 390 | if session.ReadLanguage(): |
380 | lang = session.GetLanguage() | 391 | lang = session.GetLanguage() |
381 | - if (lang != "False"): | ||
382 | - _ = i18n.InstallLanguage(lang) | ||
383 | - install_lang = 1 | ||
384 | - if (install_lang==0): | ||
385 | - return | 392 | + #if (lang != "False"): |
393 | + #_ = i18n.InstallLanguage(lang) | ||
394 | + #install_lang = 1 | ||
395 | + #if (install_lang==0): | ||
396 | + #return | ||
386 | if session.ReadRandomId(): | 397 | if session.ReadRandomId(): |
387 | random_id = session.GetRandomId() | 398 | random_id = session.GetRandomId() |
388 | 399 | ||
@@ -406,18 +417,4 @@ def UpdateCheck(): | @@ -406,18 +417,4 @@ def UpdateCheck(): | ||
406 | url = response.readline().rstrip() | 417 | url = response.readline().rstrip() |
407 | if (last!=const.INVESALIUS_VERSION): | 418 | if (last!=const.INVESALIUS_VERSION): |
408 | print " ...New update found!!! -> version:", last #, ", url=",url | 419 | print " ...New update found!!! -> version:", last #, ", url=",url |
409 | - from time import sleep | ||
410 | - sleep(2) | ||
411 | - import wx | ||
412 | - app=wx.App() | ||
413 | - import i18n | ||
414 | - _ = i18n.InstallLanguage(lang) | ||
415 | - msg=_("A new version of InVesalius is available. Do you want to open the download website now?") | ||
416 | - title=_("Invesalius Update") | ||
417 | - msgdlg = wx.MessageDialog(None,msg,title, wx.YES_NO | wx.ICON_INFORMATION) | ||
418 | - if (msgdlg.ShowModal()==wx.ID_YES): | ||
419 | - wx.LaunchDefaultBrowser(url) | ||
420 | - msgdlg.Destroy() | ||
421 | - app.MainLoop() | ||
422 | - | ||
423 | - | 420 | + wx.CallAfter(wx.CallLater, 1000, _show_update_info) |