Prepare for py3 port.

This commit is contained in:
Bill Dengler
2017-06-15 22:11:31 +00:00
parent d0290b4d61
commit e85c9b5af0
81 changed files with 7701 additions and 7133 deletions

View File

@@ -1 +1,2 @@
from keystrokeEditor import KeystrokeEditor
from __future__ import absolute_import
from .keystrokeEditor import KeystrokeEditor

View File

@@ -1,58 +1,59 @@
# -*- coding: utf-8 -*-
import widgetUtils
import config
import wx_ui
import constants
from pubsub import pub
class KeystrokeEditor(object):
def __init__(self):
super(KeystrokeEditor, self).__init__()
self.changed = False # Change it if the keyboard shorcuts are reassigned.
self.dialog = wx_ui.keystrokeEditorDialog()
self.map = config.keymap["keymap"]
# we need to copy the keymap before modify it, for unregistering the old keystrokes if is needed.
self.hold_map = self.map.copy()
self.dialog.put_keystrokes(constants.actions, self.map)
widgetUtils.connect_event(self.dialog.edit, widgetUtils.BUTTON_PRESSED, self.edit_keystroke)
widgetUtils.connect_event(self.dialog.execute, widgetUtils.BUTTON_PRESSED, self.execute_action)
self.dialog.get_response()
def edit_keystroke(self, *args, **kwargs):
action = self.dialog.actions[self.dialog.get_action()]
edit_dialog = wx_ui.editKeystrokeDialog()
self.set_keystroke(self.map[action], edit_dialog)
answer = edit_dialog.get_response()
if answer == widgetUtils.OK:
new_keystroke = self.get_edited_keystroke(edit_dialog)
if new_keystroke != self.map[action]:
self.changed = True
self.map[action] = new_keystroke
self.dialog.put_keystrokes(constants.actions, self.map)
def set_keystroke(self, keystroke, dialog):
for i in keystroke.split("+"):
if hasattr(dialog, i):
dialog.set(i, True)
dialog.set("key", keystroke.split("+")[-1])
def get_edited_keystroke(self, dialog):
keys = []
if dialog.get("control") == True:
keys.append("control")
if dialog.get("win") == True:
keys.append("win")
if dialog.get("alt") == True:
keys.append("alt")
if dialog.get("shift") == True:
keys.append("shift")
if dialog.get("key") != "":
keys.append(dialog.get("key"))
else:
wx_ui.no_key()
return
return "+".join(keys)
def execute_action(self, *args, **kwargs):
action = self.dialog.actions[self.dialog.get_action()]
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import widgetUtils
import config
from . import wx_ui
from . import constants
from pubsub import pub
class KeystrokeEditor(object):
def __init__(self):
super(KeystrokeEditor, self).__init__()
self.changed = False # Change it if the keyboard shorcuts are reassigned.
self.dialog = wx_ui.keystrokeEditorDialog()
self.map = config.keymap["keymap"]
# we need to copy the keymap before modify it, for unregistering the old keystrokes if is needed.
self.hold_map = self.map.copy()
self.dialog.put_keystrokes(constants.actions, self.map)
widgetUtils.connect_event(self.dialog.edit, widgetUtils.BUTTON_PRESSED, self.edit_keystroke)
widgetUtils.connect_event(self.dialog.execute, widgetUtils.BUTTON_PRESSED, self.execute_action)
self.dialog.get_response()
def edit_keystroke(self, *args, **kwargs):
action = self.dialog.actions[self.dialog.get_action()]
edit_dialog = wx_ui.editKeystrokeDialog()
self.set_keystroke(self.map[action], edit_dialog)
answer = edit_dialog.get_response()
if answer == widgetUtils.OK:
new_keystroke = self.get_edited_keystroke(edit_dialog)
if new_keystroke != self.map[action]:
self.changed = True
self.map[action] = new_keystroke
self.dialog.put_keystrokes(constants.actions, self.map)
def set_keystroke(self, keystroke, dialog):
for i in keystroke.split("+"):
if hasattr(dialog, i):
dialog.set(i, True)
dialog.set("key", keystroke.split("+")[-1])
def get_edited_keystroke(self, dialog):
keys = []
if dialog.get("control") == True:
keys.append("control")
if dialog.get("win") == True:
keys.append("win")
if dialog.get("alt") == True:
keys.append("alt")
if dialog.get("shift") == True:
keys.append("shift")
if dialog.get("key") != "":
keys.append(dialog.get("key"))
else:
wx_ui.no_key()
return
return "+".join(keys)
def execute_action(self, *args, **kwargs):
action = self.dialog.actions[self.dialog.get_action()]
pub.sendMessage("execute-action", action=action)

View File

@@ -1,81 +1,81 @@
# -*- coding: utf-8 -*-
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)
firstSizer.Add(keysText, 0, wx.ALL, 5)
firstSizer.Add(self.keys.list, 0, wx.ALL, 5)
self.edit = wx.Button(panel, -1, _(u"Edit"))
self.edit.SetDefault()
self.execute = wx.Button(panel, -1, _(u"Execute action"))
close = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
secondSizer = wx.BoxSizer(wx.HORIZONTAL)
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())
def put_keystrokes(self, actions, keystrokes):
selection = self.keys.get_selected()
self.keys.clear()
for i in keystrokes:
if actions.has_key(i) == False:
continue
action = actions[i]
self.actions.append(i)
keystroke = keystrokes[i]
self.keys.insert_item(False, *[action, keystroke])
self.keys.select_item(selection)
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():
# -*- coding: utf-8 -*-
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)
firstSizer.Add(keysText, 0, wx.ALL, 5)
firstSizer.Add(self.keys.list, 0, wx.ALL, 5)
self.edit = wx.Button(panel, -1, _(u"Edit"))
self.edit.SetDefault()
self.execute = wx.Button(panel, -1, _(u"Execute action"))
close = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
secondSizer = wx.BoxSizer(wx.HORIZONTAL)
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())
def put_keystrokes(self, actions, keystrokes):
selection = self.keys.get_selected()
self.keys.clear()
for i in keystrokes:
if (i in actions) == False:
continue
action = actions[i]
self.actions.append(i)
keystroke = keystrokes[i]
self.keys.insert_item(False, *[action, keystroke])
self.keys.select_item(selection)
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()