def hide(self): component.get('TorrentView').save_state() component.pause(self.child_components) # Store the x, y positions for when we restore the window self.config['window_x_pos'], self.config['window_y_pos'] = self.window.get_position() self.window.hide()
def on_started(result): component.pause([ 'TorrentList', 'EventView', 'AddTorrents', 'TorrentDetail', 'Preferences', ])
def on_window_state_event(self, widget, event): if event.changed_mask & WindowState.ICONIFIED: if event.new_window_state & WindowState.ICONIFIED: log.debug('MainWindow is minimized..') component.get('TorrentView').save_state() component.pause(self.child_components) self.is_minimized = True else: log.debug('MainWindow is not minimized..') component.resume(self.child_components) self.is_minimized = False return False
def update(self): if not self.config["autoadd_enable"]: # We shouldn't be updating because autoadd is not enabled component.pause("AutoAdd") return # Check the auto add folder for new torrents to add if not os.path.isdir(self.config["autoadd_location"]): log.warning("Invalid AutoAdd folder: %s", self.config["autoadd_location"]) component.pause("AutoAdd") return for filename in os.listdir(self.config["autoadd_location"]): try: filepath = os.path.join(self.config["autoadd_location"], filename) except UnicodeDecodeError, e: log.error( "Unable to auto add torrent due to improper filename encoding: %s", e) continue if os.path.isfile(filepath) and filename.endswith(".torrent"): try: filedump = self.load_torrent(filepath) except (RuntimeError, Exception), e: # If the torrent is invalid, we keep track of it so that we # can try again on the next pass. This is because some # torrents may not be fully saved during the pass. log.debug("Torrent is invalid: %s", e) if filename in self.invalid_torrents: self.attempts[filename] += 1 if self.attempts[filename] >= MAX_NUM_ATTEMPTS: os.rename(filepath, filepath + ".invalid") del self.attempts[filename] self.invalid_torrents.remove(filename) else: self.invalid_torrents.append(filename) self.attempts[filename] = 1 continue # The torrent looks good, so lets add it to the session component.get("TorrentManager").add(filedump=filedump, filename=filename) os.remove(filepath)
def on_window_state_event(self, widget, event): if event.changed_mask & WINDOW_STATE_MAXIMIZED: if event.new_window_state & WINDOW_STATE_MAXIMIZED: log.debug('pos: %s', self.window.get_position()) self.config['window_maximized'] = True elif not event.new_window_state & WINDOW_STATE_WITHDRAWN: self.config['window_maximized'] = False if event.changed_mask & WINDOW_STATE_ICONIFIED: if event.new_window_state & WINDOW_STATE_ICONIFIED: log.debug('MainWindow is minimized..') component.get('TorrentView').save_state() component.pause(self.child_components) self.is_minimized = True else: log.debug('MainWindow is not minimized..') component.resume(self.child_components) self.is_minimized = False return False
def test_component_start_error(self): ComponentTesterUpdate('test_pause_c1') yield component.start(['test_pause_c1']) yield component.pause(['test_pause_c1']) test_comp = component.get('test_pause_c1') try: result = self.failureResultOf(test_comp._component_start()) except AttributeError: raise SkipTest('This test requires trial failureResultOf() in Twisted version >= 13') self.assertEqual(result.check(component.ComponentException), component.ComponentException)
def update(self): if not self.config["autoadd_enable"]: # We shouldn't be updating because autoadd is not enabled component.pause("AutoAdd") return # Check the auto add folder for new torrents to add if not os.path.isdir(self.config["autoadd_location"]): log.warning("Invalid AutoAdd folder: %s", self.config["autoadd_location"]) component.pause("AutoAdd") return for filename in os.listdir(self.config["autoadd_location"]): try: filepath = os.path.join(self.config["autoadd_location"], filename) except UnicodeDecodeError, e: log.error("Unable to auto add torrent due to improper filename encoding: %s", e) continue if os.path.isfile(filepath) and filename.endswith(".torrent"): try: filedump = self.load_torrent(filepath) except (RuntimeError, Exception), e: # If the torrent is invalid, we keep track of it so that we # can try again on the next pass. This is because some # torrents may not be fully saved during the pass. log.debug("Torrent is invalid: %s", e) if filename in self.invalid_torrents: self.attempts[filename] += 1 if self.attempts[filename] >= MAX_NUM_ATTEMPTS: os.rename(filepath, filepath + ".invalid") del self.attempts[filename] self.invalid_torrents.remove(filename) else: self.invalid_torrents.append(filename) self.attempts[filename] = 1 continue # The torrent looks good, so lets add it to the session component.get("TorrentManager").add(filedump=filedump, filename=filename) os.remove(filepath)
def test_component_start_error(self): ComponentTesterUpdate('test_pause_c1') yield component.start(['test_pause_c1']) yield component.pause(['test_pause_c1']) test_comp = component.get('test_pause_c1') try: result = self.failureResultOf(test_comp._component_start()) except AttributeError: raise SkipTest( 'This test requires trial failureResultOf() in Twisted version >= 13' ) self.assertEqual(result.check(component.ComponentException), component.ComponentException)
def on_window_state_event(self, widget, event): if event.changed_mask & gtk.gdk.WINDOW_STATE_MAXIMIZED: if event.new_window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED: log.debug("pos: %s", self.window.get_position()) self.config["window_maximized"] = True elif not event.new_window_state & gtk.gdk.WINDOW_STATE_WITHDRAWN: self.config["window_maximized"] = False if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED: log.debug("MainWindow is minimized..") component.pause("TorrentView") component.pause("StatusBar") self.is_minimized = True else: log.debug("MainWindow is not minimized..") try: component.resume("TorrentView") component.resume("StatusBar") except: pass self.is_minimized = False return False
def hide(self): component.pause("TorrentView") component.get("TorrentView").save_state() component.pause("StatusBar") component.pause("TorrentDetails") # Store the x, y positions for when we restore the window self.window_x_pos = self.window.get_position()[0] self.window_y_pos = self.window.get_position()[1] self.window.hide()
def set_mode(self, mode_name, refresh=False): log.debug('Setting console mode: %s', mode_name) mode = self.modes.get(mode_name, None) if mode is None: log.error('Non-existent mode requested: %s', mode_name) return self.stdscr.erase() if self.active_mode: self.active_mode.pause() d = component.pause([self.active_mode.mode_name]) def on_mode_paused(result, mode, *args): from deluge.ui.console.widgets.popup import PopupsHandler if isinstance(mode, PopupsHandler): if mode.popup is not None: # If popups are not removed, they are still referenced in the memory # which can cause issues as the popup's screen will not be destroyed. # This can lead to the popup border being visible for short periods # while the current modes' screen is repainted. log.error( 'Mode "%s" still has popups available after being paused.' ' Ensure all popups are removed on pause!', mode.popup.title, ) d.addCallback(on_mode_paused, self.active_mode) reactor.removeReader(self.active_mode) self.active_mode = mode self.statusbars.screen = self.active_mode # The Screen object is designed to run as a twisted reader so that it # can use twisted's select poll for non-blocking user input. reactor.addReader(self.active_mode) self.stdscr.clear() if self.active_mode._component_state == 'Stopped': component.start([self.active_mode.mode_name]) else: component.resume([self.active_mode.mode_name]) mode.resume() if refresh: mode.refresh() return mode
def test_start_paused_error(self): ComponentTesterUpdate('test_pause_c1') yield component.start(['test_pause_c1']) yield component.pause(['test_pause_c1']) # Deferreds that fail in component have to error handler which results in # twisted doing a log.err call which causes the test to fail. # Prevent failure by ignoring the exception self._observer._ignoreErrors(component.ComponentException) result = yield component.start() self.assertEqual([(result[0][0], result[0][1].value)], [(defer.FAILURE, component.ComponentException( 'Trying to start component "%s" but it is ' 'not in a stopped state. Current state: %s' % ('test_pause_c1', 'Paused'), ''))])
def test_start_paused_error(self): ComponentTesterUpdate('test_pause_c1') yield component.start(['test_pause_c1']) yield component.pause(['test_pause_c1']) # Deferreds that fail in component have to error handler which results in # twisted doing a log.err call which causes the test to fail. # Prevent failure by ignoring the exception self._observer._ignoreErrors(component.ComponentException) result = yield component.start() self.assertEqual( [(result[0][0], result[0][1].value)], [(defer.FAILURE, component.ComponentException( 'Trying to start component "%s" but it is ' 'not in a stopped state. Current state: %s' % ('test_pause_c1', 'Paused'), ''))])
def set_mode(self, mode_name, refresh=False): log.debug('Setting console mode: %s', mode_name) mode = self.modes.get(mode_name, None) if mode is None: log.error('Non-existent mode requested: %s', mode_name) return self.stdscr.erase() if self.active_mode: self.active_mode.pause() d = component.pause([self.active_mode.mode_name]) def on_mode_paused(result, mode, *args): from deluge.ui.console.widgets.popup import PopupsHandler if isinstance(mode, PopupsHandler): if mode.popup is not None: # If popups are not removed, they are still referenced in the memory # which can cause issues as the popup's screen will not be destroyed. # This can lead to the popup border being visible for short periods # while the current modes' screen is repainted. log.error('Mode "%s" still has popups available after being paused.' ' Ensure all popups are removed on pause!', mode.popup.title) d.addCallback(on_mode_paused, self.active_mode) reactor.removeReader(self.active_mode) self.active_mode = mode self.statusbars.screen = self.active_mode # The Screen object is designed to run as a twisted reader so that it # can use twisted's select poll for non-blocking user input. reactor.addReader(self.active_mode) self.stdscr.clear() if self.active_mode._component_state == 'Stopped': component.start([self.active_mode.mode_name]) else: component.resume([self.active_mode.mode_name]) mode.resume() if refresh: mode.refresh() return mode
def on_start(result, c1, counter): self.assertTrue(c1._component_timer) self.assertNotEqual(c1.counter, counter) d = component.pause(["test_pause_c1"]) d.addCallback(on_pause, c1, counter) return d
def _on_autoadd_enable(self, key, value): log.debug("_on_autoadd_enable") if value: component.resume("AutoAdd") else: component.pause("AutoAdd")
def hide(self): component.get('TorrentView').save_state() component.pause(self.child_components) self.save_position() self.window.hide()
# Set the right storage_mode if options["compact_allocation"]: storage_mode = lt.storage_mode_t(2) else: storage_mode = lt.storage_mode_t(1) # Fill in the rest of the add_torrent_params dictionary add_torrent_params["save_path"] = utf8_encoded(options["download_location"]) add_torrent_params["storage_mode"] = storage_mode add_torrent_params["paused"] = True add_torrent_params["auto_managed"] = False add_torrent_params["duplicate_is_error"] = True # We need to pause the AlertManager momentarily to prevent alerts # for this torrent being generated before a Torrent object is created. component.pause("AlertManager") handle = None try: if magnet: handle = lt.add_magnet_uri(self.session, utf8_encoded(magnet), add_torrent_params) else: handle = self.session.add_torrent(add_torrent_params) except RuntimeError, e: log.warning("Error adding torrent: %s", e) if not handle or not handle.is_valid(): log.debug("torrent handle is invalid!") # The torrent was not added to the session component.resume("AlertManager") return
def on_started(result): component.pause(['TorrentList', 'EventView', 'AddTorrents', 'TorrentDetail', 'Preferences'])
def changeEvent(self, event): if event.type() == QtCore.QEvent.WindowStateChange: if self.isMinimized(): component.pause(self._pause_components) else: component.resume(self._pause_components)
def on_start(result, c1, counter): self.assertTrue(c1._component_timer) self.assertNotEqual(c1.counter, counter) d = component.pause(['test_pause_c1']) d.addCallback(on_pause, c1, counter) return d