From d032a6d8f75bad4ebe1fdb89aa093ef0f8551e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Mon, 8 Dec 2014 09:44:02 -0600 Subject: [PATCH] Use invisible interface's keyboard shorcuts even if the window is displayed --- src/Conf.defaults | 1 + src/gui/dialogs/configuration.py | 11 ++++++++++- src/gui/main.py | 29 +++++++++++++++++++++++------ src/updater/update_manager.py | 5 +++-- src/widgetUtils/__init__.py | 3 +++ src/widgetUtils/wxUtils.py | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 src/widgetUtils/__init__.py create mode 100644 src/widgetUtils/wxUtils.py diff --git a/src/Conf.defaults b/src/Conf.defaults index ed13d5cb..92eb87b8 100644 --- a/src/Conf.defaults +++ b/src/Conf.defaults @@ -15,6 +15,7 @@ reverse_timelines = boolean(default=False) time_to_check_streams = integer(default=30) announce_stream_status = boolean(default=True) ask_at_exit = boolean(default=True) +use_invisible_keyboard_shorcuts = boolean(default=False) [sound] volume = float(default=1.0) diff --git a/src/gui/dialogs/configuration.py b/src/gui/dialogs/configuration.py index 95bc12c1..9cee4e01 100644 --- a/src/gui/dialogs/configuration.py +++ b/src/gui/dialogs/configuration.py @@ -52,10 +52,12 @@ class general(wx.Panel): langBox.Add(self.language, 0, wx.ALL, 5) sizer.Add(langBox, 0, wx.ALL, 5) self.au = wx.Button(self, -1, _(u"Set the autocomplete function")) -# self.Bind(wx.EVT_BUTTON, self.autocompletion, au) self.ask_at_exit = wx.CheckBox(self, -1, _(U"ask before exiting TwBlue?")) self.ask_at_exit.SetValue(config.main["general"]["ask_at_exit"]) sizer.Add(self.ask_at_exit, 0, wx.ALL, 5) + self.use_invisible_shorcuts = wx.CheckBox(self, -1, _(u"Use invisible interface's keyboard shorcuts even if the window is displayed")) + self.use_invisible_shorcuts.SetValue(config.main["general"]["use_invisible_keyboard_shorcuts"]) + sizer.Add(self.use_invisible_shorcuts, 0, wx.ALL, 5) self.relative_time = wx.CheckBox(self, -1, _(U"Relative times")) self.relative_time.SetValue(config.main["general"]["relative_times"]) sizer.Add(self.relative_time, 0, wx.ALL, 5) @@ -384,6 +386,13 @@ class configurationDialog(wx.Dialog): if platform.system() == "Windows": config.main["general"]["voice_enabled"] = self.general.disable_sapi5.GetValue() config.main["general"]["ask_at_exit"] = self.general.ask_at_exit.GetValue() + if (self.general.use_invisible_shorcuts.GetValue() == True and config.main["general"]["use_invisible_keyboard_shorcuts"] != True) and self.parent.showing == True: + km = self.parent.create_invisible_keyboard_shorcuts() + self.parent.register_invisible_keyboard_shorcuts(km) + elif (self.general.use_invisible_shorcuts.GetValue() == False and config.main["general"]["use_invisible_keyboard_shorcuts"] != False) and self.parent.showing == True: + km = self.parent.create_invisible_keyboard_shorcuts() + self.parent.unregister_invisible_keyboard_shorcuts(km) + config.main["general"]["use_invisible_keyboard_shorcuts"] = self.general.use_invisible_shorcuts.GetValue() config.main["general"]["hide_gui"] = self.general.show_gui.GetValue() config.main["general"]["max_api_calls"] = self.general.apiCalls.GetValue() config.main["general"]["max_tweets_per_call"] = self.general.itemsPerApiCall.GetValue() diff --git a/src/gui/main.py b/src/gui/main.py index 16fb7f9e..f8939233 100644 --- a/src/gui/main.py +++ b/src/gui/main.py @@ -329,6 +329,9 @@ class mainFrame(wx.Frame): buff.put_items(num) self.nb.InsertSubPage(self.db.settings["buffers"].index(self.db.settings["user_name"]), buff, _(u"Trending topics for %s") % (buff.name,)) self.sizer.Add(self.nb, 0, wx.ALL, 5) + if config.main["general"]["use_invisible_keyboard_shorcuts"] == True: + km = self.create_invisible_keyboard_shorcuts() + self.register_invisible_keyboard_shorcuts(km) panel.SetSizer(self.sizer) self.SetClientSize(self.sizer.CalcMin()) self.Bind(event.MyEVT_STARTED, self.onInit) @@ -823,20 +826,34 @@ class mainFrame(wx.Frame): msg = _(u"%s. Empty") % (self.nb.GetPageText(self.nb.GetSelection())) output.speak(msg, 1) - def show_hide(self, ev=None): -# if platform.system() == "Linux" or platform.system() == "Darwin": return + def create_invisible_keyboard_shorcuts(self): keymap = {} for i in config.main["keymap"]: if hasattr(self, i): keymap[config.main["keymap"][i]] = getattr(self, i) + return keymap + + def register_invisible_keyboard_shorcuts(self, keymap): + self.keyboard_handler = WXKeyboardHandler(self) + self.keyboard_handler.register_keys(keymap) + + def unregister_invisible_keyboard_shorcuts(self, keymap): + try: + self.keyboard_handler.unregister_keys(keymap) + del self.keyboard_handler + except AttributeError: + pass + + def show_hide(self, ev=None): + km = self.create_invisible_keyboard_shorcuts() if self.showing == True: - self.keyboard_handler = WXKeyboardHandler(self) - self.keyboard_handler.register_keys(keymap) + if config.main["general"]["use_invisible_keyboard_shorcuts"] == False: + self.register_invisible_keyboard_shorcuts(km) self.Hide() self.showing = False else: - self.keyboard_handler.unregister_keys(keymap) - del self.keyboard_handler + if config.main["general"]["use_invisible_keyboard_shorcuts"] == False: + self.unregister_invisible_keyboard_shorcuts(km) self.Show() self.showing = True diff --git a/src/updater/update_manager.py b/src/updater/update_manager.py index 5a99e63b..37ed5d76 100644 --- a/src/updater/update_manager.py +++ b/src/updater/update_manager.py @@ -26,8 +26,9 @@ def check_for_update(msg=False): else: progress.Update(percent, _(u"Update")) def update_complete(): - wx.MessageDialog(None, _(u"The new TW Blue version has been downloaded and installed. Press OK to start the application."), _(u"Done!")).ShowModal() - sys.exit() + ms = wx.MessageDialog(None, _(u"The new TW Blue version has been downloaded and installed. Press OK to start the application."), _(u"Done!")) + if ms.ShowModal() == wx.ID_OK: + sys.exit() app_updater = updater.AutoUpdater(url, new_path, 'bootstrap.exe', app_path=paths.app_path(), postexecute=paths.app_path("TWBlue.exe"), finish_callback=update_complete, percentage_callback=update) app_updater.start_update() progress.ShowModal() diff --git a/src/widgetUtils/__init__.py b/src/widgetUtils/__init__.py new file mode 100644 index 00000000..f9b60c8f --- /dev/null +++ b/src/widgetUtils/__init__.py @@ -0,0 +1,3 @@ +import platform +if platform.system() == "Windows": + from wxUtils import * diff --git a/src/widgetUtils/wxUtils.py b/src/widgetUtils/wxUtils.py new file mode 100644 index 00000000..7a3438d9 --- /dev/null +++ b/src/widgetUtils/wxUtils.py @@ -0,0 +1,32 @@ +import wx + +# Code responses for WX dialogs. +# this is when an user presses OK on a dialogue. +OK = wx.ID_OK +# This is when an user presses cancel on a dialogue. +CANCEL = wx.ID_CANCEL +# This is when an user closes the dialogue or an id to create the close button. +CLOSE = wx.ID_CLOSE +# The response for a "yes" Button pressed on a dialogue. +YES = wx.ID_YES +# This is when the user presses No on a default dialogue. +NO = wx.ID_NO + +#events +# This is raised when the application must be closed. +CLOSE_EVENT = wx.EVT_CLOSE +# This is activated when a button is pressed. +BUTTON_PRESSED = wx.EVT_BUTTON +# This is activated when an user enter text on an edit box. +ENTERED_TEXT = wx.EVT_TEXT + +def exit_application(): + """ Closes the current window cleanly. """ + wx.GetApp().ExitMainLoop() + +def connect_event(parent, event, func): + """ Connects an event to a function. + parent wx.window: The widget that will listen for the event. + event widgetUtils.event: The event that will be listened for the parent. The event should be one of the widgetUtils events. + function func: The function that will be connected to the event.""" + return getattr(parent, "Bind")(event, func) \ No newline at end of file