1 from deluge
.ui
.client
import aclient
as client
4 from deluge
.log
import LOG
as log
11 class TorFileRow(gobject
.GObject
):
12 def decide_priority(self
):
15 if self
.priorities
== 1:
17 elif self
.priorities
< 7:
22 def get_row_flag(self
):
24 return gnt
.TEXT_FLAG_DIM
25 elif self
.progress
== 1.0:
26 return gnt
.TEXT_FLAG_BOLD
28 return gnt
.TEXT_FLAG_NORMAL
30 def __init__(self
, file):
31 self
.__gobject
_init
__()
32 self
.path
= file['path']
33 self
.size
= file['size']
34 self
.pieces
= 0 #len(file['priorities'])
35 self
.priorities
= 1 #file['priorities']
36 self
.enabled
= file['priority'] #len([p for p in self.priorities if p > 0]) > 0
37 self
.progress
= file['progress']
40 prg
= "%.1f" % (self
.progress
* 100)
41 return [self
.path
, "%s (%5s%%)" % (common
.show_size(self
.size
), prg
), self
.decide_priority()]
42 gobject
.type_register(TorFileRow
)
46 class TorDetails(gnt
.Window
):
55 'download_payload_rate',
57 'total_payload_upload',
58 'upload_payload_rate',
61 'num_seeds', 'total_seeds',
62 'num_peers', 'total_peers',
71 DEFAULT
= gnt
.gnt_color_add_pair(-1, -1)
72 BLACK
= gnt
.gnt_color_add_pair(0, -1)
73 RED
= gnt
.gnt_color_add_pair(1, -1)
74 GREEN
= gnt
.gnt_color_add_pair(2, -1)
75 YELLOW
= gnt
.gnt_color_add_pair(3, -1)
76 BLUE
= gnt
.gnt_color_add_pair(4, -1)
77 MAGENTA
= gnt
.gnt_color_add_pair(5, -1)
78 CYAN
= gnt
.gnt_color_add_pair(6, -1)
79 WHITE
= gnt
.gnt_color_add_pair(7, -1)
81 INTERVAL
= 5 # Update the information every 5 seconds
83 def new(cls
, torrent_id
):
84 if torrent_id
in _tor_details
:
85 return _tor_details
[torrent_id
]
87 _tor_details
[torrent_id
] = r
89 new
= classmethod(new
)
91 def __init__(self
, torrent_id
):
92 gnt
.Window
.__init
__(self
)
93 self
.torrent
= torrent_id
94 self
.set_property('vertical', True)
95 self
.set_property('homogeneous', False)
96 self
.set_alignment(gnt
.ALIGN_MID
)
99 self
.set_title("Details")
102 def _on_torrent_status(status
):
105 client
.get_torrent_status(_on_torrent_status
, self
.torrent
, TorDetails
.KEYS
)
111 for label
, value
in info
:
112 label
= "%15s: " % label
113 tv
.append_text_with_flags(label
, gnt
.TEXT_FLAG_BOLD
)
114 tv
.append_text_with_flags(value
+ "\n", gnt
.TEXT_FLAG_NORMAL
)
115 string
= string
+ label
+ value
+ "\n"
116 tv
.set_flag(gnt
.TEXT_VIEW_TOP_ALIGN | gnt
.TEXT_VIEW_NO_SCROLL
)
117 w
, h
= gnt
.get_text_bound(string
.strip())
118 tv
.set_size(w
+ 3, h
)
123 ("Name", "%s" % status
['name']),
124 ("Path", "%s" % status
['save_path']),
125 ("# of files", "%s" % status
['num_files']),
126 ("Status", status
['state']),
127 ("Tracker", status
['tracker']),
129 self
.add_widget(add_info(top
))
130 self
.add_widget(gnt
.Line(False))
134 ("Downloaded", "%s (%s)" % (deluge.common.fsize(float(status['total_done'])),
135 deluge.common.fsize(float(status['total_size'])))),
136 ("Download Speed", "%s" % deluge.common.fspeed(float(status['download_payload_rate']))),
137 ("Uploaded", "%s (%s)" % (deluge.common.fsize(float(status['total_uploaded'])),
138 deluge.common.fsize(float(status['total_payload_upload'])))),
139 ("Upload Speed", "%s" % deluge.common.fspeed(float(status['upload_payload_rate']))),
140 ("Pieces", "%s (%s)" % (status['num_pieces'], deluge.common.fsize(status['piece_length']))),
144 ("Seeders", "%s (%s)" % (status['num_seeds'], status['total_seeds'])),
145 ("Peers", "%s (%s)" % (status['num_peers'], status['total_peers'])),
146 ("ETA", "%s" % deluge.common.ftime(status['eta'])),
147 ("Share Ratio", "%.1f" % status['ratio']),
148 ("Availability", "%.1f" % status['distributed_copies']),
152 files.set_property('columns', 3)
153 files.set_col_width(1, 13)
154 files.set_column_resizable(1, False)
155 files.set_col_width(2, 10)
156 files.set_show_title(True)
157 files.set_column_title(0, 'File')
158 files.set_column_title(1, 'Size')
159 files.set_column_title(2, 'Priority')
160 files.set_column_is_right_aligned(1, True)
161 priorities = status['file_priorities']
162 progress = status['file_progress']
163 for i, file in enumerate(status['files']):
164 if i < len(priorities):
165 file['priority'] = priorities[i]
168 file['progress'] = progress[i]
169 torfile = TorFileRow(file)
170 files.add_row_after(torfile, torfile.info(), None)
171 files.set_row_flags(torfile, torfile.get_row_flag())
172 self.add_widget(files)
176 tv
.set_flag(gnt
.TEXT_VIEW_TOP_ALIGN | gnt
.TEXT_VIEW_NO_SCROLL
)
178 def append_row(color
, llabel
, ltext
, rlabel
, rtext
):
179 tv
.append_text_with_flags("%15s: " % llabel
, gnt
.TEXT_FLAG_NORMAL | gnt
.gnt_color_pair(color
))
180 tv
.append_text_with_tag("%-25s " % ltext
, gnt
.TEXT_FLAG_BOLD | gnt
.gnt_color_pair(color
), llabel
)
181 tv
.append_text_with_flags("%15s: " % rlabel
, gnt
.TEXT_FLAG_NORMAL | gnt
.gnt_color_pair(color
))
182 tv
.append_text_with_tag("%-15s\n" % rtext
, gnt
.TEXT_FLAG_BOLD | gnt
.gnt_color_pair(color
), llabel
+ rlabel
)
183 tv
.text
= tv
.text
+ "%15s: %-25s %15s: %-15s\n" % (llabel
, ltext
, rlabel
, rtext
)
185 if not status
['is_seed']:
186 append_row(self
.GREEN
, "Downloaded",
187 "%s (%s)" % (deluge
.common
.fsize(float(status
['total_done'])),
188 deluge
.common
.fsize(float(status
['total_size']))),
189 "Speed", "%s" % deluge
.common
.fspeed(float(status
['download_payload_rate'])))
191 append_row(self
.BLUE
, "Uploaded",
192 "%s (%s)" % (deluge
.common
.fsize(float(status
['total_uploaded'])),
193 deluge
.common
.fsize(float(status
['total_payload_upload']))),
194 "Speed", "%s" % deluge
.common
.fspeed(float(status
['upload_payload_rate'])))
196 append_row(self
.CYAN
, "Seeds", "%s (%s)" % (status
['num_seeds'], status
['total_seeds']),
197 "Peers", "%s (%s)" % (status
['num_peers'], status
['total_peers']))
199 append_row(self
.MAGENTA
,
200 "Pieces", "%s (%s)" % (status
['num_pieces'], deluge
.common
.fsize(status
['piece_length'])),
201 "ETA", "%s" % deluge
.common
.ftime(status
['eta']))
203 append_row(self
.DEFAULT
,
204 "Share Ratio", "%.1f" % status
['ratio'],
205 "Availability", "%.1f" % status
['distributed_copies'])
207 w
, h
= gnt
.get_text_bound(tv
.text
)
209 gnt
.unset_flag(tv
, gnt
.WIDGET_GROW_Y
)
213 ok
= gnt
.Button("OK")
214 def close_info_dlg(b
, self
):
217 ok
.connect('activate', close_info_dlg
, self
)
218 box
= gnt
.Box(False, False)
222 def remove_self(self
):
223 del _tor_details
[torrent_id
]
224 self
.connect('destroy', remove_self
)
226 gobject
.type_register(TorDetails
)