#41: Implement keymap switching.

This commit is contained in:
Bill Dengler 2015-05-16 13:28:44 -04:00
parent 671e0e0bff
commit b5f1294b82
2 changed files with 36 additions and 5 deletions

View File

@ -14,6 +14,7 @@ from extra.autocompletionUsers import settings
from extra.AudioUploader import dropbox_transfer
from pubsub import pub
import logging
import config_utils
log = logging.getLogger("Settings")
class globalSettingsController(object):
@ -24,15 +25,34 @@ class globalSettingsController(object):
self.needs_restart = False
self.is_started = True
def make_kmmap(self):
res={}
for i in os.listdir(paths.app_path('keymaps')):
if ".keymap" not in i:
continue
print paths.app_path('keymaps/'+i)
try:
res[config_utils.load_config(paths.app_path('keymaps/'+i))['info']['name']]=i
except:
log.exception("Exception while loading keymap " + i)
return res
def create_config(self):
self.kmmap=self.make_kmmap()
self.langs = languageHandler.getAvailableLanguages()
langs = []
[langs.append(i[1]) for i in self.langs]
self.codes = []
[self.codes.append(i[0]) for i in self.langs]
id = self.codes.index(config.app["app-settings"]["language"])
self.dialog.create_general(langs)
self.kmfriendlies=[]
self.kmnames=[]
for k,v in self.kmmap.items():
self.kmfriendlies.append(k)
self.kmnames.append(v)
self.kmid=self.kmnames.index(config.app['app-settings']['load_keymap'])
self.dialog.create_general(langs,self.kmfriendlies)
self.dialog.general.language.SetSelection(id)
self.dialog.general.km.SetSelection(self.kmid)
self.dialog.set_value("general", "ask_at_exit", config.app["app-settings"]["ask_at_exit"])
self.dialog.set_value("general", "play_ready_sound", config.app["app-settings"]["play_ready_sound"])
@ -54,6 +74,10 @@ class globalSettingsController(object):
config.app["app-settings"]["language"] = self.codes[self.dialog.general.language.GetSelection()]
languageHandler.setLanguage(config.app["app-settings"]["language"])
self.needs_restart = True
if self.kmnames[self.dialog.general.km.GetSelection()] != config.app["app-settings"]["load_keymap"]:
config.app["app-settings"]["load_keymap"] =self.kmnames[self.dialog.general.km.GetSelection()]
self.needs_restart = True
if config.app["app-settings"]["use_invisible_keyboard_shorcuts"] != self.dialog.get_value("general", "use_invisible_shorcuts"):
config.app["app-settings"]["use_invisible_keyboard_shorcuts"] = self.dialog.get_value("general", "use_invisible_shorcuts")
pub.sendMessage("invisible-shorcuts-changed", registered=self.dialog.get_value("general", "use_invisible_shorcuts"))

View File

@ -7,7 +7,7 @@ from multiplatform_widgets import widgets
import output
import config
class general(wx.Panel, baseDialog.BaseWXDialog):
def __init__(self, parent, languages):
def __init__(self, parent, languages,keymaps):
super(general, self).__init__(parent)
sizer = wx.BoxSizer(wx.VERTICAL)
language = wx.StaticText(self, -1, _(u"Language"))
@ -29,9 +29,16 @@ class general(wx.Panel, baseDialog.BaseWXDialog):
sizer.Add(self.disable_sapi5, 0, wx.ALL, 5)
self.hide_gui = wx.CheckBox(self, -1, _(u"Hide GUI on launch"))
sizer.Add(self.hide_gui, 0, wx.ALL, 5)
self.SetSizer(sizer)
kmbox = wx.BoxSizer(wx.VERTICAL)
km_label = wx.StaticText(self, -1, _(u"Keymap"))
self.km = wx.ComboBox(self, -1, choices=keymaps, style=wx.CB_READONLY)
self.km.SetSize(self.km.GetBestSize())
kmbox.Add(km_label, 0, wx.ALL, 5)
kmbox.Add(self.km, 0, wx.ALL, 5)
sizer.Add(kmbox, 0, wx.ALL, 5)
self.use_slow_audio_algo= wx.CheckBox(self, -1, _(U"Use slow audio tweet detection algorithm (improves audio tweet detection accuracy at the cost of performance)"))
sizer.Add(self.use_slow_audio_algo, 0, wx.ALL, 5)
self.SetSizer(sizer)
class proxy(wx.Panel, baseDialog.BaseWXDialog):
@ -311,8 +318,8 @@ class configurationDialog(baseDialog.BaseWXDialog):
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.notebook = wx.Notebook(self.panel)
def create_general(self, languageList):
self.general = general(self.notebook, languageList)
def create_general(self, languageList,keymaps):
self.general = general(self.notebook, languageList,keymaps)
self.notebook.AddPage(self.general, _(u"General"))
self.general.SetFocus()