コード例 #1
0
    def on_execute(self, item, action):
        if item.category() not in (self.ITEM_HISTORY, self.ITEM_URL,
                                   kp.ItemCategory.KEYWORD):
            return

        if item.target() == 'urlshortenerclearhistory':
            self.historian.clear()
            return

        # Copy the URL from history or copy the shortened url
        if action is None or action.name() == 'copy':
            kpu.set_clipboard(item.label())
            return

        # Open the URL in browser
        if action.name() == 'open':
            kpu.web_browser_command(private_mode=False,
                                    url=item.label(),
                                    execute=True)
            return

        # Remove the url from history
        if action.name() == 'remove':
            self.historian.remove(item.target())
            return
コード例 #2
0
    def on_execute(self, item, action):
        if (item.category() == self.ITEMCAT):
            to_clipboard = getattr(self.fakeGenerator, item.target())()
        elif (item.category() == self.ITEMRESULT):
            to_clipboard = item.label()

        kpu.set_clipboard(to_clipboard)
コード例 #3
0
 def on_execute(self, item, action):
     if item and item.category() == self.ITEMCAT_RESULT:
         kpu.set_clipboard(item.data_bag())
     elif item and item.category() == self.ITEMCAT_RELOAD_DEFS:
         self.reconfigure()
         self.on_catalog()
     elif item and item.category() == self.ITEMCAT_CREATE_CUSTOM_DEFS:
         try:
             builtin_cvtdefs = os.path.join("data/", self.CVTDEF_FILE)
             builtin_cvtdefs_text = self.load_text_resource(
                 builtin_cvtdefs).replace("\r\n", "\n")
             custom_cvtdefs = os.path.join(kp.user_config_dir(),
                                           self.CVTDEF_FILE)
             if os.path.exists(custom_cvtdefs):
                 self.warn(
                     f"Customized conversion file '{custom_cvtdefs}' already exists. It hasn't been overwritten"
                 )
             else:
                 with open(custom_cvtdefs, "w", encoding="utf-8") as f:
                     f.write(builtin_cvtdefs_text)
                     f.close()
                 kpu.explore_file(custom_cvtdefs)
                 self.reconfigure()
                 self.on_catalog()
         except Exception as exc:
             self.warn(
                 f"Failed to create custom conversion definition file '{custom_cvtdefs}', {exc}"
             )
コード例 #4
0
    def on_execute(self, item, action):
        if item.category() != self.ITEMCAT_RESULT:
            return

        # browse or copy url
        if action and action.name() in (self.ACTION_BROWSE,
                                        self.ACTION_BROWSE_PRIVATE,
                                        self.ACTION_COPY_URL):
            # build the url and its arguments
            query = self._parse_and_merge_input(item)
            url = self._build_browse_url(query['lang_in'], query['lang_out'],
                                         query['terms'])

            # copy url
            if action.name() == self.ACTION_COPY_URL:
                kpu.set_clipboard(url)

            # launch browser
            else:
                if action.name() == self.ACTION_BROWSE_PRIVATE:
                    private_mode = True
                else:
                    private_mode = None
                kpu.web_browser_command(private_mode=private_mode,
                                        url=url,
                                        execute=True)

        # default action: copy result (ACTION_COPY_RESULT)
        else:
            kpu.set_clipboard(item.target())
コード例 #5
0
    def on_execute(self, item, action):
        self.dbg("on_execute")
        text = None
        flag_meta = eval(item.data_bag())
        self.dbg(flag_meta)
        if item.category() == self.CATEGORY_VALUE:
            if flag_meta.base == 2:
                text = "{:b}".format(flag_meta.value)
            elif flag_meta.base == 10:
                text = str(flag_meta.value)
            elif flag_meta.base == 16:
                text = "{:X}".format(flag_meta.value)
        elif item.category() == self.CATEGORY_SINGLE_FLAG:
            flag_value = int(item.target()[len(self.TARGET_PREFIX_FLAG):])
            flag_type = self._flag_types[flag_meta.flag_type]
            if flag_meta.base == 2:
                text = "0b{:b} {}".format(flag_value,
                                          flag_type[flag_value] if flag_value in flag_type else self.UNKNOWN_FLAG_LABEL)
            elif flag_meta.base == 10:
                text = "{} {}".format(flag_value,
                                      flag_type[flag_value] if flag_value in flag_type else self.UNKNOWN_FLAG_LABEL)
            elif flag_meta.base == 16:
                text = "0x{:X} {}".format(flag_value,
                                          flag_type[flag_value] if flag_value in flag_type else self.UNKNOWN_FLAG_LABEL)

        self.dbg("Clipboard text:", text)
        if text:
            kpu.set_clipboard(text)
