Add the tabs to the View menu and allow them to be shown/hidden.

Some minor UI tweaks.
This commit is contained in:
Andrew Resch 2008-05-19 02:28:47 +00:00
parent 95d0b65785
commit afa3c03691
9 changed files with 1536 additions and 1329 deletions

View File

@ -36,22 +36,26 @@ import gtk, gtk.glade
from deluge.ui.client import aclient as client
import deluge.component as component
import deluge.common
from deluge.ui.gtkui.torrentdetails import Tab
from deluge.log import LOG as log
class DetailsTab:
class DetailsTab(Tab):
def __init__(self):
# Get the labels we need to update.
# widgetname, modifier function, status keys
glade = component.get("MainWindow").main_glade
self._name = "Details"
self._child_widget = glade.get_widget("details_tab")
self._tab_label = glade.get_widget("details_tab_label")
self.label_widgets = [
(glade.get_widget("summary_name"), None, ("name",)),
(glade.get_widget("summary_total_size"), deluge.common.fsize, ("total_size",)),
(glade.get_widget("summary_num_files"), str, ("num_files",)),
(glade.get_widget("summary_tracker"), None, ("tracker",)),
(glade.get_widget("summary_torrent_path"), None, ("save_path",)),
(glade.get_widget("summary_private"), str, ("private",)),
(glade.get_widget("summary_message"), str, ("message",)),
(glade.get_widget("summary_hash"), str, ("hash",))
]
@ -65,11 +69,12 @@ class DetailsTab:
selected = selected[0]
else:
# No torrent is selected in the torrentview
self.clear()
return
# Get the torrent status
status_keys = ["name", "total_size", "num_files",
"tracker", "save_path", "private", "message", "hash"]
"tracker", "save_path", "message", "hash"]
client.get_torrent_status(
self._on_get_torrent_status, selected, status_keys)

View File

@ -37,6 +37,7 @@ import gettext
import os.path
import cPickle
from deluge.ui.gtkui.torrentdetails import Tab
from deluge.ui.client import aclient as client
from deluge.configmanager import ConfigManager
import deluge.component as component
@ -72,9 +73,14 @@ class ColumnState:
self.sort = sort
self.sort_order = sort_order
class FilesTab:
class FilesTab(Tab):
def __init__(self):
glade = component.get("MainWindow").get_glade()
self._name = "Files"
self._child_widget = glade.get_widget("files_tab")
self._tab_label = glade.get_widget("files_tab_label")
self.listview = glade.get_widget("files_listview")
# filename, size, progress string, progress value, priority, file index
self.liststore = gtk.ListStore(str, gobject.TYPE_UINT64, str, int, int, int)

View File

