Add some torrent settings and fix a couple of issues in UnitSpinner

This commit is contained in:
Kai Huuhko 2014-07-09 18:05:44 +03:00
parent e02a0186a0
commit 2505aa214c
5 changed files with 167 additions and 37 deletions

16
TODO
View File

@ -7,25 +7,21 @@ Torrent-handle controls/options:
✔ Scrape tracker @done (18:43 06.07.2014)
☐ Torrent properties
./epour/gui/TorrentProps.py
☐ save_path() move_storage()
✔ save_path() move_storage() @done (14:18 09.07.2014)
✔ super_seeding() (status.super_seeding) @done (09:49 08.07.2014)
?
☐ set_upload_limit() set_download_limit() upload_limit() download_limit()
✔ set_upload_limit() set_download_limit() upload_limit() download_limit() @done (14:50 09.07.2014)
✔ set_sequential_download() (status.sequential_download) @done (09:49 08.07.2014)
?
✔ set_upload_mode() (status.upload_mode) @done (09:49 08.07.2014)
?
✔ set_share_mode() (status.share_mode) @done (09:49 08.07.2014)
?
☐ apply_ip_filter() (status.ip_filter_applies)
✔ apply_ip_filter() (status.ip_filter_applies) @done (12:47 08.07.2014)
☐ set_tracker_login()
☐ trackers() replace_trackers() add_tracker()
☐ add_url_seed() remove_url_seed() url_seeds()
☐ add_http_seed() remove_http_seed() http_seeds()
☐ set_priority()
☐ set_priority() (status.priority)
☐ use_interface()
☐ set_max_uploads() max_uploads()
☐ set_max_connections() max_connections()
✔ set_max_uploads() max_uploads() @done (12:47 08.07.2014)
✔ set_max_connections() max_connections() @done (12:47 08.07.2014)
☐ get_download_queue()
?
☐ get_peer_info()

View File

@ -715,7 +715,7 @@ class Limits(Frame):
usw.size_hint_weight = EXPAND_HORIZ
usw.size_hint_align = FILL_HORIZ
usw.set_value(rfunc())
usw.callback_changed_add(wfunc, delay=2.0)
usw.callback_changed_add(lambda x, y: wfunc(y), delay=2.0)
t.pack(usw, 1, r, 1, 1)
usw.show()

View File