コード例 #6
0
 def on_execute(self, item, action):
     if item and item.category() == kp.ItemCategory.EXPRESSION:
         kpu.set_clipboard(item.target())
     elif item.category() == kp.ItemCategory.URL:
         kpu.web_browser_command(
                 private_mode=False, new_window=False,
                 url=item.target(), execute=True)
コード例 #7
0
    def on_execute(self, item, action):
        if item.category() != self.ITEM_EASYSEARCH:
            return

        if action and action.name() == "copy":
            kpu.set_clipboard(item.target())
        elif action and action.name() == "private":
            self._open_browser(
                item.target(),
                True,
                self.settings.get_bool('new_window',
                                       section=self.SECTION_MAIN,
                                       fallback=False),
            )
        elif action and action.name() == "new":
            self._open_browser(
                item.target(),
                self.settings.get_bool('private_mode',
                                       section=self.SECTION_MAIN,
                                       fallback=False),
                True,
            )
        else:
            self._open_browser(
                item.target(),
                self.settings.get_bool('private_mode',
                                       section=self.SECTION_MAIN,
                                       fallback=False),
                self.settings.get_bool('new_window',
                                       section=self.SECTION_MAIN,
                                       fallback=False),
            )
コード例 #8
0
ファイル: pass.py プロジェクト: clarkb7/keypirinha-pass
 def _timer_reset_clipboard(orig_clip=None, pass_hash=None):
     if orig_clip is None or pass_hash is None:
         return
     # Only reset clip if clipboard still contains pass
     cur_clip = kpu.get_clipboard()
     clip_hash = hashlib.md5(cur_clip.encode()).digest()
     if clip_hash == pass_hash:
         kpu.set_clipboard(orig_clip)
コード例 #9
0
 def on_execute(self, item, action):
     if (action is None or (action is not None and action.name() == self.ACTION_OPEN_URL)):
         kpu.web_browser_command(
             url = item.target(),
             execute = True
         )
     else:
         kpu.set_clipboard(item.target())
     pass
コード例 #10
0
    def on_execute(self, item, action):
        if not item and item.category() != self.ITEMCAT_RESULT:
            return
        if not item.data_bag():
            return

        data_bag = kpu.kwargs_decode(item.data_bag())
        if not action or action.name() == self.ACTION_DEFAULT:
            kpu.set_clipboard(data_bag['translation'])
コード例 #11
0
ファイル: lipsum.py プロジェクト: Fuhrmann/keypirinha-lipsum
    def on_execute(self, item, action):
        ammount = self._search_number(item.label())

        start = "yes"
        if action:
            start = action.name()

        text = self._fetch_text(item.target(), ammount, start)
        kpu.set_clipboard(text)
        self.info("Lorem Ipsum text copied to clipboard!")
コード例 #12
0
ファイル: calc.py プロジェクト: reggiedev/Packages
 def on_execute(self, item, action):
     if item and item.category() == kp.ItemCategory.EXPRESSION:
         kpu.set_clipboard(item.target())
         self.var_handler.save_if_var(self.ans)
     elif item and (item.category() == self.ITEMCAT_VAR):
         if action and action.name() == "copy":
             kpu.set_clipboard(item.target())
         elif action and action.name() == "delete":
             self.var_handler.delete_var(item.data_bag(), self.MATH_CONSTANTS)
         elif action and action.name() == "delete_all":
             self.var_handler.delete_all_vars(self.MATH_CONSTANTS)
