move lite window initialization in the constructor of the main window
This commit is contained in:
parent
5b88b16600
commit
6644fcc22e
|
@ -79,46 +79,6 @@ class ElectrumGui:
|
|||
init_plugins(self)
|
||||
|
||||
|
||||
|
||||
def expand(self):
|
||||
"""Hide the lite mode window and show pro-mode."""
|
||||
self.config.set_key('lite_mode', False, True)
|
||||
self.mini.hide()
|
||||
self.expert.show()
|
||||
|
||||
def minimize(self):
|
||||
self.config.set_key('lite_mode', True, True)
|
||||
self.expert.hide()
|
||||
self.mini.show()
|
||||
|
||||
def init_lite(self, wallet, expert, url):
|
||||
import lite_window
|
||||
if not self.check_qt_version():
|
||||
return
|
||||
|
||||
actuator = lite_window.MiniActuator(self.config, wallet)
|
||||
# Should probably not modify the current path but instead
|
||||
# change the behaviour of rsrc(...)
|
||||
old_path = QDir.currentPath()
|
||||
actuator.load_theme()
|
||||
|
||||
mini = lite_window.MiniWindow(actuator, self.expand, self.config)
|
||||
driver = lite_window.MiniDriver(wallet, mini)
|
||||
|
||||
# Reset path back to original value now that loading the GUI
|
||||
# is completed.
|
||||
QDir.setCurrent(old_path)
|
||||
if url:
|
||||
payto, amount, label, message, signature, identity, url = parse_url(url)
|
||||
mini.set_payment_fields(payto, amount)
|
||||
|
||||
return mini
|
||||
|
||||
def check_qt_version(self):
|
||||
qtVersion = qVersion()
|
||||
return int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7
|
||||
|
||||
|
||||
def main(self, url):
|
||||
|
||||
storage = WalletStorage(self.config)
|
||||
|
@ -133,8 +93,7 @@ class ElectrumGui:
|
|||
|
||||
wallet.start_threads(self.network)
|
||||
|
||||
|
||||
self.main_window = w = ElectrumWindow(self.config, self.network, self.minimize)
|
||||
self.main_window = w = ElectrumWindow(self.config, self.network)
|
||||
|
||||
# plugins that need to change the GUI do it here
|
||||
run_hook('init')
|
||||
|
@ -150,21 +109,6 @@ class ElectrumGui:
|
|||
w.connect_slots(s)
|
||||
w.update_wallet()
|
||||
|
||||
self.expert = w
|
||||
self.mini = self.init_lite(wallet, w, url)
|
||||
|
||||
if self.config.get('lite_mode'):
|
||||
if not self.mini:
|
||||
QMessageBox.warning(None,"Could not start Lite GUI.", "Electrum was unable to load the 'Lite GUI' because it needs Qt version >= 4.7.\nChanging your config to use the 'Classic' GUI")
|
||||
self.config.set_key('lite_mode', False, True)
|
||||
sys.exit(0)
|
||||
else:
|
||||
self.minimize()
|
||||
else:
|
||||
w.show()
|
||||
if self.mini:
|
||||
self.mini.hide()
|
||||
|
||||
self.app.exec_()
|
||||
|
||||
wallet.stop_threads()
|
||||
|
|
|
@ -179,7 +179,7 @@ class MiniWindow(QDialog):
|
|||
self.btc_balance = None
|
||||
self.quote_currencies = ["BRL", "CNY", "EUR", "GBP", "RUB", "USD"]
|
||||
self.actuator.set_configured_currency(self.set_quote_currency)
|
||||
#self.exchanger = exchange_rate.Exchanger(self)
|
||||
|
||||
# Needed because price discovery is done in a different thread
|
||||
# which needs to be sent back to this main one to update the GUI
|
||||
self.connect(self, SIGNAL("refresh_balance()"), self.refresh_balance)
|
||||
|
@ -224,10 +224,10 @@ class MiniWindow(QDialog):
|
|||
self.amount_input.setAttribute(Qt.WA_MacShowFocusRect, 0)
|
||||
self.amount_input.textChanged.connect(self.amount_input_changed)
|
||||
|
||||
if self.actuator.wallet.seed:
|
||||
#if self.actuator.g.wallet.seed:
|
||||
self.send_button = QPushButton(_("&Send"))
|
||||
else:
|
||||
self.send_button = QPushButton(_("&Create"))
|
||||
#else:
|
||||
# self.send_button = QPushButton(_("&Create"))
|
||||
|
||||
self.send_button.setObjectName("send_button")
|
||||
self.send_button.setDisabled(True);
|
||||
|
@ -403,9 +403,12 @@ class MiniWindow(QDialog):
|
|||
quote_text = self.create_quote_text(btc_balance)
|
||||
if quote_text:
|
||||
quote_text = "(%s)" % quote_text
|
||||
btc_balance = "%.4f" % (btc_balance / bitcoin(1))
|
||||
self.balance_label.set_balance_text(btc_balance, quote_text)
|
||||
self.setWindowTitle("Electrum %s - %s BTC" % (electrum_version, btc_balance))
|
||||
|
||||
amount = self.actuator.g.format_amount(btc_balance)
|
||||
unit = self.actuator.g.base_unit()
|
||||
|
||||
self.balance_label.set_balance_text(amount, unit, quote_text)
|
||||
self.setWindowTitle("Electrum %s - %s %s" % (electrum_version, amount, unit))
|
||||
|
||||
def amount_input_changed(self, amount_text):
|
||||
"""Update the number of bitcoins displayed."""
|
||||
|
@ -426,14 +429,10 @@ class MiniWindow(QDialog):
|
|||
def create_quote_text(self, btc_balance):
|
||||
"""Return a string copy of the amount fiat currency the
|
||||
user has in bitcoins."""
|
||||
quote_currency = self.quote_currencies[0]
|
||||
quote_balance = None #self.exchanger.exchange(btc_balance, quote_currency)
|
||||
if quote_balance is None:
|
||||
quote_text = ""
|
||||
else:
|
||||
quote_text = "%.2f %s" % ((quote_balance / bitcoin(1)),
|
||||
quote_currency)
|
||||
return quote_text
|
||||
from electrum.plugins import run_hook
|
||||
r = {}
|
||||
run_hook('set_quote_text', btc_balance, r)
|
||||
return r.get(0,'')
|
||||
|
||||
def send(self):
|
||||
if self.actuator.send(self.address_input.text(),
|
||||
|
@ -495,7 +494,7 @@ class MiniWindow(QDialog):
|
|||
|
||||
for item in tx_history[-10:]:
|
||||
tx_hash, conf, is_mine, value, fee, balance, timestamp = item
|
||||
label = self.actuator.wallet.get_label(tx_hash)[0]
|
||||
label = self.actuator.g.wallet.get_label(tx_hash)[0]
|
||||
#amount = D(value) / 10**8
|
||||
v_str = format_satoshis(value, True)
|
||||
self.history_list.append(label, v_str, age(timestamp))
|
||||
|
@ -546,11 +545,15 @@ class BalanceLabel(QLabel):
|
|||
menu.exec_(position)
|
||||
|
||||
|
||||
def set_balance_text(self, btc_balance, quote_text):
|
||||
def set_balance_text(self, amount, unit, quote_text):
|
||||
"""Set the amount of bitcoins in the gui."""
|
||||
if self.state == self.SHOW_CONNECTING:
|
||||
self.state = self.SHOW_BALANCE
|
||||
self.balance_text = "<span style='font-size: 18pt'>%s</span> <span style='font-size: 10pt'>BTC</span> <span style='font-size: 10pt'>%s</span>" % (btc_balance, quote_text)
|
||||
|
||||
self.balance_text = "<span style='font-size: 18pt'>%s</span>"%amount\
|
||||
+ " <span style='font-size: 10pt'>%s</span>" % unit \
|
||||
+ " <span style='font-size: 10pt'>%s</span>" % quote_text
|
||||
|
||||
if self.state == self.SHOW_BALANCE:
|
||||
self.setText(self.balance_text)
|
||||
|
||||
|
@ -644,11 +647,10 @@ class MiniActuator:
|
|||
sending/receiving bitcoins."""
|
||||
|
||||
|
||||
def __init__(self, config, wallet):
|
||||
def __init__(self, main_window):
|
||||
"""Retrieve the gui theme used in previous session."""
|
||||
self.config = config
|
||||
self.wallet = wallet
|
||||
self.theme_name = self.config.get('litegui_theme','Cleanlook')
|
||||
self.g = main_window
|
||||
self.theme_name = self.g.config.get('litegui_theme','Cleanlook')
|
||||
self.themes = load_theme_paths()
|
||||
|
||||
def load_theme(self):
|
||||
|
@ -679,7 +681,7 @@ class MiniActuator:
|
|||
def set_configured_currency(self, set_quote_currency):
|
||||
"""Set the inital fiat currency conversion country (USD/EUR/GBP) in
|
||||
the GUI to what it was set to in the wallet."""
|
||||
currency = self.config.get('currency')
|
||||
currency = self.g.config.get('currency')
|
||||
# currency can be none when Electrum is used for the first
|
||||
# time and no setting has been created yet.
|
||||
if currency is not None:
|
||||
|
@ -687,14 +689,14 @@ class MiniActuator:
|
|||
|
||||
def set_config_currency(self, conversion_currency):
|
||||
"""Change the wallet fiat currency country."""
|
||||
self.config.set_key('conversion_currency',conversion_currency,True)
|
||||
self.g.config.set_key('conversion_currency',conversion_currency,True)
|
||||
|
||||
def copy_address(self, receive_popup):
|
||||
"""Copy the wallet addresses into the client."""
|
||||
addrs = [addr for addr in self.wallet.addresses(True)
|
||||
if not self.wallet.is_change(addr)]
|
||||
addrs = [addr for addr in self.g.wallet.addresses(True)
|
||||
if not self.g.wallet.is_change(addr)]
|
||||
# Select most recent addresses from gap limit
|
||||
addrs = addrs[-self.wallet.gap_limit:]
|
||||
addrs = addrs[-self.g.wallet.gap_limit:]
|
||||
copied_address = random.choice(addrs)
|
||||
qApp.clipboard().setText(copied_address)
|
||||
receive_popup.setup(copied_address)
|
||||
|
@ -733,7 +735,7 @@ class MiniActuator:
|
|||
int(D(unicode(amount)) * bitcoin(1))
|
||||
amount = convert_amount(amount)
|
||||
|
||||
if self.wallet.use_encryption:
|
||||
if self.g.wallet.use_encryption:
|
||||
password_dialog = PasswordDialog(parent_window)
|
||||
password = password_dialog.run()
|
||||
if not password:
|
||||
|
@ -748,17 +750,17 @@ class MiniActuator:
|
|||
fee = bitcoin(1) / 1000
|
||||
|
||||
try:
|
||||
tx = self.wallet.mktx([(dest_address, amount)], password, fee)
|
||||
tx = self.g.wallet.mktx([(dest_address, amount)], password, fee)
|
||||
except BaseException as error:
|
||||
QMessageBox.warning(parent_window, _('Error'), str(error), _('OK'))
|
||||
return False
|
||||
|
||||
if tx.is_complete:
|
||||
h = self.wallet.send_tx(tx)
|
||||
h = self.g.wallet.send_tx(tx)
|
||||
|
||||
self.waiting_dialog(lambda: False if self.wallet.tx_event.isSet() else _("Sending transaction, please wait..."))
|
||||
self.waiting_dialog(lambda: False if self.g.wallet.tx_event.isSet() else _("Sending transaction, please wait..."))
|
||||
|
||||
status, message = self.wallet.receive_tx(h)
|
||||
status, message = self.g.wallet.receive_tx(h)
|
||||
|
||||
if not status:
|
||||
import tempfile
|
||||
|
@ -794,7 +796,7 @@ class MiniActuator:
|
|||
|
||||
if match1:
|
||||
dest_address = \
|
||||
self.wallet.get_alias(recipient, True,
|
||||
self.g.wallet.get_alias(recipient, True,
|
||||
self.show_message, self.question)
|
||||
return dest_address
|
||||
elif match2:
|
||||
|
@ -813,16 +815,16 @@ class MiniDriver(QObject):
|
|||
SYNCHRONIZING = 2
|
||||
READY = 3
|
||||
|
||||
def __init__(self, wallet, window):
|
||||
def __init__(self, main_window, mini_window):
|
||||
super(QObject, self).__init__()
|
||||
|
||||
self.wallet = wallet
|
||||
self.network = wallet.network
|
||||
self.window = window
|
||||
self.g = main_window
|
||||
self.network = main_window.network
|
||||
self.window = mini_window
|
||||
|
||||
self.wallet.network.register_callback('updated',self.update_callback)
|
||||
self.wallet.network.register_callback('connected', self.update_callback)
|
||||
self.wallet.network.register_callback('disconnected', self.update_callback)
|
||||
self.network.register_callback('updated',self.update_callback)
|
||||
self.network.register_callback('connected', self.update_callback)
|
||||
self.network.register_callback('disconnected', self.update_callback)
|
||||
|
||||
self.state = None
|
||||
|
||||
|
@ -841,12 +843,13 @@ class MiniDriver(QObject):
|
|||
self.initializing()
|
||||
elif not self.network.interface.is_connected:
|
||||
self.connecting()
|
||||
elif not self.wallet.up_to_date:
|
||||
|
||||
if self.g.wallet is None:
|
||||
self.ready()
|
||||
elif not self.g.wallet.up_to_date:
|
||||
self.synchronizing()
|
||||
else:
|
||||
self.ready()
|
||||
|
||||
if self.wallet.up_to_date:
|
||||
self.update_balance()
|
||||
self.update_completions()
|
||||
self.update_history()
|
||||
|
@ -876,19 +879,19 @@ class MiniDriver(QObject):
|
|||
self.window.activate()
|
||||
|
||||
def update_balance(self):
|
||||
conf_balance, unconf_balance = self.wallet.get_balance()
|
||||
conf_balance, unconf_balance = self.g.wallet.get_balance()
|
||||
balance = D(conf_balance + unconf_balance)
|
||||
self.window.set_balances(balance)
|
||||
|
||||
def update_completions(self):
|
||||
completions = []
|
||||
for addr, label in self.wallet.labels.items():
|
||||
if addr in self.wallet.addressbook:
|
||||
for addr, label in self.g.wallet.labels.items():
|
||||
if addr in self.g.wallet.addressbook:
|
||||
completions.append("%s <%s>" % (label, addr))
|
||||
self.window.update_completions(completions)
|
||||
|
||||
def update_history(self):
|
||||
tx_history = self.wallet.get_tx_history()
|
||||
tx_history = self.g.wallet.get_tx_history()
|
||||
self.window.update_history(tx_history)
|
||||
|
||||
|
||||
|
|
|
@ -135,12 +135,11 @@ class ElectrumWindow(QMainWindow):
|
|||
self.showNormal()
|
||||
|
||||
|
||||
def __init__(self, config, network, go_lite):
|
||||
def __init__(self, config, network):
|
||||
QMainWindow.__init__(self)
|
||||
|
||||
self.config = config
|
||||
self.network = network
|
||||
self.go_lite = go_lite
|
||||
|
||||
self._close_electrum = False
|
||||
self.lite = None
|
||||
|
@ -209,6 +208,56 @@ class ElectrumWindow(QMainWindow):
|
|||
tabs.setCurrentIndex (n)
|
||||
tabs.setCurrentIndex (0)
|
||||
|
||||
self.wallet = None
|
||||
self.init_lite()
|
||||
|
||||
|
||||
def go_full(self):
|
||||
self.config.set_key('lite_mode', False, True)
|
||||
self.mini.hide()
|
||||
self.show()
|
||||
|
||||
def go_lite(self):
|
||||
self.config.set_key('lite_mode', True, True)
|
||||
self.hide()
|
||||
self.mini.show()
|
||||
|
||||
|
||||
def init_lite(self):
|
||||
import lite_window
|
||||
if not self.check_qt_version():
|
||||
if self.config.get('lite_mode') is True:
|
||||
msg = "Electrum was unable to load the 'Lite GUI' because it needs Qt version >= 4.7.\nChanging your config to use the 'Classic' GUI"
|
||||
QMessageBox.warning(None, "Could not start Lite GUI.", msg)
|
||||
self.config.set_key('lite_mode', False, True)
|
||||
sys.exit(0)
|
||||
self.mini = None
|
||||
return
|
||||
|
||||
actuator = lite_window.MiniActuator(self)
|
||||
|
||||
# Should probably not modify the current path but instead
|
||||
# change the behaviour of rsrc(...)
|
||||
old_path = QDir.currentPath()
|
||||
actuator.load_theme()
|
||||
|
||||
self.mini = lite_window.MiniWindow(actuator, self.go_full, self.config)
|
||||
|
||||
driver = lite_window.MiniDriver(self, self.mini)
|
||||
|
||||
# Reset path back to original value now that loading the GUI
|
||||
# is completed.
|
||||
QDir.setCurrent(old_path)
|
||||
|
||||
if self.config.get('lite_mode') is True:
|
||||
self.go_lite()
|
||||
else:
|
||||
self.go_full()
|
||||
|
||||
|
||||
def check_qt_version(self):
|
||||
qtVersion = qVersion()
|
||||
return int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7
|
||||
|
||||
|
||||
|
||||
|
@ -498,10 +547,6 @@ class ElectrumWindow(QMainWindow):
|
|||
assert self.decimal_point in [5,8]
|
||||
return "BTC" if self.decimal_point == 8 else "mBTC"
|
||||
|
||||
def set_status_text(self, text):
|
||||
self.balance_label.setText(text)
|
||||
run_hook('set_status_text', text)
|
||||
|
||||
|
||||
def update_status(self):
|
||||
if self.network.interface and self.network.interface.is_connected:
|
||||
|
@ -512,15 +557,23 @@ class ElectrumWindow(QMainWindow):
|
|||
c, u = self.wallet.get_account_balance(self.current_account)
|
||||
text = _( "Balance" ) + ": %s "%( self.format_amount(c) ) + self.base_unit()
|
||||
if u: text += " [%s unconfirmed]"%( self.format_amount(u,True).strip() )
|
||||
|
||||
r = {}
|
||||
run_hook('set_quote_text', c+u, r)
|
||||
quote = r.get(0)
|
||||
if quote:
|
||||
text += " (%s)"%quote
|
||||
|
||||
self.tray.setToolTip(text)
|
||||
icon = QIcon(":icons/status_connected.png")
|
||||
else:
|
||||
text = _("Not connected")
|
||||
icon = QIcon(":icons/status_disconnected.png")
|
||||
|
||||
self.set_status_text(text)
|
||||
self.balance_label.setText(text)
|
||||
self.status_button.setIcon( icon )
|
||||
|
||||
|
||||
def update_wallet(self):
|
||||
self.update_status()
|
||||
if self.wallet.up_to_date or not self.network.interface.is_connected:
|
||||
|
@ -530,7 +583,6 @@ class ElectrumWindow(QMainWindow):
|
|||
self.update_completions()
|
||||
|
||||
|
||||
|
||||
def create_history_tab(self):
|
||||
self.history_list = l = MyTreeWidget(self)
|
||||
l.setColumnCount(5)
|
||||
|
@ -886,7 +938,8 @@ class ElectrumWindow(QMainWindow):
|
|||
|
||||
def set_url(self, url):
|
||||
address, amount, label, message, signature, identity, url = util.parse_url(url)
|
||||
if self.base_unit() == 'mBTC': amount = str( 1000* Decimal(amount))
|
||||
if self.mini:
|
||||
self.mini.set_payment_fields(address, amount)
|
||||
|
||||
if label and self.wallet.labels.get(address) != label:
|
||||
if self.question('Give label "%s" to address %s ?'%(label,address)):
|
||||
|
@ -902,7 +955,10 @@ class ElectrumWindow(QMainWindow):
|
|||
self.payto_e.setText(m_addr)
|
||||
|
||||
self.message_e.setText(message)
|
||||
if amount:
|
||||
if self.base_unit() == 'mBTC': amount = str( 1000* Decimal(amount))
|
||||
self.amount_e.setText(amount)
|
||||
|
||||
if identity:
|
||||
self.set_frozen(self.payto_e,True)
|
||||
self.set_frozen(self.amount_e,True)
|
||||
|
|
|
@ -27,7 +27,7 @@ class ReceivingWidget(QTreeWidget):
|
|||
else:
|
||||
address = str(item.text(0))
|
||||
label = unicode( item.text(1) )
|
||||
self.owner.actuator.wallet.labels[address] = label
|
||||
self.owner.actuator.g.wallet.labels[address] = label
|
||||
|
||||
def copy_address(self):
|
||||
address = self.currentItem().text(0)
|
||||
|
@ -36,9 +36,9 @@ class ReceivingWidget(QTreeWidget):
|
|||
|
||||
def update_list(self):
|
||||
self.clear()
|
||||
addresses = self.owner.actuator.wallet.addresses(False)
|
||||
addresses = self.owner.actuator.g.wallet.addresses(False)
|
||||
for address in addresses:
|
||||
history = self.owner.actuator.wallet.history.get(address,[])
|
||||
history = self.owner.actuator.g.wallet.history.get(address,[])
|
||||
|
||||
used = "No"
|
||||
# It appears that at this moment history can either be an array with tx and block height
|
||||
|
@ -49,17 +49,17 @@ class ReceivingWidget(QTreeWidget):
|
|||
used = "Yes"
|
||||
else:
|
||||
for tx_hash in history:
|
||||
tx = self.owner.actuator.wallet.transactions.get(tx_hash)
|
||||
tx = self.owner.actuator.g.wallet.transactions.get(tx_hash)
|
||||
if tx:
|
||||
used = "Yes"
|
||||
else:
|
||||
for tx_hash, height in history:
|
||||
tx = self.owner.actuator.wallet.transactions.get(tx_hash)
|
||||
tx = self.owner.actuator.g.wallet.transactions.get(tx_hash)
|
||||
if tx:
|
||||
used = "Yes"
|
||||
|
||||
if(self.hide_used == True and used == "No") or self.hide_used == False:
|
||||
label = self.owner.actuator.wallet.labels.get(address,'')
|
||||
label = self.owner.actuator.g.wallet.labels.get(address,'')
|
||||
item = QTreeWidgetItem([address, label, used])
|
||||
self.insertTopLevelItem(0, item)
|
||||
|
||||
|
@ -74,4 +74,4 @@ class ReceivingWidget(QTreeWidget):
|
|||
|
||||
self.hide_used = True
|
||||
self.setColumnHidden(2, True)
|
||||
self.update_list()
|
||||
#self.update_list()
|
||||
|
|
|
@ -78,13 +78,9 @@ class Plugin(BasePlugin):
|
|||
self.exchanger.start()
|
||||
self.gui.exchanger = self.exchanger
|
||||
|
||||
def set_status_text(self, text):
|
||||
m = re.match( _( "Balance" ) + ": (\d.+) " + self.win.base_unit(), str(text))
|
||||
if m:
|
||||
amount = Decimal(m.group(1))
|
||||
if self.win.base_unit() == 'mBTC': amount = amount / 1000
|
||||
text += self.create_quote_text(amount)
|
||||
self.win.balance_label.setText(text)
|
||||
|
||||
def set_quote_text(self, btc_balance, r):
|
||||
r[0] = self.create_quote_text(Decimal(btc_balance) / 100000000)
|
||||
|
||||
def create_quote_text(self, btc_balance):
|
||||
quote_currency = self.config.get("currency", "None")
|
||||
|
@ -92,7 +88,7 @@ class Plugin(BasePlugin):
|
|||
if quote_balance is None:
|
||||
quote_text = ""
|
||||
else:
|
||||
quote_text = " (%.2f %s)" % (quote_balance, quote_currency)
|
||||
quote_text = "%.2f %s" % (quote_balance, quote_currency)
|
||||
return quote_text
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue