Beispiel #1
0
 def getResults(self, inputDataList, resultsList):
     # Take the text from the first input item and add a new
     # Catalog item with our plugin id
     text = inputDataList[0].getText()  ### 4
     resultsList.push_back(
         launchy.CatItem(text, "PySimple: " + text, self.getID(),
                         self.getIcon()))  ### 5
Beispiel #2
0
    def getResults(self, inputDataList, resultsList):
        inputs = len(inputDataList)

        if inputs != 2:
            return

        firstText = inputDataList[0].getText()
        if not self.dirs.has_key(firstText):
            return

        path = self.dirs[firstText]
        query = inputDataList[1].getText()

        if query == '':
            # Default query is '*'
            query = '*'
        elif not query.startswith('*') and not query.endswith('*'):
            # Add * at both sides to ease searching
            query = '*%s*' % query

        pathContents = glob.glob(os.path.join(path, query))
        pathContents.sort()

        for itemPath in pathContents:
            resultsList.append( launchy.CatItem(itemPath,
                                                self.__makeShortName(itemPath),
                                                self.getID(),
                                                itemPath ) )
Beispiel #3
0
 def getResults(self, inputDataList, resultsList):
     text = inputDataList[0].getText()
     if self.PLUGIN_KEYWORD == text[:4]:
         cmd = text[4:]
         cmdText = self.CMD_MAPPING[
             cmd] if cmd in self.CMD_MAPPING else '???'
         resultsList.push_back(
             launchy.CatItem(text, 'foobar2000: ' + cmdText, self.getID(),
                             self.getIcon()))
Beispiel #4
0
 def getResults(self, inputDataList, resultsList):
     if not inputDataList[-1].hasLabel(self.hash):
         return
     query = inputDataList[0].getText()
     keyword = inputDataList[-1].getText()
     if query in self.searchEngine.keys():
         resultsList.push_front(
             launchy.CatItem(
                 "%s: %s search" %
                 (self.getName(), self.searchEngine.get(query).get("name")),
                 keyword, self.getID(), self.getIcon()))
Beispiel #5
0
	def getResults(self, inputDataList, resultsList):
		if len(inputDataList) > 1:
			return
			
		text = inputDataList[0].getText()
		if not Calculator.isValidExpression(text):
			return
		
		try:
			result = Calculator.calc(text, advanced=True)
		except:
			pass
		else:
			resultsList.append( launchy.CatItem(str(result), str(result), self.getID(), self.getIcon() ))
Beispiel #6
0
    def getResults(self, inputDataList, resultsList):
        if len(inputDataList) != 2:
            return

        if not inputDataList[0].hasLabel(self.labelHash):
            return

        windowNameToMatch = inputDataList[1].getText().lower()
        if windowNameToMatch == "":
            return

        self.topLevelWindows = self._getTopLevelWindows()
        for window in self.topLevelWindows:
            if window[1].lower().find(windowNameToMatch) > -1:
                resultsList.append(
                    launchy.CatItem(window[1] + ".go", window[1], self.getID(),
                                    self.getIcon()))
Beispiel #7
0
    def getResults(self, inputDataList, resultsList):
        try:
            if len(inputDataList) > 1:
                return
            text = inputDataList[0].getText()
            if len(text) == 0:
                return

            self.__cacheFilesFromOpenDirs()

            for fileEntry in self.fileCache:
                if fileEntry[0].startswith(text):
                    filePath = path.join(fileEntry[1], fileEntry[0])
                    resultsList.append(
                        launchy.CatItem(filePath, fileEntry[0], self.hash,
                                        filePath))
        except Exception, inst:
            print inst
Beispiel #8
0
    def getResults(self, inputDataList, resultsList):
        if len(inputDataList) != 2:
            return

        catItem = inputDataList[0].getTopResult()
        if catItem.id != self.getID():
            return

        # Get the master page that corresponds to catItem.shortName
        (masterPageId, name, url) = self.db.getMasterPage(catItem.shortName)

        # Get it's subpages
        subPages = self.db.getSubPages(masterPageId,
                                       inputDataList[1].getText())

        # Add the pages to catalog
        for page in subPages:
            pageId, pageName, pageUrl = page
            resultsList.push_back(
                launchy.CatItem(str(pageId), pageName, self.getID(),
                                self.getIcon()))
