Exemplo n.º 1
0
 def on_key(self, event: wx.KeyEvent):
     """key push events controller
     can use following shortcut keys
         Ctrl + C    : copy selected cell
         Ctrl + V    : paste text data
         Delete      : delete all selected cells data
     ... and more. coming soon?
     :param event:
     :return:
     """
     # print(event.GetKeyCode())
     if event.ControlDown() and event.GetKeyCode() == KEY_CODE_C:
         self.copy()
         print('Do Copy!')
     if event.ControlDown() and event.GetKeyCode() == KEY_CODE_V:
         print('Do Paste!')
         self.paste()
     if event.ControlDown() and event.GetKeyCode() == KEY_CODE_Z:
         print('Undo!')
     if event.GetKeyCode() == KEY_CODE_BS and \
             event.GetKeyCode() == KEY_CODE_D:
         print('Cell Delete!')
     if event.GetKeyCode() == wx.WXK_DELETE:
         self.delete()
         print('Range Delete!')
         return  # not cell activate if delete key pushed
     # do other default events
     event.DoAllowNextEvent()
Exemplo n.º 2
0
    def on_key_press(self, event: wx.KeyEvent):
        widget = self.FindFocus()

        if isinstance(widget, wx.Control) and widget != self.object_list:
            # check if we are in a widget taking user input. ignore our shortcuts, then
            # the default widget with keyboard focus is the object list for some reason, so don't ignore then
            event.Skip()

            return

        key = event.GetKeyCode()

        if key in [wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE]:
            self.remove_selected_objects()
        elif event.ControlDown():
            key = event.GetUnicodeKey()
            if key == wx.WXK_NONE:
                return

            if key == ord("C"):
                self._copy_objects()
            elif key == ord("V"):
                self._paste_objects()
            elif key == ord("X"):
                self._cut_object()

            self.level_view.Refresh()
        else:
            event.Skip()
Exemplo n.º 3
0
 def OnKeyUp(self, evt: wx.KeyEvent):
     if not self.dictating:
         evt.Skip(True)
         return
     if evt.GetKeyCode() in [8]:
         evt.Skip(True)
     else:
         evt.Skip(False)
         text = self.rtext.GetValue()
         actual_char = chr(evt.GetUnicodeKey())
         expected_char = self.dictation_text[len(text)]
         if actual_char == expected_char:
             self.rtext.EndUnderline()
             self.rtext.WriteText(actual_char)
             try:
                 expected_char = self.dictation_text[len(text) + 1]
                 if expected_char in ';.,:!?" ':
                     self.say_next_word()
             except:
                 pass
         else:
             self.rtext.BeginUnderline()
             self.rtext.BeginTextColour(wx.Colour(255, 0, 0, 255))
             self.rtext.WriteText(actual_char)
             self.rtext.EndTextColour()
             self.rtext.EndUnderline()
             winsound.MessageBeep(500)
Exemplo n.º 4
0
    def processChar(self, event: KeyEvent):
        """
        Process the keyboard events.
        TODO:  Build the callable dictionary once and use it here.  This code builds it every time the
        user presses a key.  Eeks;

        Args:
            event:  The wxPython key event
        """
        c: int = event.GetKeyCode()
        funcs: Dict[int, Callable] = {
            WXK_DELETE: self.deleteSelectedShape,
            WXK_BACK: self.deleteSelectedShape,
            WXK_INSERT: self.insertSelectedShape,
            ord('i'): self.insertSelectedShape,
            ord('I'): self.insertSelectedShape,
            ord('s'): self.toggleSpline,
            ord('S'): self.toggleSpline,
            ord('<'): self.moveSelectedShapeDown,
            ord('>'): self.moveSelectedShapeUp,
        }
        if c in funcs:
            funcs[c]()
        else:
            self.logger.warning(f'Key code not supported: {c}')
            event.Skip()
