Пример #1
0
 def _make_action(self):
     """ Generates and returns Action instance """
     entName = self.builder.get_object("entName")
     cbMacroType = self.builder.get_object("cbMacroType")
     pars = [x[0] for x in self.actions]
     if len(pars) == 0:
         # No action is actually set
         action = NoAction()
     elif cbMacroType.get_active() == 2:
         # Cycle
         pars = filter(lambda a: not isinstance(a, SleepAction), pars)
         action = Cycle(*pars)
     elif cbMacroType.get_active() == 1:
         # Repeating macro
         action = Macro(*pars)
         action.repeat = True
     elif len(pars) == 1:
         # Only one action
         action = pars[0]
     else:
         # Macro
         action = Macro(*pars)
     if entName.get_text().strip() != "":
         action.name = entName.get_text().strip()
     return action
Пример #2
0
 def on_btMacro_clicked(self, *a):
     """ Asks main window to close this one and display macro editor """
     if self.ac_callback is not None:
         # Convert current action into modeshift and send it to main window
         self._set_title()
         action = Macro(self.generate_modifiers(self._action))
         action.name = action.actions[0].name
         action.actions[0].name = None
         self.close()
         self.ac_callback(self.id, action, reopen=True)
Пример #3
0
	def on_btMacro_clicked(self, *a):
		""" Asks main window to close this one and display macro editor """
		if self.ac_callback is not None:
			# Convert current action into modeshift and send it to main window
			self._set_title()
			action = Macro(self.generate_modifiers(self._action))
			action.name = action.actions[0].name
			action.actions[0].name = None
			self.close()
			self.ac_callback(self.id, action, reopen=True)
Пример #4
0
	def on_btMacro_clicked(self, *a):
		""" Convert current action into macro and send it to MacroEditor """
		e = MacroEditor(self.app, self.ac_callback)
		action = Macro(self.generate_modifiers(self._action, self._selected_component.NAME=="custom"))
		e.set_input(self.id, action, mode=self._mode)
		self.close()
		e.show(self.get_transient_for())
Пример #5
0
	def _make_action(self):
		""" Generates and returns Action instance """
		entName = self.builder.get_object("entName")
		cbMacroType = self.builder.get_object("cbMacroType")
		pars = [ x[0] for x in self.actions ]
		action = Macro(*pars)
		if len(pars) == 0:
			# No action is actually set
			action = NoAction()
		elif cbMacroType.get_active() == 1:
			action.repeat = True
		elif len(pars) == 1:
			# Only one action
			action = pars[0]
		if entName.get_text().strip() != "":
			action.name = entName.get_text().strip()
		return action
Пример #6
0
 def _make_action(self):
     """ Generates and returns Action instance """
     entName = self.builder.get_object("entName")
     cbMacroType = self.builder.get_object("cbMacroType")
     pars = [x[0] for x in self.actions]
     action = Macro(*pars)
     if len(pars) == 0:
         # No action is actually set
         action = NoAction()
     elif cbMacroType.get_active() == 1:
         action.repeat = True
     elif len(pars) == 1:
         # Only one action
         action = pars[0]
     if entName.get_text().strip() != "":
         action.name = entName.get_text().strip()
     return action
Пример #7
0
 def apply_keys(self, *a):
     """ Common part of on_*key_grabbed """
     cbToggle = self.builder.get_object("cbToggle")
     cbRepeat = self.builder.get_object("cbRepeat")
     keys = list(sorted(self.keys, key=ButtonsComponent.modifiers_first))
     action = ButtonAction(keys[0])
     if len(keys) > 1:
         actions = [ButtonAction(k) for k in keys]
         action = MultiAction(*actions)
     if cbRepeat.get_active():
         action = Macro(action)
         action.repeat = True
     elif cbToggle.get_active():
         action = Cycle(PressAction(action), ReleaseAction(action))
     self.editor.set_action(action)
Пример #8
0
    def _parse_action(self, frm=Action.ALL):
        """
		Parses one action, that is one of:
		 - something(params)
		 - something()
		 - something
		"""
        # Check if next token is TokenType.NAME and grab action name from it
        t = self._next_token()
        if t.type != TokenType.NAME:
            raise ParseError("Expected action name, got '%s'" % (t.value, ))
        if t.value not in frm:
            raise ParseError("Unknown action '%s'" % (t.value, ))
        action_name = t.value
        action_class = frm[action_name]

        # Check if there are any tokens left - return action without parameters
        # if not
        if not self._tokens_left():
            return self._create_action(action_class)

        # Check if token after action name is parenthesis and if yes, parse
        # parameters from it
        t = self._peek_token()
        parameters = []
        if t.type == TokenType.OP and t.value == '.':
            # ACTION dict can have nested dicts; SOMETHING.action
            if type(action_class) == dict:
                self._next_token()
                return self._parse_action(action_class)
            else:
                raise ParseError("Unexpected '.' after '%s'" % (action_name, ))
        if t.type == TokenType.OP and t.value == '(':
            parameters = self._parse_parameters()
            if not self._tokens_left():
                return self._create_action(action_class, *parameters)
            t = self._peek_token()

        # ... or, if it is one of ';', 'and' or 'or' and if yes, parse next action
        if t.type == TokenType.NAME and t.value == 'and':
            # Two (or more) actions joined by 'and'
            self._next_token()
            if not self._tokens_left():
                raise ParseError("Expected action after 'and'")
            action1 = self._create_action(action_class, *parameters)
            action2 = self._parse_action()
            return MultiAction(action1, action2)

        if t.type == TokenType.NEWLINE or t.value == "\n":
            # Newline can be used to join actions instead of 'and'
            self._next_token()
            if not self._tokens_left():
                # Newline at end of string is not error
                return self._create_action(action_class, *parameters)
            t = self._peek_token()
            if t.type == TokenType.OP and t.value in (')', ','):
                # ')' starts next line
                return self._create_action(action_class, *parameters)
            action1 = self._create_action(action_class, *parameters)
            action2 = self._parse_action()
            return MultiAction(action1, action2)

        if t.type == TokenType.OP and t.value == ';':
            # Two (or more) actions joined by ';'
            self._next_token()
            while self._tokens_left() and self._peek_token(
            ).type == TokenType.NEWLINE:
                self._next_token()
            if not self._tokens_left():
                # Having ';' at end of string is not actually error
                return self._create_action(action_class, *parameters)
            action1 = self._create_action(action_class, *parameters)
            action2 = self._parse_action()
            return Macro(action1, action2)

        return self._create_action(action_class, *parameters)