From 9759d66a0c64eeba9c71f79038dd3cba846e7dfe Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Sat, 15 Oct 2016 22:42:47 +0300 Subject: [PATCH] GeneralTab: Implement event handlers --- youtube_dl_gui/optionsframe.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/youtube_dl_gui/optionsframe.py b/youtube_dl_gui/optionsframe.py index 3d2e40e..b3f5fd4 100644 --- a/youtube_dl_gui/optionsframe.py +++ b/youtube_dl_gui/optionsframe.py @@ -264,10 +264,10 @@ class GeneralTab(TabPanel): super(GeneralTab, self).__init__(*args, **kwargs) self.language_label = self.crt_statictext("Language") - self.language_combobox = self.crt_combobox(list(self.LOCALE_NAMES.values())) + self.language_combobox = self.crt_combobox(list(self.LOCALE_NAMES.values()), event_handler=self._on_language) self.filename_format_label = self.crt_statictext("Filename format") - self.filename_format_combobox = self.crt_combobox(list(OUTPUT_FORMATS.values())) + self.filename_format_combobox = self.crt_combobox(list(OUTPUT_FORMATS.values()), event_handler=self._on_filename) self.filename_custom_format = self.crt_textctrl() self.filename_opts_label = self.crt_statictext("Filename options") @@ -276,13 +276,15 @@ class GeneralTab(TabPanel): self.more_opts_label = self.crt_statictext("More options") self.confirm_exit_checkbox = self.crt_checkbox("Confirm on exit") - self.shutdown_checkbox = self.crt_checkbox("Shutdown") + self.shutdown_checkbox = self.crt_checkbox("Shutdown", event_handler=self._on_shutdown) self.sudo_textctrl = self.crt_textctrl(wx.TE_PASSWORD) - self.confirm_exit_checkbox.Disable() - self._set_layout() + self.confirm_exit_checkbox.Disable() + if os.name == "nt": + self.sudo_textctrl.Hide() + def _set_layout(self): main_sizer = wx.BoxSizer(wx.HORIZONTAL) vertical_sizer = wx.BoxSizer(wx.VERTICAL) @@ -310,6 +312,21 @@ class GeneralTab(TabPanel): main_sizer.Add(vertical_sizer, 1, wx.EXPAND | wx.ALL, border=5) self.SetSizer(main_sizer) + def _on_language(self, event): + """Event handler for the wx.EVT_COMBOBOX of the language_combobox.""" + wx.MessageBox("In order for the changes to take effect please restart {0}.".format(__appname__), + "Restart", + wx.OK | wx.ICON_INFORMATION, + self) + + def _on_filename(self, event): + """Event handler for the wx.EVT_COMBOBOX of the filename_format_combobox.""" + self.filename_custom_format.Enable(self.filename_format_combobox.GetValue() == OUTPUT_FORMATS[3]) + + def _on_shutdown(self, event): + """Event handler for the wx.EVT_CHECKBOX of the shutdown_checkbox.""" + self.sudo_textctrl.Enable(self.shutdown_checkbox.GetValue()) + #TODO Implement load-save for confirm_exit_checkbox widget def load_options(self): @@ -320,6 +337,9 @@ class GeneralTab(TabPanel): self.shutdown_checkbox.SetValue(self.opt_manager.options["shutdown"]) self.sudo_textctrl.SetValue(self.opt_manager.options["sudo_password"]) + self._on_filename(None) + self._on_shutdown(None) + def save_options(self): self.opt_manager.options["locale_name"] = self.LOCALE_NAMES[self.language_combobox.GetValue()] self.opt_manager.options["output_format"] = OUTPUT_FORMATS[self.filename_format_combobox.GetValue()]