def __init__(self, stdscr, encoding=None): self.formatted_rows = None self.torrent_names = None self.cursel = 1 self.curoff = 1 # TODO: this should really be 0 indexed self.column_string = "" self.popup = None self.messages = deque() self.marked = [] self.last_mark = -1 self._sorted_ids = None self._go_top = False self._curr_filter = None self.entering_search = False self.search_string = None self.cursor = 0 self.coreconfig = component.get("ConsoleUI").coreconfig self.legacy_mode = None self.__status_dict = {} self.__torrent_info_id = None BaseMode.__init__(self, stdscr, encoding) component.Component.__init__(self, "AllTorrents", 1, depend=["SessionProxy"]) curses.curs_set(0) self.stdscr.notimeout(0) self.__split_help() self.update_config() component.start(["AllTorrents"]) self._info_fields = [ ("Name",None,("name",)), ("State", None, ("state",)), ("Down Speed", format_utils.format_speed, ("download_payload_rate",)), ("Up Speed", format_utils.format_speed, ("upload_payload_rate",)), ("Progress", format_utils.format_progress, ("progress",)), ("ETA", deluge.common.ftime, ("eta",)), ("Path", None, ("save_path",)), ("Downloaded",deluge.common.fsize,("all_time_download",)), ("Uploaded", deluge.common.fsize,("total_uploaded",)), ("Share Ratio", format_utils.format_float, ("ratio",)), ("Seeders",format_utils.format_seeds_peers,("num_seeds","total_seeds")), ("Peers",format_utils.format_seeds_peers,("num_peers","total_peers")), ("Active Time",deluge.common.ftime,("active_time",)), ("Seeding Time",deluge.common.ftime,("seeding_time",)), ("Date Added",deluge.common.fdate,("time_added",)), ("Availability", format_utils.format_float, ("distributed_copies",)), ("Pieces", format_utils.format_pieces, ("num_pieces","piece_length")), ] self.__status_keys = ["name","state","download_payload_rate","upload_payload_rate", "progress","eta","all_time_download","total_uploaded", "ratio", "num_seeds","total_seeds","num_peers","total_peers", "active_time", "seeding_time","time_added","distributed_copies", "num_pieces", "piece_length","save_path"]
def __init__(self, stdscr, encoding=None): self.formatted_rows = None self.torrent_names = None self.cursel = 1 self.curoff = 1 # TODO: this should really be 0 indexed self.column_string = "" self.popup = None self.messages = deque() self.marked = [] self.last_mark = -1 self._sorted_ids = None self._go_top = False self._curr_filter = None self.entering_search = False self.search_string = None self.cursor = 0 self.coreconfig = component.get("ConsoleUI").coreconfig self.legacy_mode = None self.__status_dict = {} self.__torrent_info_id = None BaseMode.__init__(self, stdscr, encoding) component.Component.__init__(self, "AllTorrents", 1, depend=["SessionProxy"]) curses.curs_set(0) self.stdscr.notimeout(0) self.__split_help() self.update_config() component.start(["AllTorrents"]) self._info_fields = [ ("Name",None,("name",)), ("State", None, ("state",)), ("Down Speed", format_utils.format_speed, ("download_payload_rate",)), ("Up Speed", format_utils.format_speed, ("upload_payload_rate",)), ("Progress", format_utils.format_progress, ("progress",)), ("ETA", deluge.common.ftime, ("eta",)), ("Path", None, ("save_path",)), ("Downloaded",deluge.common.fsize,("all_time_download",)), ("Uploaded", deluge.common.fsize,("total_uploaded",)), ("Share Ratio", format_utils.format_float, ("ratio",)), ("Seeders",format_utils.format_seeds_peers,("num_seeds","total_seeds")), ("Peers",format_utils.format_seeds_peers,("num_peers","total_peers")), ("Active Time",deluge.common.ftime,("active_time",)), ("Seeding Time",deluge.common.ftime,("seeding_time",)), ("Date Added",deluge.common.fdate,("time_added",)), ("Availability", format_utils.format_float, ("distributed_copies",)), ("Pieces", format_utils.format_pieces, ("num_pieces","piece_length")), ] self.__status_keys = ["name","state","download_payload_rate","upload_payload_rate", "progress","eta","all_time_download","total_uploaded", "ratio", "num_seeds","total_seeds","num_peers","total_peers", "active_time", "seeding_time","time_added","distributed_copies", "num_pieces", "piece_length","save_path"]
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) self.__update_columns() self.__split_help() if self.popup: self.popup.handle_resize() self.refresh()
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) self.__update_columns() self.__split_help() if self.popup: self.popup.handle_resize() self.refresh()
def __init__(self, alltorrentmode, torrentid, stdscr, console_config, encoding=None): self.console_config = console_config self.alltorrentmode = alltorrentmode self.torrentid = torrentid self.torrent_state = None self.popup = None self.messages = deque() self._status_keys = [ "files", "name", "state", "download_payload_rate", "upload_payload_rate", "progress", "eta", "all_time_download", "total_uploaded", "ratio", "num_seeds", "total_seeds", "num_peers", "total_peers", "active_time", "seeding_time", "time_added", "distributed_copies", "num_pieces", "piece_length", "save_path", "file_progress", "file_priorities", "message", "total_wanted", "tracker_host", "owner" ] self.file_list = None self.current_file = None self.current_file_idx = 0 self.file_limit = maxint self.file_off = 0 self.more_to_draw = False self.full_names = None self.column_string = "" self.files_sep = None self.marked = {} BaseMode.__init__(self, stdscr, encoding) component.Component.__init__(self, "TorrentDetail", 1, depend=["SessionProxy"]) self.column_names = ["Filename", "Size", "Progress", "Priority"] self.__update_columns() component.start(["TorrentDetail"]) self._listing_start = self.rows // 2 self._listing_space = self._listing_start - self._listing_start client.register_event_handler("TorrentFileRenamedEvent", self._on_torrentfilerenamed_event) client.register_event_handler("TorrentFolderRenamedEvent", self._on_torrentfolderrenamed_event) client.register_event_handler("TorrentRemovedEvent", self._on_torrentremoved_event) curses.curs_set(0) self.stdscr.notimeout(0)
def __init__(self, stdscr, encoding=None): self.popup = None self.statuses = {} self.messages = deque() self.config = ConfigManager("hostlist.conf.1.2", DEFAULT_CONFIG) BaseMode.__init__(self, stdscr, encoding) self.__update_statuses() self.__update_popup()
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) if self.popup: self.popup.handle_resize() self.stdscr.erase() self.refresh()
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) #Always refresh Legacy(it will also refresh AllTorrents), otherwise it will bug deluge out legacy = component.get("LegacyUI") legacy.on_resize(*args) self.stdscr.erase() self.refresh()
def __init__(self, stdscr, encoding=None): self.popup = None self.statuses = {} self.messages = deque() self.config = ConfigManager("hostlist.conf.1.2", DEFAULT_CONFIG) BaseMode.__init__(self, stdscr, encoding) self.__update_statuses() self.__update_popup()
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) if self.popup: self.popup.handle_resize() self.stdscr.erase() self.refresh()
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) #We need to also refresh AllTorrents because otherwise it will # be only us that get properly resized all_torrents = component.get("AllTorrents") all_torrents.on_resize(*args) self.stdscr.erase() self.refresh()
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) #We need to also refresh AllTorrents because otherwise it will # be only us that get properly resized all_torrents = component.get("AllTorrents") all_torrents.on_resize(*args) self.stdscr.erase() self.refresh()
def __init__(self, parent_mode, core_config, console_config, active_port, status, stdscr, encoding=None): self.parent_mode = parent_mode self.categories = [ _("Downloads"), _("Network"), _("Bandwidth"), _("Interface"), _("Other"), _("Daemon"), _("Queue"), _("Proxy"), _("Cache") ] # , _("Plugins")] self.cur_cat = 0 self.popup = None self.messages = deque() self.action_input = None self.core_config = core_config self.console_config = console_config self.active_port = active_port self.status = status self.active_zone = ZONE.CATEGORIES # how wide is the left 'pane' with categories self.div_off = 15 BaseMode.__init__(self, stdscr, encoding, False) # create the panes self.prefs_width = self.cols - self.div_off - 1 self.prefs_height = self.rows - 4 self.panes = [ DownloadsPane(self.div_off + 2, self, self.prefs_width), NetworkPane(self.div_off + 2, self, self.prefs_width), BandwidthPane(self.div_off + 2, self, self.prefs_width), InterfacePane(self.div_off + 2, self, self.prefs_width), OtherPane(self.div_off + 2, self, self.prefs_width), DaemonPane(self.div_off + 2, self, self.prefs_width), QueuePane(self.div_off + 2, self, self.prefs_width), ProxyPane(self.div_off + 2, self, self.prefs_width), CachePane(self.div_off + 2, self, self.prefs_width) ] self.action_input = SelectInput(self, None, None, ["Cancel", "Apply", "OK"], [0, 1, 2], 0) self.refresh()
def __init__(self, alltorrentmode, torrentid, stdscr, encoding=None): self.alltorrentmode = alltorrentmode self.torrentid = torrentid self.torrent_state = None self.popup = None self.messages = deque() self._status_keys = ["files", "name","state","download_payload_rate","upload_payload_rate", "progress","eta","all_time_download","total_uploaded", "ratio", "num_seeds","total_seeds","num_peers","total_peers", "active_time", "seeding_time","time_added","distributed_copies", "num_pieces", "piece_length","save_path","file_progress","file_priorities","message"] self._info_fields = [ ("Name",None,("name",)), ("State", None, ("state",)), ("Status",None,("message",)), ("Down Speed", format_utils.format_speed, ("download_payload_rate",)), ("Up Speed", format_utils.format_speed, ("upload_payload_rate",)), ("Progress", format_utils.format_progress, ("progress",)), ("ETA", deluge.common.ftime, ("eta",)), ("Path", None, ("save_path",)), ("Downloaded",deluge.common.fsize,("all_time_download",)), ("Uploaded", deluge.common.fsize,("total_uploaded",)), ("Share Ratio", lambda x:x < 0 and "∞" or "%.3f"%x, ("ratio",)), ("Seeders",format_utils.format_seeds_peers,("num_seeds","total_seeds")), ("Peers",format_utils.format_seeds_peers,("num_peers","total_peers")), ("Active Time",deluge.common.ftime,("active_time",)), ("Seeding Time",deluge.common.ftime,("seeding_time",)), ("Date Added",deluge.common.fdate,("time_added",)), ("Availability", lambda x:x < 0 and "∞" or "%.3f"%x, ("distributed_copies",)), ("Pieces", format_utils.format_pieces, ("num_pieces","piece_length")), ] self.file_list = None self.current_file = None self.current_file_idx = 0 self.file_limit = maxint self.file_off = 0 self.more_to_draw = False self.column_string = "" self.files_sep = None self.marked = {} BaseMode.__init__(self, stdscr, encoding) component.Component.__init__(self, "TorrentDetail", 1, depend=["SessionProxy"]) self.__split_help() self.column_names = ["Filename", "Size", "Progress", "Priority"] self.__update_columns() component.start(["TorrentDetail"]) curses.curs_set(0) self.stdscr.notimeout(0)
def __init__(self, stdscr, encoding=None): self.batch_write = False self.lines = [] # A list of strings to be displayed based on the offset (scroll) self.lines = [] # The offset to display lines self.display_lines_offset = 0 # Holds the user input and is cleared on 'enter' self.input = "" self.input_incomplete = "" # Keep track of where the cursor is self.input_cursor = 0 # Keep a history of inputs self.input_history = [] self.input_history_index = 0 # Keep track of double-tabs self.tab_count = 0 # Get a handle to the main console self.console = component.get("ConsoleUI") # show the cursor curses.curs_set(2) BaseMode.__init__(self, stdscr, encoding) # This gets fired once we have received the torrents list from the core self.started_deferred = defer.Deferred() # Maintain a list of (torrent_id, name) for use in tab completion self.torrents = [] def on_session_state(result): def on_torrents_status(torrents): for torrent_id, status in torrents.items(): self.torrents.append((torrent_id, status["name"])) self.started_deferred.callback(True) client.core.get_torrents_status({ "id": result }, ["name"]).addCallback(on_torrents_status) client.core.get_session_state().addCallback(on_session_state) # Register some event handlers to keep the torrent list up-to-date client.register_event_handler("TorrentAddedEvent", self.on_torrent_added_event) client.register_event_handler("TorrentRemovedEvent", self.on_torrent_removed_event)
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) #Always refresh Legacy(it will also refresh AllTorrents), otherwise it will bug deluge out legacy = component.get("LegacyUI") legacy.on_resize(*args) self.__update_columns() if self.popup: self.popup.handle_resize() self._listing_start = self.rows / 2 self.refresh()
def on_resize(self, *args): BaseMode.on_resize_norefresh(self, *args) #Always refresh Legacy(it will also refresh AllTorrents), otherwise it will bug deluge out legacy = component.get("LegacyUI") legacy.on_resize(*args) self.__update_columns() if self.popup: self.popup.handle_resize() self._listing_start = self.rows / 2 self.refresh()
def __init__(self, stdscr, encoding=None): self.batch_write = False self.lines = [] # A list of strings to be displayed based on the offset (scroll) self.lines = [] # The offset to display lines self.display_lines_offset = 0 # Holds the user input and is cleared on 'enter' self.input = "" self.input_incomplete = "" # Keep track of where the cursor is self.input_cursor = 0 # Keep a history of inputs self.input_history = [] self.input_history_index = 0 # Keep track of double-tabs self.tab_count = 0 # Get a handle to the main console self.console = component.get("ConsoleUI") # show the cursor curses.curs_set(2) BaseMode.__init__(self, stdscr, encoding) # This gets fired once we have received the torrents list from the core self.started_deferred = defer.Deferred() # Maintain a list of (torrent_id, name) for use in tab completion self.torrents = [] def on_session_state(result): def on_torrents_status(torrents): for torrent_id, status in torrents.items(): self.torrents.append((torrent_id, status["name"])) self.started_deferred.callback(True) client.core.get_torrents_status({"id": result}, ["name"]).addCallback(on_torrents_status) client.core.get_session_state().addCallback(on_session_state) # Register some event handlers to keep the torrent list up-to-date client.register_event_handler("TorrentAddedEvent", self.on_torrent_added_event) client.register_event_handler("TorrentRemovedEvent", self.on_torrent_removed_event)
def __init__(self, alltorrentmode, torrentid, stdscr, console_config, encoding=None): self.console_config = console_config self.alltorrentmode = alltorrentmode self.torrentid = torrentid self.torrent_state = None self.popup = None self.messages = deque() self._status_keys = ["files", "name","state","download_payload_rate","upload_payload_rate", "progress","eta","all_time_download","total_uploaded", "ratio", "num_seeds","total_seeds","num_peers","total_peers", "active_time", "seeding_time","time_added","distributed_copies", "num_pieces", "piece_length","save_path","file_progress","file_priorities","message", "total_wanted", "tracker_host", "owner"] self.file_list = None self.current_file = None self.current_file_idx = 0 self.file_limit = maxint self.file_off = 0 self.more_to_draw = False self.full_names = None self.column_string = "" self.files_sep = None self.marked = {} BaseMode.__init__(self, stdscr, encoding) component.Component.__init__(self, "TorrentDetail", 1, depend=["SessionProxy"]) self.column_names = ["Filename", "Size", "Progress", "Priority"] self.__update_columns() component.start(["TorrentDetail"]) self._listing_start = self.rows // 2 self._listing_space = self._listing_start - self._listing_start client.register_event_handler("TorrentFileRenamedEvent", self._on_torrentfilerenamed_event) client.register_event_handler("TorrentFolderRenamedEvent", self._on_torrentfolderrenamed_event) client.register_event_handler("TorrentRemovedEvent", self._on_torrentremoved_event) curses.curs_set(0) self.stdscr.notimeout(0)
def __init__(self, alltorrentmode, stdscr, console_config, encoding=None): self.console_config = console_config self.alltorrentmode = alltorrentmode self.popup = None self.view_offset = 0 self.cursel = 0 self.marked = set() self.last_mark = -1 path = os.path.expanduser(self.console_config["addtorrents_last_path"]) self.path_stack = ["/"] + path.strip("/").split("/") self.path_stack_pos = len(self.path_stack) self.listing_files = [] self.listing_dirs = [] self.raw_rows = [] self.raw_rows_files = [] self.raw_rows_dirs = [] self.formatted_rows = [] self.sort_column = self.console_config["addtorrents_sort_column"] self.reverse_sort = self.console_config["addtorrents_reverse_sort"] BaseMode.__init__(self, stdscr, encoding) self._listing_space = self.rows - 5 self.__refresh_listing() component.Component.__init__(self, "AddTorrents", 1, depend=["SessionProxy"]) component.start(["AddTorrents"]) curses.curs_set(0) self.stdscr.notimeout(0)
def __init__(self, alltorrentmode, stdscr, console_config, encoding=None): self.console_config = console_config self.alltorrentmode = alltorrentmode self.popup = None self.view_offset = 0 self.cursel = 0 self.marked = set() self.last_mark = -1 path = os.path.expanduser(self.console_config["addtorrents_last_path"]) self.path_stack = ["/"] + path.strip("/").split("/") self.path_stack_pos = len(self.path_stack) self.listing_files = [] self.listing_dirs = [] self.raw_rows = [] self.raw_rows_files = [] self.raw_rows_dirs = [] self.formatted_rows = [] self.sort_column = self.console_config["addtorrents_sort_column"] self.reverse_sort = self.console_config["addtorrents_reverse_sort"] BaseMode.__init__(self, stdscr, encoding) self._listing_space = self.rows - 5 self.__refresh_listing() component.Component.__init__(self, "AddTorrents", 1, depend=["SessionProxy"]) component.start(["AddTorrents"]) curses.curs_set(0) self.stdscr.notimeout(0)
def __init__(self, parent_mode, core_config, console_config, active_port, status, stdscr, encoding=None): self.parent_mode = parent_mode self.categories = [_("Downloads"), _("Network"), _("Bandwidth"), _("Interface"), _("Other"), _("Daemon"), _("Queue"), _("Proxy"), _("Cache")] # , _("Plugins")] self.cur_cat = 0 self.popup = None self.messages = deque() self.action_input = None self.core_config = core_config self.console_config = console_config self.active_port = active_port self.status = status self.active_zone = ZONE.CATEGORIES # how wide is the left 'pane' with categories self.div_off = 15 BaseMode.__init__(self, stdscr, encoding, False) # create the panes self.prefs_width = self.cols-self.div_off-1 self.prefs_height = self.rows-4 self.panes = [ DownloadsPane(self.div_off+2, self, self.prefs_width), NetworkPane(self.div_off+2, self, self.prefs_width), BandwidthPane(self.div_off+2, self, self.prefs_width), InterfacePane(self.div_off+2, self, self.prefs_width), OtherPane(self.div_off+2, self, self.prefs_width), DaemonPane(self.div_off+2, self, self.prefs_width), QueuePane(self.div_off+2, self, self.prefs_width), ProxyPane(self.div_off+2, self, self.prefs_width), CachePane(self.div_off+2, self, self.prefs_width) ] self.action_input = SelectInput(self,None,None,["Cancel","Apply","OK"],[0,1,2],0) self.refresh()
def __init__(self, parent_mode, stdscr, encoding=None): self.parent_mode = parent_mode BaseMode.__init__(self, stdscr, encoding)
def __init__(self, stdscr, encoding=None): component.Component.__init__(self, "LegacyUI", 1, depend=["SessionProxy"]) self.batch_write = False # A list of strings to be displayed based on the offset (scroll) self.lines = [] # The offset to display lines self.display_lines_offset = 0 # Holds the user input and is cleared on 'enter' self.input = "" self.input_incomplete = "" self._old_char = 0 self._last_char = 0 self._last_del_char = '' # Keep track of where the cursor is self.input_cursor = 0 # Keep a history of inputs self.input_history = [] self.input_history_index = 0 # Keep track of double- and multi-tabs self.tab_count = 0 # Get a handle to the main console self.console = component.get("ConsoleUI") self.console_config = component.get("AllTorrents").config #To avoid having to truncate the file every time we're writing # or doing it on exit(and therefore relying on an error-less # or in other words clean exit, we're going to have two files # that we swap around based on length config_dir = deluge.configmanager.get_config_dir() self.history_file = [ os.path.join(config_dir, "legacy.hist1"), os.path.join(config_dir, "legacy.hist2") ] self._hf_lines = [0, 0] if self.console_config["save_legacy_history"]: try: lines1 = open(self.history_file[0], 'r').read().splitlines() self._hf_lines[0] = len(lines1) except: lines1 = [] self._hf_lines[0] = 0 try: lines2 = open(self.history_file[1], 'r').read().splitlines() self._hf_lines[1] = len(lines2) except: lines2 = [] self._hf_lines[1] = 0 #The non-full file is the active one if self._hf_lines[0] > self._hf_lines[1]: self.lines = lines1 + lines2 else: self.lines = lines2 + lines1 if len(self.lines) > MAX_HISTFILE_SIZE: self.lines = self.lines[-MAX_HISTFILE_SIZE:] #Instead of having additional input history file, we can # simply scan for lines beginning with ">>> " for i, line in enumerate(self.lines): #if not isinstance(line, unicode): #line = line.encode(self.encoding) #self.lines[i] = line line = format_utils.remove_formatting(line) if line.startswith(">>> "): input = line[4:] if self.console_config["ignore_duplicate_lines"]: if len(self.input_history) > 0: if self.input_history[-1] != input: self.input_history.append(input) else: self.input_history.append(input) self.input_history_index = len(self.input_history) component.start("LegacyUI") # show the cursor curses.curs_set(2) BaseMode.__init__(self, stdscr, encoding) # This gets fired once we have received the torrents list from the core self.started_deferred = defer.Deferred() # Maintain a list of (torrent_id, name) for use in tab completion self.torrents = [] def on_session_state(result): def on_torrents_status(torrents): for torrent_id, status in torrents.items(): self.torrents.append((torrent_id, status["name"])) self.started_deferred.callback(True) client.core.get_torrents_status({"id": result}, ["name"]).addCallback(on_torrents_status) client.core.get_session_state().addCallback(on_session_state) # Register some event handlers to keep the torrent list up-to-date client.register_event_handler("TorrentAddedEvent", self.on_torrent_added_event) client.register_event_handler("TorrentRemovedEvent", self.on_torrent_removed_event)
def __init__(self, alltorrentmode, torrentid, stdscr, encoding=None): self.alltorrentmode = alltorrentmode self.torrentid = torrentid self.torrent_state = None self.popup = None self.messages = deque() self._status_keys = [ "files", "name", "state", "download_payload_rate", "upload_payload_rate", "progress", "eta", "all_time_download", "total_uploaded", "ratio", "num_seeds", "total_seeds", "num_peers", "total_peers", "active_time", "seeding_time", "time_added", "distributed_copies", "num_pieces", "piece_length", "save_path", "file_progress", "file_priorities", "message" ] self._info_fields = [ ("Name", None, ("name", )), ("State", None, ("state", )), ("Status", None, ("message", )), ("Down Speed", format_utils.format_speed, ("download_payload_rate", )), ("Up Speed", format_utils.format_speed, ("upload_payload_rate", )), ("Progress", format_utils.format_progress, ("progress", )), ("ETA", deluge.common.ftime, ("eta", )), ("Path", None, ("save_path", )), ("Downloaded", deluge.common.fsize, ("all_time_download", )), ("Uploaded", deluge.common.fsize, ("total_uploaded", )), ("Share Ratio", lambda x: x < 0 and "∞" or "%.3f" % x, ("ratio", )), ("Seeders", format_utils.format_seeds_peers, ("num_seeds", "total_seeds")), ("Peers", format_utils.format_seeds_peers, ("num_peers", "total_peers")), ("Active Time", deluge.common.ftime, ("active_time", )), ("Seeding Time", deluge.common.ftime, ("seeding_time", )), ("Date Added", deluge.common.fdate, ("time_added", )), ("Availability", lambda x: x < 0 and "∞" or "%.3f" % x, ("distributed_copies", )), ("Pieces", format_utils.format_pieces, ("num_pieces", "piece_length")), ] self.file_list = None self.current_file = None self.current_file_idx = 0 self.file_limit = maxint self.file_off = 0 self.more_to_draw = False self.column_string = "" self.files_sep = None self.marked = {} BaseMode.__init__(self, stdscr, encoding) component.Component.__init__(self, "TorrentDetail", 1, depend=["SessionProxy"]) self.__split_help() self.column_names = ["Filename", "Size", "Progress", "Priority"] self.__update_columns() component.start(["TorrentDetail"]) curses.curs_set(0) self.stdscr.notimeout(0)
def __init__(self, parent_mode, stdscr, encoding=None): self.parent_mode = parent_mode BaseMode.__init__(self, stdscr, encoding)
def __init__(self, stdscr, encoding=None): component.Component.__init__(self, "LegacyUI", 1, depend=["SessionProxy"]) self.batch_write = False # A list of strings to be displayed based on the offset (scroll) self.lines = [] # The offset to display lines self.display_lines_offset = 0 # Holds the user input and is cleared on 'enter' self.input = "" self.input_incomplete = "" self._old_char = 0 self._last_char = 0 self._last_del_char = '' # Keep track of where the cursor is self.input_cursor = 0 # Keep a history of inputs self.input_history = [] self.input_history_index = 0 # Keep track of double- and multi-tabs self.tab_count = 0 # Get a handle to the main console self.console = component.get("ConsoleUI") self.console_config = component.get("AllTorrents").config #To avoid having to truncate the file every time we're writing # or doing it on exit(and therefore relying on an error-less # or in other words clean exit, we're going to have two files # that we swap around based on length config_dir = deluge.configmanager.get_config_dir() self.history_file = [ os.path.join(config_dir, "legacy.hist1"), os.path.join(config_dir, "legacy.hist2") ] self._hf_lines = [0, 0] if self.console_config["save_legacy_history"]: try: lines1 = open(self.history_file[0], 'r').read().splitlines() self._hf_lines[0] = len(lines1) except: lines1 = [] self._hf_lines[0] = 0 try: lines2 = open(self.history_file[1], 'r').read().splitlines() self._hf_lines[1] = len(lines2) except: lines2 = [] self._hf_lines[1] = 0 #The non-full file is the active one if self._hf_lines[0] > self._hf_lines[1]: self.lines = lines1 + lines2 else: self.lines = lines2 + lines1 if len(self.lines) > MAX_HISTFILE_SIZE: self.lines = self.lines[-MAX_HISTFILE_SIZE:] #Instead of having additional input history file, we can # simply scan for lines beginning with ">>> " for i, line in enumerate(self.lines): #if not isinstance(line, unicode): #line = line.encode(self.encoding) #self.lines[i] = line line = format_utils.remove_formatting(line) if line.startswith(">>> "): input = line[4:] if self.console_config["ignore_duplicate_lines"]: if len(self.input_history) > 0: if self.input_history[-1] != input: self.input_history.append(input) else: self.input_history.append(input) self.input_history_index = len(self.input_history) component.start("LegacyUI") # show the cursor curses.curs_set(2) BaseMode.__init__(self, stdscr, encoding) # This gets fired once we have received the torrents list from the core self.started_deferred = defer.Deferred() # Maintain a list of (torrent_id, name) for use in tab completion self.torrents = [] def on_session_state(result): def on_torrents_status(torrents): for torrent_id, status in torrents.items(): self.torrents.append((torrent_id, status["name"])) self.started_deferred.callback(True) client.core.get_torrents_status({ "id": result }, ["name"]).addCallback(on_torrents_status) client.core.get_session_state().addCallback(on_session_state) # Register some event handlers to keep the torrent list up-to-date client.register_event_handler("TorrentAddedEvent", self.on_torrent_added_event) client.register_event_handler("TorrentRemovedEvent", self.on_torrent_removed_event)