class FileSelectorInwin(Fileselector): def __init__(self, parent, title, done_cb, **kargs): self._user_cb = done_cb self._inwin = InnerWindow(parent) vbox = Box(self._inwin) self._inwin.content = vbox vbox.show() lb = Label(vbox, text='<b>%s</b>' % title) vbox.pack_end(lb) lb.show() Fileselector.__init__(self, vbox, expandable=False, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, **kargs) self.callback_done_add(self._fileselector_done_cb) self.callback_activated_add(self._fileselector_done_cb) # TODO this filter seems not to work well...need fixing # fs.mime_types_filter_append(list(EXTRACT_MAP.keys()), 'Archive files') # fs.mime_types_filter_append(['*'], 'All files') vbox.pack_end(self) self.show() self._inwin.activate() def delete(self): self._inwin.delete() def _fileselector_done_cb(self, fs, path): if path is not None: self._user_cb(path) self.delete()
def select_torrent(self): sel = Fileselector(self.win) sel.expandable = False sel.path_set(os.path.expanduser("~")) sel.size_hint_weight_set(1.0, 1.0) sel.size_hint_align_set(-1.0, -1.0) sel.show() sf = Frame(self.win) sf.size_hint_weight_set(1.0, 1.0) sf.size_hint_align_set(-1.0, -1.0) sf.text = "Select torrent file" sf.content = sel sf.show() magnet = Entry(self.win) magnet.single_line = True magnet.scrollable = True if hasattr(magnet, "cnp_selection_get"): magnet.cnp_selection_get(ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT) else: import pyperclip t = pyperclip.paste() if t is not None and t.startswith("magnet:"): magnet.entry = t magnet.show() mf = Frame(self.win) mf.size_hint_weight_set(1.0, 0.0) mf.size_hint_align_set(-1.0, 0.0) mf.text = "Or enter magnet URI here" mf.content = magnet mf.show() mbtn = Button(self.win) mbtn.text = "Done" mbtn.show() mbox = Box(self.win) mbox.size_hint_weight_set(1.0, 0.0) mbox.size_hint_align_set(-1.0, 0.0) mbox.horizontal = True mbox.pack_end(mf) mbox.pack_end(mbtn) mbox.show() box = Box(self.win) box.size_hint_weight = (1.0, 1.0) box.size_hint_align = (-1.0, -1.0) box.pack_end(sf) box.pack_end(mbox) box.show() inwin = InnerWindow(self.win) inwin.content = box sel.callback_done_add(self.add_torrent_cb) sel.callback_done_add(lambda x, y: inwin.delete()) mbtn.callback_clicked_add(self.add_magnet_uri_cb, magnet) mbtn.callback_clicked_add(lambda x: inwin.delete()) inwin.activate()
def select_torrent(self): sel = Fileselector(self.win) sel.expandable = False sel.path_set(os.path.expanduser("~")) sel.size_hint_weight_set(1.0, 1.0) sel.size_hint_align_set(-1.0, -1.0) sel.show() sf = Frame(self.win) sf.size_hint_weight_set(1.0, 1.0) sf.size_hint_align_set(-1.0, -1.0) sf.text = "Select torrent file" sf.content = sel sf.show() magnet = Entry(self.win) magnet.single_line = True magnet.scrollable = True if hasattr(magnet, "cnp_selection_get"): magnet.cnp_selection_get(ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT) else: import pyperclip t = pyperclip.paste() if t is not None and t.startswith("magnet:"): magnet.entry = t magnet.show() mf = Frame(self.win) mf.size_hint_weight_set(1.0, 0.0) mf.size_hint_align_set(-1.0, 0.0) mf.text = "Or enter magnet URI here" mf.content = magnet mf.show() mbtn = Button(self.win) mbtn.text = "Done" mbtn.show() mbox = Box(self.win) mbox.size_hint_weight_set(1.0, 0.0) mbox.size_hint_align_set(-1.0, 0.0) mbox.horizontal = True mbox.pack_end(mf) mbox.pack_end(mbtn) mbox.show() box = Box(self.win) box.size_hint_weight = (1.0, 1.0) box.size_hint_align = (-1.0, -1.0) box.pack_end(sf) box.pack_end(mbox) box.show() inwin = InnerWindow(self.win) inwin.content = box sel.callback_done_add(self.add_torrent_cb) sel.callback_done_add(lambda x, y: inwin.delete()) mbtn.callback_clicked_add(self.add_magnet_uri_cb, magnet) mbtn.callback_clicked_add(lambda x: inwin.delete()) inwin.activate()
class FileSelectorInwin(Fileselector): def __init__(self, parent, title, done_cb, **kargs): self._user_cb = done_cb self._inwin = InnerWindow(parent) vbox = Box(self._inwin) self._inwin.content = vbox vbox.show() lb = Label(vbox, text='<b>%s</b>' % title) vbox.pack_end(lb) lb.show() Fileselector.__init__(self, vbox, expandable=False, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, **kargs) self.callback_done_add(self._fileselector_done_cb) self.callback_activated_add(self._fileselector_done_cb) # TODO this filter seems not to work well...need fixing # fs.mime_types_filter_append(list(EXTRACT_MAP.keys()), 'Archive files') # fs.mime_types_filter_append(['*'], 'All files') vbox.pack_end(self) self.show() self._inwin.activate() def delete(self): self._inwin.delete() def _fileselector_done_cb(self, fs, path): if path is not None: self._user_cb(path) self.delete()