def on_show_close_splash(self, subject, changetype, objectID, *args): gui_image_manager = GuiImageManager.getInstance() bm = gui_image_manager.getImage(u'closescreen.png') self.close_splash = GaugeSplash(bm, "Closing...", self.CLOSE_GAUGE_SPLASH_TICKS) if self.close_completed: self.destroy_close_splash(None, None, None, None)
def on_show_startup_splash(self, subject, changetype, objectID, *args): gui_image_manager = GuiImageManager.getInstance() bm = gui_image_manager.getImage(u'splash.png') self.startup_splash = GaugeSplash(bm, "Loading...", self.START_GAUGE_SPLASH_TICKS) # Check if the destroy message has already arrived. Loading the splash takes a while, # so the setup may have already been completed. if self.startup_completed: self.destroy_startup_splash(None, None, None, None)
def OnExit(self): bm = self.gui_image_manager.getImage(u'closescreen.png') self.closewindow = GaugeSplash(bm, "Closing...", 6) self.closewindow.Show() self._logger.info("main: ONEXIT") self.ready = False self.done = True # write all persistent data to disk self.closewindow.tick('Write all persistent data to disk') if self.torrentfeed: self.torrentfeed.shutdown() self.torrentfeed.delInstance() if self.webUI: self.webUI.stop() self.webUI.delInstance() if self.frame: self.frame.Destroy() self.frame = None # Don't checkpoint, interferes with current way of saving Preferences, # see Tribler/Main/Dialogs/abcoption.py if self.utility: # Niels: lets add a max waiting time for this session shutdown. session_shutdown_start = time() try: self._logger.info("ONEXIT cleaning database") self.closewindow.tick('Cleaning database') torrent_db = self.utility.session.open_dbhandler(NTFY_TORRENTS) torrent_db._db.clean_db(randint(0, 24) == 0, exiting=True) except: print_exc() self.closewindow.tick('Shutdown session') self.utility.session.shutdown(hacksessconfcheckpoint=False) # Arno, 2012-07-12: Shutdown should be quick # Niels, 2013-03-21: However, setting it too low will prevent checkpoints from being written to disk waittime = 60 while not self.utility.session.has_shutdown(): diff = time() - session_shutdown_start if diff > waittime: self._logger.info( "main: ONEXIT NOT Waiting for Session to shutdown, took too long" ) break self._logger.info( "ONEXIT Waiting for Session to shutdown, will wait for an additional %d seconds", waittime - diff) sleep(3) self._logger.info("ONEXIT Session is shutdown") self.closewindow.tick('Deleting instances') self._logger.debug("ONEXIT deleting instances") Session.del_instance() GUIUtility.delInstance() GUIDBProducer.delInstance() DefaultDownloadStartupConfig.delInstance() GuiImageManager.delInstance() self.closewindow.tick('Exiting now') self.closewindow.Destroy() return 0
def __init__(self, params, installdir, autoload_discovery=True, use_torrent_search=True, use_channel_search=True): assert not isInIOThread( ), "isInIOThread() seems to not be working correctly" self._logger = logging.getLogger(self.__class__.__name__) self.params = params self.installdir = installdir self.state_dir = None self.error = None self.last_update = 0 self.ready = False self.done = False self.frame = None self.upgrader = None self.said_start_playback = False self.decodeprogress = 0 self.old_reputation = 0 # DISPERSY will be set when available self.dispersy = None # BARTER_COMMUNITY will be set when both Dispersy and the EffortCommunity are available self.barter_community = None self.tunnel_community = None self.torrentfeed = None self.webUI = None self.utility = None # Stage 1 start session = self.InitStage1(installdir, autoload_discovery=autoload_discovery, use_torrent_search=use_torrent_search, use_channel_search=use_channel_search) self.splash = None try: bm = self.gui_image_manager.getImage(u'splash.png') self.splash = GaugeSplash(bm, "Loading...", 13) self.splash.Show() self._logger.info('Client Starting Up.') self._logger.info("Tribler is using %s as working directory", self.installdir) # Stage 2: show the splash window and start the session self.splash.tick('Starting API') s = self.startAPI(session, self.splash.tick) self.utility = Utility(self.installdir, s.get_state_dir()) if self.utility.read_config(u'saveas', u'downloadconfig'): DefaultDownloadStartupConfig.getInstance().set_dest_dir( self.utility.read_config(u'saveas', u'downloadconfig')) self.utility.set_app(self) self.utility.set_session(s) self.guiUtility = GUIUtility.getInstance(self.utility, self.params, self) GUIDBProducer.getInstance() self._logger.info('Tribler Version: %s Build: %s', version_id, commit_id) version_info = self.utility.read_config('version_info') if version_info.get('version_id', None) != version_id: # First run of a different version version_info['first_run'] = int(time()) version_info['version_id'] = version_id self.utility.write_config('version_info', version_info) self.splash.tick( 'Starting session and upgrading database (it may take a while)' ) s.start() self.dispersy = s.lm.dispersy self.splash.tick('Loading userdownloadchoice') from Tribler.Main.vwxGUI.UserDownloadChoice import UserDownloadChoice UserDownloadChoice.get_singleton().set_utility(self.utility) self.splash.tick('Initializing Family Filter') cat = Category.getInstance(session) state = self.utility.read_config('family_filter') if state in (1, 0): cat.set_family_filter(state == 1) else: self.utility.write_config('family_filter', 1) self.utility.flush_config() cat.set_family_filter(True) # Create global speed limits self.splash.tick('Setting up speed limits') # Counter to suppress some event from occurring self.ratestatecallbackcount = 0 maxup = self.utility.read_config('maxuploadrate') maxdown = self.utility.read_config('maxdownloadrate') # set speed limits using LibtorrentMgr s.set_max_upload_speed(maxup) s.set_max_download_speed(maxdown) # Only allow updates to come in after we defined ratelimiter self.prevActiveDownloads = [] s.set_download_states_callback(self.sesscb_states_callback) # Schedule task for checkpointing Session, to avoid hash checks after # crashes. startWorker(consumer=None, workerFn=self.guiservthread_checkpoint_timer, delay=SESSION_CHECKPOINT_INTERVAL) if not ALLOW_MULTIPLE: # Put it here so an error is shown in the startup-error popup # Start server for instance2instance communication Instance2InstanceServer( self.utility.read_config('i2ilistenport'), self.i2ithread_readlinecallback) self.splash.tick('GUIUtility register') self.guiUtility.register() self.frame = MainFrame( self, None, PLAYBACKMODE_INTERNAL in return_feasible_playback_modes(), self.splash.tick) self.frame.SetIcon( wx.Icon( os.path.join(self.installdir, 'Tribler', 'Main', 'vwxGUI', 'images', 'tribler.ico'), wx.BITMAP_TYPE_ICO)) # Arno, 2011-06-15: VLC 1.1.10 pops up separate win, don't have two. self.frame.videoframe = None if PLAYBACKMODE_INTERNAL in return_feasible_playback_modes(): vlcwrap = s.lm.videoplayer.get_vlcwrap() wx.CallLater(3000, vlcwrap._init_vlc) self.frame.videoframe = VideoDummyFrame( self.frame.videoparentpanel, self.utility, vlcwrap) if sys.platform == 'win32': wx.CallAfter(self.frame.top_bg.Refresh) wx.CallAfter(self.frame.top_bg.Layout) else: self.frame.top_bg.Layout() # Arno, 2007-05-03: wxWidgets 2.8.3.0 and earlier have the MIME-type for .bmp # files set to 'image/x-bmp' whereas 'image/bmp' is the official one. try: bmphand = None hands = wx.Image.GetHandlers() for hand in hands: # print "Handler",hand.GetExtension(),hand.GetType(),hand.GetMimeType() if hand.GetMimeType() == 'image/x-bmp': bmphand = hand break # wx.Image.AddHandler() if bmphand is not None: bmphand.SetMimeType('image/bmp') except: # wx < 2.7 don't like wx.Image.GetHandlers() print_exc() self.splash.Destroy() self.frame.Show(True) session.lm.threadpool.call_in_thread( 0, self.guiservthread_free_space_check) self.torrentfeed = RssParser.getInstance() self.webUI = None if self.utility.read_config('use_webui'): try: from Tribler.Main.webUI.webUI import WebUI self.webUI = WebUI.getInstance( self.guiUtility.library_manager, self.guiUtility.torrentsearch_manager, self.utility.read_config('webui_port')) self.webUI.start() except Exception: print_exc() self.emercoin_mgr = None try: from Tribler.Main.Emercoin.EmercoinMgr import EmercoinMgr self.emercoin_mgr = EmercoinMgr(self.utility) except Exception: print_exc() wx.CallAfter(self.PostInit2) # 08/02/10 Boudewijn: Working from home though console # doesn't allow me to press close. The statement below # gracefully closes Tribler after 120 seconds. # wx.CallLater(120*1000, wx.GetApp().Exit) self.ready = True except Exception as e: if self.splash: self.splash.Destroy() self.onError(e)