@ -133,22 +133,34 @@
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem_sidebar">
<widget class="GtkCheckMenuItem" id="menuitem_labels">
<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">_Sidebar</property>
<property name="label" translatable="yes">_Labels</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="on_menuitem_sidebar_toggled"/>
<signal name="toggled" handler="on_menuitem_labels_toggled"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menuitem_infopane">
<widget class="GtkCheckMenuItem" id="menuitem_statusbar">
<property name="visible">True</property>
<property name="label" translatable="yes">_Info Pane</property>
<property name="label" translatable="yes">Status_bar</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<signal name="toggled" handler="on_menuitem_infopane_toggled"/>
<signal name="toggled" handler="on_menuitem_statusbar_toggled"/>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="menuitem1">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menu_tabs">
<property name="visible">True</property>
<property name="label" translatable="yes">T_abs</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
@ -471,8 +483,115 @@
<widget class="GtkNotebook" id="torrent_info">
<property name="visible">True</property>
<property name="show_border">False</property>
</widget>
<packing>
<property name="resize">False</property>
<property name="shrink">False</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="torrentdetails_tab">
<widget class="GtkStatusbar" id="statusbar">
<property name="visible">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
</widget>
</child>
</widget>
<widget class="GtkMenu" id="menu_file_tab">
<property name="visible">True</property>
<child>
<widget class="GtkImageMenuItem" id="menuitem_open_file">
<property name="visible">True</property>
<property name="label" translatable="yes">gtk-open</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_menuitem_open_file_activate"/>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="menuitem2">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_donotdownload">
<property name="visible">True</property>
<property name="label" translatable="yes">_Do Not Download</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_donotdownload_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image9">
<property name="visible">True</property>
<property name="stock">gtk-stop</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_normal">
<property name="visible">True</property>
<property name="label" translatable="yes">_Normal Priority</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_normal_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image10">
<property name="visible">True</property>
<property name="stock">gtk-yes</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_high">
<property name="visible">True</property>
<property name="label" translatable="yes">_High Priority</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_high_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image11">
<property name="visible">True</property>
<property name="stock">gtk-go-up</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_highest">
<property name="visible">True</property>
<property name="label" translatable="yes">Hi_ghest Priority</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_highest_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image12">
<property name="visible">True</property>
<property name="stock">gtk-goto-top</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
</widget>
<widget class="GtkWindow" id="tabs">
<child>
<widget class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<widget class="GtkScrolledWindow" id="statistics_tab">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@ -492,7 +611,7 @@
<property name="left_padding">15</property>
<property name="right_padding">15</property>
<child>
<widget class="GtkVBox" id="vbox2">
<widget class="GtkVBox" id="vbox3">
<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="spacing">5</property>
@ -910,7 +1029,7 @@
</widget>
</child>
<child>
<widget class="GtkHBox" id="hbox1">
<widget class="GtkHBox" id="statistics_tab_label">
<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="spacing">2</property>
@ -939,7 +1058,7 @@
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
<widget class="GtkScrolledWindow" id="details_tab">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@ -962,9 +1081,50 @@
<child>
<widget class="GtkTable" id="table9">
<property name="visible">True</property>
<property name="n_rows">6</property>
<property name="n_rows">7</property>
<property name="n_columns">4</property>
<property name="row_spacing">2</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<widget class="GtkLabel" id="summary_num_files">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="selectable">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label49">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="ypad">1</property>
<property name="label" translatable="yes">&lt;b&gt;# of files:&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="summary_hash">
<property name="visible">True</property>
@ -1006,8 +1166,8 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">4</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="y_options"></property>
</packing>
</child>
@ -1020,8 +1180,8 @@
<property name="use_markup">True</property>
</widget>
<packing>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
@ -1116,7 +1276,7 @@
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="right_attach">4</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
@ -1131,8 +1291,8 @@
<property name="use_markup">True</property>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
@ -1146,39 +1306,8 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">4</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label49">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="ypad">1</property>
<property name="label" translatable="yes">&lt;b&gt;# of files:&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="summary_num_files">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="selectable">True</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="y_options"></property>
</packing>
</child>
@ -1196,39 +1325,6 @@
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="ypad">1</property>
<property name="label" translatable="yes">&lt;b&gt;Private:&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="summary_private">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="wrap">True</property>
<property name="wrap_mode">PANGO_WRAP_CHAR</property>
<property name="selectable">True</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
</child>
</widget>
@ -1241,7 +1337,7 @@
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox2">
<widget class="GtkHBox" id="details_tab_label">
<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="spacing">2</property>
@ -1271,7 +1367,7 @@
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow3">
<widget class="GtkScrolledWindow" id="files_tab">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@ -1291,7 +1387,7 @@
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox3">
<widget class="GtkHBox" id="files_tab_label">
<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="spacing">2</property>
@ -1321,7 +1417,7 @@
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow4">
<widget class="GtkScrolledWindow" id="peers_tab">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@ -1341,7 +1437,7 @@
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox4">
<widget class="GtkHBox" id="peers_tab_label">
<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="spacing">2</property>
@ -1371,7 +1467,7 @@
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow5">
<widget class="GtkScrolledWindow" id="options_tab">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
@ -1556,7 +1652,7 @@
</widget>
</child>
<child>
<widget class="GtkLabel" id="label9">
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Bandwidth&lt;/b&gt;</property>
<property name="use_markup">True</property>
@ -1727,7 +1823,7 @@
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox5">
<widget class="GtkHBox" id="options_tab_label">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
@ -1737,7 +1833,7 @@
</widget>
</child>
<child>
<widget class="GtkLabel" id="label6">
<widget class="GtkLabel" id="label18">
<property name="visible">True</property>
<property name="label" translatable="yes">_Options</property>
<property name="use_underline">True</property>
@ -1754,105 +1850,6 @@
</packing>
</child>
</widget>
<packing>
<property name="resize">False</property>
<property name="shrink">False</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkStatusbar" id="statusbar">
<property name="visible">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
</widget>
</child>
</widget>
<widget class="GtkMenu" id="menu_file_tab">
<property name="visible">True</property>
<child>
<widget class="GtkImageMenuItem" id="menuitem_open_file">
<property name="visible">True</property>
<property name="label" translatable="yes">gtk-open</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_menuitem_open_file_activate"/>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="menuitem2">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_donotdownload">
<property name="visible">True</property>
<property name="label" translatable="yes">_Do Not Download</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_donotdownload_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image9">
<property name="visible">True</property>
<property name="stock">gtk-stop</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_normal">
<property name="visible">True</property>
<property name="label" translatable="yes">_Normal Priority</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_normal_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image10">
<property name="visible">True</property>
<property name="stock">gtk-yes</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_high">
<property name="visible">True</property>
<property name="label" translatable="yes">_High Priority</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_high_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image11">
<property name="visible">True</property>
<property name="stock">gtk-go-up</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_highest">
<property name="visible">True</property>
<property name="label" translatable="yes">Hi_ghest Priority</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_highest_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image12">
<property name="visible">True</property>
<property name="stock">gtk-goto-top</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -114,8 +114,8 @@ class MenuBar(component.Component):
## View Menu
"on_menuitem_toolbar_toggled": self.on_menuitem_toolbar_toggled,
"on_menuitem_sidebar_toggled": self.on_menuitem_sidebar_toggled,
"on_menuitem_infopane_toggled": self.on_menuitem_infopane_toggled,
"on_menuitem_labels_toggled": self.on_menuitem_labels_toggled,
"on_menuitem_statusbar_toggled": self.on_menuitem_statusbar_toggled,
## Help Menu
"on_menuitem_homepage_activate": self.on_menuitem_homepage_activate,
@ -322,13 +322,13 @@ class MenuBar(component.Component):
log.debug("on_menuitem_toolbar_toggled")
component.get("ToolBar").visible(value.get_active())
def on_menuitem_sidebar_toggled(self, value):
log.debug("on_menuitem_sidebar_toggled")
def on_menuitem_labels_toggled(self, value):
log.debug("on_menuitem_labels_toggled")
component.get("SideBar").visible(value.get_active())
def on_menuitem_infopane_toggled(self, value):
log.debug("on_menuitem_infopane_toggled")
component.get("TorrentDetails").visible(value.get_active())
def on_menuitem_statusbar_toggled(self, value):
log.debug("on_menuitem_statusbar_toggled")
component.get("StatusBar").visible(value.get_active())
## Help Menu ##
def on_menuitem_homepage_activate(self, data=None):

