コード例 #1
0
    def _enter_dir(self):
        #Enter currently selected directory
        dirname = self.raw_rows[self.cursel][0]
        new_dir = self.path_stack_pos >= len(self.path_stack)
        new_dir = new_dir or (dirname != self.path_stack[self.path_stack_pos])
        if new_dir:
            self.path_stack = self.path_stack[:self.path_stack_pos]
            self.path_stack.append(dirname)

        path = os.path.join(*self.path_stack[:self.path_stack_pos + 1])

        if not os.access(path, os.R_OK):
            self.path_stack = self.path_stack[:self.path_stack_pos]
            self.popup = MessagePopup(self, "Error",
                                      "{!error!}Access denied: %s" % path)
            self.__refresh_listing()
            return

        self.path_stack_pos += 1

        self.view_offset = 0
        self.cursel = 0
        self.last_mark = -1
        self.marked = set()

        self.__refresh_listing()
コード例 #2
0
ファイル: torrentdetail.py プロジェクト: Aniverse/deluge-1
    def refresh(self, lines=None):
        # show a message popup if there's anything queued
        if self.popup == None and self.messages:
            title, msg = self.messages.popleft()
            self.popup = MessagePopup(self, title, msg)

        # Update the status bars
        self.stdscr.erase()
        self.add_string(0, self.statusbars.topbar)

        #This will quite likely fail when switching modes
        try:
            rf = format_utils.remove_formatting
            string = self.statusbars.bottombar
            hstr = "Press {!magenta,blue,bold!}[h]{!status!} for help"

            string += " " * (self.cols - len(rf(string)) -
                             len(rf(hstr))) + hstr

            self.add_string(self.rows - 1, string)
        except:
            pass

        off = 1
        if self.torrent_state:
            off = self.render_header(off)
        else:
            self.add_string(1, "Waiting for torrent state")

        off += 1

        if self.files_sep:
            self.add_string(off, self.files_sep)
            off += 1

        self._listing_start = off
        self._listing_space = self.rows - self._listing_start

        self.add_string(off, self.column_string)
        if self.file_list:
            off += 1
            self.more_to_draw = False
            self.draw_files(self.file_list, 0, off, 0)

        if component.get("ConsoleUI").screen != self:
            return

        self.stdscr.noutrefresh()

        if self.popup:
            self.popup.refresh()

        curses.doupdate()
コード例 #3
0
ファイル: torrentdetail.py プロジェクト: cheuschober/deluge
    def refresh(self, lines=None):
        # show a message popup if there's anything queued
        if self.popup == None and self.messages:
            title, msg = self.messages.popleft()
            self.popup = MessagePopup(self, title, msg)

        # Update the status bars
        self.stdscr.clear()
        self.add_string(0, self.statusbars.topbar)
        hstr = "%sPress [h] for help" % (
            " " * (self.cols - len(self.statusbars.bottombar) - 10))
        self.add_string(self.rows - 1,
                        "%s%s" % (self.statusbars.bottombar, hstr))

        if self.files_sep:
            self.add_string((self.rows / 2) - 1, self.files_sep)

        off = 1
        if self.torrent_state:
            for f in self._info_fields:
                if off >= (self.rows / 2): break
                if f[1] != None:
                    args = []
                    try:
                        for key in f[2]:
                            args.append(self.torrent_state[key])
                    except:
                        log.debug("Could not get info field: %s", e)
                        continue
                    info = f[1](*args)
                else:
                    info = self.torrent_state[f[2][0]]

                self.add_string(off, "{!info!}%s: {!input!}%s" % (f[0], info))
                off += 1
        else:
            self.add_string(1, "Waiting for torrent state")

        off = self.rows / 2
        self.add_string(off, self.column_string)
        if self.file_list:
            off += 1
            self.more_to_draw = False
            self.draw_files(self.file_list, 0, off, 0)

        #self.stdscr.redrawwin()
        self.stdscr.noutrefresh()

        if self.popup:
            self.popup.refresh()

        curses.doupdate()
コード例 #4
0
ファイル: torrentdetail.py プロジェクト: Aniverse/deluge-1
    def _show_rename_popup(self):
        #Perhaps in the future: Renaming multiple files
        if self.marked:
            title = "Error (Enter to close)"
            text = "Sorry, you can't rename multiple files, please clear selection with {!info!}'c'{!normal!} key"
            self.popup = MessagePopup(self, title, text)
        else:
            _file = self.__get_file_by_num(self.current_file_idx,
                                           self.file_list)
            old_filename = _file[0]

            idx = self._selection_to_file_idx()
            tid = self.torrentid

            if _file[3]:

                def do_rename(result):
                    if not result["new_foldername"]:
                        return
                    old_fname = self._get_full_folder_path(
                        self.current_file_idx)
                    new_fname = "%s/%s/" % (old_fname.strip("/").rpartition(
                        "/")[0], result["new_foldername"])
                    self._do_rename_folder(tid, old_fname, new_fname)

                popup = InputPopup(self,
                                   "Rename folder (Esc to cancel)",
                                   close_cb=do_rename)
                popup.add_text("{!info!}Renaming folder:{!input!}")
                popup.add_text(" * %s\n" % old_filename)
                popup.add_text_input("Enter new folder name:",
                                     "new_foldername", old_filename.strip("/"))

                self.popup = popup
            else:

                def do_rename(result):
                    fname = "%s/%s" % (self.full_names[idx].rpartition("/")[0],
                                       result["new_filename"])
                    self._do_rename_file(tid, idx, fname)

                popup = InputPopup(self,
                                   "Rename file (Esc to cancel)",
                                   close_cb=do_rename)
                popup.add_text("{!info!}Renaming file:{!input!}")
                popup.add_text(" * %s\n" % old_filename)
                popup.add_text_input("Enter new filename:", "new_filename",
                                     old_filename)

                self.popup = popup
