Inital import of SystemTray

This commit is contained in:
Andrew Resch 2007-09-22 23:02:58 +00:00
parent 28447f7564
commit 8f62df0732
9 changed files with 158 additions and 145 deletions

View File

@ -58,6 +58,8 @@ class _ConfigManager:
"""Saves all the configs to disk."""
for key in self.config_files.keys():
self.config_files[key].save()
# We need to return True to keep the timer active
return True
def get_config(self, config_file, defaults=None):
"""Get a reference to the Config object for this filename"""

View File

@ -224,7 +224,21 @@ class Core(dbus.service.Object):
log.debug("Pausing torrent %s", torrent_id)
if self.torrents.pause(torrent_id):
self.torrent_paused(torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge")
def pause_all_torrents(self):
"""Pause all torrents in the session"""
if self.torrents.pause_all():
# Emit 'torrent_all_paused' signal
self.torrent_all_paused()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge")
def resume_all_torrents(self):
"""Resume all torrents in the session"""
if self.torrents.resume_all():
# Emit the 'torrent_all_resumed' signal
self.torrent_all_resumed()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
in_signature="s", out_signature="")
def resume_torrent(self, torrent_id):
@ -282,6 +296,19 @@ class Core(dbus.service.Object):
config = pickle.dumps(config)
return config
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
in_signature="s",
out_signature="ay")
def get_config_value(self, key):
"""Get the config value for key"""
try:
value = self.config[key]
except KeyError:
return None
value = pickle.dumps(value)
return value
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
in_signature="ay")
def set_config(self, config):
@ -317,10 +344,22 @@ class Core(dbus.service.Object):
def torrent_paused(self, torrent_id):
"""Emitted when a torrent is paused"""
log.debug("torrent_paused signal emitted")
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge",
signature="s")
def torrent_resumed(self, torrent_id):
"""Emitted when a torrent is resumed"""
log.debug("torrent_resumed signal emitted")
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge")
def torrent_all_paused(self):
"""Emitted when all torrents have been paused"""
log.debug("torrent_all_paused signal emitted")
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge")
def torrent_all_resumed(self):
"""Emitted when all torrents have been resumed"""
log.debug("torrent_all_resumed signal emitted")
# Config set functions
def on_set_listen_ports(self, key, value):

View File

@ -187,6 +187,18 @@ class TorrentManager:
return False
return True
def pause_all(self):
"""Pauses all torrents.. Returns a list of torrents paused."""
torrent_was_paused = False
for key in self.torrents.keys():
try:
self.torrents[key].handle.pause()
torrent_was_paused = True
except:
log.warning("Unable to pause torrent %s", key)
return torrent_was_paused
def resume(self, torrent_id):
"""Resume a torrent"""
@ -197,6 +209,18 @@ class TorrentManager:
return True
def resume_all(self):
"""Resumes all torrents.. Returns a list of torrents resumed"""
torrent_was_resumed = False
for key in self.torrents.keys():
try:
self.torrents[key].handle.resume()
torrent_was_resumed = True
except:
log.warning("Unable to resume torrent %s", key)
return torrent_was_resumed
def force_reannounce(self, torrent_id):
"""Force a tracker reannounce"""
try:
@ -206,7 +230,6 @@ class TorrentManager:
return True
def load_state(self):
"""Load the state of the TorrentManager from the torrents.state file"""
state = TorrentManagerState()

View File

@ -156,6 +156,14 @@ def get_config(core=None):
config = pickle.loads(config)
return config
def get_config_value(key, core=None):
if core is None:
core = get_core()
config = core.get_config_value(key)
config = "".join(chr(b) for b in config)
config = pickle.loads(config)
return config
def set_config(config, core=None):
if config == {}:
return

View File

@ -1,86 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.2 on Wed Jun 20 16:04:00 2007 by andrew@fractal-->
<!--Generated with glade3 3.2.2 on Wed Aug 8 23:27:43 2007 by markybob@peg-->
<glade-interface>
<widget class="GtkMenu" id="torrent_popup">
<property name="visible">True</property>
<child>
<widget class="GtkCheckMenuItem" id="menuitem1">
<property name="visible">True</property>
<property name="label" translatable="yes">Size</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="size_toggle"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem2">
<property name="visible">True</property>
<property name="label" translatable="yes">Status</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="status_toggle"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem3">
<property name="visible">True</property>
<property name="label" translatable="yes">Seeders</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="seeders_toggle"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="label" translatable="yes">Peers</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="peers_toggle"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem5">
<property name="visible">True</property>
<property name="label" translatable="yes">Download Speed</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="dl_toggle"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem6">
<property name="visible">True</property>
<property name="label" translatable="yes">Upload Speed</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="ul_toggle"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem7">
<property name="visible">True</property>
<property name="label" translatable="yes">Time Remaining</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="eta_toggle"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem8">
<property name="visible">True</property>
<property name="label" translatable="yes">Share Ratio</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="share_toggle"/>
</widget>
</child>
</widget>
<widget class="GtkDialog" id="remove_torrent_dlg">
<property name="title" translatable="yes">Remove Torrent</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="has_separator">False</property>
@ -309,14 +234,15 @@
</widget>
</child>
</widget>
<widget class="GtkDialog" id="rate_dialog">
<widget class="GtkDialog" id="speed_dialog">
<property name="app_paintable">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">5</property>
<property name="window_position">GTK_WIN_POS_MOUSE</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="title" translatable="yes">Speed</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="skip_taskbar_hint">True</property>
<property name="decorated">False</property>
<property name="skip_pager_hint">True</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox2">
@ -329,17 +255,16 @@
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">10</property>
<child>
<widget class="GtkLabel" id="label2">
<widget class="GtkLabel" id="spin_title">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Rate:</property>
</widget>
<packing>
<property name="expand">False</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_rate">
<widget class="GtkSpinButton" id="spin_speed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>

