Exemple #1
0
    def __init__(self, keyval, is_press, state):
        self.code = keyval
        self.mask = state
        self.name = ""
        if not is_press:
            self.mask |= modifier.RELEASE_MASK
            return

        try:
            self.name = chr(self.code)
            if self.name == " ":
                self.name = "space"
            else:
                self.mask &= ~modifier.SHIFT_MASK
        except:
            self.name = keysyms.keycode_to_name(self.code).lower()

        if self.name in ("control_l", "control_r", "alt_l", "alt_r", "shift_l", "shift_r"):
            self.name = ""
            return

        mods = ""
        if self.mask & modifier.ALT_MASK:
            mods += "A"
        if self.mask & modifier.CONTROL_MASK:
            mods += "C"
        if self.mask & modifier.SHIFT_MASK:
            mods += "S"

        if mods != "":
            self.name = mods + " " + self.name
Exemple #2
0
def DebugKeySequence(key_sequence):
  """Creates human-readable representation of the key sequence.

  The output format is as follows:
    - A key event is formatted as (key, modifier)
    - Key is the name of the key code.  See ibus.modifier module.
    - If no modifier keys are pressed, modifier is 'no_mod'.
      Otherwise, modifier is a concatination of 'SHIFT', 'CONTROL', or 'ALT'.
    - and key events are separated by comma ','
  Args:
    key_sequence: A list of (keycode, modifier) tuples.
  Returns:
    A human-readable string which represents the key_sequence.
  """
  elems = []
  for (keycode, mods) in key_sequence:
    if mods == 0:
      mod_str = 'no_mod'
    else:
      mod_str = ''
      if mods & modifier.SHIFT_MASK != 0:
        mod_str += 'SHIFT'
      if mods & modifier.CONTROL_MASK != 0:
        mod_str += 'CONTROL'
      if mods & modifier.ALT_MASK != 0:
        mod_str += 'ALT'
    elems.append('(%s, %s)' % (keysyms.keycode_to_name(keycode), mod_str))
  return ', '.join(elems)
Exemple #3
0
    def on_button7_clicked(self, widget):
        dlg = self.xml.get_widget('key_input_dialog')
        dlg.set_markup('<big><b>%s</b></big>' % _('Please press a key (or a key combination)'))
        dlg.format_secondary_text(_('The dialog will be closed when the key is released'))
        id = dlg.run()
        dlg.hide()
        if id == gtk.RESPONSE_OK:
            key, state = dlg.e
            if (state & (modifier.CONTROL_MASK | modifier.ALT_MASK) and
                    ord('a') <= key <= ord('z')):
                key = ord(chr(key).upper())
            self.xml.get_widget('entry2').set_text(keysyms.keycode_to_name(key))

            for w, i in [('checkbutton6', modifier.CONTROL_MASK),
                         ('checkbutton7', modifier.ALT_MASK),
                         ('checkbutton8', modifier.SHIFT_MASK)]:
                self.xml.get_widget(w).set_active(True if state & i else False)
Exemple #4
0
    def _process_key_event_internal(self, keyval, keycode, state):
        is_press = (state & modifier.RELEASE_MASK) == 0

        if not is_press:
            return False

        self.__cycle_hotkeys = prefs_get_cycle_hotkeys()
        self.__rcycle_hotkeys = prefs_get_rcycle_hotkeys()
        self.__compose_triggers = prefs_get_compose_triggers()

        if self._check_hotkeys(keyval, state):
            return True

        # after checking hotkeys, non character keys are passed though
        if (state & ST_CONTROL) or (state & ST_ALT_L) or non_trans_key(keyval):
            return False

        self.__source_layout_name = prefs_get_physical_layout()

        keysym = keysyms.keycode_to_name(keyval)
        key_name = self.__xkbc.search_key_name(self.__source_layout_name,
                                               keysym, state)
        commit_str = self.__xkbc.get_trans_ustr(self.__target_layout_name,
                                                key_name, state)

        if commit_str == None:
            return False

        if self._compose_state() == COMPOSE_START:
            cd = self._compose_get_cand_dict(commit_str)
            if cd != None:
                self._compose_process(cd)
                return True
            else:
                self._compose_end()
        elif self._compose_state() == COMPOSE_PROCESS:
            commit_str = self._compose_get_char(commit_str)
            self._compose_end()

        self.__commit_string(commit_str)
        return True
