move gtk-label config to sidebar

This commit is contained in:
Martijn Voncken 2008-07-30 19:35:43 +00:00
parent 9a00d4db39
commit 7dc16ec20b
4 changed files with 537 additions and 559 deletions

View File

@ -0,0 +1,404 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Wed Jul 30 20:20:04 2008 -->
<glade-interface>
<widget class="GtkDialog" id="dlg_label_options">
<property name="border_width">5</property>
<property name="title" translatable="yes">Label Options</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<widget class="GtkNotebook" id="notebook2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">6</property>
<property name="n_columns">4</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<widget class="GtkLabel" id="label14">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_connections">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
<property name="numeric">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options"></property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Connections:</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="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_upload_slots">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
<property name="numeric">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_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">Kib/s</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">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Download Speed:</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Upload Speed:</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</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="label5">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Upload Slots: </property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</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="GtkSpinButton" id="max_download_speed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">Kib/s</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_upload_speed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</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_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="label" translatable="yes">Bandwith</property>
</widget>
<packing>
<property name="type">tab</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label10">
<property name="visible">True</property>
<property name="label" translatable="yes">todo</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="label" translatable="yes">Queue</property>
</widget>
<packing>
<property name="type">tab</property>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label11">
<property name="visible">True</property>
<property name="label" translatable="yes">todo
</property>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="label" translatable="yes">Location</property>
</widget>
<packing>
<property name="type">tab</property>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_options_cancel"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">gtk-ok</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_options_ok"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
<widget class="GtkDialog" id="dlg_label_add">
<property name="border_width">5</property>
<property name="title" translatable="yes">Add Label</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property>
<signal name="close" handler="on_label_cancel"/>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox2">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<widget class="GtkLabel" id="label12">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Label name:&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
</child>
<child>
<widget class="GtkEntry" id="txt_add">
<property name="visible">True</property>
<property name="can_focus">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area2">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_add_cancel"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">gtk-ok</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_add_ok"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Sun Jul 20 22:26:59 2008 --> <!--Generated with glade3 3.4.5 on Wed Jul 30 20:32:12 2008 -->
<glade-interface> <glade-interface>
<widget class="GtkWindow" id="window1"> <widget class="GtkWindow" id="window1">
<child> <child>
@ -73,371 +73,13 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkFrame" id="frame2"> <widget class="GtkLabel" id="label3">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label_xalign">0</property> <property name="label" translatable="yes">&lt;i&gt;Use the sidebar to add,edit and remove labels.&lt;/i&gt;
<property name="shadow_type">GTK_SHADOW_NONE</property> </property>
<child> <property name="use_markup">True</property>
<widget class="GtkHPaned" id="hpaned1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="position">150</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<widget class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="n_rows">1</property>
<property name="n_columns">2</property>
<child>
<widget class="GtkButton" id="btn_add">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">add</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="txt_add">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkTreeView" id="label_view">
<property name="height_request">250</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_clickable">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn_remove">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">Remove</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</widget>
<packing>
<property name="resize">False</property>
<property name="shrink">False</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox3">
<property name="visible">True</property>
<child>
<widget class="GtkLabel" id="txt_label">
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;label&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
</child>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">12</property>
<property name="n_columns">3</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<widget class="GtkButton" id="btn_apply">
<property name="width_request">50</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">Apply to all</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
</packing>
</child>
<child>
<widget class="GtkFileChooserButton" id="move_completed_to">
<property name="visible">True</property>
<property name="title" translatable="yes">Select A Folder</property>
</widget>
<packing>
<property name="right_attach">3</property>
<property name="top_attach">7</property>
<property name="bottom_attach">8</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_upload_speed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="apply_max">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Apply maximum limits on add:</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="chk_move_completed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Move completed to:</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="right_attach">3</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="label" translatable="yes">Kib/s</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_EXPAND | GTK_SHRINK | GTK_FILL</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_download_speed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_connections">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
<property name="numeric">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Upload Slots: </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="label6">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Upload Speed:</property>
</widget>
<packing>
<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="label5">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Download Speed:</property>
<property name="use_markup">True</property>
</widget>
<packing>
<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="label4">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Connections:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="label" translatable="yes">Kib/s</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="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_upload_slots">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
<property name="numeric">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="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn_save">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">Save Label Settings</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="right_attach">3</property>
<property name="top_attach">9</property>
<property name="bottom_attach">10</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label10">
<property name="visible">True</property>
<property name="ypad">5</property>
<property name="label" translatable="yes">&lt;b&gt;Labels&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>