View File

@ -6,12 +6,12 @@
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkCheckMenuItem" id="show_hide_window">
<widget class="GtkCheckMenuItem" id="menuitem_show_deluge">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Show Deluge</property>
<property name="use_underline">True</property>
<signal name="activate" handler="show_hide_window_toggled"/>
<signal name="activate" handler="on_menuitem_show_deluge_activate"/>
</widget>
</child>
<child>
@ -21,12 +21,12 @@
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="add_torrent">
<widget class="GtkImageMenuItem" id="menuitem_add_torrent">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Add Torrent</property>
<property name="use_underline">True</property>
<signal name="activate" handler="add_torrent"/>
<signal name="activate" handler="on_menuitem_add_torrent_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image1">
<property name="visible">True</property>
@ -38,17 +38,40 @@
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="clear_finished">
<widget class="GtkSeparatorMenuItem" id="separatormenuitem5">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Clear Finished</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_pause_all">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Pause All</property>
<property name="use_underline">True</property>
<signal name="activate" handler="clear_finished"/>
<signal name="activate" handler="on_menuitem_pause_all_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image2">
<widget class="GtkImage" id="menu-item-image6">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="stock">gtk-clear</property>
<property name="stock">gtk-media-pause</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_resume_all">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Resume All</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_resume_all_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image7">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="stock">gtk-media-play</property>
<property name="icon_size">1</property>
</widget>
</child>
@ -61,17 +84,11 @@
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="download_limit">
<widget class="GtkImageMenuItem" id="menuitem_download_limit">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Download Limit</property>
<property name="label" translatable="yes">_Download Speed Limit</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="menu1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
</child>
<child internal-child="image">
<widget class="GtkImage" id="download-limit-image">
<property name="visible">True</property>
@ -83,10 +100,10 @@
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="upload_limit">
<widget class="GtkImageMenuItem" id="menuitem_upload_limit">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Upload Limit</property>
<property name="label" translatable="yes">_Upload Speed Limit</property>
<property name="use_underline">True</property>
<child internal-child="image">
<widget class="GtkImage" id="upload-limit-image">
@ -105,45 +122,12 @@
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="preferences">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label">gtk-preferences</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="preferences"/>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="plugins">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Plu_gins</property>
<property name="use_underline">True</property>
<signal name="activate" handler="plugins"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image3">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="stock">gtk-disconnect</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="quit">
<widget class="GtkImageMenuItem" id="menuitem_quit">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Quit</property>
<property name="use_underline">True</property>
<signal name="activate" handler="quit"/>
<signal name="activate" handler="on_menuitem_quit_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image4">
<property name="visible">True</property>

View File

@ -63,7 +63,9 @@ DEFAULT_PREFS = {
"window_x_pos": 0,
"window_y_pos": 0,
"window_width": 640,
"window_height": 480
"window_height": 480,
"tray_download_speed_list" : [5.0, 10.0, 30.0, 80.0, 300.0],
"tray_upload_speed_list" : [5.0, 10.0, 30.0, 80.0, 300.0]
}
class GtkUI:

View File

@ -43,6 +43,7 @@ from toolbar import ToolBar
from torrentview import TorrentView
from torrentdetails import TorrentDetails
from preferences import Preferences
from systemtray import SystemTray
import deluge.common
from deluge.log import LOG as log
@ -74,6 +75,7 @@ class MainWindow:
self.torrentview = TorrentView(self)
self.torrentdetails = TorrentDetails(self)
self.preferences = Preferences(self)
self.systemtray = SystemTray(self)
gobject.timeout_add(1000, self.update)
@ -86,11 +88,22 @@ class MainWindow:
return True
def show(self):
self.window.show_all()
self.window.show()
def hide(self):
self.window.hide()
def present(self):
self.window.present()
def active(self):
"""Returns True if the window is active, False if not."""
return self.window.is_active()
def visible(self):
"""Returns True if window is visible, False if not."""
return self.window.get_property("visible")
def quit(self):
del self.menubar
del self.toolbar

View File

@ -42,7 +42,12 @@ class Signals:
self.core.connect_to_signal("torrent_removed",
self.torrent_removed_signal)
self.core.connect_to_signal("torrent_paused", self.torrent_paused)
self.core.connect_to_signal("torrent_resumed", self.torrent_resumed)
self.core.connect_to_signal("torrent_all_paused",
self.torrent_all_paused)
self.core.connect_to_signal("torrent_all_resumed",
self.torrent_all_resumed)
def torrent_added_signal(self, torrent_id):
log.debug("torrent_added signal received..")
log.debug("torrent id: %s", torrent_id)
@ -58,3 +63,15 @@ class Signals:
def torrent_paused(self, torrent_id):
log.debug("torrent_paused signal received..")
self.ui.mainwindow.torrentview.update()
def torrent_resumed(self, torrent_id):
log.debug("torrent_resumed signal received..")
self.ui.mainwindow.torrentview.update()
def torrent_all_paused(self):
log.debug("torrent_all_paused signal received..")
self.ui.mainwindow.torrentview.update()
def torrent_all_resumed(self):
log.debug("torrent_all_resumed signal received..")
self.ui.mainwindow.torrentview.update()