View File

@ -33,10 +33,16 @@
import deluge.component as component
from deluge.ui.client import aclient as client
from deluge.ui.gtkui.torrentdetails import Tab
class OptionsTab:
class OptionsTab(Tab):
def __init__(self):
glade = component.get("MainWindow").get_glade()
self._name = "Options"
self._child_widget = glade.get_widget("options_tab")
self._tab_label = glade.get_widget("options_tab_label")
self.spin_max_download = glade.get_widget("spin_max_download")
self.spin_max_upload = glade.get_widget("spin_max_upload")
self.spin_max_connections = glade.get_widget("spin_max_connections")

View File

@ -43,6 +43,7 @@ from deluge.configmanager import ConfigManager
import deluge.component as component
import deluge.common
from deluge.ui.gtkui.listview import cell_data_speed as cell_data_speed
from deluge.ui.gtkui.torrentdetails import Tab
from deluge.log import LOG as log
class ColumnState:
@ -53,9 +54,14 @@ class ColumnState:
self.sort = sort
self.sort_order = sort_order
class PeersTab:
class PeersTab(Tab):
def __init__(self):
glade = component.get("MainWindow").get_glade()
self._name = "Peers"
self._child_widget = glade.get_widget("peers_tab")
self._tab_label = glade.get_widget("peers_tab_label")
self.listview = glade.get_widget("peers_listview")
# country pixbuf, ip, client, downspeed, upspeed, country code, int_ip, seed/peer icon
self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, str, int, int, str, gobject.TYPE_UINT, gtk.gdk.Pixbuf)

View File

