kuuko pushed a commit to branch master. http://git.enlightenment.org/apps/epour.git/commit/?id=2505aa214c516a2725e55470433f5b558d5d9609
commit 2505aa214c516a2725e55470433f5b558d5d9609 Author: Kai Huuhko <[email protected]> Date: Wed Jul 9 18:05:44 2014 +0300 Add some torrent settings and fix a couple of issues in UnitSpinner --- TODO | 16 ++-- epour/gui/Preferences.py | 2 +- epour/gui/TorrentProps.py | 176 +++++++++++++++++++++++++++++++++++++------ epour/gui/TorrentSelector.py | 3 + epour/gui/Widgets.py | 7 +- 5 files changed, 167 insertions(+), 37 deletions(-) diff --git a/TODO b/TODO index 6abd50f..37a55c2 100644 --- a/TODO +++ b/TODO @@ -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() diff --git a/epour/gui/Preferences.py b/epour/gui/Preferences.py index 6635ae1..81f8d9f 100644 --- a/epour/gui/Preferences.py +++ b/epour/gui/Preferences.py @@ -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() diff --git a/epour/gui/TorrentProps.py b/epour/gui/TorrentProps.py index f8e4755..e375a91 100644 --- a/epour/gui/TorrentProps.py +++ b/epour/gui/TorrentProps.py @@ -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) diff --git a/epour/gui/TorrentSelector.py b/epour/gui/TorrentSelector.py index ffa7b71..7ddf2a2 100644 --- a/epour/gui/TorrentSelector.py +++ b/epour/gui/TorrentSelector.py @@ -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() diff --git a/epour/gui/Widgets.py b/epour/gui/Widgets.py index 2ca5efe..6262558 100644 --- a/epour/gui/Widgets.py +++ b/epour/gui/Widgets.py @@ -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): --