Exemple #5
0
def event_to_string(keyval, state):
    mod = None

    if state & ST_SHIFT:
        mod = "Shift"
    if state & ST_CONTROL:
        if mod == None:
            mod = "Control"
        else:
            mod += "+Control"
    if state & ST_ALT_L:
        if mod == None:
            mod = "Alt_L"
        else:
            mod += "+Alt_L"

    name = keysyms.keycode_to_name(keyval)
    if mod == None:
        return name
    else:
        return mod + "+" + name
Exemple #6
0
def event_to_string(keyval, state):
    mod = None

    if state & ST_SHIFT:
        mod = "Shift"
    if state & ST_CONTROL:
        if mod == None:
            mod = "Control"
        else:
            mod += "+Control"
    if state & ST_ALT_L:
        if mod == None:
            mod = "Alt_L"
        else:
            mod += "+Alt_L"

    name = keysyms.keycode_to_name(keyval)
    if mod == None:
        return name
    else:
        return mod + "+" + name
Exemple #7
0
    def _process_key_event_internal(self, keyval, keycode, state):
        is_press = (state & modifier.RELEASE_MASK) == 0

        if not is_press:
            return False

        self.__cycle_hotkeys = prefs_get_cycle_hotkeys()
        self.__rcycle_hotkeys = prefs_get_rcycle_hotkeys()
        self.__compose_triggers = prefs_get_compose_triggers()

        if self._check_hotkeys(keyval, state):
            return True

        # after checking hotkeys, non character keys are passed though
        if (state & ST_CONTROL) or (state & ST_ALT_L) or non_trans_key(keyval):
            return False

        self.__source_layout_name = prefs_get_physical_layout()

        keysym = keysyms.keycode_to_name(keyval)
        key_name = self.__xkbc.search_key_name(self.__source_layout_name, keysym, state)
        commit_str = self.__xkbc.get_trans_ustr(self.__target_layout_name, key_name, state)

        if commit_str == None:
            return False
        
        if self._compose_state() == COMPOSE_START:
            cd = self._compose_get_cand_dict(commit_str)
            if cd != None:
                self._compose_process(cd)
                return True
            else:
                self._compose_end()
        elif self._compose_state() == COMPOSE_PROCESS:
            commit_str = self._compose_get_char(commit_str)
            self._compose_end()

        self.__commit_string(commit_str)
        return True
Exemple #8
0
    def __init__(self, keyval, is_press, state):
        self.code = keyval
        self.mask = state
        self.name = ''
        if not is_press:
            self.mask |= modifier.RELEASE_MASK
            return

        try:
            self.name = chr(self.code)
            if self.name == ' ':
                self.name = 'space'
            else:
                self.mask &= ~modifier.SHIFT_MASK
        except:
            self.name = keysyms.keycode_to_name(self.code).lower()

        if self.name in (
                "control_l",
                "control_r",
                "alt_l",
                "alt_r",
                "shift_l",
                "shift_r",
        ):
            self.name = ""
            return

        mods = ''
        if self.mask & modifier.ALT_MASK:
            mods += 'A'
        if self.mask & modifier.CONTROL_MASK:
            mods += 'C'
        if self.mask & modifier.SHIFT_MASK:
            mods += 'S'

        if mods != '':
            self.name = mods + ' ' + self.name
Exemple #9
0
 def __str__(self):
     return "<KeyEvent: '%s'(%x), %08x>" % (keysyms.keycode_to_name(
         self.keycode), self.keycode, self.mask)
Exemple #10
0
 def __str__(self):
     return "<KeyEvent: '%s'(%x), %08x>" % (keysyms.keycode_to_name(self.keycode), self.keycode, self.mask)
 def __str__(self):
     return "%s 0x%08x" % (keysyms.keycode_to_name(self.code), self.mask)
 def __str__(self):
     return "%s 0x%08x" % (keysyms.keycode_to_name(self.code), self.mask)