View File

@ -50,32 +50,13 @@ class LabelConfig(object):
#self.glade = gtk.glade.XML(self.get_resource("label_pref.glade")) #self.glade = gtk.glade.XML(self.get_resource("label_pref.glade"))
log.debug('Adding Label Preferences page') log.debug('Adding Label Preferences page')
self.glade = gtk.glade.XML(self.get_resource("label_pref.glade")) self.glade = gtk.glade.XML(self.get_resource("label_pref.glade"))
self.prefs_box = self.glade.get_widget("label_prefs_box")
self.label_view = self.glade.get_widget("label_view")
self.txt_add = self.glade.get_widget("txt_add")
self.btn_add = self.glade.get_widget("btn_add")
self.btn_remove = self.glade.get_widget("btn_remove")
self.label_view = self.glade.get_widget("label_view")
self.btn_remove.connect("clicked", self.on_remove, None)
self.btn_add.connect("clicked", self.on_add, None)
self.build_label_view()
self.plugin.add_preferences_page("Label", self.glade.get_widget("label_prefs_box")) self.plugin.add_preferences_page("Label", self.glade.get_widget("label_prefs_box"))
self.plugin.register_hook("on_show_prefs", self.load_settings) self.plugin.register_hook("on_show_prefs", self.load_settings)
self.plugin.register_hook("on_apply_prefs", self.on_apply_prefs) self.plugin.register_hook("on_apply_prefs", self.on_apply_prefs)
self.glade.get_widget("chk_move_completed").connect("clicked",self.on_chk_move_changed)
self.glade.get_widget("apply_max").connect("clicked",self.on_apply_max_changed)
self.glade.get_widget("btn_save").connect("clicked",self.on_save_label)
self.glade.get_widget("btn_apply").connect("clicked",self.on_apply_label)
self.load_settings() self.load_settings()
def unload(self): def unload(self):
@ -86,188 +67,12 @@ class LabelConfig(object):
return pkg_resources.resource_filename("label", os.path.join("data", filename)) return pkg_resources.resource_filename("label", os.path.join("data", filename))
def load_settings(self ,widget = None , data = None): def load_settings(self ,widget = None , data = None):
aclient.label_get_labels(self.cb_update_labels)
aclient.label_get_global_options(self.cb_global_options) aclient.label_get_global_options(self.cb_global_options)
def cb_global_options(self, data): def cb_global_options(self, data):
self.glade.get_widget("hide_zero_hits").set_active(data["hide_zero_hits"]) self.glade.get_widget("hide_zero_hits").set_active(data["hide_zero_hits"])
def cb_update_labels(self, labels):
log.debug("update labels")
self.labels = labels
self.label_store.clear()
for label in labels:
self.label_store.append([label])
if labels:
self.label_view.get_selection().select_iter(self.label_store.get_iter_first())
def cb_label_options(self, data):
for key in ["max_download_speed", "max_upload_speed", "max_connections" ,"max_upload_slots"]:
spin = self.glade.get_widget(key)
spin.set_value(data[key])
self.glade.get_widget("apply_max").set_active(data["apply_max"])
self.glade.get_widget("chk_move_completed").set_active(bool(data["move_completed_to"]))
self.glade.get_widget("move_completed_to").set_filename(data["move_completed_to"] or "")
self.on_apply_max_changed()
self.on_chk_move_changed()
def on_apply_prefs(self): def on_apply_prefs(self):
options = {"hide_zero_hits":self.glade.get_widget("hide_zero_hits").get_active()} options = {"hide_zero_hits":self.glade.get_widget("hide_zero_hits").get_active()}
aclient.label_set_global_options(None, options) aclient.label_set_global_options(None, options)
def on_chk_move_changed(self, data = None):
self.glade.get_widget("move_completed_to").set_sensitive(
self.glade.get_widget("chk_move_completed").get_active())
def on_apply_max_changed(self, data = None):
active = self.glade.get_widget("apply_max").get_active()
for key in ["max_download_speed", "max_upload_speed", "max_connections" ,"max_upload_slots","btn_apply"]:
spin = self.glade.get_widget(key)
spin.set_sensitive(active)
def on_add(self, widget, data = None):
label = self.txt_add.get_text()
self.txt_add.set_text("")
if label in self.labels:
return
aclient.label_add(None , label)
aclient.label_get_labels(self.cb_update_labels)
aclient.force_call(block=True)
self.select_label(label)
def on_remove(self, widget, data=None):
label = self.get_selected_label()
aclient.label_remove(None, label)
aclient.label_get_labels(self.cb_update_labels)
self.select_label(0)
def on_save_label(self, arg = None, apply = False):
options = {}
for key in ["max_download_speed", "max_upload_speed", "max_connections" ,"max_upload_slots"]:
options[key] = self.glade.get_widget(key).get_value()
options["apply_max"] = self.glade.get_widget("apply_max").get_active()
if self.glade.get_widget("chk_move_completed").get_active():
options["move_completed_to"] = self.glade.get_widget("move_completed_to").get_filename()
else:
options["move_completed_to"] = None
aclient.label_set_options(None, self.label, options , apply)
def on_apply_label(self, arg = None):
self.on_save_label(apply = True)
def get_selected_label(self):
model , iter = self.label_view.get_selection().get_selected()
return self.label_store.get_value(iter,0)
def select_label(self, label):
aclient.force_call(block=True) #sync..
if label:
it = self.label_store.iter_nth_child(None,self.labels.index(label))
elif self.labels:
it = self.label_store.iter_nth_child(None,0)
if self.labels:
self.label_view.get_selection().select_iter(it)
def build_label_view(self):
"gtk should have a simple listbox widget..."
self.label_store = gtk.ListStore(str)
column = gtk.TreeViewColumn(_("Label"))
renderer = gtk.CellRendererText()
column.pack_start(renderer)
column.set_attributes(renderer, text = 0)
self.label_view.set_model(self.label_store)
self.label_view.append_column(column)
self.label_view.set_headers_visible(False)
self.label_view.get_selection().connect("changed", self.on_label_changed)
def on_label_changed(self, selection):
try:
(model, row) = self.label_view.get_selection().get_selected()
self.label = model.get_value(row, 0)
self.glade.get_widget("txt_label").set_markup("<b>%s</b>" % self.label)
aclient.label_get_options(self.cb_label_options, self.label)
except:
log.debug("none selected")
"""
label = gtk.Label()
label.set_markup('<b>' + _('General') + '</b>')
self.set_shadow_type(gtk.SHADOW_NONE)
self.set_label_widget(label)
self.btn_load = gtk.Button("Load Settings")
self.btn_load.connect("clicked", self.load_settings, None)
self.btn_remove = gtk.Button("Remove")
self.btn_remove.connect("clicked", self.on_remove, None)
vb = gtk.VBox()
self.add(vb)
#vb.add(self.btn_load)
#vb.add(gtk.Label("Label is in developent, you're testing pre-alfa!!!"))
self.hide_zero_hits = gtk.CheckButton(_('Hide Zero Hits'))
vb.add(self.hide_zero_hits)
label = gtk.Label()
label.set_markup('<b>' + _('Labels') + '</b>')
vb.add(label)
hp = gtk.HPaned()
hp.add1(self.label_view)
hp.add2(self.label_options)
hp.set_position(100)
hp.set_size_request(400, 200) #bug..
hbAdd = gtk.HBox()
hbAdd.add(gtk.Label("Label:"))
self.txt_add = gtk.Entry()
hbAdd.add(self.txt_add)
btn_add = gtk.Button("Add")
hbAdd.add(btn_add)
btn_add.connect("clicked", self.on_add, None)
vb.pack_end(hbAdd)
label = gtk.Label()
label.set_markup('<b>' + _('Add') + '</b>')
vb.pack_end(label)
vb.pack_end(self.btn_remove, True , True)
vb.pack_end(hp,True , True)
"""

