Browse Source

Enable video formats ComboBox

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
0c9a31a8b1
3 changed files with 36 additions and 5 deletions
  1. 21
      youtube_dl_gui/mainframe.py
  2. 2
      youtube_dl_gui/optionsframe.py
  3. 18
      youtube_dl_gui/utils.py

21
youtube_dl_gui/mainframe.py

@ -35,6 +35,7 @@ from .utils import (
get_config_path,
get_icon_file,
shutdown_sys,
read_formats,
json_store,
json_load,
get_time,
@ -178,15 +179,15 @@ class MainFrame(wx.Frame):
# Get stored save paths file
self._stored_paths = os.path.join(get_config_path(), "spaths")
# Get video formats
self._video_formats = read_formats()
# Set the app icon
app_icon_path = get_icon_file()
if app_icon_path is not None:
self.app_icon = wx.Icon(app_icon_path, wx.BITMAP_TYPE_PNG)
self.SetIcon(self.app_icon)
# Create options frame
self._options_frame = OptionsFrame(self)
# Set the data for all the wx.Button items
# name, label, icon, size, event_handler
buttons_data = (
@ -210,6 +211,9 @@ class MainFrame(wx.Frame):
(self.ABOUT_LABEL, self._on_about)
)
# Create options frame
self._options_frame = OptionsFrame(self)
# Create frame components
self._panel = wx.Panel(self)
@ -219,8 +223,10 @@ class MainFrame(wx.Frame):
self._url_list = self._create_textctrl(wx.TE_MULTILINE | wx.TE_DONTWRAP, self._on_urllist_edit)
self._folder_icon = self._create_static_bitmap("folder_32px.png")
#TODO on change event update save path
self._path_combobox = ComboBoxLimit(self._panel)
self._videoformat_combobox = wx.ComboBox(self._panel)
self._videoformat_combobox = wx.ComboBox(self._panel, choices=self._video_formats.values())
self._download_text = self._create_statictext(self.DOWNLOAD_LIST_LABEL)
self._status_list = ListCtrl(self.STATUSLIST_COLUMNS,
@ -272,6 +278,10 @@ class MainFrame(wx.Frame):
self._set_buttons_width()
self._status_bar_write(self.WELCOME_MSG)
# TODO method to do this in one line
self._videoformat_combobox.SetValue(self._video_formats[self.opt_manager.options["video_format"]])
self._videoformat_combobox.SetSelection(self._videoformat_combobox.FindString(self._videoformat_combobox.GetValue()))
self._path_combobox.LoadMultiple(json_load(self._stored_paths))
self._set_layout()
@ -713,6 +723,9 @@ class MainFrame(wx.Frame):
self.opt_manager.options['main_win_size'] = self.GetSize()
self.opt_manager.options['opts_win_size'] = self._options_frame.GetSize()
#TODO update opt_manager on ComboBox edit
self.opt_manager.options["video_format"] = self._video_formats[self._videoformat_combobox.GetValue()]
self._options_frame.save_all_options()
self.opt_manager.save_to_file()

2
youtube_dl_gui/optionsframe.py

@ -941,7 +941,7 @@ class VideoTab(TabPanel):
self._on_videoformat(None)
def save_options(self):
self.opt_manager.options['video_format'] = self.FORMATS.get(self.videoformat_combo.GetValue(), '0')
#self.opt_manager.options['video_format'] = self.FORMATS.get(self.videoformat_combo.GetValue(), '0')
self.opt_manager.options['second_video_format'] = self.FORMATS.get(self.sec_videoformat_combo.GetValue(), '0')

18
youtube_dl_gui/utils.py

@ -328,6 +328,24 @@ def json_store(filename, item):
with open(filename, 'w') as output_json_file:
json.dump(item, output_json_file)
def read_formats():
"""Returns a twodict containing all the formats from 'data/formats'."""
# TODO Support for other directories? Test with py2exe
formats_file = os.path.join(absolute_path(__file__), "data", "formats")
if os_path_exists(formats_file):
formats_dict = TwoWayOrderedDict()
with open(formats_file) as input_file:
for line in input_file:
format_id, format_label = line.split('-')
formats_dict[format_id.strip()] = format_label.strip()
return formats_dict
return None
class TwoWayOrderedDict(dict):

Loading…
Cancel
Save