コード例 #13
0
    def on_execute(self, item, action):
        target_props = kpu.kwargs_decode(item.target())
        profile_name = target_props['profile']
        args = item.raw_args()

        try:
            profile = self.profiles[profile_name]
        except KeyError:
            self.warn(
                'Item definition not found in current config: "{}"'.format(
                    profile_name))
            return

        if not args:  # open the search engine home page
            base = profile['provider'].browse_base
            try:
                parts = urllib.parse.urlsplit(base)
                url = '{}://{}'.format(parts.scheme, parts.netloc)
            except ValueError:
                url = base
            kpu.web_browser_command(url=url, execute=True)
            return

        # choose action
        action_name = action.name() if action else None
        if not action_name:
            action_name = profile['default_action']
        if action_name and action_name not in self.actions_names:
            self.warn(
                'Unknown action "{}". Falling back to default: {}'.format(
                    action_name, self.DEFAULT_ACTION))
            action_name = self.DEFAULT_ACTION
        if not action_name:
            action_name = self.DEFAULT_ACTION

        # browse or copy url
        if action_name in (self.ACTION_BROWSE, self.ACTION_BROWSE_PRIVATE,
                           self.ACTION_COPY_URL):
            url = profile['provider'].build_browse_url(args)

            # copy url
            if action_name == self.ACTION_COPY_URL:
                kpu.set_clipboard(url)

            # launch browser
            else:
                private_mode = True if action_name == self.ACTION_BROWSE_PRIVATE else None
                kpu.web_browser_command(private_mode=private_mode,
                                        url=url,
                                        execute=True)

        # default action: copy result (ACTION_COPY_RESULT)
        else:
            kpu.set_clipboard(args)
コード例 #14
0
    def on_execute(self, item, action):
        """
        Exeute the given item
        """
        print(
            "Executing item [{}] of type [{}], category [{}] and target [{}]".
            format(item, type(item), item.category(), item.target()))

        # Extract and copy the value
        value = item.target().split(',', maxsplit=1)[-1]
        print("Copying symbol to clipboard [{}]".format(value))
        kpu.set_clipboard(value)
コード例 #15
0
    def do_card_action(self, contact):
        text = f"Name\t{contact[self.AD_ATTR_NAME]}"

        if contact[self.AD_ATTR_MAIL]:
            text += f"\nMail\t{contact[self.AD_ATTR_MAIL]}"
        for v in self.VERB_LIST:
            if v.contact_field.startswith(
                    "TEL;") and v.contact_field in contact:
                text += f"\n{v.name}#\t{contact[v.contact_field]}"
        if contact[self.AD_ATTR_TITLE]:
            text += f"\nTitle\t{contact[self.AD_ATTR_TITLE]}"

        kpu.set_clipboard(text)
コード例 #16
0
ファイル: pass.py プロジェクト: clarkb7/keypirinha-pass
    def _put_data_in_clipboard(self, data):
        # XXX: This only works with text clipboard data, not fancy Windows objects (files, office content, etc)
        orig_clip = kpu.get_clipboard()
        pass_hash = hashlib.md5(data.encode()).digest()

        # keypirinha.delay isn't implemented yet, so a timer will do
        kwargs = {'orig_clip': orig_clip, 'pass_hash': pass_hash}
        self._clip_timer = threading.Timer(self.CLIP_TIME,
                                           self._timer_reset_clipboard,
                                           kwargs=kwargs)

        kpu.set_clipboard(data)
        self._clip_timer.start()
コード例 #17
0
 def on_execute(self, item, action):
     if item.category() in [self.ITEMCAT_JOB_FOLDER, self.ITEMCAT_NODE]:
         if action and action.name() in ["open_url", "copy_url", "open_in_private"]:
             if action.name() == "open_url":
                 kpu.web_browser_command(private_mode=None, new_window=None, url=item.target(), execute=True)
             elif action.name() == "copy_url":
                 kpu.set_clipboard(item.target())
             elif action.name() == "open_in_private":
                 kpu.web_browser_command(private_mode=True, new_window=None, url=item.target(), execute=True)
         else:
             kpu.web_browser_command(private_mode=None, new_window=None, url=item.target(), execute=True)
     else:
         kpu.execute_default_action(self, item, action)