View File

@ -49,7 +49,107 @@ STATE_PIX = {
"Error":"alert" "Error":"alert"
} }
NO_LABEL = "No Label"
#helpers:
def get_resource(filename):
import pkg_resources
import os
return pkg_resources.resource_filename("label", os.path.join("data", filename))
#menu
class LabelMenu(gtk.Menu):
def __init__(self):
gtk.Menu.__init__(self)
self._add_item("add", _("_Add"), gtk.STOCK_ADD)
self._add_item("options", _("_Options") ,gtk.STOCK_PREFERENCES)
self._add_item("remove", _("Remove"), gtk.STOCK_REMOVE)
self.show_all()
self.label = None
#dialogs:
self.add_dialog = AddDialog()
self.options_dialog = OptionsDialog()
def _add_item(self, id, label , stock):
"add a menu item, some magic here because i hate glade."
method = getattr(self,"on_%s" % id)
item = gtk.ImageMenuItem(stock)
item.connect("activate", method)
self.append(item)
setattr(self,"item_%s" % id, item)
def on_add(self, event=None):
self.add_dialog.show(self.label)
def on_remove(self, event=None):
aclient.label_remove(None, self.label)
def on_options (self, event=None):
self.options_dialog.show(self.label)
def set_label(self,label):
"No Label:disable options/del"
self.label = label
sensitive = (label != NO_LABEL)
self.item_options.set_sensitive(sensitive)
self.item_remove.set_sensitive(sensitive)
#dialogs:
class AddDialog(object):
def __init__(self):
pass
def show(self, label):
self.glade = gtk.glade.XML(get_resource("label_options.glade"))
self.dialog = self.glade.get_widget("dlg_label_add")
self.glade.signal_autoconnect({
"on_add_ok":self.on_ok,
"on_add_cancel":self.on_cancel,
})
self.dialog.run()
def on_ok(self, event=None):
value = self.glade.get_widget("txt_add").get_text()
aclient.label_add(None, value)
self.dialog.destroy()
def on_cancel(self, event=None):
self.dialog.destroy()
class OptionsDialog(object):
spin_ids = ["max_download_speed","max_upload_speed","max_upload_slots","max_connections"]
def __init__(self):
pass
def show(self, label):
self.label = label
self.glade = gtk.glade.XML(get_resource("label_options.glade"))
self.dialog = self.glade.get_widget("dlg_label_options")
self.glade.signal_autoconnect({
"on_options_ok":self.on_ok,
"on_options_cancel":self.on_cancel,
})
aclient.label_get_options(self.load_options, self.label)
self.dialog.run()
def load_options(self, options):
for id in self.spin_ids:
self.glade.get_widget(id).set_value(options[id])
def on_ok(self, event=None):
options = {}
for id in self.spin_ids:
options[id] = self.glade.get_widget(id).get_value()
aclient.label_set_options(None, self.label, options)
self.dialog.destroy()
def on_cancel(self, event=None):
self.dialog.destroy()
#sidebar-treeview
class LabelSideBar(component.Component): class LabelSideBar(component.Component):
def __init__(self): def __init__(self):
component.Component.__init__(self, "LabelSideBar", interval=2000) component.Component.__init__(self, "LabelSideBar", interval=2000)
@ -108,6 +208,10 @@ class LabelSideBar(component.Component):
self.label_view.expand_all() self.label_view.expand_all()
self.hpaned.set_position(170) self.hpaned.set_position(170)
self.label_view.connect("button-press-event", self.on_button_press_event)
self.label_menu = LabelMenu()
def load(self): def load(self):
sidebar = component.get("SideBar") sidebar = component.get("SideBar")
@ -208,7 +312,7 @@ class LabelSideBar(component.Component):
filter = (cat, value) filter = (cat, value)
if value == "All" or cat == "cat": if value == "All" or cat == "cat":
filter = (None, None) filter = (None, None)
elif (cat == "label" and value == "No Label"): elif (cat == "label" and value == NO_LABEL):
filter = ("label","") filter = ("label","")
component.get("TorrentView").set_filter(*filter) component.get("TorrentView").set_filter(*filter)
@ -225,3 +329,26 @@ class LabelSideBar(component.Component):
log.debug(e) log.debug(e)
### Callbacks ###
def on_button_press_event(self, widget, event):
"""This is a callback for showing the right-click context menu."""
# We only care about right-clicks
if event.button == 3:
x, y = event.get_coords()
path = self.label_view.get_path_at_pos(int(x), int(y))
if not path:
return
row = self.model_filter.get_iter(path[0])
cat = self.model_filter.get_value(row, 0)
value = self.model_filter.get_value(row, 1)
log.debug("right-click->cat='%s',value='%s'", cat ,value)
if cat == "label":
self.show_label_menu(value, event)
def show_label_menu(self, label, event):
self.label_menu.set_label(label)
self.label_menu.popup(None, None, None, event.button, event.time)