コード例 #5
0
    def refresh(self):
        self.stdscr.erase()
        self.draw_statusbars()
        self.stdscr.noutrefresh()

        if self.popup == None and self.messages:
            title, msg = self.messages.popleft()
            self.popup = MessagePopup(self, title, msg)

        if not self.popup:
            self.__update_popup()

        self.popup.refresh()
        curses.doupdate()
コード例 #6
0
ファイル: torrentdetail.py プロジェクト: Aniverse/deluge-1
    def _doRead(self):
        c = self.stdscr.getch()

        if self.popup:
            if self.popup.handle_read(c):
                self.popup = None
            self.refresh()
            return

        if c > 31 and c < 256:
            if chr(c) == 'Q':
                from twisted.internet import reactor
                if client.connected():

                    def on_disconnect(result):
                        reactor.stop()

                    client.disconnect().addCallback(on_disconnect)
                else:
                    reactor.stop()
                return
            elif chr(c) == 'q':
                self.back_to_overview()
                return

        if c == 27 or c == curses.KEY_LEFT:
            self.back_to_overview()
            return

        if not self.torrent_state:
            # actions below only make sense if there is a torrent state
            return

        # Navigate the torrent list
        if c == curses.KEY_UP:
            self.file_list_up()
        elif c == curses.KEY_PPAGE:
            self.file_list_up(self._listing_space - 2)
        elif c == curses.KEY_HOME:
            self.file_off = 0
            self.current_file_idx = 0
        elif c == curses.KEY_DOWN:
            self.file_list_down()
        elif c == curses.KEY_NPAGE:
            self.file_list_down(self._listing_space - 2)
        elif c == curses.KEY_END:
            self.current_file_idx = self.__get_file_list_length() - 1
            self.file_off = self.current_file_idx - (self._listing_space - 3)
        elif c == curses.KEY_DC:
            torrent_actions_popup(self, [self.torrentid], action=ACTION.REMOVE)
        # Enter Key
        elif c == curses.KEY_ENTER or c == 10:
            was_empty = (self.marked == {})
            self.__mark_tree(self.file_list, self.current_file[1])
            self.show_priority_popup(was_empty)

        # space
        elif c == 32:
            self.expcol_cur_file()
        else:
            if c > 31 and c < 256:
                if chr(c) == 'm':
                    if self.current_file:
                        self.__mark_unmark(self.current_file[1])
                elif chr(c) == 'r':
                    self._show_rename_popup()
                elif chr(c) == 'c':
                    self.marked = {}
                elif chr(c) == 'a':
                    torrent_actions_popup(self, [self.torrentid],
                                          details=False)
                    return
                elif chr(c) == 'o':
                    torrent_actions_popup(self, [self.torrentid],
                                          action=ACTION.TORRENT_OPTIONS)
                    return
                elif chr(c) == 'h':
                    self.popup = MessagePopup(self,
                                              "Help",
                                              HELP_STR,
                                              width_req=0.75)
                elif chr(c) == 'j':
                    self.file_list_up()
                if chr(c) == 'k':
                    self.file_list_down()

        self.refresh()
