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)
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())
def on_execute(self, item, action): if item.category() != kp.ItemCategory.REFERENCE: return try: item_target = kpu.kwargs_decode(item.target()) site_name = item_target['site'] except Exception as exc: self.dbg(str(exc)) return if site_name not in self.sites: self.warn( 'Could not execute item "{}". Site "{}" not found.'.format( item.label(), site_name)) return site = self.sites[site_name] if len(item.raw_args()) > 0: for url in site['urls']: final_url = self._url_build(url, item.raw_args(), site['quoting']) kpu.web_browser_command(private_mode=site['incognito'], new_window=site['new_window'], url=final_url, execute=True) else: for home_url in site['home_urls']: kpu.web_browser_command(private_mode=site['incognito'], new_window=site['new_window'], url=home_url, execute=True)
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
def _open_browser(self, item, private_mode, new_window): kpu.web_browser_command(private_mode=private_mode, new_window=new_window, url=item.target(), execute=True) self._create_history(item)
def on_execute(self, item, action): if action: kpu.execute_default_action(self, item, action) else: kpu.web_browser_command(private_mode=self.force_private_mode, new_window=self.force_new_window, url=item.target(), execute=True)
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
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)
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)
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)
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 )
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)
def on_execute(self, item, action): target = item.target() p = "" if target == self.CMD_GH: return elif self.CMD_PREFIX["repos_action"] in target: p = target.replace(self.CMD_PREFIX["repos_action"], "") print(p) elif self.CMD_PREFIX["my_account_action"] in target: p = target.replace(self.CMD_PREFIX["my_account_action"], "") if "https://" in p: url = p else: url = f"https://github.com{p}" kpu.web_browser_command(url=url, execute=True)
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())
def _setup_default_icon(self): if self.default_icon_handle: self.default_icon_handle.free() self.default_icon_handle = None args = kpu.web_browser_command() if args and os.path.isfile(args[0]): self.default_icon_handle = self.load_icon("@{},0".format(args[0])) if self.default_icon_handle: self.set_default_icon(self.default_icon_handle)
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)
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)
def _load_icons(self): if self.default_icon: self.default_icon.free() self.default_icon = None for icon in self.icons.values(): icon.free() self.icons = {} # default icon args = kpu.web_browser_command() if args and os.path.isfile(args[0]): self.default_icon = self.load_icon("@{},0".format(args[0])) if self.default_icon: self.set_default_icon(self.default_icon) # find embedded icon resources and group them by network domain name resources = self.find_resources("*") resources_by_domain = {} for file in resources: if not file.lower().startswith("icons/"): continue file_title, file_ext = os.path.splitext(file) if file_ext.lower() not in (".ico", ".png", ".jpg", ".jpeg"): continue netdomain = os.path.basename(file_title).lower() try: resources_by_domain[netdomain].append(file) except KeyError: resources_by_domain[netdomain] = [file] # load embedded icons package_name = self.package_full_name() for netdomain, files in resources_by_domain.items(): resources = ["res://{}/{}".format(package_name, f) for f in files] try: icon = self.load_icon(resources) except: self.warn("Failed to load icon from:", ", ".join(resources)) traceback.print_exc() continue self.icons[netdomain] = icon
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)
def openBrowser(self, item): url = urljoin(self.DOMAIN, item.short_desc() + "/" + item.target()) self.dbg("open", url) kpu.web_browser_command(private_mode=None, url=url, execute=True)
def _open_browser(self, target, private_mode, new_window): kpu.web_browser_command(private_mode=private_mode, new_window=new_window, url=target, execute=True)
def on_execute(self, item, action): if item.category() != self.ITEMCAT: return url=item.target() self.dbg(item.target()) kpu.web_browser_command(private_mode=None,url=url,execute=True)