Skip to content

Commit

Permalink
Updated key codes and key events
Browse files Browse the repository at this point in the history
  • Loading branch information
xxao committed Mar 3, 2022
1 parent 0687faa commit f4cb7e5
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 10 deletions.
58 changes: 51 additions & 7 deletions pero/backends/qt/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@
CURSOR_SIZENS: Qt.CursorShape.SizeVerCursor}

QT_KEYS = {
Qt.Key.Key_Backspace: KEY_BACK,
Qt.Key.Key_Tab: KEY_TAB,
Qt.Key.Key_Return: KEY_RETURN,
Qt.Key.Key_Control: KEY_CTRL,

Qt.Key.Key_Shift: KEY_SHIFT,
Qt.Key.Key_Control: KEY_CTRL,
Qt.Key.Key_Alt: KEY_ALT,

Qt.Key.Key_Escape: KEY_ESC,
Qt.Key.Key_Space: KEY_SPACE,

Qt.Key.Key_PageUp: KEY_PAGEUP,
Qt.Key.Key_PageDown: KEY_PAGEDOWN,
Qt.Key.Key_End: KEY_END,
Expand All @@ -73,7 +77,47 @@
Qt.Key.Key_Up: KEY_UP,
Qt.Key.Key_Right: KEY_RIGHT,
Qt.Key.Key_Down: KEY_DOWN,

Qt.Key.Key_Delete: KEY_DELETE,

Qt.Key.Key_0: KEY_0,
Qt.Key.Key_1: KEY_1,
Qt.Key.Key_2: KEY_2,
Qt.Key.Key_3: KEY_3,
Qt.Key.Key_4: KEY_4,
Qt.Key.Key_5: KEY_5,
Qt.Key.Key_6: KEY_6,
Qt.Key.Key_7: KEY_7,
Qt.Key.Key_8: KEY_8,
Qt.Key.Key_9: KEY_9,

Qt.Key.Key_A: KEY_A,
Qt.Key.Key_B: KEY_B,
Qt.Key.Key_C: KEY_C,
Qt.Key.Key_D: KEY_D,
Qt.Key.Key_E: KEY_E,
Qt.Key.Key_F: KEY_F,
Qt.Key.Key_G: KEY_G,
Qt.Key.Key_H: KEY_H,
Qt.Key.Key_I: KEY_I,
Qt.Key.Key_J: KEY_J,
Qt.Key.Key_K: KEY_K,
Qt.Key.Key_L: KEY_L,
Qt.Key.Key_M: KEY_M,
Qt.Key.Key_N: KEY_N,
Qt.Key.Key_O: KEY_O,
Qt.Key.Key_P: KEY_P,
Qt.Key.Key_Q: KEY_Q,
Qt.Key.Key_R: KEY_R,
Qt.Key.Key_S: KEY_S,
Qt.Key.Key_T: KEY_T,
Qt.Key.Key_U: KEY_U,
Qt.Key.Key_V: KEY_V,
Qt.Key.Key_W: KEY_W,
Qt.Key.Key_X: KEY_X,
Qt.Key.Key_Y: KEY_Y,
Qt.Key.Key_Z: KEY_Z,

Qt.Key.Key_F1: KEY_F1,
Qt.Key.Key_F2: KEY_F2,
Qt.Key.Key_F3: KEY_F3,
Expand All @@ -87,6 +131,12 @@
Qt.Key.Key_F11: KEY_F11,
Qt.Key.Key_F12: KEY_F12}

QT_TOUCH_STATE = {
Qt.TouchPointState.TouchPointPressed: TOUCH_PRESSED,
Qt.TouchPointState.TouchPointReleased: TOUCH_RELEASED,
Qt.TouchPointState.TouchPointMoved: TOUCH_MOVED,
Qt.TouchPointState.TouchPointStationary: TOUCH_STATIC}