コード例 #7
0
ファイル: alltorrents.py プロジェクト: cheuschober/deluge
    def refresh(self,lines=None):
        #log.error("ref")
        #import traceback
        #traceback.print_stack()
        # Something has requested we scroll to the top of the list
        if self._go_top:
            self.cursel = 1
            self.curoff = 1
            self._go_top = False

        # show a message popup if there's anything queued
        if self.popup == None and self.messages:
            title,msg = self.messages.popleft()
            self.popup = MessagePopup(self,title,msg)

        if not lines:
            self.stdscr.clear()

        # Update the status bars
        if self._curr_filter == None:
            self.add_string(0,self.statusbars.topbar)
        else:
            self.add_string(0,"%s    {!filterstatus!}Current filter: %s"%(self.statusbars.topbar,self._curr_filter))
        self.add_string(1,self.column_string)

        if self.entering_search:
            self.add_string(self.rows - 1,"{!black,white!}Search torrents: %s"%self.search_string)
        else:
            hstr =  "%sPress [h] for help"%(" "*(self.cols - len(self.statusbars.bottombar) - 10))
            self.add_string(self.rows - 1, "%s%s"%(self.statusbars.bottombar,hstr))

        # add all the torrents
        if self.formatted_rows == []:
            msg = "No torrents match filter".center(self.cols)
            self.add_string(3, "{!info!}%s"%msg)
        elif self.formatted_rows:
            tidx = self.curoff
            currow = 2

            if lines:
                todraw = []
                for l in lines:
                    todraw.append(self.formatted_rows[l])
                lines.reverse()
            else:
                todraw = self.formatted_rows[tidx-1:]

            for row in todraw:
                # default style
                fg = "white"
                bg = "black"
                attr = None
                if lines:
                    tidx = lines.pop()+1
                    currow = tidx-self.curoff+2

                if tidx in self.marked:
                    bg = "blue"
                    attr = "bold"

                if tidx == self.cursel:
                    bg = "white"
                    attr = "bold"
                    if tidx in self.marked:
                        fg = "blue"
                    else:
                        fg = "black"

                if row[1] == "Downloading":
                    fg = "green"
                elif row[1] == "Seeding":
                    fg = "cyan"
                elif row[1] == "Error":              
                    fg = "red"
                elif row[1] == "Queued":
                    fg = "yellow"
                elif row[1] == "Checking":
                    fg = "blue"
                    
                if attr:
                    colorstr = "{!%s,%s,%s!}"%(fg,bg,attr)
                else:
                    colorstr = "{!%s,%s!}"%(fg,bg)

                self.add_string(currow,"%s%s"%(colorstr,row[0]),trim=False)
                tidx += 1
                currow += 1 
                if (currow > (self.rows - 2)):
                    break
        else:
            self.add_string(1, "Waiting for torrents from core...")

        #self.stdscr.redrawwin()
        if self.entering_search:
            curses.curs_set(2)
            self.stdscr.move(self.rows-1,self.cursor+17)
        else:
            curses.curs_set(0)

        self.stdscr.noutrefresh()

        if self.popup:
            self.popup.refresh()

        curses.doupdate()
コード例 #8
0
    def _doRead(self):
        c = self.stdscr.getch()

        if self.popup:
            if self.popup.handle_read(c):
                self.popup = None
            self.refresh()
            return

        if c > 31 and c < 256:
            if chr(c) == 'Q':
                from twisted.internet import reactor
                if client.connected():

                    def on_disconnect(result):
                        reactor.stop()

                    client.disconnect().addCallback(on_disconnect)
                else:
                    reactor.stop()
                return
            elif chr(c) == 'q':
                self.back_to_overview()
                return

        # Navigate the torrent list
        if c == curses.KEY_UP:
            self.scroll_list_up(1)
        elif c == curses.KEY_PPAGE:
            #self.scroll_list_up(self._listing_space-2)
            self.scroll_list_up(self.rows // 2)
        elif c == curses.KEY_HOME:
            self.scroll_list_up(len(self.formatted_rows))
        elif c == curses.KEY_DOWN:
            self.scroll_list_down(1)
        elif c == curses.KEY_NPAGE:
            #self.scroll_list_down(self._listing_space-2)
            self.scroll_list_down(self.rows // 2)
        elif c == curses.KEY_END:
            self.scroll_list_down(len(self.formatted_rows))
        elif c == curses.KEY_RIGHT:
            if self.cursel < len(self.listing_dirs):
                self._enter_dir()
        elif c == curses.KEY_LEFT:
            self._go_up()
        # Enter Key
        elif c == curses.KEY_ENTER or c == 10:
            self._perform_action()
        #Escape
        elif c == 27:
            self.back_to_overview()
        else:
            if c > 31 and c < 256:
                if chr(c) == 'h':
                    self.popup = MessagePopup(self,
                                              "Help",
                                              HELP_STR,
                                              width_req=0.75)
                elif chr(c) == '>':
                    if self.sort_column == "date":
                        self.reverse_sort = not self.reverse_sort
                    else:
                        self.sort_column = "date"
                        self.reverse_sort = True
                    self.__sort_rows()
                elif chr(c) == '<':
                    if self.sort_column == "name":
                        self.reverse_sort = not self.reverse_sort
                    else:
                        self.sort_column = "name"
                        self.reverse_sort = False
                    self.__sort_rows()
                elif chr(c) == 'm':
                    s = self.raw_rows[self.cursel][0]
                    if s in self.marked:
                        self.marked.remove(s)
                    else:
                        self.marked.add(s)

                    self.last_mark = self.cursel
                elif chr(c) == 'j':
                    self.scroll_list_up(1)
                elif chr(c) == 'k':
                    self.scroll_list_down(1)
                elif chr(c) == 'M':
                    if self.last_mark != -1:
                        if self.last_mark > self.cursel:
                            m = range(self.cursel, self.last_mark)
                        else:
                            m = range(self.last_mark, self.cursel + 1)

                        for i in m:
                            s = self.raw_rows[i][0]
                            self.marked.add(s)
                elif chr(c) == 'c':
                    self.marked.clear()

        self.refresh()