1 from deluge
.ui
.client
import aclient
as client
11 class TorSettings(gnt
.Window
):
12 def new(cls
, torrent_id
):
13 if torrent_id
in _tor_settings
:
14 return _tor_settings
[torrent_id
]
16 _tor_settings
[torrent_id
] = r
18 new
= classmethod(new
)
20 def __init__(self
, torrent_id
):
21 gnt
.Window
.__init
__(self
)
22 self
.torrent
= torrent_id
23 self
.set_title("Change Torrent Settings...")
24 self
.set_property('vertical', True)
26 self
.set_alignment(gnt
.ALIGN_MID
)
28 self
.label
= gnt
.Label("...")
29 self
.add_widget(self
.label
)
30 self
.add_widget(gnt
.Line(False))
32 self
.maxdls
= gnt
.Entry("")
33 self
.maxups
= gnt
.Entry("")
34 self
.maxcon
= gnt
.Entry("")
35 self
.priv
= gnt
.CheckBox("Private")
36 self
.maxdls
.set_size(8, 1)
37 self
.maxups
.set_size(8, 1)
38 self
.maxcon
.set_size(8, 1)
40 for label
, widget
in (
41 ('Maximum Download Speed (KB/s)', self
.maxdls
),
42 ('Maximum Upload Speed (KB/s)', self
.maxups
),
43 ('Maximum Connections', self
.maxcon
)):
44 self
.add_widget(common
.pack_widget(False, [gnt
.Label(label
), widget
]))
45 self
.add_widget(self
.priv
)
47 save
= gnt
.Button("Save")
48 cancel
= gnt
.Button("Cancel")
49 self
.add_widget(common
.pack_widget(False, [save
, cancel
]))
53 (self
.maxdls
, client
.set_torrent_max_download_speed
),
54 (self
.maxups
, client
.set_torrent_max_upload_speed
),
55 (self
.maxcon
, client
.set_torrent_max_connections
),
57 nvalue
= widget
.get_text()
58 ovalue
= widget
.get_data('original-value')
60 fn(self
.torrent
, float(nvalue
))
61 if self
.priv
.get_checked() != self
.priv
.get_data('original-value'):
62 client
.set_torrent_private_flag(self
.torrent
, self
.priv
.get_checked())
64 save
.connect('activate', _on_save
)
68 cancel
.connect('activate', _on_cancel
)
70 def _got_details(status
):
72 ('max_download_speed', self
.maxdls
),
73 ('max_upload_speed', self
.maxups
),
74 ('max_connections', self
.maxcon
),
76 value
= str(status
[key
])
77 widget
.set_text(value
)
78 widget
.set_data('original-value', value
)
79 self
.priv
.set_checked(int(status
['private']))
80 self
.priv
.set_data('original-value', int(status
['private']))
81 self
.label
.set_text(str(status
['name']))
83 client
.get_torrent_status(_got_details
, self
.torrent
,
84 ['max_connections', 'max_upload_slots', 'max_upload_speed', 'max_download_speed', 'private', 'name'])
87 def remove_self(self
):
88 del _tor_settings
[self
.torrent
]
89 self
.connect('destroy', remove_self
)
90 gobject
.type_register(TorSettings
)