Use invisible interface's keyboard shorcuts even if the window is displayed

This commit is contained in:
Manuel Cortez 2014-12-08 09:44:02 -06:00
parent 5e3bcfc82e
commit d032a6d8f7
6 changed files with 72 additions and 9 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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)
if self.showing == True:
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:
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

View File

@ -26,7 +26,8 @@ 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()
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()

View File

@ -0,0 +1,3 @@
import platform
if platform.system() == "Windows":
from wxUtils import *

View File

@ -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)