diff --git a/youtube_dl_gui/downloaders.py b/youtube_dl_gui/downloaders.py index 94e6a14..9b67cc3 100644 --- a/youtube_dl_gui/downloaders.py +++ b/youtube_dl_gui/downloaders.py @@ -244,7 +244,7 @@ class YoutubeDLDownloader(object): """Extract informations about the download process from the given data. Args: - data (dictionary): Python dictionary that contains different + data (dict): Python dictionary that contains different keys. The keys are not standar the dictionary can also be empty when there are no data to extract. See extract_data(). diff --git a/youtube_dl_gui/downloadmanager.py b/youtube_dl_gui/downloadmanager.py index ba582e9..008d9d8 100644 --- a/youtube_dl_gui/downloadmanager.py +++ b/youtube_dl_gui/downloadmanager.py @@ -158,7 +158,7 @@ class DownloadManager(Thread): """Add given url to the urls_list. Args: - url (dictionary): Python dictionary that contains two keys. + url (dict): Python dictionary that contains two keys. The url and the index of the corresponding row in which the worker should send back the information about the download process. @@ -281,7 +281,7 @@ class Worker(Thread): """Download given item. Args: - item (dictionary): Python dictionary that contains two keys. + item (dict): Python dictionary that contains two keys. The url and the index of the corresponding row in which the worker should send back the information about the download process. @@ -331,30 +331,38 @@ class Worker(Thread): def _data_hook(self, data): """Callback method for self._downloader. - This method updates self._data and sends them back to the GUI - using the self._talk_to_gui() method. + This method updates self._data and sends the updates back to the + GUI using the self._talk_to_gui() method. Args: - data (dictionary): Python dictionary which contains information + data (dict): Python dictionary which contains information about the download process. For more info see the extract_data() function under the downloaders.py module. """ + # Temp dictionary which holds the updates + temp_dict = {} + # Update each key for key in data: - self._data[key] = data[key] - - # Build the playlist status - if self._data['status'] is not None and self._data['playlist_index'] is not None: - self._data['status'] = '{status} {index}/{size}'.format( - status=self._data['status'], - index=self._data['playlist_index'], - size=self._data['playlist_size'] - ) + if self._data[key] != data[key]: + self._data[key] = data[key] + temp_dict[key] = data[key] + + # Build the playlist status if there is an update + if self._data['playlist_index'] is not None: + if 'status' in temp_dict or 'playlist_index' in temp_dict: + temp_dict['status'] = '{status} {index}/{size}'.format( + status=self._data['status'], + index=self._data['playlist_index'], + size=self._data['playlist_size'] + ) + + if len(temp_dict): + temp_dict['index'] = self._data['index'] + self._talk_to_gui(temp_dict) - self._talk_to_gui() - - def _talk_to_gui(self): - """Send self._data back to the GUI. """ - CallAfter(Publisher.sendMessage, WORKER_PUB_TOPIC, self._data) + def _talk_to_gui(self, data): + """Send data back to the GUI. """ + CallAfter(Publisher.sendMessage, WORKER_PUB_TOPIC, data) diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index 27361eb..11f8181 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -54,11 +54,9 @@ class MainFrame(wx.Frame): Labels area (strings): Strings for the widgets labels. - STATUSLIST_COLUMNS (tuple): Tuple of tuples that contains informations - about the ListCtrl columns. First item is the column name. Second - item is the column position. Third item is the column label. - Fourth item is the column default width. Last item is a boolean - flag if True the current column is resizable. + STATUSLIST_COLUMNS (dict): Python dictionary which holds informations + about the wxListCtrl columns. For more informations read the + comments above the STATUSLIST_COLUMNS declaration. Args: opt_manager (optionsmanager.OptionsManager): Object responsible for @@ -115,16 +113,22 @@ class MainFrame(wx.Frame): STATUS_LABEL = _("Status") ################################# - # (column_name, column_index, column_label, minimum_width, resizable) - STATUSLIST_COLUMNS = ( - ('filename', 0, VIDEO_LABEL, 150, True), - ('extension', 1, EXTENSION_LABEL, 60, False), - ('filesize', 2, SIZE_LABEL, 80, False), - ('percent', 3, PERCENT_LABEL, 65, False), - ('eta', 4, ETA_LABEL, 45, False), - ('speed', 5, SPEED_LABEL, 90, False), - ('status', 6, STATUS_LABEL, 160, False) - ) + # STATUSLIST_COLUMNS + # + # Dictionary which contains the columns for the wxListCtrl widget. + # Each key represents a column and holds informations about itself. + # Structure informations: + # column_key: (column_number, column_label, minimum_width, is_resizable) + # + STATUSLIST_COLUMNS = { + 'filename': (0, VIDEO_LABEL, 150, True), + 'extension': (1, EXTENSION_LABEL, 60, False), + 'filesize': (2, SIZE_LABEL, 80, False), + 'percent': (3, PERCENT_LABEL, 65, False), + 'eta': (4, ETA_LABEL, 45, False), + 'speed': (5, SPEED_LABEL, 90, False), + 'status': (6, STATUS_LABEL, 160, False) + } def __init__(self, opt_manager, log_manager, parent=None): wx.Frame.__init__(self, parent, title=__appname__, size=opt_manager.options['main_win_size']) @@ -513,7 +517,7 @@ class ListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin): """Custom ListCtrl widget. Args: - columns (tuple): See MainFrame class STATUSLIST_COLUMNS attribute. + columns (dict): See MainFrame class STATUSLIST_COLUMNS attribute. """ @@ -529,21 +533,16 @@ class ListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin): """Write data on ListCtrl row-column. Args: - data (dictionary): Dictionary that contains the data to be + data (dict): Dictionary that contains the data to be written on the ListCtrl. In order for this method to write the given data there must be an 'index' key that - identifies the current row and a corresponding key for - each item of the self.columns. - - Note: - Income data must contain all the columns keys else a KeyError will - be raised. Also there must be an 'index' key that identifies the - row to write the data. For a valid data dictionary see - downloaders.YoutubeDLDownloader self._data. + identifies the current row. For a valid data dictionary see + Worker class __init__() method under downloadmanager.py module. """ - for column in self.columns: - self._write_data(data[column[0]], data['index'], column[1]) + for key in data: + if key in self.columns: + self._write_data(data['index'], self.columns[key][0], data[key]) def load_urls(self, url_list, func=None): """Load URLs from the url_list on the ListCtrl widget. @@ -612,7 +611,7 @@ class ListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin): return items - def _write_data(self, data, row, column): + def _write_data(self, row, column, data): """Write data on row-column. """ if isinstance(data, basestring): self.SetStringItem(row, column, data) @@ -636,14 +635,16 @@ class ListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin): def _set_columns(self): """Initializes ListCtrl columns. See MainFrame STATUSLIST_COLUMNS attribute for more info. """ - for column in self.columns: - self.InsertColumn(column[1], column[2], width=wx.LIST_AUTOSIZE_USEHEADER) + for column_item in sorted(self.columns.values()): + self.InsertColumn(column_item[0], column_item[1], width=wx.LIST_AUTOSIZE_USEHEADER) # If the column width obtained from wxLIST_AUTOSIZE_USEHEADER # is smaller than the minimum allowed column width # then set the column width to the minumum allowed size - if self.GetColumnWidth(column[1]) < column[3]: - self.SetColumnWidth(column[1], column[3]) + if self.GetColumnWidth(column_item[0]) < column_item[2]: + self.SetColumnWidth(column_item[0], column_item[2]) + + # Set auto-resize if enabled + if column_item[3]: + self.setResizeColumn(column_item[0]) - if column[4]: - self.setResizeColumn(column[1]) diff --git a/youtube_dl_gui/optionsmanager.py b/youtube_dl_gui/optionsmanager.py index 145da10..a2d97c1 100644 --- a/youtube_dl_gui/optionsmanager.py +++ b/youtube_dl_gui/optionsmanager.py @@ -273,7 +273,7 @@ class OptionsManager(object): """Check settings.json dictionary. Args: - settings_dictionary (dictionary): Options dictionary loaded + settings_dictionary (dict): Options dictionary loaded from the settings file. See load_from_file() method. Returns: diff --git a/youtube_dl_gui/parsers.py b/youtube_dl_gui/parsers.py index b77d155..d22fc7c 100644 --- a/youtube_dl_gui/parsers.py +++ b/youtube_dl_gui/parsers.py @@ -50,7 +50,7 @@ class OptionHolder(object): """Check if the required options are enabled. Args: - options_dict (dictionary): Dictionary with all the options. + options_dict (dict): Dictionary with all the options. Returns: True if any of the required options is enabled else False. @@ -109,7 +109,7 @@ class OptionsParser(object): Parses the given options to youtube-dl command line arguments. Args: - options_dictionary (dictionary): Dictionary with all the options. + options_dictionary (dict): Dictionary with all the options. Returns: List of strings with all the youtube-dl command line options. @@ -150,7 +150,7 @@ class OptionsParser(object): store it back to the options dictionary. Args: - options_dict (dictionary): Copy of the original options dictionary. + options_dict (dict): Copy of the original options dictionary. """ save_path = remove_shortcuts(options_dict['save_path']) @@ -171,7 +171,7 @@ class OptionsParser(object): store it back to the options dictionary. Args: - options_dict (dictionary): Copy of the original options dictionary. + options_dict (dict): Copy of the original options dictionary. """ if options_dict['video_format'] != '0' and options_dict['second_video_format'] != '0': @@ -184,7 +184,7 @@ class OptionsParser(object): 'max_filesize' options and store them back to options dictionary. Args: - options_dict (dictionary): Copy of the original options dictionary. + options_dict (dict): Copy of the original options dictionary. """ if options_dict['min_filesize']: