tray icon

This commit is contained in:
Zach Tibbitts 2007-02-14 18:08:33 +00:00
commit 3c0ab4a0f2
3 changed files with 106 additions and 22 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.1.4 on Mon Feb 12 12:36:18 2007 by zach@notapowerbook-->
<!--Generated with glade3 3.1.4 on Wed Feb 14 13:05:31 2007 by zach@notapowerbook-->
<glade-interface>
<widget class="GtkMenu" id="torrent_popup">
<property name="visible">True</property>
@ -156,4 +156,67 @@
</widget>
</child>
</widget>
<widget class="GtkMenu" id="tray_menu">
<property name="visible">True</property>
<child>
<widget class="GtkMenuItem" id="menuitem10">
<property name="visible">True</property>
<property name="label" translatable="yes">Show/Hide</property>
<property name="use_underline">True</property>
<signal name="activate" handler="show_hide_window"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem9">
<property name="visible">True</property>
<property name="label" translatable="yes">Add a Torrent...</property>
<property name="use_underline">True</property>
<signal name="activate" handler="add_torrent"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem11">
<property name="visible">True</property>
<property name="label" translatable="yes">Clear Finished</property>
<property name="use_underline">True</property>
<signal name="activate" handler="clear_finished"/>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem2">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem12">
<property name="visible">True</property>
<property name="label" translatable="yes">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="GtkMenuItem" id="menuitem13">
<property name="visible">True</property>
<property name="label" translatable="yes">Plugins</property>
<property name="use_underline">True</property>
<signal name="activate" handler="plugins"/>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem14">
<property name="visible">True</property>
<property name="label" translatable="yes">gtk-quit</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="quit"/>
</widget>
</child>
</widget>
</glade-interface>

View file

@ -62,11 +62,9 @@ class DelugeGTK(dbus.service.Object):
self.window.connect("destroy", self.quit)
self.window.set_title('%s %s'%(dcommon.PROGRAM_NAME, dcommon.PROGRAM_VERSION))
self.window.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
## Create the system tray icon
self.tray = dgtk.TrayIcon(self)
## Construct the Interface
self.build_tray_icon()
self.build_about_dialog()
self.build_pref_dialog()
self.build_plugin_dialog()
@ -110,6 +108,45 @@ class DelugeGTK(dbus.service.Object):
"torrentrow_click": self.torrentview_clicked,
})
def build_tray_icon(self):
self.tray = gtk.StatusIcon()
self.tray.set_from_file(dcommon.get_pixmap("deluge32.png"))
self.tray.set_tooltip("Deluge BitTorrent Client")
tray_glade = gtk.glade.XML(dcommon.get_glade_file("dgtkpopups.glade"))
self.tray_menu = tray_glade.get_widget("tray_menu")
dic = { "show_hide_window": self.force_show_hide,
"add_torrent": self.add_torrent_clicked,
"clear_finished": self.clear_finished,
"preferences": self.show_pref_dialog,
"plugins": self.show_plugin_dialog,
"quit": self.quit,
}
tray_glade.signal_autoconnect(dic)
self.tray.connect("popup-menu", self.tray_popup, None)
self.tray.connect("activate", self.tray_clicked, None)
def tray_popup(self, status_icon, button, activate_time, arg0=None):
self.tray_menu.popup(None, None, gtk.status_icon_position_menu,
button, activate_time, self.tray)
def tray_clicked(self, status_icon=None, arg=None):
if self.window.get_property("visible"):
if self.window.is_active():
self.window.hide()
else:
self.window.present()
else:
self.window.show()
def force_show_hide(self, arg=None):
if self.window.get_property("visible"):
self.window.hide()
else:
self.window.show()
def build_about_dialog(self):
gtk.about_dialog_set_url_hook(dcommon.open_url_in_browser)
self.abt = gtk.AboutDialog()
@ -151,8 +188,8 @@ class DelugeGTK(dbus.service.Object):
self.peer_column = dgtk.add_text_column(self.view, "Peers", 7)
self.dl_column = dgtk.add_text_column(self.view, "Download", 8)
self.ul_column = dgtk.add_text_column(self.view, "Upload", 9)
self.eta_column = dgtk.add_text_column(self.view, "ETA", 10)
self.share_column = dgtk.add_text_column(self.view, "Share Ratio", 11)
self.eta_column = dgtk.add_text_column(self.view, "Time Remaining", 10)
self.share_column = dgtk.add_text_column(self.view, "Ratio", 11)
self.status_column.set_expand(True)

View file

@ -28,22 +28,6 @@ pygtk.require('2.0')
import gtk
import gtk.glade
## Right now this only supports PyGTK's native
## tray library. I may add egg support into
## this class at a later time.
class TrayIcon:
def __init__(self, parent):
self.parent = parent
self.tray = gtk.StatusIcon()
## uncomment later
##self.gladefile = dcommon.get_glade_file("dgtkpopups.glade")
self.tray.set_from_file(dcommon.get_pixmap("deluge32.png"))
self.tray.set_tooltip("Deluge Bittorrent Client")
def popup(self):
pass
## Browse for .torrent files
def show_file_open_dialog(parent=None):
chooser = gtk.FileChooserDialog("Choose a .torrent file", parent, gtk.FILE_CHOOSER_ACTION_OPEN,