Exemple #1
0
    def getResults(self, inputDataList, resultsList):
        if len(inputDataList) <= 1 or inputDataList[0].getText() != 'tr':
            return

        text = inputDataList[1].getText()
        print('TranslatorPy, getResults, input text:', text)
        if len(text) == 0:
            print('TranslatorPy, getResults, input text is empty')
            return

        # press tab to query
        if len(inputDataList) < 3:
            item = CatItem('press tab to translate', text, self.getID(),
                           self.getIcon())
            item.setUsage(50000)
            resultsList.append(item)
            return

        gt = YoudaoTranslator()
        print('TranslatorPy, getResults, translating ...')
        ret = gt.translate('auto', 'auto', text)
        if not ret:
            print('TranslatorPy, getResults, fail to translate')
            return

        print('TranslatorPy, getResults, ret:', ret)
        item = CatItem(text + ".translatorpy", ret['result'], self.getID(),
                       self.getIcon())
        item.setUsage(50000)
        resultsList.append(item)
Exemple #2
0
 def getResults(self, inputDataList, resultsList):
     # add items that shows in suggestion list
     if not inputDataList[-1].hasLabel(self.hash):
         return
     resultsList.append(
         CatItem("demopy.demopy", "demopy item", self.getID(),
                 self.getIcon()))
Exemple #3
0
    def getResults(self, inputDataList, resultsList):
        if len(inputDataList) > 1:
            return

        text = inputDataList[0].getText()
        text = self.__prepareExpression(text)
        if not Calculator.isValidExpression(text):
            return

        try:
            ret = Calculator.calc(text, advanced=True)
        except:
            return

        log.debug('CalcyPy::getResults, text = {}, result = {}'.format(
            text, ret))

        # full divide
        if isinstance(ret, float) and abs(ret - int(ret)) < 1e-15:
            ret = int(ret)
            log.debug(
                'CalcyPy::getResults, transform float to int: {}'.format(ret))

        if isinstance(ret, int):
            retInFloat = None
            # hexadecimal
            retInHex = self.__formatHexadecimal(ret)
            # decimal
            retInDec = self.__formatDecimal(ret)
            # octal
            retInOct = self.__formatOctal(ret)
            # binary
            retInBin = self.__formatBinary(ret)
            # size
            retInSize = self.__formatSize(ret)
        else:
            retInFloat = self.__formatFloat(ret)
            retInHex = None
            retInDec = None
            retInOct = None
            retInBin = None
            retInSize = None

        if retInFloat is not None:
            item = CatItem("float.calcypy", retInFloat, self.getName(),
                           self.getIcon())
            item.setUsage(50000)
            resultsList.append(item)

        if retInDec is not None:
            item = CatItem("dec.calcpy", retInDec, self.getName(),
                           self.getIcon())
            item.setUsage(50000)
            resultsList.append(item)

        if retInHex is not None:
            item = CatItem("hex.calcpy", retInHex, self.getName(),
                           self.getIcon())
            item.setUsage(40000)
            resultsList.append(item)

        if retInOct is not None:
            item = CatItem("oct.calcpy", retInOct, self.getName(),
                           self.getIcon())
            item.setUsage(30000)
            resultsList.append(item)

        if retInBin is not None:
            item = CatItem("bin.calcpy", retInBin, self.getName(),
                           self.getIcon())
            item.setUsage(20000)
            resultsList.append(item)

        if retInSize is not None:
            item = CatItem("size.calcpy", retInSize, self.getName(),
                           self.getIcon())
            item.setUsage(10000)
            resultsList.append(item)
Exemple #4
0
    def getResults(self, inputDataList, resultsList):
        if len(inputDataList) > 1:
            return

        text = inputDataList[0].getText()
        text = self.__prepareExpression(text)
        if not Calculator.isValidExpression(text):
            return

        try:
            ret = Calculator.calc(text, advanced=True)
        except:
            return

        print('CalcyPy, getResults,', text, ret)

        # full divide
        if isinstance(ret, float) and ret - int(ret) < 1e-15:
            ret = int(ret)

        if isinstance(ret, int):
            retInFloat = None

            # hexadecimal
            retInHex = self.__formatHexadecimal(ret)

            # decimal
            retInDec = self.__formatDecimal(ret)

            # octal
            retInOct = self.__formatOctal(ret)

            # binary
            retInBin = self.__formatBinary(ret)

            # size
            retInSize = self.__formatSize(ret)

        else:
            retInFloat = ("%%.%df" % self.settings['outputPrecision']) % ret
            retInHex = None
            retInDec = None
            retInOct = None
            retInBin = None
            retInSize = None

        if retInFloat is not None:
            item = CatItem("float.calcypy", retInFloat, self.getID(),
                           self.getIcon())
            item.setUsage(50000)
            resultsList.append(item)

        if retInDec is not None:
            item = CatItem("dec.calcpy", retInDec, self.getID(),
                           self.getIcon())
            item.setUsage(50000)
            resultsList.append(item)

        if retInHex is not None:
            item = CatItem("hex.calcpy", retInHex, self.getID(),
                           self.getIcon())
            item.setUsage(40000)
            resultsList.append(item)

        if retInOct is not None:
            item = CatItem("oct.calcpy", retInOct, self.getID(),
                           self.getIcon())
            item.setUsage(30000)
            resultsList.append(item)

        if retInBin is not None:
            item = CatItem("bin.calcpy", retInBin, self.getID(),
                           self.getIcon())
            item.setUsage(20000)
            resultsList.append(item)

        if retInSize is not None:
            item = CatItem("size.calcpy", retInSize, self.getID(),
                           self.getIcon())
            item.setUsage(10000)
            resultsList.append(item)
Exemple #5
0
    def getResults(self, inputDataList, resultsList):
        if len(inputDataList) > 1:
            return

        text = inputDataList[0].getText()
        if not Calculator.isValidExpression(text):
            return

        try:
            ret = Calculator.calc(text, advanced=True)
        except:
            ret = None

        if isinstance(ret, int):
            retInFloat = None

            # hex
            retInHex = '0x%x' % ret

            # dec
            retInDec = ret

            # octal
            retInOct = '0%o' % ret

            # bin
            retb = format(ret, '032b')
            retInBin = ""
            for i in range(len(retb)):
                retInBin += retb[i] if (i % 4 or i == 0) else ("," + retb[i])

            # size
            retInSize = ""

            size_giga_bytes = int(ret / (1024**3)) if int(ret /
                                                          (1024**3)) else 0
            ret -= size_giga_bytes * (1024**3)
            retInSize += "%s GB " % size_giga_bytes if size_giga_bytes else ""

            size_mega_bytes = int(ret /
                                  (1024 * 1024)) if int(ret /
                                                        (1024 * 1024)) else 0
            ret -= size_mega_bytes * (1024**2)
            retInSize += "%s MB " % size_mega_bytes if size_mega_bytes else ""

            size_kilo_bytes = int(ret / (1024)) if int(ret / (1024)) else 0
            ret -= size_mega_bytes * (1024**1)
            retInSize += "%s KB " % size_kilo_bytes if size_kilo_bytes else ""

            size_bytes = int(ret % (1024)) if int(ret % (1024)) else 0
            retInSize += "%s B " % size_bytes if size_bytes else ""

            if not retInSize:
                retInSize = "0 B"

        else:
            retInFloat = ret
            retInHex = None
            retInDec = None
            retInOct = None
            retInBin = None
            retInSize = None

        if retInFloat is not None:
            resultsList.append(
                CatItem("float.calcypy", "%s" % (retInFloat), self.getID(),
                        self.getIcon()))

        if retInDec is not None:
            resultsList.append(
                CatItem("dec.calcpy", str(retInDec), self.getID(),
                        self.getIcon()))

        if retInOct is not None:
            resultsList.append(
                CatItem("oct.calcpy", str(retInOct), self.getID(),
                        self.getIcon()))

        if retInHex is not None:
            resultsList.append(
                CatItem("hex.calcpy", str(retInHex), self.getID(),
                        self.getIcon()))

        if retInBin is not None:
            resultsList.append(
                CatItem("bin.calcpy", str(retInBin), self.getID(),
                        self.getIcon()))

        if retInSize is not None:
            resultsList.append(
                CatItem("size.calcpy", "%s" % (retInSize), self.getID(),
                        self.getIcon()))
Exemple #6
0
 def getCatalog(self, resultsList):
     resultsList.push_back(
         CatItem("translatorpy", "tr", self.getID(), self.getIcon()))