Exemplo n.º 5
0
    def on_key_down(self, event: wx.KeyEvent):
        event_obj = event.GetEventObject()
        keycode = event.KeyCode

        if event_obj == self.search_bar and keycode in (315, 317):
            if keycode == 315:  # UP
                self.in_grid.select_new_row('U')
            elif keycode == 317:  # DOWN
                self.in_grid.select_new_row('D')
        else:
            event.Skip()
Exemplo n.º 6
0
    def on_key_down(self, event: wx.KeyEvent) -> None:
        """On EVT_KEY_DOWN, process the text if enter or tab is pressed."""
        keycode = event.KeyCode
        if not event.HasAnyModifiers() and \
            (keycode == wx.WXK_RETURN or keycode == wx.WXK_NUMPAD_ENTER or keycode == wx.WXK_TAB):
            if self._process_text():
                # handle if shift is held
                event.EventObject.Navigate(flags=
                    wx.NavigationKeyEvent.IsBackward if event.shiftDown else wx.NavigationKeyEvent.IsForward)

        else:
            event.Skip()
Exemplo n.º 7
0
 def _on_key_press(self, event: wx.KeyEvent):
     key = event.GetUnicodeKey()
     if key == wx.WXK_NONE:
         key = event.GetKeyCode()
     self._keys_pressed.add(key)
     if key == wx.WXK_ESCAPE:
         self._escape()
     if event.ControlDown() and key != wx.WXK_CONTROL:
         if key == 71:
             location = show_goto(self, *self._camera[:3])
             if location:
                 self._camera[:3] = location
                 self._collision_locations_cache = None
                 self._transformation_matrix = None
                 self._change_box_location()
     event.Skip()
Exemplo n.º 8
0
 def on_text(self, event: wx.KeyEvent) -> None:
     """Handle characters being typed."""
     f: float
     value: str = self.GetValue()
     allowed_keys: List[int] = [wx.WXK_DELETE, wx.WXK_BACK]
     keycode: int = event.GetKeyCode()
     if keycode < 255:
         # Valid ascii.
         char: str = chr(keycode)
         if char.isdigit() or (value and char == '.' and '.'
                               not in value) or keycode in allowed_keys:
             event.Skip()
             if value.endswith('.'):
                 self.AppendText('0')
                 self.SetSelection(len(value), len(value) + 1)
             if value.startswith('.'):
                 self.SetValue('0' + value)
                 self.SetSelection(0, 1)
         else:
             return None
         if self.bounds is not None:
             f = self.get_float()
             if f < self.bounds.min:
                 self.SetValue(str(self.bounds.min))
                 self.SelectAll()
             if f > self.bounds.max:
                 self.SetValue(str(self.bounds.max))
                 self.SelectAll()
     elif keycode == wx.WXK_UP:
         self.set_float(self.get_float() + self.increment)
     elif keycode == wx.WXK_DOWN:
         self.set_float(self.get_float() - self.increment)
     elif keycode == wx.WXK_HOME and self.bounds is not None:
         self.set_float(self.bounds.min)
     elif keycode == wx.WXK_END and self.bounds is not None:
         self.set_float(self.bounds.max)
     elif keycode == wx.WXK_PAGEUP:
         self.set_float(self.get_float() + (self.increment * 10))
     elif keycode == wx.WXK_PAGEDOWN:
         self.set_float(self.get_float() - (self.increment * 10))
     else:
         return None  # Don't skip.
     event.Skip()
     f = self.get_float()
     e = FloatEvent(name=self.GetName(), value=f)
     wx.PostEvent(self, e)
Exemplo n.º 9
0
 def OnBufferChar(self, event: wx.KeyEvent):
     keycode = f"{event.UnicodeKey:c}"
     key = wx_to_kakoune_keys.get(event.UnicodeKey, keycode)
     #print("CHAR", keycode, event.UnicodeKey, keys)
     if event.altDown:
         key = alt_key(key)
     self.kakoune.send_keys(key)
     event.Skip()