コード例 #18
0
ファイル: codic.py プロジェクト: shuGH/keypirinha-codic
    def _on_execute_result(self, item, action):
        url = self._build_browse_url(self._query)
        name = action.name() if action else self.ACTION_COPY_RESULT

        if name == self.ACTION_COPY_RESULT:
            decided = self._remove_open_box(item.label())
            kpu.set_clipboard(decided)
        elif name == self.ACTION_BROWSE:
            kpu.web_browser_command(private_mode=False, url=url, execute=True)
        elif name == self.ACTION_BROWSE_PRIVATE:
            kpu.web_browser_command(private_mode=True, url=url, execute=True)
        elif name == self.ACTION_COPY_URL:
            kpu.set_clipboard(url)
コード例 #19
0
 def on_execute(self, item, action):
     self.dbg(action.name() if action else "No action")
     self.dbg(item.category() if item else "No item")
     if item and item.category() == self.ITEMCAT_RESULT:
         if action and action.name() == "copy":
             kpu.set_clipboard(item.target())
         elif action and action.name() == "copy_md":
             link = "[{}]({})".format(
                 item.label().split(":", maxsplit=1)[0], item.target())
             kpu.set_clipboard(link)
         else:
             self.dbg("Launching", item.target())
             kpu.web_browser_command(url=item.target(), execute=True)
コード例 #20
0
    def on_execute(self, item, action):
        if not item and item.category() != kp.ItemCategory.EXPRESSION:
            return
        if not item.data_bag():
            return

        data_bag = kpu.kwargs_decode(item.data_bag())
        if not action or action.name() == self.ACTION_DEFAULT:
            kpu.set_clipboard(data_bag['translation_result'])
        elif action.name() == self.ACTION_OPEN_LEO:
            kpu.web_browser_command(
                url=self.URL_LEO.format(**data_bag),
                execute=True
            )
コード例 #21
0
 def on_execute(self, item, action):
     self.dbg('On Execute "{}" (action: {})'.format(item, action))
     if not item:
         return
     if item.category() == kp.ItemCategory.EXPRESSION:
         kpu.set_clipboard(item.data_bag())
         return
     if item.category() == self.SAVE_CATEGORY:
         self._add_fact(Fact(item.data_bag(), item.label()))
         self.facts = self._load_facts()
         return
     if item.category() == self.DELETE_CATEGORY:
         self._delete_fact(item.label())
         self.facts = self._load_facts()
         return
コード例 #22
0
    def on_execute(self, item, action):
        if item:
            is_private = action and action.name() == "browse_private"
            is_url_copy = (item.category() == kp.ItemCategory.URL and action
                           and action.name() == "copy")
            is_browse_action = action is None or action.name().find(
                "browse") != -1

            if item.target() == "update":
                self._update_cache(force=True)
            elif item.category() == self.ITEMCAT_COMMAND or is_url_copy:
                kpu.set_clipboard(item.target())
            elif is_browse_action:
                kpu.web_browser_command(private_mode=is_private,
                                        url=item.target(),
                                        execute=True)
コード例 #23
0
    def on_execute(self, item, action):
        if item.category() == self.ITEMCAT_UPDATE:
            self.broker.update()
            self._update_update_item()
            return
        if item.category() != self.ITEMCAT_RESULT:
            return

        # browse or copy url
        if action and action.name() == self.ACTION_COPY_AMOUNT:
            amount = item.data_bag()[:-4]

            kpu.set_clipboard(amount)
        # default action: copy result (ACTION_COPY_RESULT)
        else:
            kpu.set_clipboard(item.data_bag())
コード例 #24
0
    def on_execute(self, item, action):
        self.dbg('on_execute')

        if not item or not item.data_bag():
            return
        data_bag = kpu.kwargs_decode(item.data_bag())
        if not data_bag:
            return

        # ACTION_KEY_DEFAULT
        if not action or action.name() == self.ACTION_BROWSE:
            webbrowser.open(data_bag['url'])
        elif action.name() == self.ACTION_COPY_URL:
            kpu.set_clipboard(data_bag['url'])
        elif action.name() == self.ACTION_COPY_RESULT and item.category(
        ) != self.ITEMCAT_ISSUES:
            kpu.set_clipboard(data_bag['effective_value'])
