2015-02-26 10:09:13 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-06-06 11:52:23 -05:00
|
|
|
from __future__ import unicode_literals
|
2015-02-26 10:09:13 -06:00
|
|
|
import wx
|
|
|
|
from multiplatform_widgets import widgets
|
|
|
|
from wxUI.dialogs import baseDialog
|
|
|
|
|
|
|
|
class keystrokeEditorDialog(baseDialog.BaseWXDialog):
|
|
|
|
def __init__(self):
|
|
|
|
super(keystrokeEditorDialog, self).__init__(parent=None, id=-1, title=_(u"Keystroke editor"))
|
|
|
|
panel = wx.Panel(self)
|
|
|
|
self.actions = []
|
|
|
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
keysText = wx.StaticText(panel, -1, _(u"Select a keystroke to edit"))
|
|
|
|
self.keys = widgets.list(self, _(u"Action"), _(u"Keystroke"), style=wx.LC_REPORT|wx.LC_SINGLE_SEL, size=(400, 450))
|
|
|
|
self.keys.list.SetFocus()
|
|
|
|
firstSizer = wx.BoxSizer(wx.HORIZONTAL)
|
2015-08-21 09:51:01 -05:00
|
|
|
firstSizer.Add(keysText, 0, wx.ALL, 5)
|
|
|
|
firstSizer.Add(self.keys.list, 0, wx.ALL, 5)
|
2015-02-26 10:09:13 -06:00
|
|
|
self.edit = wx.Button(panel, -1, _(u"Edit"))
|
|
|
|
self.edit.SetDefault()
|
2015-08-21 09:51:01 -05:00
|
|
|
self.execute = wx.Button(panel, -1, _(u"Execute action"))
|
2015-02-26 10:09:13 -06:00
|
|
|
close = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
|
|
|
|
secondSizer = wx.BoxSizer(wx.HORIZONTAL)
|
2015-08-21 09:51:01 -05:00
|
|
|
secondSizer.Add(self.edit, 0, wx.ALL, 5)
|
|
|
|
secondSizer.Add(self.execute, 0, wx.ALL, 5)
|
|
|
|
secondSizer.Add(close, 0, wx.ALL, 5)
|
|
|
|
sizer.Add(firstSizer, 0, wx.ALL, 5)
|
|
|
|
sizer.Add(secondSizer, 0, wx.ALL, 5)
|
|
|
|
panel.SetSizer(sizer)
|
|
|
|
self.SetClientSize(sizer.CalcMin())
|
2015-02-26 10:09:13 -06:00
|
|
|
|
|
|
|
def put_keystrokes(self, actions, keystrokes):
|
2016-10-09 09:03:21 -05:00
|
|
|
selection = self.keys.get_selected()
|
|
|
|
self.keys.clear()
|
2015-02-26 10:09:13 -06:00
|
|
|
for i in keystrokes:
|
2018-11-22 13:35:19 -06:00
|
|
|
if (i in actions) == False:
|
2015-04-14 09:41:12 -05:00
|
|
|
continue
|
2015-02-26 10:09:13 -06:00
|
|
|
action = actions[i]
|
|
|
|
self.actions.append(i)
|
|
|
|
keystroke = keystrokes[i]
|
|
|
|
self.keys.insert_item(False, *[action, keystroke])
|
2016-10-09 09:03:21 -05:00
|
|
|
self.keys.select_item(selection)
|
2015-02-26 10:09:13 -06:00
|
|
|
|
|
|
|
def get_action(self):
|
|
|
|
return self.keys.get_selected()
|
|
|
|
|
|
|
|
class editKeystrokeDialog(baseDialog.BaseWXDialog):
|
|
|
|
def __init__(self):
|
|
|
|
super(editKeystrokeDialog, self).__init__(parent=None, id=-1, title=_(u"Editing keystroke"))
|
|
|
|
panel = wx.Panel(self)
|
|
|
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
self.control = wx.CheckBox(panel, -1, _(u"Control"))
|
|
|
|
self.alt = wx.CheckBox(panel, -1, _(u"Alt"))
|
|
|
|
self.shift = wx.CheckBox(panel, -1, _(u"Shift"))
|
|
|
|
self.win = wx.CheckBox(panel, -1, _(u"Windows"))
|
|
|
|
sizer1 = wx.BoxSizer(wx.HORIZONTAL)
|
|
|
|
sizer1.Add(self.control)
|
|
|
|
sizer1.Add(self.alt)
|
|
|
|
sizer1.Add(self.shift)
|
|
|
|
sizer1.Add(self.win)
|
|
|
|
charLabel = wx.StaticText(panel, -1, _(u"Key"))
|
|
|
|
self.key = wx.TextCtrl(panel, -1)
|
|
|
|
sizer2 = wx.BoxSizer(wx.HORIZONTAL)
|
|
|
|
sizer2.Add(charLabel)
|
|
|
|
sizer2.Add(self.key)
|
|
|
|
ok = wx.Button(panel, wx.ID_OK, _(u"OK"))
|
|
|
|
ok.SetDefault()
|
|
|
|
cancel = wx.Button(panel, wx.ID_CANCEL)
|
|
|
|
sizer3 = wx.BoxSizer(wx.HORIZONTAL)
|
|
|
|
sizer3.Add(ok)
|
|
|
|
sizer3.Add(cancel)
|
|
|
|
sizer.Add(sizer1)
|
|
|
|
sizer.Add(sizer2)
|
|
|
|
sizer.Add(sizer3)
|
|
|
|
panel.SetSizerAndFit(sizer)
|
|
|
|
|
|
|
|
|
|
|
|
def no_win_message():
|
|
|
|
return wx.MessageDialog(None, _(u"You need to use the Windows key"), _(u"Invalid keystroke"), wx.OK|wx.ICON_ERROR).ShowModal()
|
|
|
|
|
|
|
|
def no_key():
|
|
|
|
return wx.MessageDialog(None, _(u"You must provide a character for the keystroke"), _(u"Invalid keystroke"), wx.ICON_ERROR).ShowModal()
|