Beispiel #9
0
    def getResults(self, inputDataList, resultsList):
        if len(inputDataList) < 1:
            return

        text = inputDataList[0].getText()
        isVerbyQuery = (text[-4:-1] == "   ")
        print "%s##%s##%s" % (text, text[-4:-1], isVerbyQuery)
        if not isVerbyQuery:
            return

        text = text[:-4]
        isFileOrDir = os.path.isdir(text) or os.path.isfile(text)
        print "%s##%s" % (text, isFileOrDir)
        if not isFileOrDir:
            return

        runmenuApp = 'C:\\Program Files\\Launchy\\plugins\\python\\runmenu\\runmenu.exe'
        runmenu = Popen([runmenuApp, "/list", text],
                        stdout=PIPE,
                        startupinfo=self.__startupinfo)
        output = runmenu.stdout.read()

        splitted = output.split("\r\n")
        for command in splitted:
            if command == "":
                continue

            verbIdx = command.rfind("(Verb:")
            if verbIdx > -1:
                commandToExec = command[:verbIdx]
            else:
                commandToExec = command

            resultsList.append(
                launchy.CatItem(text, commandToExec, self.getID(),
                                self.getIcon()))
Beispiel #10
0
 def getCatalog(self, resultsList):
     resultsList.push_back(
         launchy.CatItem("Go.go-y", "Go", self.getID(), self.getIcon()))
     resultsList.push_back(
         launchy.CatItem("Focus.go-y", "Focus", self.getID(),
                         self.getIcon()))
Beispiel #11
0
 def getCatalog(self, resultsList):
     for name,path in self.dirs.items():
         resultsList.push_back( launchy.CatItem( name + ".pydiry",
                                                 name,
                                                 self.getID(),
                                                 self.getIcon() ) )
Beispiel #12
0
    def getResults(self, inputDataList, resultsList):
        # Take the text from the first input item and add a new
        # Catalog item with our plugin id

        # print len(inputDataList)
        inputData = inputDataList[0]

        first_result = True

        all_text = inputData.getText()

        all_text_parts = all_text.split(" ")

        if DO_TIMING:
            start_time = time.time()

        # print inputDataList

        for table_entry in self.config["tables"]:
            # go through the tables to use from this sqlite database according to the config
            table_name = table_entry["name"]
            display_name_field = table_entry.get("display_name_field")
            search_fields = table_entry["search_fields"]

            # 1. build the list of fields we want for this table
            output_fields = []

            # the fields definitions for this table from our config file
            field_defs = table_entry["fields"]

            for field_name, field_def in field_defs.iteritems():
                if self.has_valid_action(field_def):
                    output_fields.append(field_name)
                else:
                    print "field %s has no valid action; skipping" % field_name

            icon_url_field = table_entry.get("icon_url_field")
            if icon_url_field and icon_url_field not in output_fields:
                output_fields.append(icon_url_field)
            if display_name_field and display_name_field not in output_fields:
                output_fields.append(display_name_field)

            # What we want
            # - the rows where all the words are in any of the fields
            # - for any combination of the words that are in an action, the rows where all the other words are in any of the fields
            #   (we will show just certain actions for these)
            #
            # For a simple first cut of this, let's just narrow the actions to any word that is part of an action
            # rather than doing the full union.

            # 2. figure out what action names the search terms match and what other actions to exclude

            action_names = []
            action_entries = []

            for output_column_name in output_fields:
                field_defs_entry = self.field_defs_entry_proper(
                    field_defs.get(output_column_name))
                if field_defs_entry is None:
                    continue
                for field_def_num, field_def in enumerate(field_defs_entry):
                    action_name = self.get_action_name(field_def,
                                                       output_column_name)
                    action_names.append(action_name)
                    action_entries.append(
                        (output_column_name, field_def_num, action_name))

            exclude_output_fields = set()

            text_parts = []
            for text_part in all_text_parts:
                if any(
                        self.action_name_match(text_part, action_name)
                        for action_name in action_names):
                    # text is in any action name; treat as a search for those specific actions

                    # we only want actions that have all of these action words
                    for output_field, field_def_num, action_name in action_entries:
                        if action_name is None:
                            continue
                        if not self.action_name_match(text_part, action_name):
                            key = (output_field, field_def_num)
                            if key not in exclude_output_fields:
                                exclude_output_fields.add(key)
                else:
                    # text is not in any action name; treat as ordinary search text
                    text_parts.append(text_part)

            if DEBUG_OUTPUT:
                print ""
                print "QUERY %r" % all_text_parts
                print "exclude output fields %r" % exclude_output_fields
                print "text parts %r" % text_parts

            # 3. build database query to do for this table to match on those fields

            output_clause = ", ".join(sqlite_escape(x) for x in output_fields)
            if len(text_parts) == 0:
                search_clause = "1"
            else:
                search_clause = " OR ".join("%s LIKE ?" % sqlite_escape(x)
                                            for x in search_fields)
                search_clause = " AND ".join(["(" + search_clause + ")"] *
                                             len(text_parts))

            query = "SELECT %s FROM %s WHERE %s" % (
                output_clause, sqlite_escape(table_name), search_clause)

            args = []
            for text_part in text_parts:
                args += ["%" + text_part.replace("%", "%%") + "%"
                         ] * len(search_fields)

            if DEBUG_OUTPUT:
                print query

            # print "running query: " + query
            # print "with args: " + repr(args)

            # 4. Use the database query results to create the action items, respecting the action filters

            c = self.conn.cursor()
            assert isinstance(c, sqlite3.Cursor)
            try:
                try:
                    c.execute(query, args)
                except sqlite3.OperationalError:
                    print "failing query was %r args %r" % (query, args)
                    raise
                result_rows = c.fetchall()
                if DEBUG_OUTPUT:
                    print "got %d rows" % len(result_rows)
                for result_row in result_rows:

                    column_pairs = zip(output_fields, result_row)
                    column_dict = dict(column_pairs)

                    icon = self.getIcon()
                    # noinspection PyBroadException
                    try:
                        if icon_url_field:
                            icon_url = column_dict[icon_url_field]
                            if icon_url:
                                assert isinstance(icon_url, basestring)
                                icon_filename = os.path.join(
                                    launchy.getIconsPath(),
                                    url_hash(icon_url) + ".png")
                                if not os.path.exists(icon_filename):
                                    self.download(icon_url, icon_filename)
                                icon = icon_filename
                    except Exception:
                        print "error getting icon"
                        traceback.print_exc()
                    # print "icon is " + icon

                    for output_column_name, output_value in column_pairs:
                        if not output_value:
                            continue

                        field_defs_entry = self.field_defs_entry_proper(
                            field_defs.get(output_column_name))
                        if field_defs_entry is None:
                            continue

                        for field_def_number, field_def in enumerate(
                                field_defs_entry):
                            if (output_column_name,
                                    field_def_number) in exclude_output_fields:
                                continue

                            if not self.has_valid_action(field_def):
                                continue

                            action_name = self.get_action_name(
                                field_def, output_column_name)

                            action = {
                                "table": table_name,
                                "field": output_column_name,
                                "value": output_value,
                                "field_def_number": field_def_number
                            }
                            action_json = json.dumps(action)

                            if display_name_field and column_dict[
                                    display_name_field]:
                                entry_display_text = "%s: %s (%s)" % (
                                    column_dict[display_name_field],
                                    action_name, output_value)
                            else:
                                entry_display_text = "%s: %s" % (output_value,
                                                                 action_name)

                            if DEBUG_OUTPUT:
                                print "ENTRY: " + entry_display_text

                            cat_item = launchy.CatItem(PRE_TAG + action_json,
                                                       entry_display_text,
                                                       self.getID(), icon)

                            resultsList.push_back(cat_item)
                            if first_result:
                                first_result = False
                                inputData.setTopResult(cat_item)

            finally:
                c.close()

        if DO_TIMING:
            end_time = time.time()

            # noinspection PyUnboundLocalVariable
            print "elapsed time %0.0f ms" % ((end_time - start_time) * 1000)
Beispiel #13
0
 def getResults(self, inputDataList, resultsList):
     text = inputDataList[0].getText()
     resultsList.append(
         launchy.CatItem(text, "From python: " + text, self.hash,
                         self.icon))
Beispiel #14
0
 def getCatalog(self, resultsList):
     for masterPage in self.masterPages:
         resultsList.push_back(
             launchy.CatItem(masterPage[1] + ".webindex", masterPage[1],
                             self.getID(), self.getIcon()))
 def getResults(self, inputDataList, resultsList):
     text = inputDataList[0].getText()
     resultsList.push_back(
         launchy.CatItem(text, "Play Song: " + text, self.getID(),
                         self.getIcon()))
Beispiel #16
0
 def getCatItem(self, fullPath, shortName):
     return launchy.CatItem(fullPath, shortName, self.getAddonId(),
                            self.getAddonIcon())
Beispiel #17
0
 def getCatalog(self, resultsList):
     resultsList.push_back(
         launchy.CatItem("translatorpy", "tr", self.getID(),
                         self.getIcon()))