コード例 #25
0
    def on_execute(self, item, action):
        self.dbg("on_execute", item.target(), item.raw_args(), item.data_bag())

        if item.target() == self.COMMAND_RESCAN:
            self._rescan()
            self.on_catalog()
        elif item.target() == self.COMMAND_OPEN_GIT_BASH:
            self._run_command(self._git_bash_path, None, False, item.raw_args())
        elif item.target() == self.COMMAND_REMOVE_OLD:
            remove_repos = []
            for repo in self._git_repos:
                if not os.path.exists(repo.path):
                    remove_repos.append(repo)
            for repo in remove_repos:
                self._git_repos.remove(repo)
            self._save_repos()
            self.on_catalog()
            self.info("Removed", len(remove_repos), "repositories that don't exist anymore.")
        elif item.target() == self.COMMAND_RENAME:
            new_name = item.raw_args()
            repo_path = item.data_bag()
            for repo in self._git_repos:
                if repo.path == repo_path:
                    self.info("renaming", repo.name, "to", new_name, repo_path)
                    repo.name = new_name
                    break
            self._save_repos()
            self.on_catalog()
        elif item.target() == self.COMMAND_COPY_PATH:
            repo_path = item.data_bag()
            kpu.set_clipboard(repo_path)
        elif item.target().startswith(self.COMMAND_CMD_ALL):
            cmd = eval(item.data_bag())
            self.dbg(cmd)
            args = cmd.args
            for repo in self._git_repos:
                cmd.args = args.format(repo_path=repo.path)
                self.dbg(cmd)
                self._run_command(cmd.cmd, cmd.args, cmd.internal, repo.path)
        elif item.category() == kp.ItemCategory.FILE:
            kpu.execute_default_action(self, item, action)
        else:
            cmd = eval(item.data_bag())
            self._run_command(cmd.cmd, item.raw_args(), cmd.internal, cmd.cwd)
コード例 #26
0
ファイル: websuggest.py プロジェクト: joedf/Packages
    def on_execute(self, item, action):
        target_props = kpu.kwargs_decode(item.target())
        profile_name = target_props['profile']

        try:
            profile = self.profiles[profile_name]
        except KeyError:
            self.warn('Item definition not found in current config: "{}"'.format(profile_name))
            return

        # choose action
        action_name = action.name() if action else None
        if not action_name:
            action_name = profile['default_action']
        if action_name and action_name not in self.actions_names:
            self.warn(
                'Unknown action "{}". Falling back to default: {}'.format(
                    action_name, self.DEFAULT_ACTION))
            action_name = self.DEFAULT_ACTION
        if not action_name:
            action_name = self.DEFAULT_ACTION

        # browse or copy url
        if action_name in (self.ACTION_BROWSE, self.ACTION_BROWSE_PRIVATE,
                           self.ACTION_COPY_URL):
            url = profile['provider'].build_browse_url(item.raw_args())

            # copy url
            if action_name == self.ACTION_COPY_URL:
                kpu.set_clipboard(url)

            # launch browser
            else:
                if action_name == self.ACTION_BROWSE_PRIVATE:
                    private_mode = True
                else:
                    private_mode = None
                kpu.web_browser_command(private_mode=private_mode, url=url,
                                        execute=True)

        # default action: copy result (ACTION_COPY_RESULT)
        else:
            kpu.set_clipboard(item.raw_args())
