示例#1
0
    def __init__(self, name='', file=None):
        """
            Constructor arguments:
             - *name* (*str*, default *empty string*) --
               name of the Windows system sound to play. This argument is
               effectively an alias for *file* on other platforms.
             - *file* (*str*, default *None*) --
               path of wave file to play when the action is executed.

            If *name* and *file* are both *None*, then waveform playback
            will be silenced on Windows when the action is executed. Nothing
            will happen on other platforms.

        """
        ActionBase.__init__(self)
        self._flags = 0
        if file is not None:
            self._name = file
            if os.name == 'nt':
                self._flags = winsound.SND_FILENAME
        else:
            self._name = name
            if os.name == 'nt':
                self._flags = winsound.SND_ALIAS

        # Expand ~ constructions and shell variables in the file path if
        # necessary.
        if file is not None or os.name != 'nt':
            self._name = os.path.expanduser(os.path.expandvars(self._name))

        self._str = str(self._name)
示例#2
0
    def __init__(self, *args, **kwargs):
        """
            Constructor arguments:
             - *args* (variable argument list of *str*'s) --
               these strings are passed to subprocess.Popen()
               to start the application as a child process
             - *cwd* (*str*, default *None*) --
               if not *None*, then start the application in this
               directory
             - *focus_after_start* (*bool*, default *False*) --
               if *True*, then attempt to bring the window to the foreground
               after starting the application.

            A single *list* or *tuple* argument can be used instead of
            variable arguments.

        """
        ActionBase.__init__(self)
        if len(args) == 1 and isinstance(args[0], (tuple, list)):
            args = args[0]  # use the sub-list instead

        self._args = args

        self._cwd = kwargs.pop("cwd", None)
        self._focus_after_start = kwargs.pop("focus_after_start", False)
        if kwargs:
            raise ActionError("Invalid keyword arguments: %r" % kwargs)

        # Expand any variables within path names.
        self._args = [self._interpret(a) for a in self._args]
        if self._cwd:
            self._cwd = self._interpret(self._cwd)

        self._str = str(", ".join(repr(a) for a in self._args))
示例#3
0
    def __init__(self, function, remap_data=None, **defaults):
        """
            Constructor arguments:
             - *function* (callable) --
               the function to call when this action is executed
             - *remap_data* (dict, default: None) --
               optional dict of data keys to function keyword arguments
             - defaults --
               default keyword-values for the arguments with which
               the function will be called

        """
        ActionBase.__init__(self)
        self._function = function
        self._defaults = defaults
        self._remap_data = remap_data or {}
        self._str = function.__name__

        # Get argument names and defaults. Use getfullargspec() in Python 3
        # to avoid deprecation warnings.
        if six.PY2:
            # pylint: disable=deprecated-method
            argspec = inspect.getargspec(self._function)
        else:
            argspec = inspect.getfullargspec(self._function)

        args, varkw = argspec[0], argspec[2]
        self._filter_keywords = not varkw
        self._valid_keywords = set(args)
示例#4
0
    def __init__(self, default=None, actions=None):
        '''
            Constructor arguments:
             - *default* (action object, default *do nothing*) -- the
               default action to execute if there was no matching context in
               *actions*.
             - *actions* (iterable, default *empty list*) -- an iterable
               object containing context-action pairs. The action of the
               first matching context will be executed.

        '''
        if actions is None:
            actions = []

        # Validate default action.
        # Use a new ActionBase action (to do nothing) if default is None.
        if default is None:
            self._log_init.debug("Using default action for ContextAction")
            default = ActionBase()

        # Otherwise check if default is an action.
        elif not isinstance(default, ActionBase):
            raise TypeError("Default action for ContextAction should be an "
                            "ActionBase or None, not %s." % default)

        # Set the default action.
        self.default = default

        # Validate the actions list.
        # Check if it can be converted to a dictionary. or convert it to a
        # is one already (for consistent evaluation order).
        if not isinstance(actions, dict):
            dict(actions)  # can raise a ValueError

        # Convert dictionaries to lists instead for consistent evaluation
        # order.
        else:
            actions = list(actions.items())

        # Check the types of all keys and values.
        for (context, action) in actions:
            if not isinstance(context, Context):
                raise TypeError("ContextAction actions list contains "
                                "unexpected object: %s, instead of a "
                                "Context." % context)
            if not isinstance(action, ActionBase):
                raise TypeError("ContextAction actions list contains "
                                "unexpected object: %s, instead of an "
                                "ActionBase." % action)

        # Set the actions list.
        self.actions = actions
        ActionBase.__init__(self)
示例#5
0
    def __init__(self,
                 command=None,
                 process_command=None,
                 synchronous=False,
                 hide_window=True):
        """
            Constructor arguments:
             - *command* (str or list) -- the command to run when this
               action is executed. It will be parsed by :meth:`shlex.split`
               if it is a string and passed directly to ``subprocess.Popen``
               if it is a list. Command arguments can be included.
             - *process_command* (callable) -- optional callable to invoke
               with the :class:`Popen` object after successfully starting
               the subprocess. Using this argument overrides the
               :meth:`process_command` method.
             - *synchronous* (bool, default *False*) -- whether to wait
               until :meth:`process_command` has finished executing before
               continuing.
             - *hide_window* (bool, default *True*) -- whether to hide the
               application window. Set to *False* if using this action with
               GUI programs. This argument only applies to Windows. It has
               no effect on other platforms.

        """
        ActionBase.__init__(self)
        self._proc = None

        # Complex handling of arguments because of clashing use of the names
        # at the class level: property & class-value.
        if command is not None:
            self.command = command
        command_types = (string_types, list)
        if not (self.command and isinstance(self.command, command_types)):
            raise TypeError("command must be a non-empty string or list, "
                            "not %s" % self.command)
        if synchronous is not False:
            self.synchronous = synchronous

        if not (process_command is None or callable(process_command)):
            raise TypeError("process_command must be a callable object or "
                            "None")

        self._process_command = process_command
        self._hide_window = hide_window

        # Set the string used for representing actions.
        if isinstance(self.command, list):
            self._str = "'%s'" % " ".join(self.command)
        else:
            self._str = "'%s'" % self.command
示例#6
0
    def __init__(self, *words, **kwargs):
        ActionBase.__init__(self)
        self._words = tuple(words)
        if "extra" in kwargs:
            self._extra = kwargs.pop("extra")
        else:
            self._extra = None

        # Set pretty printing string used by __str__ and __unicode__.
        self._str = u", ".join(repr(w) for w in self._words)

        # Make sure that all keyword arguments have been consumed.
        if kwargs:
            raise ActionError("Invalid arguments: %r"
                              % ", ".join(list(kwargs.keys())))
示例#7
0
    def __init__(self, series, speed=1):
        """
            Constructor arguments:
             - *series* (sequence of 2-tuples) --
               the recognitions to playback.  Each element must be a
               2-tuple of the form *(["words", "two", "mimic"], interval)*,
               where *interval* is a float giving the number of seconds to
               pause after the given words are mimicked.
             - *speed* (*float*) --
               the factor by which to speed up playback.  The intervals
               after each mimic are divided by this number.

        """
        ActionBase.__init__(self)
        self._series = tuple(series)
        self._speed = float(speed)
        self._str = str([w for w, i in self._series])
    def __init__(self, title=None, executable=None, timeout=15):
        self._match_functions = []
        string = []

        if title is not None:
            self._title = title.lower()
            self._match_functions.append("_match_title")
            string.append("title=%r" % self._title)
        else:
            self._title = None

        if executable is not None:
            self._executable = executable.lower()
            self._match_functions.append("_match_executable")
            string.append("executable=%r" % self._executable)
        else:
            self._executable = None

        self._timeout = timeout

        ActionBase.__init__(self)
        self._str = ", ".join(string)
    def __init__(self,
                 executable=None,
                 title=None,
                 index=None,
                 filter_func=None,
                 focus_only=False):
        if executable: self.executable = executable.lower()
        else: self.executable = None
        if title: self.title = title.lower()
        else: self.title = None
        self.index = index
        self.filter_func = filter_func
        self.focus_only = focus_only
        ActionBase.__init__(self)

        arguments = []
        if executable: arguments.append("executable=%r" % executable)
        if title: arguments.append("title=%r" % title)
        if index: arguments.append("index=%r" % index)
        if filter_func: arguments.append("filter_func=%r" % filter_func)
        if focus_only: arguments.append("focus_only=%r" % focus_only)
        self._str = ", ".join(arguments)
    def __init__(self, title=None, executable=None,
                 timeout=15):
        self._match_functions = []
        string = []

        if title is not None:
            self._title = title.lower()
            self._match_functions.append("_match_title")
            string.append("title=%r" % self._title)
        else:
            self._title = None

        if executable is not None:
            self._executable = executable.lower()
            self._match_functions.append("_match_executable")
            string.append("executable=%r" % self._executable)
        else:
            self._executable = None

        self._timeout = timeout

        ActionBase.__init__(self)
        self._str = ", ".join(string)
示例#11
0
    def __init__(self, function, remap_data=None, **defaults):
        """
            Constructor arguments:
             - *function* (callable) --
               the function to call when this action is executed
             - *remap_data* (dict, default: None) --
               optional dict of data keys to function keyword arguments
             - defaults --
               default keyword-values for the arguments with which
               the function will be called

        """
        ActionBase.__init__(self)
        self._function = function
        self._defaults = defaults
        self._remap_data = remap_data or {}
        self._str = function.__name__

        # TODO Use inspect.signature instead; getargspec is deprecated.
        (args, _, varkw, defaults) = getargspec(self._function)
        if varkw: self._filter_keywords = False
        else: self._filter_keywords = True
        self._valid_keywords = set(args)
    def __init__(self, function, remap_data=None, **defaults):
        """
            Constructor arguments:
             - *function* (callable) --
               the function to call when this action is executed
             - *remap_data* (dict, default: None) --
               optional dict of data keys to function keyword arguments
             - defaults --
               default keyword-values for the arguments with which
               the function will be called

        """
        ActionBase.__init__(self)
        self._function = function
        self._defaults = defaults
        self._remap_data = remap_data or {}
        self._str = function.__name__

        # TODO Use inspect.signature instead; getargspec is deprecated.
        (args, varargs, varkw, defaults) = getargspec(self._function)
        if varkw:  self._filter_keywords = False
        else:      self._filter_keywords = True
        self._valid_keywords = set(args)
示例#13
0
文件: node.py 项目: vishweshs4/caster
 def __init__(self, _):
     ActionBase.__init__(self)
示例#14
0
 def __init__(self, *args, **kwargs):
     ActionBase.__init__(self)
示例#15
0
文件: node.py 项目: seekM/caster
 def __init__(self, _):
     ActionBase.__init__(self)