source: deluge/ui/gtkui/trackers_tab.py@ 649638

2.0.x develop
Last change on this file since 649638 was 649638, checked in by Calum Lind <calumlind+deluge@gmail.com>, 11 years ago

[GTKUI] Reorganise layout of tab items and add Tracker tab

  • Changed layout of Status, Details and Options tabs.
  • Moved the Tracker translations to ui.common.
  • Created a new Trackers tab.
  • Added State to progressbar.
  • Translate State in piecesbar.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
4#
5# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
6# the additional special exception to link portions of this program with the OpenSSL library.
7# See LICENSE for more details.
8#
9
10import logging
11
12import deluge.component as component
13from deluge.common import ftime
14from deluge.ui.gtkui.torrentdetails import Tab
15
16log = logging.getLogger(__name__)
17
18
19def fcount(value):
20 return "%s" % len(value)
21
22
23def ftranslate(text):
24 if text:
25 text = _(text)
26 return text
27
28
29class TrackersTab(Tab):
30 def __init__(self):
31 Tab.__init__(self)
32 # Get the labels we need to update.
33 # widget name, modifier function, status keys
34 builder = component.get("MainWindow").get_builder()
35
36 self._name = "Trackers"
37 self._child_widget = builder.get_object("trackers_tab")
38 self._tab_label = builder.get_object("trackers_tab_label")
39
40 self.label_widgets = [
41 (builder.get_object("summary_next_announce"), ftime, ("next_announce",)),
42 (builder.get_object("summary_tracker"), None, ("tracker_host",)),
43 (builder.get_object("summary_tracker_status"), ftranslate, ("tracker_status",)),
44 (builder.get_object("summary_tracker_total"), fcount, ("trackers",)),
45 ]
46
47 self.status_keys = [status for widget in self.label_widgets for status in widget[2]]
48
49 component.get("MainWindow").connect_signals({
50 "on_button_edit_trackers_clicked": self._on_button_edit_trackers_clicked,
51 })
52
53 def update(self):
54 # Get the first selected torrent
55 selected = component.get("TorrentView").get_selected_torrents()
56
57 # Only use the first torrent in the list or return if None selected
58 if selected:
59 selected = selected[0]
60 else:
61 self.clear()
62 return
63
64 session = component.get("SessionProxy")
65 session.get_torrent_status(selected, self.status_keys).addCallback(self._on_get_torrent_status)
66
67 def _on_get_torrent_status(self, status):
68 # Check to see if we got valid data from the core
69 if not status:
70 return
71
72 # Update all the label widgets
73 for widget in self.label_widgets:
74 if widget[1] is None:
75 txt = status[widget[2][0]]
76 else:
77 try:
78 args = [status[key] for key in widget[2]]
79 except KeyError, ex:
80 log.debug("Unable to get status value: %s", ex)
81 continue
82 txt = widget[1](*args)
83
84 if widget[0].get_text() != txt:
85 widget[0].set_text(txt)
86
87 def clear(self):
88 for widget in self.label_widgets:
89 widget[0].set_text("")
90
91 def _on_button_edit_trackers_clicked(self, button):
92 torrent_id = component.get("TorrentView").get_selected_torrent()
93 if torrent_id:
94 from edittrackersdialog import EditTrackersDialog
95 dialog = EditTrackersDialog(torrent_id, component.get("MainWindow").window)
96 dialog.run()
Note: See TracBrowser for help on using the repository browser.