@ -36,6 +36,7 @@ import gtk, gtk.glade
from deluge.ui.client import aclient as client
import deluge.component as component
import deluge.common
from deluge.ui.gtkui.torrentdetails import Tab
def fpeer_sized(first, second):
return "%s (%s)" % (deluge.common.fsize(first), deluge.common.fsize(second))
@ -55,12 +56,16 @@ def fspeed(value, max_value=-1):
else:
return deluge.common.fspeed(value)
class StatisticsTab:
class StatisticsTab(Tab):
def __init__(self):
# Get the labels we need to update.
# widgetname, modifier function, status keys
glade = component.get("MainWindow").main_glade
self._name = "Statistics"
self._child_widget = glade.get_widget("statistics_tab")
self._tab_label = glade.get_widget("statistics_tab_label")
self.label_widgets = [
(glade.get_widget("summary_pieces"), fpeer_size_second, ("num_pieces", "piece_length")),
(glade.get_widget("summary_availability"), fratio, ("distributed_copies",)),

View File

@ -188,6 +188,12 @@ class StatusBar(component.Component):
log.debug("Unable to remove StatusBar item: %s", e)
self.show_not_connected()
def visible(self, visible):
if visible:
self.statusbar.show()
else:
self.statusbar.hide()
def show_not_connected(self):
self.hbox.pack_start(
self.not_connected_item.get_eventbox(), expand=False, fill=False)

View File

@ -34,17 +34,37 @@
"""The torrent details component shows info about the selected torrent."""
import gtk, gtk.glade
import os
import os.path
import cPickle
import deluge.component as component
from deluge.ui.client import aclient as client
from statistics_tab import StatisticsTab
from details_tab import DetailsTab
from files_tab import FilesTab
from peers_tab import PeersTab
from options_tab import OptionsTab
from deluge.configmanager import ConfigManager
from deluge.log import LOG as log
class Tab:
def __init__(self):
pass
def get_name(self):
return self._name
def get_child_widget(self):
parent = self._child_widget.get_parent()
if parent is not None:
parent.remove(self._child_widget)
return self._child_widget
def get_tab_label(self):
parent = self._tab_label.get_parent()
if parent is not None:
parent.remove(self._tab_label)
return self._tab_label
class TorrentDetails(component.Component):
def __init__(self):
component.Component.__init__(self, "TorrentDetails", interval=2000)
@ -52,22 +72,113 @@ class TorrentDetails(component.Component):
glade = self.window.main_glade
self.notebook = glade.get_widget("torrent_info")
self.details_tab = glade.get_widget("torrentdetails_tab")
# This is the menu item we'll attach the tabs checklist menu to
self.menu_tabs = glade.get_widget("menu_tabs")
self.notebook.connect("switch-page", self._on_switch_page)
statistics_tab = StatisticsTab()
details_tab = DetailsTab()
files_tab = FilesTab()
peers_tab = PeersTab()
options_tab = OptionsTab()
# Tab index is a list of tab names in the order which they presented
# to the user.
self.tab_index = []
self.tabs = []
self.tabs.insert(0, statistics_tab)
self.tabs.insert(1, details_tab)
self.tabs.insert(2, files_tab)
self.tabs.insert(3, peers_tab)
self.tabs.insert(4, options_tab)
# Tabs holds references to the Tab objects by their name
self.tabs = {}
# tab_name: (tab_object, position)
self.hidden_tabs = {}
# Add the default tabs
from statistics_tab import StatisticsTab
from details_tab import DetailsTab
from files_tab import FilesTab
from peers_tab import PeersTab
from options_tab import OptionsTab
default_tabs = {
"Statistics": StatisticsTab,
"Details": DetailsTab,
"Files": FilesTab,
"Peers": PeersTab,
"Options": OptionsTab
}
default_order = [
"Statistics",
"Details",
"Files",
"Peers",
"Options"
]
# Get the state from saved file
state = self.load_state()
# The state is a list of tab_names in the order they should appear
if state == None:
# Set the default order
state = default_order
# Add the tabs in the order from the state
for tab_name in state:
self.add_tab(default_tabs[tab_name]())
if len(state) < len(default_order):
# We have hidden tabs and need to add them to the hidden_tabs dict
for i, tab_name in enumerate(default_order):
if tab_name not in state:
self.hidden_tabs[tab_name] = (default_tabs[tab_name](), i)
# Generate the checklist menu
self.generate_menu()
def add_tab(self, tab_object, position=-1, generate_menu=True):
"""Adds a tab object to the notebook."""
self.tabs[tab_object.get_name()] = tab_object
pos = self.notebook.insert_page(
tab_object.get_child_widget(),
tab_object.get_tab_label(),
position)
self.tab_index.insert(pos, tab_object.get_name())
if generate_menu:
self.generate_menu()
if not self.notebook.get_property("visible"):
# If the notebook isn't visible, show it
self.visible(True)
def remove_tab(self, tab_name):
"""Removes a tab by name."""
index = self.tab_index.index(tab_name)
self.notebook.remove_page(index)
del self.tabs[tab_name]
del self.tab_index[index]
self.generate_menu()
# If there are no tabs visible, then do not show the notebook
if len(self.tabs) == 0:
self.visible(False)
def generate_menu(self):
"""Generates the checklist menu for all the tabs and attaches it"""
menu = gtk.Menu()
# Add all the tabs to the menu
for tab in self.tab_index:
menuitem = gtk.CheckMenuItem(tab)
menuitem.connect("toggled", self._on_menuitem_toggled)
menuitem.set_active(True)
menu.append(menuitem)
# Add all hidden_tabs to the menu too
for tab in self.hidden_tabs.keys():
menuitem = gtk.CheckMenuItem(tab)
menuitem.connect("toggled", self._on_menuitem_toggled)
menuitem.set_active(False)
# Try to keep position in sync
menu.insert(menuitem, self.hidden_tabs[tab][1])
self.menu_tabs.set_submenu(menu)
self.menu_tabs.show_all()
def visible(self, visible):
if visible:
@ -76,25 +187,90 @@ class TorrentDetails(component.Component):
self.notebook.hide()
self.window.vpaned.set_position(-1)
def set_tab_visible(self, tab_name, visible):
"""Sets the tab to visible"""
log.debug("set_tab_visible name: %s visible: %s", tab_name, visible)
if visible:
# We need to show tab, make sure it's not already shown
if tab_name not in self.hidden_tabs.keys():
return
# Add the tab back to the notebook
self.add_tab(self.hidden_tabs[tab_name][0], self.hidden_tabs[tab_name][1], generate_menu=False)
del self.hidden_tabs[tab_name]
else:
# Check to see if tab is already hidden
if tab_name in self.hidden_tabs.keys():
return
# Remove the tab from the notebook and store it in hidden_tabs
self.hidden_tabs[tab_name] = (self.tabs[tab_name], self.tab_index.index(tab_name))
self.remove_tab(tab_name)
def stop(self):
# Save the state of the tabs
for tab in self.tabs:
try:
tab.save_state()
self.tabs[tab].save_state()
except AttributeError:
pass
self.clear()
# Save tabs state
self.save_state()
def update(self):
def update(self, page_num=None):
if self.notebook.get_property("visible"):
if page_num == None:
page_num = self.notebook.get_current_page()
try:
# Get the tab name
name = self.tab_index[page_num]
except IndexError:
return
# Update the tab that is in view
self.tabs[self.notebook.get_current_page()].update()
self.tabs[name].update()
def clear(self):
self.tabs[self.notebook.get_current_page()].clear()
# Get the tab name
name = self.tab_index[self.notebook.get_current_page()]
self.tabs[name].clear()
def _on_switch_page(self, notebook, page, page_num):
self.tabs[page_num].update()
self.update(page_num)
client.force_call(False)
def _on_menuitem_toggled(self, widget):
# Get the tab name
name = widget.get_child().get_text()
self.set_tab_visible(name, widget.get_active())
def save_state(self):
"""We save the state, which is basically the tab_index list"""
filename = "tabs.state"
state = self.tab_index
# Get the config location for saving the state file
config_location = ConfigManager("gtkui.conf")["config_location"]
try:
log.debug("Saving TorrentDetails state file: %s", filename)
state_file = open(os.path.join(config_location, filename), "wb")
cPickle.dump(state, state_file)
state_file.close()
except IOError, e:
log.warning("Unable to save state file: %s", e)
def load_state(self):
filename = "tabs.state"
# Get the config location for loading the state file
config_location = ConfigManager("gtkui.conf")["config_location"]
state = None
try:
log.debug("Loading TorrentDetails state file: %s", filename)
state_file = open(os.path.join(config_location, filename), "rb")
state = cPickle.load(state_file)
state_file.close()
except IOError, e:
log.warning("Unable to load state file: %s", e)
return state