コード例 #27
0
ファイル: kill.py プロジェクト: ueffel/Keypirinha-Plugin-Kill
    def on_execute(self, item, action):
        """Executes the selected (or default) kill action on the selected item
        """
        self.__executing = True
        loop = None
        try:
            # get default action if no action was explicitly selected
            if action is None:
                for act in self._actions:
                    if act.name() == self._default_action:
                        action = act

            if action.name() == self.ACTION_COPY_CMD_LINE:
                databag = eval(item.data_bag())
                self.dbg(databag)
                if "CommandLine" in databag:
                    kpu.set_clipboard(databag["CommandLine"])
                else:
                    self.err("CommandLine could not be obtained")
                return
            elif action.name() == self.ACTION_COPY_IMAGE_PATH:
                databag = eval(item.data_bag())
                self.dbg(databag)
                if "ExecutablePath" in databag:
                    kpu.set_clipboard(databag["ExecutablePath"])
                else:
                    self.err("ExecutablePath could not be obtained")
                return

            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            if action.name().endswith(self.ADMIN_SUFFIX):
                self._kill_process_admin(item, action.name())
            else:
                killing_task = asyncio.ensure_future(self._kill_process_normal(item, action.name()))
                loop.run_until_complete(killing_task)
        finally:
            self._cleanup()
            self.__executing = False
            if loop:
                loop.close()
コード例 #28
0
    def on_execute(self, item, action):
        """Perform an action related with the selected item/action item."""
        item_category = item.category()
        item_label = item.label()

        try:
            item_target = kpu.kwargs_decode(item.target())
        except Exception:
            item_target = item.target()

        # Open in browser if there it is an URL in the target
        if 'url' in item_target:
            url = item_target['url']
            # If it is a moviedb url to be opened, append the language query
            if constants.URL_MOVIEDB_BASE in url:
                url += '?language={}'.format(self.settings['language'])

            kpu.web_browser_command(url=url, execute=True)

        # Copy text
        if item_category == TextSuggestion.ITEM_CAT:
            kpu.set_clipboard(item_label)
コード例 #29
0
    def on_execute(self, item, action):
        if item.category() not in [
                self.ITEM_EASYSEARCH, self.ITEM_EASYSEARCH_HISTORY
        ]:
            return

        private_mode = self.settings.get_bool('private_mode',
                                              self.SECTION_MAIN, False)
        new_window = self.settings.get_bool('new_window', self.SECTION_MAIN,
                                            False)

        if action and action.name() == "copy":
            kpu.set_clipboard(item.target())
        elif action and action.name() == "private":
            self._open_browser(item, True, new_window)
        elif action and action.name() == "new":
            self._open_browser(item, private_mode, True)
        elif action and action.name() == "delete":
            self._delete_entry(item)
        elif action and action.name() == "clear":
            self._clear_history()
        else:
            self._open_browser(item, private_mode, new_window)
コード例 #30
0
    def on_execute(self, item, action):
        if (not item):
            return

        selection = item.target()
        params = kpu.kwargs_decode(item.data_bag())
        verb_name = params['verb_name']
        contact_no = int(params['contact_no'])
        contact = self.contacts[contact_no]
        verb = self.VERBS[verb_name]

        if self._debug:
            self.dbg(
                f"Executing {verb_name}: {selection}, defaultAction: {item.category() == self.ITEMCAT_CONTACT}\n"
            )

        if verb.action == self.ACTION_CALL:
            self.do_call_action(contact, selection, self.cell_protocol)
        elif verb.action == self.ACTION_MAIL:
            self.do_mail_action(contact, verb, self.mail_protocol)
        elif verb.action == self.ACTION_CARD:
            self.do_card_action(contact)
        else:
            kpu.set_clipboard(selection)
コード例 #31
0
    def on_execute(self, item, action):
        if item.category() != self.ITEMCAT_RESULT:
            return

        # browse or copy url
        if action and action.name() in (self.ACTION_BROWSE,
                                        self.ACTION_COPY_URL):
            # build the url and its arguments
            url = self._extract_autocomplete_url(item)

            # copy url
            if action.name() == self.ACTION_COPY_URL:
                kpu.set_clipboard(url)

            # launch browser
            elif action.name() == self.ACTION_BROWSE:
                kpu.web_browser_command(private_mode=None,
                                        url=url,
                                        execute=True)

        # default action: copy result (ACTION_COPY_RESULT)
        else:
            url = self._extract_autocomplete_url(item)
            kpu.set_clipboard(url)
コード例 #32
0
 def on_execute(self, item, action):
     if item and item.category() == kp.ItemCategory.EXPRESSION:
         kpu.set_clipboard(item.target())