Exemplo n.º 10
0
    def onTyping(self, event: wx.KeyEvent) -> None:
        """Tracks the count of typed printable characters.

		Args:
			event (wx.KeyEvent): Using event.GetUnicodeKey(() will provide the key which
			was pressed.
		"""
        key = event.GetUnicodeKey()
        ignored_keys = [0, 8, 9, 13]
        if hasattr(self, "typed_character_count") and key not in ignored_keys:
            self.typed_character_count += 1
        elif key not in ignored_keys:
            self.typed_character_count = 1
        # logging.debug(f"In onTyping key={repr(chr(key))}, "
        # f"typed_text={repr(self.typed_text.GetValue())}")
        # Pass this event along.
        event.Skip()
Exemplo n.º 11
0
 def OnBufferKeyPress(self, event: wx.KeyEvent):
     key = wx_to_kakoune_keys.get(event.KeyCode)
     if key:
         #print("KEY", key)
         if event.altDown:
             key = alt_key(key)
         self.kakoune.send_keys(key)
     else:
         event.Skip()
Exemplo n.º 12
0
 def event_key_down(self, event: wx.KeyEvent):
     """Key down event like this.
     Left / Right cursor keys:
         Prev / next picture is display in same folder.
     Delete key:
         Remove displayed picture(goto trash box).
     Function key 5:
         Reload picture file.
     @todo implement
     :param event:
     :return:
     """
     print('key down')
     if event.GetKeyCode() == wx.WXK_LEFT:
         # @todo Try stopping motion when you stop pressing the key
         self.ctr.prev_file()
     elif event.GetKeyCode() == wx.WXK_RIGHT:
         self.ctr.next_file()
     elif event.GetKeyCode() == wx.WXK_DELETE:
         pass
     elif event.GetKeyCode() == wx.WXK_F5:
         pass
Exemplo n.º 13
0
    def onKeyDown(self, event: wx.KeyEvent):
        eventParams = TextEditorKeyDownParams(self, event.GetKeyCode(),
                                              event.GetUnicodeKey(),
                                              event.ControlDown(),
                                              event.ShiftDown(),
                                              event.AltDown(), event.CmdDown(),
                                              event.MetaDown())
        Application.onTextEditorKeyDown(Application.selectedPage, eventParams)

        if not eventParams.disableOutput:
            super().onKeyDown(event)

        self._checkCaretMoving()
Exemplo n.º 14
0
    def on_key_up(self, event: wx.KeyEvent) -> None:
        """Handle EVT_KEY_UP."""
        keycode = event.KeyCode

        if keycode == wx.WXK_ESCAPE:
            self.core.select_device(-1)
            self.core.select_point(-1, clear=True)
            self.select_object(-1)

        # delete selected proxy object if backspace
        elif keycode == wx.WXK_BACK or keycode == wx.WXK_DELETE:
            for obj in reversed(self._objectvis.objects):
                if obj.selected:
                    self.core.objects.pop(obj.object_id)

        else:
            event.Skip()
Exemplo n.º 15
0
 def on_key_press(self, event: wx.KeyEvent):
     key_code = event.KeyCode
     ctrl_down = event.ControlDown()
     if key_code == wx.WXK_LEFT:
         if ctrl_down:
             self.canvas.object.rotate(self.canvas.rot_point.point, ROTATE_STEP)
         else:
             self.canvas.object.shift(-SHIFT_STEP, 0)
         self.Refresh()
     elif key_code == wx.WXK_RIGHT:
         if ctrl_down:
             self.canvas.object.rotate(self.canvas.rot_point.point, -ROTATE_STEP)
         else:
             self.canvas.object.shift(SHIFT_STEP, 0)
         self.Refresh()
     elif key_code == wx.WXK_UP:
         self.canvas.object.shift(0, SHIFT_STEP)
         self.Refresh()
     elif key_code == wx.WXK_DOWN:
         self.canvas.object.shift(0, -SHIFT_STEP)
         self.Refresh()
