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.

1214 lines
42 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
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
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
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
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
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
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
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
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
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
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
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
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
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
10 years ago
10 years ago
10 years ago
  1. #!/usr/bin/env python2
  2. ''' Contains code for youtube-dlG options frame. '''
  3. from os import name
  4. import wx
  5. from .logmanager import LogGUI
  6. from .version import __version__
  7. from .info import (
  8. __descriptionfull__,
  9. __licensefull__,
  10. __projecturl__,
  11. __appname__,
  12. __author__
  13. )
  14. AUDIO_QUALITY = ['high', 'mid', 'low']
  15. AUDIO_FORMATS = [
  16. "mp3",
  17. "wav",
  18. "aac",
  19. "m4a",
  20. "vorbis"
  21. ]
  22. FORMATS = [
  23. "3gp [176x144]",
  24. "3gp [320x240]",
  25. "flv [400x240]",
  26. "flv [640x360]",
  27. "flv [854x480]",
  28. "webm [640x360]",
  29. "webm [854x480]",
  30. "webm [1280x720]",
  31. "webm [1920x1080]",
  32. "mp4 [640x360]",
  33. "mp4 [1280x720]",
  34. "mp4 [1920x1080]",
  35. "mp4 [4096x3072]",
  36. "mp4 144p (DASH)",
  37. "mp4 240p (DASH)",
  38. "mp4 360p (DASH)",
  39. "mp4 480p (DASH)",
  40. "mp4 720p (DASH)",
  41. "mp4 1080p (DASH)",
  42. "mp4 1440p (DASH)",
  43. "mp4 2160p (DASH)",
  44. "webm 240p (DASH)",
  45. "webm 360p (DASH)",
  46. "webm 480p (DASH)",
  47. "webm 720p (DASH)",
  48. "webm 1080p (DASH)",
  49. "webm 1440p (DASH)",
  50. "webm 2160p (DASH)",
  51. "mp4 360p (3D)",
  52. "mp4 480p (3D)",
  53. "mp4 720p (3D)",
  54. "mp4 1080p (3D)",
  55. "webm 360p (3D)",
  56. "webm 480p (3D)",
  57. "webm 720p (3D)",
  58. "m4a 48k (DASH AUDIO)",
  59. "m4a 128k (DASH AUDIO)",
  60. "m4a 256k (DASH AUDIO)",
  61. "webm 48k (DASH AUDIO)",
  62. "webm 256k (DASH AUDIO)"
  63. ]
  64. SUBS_LANG = [
  65. "English",
  66. "Greek",
  67. "Portuguese",
  68. "French",
  69. "Italian",
  70. "Russian",
  71. "Spanish",
  72. "German"
  73. ]
  74. FILESIZES = [
  75. 'Bytes',
  76. 'Kilobytes',
  77. 'Megabytes',
  78. 'Gigabytes',
  79. 'Terabytes',
  80. 'Petabytes',
  81. 'Exabytes',
  82. 'Zettabytes',
  83. 'Yottabytes'
  84. ]
  85. class OptionsFrame(wx.Frame):
  86. '''
  87. Youtube-dlG options frame.
  88. Params
  89. opt_manager: OptionsManager.OptionsManager object.
  90. parent: Frame parent.
  91. logger: LogManager.LogManager object.
  92. Accessible Methods
  93. reset()
  94. Params: None
  95. Return: None
  96. load_all_options()
  97. Params: None
  98. Return: None
  99. save_all_options()
  100. Params: None
  101. Return: None
  102. '''
  103. FRAME_SIZE = (640, 270)
  104. FRAME_TITLE = "Options"
  105. GENERAL_TAB = "General"
  106. VIDEO_TAB = "Video"
  107. AUDIO_TAB = "Audio"
  108. PLAYLIST_TAB = "Playlist"
  109. OUTPUT_TAB = "Output"
  110. SUBTITLES_TAB = "Subtitles"
  111. FILESYS_TAB = "Filesystem"
  112. SHUTDOWN_TAB = "Shutdown"
  113. AUTH_TAB = "Authentication"
  114. CONNECTION_TAB = "Connection"
  115. LOG_TAB = "Log"
  116. CMD_TAB = "Commands"
  117. def __init__(self, parent):
  118. wx.Frame.__init__(self, parent, title=self.FRAME_TITLE, size=self.FRAME_SIZE)
  119. self.opt_manager = parent.opt_manager
  120. self.log_manager = parent.log_manager
  121. self.app_icon = parent.app_icon
  122. if self.app_icon is not None:
  123. self.SetIcon(self.app_icon)
  124. # Create GUI
  125. panel = wx.Panel(self)
  126. notebook = wx.Notebook(panel)
  127. # Create Tabs
  128. tab_args = (self, notebook)
  129. self.tabs = (
  130. (GeneralTab(*tab_args), self.GENERAL_TAB),
  131. (VideoTab(*tab_args), self.VIDEO_TAB),
  132. (AudioTab(*tab_args), self.AUDIO_TAB),
  133. (PlaylistTab(*tab_args), self.PLAYLIST_TAB),
  134. (OutputTab(*tab_args), self.OUTPUT_TAB),
  135. (SubtitlesTab(*tab_args), self.SUBTITLES_TAB),
  136. (FilesystemTab(*tab_args), self.FILESYS_TAB),
  137. (ShutdownTab(*tab_args), self.SHUTDOWN_TAB),
  138. (AuthenticationTab(*tab_args), self.AUTH_TAB),
  139. (ConnectionTab(*tab_args), self.CONNECTION_TAB),
  140. (LogTab(*tab_args), self.LOG_TAB),
  141. (CMDTab(*tab_args), self.CMD_TAB)
  142. )
  143. # Add tabs on notebook
  144. for tab, label in self.tabs:
  145. notebook.AddPage(tab, label)
  146. sizer = wx.BoxSizer()
  147. sizer.Add(notebook, 1, wx.EXPAND)
  148. panel.SetSizer(sizer)
  149. self.Bind(wx.EVT_CLOSE, self._on_close)
  150. self.load_all_options()
  151. def _on_close(self, event):
  152. ''' Event handler for wx.EVT_CLOSE. '''
  153. self.save_all_options()
  154. self.Hide()
  155. def reset(self):
  156. ''' Reset default options. '''
  157. self.opt_manager.load_default()
  158. self.load_all_options()
  159. def load_all_options(self):
  160. ''' Load tabs options. '''
  161. for tab, _ in self.tabs:
  162. tab.load_options()
  163. def save_all_options(self):
  164. ''' Save tabs options '''
  165. for tab, _ in self.tabs:
  166. tab.save_options()
  167. class TabPanel(wx.Panel):
  168. # Set wx.CheckBox height for Windows & Linux
  169. # so it looks the same on both platforms
  170. CHECKBOX_SIZE = (-1, -1)
  171. if name == 'nt':
  172. CHECKBOX_SIZE = (-1, 25)
  173. BUTTONS_SIZE = (-1, -1)
  174. TEXTCTRL_SIZE = (-1, -1)
  175. SPINCTRL_SIZE = (70, 20)
  176. SIZE_80 = 80
  177. SIZE_50 = 50
  178. SIZE_40 = 40
  179. SIZE_30 = 30
  180. SIZE_20 = 20
  181. SIZE_15 = 15
  182. SIZE_10 = 10
  183. SIZE_5 = 5
  184. def __init__(self, parent, notebook):
  185. wx.Panel.__init__(self, notebook)
  186. self.opt_manager = parent.opt_manager
  187. self.log_manager = parent.log_manager
  188. self.app_icon = parent.app_icon
  189. self.reset_handler = parent.reset
  190. def create_button(self, label, event_handler=None):
  191. button = wx.Button(self, label=label, size=self.BUTTONS_SIZE)
  192. if event_handler is not None:
  193. button.Bind(wx.EVT_BUTTON, event_handler)
  194. return button
  195. def create_checkbox(self, label, event_handler=None):
  196. checkbox = wx.CheckBox(self, label=label, size=self.CHECKBOX_SIZE)
  197. if event_handler is not None:
  198. checkbox.Bind(wx.EVT_CHECKBOX, event_handler)
  199. return checkbox
  200. def create_textctrl(self, style=None):
  201. if style is None:
  202. textctrl = wx.TextCtrl(self, size=self.TEXTCTRL_SIZE)
  203. else:
  204. textctrl = wx.TextCtrl(self, size=self.TEXTCTRL_SIZE, style=style)
  205. return textctrl
  206. def create_combobox(self, choices, size=(-1, -1), event_handler=None):
  207. combobox = wx.ComboBox(self, choices=choices, size=size)
  208. if event_handler is not None:
  209. combobox.Bind(wx.EVT_COMBOBOX, event_handler)
  210. return combobox
  211. def create_dirdialog(self, label):
  212. dlg = wx.DirDialog(self, label)
  213. return dlg
  214. def create_radiobutton(self, label, event_handler=None, style=None):
  215. if style is None:
  216. radiobutton = wx.RadioButton(self, label=label)
  217. else:
  218. radiobutton = wx.RadioButton(self, label=label, style=style)
  219. if event_handler is not None:
  220. radiobutton.Bind(wx.EVT_RADIOBUTTON, event_handler)
  221. return radiobutton
  222. def create_spinctrl(self, spin_range=(0, 999)):
  223. spinctrl = wx.SpinCtrl(self, size=self.SPINCTRL_SIZE)
  224. spinctrl.SetRange(*spin_range)
  225. return spinctrl
  226. def create_statictext(self, label):
  227. statictext = wx.StaticText(self, label=label)
  228. return statictext
  229. def create_popup(self, text, title, style):
  230. ''' Create popup. '''
  231. wx.MessageBox(text, title, style)
  232. def _set_sizer(self):
  233. pass
  234. def _disable_items(self):
  235. pass
  236. def load_options(self):
  237. pass
  238. def save_options(self):
  239. pass
  240. class LogTab(TabPanel):
  241. '''
  242. Options frame log tab panel.
  243. Params
  244. parent: wx.Panel parent.
  245. logger: LogManager.LogManager.object.
  246. '''
  247. ENABLE_LABEL = "Enable Log"
  248. WRITE_LABEL = "Write Time"
  249. CLEAR_LABEL = "Clear Log"
  250. VIEW_LABEL = "View Log"
  251. PATH_LABEL = "Path: {0}"
  252. LOGSIZE_LABEL = "Log Size: {0} Bytes"
  253. RESTART_LABEL = "Restart"
  254. RESTART_MSG = "Please restart {0}"
  255. def __init__(self, *args, **kwargs):
  256. super(LogTab, self).__init__(*args, **kwargs)
  257. self.enable_checkbox = self.create_checkbox(self.ENABLE_LABEL, self._on_enable)
  258. self.time_checkbox = self.create_checkbox(self.WRITE_LABEL, self._on_time)
  259. self.clear_button = self.create_button(self.CLEAR_LABEL, self._on_clear)
  260. self.view_button = self.create_button(self.VIEW_LABEL, self._on_view)
  261. self.log_path = self.create_statictext(self.PATH_LABEL.format(self._get_logpath()))
  262. self.log_size = self.create_statictext(self.LOGSIZE_LABEL.format(self._get_logsize()))
  263. self._set_sizer()
  264. self._disable_items()
  265. def _set_sizer(self):
  266. main_sizer = wx.BoxSizer(wx.VERTICAL)
  267. main_sizer.AddSpacer(self.SIZE_20)
  268. main_sizer.Add(self.enable_checkbox, flag=wx.ALIGN_CENTER_HORIZONTAL)
  269. main_sizer.AddSpacer(self.SIZE_5)
  270. main_sizer.Add(self.time_checkbox, flag=wx.ALIGN_CENTER_HORIZONTAL)
  271. main_sizer.AddSpacer(self.SIZE_15)
  272. buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
  273. buttons_sizer.Add(self.clear_button)
  274. buttons_sizer.AddSpacer(self.SIZE_20)
  275. buttons_sizer.Add(self.view_button)
  276. main_sizer.Add(buttons_sizer, flag=wx.ALIGN_CENTER_HORIZONTAL)
  277. main_sizer.AddSpacer(self.SIZE_20)
  278. main_sizer.Add(self.log_path, flag=wx.ALIGN_CENTER_HORIZONTAL)
  279. main_sizer.AddSpacer(self.SIZE_10)
  280. main_sizer.Add(self.log_size, flag=wx.ALIGN_CENTER_HORIZONTAL)
  281. self.SetSizer(main_sizer)
  282. def _disable_items(self):
  283. if self.log_manager is None:
  284. self.time_checkbox.Disable()
  285. self.clear_button.Disable()
  286. self.view_button.Disable()
  287. self.log_path.Hide()
  288. self.log_size.Hide()
  289. def _get_logpath(self):
  290. if self.log_manager is None:
  291. return ''
  292. return self.log_manager.log_file
  293. def _get_logsize(self):
  294. if self.log_manager is None:
  295. return 0
  296. return self.log_manager.log_size()
  297. def _set_logsize(self):
  298. self.log_size.SetLabel(self.LOGSIZE_LABEL.format(self._get_logsize()))
  299. def _on_time(self, event):
  300. ''' Event handler for self.time_checkbox. '''
  301. self.log_manager.add_time = self.time_checkbox.GetValue()
  302. def _on_enable(self, event):
  303. ''' Event handler for self.enable_checkbox. '''
  304. self.create_popup(self.RESTART_MSG.format(__appname__),
  305. self.RESTART_LABEL,
  306. wx.OK | wx.ICON_INFORMATION)
  307. def _on_clear(self, event):
  308. ''' Event handler for self.clear_button. '''
  309. self.log_manager.clear()
  310. self.log_size.SetLabel(self.LOGSIZE_LABEL.format(self._get_logsize()))
  311. def _on_view(self, event):
  312. ''' Event handler for self.view_button. '''
  313. logger_gui = LogGUI(self)
  314. logger_gui.Show()
  315. logger_gui.load(self.log_manager.log_file)
  316. def load_options(self):
  317. ''' Load panel options from OptionsHandler object. '''
  318. self.enable_checkbox.SetValue(self.opt_manager.options['enable_log'])
  319. self.time_checkbox.SetValue(self.opt_manager.options['log_time'])
  320. self._set_logsize()
  321. def save_options(self):
  322. ''' Save panel options to OptionsHandler object. '''
  323. self.opt_manager.options['enable_log'] = self.enable_checkbox.GetValue()
  324. self.opt_manager.options['log_time'] = self.time_checkbox.GetValue()
  325. class ShutdownTab(TabPanel):
  326. '''
  327. Options frame shutdown tab panel.
  328. Params
  329. parent: wx.Panel parent.
  330. '''
  331. TEXTCTRL_SIZE = (250, 25)
  332. SHUTDOWN_LABEL = "Shutdown when finished"
  333. SUDO_LABEL = "SUDO password"
  334. def __init__(self, *args, **kwargs):
  335. super(ShutdownTab, self).__init__(*args, **kwargs)
  336. self.shutdown_checkbox = self.create_checkbox(self.SHUTDOWN_LABEL, self._on_shutdown_check)
  337. self.sudo_text = self.create_statictext(self.SUDO_LABEL)
  338. self.sudo_box = self.create_textctrl(wx.TE_PASSWORD)
  339. self._set_sizer()
  340. self._disable_items()
  341. def _disable_items(self):
  342. if name == 'nt':
  343. self.sudo_text.Hide()
  344. self.sudo_box.Hide()
  345. def _set_sizer(self):
  346. main_sizer = wx.BoxSizer(wx.VERTICAL)
  347. main_sizer.AddSpacer(self.SIZE_40)
  348. main_sizer.Add(self.shutdown_checkbox, flag=wx.ALIGN_CENTER_HORIZONTAL)
  349. main_sizer.AddSpacer(self.SIZE_20)
  350. main_sizer.Add(self.sudo_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  351. main_sizer.AddSpacer(self.SIZE_5)
  352. main_sizer.Add(self.sudo_box, flag=wx.ALIGN_CENTER_HORIZONTAL)
  353. self.SetSizer(main_sizer)
  354. def _on_shutdown_check(self, event):
  355. ''' Event handler for self.shutdown_checkbox. '''
  356. self.sudo_box.Enable(self.shutdown_checkbox.GetValue())
  357. def load_options(self):
  358. ''' Load panel options from OptionsHandler object. '''
  359. self.shutdown_checkbox.SetValue(self.opt_manager.options['shutdown'])
  360. self.sudo_box.SetValue(self.opt_manager.options['sudo_password'])
  361. self._on_shutdown_check(None)
  362. def save_options(self):
  363. ''' Save panel options to OptionsHandler object. '''
  364. self.opt_manager.options['shutdown'] = self.shutdown_checkbox.GetValue()
  365. self.opt_manager.options['sudo_password'] = self.sudo_box.GetValue()
  366. class PlaylistTab(TabPanel):
  367. '''
  368. Options frame playlist tab panel.
  369. Params
  370. parent: wx.Panel parent.
  371. '''
  372. START_LABEL = "Playlist Start"
  373. STOP_LABEL = "Playlist Stop"
  374. MAX_LABEL = "Max Downloads"
  375. def __init__(self, *args, **kwargs):
  376. super(PlaylistTab, self).__init__(*args, **kwargs)
  377. self.start_spinctrl = self.create_spinctrl((1, 999))
  378. self.stop_spinctrl = self.create_spinctrl()
  379. self.max_spinctrl = self.create_spinctrl()
  380. self.start_text = self.create_statictext(self.START_LABEL)
  381. self.stop_text = self.create_statictext(self.STOP_LABEL)
  382. self.max_text = self.create_statictext(self.MAX_LABEL)
  383. self._set_sizer()
  384. def _set_sizer(self):
  385. main_sizer = wx.BoxSizer(wx.VERTICAL)
  386. main_sizer.AddSpacer(self.SIZE_20)
  387. main_sizer.Add(self.start_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  388. main_sizer.AddSpacer(self.SIZE_5)
  389. main_sizer.Add(self.start_spinctrl, flag=wx.ALIGN_CENTER_HORIZONTAL)
  390. main_sizer.AddSpacer(self.SIZE_15)
  391. main_sizer.Add(self.stop_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  392. main_sizer.AddSpacer(self.SIZE_5)
  393. main_sizer.Add(self.stop_spinctrl, flag=wx.ALIGN_CENTER_HORIZONTAL)
  394. main_sizer.AddSpacer(self.SIZE_15)
  395. main_sizer.Add(self.max_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  396. main_sizer.AddSpacer(self.SIZE_5)
  397. main_sizer.Add(self.max_spinctrl, flag=wx.ALIGN_CENTER_HORIZONTAL)
  398. self.SetSizer(main_sizer)
  399. def load_options(self):
  400. ''' Load panel options from OptionsHandler object. '''
  401. self.start_spinctrl.SetValue(self.opt_manager.options['playlist_start'])
  402. self.stop_spinctrl.SetValue(self.opt_manager.options['playlist_end'])
  403. self.max_spinctrl.SetValue(self.opt_manager.options['max_downloads'])
  404. def save_options(self):
  405. ''' Save panel options to OptionsHandler object. '''
  406. self.opt_manager.options['playlist_start'] = self.start_spinctrl.GetValue()
  407. self.opt_manager.options['playlist_end'] = self.stop_spinctrl.GetValue()
  408. self.opt_manager.options['max_downloads'] = self.max_spinctrl.GetValue()
  409. class ConnectionTab(TabPanel):
  410. '''
  411. Options frame connection tab panel.
  412. Params
  413. parent: wx.Panel parent.
  414. '''
  415. SPINCTRL_SIZE = (50, -1)
  416. RETRIES_LABEL = "Retries"
  417. USERAGENT_LABEL = "User Agent"
  418. REF_LABEL = "Referer"
  419. PROXY_LABEL = "Proxy"
  420. def __init__(self, *args, **kwargs):
  421. super(ConnectionTab, self).__init__(*args, **kwargs)
  422. # Create components
  423. self.retries_spinctrl = self.create_spinctrl((1, 99))
  424. self.useragent_box = self.create_textctrl()
  425. self.referer_box = self.create_textctrl()
  426. self.proxy_box = self.create_textctrl()
  427. self.retries_text = self.create_statictext(self.RETRIES_LABEL)
  428. self.useragent_text = self.create_statictext(self.USERAGENT_LABEL)
  429. self.referer_text = self.create_statictext(self.REF_LABEL)
  430. self.proxy_text = self.create_statictext(self.PROXY_LABEL)
  431. self._set_sizer()
  432. def _set_sizer(self):
  433. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  434. vertical_sizer = wx.BoxSizer(wx.VERTICAL)
  435. vertical_sizer.AddSpacer(self.SIZE_10)
  436. retries_sizer = wx.BoxSizer(wx.HORIZONTAL)
  437. retries_sizer.Add(self.retries_text)
  438. retries_sizer.AddSpacer(self.SIZE_5)
  439. retries_sizer.Add(self.retries_spinctrl)
  440. vertical_sizer.Add(retries_sizer)
  441. vertical_sizer.AddSpacer(self.SIZE_10)
  442. vertical_sizer.Add(self.useragent_text)
  443. vertical_sizer.AddSpacer(self.SIZE_5)
  444. vertical_sizer.Add(self.useragent_box, flag=wx.EXPAND)
  445. vertical_sizer.AddSpacer(self.SIZE_10)
  446. vertical_sizer.Add(self.referer_text)
  447. vertical_sizer.AddSpacer(self.SIZE_5)
  448. vertical_sizer.Add(self.referer_box, flag=wx.EXPAND)
  449. vertical_sizer.AddSpacer(self.SIZE_10)
  450. vertical_sizer.Add(self.proxy_text)
  451. vertical_sizer.AddSpacer(self.SIZE_5)
  452. vertical_sizer.Add(self.proxy_box, flag=wx.EXPAND)
  453. main_sizer.AddSpacer(self.SIZE_10)
  454. main_sizer.Add(vertical_sizer, 1, flag=wx.RIGHT, border=self.SIZE_40)
  455. self.SetSizer(main_sizer)
  456. def load_options(self):
  457. ''' Load panel options from OptionsHandler object. '''
  458. self.proxy_box.SetValue(self.opt_manager.options['proxy'])
  459. self.referer_box.SetValue(self.opt_manager.options['referer'])
  460. self.retries_spinctrl.SetValue(self.opt_manager.options['retries'])
  461. self.useragent_box.SetValue(self.opt_manager.options['user_agent'])
  462. def save_options(self):
  463. ''' Save panel options to OptionsHandler object. '''
  464. self.opt_manager.options['proxy'] = self.proxy_box.GetValue()
  465. self.opt_manager.options['referer'] = self.referer_box.GetValue()
  466. self.opt_manager.options['retries'] = self.retries_spinctrl.GetValue()
  467. self.opt_manager.options['user_agent'] = self.useragent_box.GetValue()
  468. class AuthenticationTab(TabPanel):
  469. '''
  470. Options frame authentication tab panel.
  471. Params
  472. parent: wx.Panel parent.
  473. '''
  474. TEXTCTRL_SIZE = (250, 25)
  475. USERNAME_LABEL = "Username"
  476. PASSWORD_LABEL = "Password"
  477. VIDEOPASS_LABEL = "Video Password (vimeo, smotri)"
  478. def __init__(self, *args, **kwargs):
  479. super(AuthenticationTab, self).__init__(*args, **kwargs)
  480. self.username_box = self.create_textctrl()
  481. self.password_box = self.create_textctrl(wx.TE_PASSWORD)
  482. self.videopass_box = self.create_textctrl(wx.TE_PASSWORD)
  483. self.username_text = self.create_statictext(self.USERNAME_LABEL)
  484. self.password_text = self.create_statictext(self.PASSWORD_LABEL)
  485. self.videopass_text = self.create_statictext(self.VIDEOPASS_LABEL)
  486. self._set_sizer()
  487. def _set_sizer(self):
  488. main_sizer = wx.BoxSizer(wx.VERTICAL)
  489. main_sizer.AddSpacer(self.SIZE_15)
  490. main_sizer.Add(self.username_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  491. main_sizer.AddSpacer(self.SIZE_5)
  492. main_sizer.Add(self.username_box, flag=wx.ALIGN_CENTER_HORIZONTAL)
  493. main_sizer.AddSpacer(self.SIZE_15)
  494. main_sizer.Add(self.password_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  495. main_sizer.AddSpacer(self.SIZE_5)
  496. main_sizer.Add(self.password_box, flag=wx.ALIGN_CENTER_HORIZONTAL)
  497. main_sizer.AddSpacer(self.SIZE_15)
  498. main_sizer.Add(self.videopass_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  499. main_sizer.AddSpacer(self.SIZE_5)
  500. main_sizer.Add(self.videopass_box, flag=wx.ALIGN_CENTER_HORIZONTAL)
  501. self.SetSizer(main_sizer)
  502. def load_options(self):
  503. ''' Load panel options from OptionsHandler object. '''
  504. self.username_box.SetValue(self.opt_manager.options['username'])
  505. self.password_box.SetValue(self.opt_manager.options['password'])
  506. self.videopass_box.SetValue(self.opt_manager.options['video_password'])
  507. def save_options(self):
  508. ''' Save panel options to OptionsHandler object. '''
  509. self.opt_manager.options['username'] = self.username_box.GetValue()
  510. self.opt_manager.options['password'] = self.password_box.GetValue()
  511. self.opt_manager.options['video_password'] = self.videopass_box.GetValue()
  512. class AudioTab(TabPanel):
  513. '''
  514. Options frame audio tab panel.
  515. Params
  516. parent: wx.Panel parent.
  517. '''
  518. TO_AUDIO_LABEL = "Convert to Audio"
  519. KEEP_VIDEO_LABEL = "Keep Video"
  520. AUDIO_FORMAT_LABEL = "Audio Format"
  521. AUDIO_QUALITY_LABEL = "Audio Quality"
  522. def __init__(self, *args, **kwargs):
  523. super(AudioTab, self).__init__(*args, **kwargs)
  524. self.to_audio_checkbox = self.create_checkbox(self.TO_AUDIO_LABEL, self._on_audio_check)
  525. self.keep_video_checkbox = self.create_checkbox(self.KEEP_VIDEO_LABEL)
  526. self.audioformat_combo = self.create_combobox(AUDIO_FORMATS, (160, 30))
  527. self.audioquality_combo = self.create_combobox(AUDIO_QUALITY, (80, 25))
  528. self.audioformat_text = self.create_statictext(self.AUDIO_FORMAT_LABEL)
  529. self.audioquality_text = self.create_statictext(self.AUDIO_QUALITY_LABEL)
  530. self._set_sizer()
  531. def _set_sizer(self):
  532. main_sizer = wx.BoxSizer(wx.VERTICAL)
  533. main_sizer.AddSpacer(self.SIZE_15)
  534. main_sizer.Add(self.to_audio_checkbox, flag=wx.ALIGN_CENTER_HORIZONTAL)
  535. main_sizer.AddSpacer(self.SIZE_5)
  536. main_sizer.Add(self.keep_video_checkbox, flag=wx.ALIGN_CENTER_HORIZONTAL)
  537. main_sizer.AddSpacer(self.SIZE_10)
  538. main_sizer.Add(self.audioformat_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  539. main_sizer.AddSpacer(self.SIZE_5)
  540. main_sizer.Add(self.audioformat_combo, flag=wx.ALIGN_CENTER_HORIZONTAL)
  541. main_sizer.AddSpacer(self.SIZE_10)
  542. main_sizer.Add(self.audioquality_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  543. main_sizer.AddSpacer(self.SIZE_5)
  544. main_sizer.Add(self.audioquality_combo, flag=wx.ALIGN_CENTER_HORIZONTAL)
  545. self.SetSizer(main_sizer)
  546. def _on_audio_check(self, event):
  547. ''' Event handler for self.to_audio_checkbox. '''
  548. self.audioformat_combo.Enable(self.to_audio_checkbox.GetValue())
  549. self.audioquality_combo.Enable(self.to_audio_checkbox.GetValue())
  550. def load_options(self):
  551. ''' Load panel options from OptionsHandler object. '''
  552. self.to_audio_checkbox.SetValue(self.opt_manager.options['to_audio'])
  553. self.keep_video_checkbox.SetValue(self.opt_manager.options['keep_video'])
  554. self.audioformat_combo.SetValue(self.opt_manager.options['audio_format'])
  555. self.audioquality_combo.SetValue(self.opt_manager.options['audio_quality'])
  556. self._on_audio_check(None)
  557. def save_options(self):
  558. ''' Save panel options to OptionsHandler object. '''
  559. self.opt_manager.options['to_audio'] = self.to_audio_checkbox.GetValue()
  560. self.opt_manager.options['keep_video'] = self.keep_video_checkbox.GetValue()
  561. self.opt_manager.options['audio_format'] = self.audioformat_combo.GetValue()
  562. self.opt_manager.options['audio_quality'] = self.audioquality_combo.GetValue()
  563. class VideoTab(TabPanel):
  564. '''
  565. Options frame video tab panel.
  566. Params
  567. parent: wx.Panel parent.
  568. '''
  569. VIDEO_FORMATS = ["default"] + FORMATS
  570. SECOND_VIDEO_FORMATS = ["none"] + FORMATS
  571. COMBOBOX_SIZE = (200, 30)
  572. VIDEO_FORMAT_LABEL = "Video Format"
  573. SEC_VIDEOFORMAT_LABEL = "Mix Format"
  574. def __init__(self, *args, **kwargs):
  575. super(VideoTab, self).__init__(*args, **kwargs)
  576. self.videoformat_combo = self.create_combobox(self.VIDEO_FORMATS,
  577. self.COMBOBOX_SIZE,
  578. self._on_videoformat)
  579. self.sec_videoformat_combo = self.create_combobox(self.SECOND_VIDEO_FORMATS,
  580. self.COMBOBOX_SIZE)
  581. self.videoformat_text = self.create_statictext(self.VIDEO_FORMAT_LABEL)
  582. self.sec_videoformat_text = self.create_statictext(self.SEC_VIDEOFORMAT_LABEL)
  583. self._set_sizer()
  584. def _set_sizer(self):
  585. main_sizer = wx.BoxSizer(wx.VERTICAL)
  586. main_sizer.AddSpacer(self.SIZE_30)
  587. main_sizer.Add(self.videoformat_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  588. main_sizer.AddSpacer(self.SIZE_5)
  589. main_sizer.Add(self.videoformat_combo, flag=wx.ALIGN_CENTER_HORIZONTAL)
  590. main_sizer.AddSpacer(self.SIZE_10)
  591. main_sizer.Add(self.sec_videoformat_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  592. main_sizer.AddSpacer(self.SIZE_5)
  593. main_sizer.Add(self.sec_videoformat_combo, flag=wx.ALIGN_CENTER_HORIZONTAL)
  594. self.SetSizer(main_sizer)
  595. def _on_videoformat(self, event):
  596. ''' Event handler for self.videoformat_combo. '''
  597. condition = (self.videoformat_combo.GetValue() != 'default')
  598. self.sec_videoformat_combo.Enable(condition)
  599. def load_options(self):
  600. ''' Load panel options from OptionsHandler object. '''
  601. self.videoformat_combo.SetValue(self.opt_manager.options['video_format'])
  602. self.sec_videoformat_combo.SetValue(self.opt_manager.options['second_video_format'])
  603. self._on_videoformat(None)
  604. def save_options(self):
  605. ''' Save panel options to OptionsHandler object. '''
  606. self.opt_manager.options['video_format'] = self.videoformat_combo.GetValue()
  607. self.opt_manager.options['second_video_format'] = self.sec_videoformat_combo.GetValue()
  608. class OutputTab(TabPanel):
  609. '''
  610. Options frame output tab panel.
  611. Params
  612. parent: wx.Panel parent.
  613. '''
  614. TEXTCTRL_SIZE = (300, 20)
  615. RESTRICT_LABEL = "Restrict filenames (ASCII)"
  616. ID_AS_NAME = "ID as Name"
  617. TITLE_AS_NAME = "Title as Name"
  618. CUST_TITLE = "Custom Template (youtube-dl)"
  619. def __init__(self, *args, **kwargs):
  620. super(OutputTab, self).__init__(*args, **kwargs)
  621. self.res_names_checkbox = self.create_checkbox(self.RESTRICT_LABEL)
  622. self.id_rbtn = self.create_radiobutton(self.ID_AS_NAME, self._on_pick, wx.RB_GROUP)
  623. self.title_rbtn = self.create_radiobutton(self.TITLE_AS_NAME, self._on_pick)
  624. self.custom_rbtn = self.create_radiobutton(self.CUST_TITLE, self._on_pick)
  625. self.title_template = self.create_textctrl()
  626. self._set_sizer()
  627. def _set_sizer(self):
  628. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  629. vertical_sizer = wx.BoxSizer(wx.VERTICAL)
  630. vertical_sizer.AddSpacer(self.SIZE_15)
  631. vertical_sizer.Add(self.res_names_checkbox)
  632. vertical_sizer.AddSpacer(self.SIZE_5)
  633. vertical_sizer.Add(self.id_rbtn)
  634. vertical_sizer.AddSpacer(self.SIZE_5)
  635. vertical_sizer.Add(self.title_rbtn)
  636. vertical_sizer.AddSpacer(self.SIZE_5)
  637. vertical_sizer.Add(self.custom_rbtn)
  638. vertical_sizer.AddSpacer(self.SIZE_10)
  639. vertical_sizer.Add(self.title_template)
  640. main_sizer.Add(vertical_sizer, flag=wx.LEFT, border=self.SIZE_5)
  641. self.SetSizer(main_sizer)
  642. def _on_pick(self, event):
  643. self.title_template.Enable(self.custom_rbtn.GetValue())
  644. def _get_output_format(self):
  645. ''' Return output_format. '''
  646. if self.id_rbtn.GetValue():
  647. return 'id'
  648. elif self.title_rbtn.GetValue():
  649. return 'title'
  650. elif self.custom_rbtn.GetValue():
  651. return 'custom'
  652. def _set_output_format(self, output_format):
  653. if output_format == 'id':
  654. self.id_rbtn.SetValue(True)
  655. elif output_format == 'title':
  656. self.title_rbtn.SetValue(True)
  657. elif output_format == 'custom':
  658. self.custom_rbtn.SetValue(True)
  659. def load_options(self):
  660. ''' Load panel options from OptionsHandler object. '''
  661. self._set_output_format(self.opt_manager.options['output_format'])
  662. self.title_template.SetValue(self.opt_manager.options['output_template'])
  663. self.res_names_checkbox.SetValue(self.opt_manager.options['restrict_filenames'])
  664. self._on_pick(None)
  665. def save_options(self):
  666. ''' Save panel options to OptionsHandler object. '''
  667. self.opt_manager.options['output_format'] = self._get_output_format()
  668. self.opt_manager.options['output_template'] = self.title_template.GetValue()
  669. self.opt_manager.options['restrict_filenames'] = self.res_names_checkbox.GetValue()
  670. class FilesystemTab(TabPanel):
  671. '''
  672. Options frame filesystem tab panel.
  673. Params
  674. parent: wx.Panel parent.
  675. '''
  676. IGN_ERR_LABEL = "Ignore Errors"
  677. OPEN_DIR_LABEL = "Open destination folder"
  678. WRT_INFO_LABEL = "Write info to (.json) file"
  679. WRT_DESC_LABEL = "Write description to file"
  680. WRT_THMB_LABEL = "Write thumbnail to disk"
  681. FILESIZE_LABEL = "Filesize"
  682. MIN_LABEL = "Min"
  683. MAX_LABEL = "Max"
  684. def __init__(self, *args, **kwargs):
  685. super(FilesystemTab, self).__init__(*args, **kwargs)
  686. self.ign_err_checkbox = self.create_checkbox(self.IGN_ERR_LABEL)
  687. self.open_dir_checkbox = self.create_checkbox(self.OPEN_DIR_LABEL)
  688. self.write_info_checkbox = self.create_checkbox(self.WRT_INFO_LABEL)
  689. self.write_desc_checkbox = self.create_checkbox(self.WRT_DESC_LABEL)
  690. self.write_thumbnail_checkbox = self.create_checkbox(self.WRT_THMB_LABEL)
  691. self.min_filesize_spinner = self.create_spinctrl((0, 1024))
  692. self.max_filesize_spinner = self.create_spinctrl((0, 1024))
  693. self.min_filesize_combo = self.create_combobox(FILESIZES)
  694. self.max_filesize_combo = self.create_combobox(FILESIZES)
  695. self.min_text = self.create_statictext(self.MIN_LABEL)
  696. self.max_text = self.create_statictext(self.MAX_LABEL)
  697. self._set_sizer()
  698. def _set_sizer(self):
  699. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  700. main_sizer.Add(self._set_left_sizer(), 1, wx.LEFT, border=self.SIZE_5)
  701. main_sizer.Add(self._set_right_sizer(), 1, wx.EXPAND)
  702. self.SetSizer(main_sizer)
  703. def _set_left_sizer(self):
  704. ''' Set left BoxSizer. '''
  705. sizer = wx.BoxSizer(wx.VERTICAL)
  706. sizer.AddSpacer(self.SIZE_15)
  707. sizer.Add(self.ign_err_checkbox)
  708. sizer.AddSpacer(self.SIZE_5)
  709. sizer.Add(self.open_dir_checkbox)
  710. sizer.AddSpacer(self.SIZE_5)
  711. sizer.Add(self.write_desc_checkbox)
  712. sizer.AddSpacer(self.SIZE_5)
  713. sizer.Add(self.write_thumbnail_checkbox)
  714. sizer.AddSpacer(self.SIZE_5)
  715. sizer.Add(self.write_info_checkbox)
  716. return sizer
  717. def _set_right_sizer(self):
  718. ''' Set right BoxSizer. '''
  719. static_box = wx.StaticBox(self, label=self.FILESIZE_LABEL)
  720. sizer = wx.StaticBoxSizer(static_box, wx.VERTICAL)
  721. sizer.AddSpacer(self.SIZE_20)
  722. sizer.Add(self.min_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  723. sizer.AddSpacer(self.SIZE_5)
  724. hor_sizer = wx.BoxSizer(wx.HORIZONTAL)
  725. hor_sizer.Add(self.min_filesize_spinner)
  726. hor_sizer.AddSpacer(self.SIZE_10)
  727. hor_sizer.Add(self.min_filesize_combo)
  728. sizer.Add(hor_sizer, flag=wx.ALIGN_CENTER_HORIZONTAL)
  729. sizer.AddSpacer(self.SIZE_10)
  730. sizer.Add(self.max_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  731. sizer.AddSpacer(self.SIZE_5)
  732. hor_sizer = wx.BoxSizer(wx.HORIZONTAL)
  733. hor_sizer.Add(self.max_filesize_spinner)
  734. hor_sizer.AddSpacer(self.SIZE_10)
  735. hor_sizer.Add(self.max_filesize_combo)
  736. sizer.Add(hor_sizer, flag=wx.ALIGN_CENTER_HORIZONTAL)
  737. return sizer
  738. def load_options(self):
  739. ''' Load panel options from OptionsHandler object. '''
  740. self.open_dir_checkbox.SetValue(self.opt_manager.options['open_dl_dir'])
  741. self.write_info_checkbox.SetValue(self.opt_manager.options['write_info'])
  742. self.ign_err_checkbox.SetValue(self.opt_manager.options['ignore_errors'])
  743. self.write_desc_checkbox.SetValue(self.opt_manager.options['write_description'])
  744. self.write_thumbnail_checkbox.SetValue(self.opt_manager.options['write_thumbnail'])
  745. self.min_filesize_spinner.SetValue(self.opt_manager.options['min_filesize'])
  746. self.max_filesize_spinner.SetValue(self.opt_manager.options['max_filesize'])
  747. self.min_filesize_combo.SetValue(self.opt_manager.options['min_filesize_unit'])
  748. self.max_filesize_combo.SetValue(self.opt_manager.options['max_filesize_unit'])
  749. def save_options(self):
  750. ''' Save panel options to OptionsHandler object. '''
  751. self.opt_manager.options['write_thumbnail'] = self.write_thumbnail_checkbox.GetValue()
  752. self.opt_manager.options['write_description'] = self.write_desc_checkbox.GetValue()
  753. self.opt_manager.options['ignore_errors'] = self.ign_err_checkbox.GetValue()
  754. self.opt_manager.options['write_info'] = self.write_info_checkbox.GetValue()
  755. self.opt_manager.options['open_dl_dir'] = self.open_dir_checkbox.GetValue()
  756. self.opt_manager.options['min_filesize'] = self.min_filesize_spinner.GetValue()
  757. self.opt_manager.options['max_filesize'] = self.max_filesize_spinner.GetValue()
  758. self.opt_manager.options['min_filesize_unit'] = self.min_filesize_combo.GetValue()
  759. self.opt_manager.options['max_filesize_unit'] = self.max_filesize_combo.GetValue()
  760. class SubtitlesTab(TabPanel):
  761. '''
  762. Options frame subtitles tab panel.
  763. Params
  764. parent: wx.Panel parent.
  765. '''
  766. DL_SUBS_LABEL = "Download subtitle file by language"
  767. DL_ALL_SUBS_LABEL = "Download all available subtitles"
  768. DL_AUTO_SUBS_LABEL = "Download automatic subtitle file (YOUTUBE ONLY)"
  769. EMBED_SUBS_LABEL = "Embed subtitles in the video (only for mp4 videos)"
  770. SUBS_LANG_LABEL = "Subtitles Language"
  771. def __init__(self, *args, **kwargs):
  772. super(SubtitlesTab, self).__init__(*args, **kwargs)
  773. # Change those to radiobuttons
  774. self.write_subs_checkbox = self.create_checkbox(self.DL_SUBS_LABEL, self._on_subs_pick)
  775. self.write_all_subs_checkbox = self.create_checkbox(self.DL_ALL_SUBS_LABEL, self._on_subs_pick)
  776. self.write_auto_subs_checkbox = self.create_checkbox(self.DL_AUTO_SUBS_LABEL, self._on_subs_pick)
  777. self.embed_subs_checkbox = self.create_checkbox(self.EMBED_SUBS_LABEL)
  778. self.subs_lang_combo = self.create_combobox(SUBS_LANG, (140, 30))
  779. self.subs_lang_text = self.create_statictext(self.SUBS_LANG_LABEL)
  780. self._set_sizer()
  781. self._disable_items()
  782. def _disable_items(self):
  783. self.embed_subs_checkbox.Disable()
  784. self.subs_lang_combo.Disable()
  785. def _set_sizer(self):
  786. main_sizer = wx.BoxSizer(wx.HORIZONTAL)
  787. vertical_sizer = wx.BoxSizer(wx.VERTICAL)
  788. vertical_sizer.AddSpacer(self.SIZE_15)
  789. vertical_sizer.Add(self.write_subs_checkbox)
  790. vertical_sizer.AddSpacer(self.SIZE_5)
  791. vertical_sizer.Add(self.write_all_subs_checkbox)
  792. vertical_sizer.AddSpacer(self.SIZE_5)
  793. vertical_sizer.Add(self.write_auto_subs_checkbox)
  794. vertical_sizer.AddSpacer(self.SIZE_5)
  795. vertical_sizer.Add(self.embed_subs_checkbox)
  796. vertical_sizer.AddSpacer(self.SIZE_10)
  797. vertical_sizer.Add(self.subs_lang_text, flag=wx.LEFT, border=self.SIZE_5)
  798. vertical_sizer.AddSpacer(self.SIZE_5)
  799. vertical_sizer.Add(self.subs_lang_combo, flag=wx.LEFT, border=self.SIZE_10)
  800. main_sizer.Add(vertical_sizer, flag=wx.LEFT, border=self.SIZE_5)
  801. self.SetSizer(main_sizer)
  802. def _on_subs_pick(self, event):
  803. if self.write_subs_checkbox.GetValue():
  804. self.write_all_subs_checkbox.Disable()
  805. self.write_auto_subs_checkbox.Disable()
  806. self.embed_subs_checkbox.Enable()
  807. self.subs_lang_combo.Enable()
  808. elif self.write_all_subs_checkbox.GetValue():
  809. self.write_subs_checkbox.Disable()
  810. self.write_auto_subs_checkbox.Disable()
  811. elif self.write_auto_subs_checkbox.GetValue():
  812. self.write_subs_checkbox.Disable()
  813. self.write_all_subs_checkbox.Disable()
  814. self.embed_subs_checkbox.Enable()
  815. else:
  816. self.embed_subs_checkbox.Disable()
  817. self.embed_subs_checkbox.SetValue(False)
  818. self.subs_lang_combo.Disable()
  819. self.write_subs_checkbox.Enable()
  820. self.write_all_subs_checkbox.Enable()
  821. self.write_auto_subs_checkbox.Enable()
  822. def load_options(self):
  823. ''' Load panel options from OptionsHandler object. '''
  824. self.subs_lang_combo.SetValue(self.opt_manager.options['subs_lang'])
  825. self.write_subs_checkbox.SetValue(self.opt_manager.options['write_subs'])
  826. self.embed_subs_checkbox.SetValue(self.opt_manager.options['embed_subs'])
  827. self.write_all_subs_checkbox.SetValue(self.opt_manager.options['write_all_subs'])
  828. self.write_auto_subs_checkbox.SetValue(self.opt_manager.options['write_auto_subs'])
  829. self._on_subs_pick(None)
  830. def save_options(self):
  831. ''' Save panel options to OptionsHandler object. '''
  832. self.opt_manager.options['subs_lang'] = self.subs_lang_combo.GetValue()
  833. self.opt_manager.options['write_subs'] = self.write_subs_checkbox.GetValue()
  834. self.opt_manager.options['embed_subs'] = self.embed_subs_checkbox.GetValue()
  835. self.opt_manager.options['write_all_subs'] = self.write_all_subs_checkbox.GetValue()
  836. self.opt_manager.options['write_auto_subs'] = self.write_auto_subs_checkbox.GetValue()
  837. class GeneralTab(TabPanel):
  838. '''
  839. Options frame general tab panel.
  840. Params
  841. parent: wx.Panel parent.
  842. opt_manager: OptionsHandler.OptionsHandler object.
  843. reset_handler: Method to reset all options & frame.
  844. '''
  845. BUTTONS_SIZE = (110, 40)
  846. ABOUT_LABEL = "About"
  847. OPEN_LABEL = "Open"
  848. RESET_LABEL = "Reset Options"
  849. SAVEPATH_LABEL = "Save Path"
  850. SETTINGS_DIR_LABEL = "Settings File: {0}"
  851. PICK_DIR_LABEL = "Choose Directory"
  852. def __init__(self, *args, **kwargs):
  853. super(GeneralTab, self).__init__(*args, **kwargs)
  854. self.savepath_box = self.create_textctrl()
  855. self.about_button = self.create_button(self.ABOUT_LABEL, self._on_about)
  856. self.open_button = self.create_button(self.OPEN_LABEL, self._on_open)
  857. self.reset_button = self.create_button(self.RESET_LABEL, self._on_reset)
  858. self.savepath_text = self.create_statictext(self.SAVEPATH_LABEL)
  859. cfg_file = self.SETTINGS_DIR_LABEL.format(self.opt_manager.settings_file)
  860. self.cfg_file_dir = self.create_statictext(cfg_file)
  861. self._set_sizer()
  862. def _set_sizer(self):
  863. main_sizer = wx.BoxSizer(wx.VERTICAL)
  864. main_sizer.AddSpacer(self.SIZE_20)
  865. main_sizer.Add(self.savepath_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  866. main_sizer.AddSpacer(self.SIZE_10)
  867. savepath_sizer = wx.BoxSizer(wx.HORIZONTAL)
  868. savepath_sizer.Add(self.savepath_box, 1, wx.LEFT | wx.RIGHT, self.SIZE_80)
  869. main_sizer.Add(savepath_sizer, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND)
  870. main_sizer.AddSpacer(self.SIZE_20)
  871. buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
  872. buttons_sizer.Add(self.about_button)
  873. buttons_sizer.Add(self.open_button, flag=wx.LEFT | wx.RIGHT, border=self.SIZE_50)
  874. buttons_sizer.Add(self.reset_button)
  875. main_sizer.Add(buttons_sizer, flag=wx.ALIGN_CENTER_HORIZONTAL)
  876. main_sizer.AddSpacer(self.SIZE_30)
  877. main_sizer.Add(self.cfg_file_dir, flag=wx.ALIGN_CENTER_HORIZONTAL)
  878. self.SetSizer(main_sizer)
  879. def _on_reset(self, event):
  880. ''' Event handler reset button. '''
  881. self.reset_handler()
  882. def _on_open(self, event):
  883. ''' Event handler open button. '''
  884. dlg = self.create_dirdialog(self.PICK_DIR_LABEL)
  885. if dlg.ShowModal() == wx.ID_OK:
  886. self.savepath_box.SetValue(dlg.GetPath())
  887. dlg.Destroy()
  888. def _on_about(self, event):
  889. ''' Event handler about button. '''
  890. info = wx.AboutDialogInfo()
  891. # Load about icon
  892. if self.app_icon is not None:
  893. info.SetIcon(self.app_icon)
  894. info.SetName(__appname__)
  895. info.SetVersion(__version__)
  896. info.SetDescription(__descriptionfull__)
  897. info.SetWebSite(__projecturl__)
  898. info.SetLicense(__licensefull__)
  899. info.AddDeveloper(__author__)
  900. wx.AboutBox(info)
  901. def load_options(self):
  902. ''' Load panel options from OptionsHandler object. '''
  903. self.savepath_box.SetValue(self.opt_manager.options['save_path'])
  904. def save_options(self):
  905. ''' Save panel options to OptionsHandler object. '''
  906. self.opt_manager.options['save_path'] = self.savepath_box.GetValue()
  907. class CMDTab(TabPanel):
  908. '''
  909. Options frame command tab panel.
  910. Params
  911. parent: wx.Panel parent.
  912. '''
  913. CMD_LABEL = "Command line arguments (e.g. --help)"
  914. def __init__(self, *args, **kwargs):
  915. super(CMDTab, self).__init__(*args, **kwargs)
  916. self.cmd_args_box = self.create_textctrl()
  917. self.cmd_args_text = self.create_statictext(self.CMD_LABEL)
  918. self._set_sizer()
  919. def _set_sizer(self):
  920. main_sizer = wx.BoxSizer(wx.VERTICAL)
  921. main_sizer.AddSpacer(self.SIZE_50)
  922. main_sizer.Add(self.cmd_args_text, flag=wx.ALIGN_CENTER_HORIZONTAL)
  923. main_sizer.AddSpacer(self.SIZE_10)
  924. cmdbox_sizer = wx.BoxSizer(wx.HORIZONTAL)
  925. cmdbox_sizer.Add(self.cmd_args_box, 1, wx.LEFT | wx.RIGHT, border=self.SIZE_80)
  926. main_sizer.Add(cmdbox_sizer, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND)
  927. self.SetSizer(main_sizer)
  928. def load_options(self):
  929. ''' Load panel options from OptionsHandler object. '''
  930. self.cmd_args_box.SetValue(self.opt_manager.options['cmd_args'])
  931. def save_options(self):
  932. ''' Save panel options to OptionsHandler object. '''
  933. self.opt_manager.options['cmd_args'] = self.cmd_args_box.GetValue()