QT_RASTER_TYPES = {
'.bmp',
'.gif',
Expand All @@ -96,9 +146,3 @@

QT_VECTOR_TYPES = {
'.pdf'}

QT_TOUCH_STATE = {
Qt.TouchPointState.TouchPointPressed: TOUCH_PRESSED,
Qt.TouchPointState.TouchPointReleased: TOUCH_RELEASED,
Qt.TouchPointState.TouchPointMoved: TOUCH_MOVED,
Qt.TouchPointState.TouchPointStationary: TOUCH_STATIC}
7 changes: 6 additions & 1 deletion pero/backends/wx/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@
WX_KEYS = {
wx.WXK_TAB: KEY_TAB,
wx.WXK_RETURN: KEY_RETURN,
wx.WXK_CONTROL: KEY_CTRL,

wx.WXK_SHIFT: KEY_SHIFT,
wx.WXK_CONTROL: KEY_CTRL,
wx.WXK_ALT: KEY_ALT,

wx.WXK_ESCAPE: KEY_ESC,
wx.WXK_SPACE: KEY_SPACE,

wx.WXK_PAGEUP: KEY_PAGEUP,
wx.WXK_PAGEDOWN: KEY_PAGEDOWN,
wx.WXK_END: KEY_END,
Expand All @@ -73,7 +76,9 @@
wx.WXK_UP: KEY_UP,
wx.WXK_RIGHT: KEY_RIGHT,
wx.WXK_DOWN: KEY_DOWN,

wx.WXK_DELETE: KEY_DELETE,

wx.WXK_F1: KEY_F1,
wx.WXK_F2: KEY_F2,
wx.WXK_F3: KEY_F3,
Expand Down
80 changes: 78 additions & 2 deletions pero/enums/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
KEY_TAB = 9
KEY_RETURN = 13

KEY_CTRL = 17
KEY_SHIFT = 16
KEY_CTRL = 17
KEY_ALT = 18

KEY_ESC = 27
Expand All @@ -26,6 +26,44 @@

KEY_DELETE = 46

KEY_0 = 48
KEY_1 = 49
KEY_2 = 50
KEY_3 = 51
KEY_4 = 52
KEY_5 = 53
KEY_6 = 54
KEY_7 = 55
KEY_8 = 56
KEY_9 = 57

KEY_A = 65
KEY_B = 66
KEY_C = 67
KEY_D = 68
KEY_E = 69
KEY_F = 70
KEY_G = 71
KEY_H = 72
KEY_I = 73
KEY_J = 74
KEY_K = 75
KEY_L = 76
KEY_M = 77
KEY_N = 78
KEY_O = 79
KEY_P = 80
KEY_Q = 81
KEY_R = 82
KEY_S = 83
KEY_T = 84
KEY_U = 85
KEY_V = 86
KEY_W = 87
KEY_X = 88
KEY_Y = 89
KEY_Z = 90

KEY_F1 = 112
KEY_F2 = 113
KEY_F3 = 114
Expand All @@ -45,8 +83,8 @@
TAB = KEY_TAB,
RETURN = KEY_RETURN,

CTRL = KEY_CTRL,
SHIFT = KEY_SHIFT,
CTRL = KEY_CTRL,
ALT = KEY_ALT,

ESC = KEY_ESC,
Expand All @@ -63,6 +101,44 @@

DELETE = KEY_DELETE,

KEY_0 = KEY_0,
KEY_1 = KEY_1,
KEY_2 = KEY_2,
KEY_3 = KEY_3,
KEY_4 = KEY_4,
KEY_5 = KEY_5,
KEY_6 = KEY_6,
KEY_7 = KEY_7,
KEY_8 = KEY_8,
KEY_9 = KEY_9,

KEY_A = KEY_A,
KEY_B = KEY_B,
KEY_C = KEY_C,
KEY_D = KEY_D,
KEY_E = KEY_E,
KEY_F = KEY_F,
KEY_G = KEY_G,
KEY_H = KEY_H,
KEY_I = KEY_I,
KEY_J = KEY_J,
KEY_K = KEY_K,
KEY_L = KEY_L,
KEY_M = KEY_M,
KEY_N = KEY_N,
KEY_O = KEY_O,
KEY_P = KEY_P,
KEY_Q = KEY_Q,
KEY_R = KEY_R,
KEY_S = KEY_S,
KEY_T = KEY_T,
KEY_U = KEY_U,
KEY_V = KEY_V,
KEY_W = KEY_W,
KEY_X = KEY_X,
KEY_Y = KEY_Y,
KEY_Z = KEY_Z,

F1 = KEY_F1,
F2 = KEY_F2,
F3 = KEY_F3,
Expand Down
19 changes: 19 additions & 0 deletions pero/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ def __init__(self, **kwargs):
raise AttributeError("Attribute not found! --> %s" % name)


def __str__(self):
"""Gets standard string representation."""

# add type
text = "%s" % self.TYPE

# mark as cancelled
if self._canceled:
text += "(canceled)"

return text


def __repr__(self):
"""Gets debug string representation."""

return "%s(%s)" % (self.__class__.__name__, self.__str__())


def cancel(self):
"""
Sets current event as canceled to prevent following subscribers to be
Expand Down
26 changes: 26 additions & 0 deletions pero/events/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)


def __str__(self):
"""Gets standard string representation."""

# init from base
text = super().__str__()

# add key
text += " key: %s" % self.key

# add char
if self.char:
text += " char: %s" % self.char

# add modifiers
if self.alt_down:
text += " Alt"
if self.cmd_down:
text += " Cmd"
if self.ctrl_down:
text += " Ctrl"
if self.shift_down:
text += " Shift"

return text


@classmethod
def from_evt(cls, evt):
"""
Expand Down

0 comments on commit f4cb7e5

Please sign in to comment.