You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

683 lines
24 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
8 years ago
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. """Youtubedlg module responsible for the options window. """
  4. from __future__ import unicode_literals
  5. import os
  6. import gettext
  7. import wx
  8. from .version import __version__
  9. from .info import (
  10. __descriptionfull__,
  11. __licensefull__,
  12. __projecturl__,
  13. __appname__,
  14. __author__
  15. )
  16. from .utils import (
  17. TwoWayOrderedDict as twodict,
  18. os_path_exists,
  19. get_icon_file
  20. )
  21. #TODO Set up load-save methods
  22. #TODO Adjust layout
  23. #TODO Set frame's min size
  24. #TODO Add labels to gettext
  25. class OptionsFrame(wx.Frame):
  26. """Youtubedlg options frame class.
  27. Args:
  28. parent (mainframe.MainFrame): Parent class.
  29. """
  30. FRAME_TITLE = _("Options")
  31. def __init__(self, parent):
  32. wx.Frame.__init__(self, parent, title=self.FRAME_TITLE, size=parent.opt_manager.options["opts_win_size"])
  33. self.opt_manager = parent.opt_manager
  34. self.log_manager = parent.log_manager
  35. self.app_icon = None
  36. # Set the app icon
  37. app_icon_path = get_icon_file()
  38. if app_icon_path is not None:
  39. self.app_icon = wx.Icon(app_icon_path, wx.BITMAP_TYPE_PNG)
  40. self.SetIcon(self.app_icon)
  41. self._was_shown = False
  42. # Create options frame basic components
  43. self.panel = wx.Panel(self)
  44. self.notebook = wx.Notebook(self.panel)
  45. self.separator_line = wx.StaticLine(self.panel)
  46. self.reset_button = wx.Button(self.panel, label="Reset")
  47. self.close_button = wx.Button(self.panel, label="Close")
  48. # Create tabs
  49. tab_args = (self, self.notebook)
  50. self.tabs = (
  51. (GeneralTab(*tab_args), "General"),
  52. (FormatsTab(*tab_args), "Formats"),
  53. (DownloadsTab(*tab_args), "Downloads"),
  54. (AdvancedTab(*tab_args), "Advanced"),
  55. (ExtraTab(*tab_args), "Extra")
  56. )
  57. # Add tabs on notebook
  58. for tab, label in self.tabs:
  59. self.notebook.AddPage(tab, label)
  60. # Bind events
  61. self.Bind(wx.EVT_BUTTON, self._on_reset, self.reset_button)
  62. self.Bind(wx.EVT_BUTTON, self._on_close, self.close_button)
  63. self.Bind(wx.EVT_CLOSE, self._on_close)
  64. self._set_layout()
  65. self.load_all_options()
  66. def _set_layout(self):
  67. main_sizer = wx.BoxSizer(wx.VERTICAL)
  68. main_sizer.Add(self.notebook, 1, wx.EXPAND | wx.ALL, border=5)
  69. main_sizer.Add(self.separator_line, 0, wx.EXPAND)
  70. buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
  71. buttons_sizer.Add(self.reset_button)
  72. buttons_sizer.Add(self.close_button)
  73. main_sizer.Add(buttons_sizer, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
  74. self.panel.SetSizer(main_sizer)
  75. def _on_close(self, event):
  76. """Event handler for wx.EVT_CLOSE event."""
  77. self.save_all_options()
  78. self.Hide()
  79. def _on_reset(self, event):
  80. """Event handler for the reset button wx.EVT_BUTTON event."""
  81. self.reset()
  82. def reset(self):
  83. """Reset the default options."""
  84. self.opt_manager.load_default()
  85. self.load_all_options()
  86. def load_all_options(self):
  87. """Load all the options on each tab."""
  88. for tab, _ in self.tabs:
  89. tab.load_options()
  90. def save_all_options(self):
  91. """Save all the options from all the tabs back to the OptionsManager."""
  92. for tab, _ in self.tabs:
  93. tab.save_options()
  94. def Show(self, *args, **kwargs):
  95. # CenterOnParent can't go to main frame's __init__ as main frame may change
  96. # own position and options frame won't be centered on main frame anymore.
  97. if not self._was_shown:
  98. self._was_shown = True
  99. self.CenterOnParent()
  100. return wx.Frame.Show(self, *args, **kwargs)
  101. class TabPanel(wx.Panel):
  102. """Main tab class from which each tab inherits.
  103. Args:
  104. parent (OptionsFrame): The parent of all tabs.
  105. notebook (wx.Notebook): The container for each tab.
  106. Notes:
  107. In order to use a different size you must overwrite the below *_SIZE
  108. attributes on the corresponding child object.
  109. """
  110. CHECKBOX_SIZE = (-1, -1)
  111. if os.name == "nt":
  112. # Make checkboxes look the same on Windows
  113. CHECKBOX_SIZE = (-1, 25)
  114. BUTTONS_SIZE = (-1, -1)
  115. TEXTCTRL_SIZE = (-1, -1)
  116. SPINCTRL_SIZE = (70, -1)
  117. def __init__(self, parent, notebook):
  118. wx.Panel.__init__(self, notebook)
  119. self.opt_manager = parent.opt_manager
  120. self.log_manager = parent.log_manager
  121. self.app_icon = parent.app_icon
  122. self.reset_handler = parent.reset
  123. # Shortcut methods below
  124. def crt_button(self, label, event_handler=None):
  125. button = wx.Button(self, label=label, size=self.BUTTONS_SIZE)
  126. if event_handler is not None:
  127. button.Bind(wx.EVT_BUTTON, event_handler)
  128. return button
  129. def crt_checkbox(self, label, event_handler=None):
  130. checkbox = wx.CheckBox(self, label=label, size=self.CHECKBOX_SIZE)
  131. if event_handler is not None:
  132. checkbox.Bind(wx.EVT_CHECKBOX, event_handler)
  133. return checkbox
  134. def crt_textctrl(self, style=None):
  135. if style is None:
  136. textctrl = wx.TextCtrl(self, size=self.TEXTCTRL_SIZE)
  137. else:
  138. textctrl = wx.TextCtrl(self, size=self.TEXTCTRL_SIZE, style=style)
  139. return textctrl
  140. def crt_combobox(self, choices, size=(-1, -1), event_handler=None):
  141. combobox = wx.ComboBox(self, choices=choices, size=size, style=wx.CB_READONLY)
  142. if event_handler is not None:
  143. combobox.Bind(wx.EVT_COMBOBOX, event_handler)
  144. return combobox
  145. def crt_spinctrl(self, spin_range=(0, 9999)):
  146. spinctrl = wx.SpinCtrl(self, size=self.SPINCTRL_SIZE)
  147. spinctrl.SetRange(*spin_range)
  148. return spinctrl
  149. def crt_statictext(self, label):
  150. return wx.StaticText(self, wx.ID_ANY, label)
  151. class GeneralTab(TabPanel):
  152. LOCALE_NAMES = twodict([
  153. ('ar_AR', 'Arabic'),
  154. ('cs_CZ', 'Czech'),
  155. ('en_US', 'English'),
  156. ('fr_FR', 'French'),
  157. ('de_DE', 'German'),
  158. ('it_IT', 'Italian'),
  159. ('he_IS', 'Hebrew'),
  160. ('hu_HU', 'Hungarian'),
  161. ('pt_BR', 'Portuguese'),
  162. ('ru_RU', 'Russian'),
  163. ('es_ES', 'Spanish'),
  164. ('es_MX', 'Mexican Spanish'),
  165. ('tr_TR', 'Turkish')
  166. ])
  167. def __init__(self, *args, **kwargs):
  168. super(GeneralTab, self).__init__(*args, **kwargs)
  169. self.language_label = wx.StaticText(self, label="Language")
  170. self.language_combobox = wx.ComboBox(self, style=wx.CB_READONLY)
  171. self.filename_format_label = wx.StaticText(self, label="Filename format")
  172. self.filename_format_combobox = wx.ComboBox(self, style=wx.CB_READONLY)
  173. self.filename_custom_format = wx.TextCtrl(self)
  174. self.filename_opts_label = wx.StaticText(self, label="Filename options")
  175. self.filename_ascii_checkbox = wx.CheckBox(self, label="Restrict filenames to ASCII")
  176. self.more_opts_label = wx.StaticText(self, label="More options")
  177. self.confirm_exit_checkbox = wx.CheckBox(self, label="Confirm on exit")
  178. self.shutdown_checkbox = wx.CheckBox(self, label="Shutdown")
  179. self.sudo_textctrl = wx.TextCtrl(self, style=wx.TE_PASSWORD)
  180. self._set_layout()
  181. def _set_layout(self):
  182. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  183. vertical_sizer = wx.BoxSizer(wx.VERTICAL)
  184. vertical_sizer.Add(self.language_label)
  185. vertical_sizer.Add(self.language_combobox, flag=wx.EXPAND | wx.ALL, border=5)
  186. vertical_sizer.Add(self.filename_format_label)
  187. vertical_sizer.Add(self.filename_format_combobox, flag=wx.EXPAND | wx.ALL, border=5)
  188. vertical_sizer.Add(self.filename_custom_format, flag=wx.EXPAND | wx.ALL, border=5)
  189. vertical_sizer.Add(self.filename_opts_label)
  190. vertical_sizer.Add(self.filename_ascii_checkbox, flag=wx.ALL, border=5)
  191. vertical_sizer.Add(self.more_opts_label)
  192. vertical_sizer.Add(self.confirm_exit_checkbox, flag=wx.ALL, border=5)
  193. shutdown_sizer = wx.BoxSizer(wx.HORIZONTAL)
  194. shutdown_sizer.Add(self.shutdown_checkbox)
  195. shutdown_sizer.AddSpacer((-1, -1), 1)
  196. shutdown_sizer.Add(self.sudo_textctrl, 1)
  197. vertical_sizer.Add(shutdown_sizer, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
  198. main_sizer.Add(vertical_sizer, 1, wx.EXPAND | wx.ALL, border=5)
  199. self.SetSizer(main_sizer)
  200. def load_options(self):
  201. pass
  202. def save_options(self):
  203. pass
  204. class FormatsTab(TabPanel):
  205. AUDIO_QUALITY = twodict([("0", _("high")), ("5", _("mid")), ("9", _("low"))])
  206. #TODO Move those to separate file
  207. AUDIO_FORMATS = ["mp3", "wav", "aac", "m4a", "vorbis", "opus"]
  208. def __init__(self, *args, **kwargs):
  209. super(FormatsTab, self).__init__(*args, **kwargs)
  210. self.video_formats_label = wx.StaticText(self, label="Video formats")
  211. self.video_formats_checklistbox = wx.CheckListBox(self)
  212. self.audio_formats_label = wx.StaticText(self, label="Audio formats")
  213. self.audio_formats_checklistbox = wx.CheckListBox(self)
  214. self.post_proc_opts_label = wx.StaticText(self, label="Post-Process options")
  215. self.keep_video_checkbox = wx.CheckBox(self, label="Keep original video")
  216. self.audio_quality_label = wx.StaticText(self, label="Audio quality")
  217. self.audio_quality_combobox = wx.ComboBox(self, size=(100, -1), style=wx.CB_READONLY)
  218. self._set_layout()
  219. def _set_layout(self):
  220. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  221. vertical_sizer = wx.BoxSizer(wx.VERTICAL)
  222. vertical_sizer.Add(self.video_formats_label)
  223. vertical_sizer.Add(self.video_formats_checklistbox, 1, wx.EXPAND | wx.ALL, border=5)
  224. vertical_sizer.Add(self.audio_formats_label)
  225. vertical_sizer.Add(self.audio_formats_checklistbox, 1, wx.EXPAND | wx.ALL, border=5)
  226. vertical_sizer.Add(self.post_proc_opts_label)
  227. vertical_sizer.Add(self.keep_video_checkbox, flag=wx.ALL, border=5)
  228. audio_quality_sizer = wx.BoxSizer(wx.HORIZONTAL)
  229. audio_quality_sizer.Add(self.audio_quality_label, flag=wx.ALIGN_CENTER_VERTICAL)
  230. audio_quality_sizer.AddSpacer((20, -1))
  231. audio_quality_sizer.Add(self.audio_quality_combobox)
  232. vertical_sizer.Add(audio_quality_sizer, flag=wx.LEFT | wx.RIGHT, border=10)
  233. main_sizer.Add(vertical_sizer, 1, wx.EXPAND | wx.ALL, border=5)
  234. self.SetSizer(main_sizer)
  235. def load_options(self):
  236. pass
  237. def save_options(self):
  238. pass
  239. class DownloadsTab(TabPanel):
  240. SUBS_LANG = twodict([
  241. ("en", _("English")),
  242. ("gr", _("Greek")),
  243. ("pt", _("Portuguese")),
  244. ("fr", _("French")),
  245. ("it", _("Italian")),
  246. ("ru", _("Russian")),
  247. ("es", _("Spanish")),
  248. ("tr", _("Turkish")),
  249. ("de", _("German"))
  250. ])
  251. FILESIZES = twodict([
  252. ("", "Bytes"),
  253. ("k", "Kilobytes"),
  254. ("m", "Megabytes"),
  255. ("g", "Gigabytes"),
  256. ("t", "Terabytes"),
  257. ("p", "Petabytes"),
  258. ("e", "Exabytes"),
  259. ("z", "Zettabytes"),
  260. ("y", "Yottabytes")
  261. ])
  262. def __init__(self, *args, **kwargs):
  263. super(DownloadsTab, self).__init__(*args, **kwargs)
  264. self.subtitles_label = wx.StaticText(self, label="Subtitles")
  265. self.subtitles_combobox = wx.ComboBox(self, style=wx.CB_READONLY)
  266. self.subtitles_lang_listbox = wx.ListBox(self)
  267. self.subtitles_opts_label = wx.StaticText(self, label="Subtitles options")
  268. self.embed_subs_checkbox = wx.CheckBox(self, label="Embed subtitles into video file (mp4 ONLY)")
  269. self.playlist_box = wx.StaticBox(self, label="Playlist")
  270. self.playlist_start_label = wx.StaticText(self, label="Start")
  271. self.playlist_start_spinctrl = wx.SpinCtrl(self, size=(80, -1))
  272. self.playlist_stop_label = wx.StaticText(self, label="Stop")
  273. self.playlist_stop_spinctrl = wx.SpinCtrl(self, size=(80, -1))
  274. self.playlist_max_label = wx.StaticText(self, label="Max")
  275. self.playlist_max_spinctrl = wx.SpinCtrl(self, size=(80, -1))
  276. self.filesize_box = wx.StaticBox(self, label="Filesize")
  277. self.filesize_min_label = wx.StaticText(self, label="Min")
  278. self.filesize_min_spinctrl = wx.SpinCtrl(self)
  279. self.filesize_min_sizeunit_combobox = wx.ComboBox(self)
  280. self.filesize_max_label = wx.StaticText(self, label="Max")
  281. self.filesize_max_spinctrl = wx.SpinCtrl(self)
  282. self.filesize_max_sizeunit_combobox = wx.ComboBox(self)
  283. self._set_layout()
  284. def _set_layout(self):
  285. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  286. vertical_sizer = wx.BoxSizer(wx.VERTICAL)
  287. vertical_sizer.Add(self.subtitles_label)
  288. vertical_sizer.Add(self.subtitles_combobox, flag=wx.EXPAND | wx.ALL, border=5)
  289. vertical_sizer.Add(self.subtitles_lang_listbox, 1, wx.EXPAND | wx.ALL, border=5)
  290. vertical_sizer.Add(self.subtitles_opts_label)
  291. vertical_sizer.Add(self.embed_subs_checkbox, flag=wx.ALL, border=5)
  292. plist_and_fsize_sizer = wx.BoxSizer(wx.HORIZONTAL)
  293. plist_and_fsize_sizer.Add(self._build_playlist_sizer(), 1, wx.EXPAND)
  294. plist_and_fsize_sizer.AddSpacer((10, -1))
  295. plist_and_fsize_sizer.Add(self._build_filesize_sizer(), 1, wx.EXPAND)
  296. vertical_sizer.Add(plist_and_fsize_sizer, 1, wx.EXPAND | wx.TOP, border=5)
  297. main_sizer.Add(vertical_sizer, 1, wx.EXPAND | wx.ALL, border=5)
  298. self.SetSizer(main_sizer)
  299. def _build_playlist_sizer(self):
  300. left_right_border = 80
  301. playlist_box_sizer = wx.StaticBoxSizer(self.playlist_box, wx.VERTICAL)
  302. playlist_box_sizer.AddSpacer((-1, 10))
  303. start_plist_sizer = wx.BoxSizer(wx.HORIZONTAL)
  304. start_plist_sizer.AddSpacer((left_right_border, -1))
  305. start_plist_sizer.Add(self.playlist_start_label, flag=wx.ALIGN_CENTER_VERTICAL)
  306. start_plist_sizer.AddSpacer((-1, -1), 1)
  307. start_plist_sizer.Add(self.playlist_start_spinctrl)
  308. start_plist_sizer.AddSpacer((left_right_border, -1))
  309. stop_plist_sizer = wx.BoxSizer(wx.HORIZONTAL)
  310. stop_plist_sizer.AddSpacer((left_right_border, -1))
  311. stop_plist_sizer.Add(self.playlist_stop_label, flag=wx.ALIGN_CENTER_VERTICAL)
  312. stop_plist_sizer.AddSpacer((-1, -1), 1)
  313. stop_plist_sizer.Add(self.playlist_stop_spinctrl)
  314. stop_plist_sizer.AddSpacer((left_right_border, -1))
  315. max_plist_sizer = wx.BoxSizer(wx.HORIZONTAL)
  316. max_plist_sizer.AddSpacer((left_right_border, -1))
  317. max_plist_sizer.Add(self.playlist_max_label, flag=wx.ALIGN_CENTER_VERTICAL)
  318. max_plist_sizer.AddSpacer((-1, -1), 1)
  319. max_plist_sizer.Add(self.playlist_max_spinctrl)
  320. max_plist_sizer.AddSpacer((left_right_border, -1))
  321. playlist_box_sizer.Add(start_plist_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  322. playlist_box_sizer.Add(stop_plist_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  323. playlist_box_sizer.Add(max_plist_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  324. return playlist_box_sizer
  325. def _build_filesize_sizer(self):
  326. left_right_border = 40
  327. filesize_box_sizer = wx.StaticBoxSizer(self.filesize_box, wx.VERTICAL)
  328. filesize_box_sizer.AddSpacer((-1, 10))
  329. max_filesize_sizer = wx.BoxSizer(wx.HORIZONTAL)
  330. max_filesize_sizer.AddSpacer((left_right_border, -1))
  331. max_filesize_sizer.Add(self.filesize_max_spinctrl)
  332. max_filesize_sizer.AddSpacer((-1, -1), 1)
  333. max_filesize_sizer.Add(self.filesize_max_sizeunit_combobox)
  334. max_filesize_sizer.AddSpacer((left_right_border, -1))
  335. min_filesize_sizer = wx.BoxSizer(wx.HORIZONTAL)
  336. min_filesize_sizer.AddSpacer((left_right_border, -1))
  337. min_filesize_sizer.Add(self.filesize_min_spinctrl)
  338. min_filesize_sizer.AddSpacer((-1, -1), 1)
  339. min_filesize_sizer.Add(self.filesize_min_sizeunit_combobox)
  340. min_filesize_sizer.AddSpacer((left_right_border, -1))
  341. filesize_box_sizer.Add(self.filesize_max_label, flag=wx.ALIGN_CENTER_HORIZONTAL)
  342. filesize_box_sizer.Add(max_filesize_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  343. filesize_box_sizer.Add(self.filesize_min_label, flag=wx.ALIGN_CENTER_HORIZONTAL)
  344. filesize_box_sizer.Add(min_filesize_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  345. return filesize_box_sizer
  346. def load_options(self):
  347. pass
  348. def save_options(self):
  349. pass
  350. class AdvancedTab(TabPanel):
  351. def __init__(self, *args, **kwargs):
  352. super(AdvancedTab, self).__init__(*args, **kwargs)
  353. self.retries_label = wx.StaticText(self, label="Retries")
  354. self.retries_spinctrl = wx.SpinCtrl(self, size=(70, -1))
  355. self.auth_label = wx.StaticText(self, label="Authentication")
  356. self.username_label = wx.StaticText(self, label="Username")
  357. self.username_textctrl = wx.TextCtrl(self, size=(250, -1))
  358. self.password_label = wx.StaticText(self, label="Password")
  359. self.password_textctrl = wx.TextCtrl(self, size=(250, -1), style=wx.TE_PASSWORD)
  360. self.video_pass_label = wx.StaticText(self, label="Video password")
  361. self.video_pass_textctrl = wx.TextCtrl(self, size=(250, -1), style=wx.TE_PASSWORD)
  362. self.network_label = wx.StaticText(self, label="Network")
  363. self.proxy_label = wx.StaticText(self, label="Proxy")
  364. self.proxy_textctrl = wx.TextCtrl(self, size=(250, -1))
  365. self.useragent_label = wx.StaticText(self, label="User agent")
  366. self.useragent_textctrl = wx.TextCtrl(self, size=(250, -1))
  367. self.referer_label = wx.StaticText(self, label="Referer")
  368. self.referer_textctrl = wx.TextCtrl(self, size=(250, -1))
  369. self.logging_label = wx.StaticText(self, label="Logging")
  370. self.enable_log_checkbox = wx.CheckBox(self, label="Enable log")
  371. self.view_log_button = wx.Button(self, label="View")
  372. self.clear_log_button = wx.Button(self, label="Clear")
  373. self._set_layout()
  374. def _set_layout(self):
  375. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  376. vertical_sizer = wx.BoxSizer(wx.VERTICAL)
  377. retries_sizer = wx.BoxSizer(wx.HORIZONTAL)
  378. retries_sizer.AddSpacer((10, -1))
  379. retries_sizer.Add(self.retries_label, flag=wx.ALIGN_CENTER_VERTICAL)
  380. retries_sizer.AddSpacer((20, -1))
  381. retries_sizer.Add(self.retries_spinctrl)
  382. retries_sizer.AddSpacer((10, -1))
  383. vertical_sizer.Add(retries_sizer, flag=wx.ALIGN_RIGHT | wx.TOP, border=5)
  384. vertical_sizer.Add(self.auth_label, flag=wx.TOP, border=5)
  385. username_sizer = wx.BoxSizer(wx.HORIZONTAL)
  386. username_sizer.AddSpacer((10, -1))
  387. username_sizer.Add(self.username_label, flag=wx.ALIGN_CENTER_VERTICAL)
  388. username_sizer.AddSpacer((-1, -1), 1)
  389. username_sizer.Add(self.username_textctrl)
  390. username_sizer.AddSpacer((10, -1))
  391. vertical_sizer.Add(username_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  392. password_sizer = wx.BoxSizer(wx.HORIZONTAL)
  393. password_sizer.AddSpacer((10, -1))
  394. password_sizer.Add(self.password_label, flag=wx.ALIGN_CENTER_VERTICAL)
  395. password_sizer.AddSpacer((-1, -1), 1)
  396. password_sizer.Add(self.password_textctrl)
  397. password_sizer.AddSpacer((10, -1))
  398. vertical_sizer.Add(password_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  399. video_pass_sizer = wx.BoxSizer(wx.HORIZONTAL)
  400. video_pass_sizer.AddSpacer((10, -1))
  401. video_pass_sizer.Add(self.video_pass_label, flag=wx.ALIGN_CENTER_VERTICAL)
  402. video_pass_sizer.AddSpacer((-1, -1), 1)
  403. video_pass_sizer.Add(self.video_pass_textctrl)
  404. video_pass_sizer.AddSpacer((10, -1))
  405. vertical_sizer.Add(video_pass_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  406. vertical_sizer.Add(self.network_label, flag=wx.TOP, border=15)
  407. proxy_sizer = wx.BoxSizer(wx.HORIZONTAL)
  408. proxy_sizer.AddSpacer((10, -1))
  409. proxy_sizer.Add(self.proxy_label, flag=wx.ALIGN_CENTER_VERTICAL)
  410. proxy_sizer.AddSpacer((-1, -1), 1)
  411. proxy_sizer.Add(self.proxy_textctrl)
  412. proxy_sizer.AddSpacer((10, -1))
  413. vertical_sizer.Add(proxy_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  414. useragent_sizer = wx.BoxSizer(wx.HORIZONTAL)
  415. useragent_sizer.AddSpacer((10, -1))
  416. useragent_sizer.Add(self.useragent_label, flag=wx.ALIGN_CENTER_VERTICAL)
  417. useragent_sizer.AddSpacer((-1, -1), 1)
  418. useragent_sizer.Add(self.useragent_textctrl)
  419. useragent_sizer.AddSpacer((10, -1))
  420. vertical_sizer.Add(useragent_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  421. referer_sizer = wx.BoxSizer(wx.HORIZONTAL)
  422. referer_sizer.AddSpacer((10, -1))
  423. referer_sizer.Add(self.referer_label, flag=wx.ALIGN_CENTER_VERTICAL)
  424. referer_sizer.AddSpacer((-1, -1), 1)
  425. referer_sizer.Add(self.referer_textctrl)
  426. referer_sizer.AddSpacer((10, -1))
  427. vertical_sizer.Add(referer_sizer, flag=wx.EXPAND | wx.TOP, border=5)
  428. vertical_sizer.Add(self.logging_label, flag=wx.TOP, border=15)
  429. logging_sizer = wx.BoxSizer(wx.HORIZONTAL)
  430. logging_sizer.AddSpacer((10, -1))
  431. logging_sizer.Add(self.enable_log_checkbox)
  432. logging_sizer.AddSpacer((-1, -1), 1)
  433. logging_sizer.Add(self.view_log_button)
  434. logging_sizer.Add(self.clear_log_button)
  435. logging_sizer.AddSpacer((10, -1))
  436. vertical_sizer.Add(logging_sizer, flag=wx.EXPAND | wx.ALL, border=5)
  437. main_sizer.Add(vertical_sizer, 1, wx.EXPAND | wx.ALL, border=5)
  438. self.SetSizer(main_sizer)
  439. def load_options(self):
  440. pass
  441. def save_options(self):
  442. pass
  443. class ExtraTab(TabPanel):
  444. def __init__(self, *args, **kwargs):
  445. super(ExtraTab, self).__init__(*args, **kwargs)
  446. self.cmdline_args_label = wx.StaticText(self, label="Command line arguments (e.g. --help)")
  447. self.cmdline_args_textctrl = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_LINEWRAP)
  448. self.extra_opts_label = wx.StaticText(self, label="Extra options")
  449. self.ignore_errors_checkbox = wx.CheckBox(self, label="Ignore errors")
  450. self._set_layout()
  451. def _set_layout(self):
  452. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  453. vertical_sizer = wx.BoxSizer(wx.VERTICAL)
  454. vertical_sizer.Add(self.cmdline_args_label)
  455. vertical_sizer.Add(self.cmdline_args_textctrl, 1, wx.EXPAND | wx.ALL, border=5)
  456. vertical_sizer.Add(self.extra_opts_label)
  457. extra_opts_sizer = wx.WrapSizer()
  458. extra_opts_sizer.Add(self.ignore_errors_checkbox)
  459. vertical_sizer.Add(extra_opts_sizer, flag=wx.ALL, border=5)
  460. main_sizer.Add(vertical_sizer, 1, wx.EXPAND | wx.ALL, border=5)
  461. self.SetSizer(main_sizer)
  462. def load_options(self):
  463. pass
  464. def save_options(self):
  465. pass
  466. class LogGUI(wx.Frame):
  467. """Simple window for reading the STDERR.
  468. Attributes:
  469. TITLE (string): Frame title.
  470. FRAME_SIZE (tuple): Tuple that holds the frame size (width, height).
  471. Args:
  472. parent (wx.Window): Frame parent.
  473. """
  474. # REFACTOR move it on widgets module
  475. TITLE = _("Log Viewer")
  476. FRAME_SIZE = (650, 200)
  477. def __init__(self, parent=None):
  478. wx.Frame.__init__(self, parent, title=self.TITLE, size=self.FRAME_SIZE)
  479. panel = wx.Panel(self)
  480. self._text_area = wx.TextCtrl(
  481. panel,
  482. style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL
  483. )
  484. sizer = wx.BoxSizer()
  485. sizer.Add(self._text_area, 1, wx.EXPAND)
  486. panel.SetSizerAndFit(sizer)
  487. def load(self, filename):
  488. """Load file content on the text area. """
  489. if os_path_exists(filename):
  490. self._text_area.LoadFile(filename)