Exemplo n.º 16
0
    def OnKey(self, event: wx.KeyEvent):
        keycode = event.GetUnicodeKey()
        if keycode != wx.WXK_NONE:
            self.camera_interactor.key_down("{:c}".format(keycode))
            self.Sync()

            # Allow escaping from selection mode
            if keycode == wx.WXK_ESCAPE:
                self.selection_mode = None
                self.camera.poly_select.reset()
                self.camera.box_select.reset()
                self.selection_controls.set_mode(
                    self.selection_controls.CANCEL)

            # Allow point removal from polygon selection
            elif self.selection_mode == GLSelectionControls.POLY and \
                    any((keycode == wx.WXK_BACK, keycode == wx.WXK_DELETE, keycode == wx.WXK_NUMPAD_DELETE)):
                self.camera.poly_select.remove_last()

            elif keycode == wx.WXK_RETURN or keycode == wx.WXK_NUMPAD_ENTER:
                self.selection_controls.set_mode(
                    self.selection_controls.CONFIRM)

            self.Refresh()
Exemplo n.º 17
0
 def on_list_key(self, evt: wx.KeyEvent):
     kc = evt.GetKeyCode()
     if kc == wx.WXK_ESCAPE and self.proto.can_cancel:
         self.do_cancel()
     evt.Skip()
Exemplo n.º 18
0
 def choose_enter(self, event: wx.KeyEvent):
     self.set_values()
     event.Skip()
Exemplo n.º 19
0
 def _on_key_press(self, evt: wx.KeyEvent):
     key = evt.GetUnicodeKey() or evt.GetKeyCode()
     if key == wx.WXK_ESCAPE:
         self._escape()
     evt.Skip()
Exemplo n.º 20
0
def on_text_control_changed(event: wx.KeyEvent, callback: Callable):
    callback(event.GetString())
Exemplo n.º 21
0
    def _on_key_down(self, event: wx.KeyEvent):
        if event.GetKeyCode() == wx.WXK_RETURN or event.GetKeyCode(
        ) == wx.WXK_TAB:
            if event.ControlDown():  # the edit control needs this key
                event.Skip()
            else:
                self.DisableCellEditControl()
                if event.ShiftDown():
                    (row, col) = self.GetTable().get_prev_cursor_rowcol(
                        self.GetGridCursorRow(), self.GetGridCursorCol())
                else:
                    (row, col) = self.GetTable().get_next_cursor_rowcol(
                        self.GetGridCursorRow(), self.GetGridCursorCol())
                self.SetGridCursor(row, col)
                self.MakeCellVisible(row, col)

        # Shift+Up
        elif event.ShiftDown() and event.GetKeyCode() == wx.WXK_UP:
            self._on_range_selecting_keyboard(row_diff=-1)

        # Shift+Down
        elif event.ShiftDown() and event.GetKeyCode() == wx.WXK_DOWN:
            self._on_range_selecting_keyboard(row_diff=1)

        # Shift+Left
        elif event.ShiftDown() and event.GetKeyCode() == wx.WXK_LEFT:
            self._on_range_selecting_keyboard(col_diff=-1)

        # Shift+Right
        elif event.ShiftDown() and event.GetKeyCode() == wx.WXK_RIGHT:
            self._on_range_selecting_keyboard(col_diff=1)

        # Ctrl+Z
        elif event.ControlDown() and event.GetKeyCode() == ord("Z"):
            self._undo()

        # Ctrl+Y
        elif event.ControlDown() and event.GetKeyCode() == ord("Y"):
            self._redo()

        # Ctrl+X
        elif event.ControlDown() and event.GetKeyCode() == ord("X"):
            self._cut_selection()

        # Ctrl+C
        elif event.ControlDown() and event.GetKeyCode() == ord("C"):
            self._copy_selection()

        elif event.ControlDown() and event.GetKeyCode() == ord("V"):
            # Ctrl+Shift+V
            if event.ShiftDown():
                self._paste(insert=True)

            # Ctrl+V
            else:
                self._paste(overwrite=True)

        # Ctrl+A
        elif event.ControlDown() and event.GetKeyCode() == ord("A"):
            self.select_range(0, len(self._binary_data) - 1)

        else:
            event.Skip()