@ -48,9 +48,12 @@ from efl.elementary.configuration import Configuration
elm_conf = Configuration()
SCALE = elm_conf.scale
from efl.elementary.scroller import Scroller
from efl.elementary.spinner import Spinner
from efl.elementary.fileselector import Fileselector
from efl.elementary.fileselector_entry import FileselectorEntry
from intrepr import intrepr
from Widgets import Information
from Widgets import Information, UnitSpinner
EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0
@ -141,12 +144,21 @@ class TorrentProps(StandardWindow):
if h.has_metadata():
f = Frame(self, text="Torrent info", size_hint_align=FILL_HORIZ)
ti = TorrentInfo(f, h, size_hint_align=FILL_HORIZ)
ti = TorrentInfo(
f, h, size_hint_align=FILL_HORIZ)
f.content = ti
box.pack_end(f)
ti.show()
f.show()
f = Frame(self, text="Torrent settings", size_hint_align=FILL_HORIZ)
ts = TorrentSettings(
f, h, size_hint_align=FILL_HORIZ)
f.content = ts
box.pack_end(f)
ts.show()
f.show()
f = Frame(self, text="Torrent status", size_hint_align=FILL_HORIZ)
ts = TorrentStatus(f, h, size_hint_align=FILL_HORIZ)
f.content = ts
@ -177,10 +189,10 @@ class TorrentProps(StandardWindow):
f.show()
box.pack_end(f)
xbtn = Button(box, text="Close")
xbtn.callback_clicked_add(lambda x: self.delete())
box.pack_end(xbtn)
xbtn.show()
# xbtn = Button(box, text="Close")
# xbtn.callback_clicked_add(lambda x: self.delete())
# box.pack_end(xbtn)
# xbtn.show()
box.show()
scroller.show()
@ -393,6 +405,126 @@ class TorrentInfo(Box):
fl_btn.show()
class TorrentSettings(Box):
status_checks = {
"super_seeding": "super_seeding",
"sequential_download": "set_sequential_download",
"upload_mode": "set_upload_mode",
"share_mode": "set_share_mode",
"ip_filter_applies": "apply_ip_filter"
}
handle_unit_spinners = {
"upload_limit": "set_upload_limit",
"download_limit": "set_download_limit"
}
handle_spinners = {
"max_uploads": "set_max_uploads",
"max_connections": "set_max_connections"
}
def __init__(self, parent, handle, *args, **kwargs):
super(self.__class__, self).__init__(parent, *args, **kwargs)
s = handle.status()
t = Table(self, size_hint_align=FILL_HORIZ, homogeneous=True)
l = Label(t)
l.size_hint_align = ALIGN_LEFT
l.text = "Storage path"
t.pack(l, 0, 0, 1, 1)
l.show()
fs = FsEntry(t)
fs.size_hint_align = FILL_HORIZ
fs.text = "Select"
fs.folder_only = True
fs.expandable = False
fs.path = handle.save_path()
def fs_cb(fs, path):
if not path:
return
if os.path.isdir(path):
handle.move_storage(path)
fs.callback_file_chosen_add(fs_cb)
t.pack(fs, 1, 0, 1, 1)
fs.show()
self.pack_end(t)
t.show()
t = Table(self, size_hint_align=FILL_HORIZ, homogeneous=True)
#Checks (bool)
for i, (getter, setter) in enumerate(self.status_checks.items()):
l = Label(t)
l.size_hint_align = ALIGN_LEFT
l.text = getter.replace("_", " ").capitalize()
t.pack(l, 0, i, 1, 1)
l.show()
w = Check(t)
w.size_hint_align = ALIGN_RIGHT
w.state = getattr(s, getter)
setter = getattr(handle, self.status_checks[getter])
w.callback_changed_add(lambda x: setter(x.state))
t.pack(w, 1, i, 1, 1)
w.show()
self.pack_end(t)
t.show()
t = Table(self, size_hint_align=FILL_HORIZ, homogeneous=True)
#Unit Spinners (int)
for i, (getter, setter) in enumerate(
self.handle_unit_spinners.items()
):
l = Label(t)
l.size_hint_align = ALIGN_LEFT
l.text = getter.replace("_", " ").capitalize()
t.pack(l, 0, i, 1, 1)
l.show()
w = UnitSpinner(self, "B/s", 1024, UnitSpinner.binary_prefixes)
w.size_hint_align = FILL_HORIZ
w.spinner.special_value_add(0, "disabled")
w.set_value(getattr(handle, getter)())
setter = getattr(handle, self.handle_unit_spinners[getter])
w.callback_changed_add(lambda x, y: setter(y))
t.pack(w, 1, i, 1, 1)
w.show()
self.pack_end(t)
t.show()
t = Table(self, size_hint_align=FILL_HORIZ, homogeneous=True)
#Spinners (int)
for i, (getter, setter) in enumerate(self.handle_spinners.items()):
l = Label(t)
l.size_hint_align = ALIGN_LEFT
l.text = getter.replace("_", " ").capitalize()
t.pack(l, 0, i, 1, 1)
l.show()
w = Spinner(t)
w.size_hint_align = FILL_HORIZ
w.min_max = -1.0, 16777215.0
w.special_value_add(-1.0, "disabled")
w.value = getattr(handle, getter)()
setter = getattr(handle, self.handle_spinners[getter])
w.callback_delay_changed_add(lambda x: setter(int(x.value)))
t.pack(w, 1, i, 1, 1)
w.show()
self.pack_end(t)
t.show()
class TorrentStatus(Table):
state_str = (
@ -416,14 +548,6 @@ class TorrentStatus(Table):
"upload_payload_rate"
)
check_enabled = (
"super_seeding"
)
check_enabled_prefixed = (
"sequential_download", "upload_mode", "share_mode"
)
timedelta_values = (
"active_time", "seeding_time", "time_since_download",
"time_since_upload", "finished_time"
@ -440,7 +564,9 @@ class TorrentStatus(Table):
self.widgets = []
for i, k in enumerate(dir(s)):
i = 0
for k in dir(s):
if k.startswith("__") or k in self.ignored_keys:
continue
try:
@ -465,14 +591,7 @@ class TorrentStatus(Table):
elif isinstance(v, bool):
w = Check(self)
w.size_hint_align = ALIGN_RIGHT
if k in self.check_enabled:
setter = getattr(h, k)
w.callback_changed_add(lambda x: setter(x.state))
elif k in self.check_enabled_prefixed:
setter = getattr(h, "set_" + k)
w.callback_changed_add(lambda x: setter(x.state))
else:
w.disabled = True
w.disabled = True
if not w:
try:
w = Label(self)
@ -494,6 +613,8 @@ class TorrentStatus(Table):
self.pack(w, 1, i, 1, 1)
w.show()
i += 1
def update():
s = h.status()
for w in self.widgets:
@ -501,7 +622,8 @@ class TorrentStatus(Table):
v = self.convert_value(key, getattr(s, key))
self.populate(w, v)
ecore.Timer(5.0, update)
timer = ecore.Timer(5.0, update)
self.on_del_add(lambda x: timer.delete())
@staticmethod
def populate(w, v):
@ -530,3 +652,9 @@ class TorrentStatus(Table):
v = intrepr(v) + "/s"
return v
class FsEntry(Fileselector, FileselectorEntry):
def __init__(self, parent, *args, **kwargs):
FileselectorEntry.__init__(self, parent, *args, **kwargs)

View File

@ -199,6 +199,9 @@ class TorrentSelector(StandardWindow):
s.size_hint_weight = EXPAND_HORIZ
s.size_hint_align = FILL_HORIZ
s.set_value(0)
s.callback_changed_add(
lambda x, y: self.add_dict.__setitem__(n, y)
)
s.spinner.label_format = n + ": %0.f"
opt_box.pack_end(s)
s.show()

View File

@ -37,6 +37,7 @@ class UnitSpinner(Box):
self.pack_end(s)
hs = self.hoversel = Hoversel(parent)
hs.hover_parent = parent.top_widget
for p in prefixes:
hs.item_add(p + unit)
hs.show()
@ -61,12 +62,14 @@ class UnitSpinner(Box):
def save_cb(self, func):
v = int(self.get_value())
func(v)
func(self, v)
self.save_timer = None
return False
def get_value(self):
p = self.hoversel.text[:-len(self.unit)]
return self.spinner.value * (
self.base ** self.prefixes.index(self.hoversel.text+self.unit)
self.base ** self.prefixes.index(p)
)
def set_value(self, v):