electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 39d765f122919377338ad11b4d9d551e852554f4
parent 64de7e55cc63e2c3300f4a23f8b91eaad70c80cc
Author: Amir Taaki <genjix@riseup.net>
Date:   Wed, 27 Jun 2012 23:06:00 +0200

show btc balance (no fiat balance yet)

Diffstat:
Melectrum | 2+-
Mlib/gui_lite.py | 92++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 85 insertions(+), 9 deletions(-)

diff --git a/electrum b/electrum @@ -140,7 +140,7 @@ if __name__ == '__main__': try: import lib.gui_lite as gui except ImportError: - import electrum.gui_life as gui + import electrum.gui_lite as gui else: print "unknown gui", options.gui exit(1) diff --git a/lib/gui_lite.py b/lib/gui_lite.py @@ -10,14 +10,20 @@ def IconButton(filename, parent=None): return QPushButton(icon, "", parent) class ElectrumGui: + def __init__(self, wallet): self.wallet = wallet + self.app = QApplication(sys.argv) + with open("data/style.css") as style_file: + self.app.setStyleSheet(style_file.read()) def main(self, url): - print url - # Do nothing. + mini = MiniWindow() + driver = MiniDriver(self.wallet, mini) + sys.exit(self.app.exec_()) class MiniWindow(QDialog): + def __init__(self): super(MiniWindow, self).__init__() @@ -45,8 +51,9 @@ class MiniWindow(QDialog): expand_button = IconButton("data/icons/expand.png") expand_button.setObjectName("expand_button") - balance_label = BalanceLabel("80.00", "60.00", "EUR") - balance_label.setObjectName("balance_label") + self.balance_label = BalanceLabel() + self.balance_label.set_balances("80.00", "60.00", "EUR") + self.balance_label.setObjectName("balance_label") copy_button = QPushButton(_("&Copy Address")) copy_button.setObjectName("copy_button") @@ -79,7 +86,7 @@ class MiniWindow(QDialog): main_layout.addWidget(interact_button, 1, 0) main_layout.addWidget(expand_button, 2, 0) - main_layout.addWidget(balance_label, 0, 1) + main_layout.addWidget(self.balance_label, 0, 1) main_layout.addWidget(copy_button, 0, 2) main_layout.addLayout(address_layout, 1, 1, 1, -1) @@ -97,13 +104,27 @@ class MiniWindow(QDialog): super(MiniWindow, self).closeEvent(event) qApp.quit() + def activate(self): + pass + + def deactivate(self): + pass + + def set_balances(self, btc_balance, quote_balance, quote_currency): + self.balance_label.set_balances( \ + btc_balance, quote_balance, quote_currency) + class BalanceLabel(QLabel): - def __init__(self, btc_balance, - quote_balance, quote_currency, parent=None): + + def __init__(self, parent=None): + super(QLabel, self).__init__("Connecting...", parent) + + def set_balances(self, btc_balance, quote_balance, quote_currency): label_text = "<span style='font-size: 16pt'>%s</span> <span style='font-size: 10pt'>BTC</span> <span style='font-size: 10pt'>(%s %s)</span>"%(btc_balance, quote_balance, quote_currency) - super(QLabel, self).__init__(label_text, parent) + self.setText(label_text) class TextedLineEdit(QLineEdit): + def __init__(self, inactive_text, parent=None): super(QLineEdit, self).__init__(parent) self.inactive_text = inactive_text @@ -135,6 +156,61 @@ class TextedLineEdit(QLineEdit): # also possible but more expensive: #qApp.setStyleSheet(qApp.styleSheet()) +class MiniDriver: + + INITIALIZING = 0 + CONNECTING = 1 + SYNCHRONIZING = 2 + READY = 3 + + def __init__(self, wallet, window): + self.wallet = wallet + self.window = window + + self.wallet.gui_callback = self.update + + self.state = None + self.update() + + def update(self): + if not self.wallet.interface: + self.initializing() + elif not self.wallet.interface.is_connected: + self.connecting() + elif not self.wallet.blocks == -1: + self.connecting() + elif not self.wallet.is_up_to_date: + self.synchronizing() + else: + self.ready() + + def initializing(self): + if self.state == self.INITIALIZING: + return + self.state = self.INITIALIZING + self.window.deactivate() + + def connecting(self): + if self.state == self.CONNECTING: + return + self.state = self.CONNECTING + self.window.deactivate() + + def synchronizing(self): + if self.state == self.SYNCHRONIZING: + return + self.state = self.SYNCHRONIZING + self.window.deactivate() + + def ready(self): + if self.state == self.READY: + return + self.state = self.READY + self.window.activate() + conf_balance, unconf_balance = self.wallet.get_balance() + balance = conf_balance if unconf_balance is None else unconf_balance + self.window.set_balances(balance, 0, 'EUR') + if __name__ == "__main__": app = QApplication(sys.argv) with open("data/style.css") as style_file: