Exemple #1
0
def responsehandler(self, resp):
    global connection
    QObject.disconnect(connection)

    soup = BeautifulSoup(str(resp.readAll(), 'utf8'), 'lxml')

    answertypes = {
        'instant': ['div.Z0LcW', 'text'],
        'calc': ['span.qv3Wpe', 'text'],
        'multiple': ['div.bVj5Zb', 'text'],
        'translate': ['pre[id*="target-text"] span.Y2IQFc', 'text'],
        'conversion': ['input.vXQmIe[jsname=fPLMtf]', 'value'],
        'currency': ['span.DFlfde.SwHCTb', 'text'],
        'graph': ['div.ayqGOc.kno-fb-ctx.KBXm4e', 'text'],
        'stock': ['span.IsqQVc.NprOob.XcVN5d.wT3VGc', 'text'],
        'definition': ['div[data-dobid=dfn] span', 'text']
    }

    text = None
    for answertype in answertypes.values():
        result = soup.select(answertype[0])
        if len(result) > 0:
            result = result[0]
            if answertype[1] == 'text':
                text = result.text
            elif answertype[1] == 'value':
                text = result.attrs['value']
            else:
                text = "ANSWER NOT FOUND"
            break

    if text is None:
        self.commandfinished.emit("INVALID QUERY")
    else:
        self.commandfinished.emit(text)
Exemple #2
0
    def makeoutput(self, tocheck, output):

        if not isinstance(output, list):
            output = [output]
        readonlyendindex = self.getNearestNotReadOnly(tocheck, 1) - 1
        readonlyamt = readonlyendindex - tocheck
        if readonlyamt < len(output):
            self.newCell(index=tocheck,
                         command=True,
                         num=len(output) - readonlyamt)
        elif readonlyamt > len(output):
            self.remCell(index=tocheck,
                         command=True,
                         num=readonlyamt - len(output))

        self.layoutchildren[tocheck].numresults = len(output)

        for i in range(len(output)):  # TODO get rid of residual info
            self.layoutchildren[tocheck + i + 1].setText(str(output[i]))
        QObject.disconnect(self.layoutchildren[tocheck].connection)
        self.layoutchildren[tocheck].connection = None
        m1 = self.layoutchildren[tocheck].findHighlight(type="m1")
        if m1:
            m1.stoppulse()
Exemple #3
0
 def shutdown(self):
     QObject.disconnect(self, SIGNAL("activated(int)"), self.fn)
     self.setEnabled(False)
     self.fn = self.watcher = None
     self.deleteLater()
 def __disconnect(self):
     for c in self.connections:
         QObject.disconnect(c)
Exemple #5
0
 def disconnect_all(self):
     for connection in self.connections:
         try:
             QObject.disconnect(connection)
         except:
             pass  # Probably a PyQt5 bug. At least we tried...