Add pausing and resuming of components. This stops the update() timer

for the component and restarts it upon resume.
This commit is contained in:
Andrew Resch 2008-02-27 07:43:47 +00:00
parent 26b8fcf086
commit f1808a0cc3
2 changed files with 57 additions and 11 deletions

View file

@ -36,7 +36,8 @@ from deluge.log import LOG as log
COMPONENT_STATE = [
"Stopped",
"Started"
"Started",
"Paused"
]
class Component:
@ -67,7 +68,17 @@ class Component:
gobject.source_remove(self._timer)
except:
pass
def _pause(self):
self._state = COMPONENT_STATE.index("Paused")
try:
gobject.source_remove(self._timer)
except:
pass
def _resume(self):
self._start()
def shutdown(self):
pass
@ -126,7 +137,28 @@ class ComponentRegistry:
log.debug("Stopping component %s..", component)
self.components[component].stop()
self.components[component]._stop()
def pause(self):
"""Pauses all components. Stops calling update()"""
for component in self.components.keys():
self.pause_component(component)
def pause_component(self, component):
if self.components[component].get_state() not in \
[COMPONENT_STATE.index("Paused"), COMPONENT_STATE.index("Stopped")]:
log.debug("Pausing component %s..", component)
self.components[component]._pause()
def resume(self):
"""Resumes all components. Starts calling update()"""
for component in self.components.keys():
self.resume_component(component)
def resume_component(self, component):
if self.components[component].get_state() == COMPONENT_STATE.index("Paused"):
log.debug("Resuming component %s..", component)
self.components[component]._resume()
def update(self):
"""Updates all components"""
for component in self.components.keys():
@ -170,6 +202,20 @@ def stop(component=None):
else:
_ComponentRegistry.stop_component(component)
def pause(component=None):
"""Pauses all or specificed components"""
if component == None:
_ComponentRegistry.pause()
else:
_ComponentRegistry.pause_component(component)
def resume(component=None):
"""Resumes all or specificed components"""
if component == None:
_ComponentRegistry.resume()
else:
_ComponentRegistry.resume_component(component)
def update():
"""Updates all components"""
_ComponentRegistry.update()

View file

@ -78,8 +78,8 @@ class MainWindow(component.Component):
def show(self):
try:
component.start("TorrentView")
component.start("StatusBar")
component.resume("TorrentView")
component.resume("StatusBar")
except:
pass
@ -88,8 +88,8 @@ class MainWindow(component.Component):
self.window.show()
def hide(self):
component.stop("TorrentView")
component.stop("StatusBar")
component.pause("TorrentView")
component.pause("StatusBar")
self.window.hide()
def present(self):
@ -135,14 +135,14 @@ class MainWindow(component.Component):
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.stop("TorrentView")
component.stop("StatusBar")
component.pause("TorrentView")
component.pause("StatusBar")
self.is_minimized = True
else:
log.debug("MainWindow is not minimized..")
try:
component.start("TorrentView")
component.start("StatusBar")
component.resume("TorrentView")
component.resume("StatusBar")
except:
pass
self.is_minimized = False