def setValueText(self, nSatoshi, ndec=None, maxZeros=None, wColor=None, wBold=None): """ When we set the text of the QMoneyLabel, remember previous values unless explicitly respecified """ if not ndec==None: self.ndec = ndec if not maxZeros==None: self.max0 = maxZeros if not wColor==None: self.colr = wColor if not wBold==None: self.bold = wBold theFont = GETFONT("Fixed", 10) if self.bold: theFont.setWeight(QFont.Bold) self.setFont(theFont) self.setWordWrap(False) valStr = coin2str(nSatoshi, ndec=self.ndec, maxZeros=self.max0) goodMoney = htmlColor('MoneyPos') badMoney = htmlColor('MoneyNeg') if nSatoshi < 0 and self.colr: self.setText('<font color=%s>%s</font>' % (badMoney, valStr)) elif nSatoshi > 0 and self.colr: self.setText('<font color=%s>%s</font>' % (goodMoney, valStr)) else: self.setText('%s' % valStr) self.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
def checkUpdatePrice(self): urlBase = "http://coinbase.com/api/v1/prices/" urlSell = urlBase + "sell" urlBuy = urlBase + "buy" try: self.lastSellStr = self.fetchFormattedPrice(urlSell) self.lastBuyStr = self.fetchFormattedPrice(urlBuy) self.lblSellPrice.setText( '<b><font color="%s">$%s</font> / BTC</b>' % (htmlColor("TextBlue"), self.lastSellStr) ) self.lblBuyPrice.setText( '<b><font color="%s">$%s</font> / BTC</b>' % (htmlColor("TextBlue"), self.lastBuyStr) ) self.lastPriceFetch = RightNow() self.updateLastTimeStr() self.updateWalletTable() self.updateCalcUSD(self.edtEnterBTC.text()) except: # LOGEXCEPT('Failed to fetch price data from %s' % urlBase) pass
def setValueText(self, nSatoshi, ndec=None, maxZeros=None, wColor=None, wBold=None, txtSize=10): """ When we set the text of the QMoneyLabel, remember previous values unless explicitly respecified """ if not ndec is None: self.ndec = ndec if not maxZeros is None: self.max0 = maxZeros if not wColor is None: self.colr = wColor if not wBold is None: self.bold = wBold theFont = GETFONT("Fixed", txtSize) if self.bold: theFont.setWeight(QFont.Bold) self.setFont(theFont) self.setWordWrap(False) valStr = coin2str(nSatoshi, ndec=self.ndec, maxZeros=self.max0) goodMoney = htmlColor('MoneyPos') badMoney = htmlColor('MoneyNeg') if nSatoshi < 0 and self.colr: self.setText('<font color=%s>%s</font>' % (badMoney, valStr)) elif nSatoshi > 0 and self.colr: self.setText('<font color=%s>%s</font>' % (goodMoney, valStr)) else: self.setText('%s' % valStr) self.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
def displayVerifiedBox(self, addrB58, messageString): atihash160 = hash160(hex_to_binary(ANNOUNCE_SIGN_PUBKEY)) addrDisp = addrB58 if addrB58 == hash160_to_addrStr(atihash160): addrDisp = '<b>Armory Technologies, Inc.</b>' if CLI_OPTIONS.testAnnounceCode: ownerStr = tr(""" <font color="%s"><b>Armory Technologies, Inc. (testing key)</b></font> has signed the following block of text:<br>""") % htmlColor('TextGreen') else: ownerStr = tr(""" <font color="%s"><b>Armory Technologies, Inc.</b></font> has signed the following block of text:<br>""") % \ htmlColor('TextGreen') else: ownerStr = tr(""" The owner of the following Groestlcoin address... <br> <blockquote> <font face="Courier" size=4 color="#000060"><b>%s</b></font> </blockquote> <br> ... has produced a <b><u>valid</u></b> signature for the following message:<br> """) % addrB58 if addrB58: msg = messageString.replace('\r\n', '\n') msg = ' ' + '<br> '.join(msg.split('\n')) # The user will be able to see the entire message # in the Message Signing/Verification dialog msg = '<br>'.join([ line[:60] + '...' * (len(line) > 60) for line in msg.split('<br>') ][:12]) MsgBoxCustom( MSGBOX.Good, tr('Verified!'), tr(""" %s <hr> <blockquote> <font face="Courier" color="#000060"><b>%s</b></font> </blockquote> <hr><br> <b>Please</b> make sure that the address above (%s...) matches the exact address you were expecting. A valid signature is meaningless unless it is made from a recognized address!""") % (ownerStr, msg, addrB58[:10])) self.lblSigResult.setText(\ '<font color="green">Valid Signature by %s</font>' % addrDisp) else: self.displayInvalidSignatureMessage()
def displayVerifiedBox(self, addrB58, messageString): atihash160 = hash160(hex_to_binary(ANNOUNCE_SIGN_PUBKEY)) addrDisp = addrB58 if addrB58==hash160_to_addrStr(atihash160): addrDisp = '<b>Armory Technologies, Inc.</b>' if CLI_OPTIONS.testAnnounceCode: ownerStr = tr(""" <font color="%s"><b>Armory Technologies, Inc. (testing key)</b></font> has signed the following block of text:<br>""") % htmlColor('TextGreen') else: ownerStr = tr(""" <font color="%s"><b>Armory Technologies, Inc.</b></font> has signed the following block of text:<br>""") % \ htmlColor('TextGreen') else: ownerStr = tr(""" The owner of the following Bitcoin address... <br> <blockquote> <font face="Courier" size=4 color="#000060"><b>%s</b></font> </blockquote> <br> ... has produced a <b><u>valid</u></b> signature for the following message:<br> """) % addrB58 if addrB58: msg = messageString.replace('\r\n','\n') msg = ' ' + '<br> '.join(msg.split('\n')) # The user will be able to see the entire message # in the Message Signing/Verification dialog msg = '<br>'.join([line[:60]+ '...'*(len(line)>60) for line in msg.split('<br>')][:12]) MsgBoxCustom(MSGBOX.Good, tr('Verified!'), tr(""" %s <hr> <blockquote> <font face="Courier" color="#000060"><b>%s</b></font> </blockquote> <hr><br> <b>Please</b> make sure that the address above (%s...) matches the exact address you were expecting. A valid signature is meaningless unless it is made from a recognized address!""") % (ownerStr, msg, addrB58[:10])) self.lblSigResult.setText(\ '<font color="green">Valid Signature by %s</font>' % addrDisp) else: self.displayInvalidSignatureMessage()
def updateLastTimeStr(self): secs = RightNow() - self.lastPriceFetch tstr = 'Less than 1 min' if secs > 60: tstr = secondsToHumanTime(secs) self.lblLastTime.setText(tr("""<font color="%s">Last updated: %s ago</font>""") % (htmlColor('DisableFG'), tstr))
def __init__(self, nBtc, ndec=8, maxZeros=2, wColor=True, wBold=False): QLabel.__init__(self, coin2str(nBtc)) theFont = GETFONT("Fixed", 10) if wBold: theFont.setWeight(QFont.Bold) self.setFont(theFont) self.setWordWrap(False) valStr = coin2str(nBtc, ndec=ndec, maxZeros=maxZeros) goodMoney = htmlColor('MoneyPos') badMoney = htmlColor('MoneyNeg') if nBtc < 0 and wColor: self.setText('<font color=%s>%s</font>' % (badMoney, valStr)) elif nBtc > 0 and wColor: self.setText('<font color=%s>%s</font>' % (goodMoney, valStr)) else: self.setText('%s' % valStr) self.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
def createToolTipObject(tiptext, iconSz=2): """ The <u></u> is to signal to Qt that it should be interpretted as HTML/Rich text even if no HTML tags are used. This appears to be necessary for Qt to wrap the tooltip text """ fgColor = htmlColor('ToolTipQ') lbl = QLabel('<font size=%d color=%s>(?)</font>' % (iconSz, fgColor)) lbl.setToolTip('<u></u>' + tiptext) lbl.setMaximumWidth(relaxedSizeStr(lbl, '(?)')[0]) lbl.connect(lbl, SIGNAL('clicked()'), lambda: printlbl) return lbl
def setText(self, text, color=None, size=None, bold=None, italic=None): if color: text = '<font color="%s">%s</font>' % (htmlColor(color), text) if size: if isinstance(size, int): text = '<font size=%d>%s</font>' % (size, text) else: text = '<font size="%s">%s</font>' % (size, text) if bold: text = '<b>%s</b>' % text if italic: text = '<i>%s</i>' % text QLabel.setText(self,text)
def setText(self, text, color=None, size=None, bold=None, italic=None): if color: text = '<font color="%s">%s</font>' % (htmlColor(color), text) if size: if isinstance(size, int): text = '<font size=%d>%s</font>' % (size, text) else: text = '<font size="%s">%s</font>' % (size, text) if bold: text = '<b>%s</b>' % text if italic: text = '<i>%s</i>' % text QLabel.setText(self, text)
def checkUpdatePrice(self): urlBase = 'http://coinbase.com/api/v1/prices/' urlSell = urlBase + 'sell' urlBuy = urlBase + 'buy' try: self.lastSellStr = self.fetchFormattedPrice(urlSell) self.lastBuyStr = self.fetchFormattedPrice(urlBuy) self.lblSellPrice.setText('<b><font color="%s">$%s</font> / BTC</b>' % \ (htmlColor('TextBlue'), self.lastSellStr)) self.lblBuyPrice.setText( '<b><font color="%s">$%s</font> / BTC</b>' % \ (htmlColor('TextBlue'), self.lastBuyStr)) self.lastPriceFetch = RightNow() self.updateLastTimeStr() self.updateWalletTable() self.updateCalcUSD(self.edtEnterBTC.text()) except: #LOGEXCEPT('Failed to fetch price data from %s' % urlBase) pass
def __init__(self, txt): colorStr = htmlColor('LBtnNormalFG') QLabel.__init__(self, '<font color=%s>%s</u></font>' % (colorStr, txt)) self.plainText = txt self.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
def setText(self, txt): colorStr = htmlColor('LBtnNormalFG') QLabel.__init__(self, '<font color=%s>%s</u></font>' % (colorStr, txt))
def createToolTipObject(tiptext, iconSz=2): fgColor = htmlColor('ToolTipQ') lbl = QLabel('<font size=%d color=%s>(?)</font>' % (iconSz, fgColor)) lbl.setToolTip('<u></u>' + tiptext) lbl.setMaximumWidth(relaxedSizeStr(lbl, '(?)')[0]) return lbl
def load(self): self.fileData = None #self.fromfile = QFileDialog.getOpenFileName(self, tr("Load file to verify"), "", tr("Armory Signed Packages (*.signed)")) self.fromfile = self.main.getFileLoad(tr('Load file to Verify'),\ ['Armory Signed Packages (*.signed)']) if len(self.fromfile)==0: return df = open(self.fromfile, "rb") allfile = df.read() df.close() magicstart="START_OF_SIGNATURE_SECTION" magicend="END_OF_SIGNATURE_SECTION" if 0 != allfile.find(magicstart, 0, 1024*1024*4): # don't search past 4MiB QMessageBox.warning(self, tr("Invalid File"), tr("This file is not a signed package")) return end = allfile.find(magicend, 0, 1024*1024*4) # don't search past 4MiB if -1 == end: # don't search past 4MiB QMessageBox.warning(self, tr("Invalid File"), tr("The end of the signature in the file could not be found")) signatureData = allfile[len(magicstart):end] fileData = allfile[end+len(magicend):] print "All:",end, end+len(magicend), len(fileData), len(allfile) allsigs = downloadLinkParser(filetext=signatureData).downloadMap res = binary_to_hex(sha256(fileData)) good=False url=None print "Hash of package file: ", res # simply check if any of the hashes match for pack in allsigs.itervalues(): for packver in pack.itervalues(): for packos in packver.itervalues(): for packosver in packos.itervalues(): for packosarch in packosver.itervalues(): okhash = packosarch[1] if okhash == res: url = packosarch[0] good=True if good: self.saveFileButton.setEnabled(True) self.fileData = fileData self.fileName = os.path.basename(url) self.lblVerified.setText(tr("""<font color="%s"><b>Signature is Valid!</b></font>""") % htmlColor('TextGreen')) reply = QMessageBox.warning(self, tr("Signature Valid"), tr(""" The downloaded file has a <b>valid</b> signature from <font color="%s"><b>Armory Technologies, Inc.</b></font>, and is safe to install. <br><br> Would you like to overwrite the original file with the extracted installer? If you would like to save it to a new location, click "No" and then use the "Save Verified Package" button to select a new save location.""") % htmlColor('TextGreen'), \ QMessageBox.Yes | QMessageBox.No) if reply==QMessageBox.Yes: newFile = self.fromfile if newFile.endswith('.signed'): newFile = self.fromfile[:-7] LOGINFO('Saving installer to: ' + newFile) with open(newFile, 'wb') as df: df.write(self.fileData) if os.path.exists(newFile): LOGINFO('Removing original file: ' + self.fromfile) os.remove(self.fromfile) QMessageBox.warning(self, tr('Saved!'), tr(""" The installer was successfully extracted and saved to the following location: <br><br> %s""") % newFile, QMessageBox.Ok) else: self.saveFileButton.setEnabled(False) self.lblVerified.setText(tr("""<font color="%s">Invalid signature on loaded file!</font>""") % htmlColor('TextRed')) QMessageBox.warning(self, tr("Signature failure"), \ tr("This file has an invalid signature"))
def leaveEvent(self, ev): ssStr = "QLabel { background-color : %s }" % htmlColor('LBtnNormalBG') self.setStyleSheet(ssStr)
def enterEvent(self, ev): ssStr = "QLabel { background-color : %s }" % htmlColor('LBtnHoverBG') self.setStyleSheet(ssStr)
def load(self): self.fileData = None #self.fromfile = QFileDialog.getOpenFileName(self, tr("Load file to verify"), "", tr("Armory Signed Packages (*.signed)")) self.fromfile = self.main.getFileLoad(tr('Load file to Verify'),\ ['Armory Signed Packages (*.signed)']) if len(self.fromfile) == 0: return df = open(self.fromfile, "rb") allfile = df.read() df.close() magicstart = "START_OF_SIGNATURE_SECTION" magicend = "END_OF_SIGNATURE_SECTION" if 0 != allfile.find(magicstart, 0, 1024 * 1024 * 4): # don't search past 4MiB QMessageBox.warning(self, tr("Invalid File"), tr("This file is not a signed package")) return end = allfile.find(magicend, 0, 1024 * 1024 * 4) # don't search past 4MiB if -1 == end: # don't search past 4MiB QMessageBox.warning( self, tr("Invalid File"), tr("The end of the signature in the file could not be found")) signatureData = allfile[len(magicstart):end] fileData = allfile[end + len(magicend):] print "All:", end, end + len(magicend), len(fileData), len(allfile) allsigs = downloadLinkParser(filetext=signatureData).downloadMap res = binary_to_hex(sha256(fileData)) good = False url = None print "Hash of package file: ", res # simply check if any of the hashes match for pack in allsigs.itervalues(): for packver in pack.itervalues(): for packos in packver.itervalues(): for packosver in packos.itervalues(): for packosarch in packosver.itervalues(): okhash = packosarch[1] if okhash == res: url = packosarch[0] good = True if good: self.saveFileButton.setEnabled(True) self.fileData = fileData self.fileName = os.path.basename(url) self.lblVerified.setText( tr("""<font color="%s"><b>Signature is Valid!</b></font>""") % htmlColor('TextGreen')) reply = QMessageBox.warning(self, tr("Signature Valid"), tr(""" The downloaded file has a <b>valid</b> signature from <font color="%s"><b>Armory Technologies, Inc.</b></font>, and is safe to install. <br><br> Would you like to overwrite the original file with the extracted installer? If you would like to save it to a new location, click "No" and then use the "Save Verified Package" button to select a new save location.""") % htmlColor('TextGreen'), \ QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: newFile = self.fromfile if newFile.endswith('.signed'): newFile = self.fromfile[:-7] LOGINFO('Saving installer to: ' + newFile) with open(newFile, 'wb') as df: df.write(self.fileData) if os.path.exists(newFile): LOGINFO('Removing original file: ' + self.fromfile) os.remove(self.fromfile) QMessageBox.warning( self, tr('Saved!'), tr(""" The installer was successfully extracted and saved to the following location: <br><br> %s""") % newFile, QMessageBox.Ok) else: self.saveFileButton.setEnabled(False) self.lblVerified.setText( tr("""<font color="%s">Invalid signature on loaded file!</font>""") % htmlColor('TextRed')) QMessageBox.warning(self, tr("Signature failure"), \ tr("This file has an invalid signature"))