created several more docstrings in miniActuator
[electrum-nvc.git] / lib / gui_lite.py
1 import sys
2
3 from PyQt4.QtCore import *
4 from PyQt4.QtGui import *
5
6 from decimal import Decimal as D
7 from util import get_resource_path as rsrc
8 from i18n import _
9 import decimal
10 import exchange_rate
11 import os.path
12 import random
13 import re
14 import time
15 import wallet
16 import webbrowser
17 import history_widget
18 import util
19
20 try:
21     import lib.gui_qt as gui_qt
22 except ImportError:
23     import electrum.gui_qt as gui_qt
24
25 bitcoin = lambda v: v * 100000000
26
27 def IconButton(filename, parent=None):
28     pixmap = QPixmap(filename)
29     icon = QIcon(pixmap)
30     return QPushButton(icon, "", parent)
31
32 class Timer(QThread):
33     def run(self):
34         while True:
35             self.emit(SIGNAL('timersignal'))
36             time.sleep(0.5)
37
38 def resize_line_edit_width(line_edit, text_input):
39     metrics = QFontMetrics(qApp.font())
40     # Create an extra character to add some space on the end
41     text_input += "A"
42     line_edit.setMinimumWidth(metrics.width(text_input))
43
44 class ElectrumGui:
45
46     def __init__(self, wallet):
47         self.wallet = wallet
48         self.app = QApplication(sys.argv)
49
50     def main(self, url):
51         actuator = MiniActuator(self.wallet)
52         # Should probably not modify the current path but instead
53         # change the behaviour of rsrc(...)
54         old_path = QDir.currentPath()
55         actuator.load_theme()
56
57         self.mini = MiniWindow(actuator, self.expand)
58         driver = MiniDriver(self.wallet, self.mini)
59
60         # Reset path back to original value now that loading the GUI
61         # is completed.
62         QDir.setCurrent(old_path)
63
64         if url:
65             self.set_url(url)
66
67         timer = Timer()
68         timer.start()
69         self.expert = gui_qt.ElectrumWindow(self.wallet)
70         self.expert.app = self.app
71         self.expert.connect_slots(timer)
72         self.expert.update_wallet()
73
74         self.app.exec_()
75
76     def expand(self):
77         self.mini.hide()
78         self.expert.show()
79
80     def set_url(self, url):
81         payto, amount, label, message, signature, identity, url = \
82             self.wallet.parse_url(url, self.show_message, self.show_question)
83         self.mini.set_payment_fields(payto, amount)
84
85     def show_message(self, message):
86         QMessageBox.information(self.mini, _("Message"), message, _("OK"))
87
88     def show_question(self, message):
89         choice = QMessageBox.question(self.mini, _("Message"), message,
90                                       QMessageBox.Yes|QMessageBox.No,
91                                       QMessageBox.No)
92         return choice == QMessageBox.Yes
93
94     def restore_or_create(self):
95         qt_gui_object = gui_qt.ElectrumGui(self.wallet, self.app)
96         return qt_gui_object.restore_or_create()
97
98 class MiniWindow(QDialog):
99
100     def __init__(self, actuator, expand_callback):
101         super(MiniWindow, self).__init__()
102
103         self.actuator = actuator
104
105         self.btc_balance = None
106         self.quote_currencies = ["EUR", "USD", "GBP"]
107         self.actuator.set_configured_currency(self.set_quote_currency)
108         self.exchanger = exchange_rate.Exchanger(self)
109         # Needed because price discovery is done in a different thread
110         # which needs to be sent back to this main one to update the GUI
111         self.connect(self, SIGNAL("refresh_balance()"), self.refresh_balance)
112
113         self.balance_label = BalanceLabel(self.change_quote_currency)
114         self.balance_label.setObjectName("balance_label")
115
116         self.receive_button = QPushButton(_("&Receive"))
117         self.receive_button.setObjectName("receive_button")
118         self.receive_button.setDefault(True)
119         self.receive_button.clicked.connect(self.copy_address)
120
121         # Bitcoin address code
122         self.address_input = QLineEdit()
123         self.address_input.setPlaceholderText(_("Enter a Bitcoin address..."))
124         self.address_input.setObjectName("address_input")
125
126
127         self.address_input.textEdited.connect(self.address_field_changed)
128         resize_line_edit_width(self.address_input,
129                                "1BtaFUr3qVvAmwrsuDuu5zk6e4s2rxd2Gy")
130
131         self.address_completions = QStringListModel()
132         address_completer = QCompleter(self.address_input)
133         address_completer.setCaseSensitivity(False)
134         address_completer.setModel(self.address_completions)
135         self.address_input.setCompleter(address_completer)
136
137         address_layout = QHBoxLayout()
138         address_layout.addWidget(self.address_input)
139
140         self.amount_input = QLineEdit()
141         self.amount_input.setPlaceholderText(_("... and amount"))
142         self.amount_input.setObjectName("amount_input")
143         # This is changed according to the user's displayed balance
144         self.amount_validator = QDoubleValidator(self.amount_input)
145         self.amount_validator.setNotation(QDoubleValidator.StandardNotation)
146         self.amount_validator.setDecimals(8)
147         self.amount_input.setValidator(self.amount_validator)
148
149         # This removes the very ugly OSX highlighting, please leave this in :D
150         self.address_input.setAttribute(Qt.WA_MacShowFocusRect, 0)
151         self.amount_input.setAttribute(Qt.WA_MacShowFocusRect, 0)
152         self.amount_input.textChanged.connect(self.amount_input_changed)
153
154         self.send_button = QPushButton(_("&Send"))
155         self.send_button.setObjectName("send_button")
156         self.send_button.setDisabled(True);
157         self.send_button.clicked.connect(self.send)
158
159         main_layout = QGridLayout(self)
160
161         main_layout.addWidget(self.balance_label, 0, 0)
162         main_layout.addWidget(self.receive_button, 0, 1)
163
164         main_layout.addWidget(self.address_input, 1, 0, 1, -1)
165
166         main_layout.addWidget(self.amount_input, 2, 0)
167         main_layout.addWidget(self.send_button, 2, 1)
168
169         self.history_list = history_widget.HistoryWidget()
170         self.history_list.setObjectName("history")
171         self.history_list.hide()
172         self.history_list.setAlternatingRowColors(True)
173         main_layout.addWidget(self.history_list, 3, 0, 1, -1)
174
175         menubar = QMenuBar()
176         electrum_menu = menubar.addMenu(_("&Bitcoin"))
177         self.servers_menu = electrum_menu.addMenu(_("&Servers"))
178         self.servers_menu.addAction(_("Foo"))
179         electrum_menu.addSeparator()
180         brain_seed = electrum_menu.addAction(_("&BrainWallet Info"))
181         brain_seed.triggered.connect(self.actuator.show_seed_dialog)
182         quit_option = electrum_menu.addAction(_("&Quit"))
183         quit_option.triggered.connect(self.actuator.quit)
184
185         view_menu = menubar.addMenu(_("&View"))
186         expert_gui = view_menu.addAction(_("&Pro Mode"))
187         expert_gui.triggered.connect(expand_callback)
188         themes_menu = view_menu.addMenu(_("&Themes"))
189         selected_theme = self.actuator.selected_theme()
190         theme_group = QActionGroup(self)
191         for theme_name in self.actuator.theme_names():
192             theme_action = themes_menu.addAction(theme_name)
193             theme_action.setCheckable(True)
194             if selected_theme == theme_name:
195                 theme_action.setChecked(True)
196             class SelectThemeFunctor:
197                 def __init__(self, theme_name, toggle_theme):
198                     self.theme_name = theme_name
199                     self.toggle_theme = toggle_theme
200                 def __call__(self, checked):
201                     if checked:
202                         self.toggle_theme(self.theme_name)
203             delegate = SelectThemeFunctor(theme_name, self.toggle_theme)
204             theme_action.toggled.connect(delegate)
205             theme_group.addAction(theme_action)
206         view_menu.addSeparator()
207         show_history = view_menu.addAction(_("Show History"))
208         show_history.setCheckable(True)
209         show_history.toggled.connect(self.show_history)
210
211         help_menu = menubar.addMenu(_("&Help"))
212         the_website = help_menu.addAction(_("&Website"))
213         the_website.triggered.connect(self.the_website)
214         help_menu.addSeparator()
215         report_bug = help_menu.addAction(_("&Report Bug"))
216         report_bug.triggered.connect(self.show_report_bug)
217         show_about = help_menu.addAction(_("&About"))
218         show_about.triggered.connect(self.show_about)
219         main_layout.setMenuBar(menubar)
220
221         quit_shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
222         quit_shortcut.activated.connect(self.close)
223         close_shortcut = QShortcut(QKeySequence("Ctrl+W"), self)
224         close_shortcut.activated.connect(self.close)
225
226         self.setWindowIcon(QIcon(":electrum.png"))
227         self.setWindowTitle("Electrum")
228         self.setWindowFlags(Qt.Window|Qt.MSWindowsFixedSizeDialogHint)
229         self.layout().setSizeConstraint(QLayout.SetFixedSize)
230         self.setObjectName("main_window")
231         self.show()
232
233     def toggle_theme(self, theme_name):
234         old_path = QDir.currentPath()
235         self.actuator.change_theme(theme_name)
236         # Recompute style globally
237         qApp.style().unpolish(self)
238         qApp.style().polish(self)
239         QDir.setCurrent(old_path)
240
241     def closeEvent(self, event):
242         super(MiniWindow, self).closeEvent(event)
243         qApp.quit()
244
245     def set_payment_fields(self, dest_address, amount):
246         self.address_input.setText(dest_address)
247         self.address_field_changed(dest_address)
248         self.amount_input.setText(amount)
249
250     def activate(self):
251         pass
252
253     def deactivate(self):
254         pass
255
256     def set_quote_currency(self, currency):
257         assert currency in self.quote_currencies
258         self.quote_currencies.remove(currency)
259         self.quote_currencies = [currency] + self.quote_currencies
260         self.refresh_balance()
261
262     def change_quote_currency(self):
263         self.quote_currencies = \
264             self.quote_currencies[1:] + self.quote_currencies[0:1]
265         self.actuator.set_config_currency(self.quote_currencies[0])
266         self.refresh_balance()
267
268     def refresh_balance(self):
269         if self.btc_balance is None:
270             # Price has been discovered before wallet has been loaded
271             # and server connect... so bail.
272             return
273         self.set_balances(self.btc_balance)
274         self.amount_input_changed(self.amount_input.text())
275
276     def set_balances(self, btc_balance):
277         self.btc_balance = btc_balance
278         quote_text = self.create_quote_text(btc_balance)
279         if quote_text:
280             quote_text = "(%s)" % quote_text
281         btc_balance = "%.2f" % (btc_balance / bitcoin(1))
282         self.balance_label.set_balance_text(btc_balance, quote_text)
283         self.setWindowTitle("Electrum - %s BTC" % btc_balance)
284
285     def amount_input_changed(self, amount_text):
286         self.check_button_status()
287
288         try:
289             amount = D(str(amount_text))
290         except decimal.InvalidOperation:
291             self.balance_label.show_balance()
292         else:
293             quote_text = self.create_quote_text(amount * bitcoin(1))
294             if quote_text:
295                 self.balance_label.set_amount_text(quote_text)
296                 self.balance_label.show_amount()
297             else:
298                 self.balance_label.show_balance()
299
300     def create_quote_text(self, btc_balance):
301         quote_currency = self.quote_currencies[0]
302         quote_balance = self.exchanger.exchange(btc_balance, quote_currency)
303         if quote_balance is None:
304             quote_text = ""
305         else:
306             quote_text = "%.2f %s" % ((quote_balance / bitcoin(1)),
307                                       quote_currency)
308         return quote_text
309
310     def send(self):
311         if self.actuator.send(self.address_input.text(),
312                               self.amount_input.text(), self):
313             self.address_input.setText("")
314             self.amount_input.setText("")
315
316     def check_button_status(self):
317         if (self.address_input.property("isValid") == True and
318             len(self.amount_input.text()) > 0):
319             self.send_button.setDisabled(False)
320         else:
321             self.send_button.setDisabled(True)
322
323     def address_field_changed(self, address):
324         if self.actuator.is_valid(address):
325             self.check_button_status()
326             self.address_input.setProperty("isValid", True)
327             self.recompute_style(self.address_input)
328         else:
329             self.send_button.setDisabled(True)
330             self.address_input.setProperty("isValid", False)
331             self.recompute_style(self.address_input)
332
333         if len(address) == 0:
334             self.address_input.setProperty("isValid", None)
335             self.recompute_style(self.address_input)
336
337     def recompute_style(self, element):
338         self.style().unpolish(element)
339         self.style().polish(element)
340
341     def copy_address(self):
342         receive_popup = ReceivePopup(self.receive_button)
343         self.actuator.copy_address(receive_popup)
344
345     def update_completions(self, completions):
346         self.address_completions.setStringList(completions)
347
348     def update_history(self, tx_history):
349         for tx in tx_history[-10:]:
350             address = tx["default_label"]
351             amount = D(tx["value"]) / 10**8
352             self.history_list.append(address, amount)
353
354     def acceptbit(self):
355         self.actuator.acceptbit(self.quote_currencies[0])
356
357     def the_website(self):
358         webbrowser.open("http://electrum-desktop.com")
359
360     def show_about(self):
361         QMessageBox.about(self, "Electrum",
362             _("Electrum's focus is speed, with low resource usage and simplifying Bitcoin. You do not need to perform regular backups, because your wallet can be recovered from a secret phrase that you can memorize or write on paper. Startup times are instant because it operates in conjuction with high-performance servers that handle the most complicated parts of the Bitcoin system.\n\nSend donations to 1JwTMv4GWaPdf931N6LNPJeZBfZgZJ3zX1"))
363
364     def show_report_bug(self):
365         QMessageBox.information(self, "Electrum - " + _("Reporting Bugs"),
366             _("Email bug reports to %s") % "genjix" + "@" + "riseup.net")
367
368     def show_history(self, toggle_state):
369         if toggle_state:
370             self.history_list.show()
371         else:
372             self.history_list.hide()
373
374 class BalanceLabel(QLabel):
375
376     SHOW_CONNECTING = 1
377     SHOW_BALANCE = 2
378     SHOW_AMOUNT = 3
379
380     def __init__(self, change_quote_currency, parent=None):
381         super(QLabel, self).__init__(_("Connecting..."), parent)
382         self.change_quote_currency = change_quote_currency
383         self.state = self.SHOW_CONNECTING
384         self.balance_text = ""
385         self.amount_text = ""
386
387     def mousePressEvent(self, event):
388         if self.state != self.SHOW_CONNECTING:
389             self.change_quote_currency()
390
391     def set_balance_text(self, btc_balance, quote_text):
392         if self.state == self.SHOW_CONNECTING:
393             self.state = self.SHOW_BALANCE
394         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)
395         if self.state == self.SHOW_BALANCE:
396             self.setText(self.balance_text)
397
398     def set_amount_text(self, quote_text):
399         self.amount_text = "<span style='font-size: 10pt'>%s</span>" % quote_text
400         if self.state == self.SHOW_AMOUNT:
401             self.setText(self.amount_text)
402
403     def show_balance(self):
404         if self.state == self.SHOW_AMOUNT:
405             self.state = self.SHOW_BALANCE
406             self.setText(self.balance_text)
407
408     def show_amount(self):
409         if self.state == self.SHOW_BALANCE:
410             self.state = self.SHOW_AMOUNT
411             self.setText(self.amount_text)
412
413 def ok_cancel_buttons(dialog):
414     row_layout = QHBoxLayout()
415     row_layout.addStretch(1)
416     ok_button = QPushButton(_("OK"))
417     row_layout.addWidget(ok_button)
418     ok_button.clicked.connect(dialog.accept)
419     cancel_button = QPushButton(_("Cancel"))
420     row_layout.addWidget(cancel_button)
421     cancel_button.clicked.connect(dialog.reject)
422     return row_layout
423
424 class PasswordDialog(QDialog):
425
426     def __init__(self, parent):
427         super(QDialog, self).__init__(parent)
428
429         self.setModal(True)
430
431         self.password_input = QLineEdit()
432         self.password_input.setEchoMode(QLineEdit.Password)
433
434         main_layout = QVBoxLayout(self)
435         message = _('Please enter your password')
436         main_layout.addWidget(QLabel(message))
437
438         grid = QGridLayout()
439         grid.setSpacing(8)
440         grid.addWidget(QLabel(_('Password')), 1, 0)
441         grid.addWidget(self.password_input, 1, 1)
442         main_layout.addLayout(grid)
443
444         main_layout.addLayout(ok_cancel_buttons(self))
445         self.setLayout(main_layout) 
446
447     def run(self):
448         if not self.exec_():
449             return
450         return unicode(self.password_input.text())
451
452 class ReceivePopup(QDialog):
453
454     def leaveEvent(self, event):
455         self.close()
456
457     def setup(self, address):
458         label = QLabel(_("Copied your Bitcoin address to the clipboard!"))
459         address_display = QLineEdit(address)
460         address_display.setReadOnly(True)
461         resize_line_edit_width(address_display, address)
462
463         main_layout = QVBoxLayout(self)
464         main_layout.addWidget(label)
465         main_layout.addWidget(address_display)
466
467         self.setMouseTracking(True)
468         self.setWindowTitle("Electrum - " + _("Receive Bitcoin payment"))
469         self.setWindowFlags(Qt.Window|Qt.FramelessWindowHint|Qt.MSWindowsFixedSizeDialogHint)
470         self.layout().setSizeConstraint(QLayout.SetFixedSize)
471         #self.setFrameStyle(QFrame.WinPanel|QFrame.Raised)
472         #self.setAlignment(Qt.AlignCenter)
473
474     def popup(self):
475         parent = self.parent()
476         top_left_pos = parent.mapToGlobal(parent.rect().bottomLeft())
477         self.move(top_left_pos)
478         center_mouse_pos = self.mapToGlobal(self.rect().center())
479         QCursor.setPos(center_mouse_pos)
480         self.show()
481
482 class MiniActuator:
483     """Initialize the definitions for all the menubar functions and 
484     sending/recieving bitcoins.
485     """
486     
487     
488     def __init__(self, wallet):
489         """Retrieve the gui theme used in previous session."""
490         self.wallet = wallet
491         self.theme_name = self.wallet.theme
492         self.themes = util.load_theme_paths()
493
494     def load_theme(self):
495         """Load theme retrieved from wallet file."""
496         try:
497             theme_prefix, theme_path = self.themes[self.theme_name]
498         except KeyError:
499             util.print_error("Theme not found!", self.theme_name)
500             return
501         QDir.setCurrent(os.path.join(theme_prefix, theme_path))
502         with open(rsrc("style.css")) as style_file:
503             qApp.setStyleSheet(style_file.read())
504
505     def theme_names(self):
506         """Sort themes."""
507         return sorted(self.themes.keys())
508     def selected_theme(self):
509         """Select theme."""
510         return self.theme_name
511
512     def change_theme(self, theme_name):
513         """Change theme."""
514         self.wallet.theme = self.theme_name = theme_name
515         self.load_theme()
516     
517     def set_configured_currency(self, set_quote_currency):
518         """Set the inital fiat currency conversion country (USD/EUR/GBP) in 
519         the GUI to what it was set to in the wallet."""
520         currency = self.wallet.conversion_currency
521         # currency can be none when Electrum is used for the first
522         # time and no setting has been created yet.
523         if currency is not None:
524             set_quote_currency(currency)
525
526     def set_config_currency(self, conversion_currency):
527         """Change the fiat currency conversion country."""
528         self.wallet.conversion_currency = conversion_currency
529
530     def copy_address(self, receive_popup):
531         """Copy the wallet addresses into the client."""
532         addrs = [addr for addr in self.wallet.all_addresses()
533                  if not self.wallet.is_change(addr)]
534         # Select most recent addresses from gap limit
535         addrs = addrs[-self.wallet.gap_limit:]
536         copied_address = random.choice(addrs)
537         qApp.clipboard().setText(copied_address)
538         receive_popup.setup(copied_address)
539         receive_popup.popup()
540
541     def send(self, address, amount, parent_window):
542         """Send bitcoins to the target address."""
543         dest_address = self.fetch_destination(address)
544
545         if dest_address is None or not self.wallet.is_valid(dest_address):
546             QMessageBox.warning(parent_window, _('Error'), 
547                 _('Invalid Bitcoin Address') + ':\n' + address, _('OK'))
548             return False
549
550         convert_amount = lambda amount: \
551             int(D(unicode(amount)) * bitcoin(1))
552         amount = convert_amount(amount)
553
554         if self.wallet.use_encryption:
555             password_dialog = PasswordDialog(parent_window)
556             password = password_dialog.run()
557             if not password:
558                 return
559         else:
560             password = None
561
562         fee = 0
563         # 0.1 BTC = 10000000
564         if amount < bitcoin(1) / 10:
565             # 0.001 BTC
566             fee = bitcoin(1) / 1000
567
568         try:
569             tx = self.wallet.mktx(dest_address, amount, "", password, fee)
570         except BaseException as error:
571             QMessageBox.warning(parent_window, _('Error'), str(error), _('OK'))
572             return False
573             
574         status, message = self.wallet.sendtx(tx)
575         if not status:
576             QMessageBox.warning(parent_window, _('Error'), message, _('OK'))
577             return False
578
579         QMessageBox.information(parent_window, '',
580             _('Payment sent.') + '\n' + message, _('OK'))
581         return True
582
583     def fetch_destination(self, address):
584         recipient = unicode(address).strip()
585
586         # alias
587         match1 = re.match("^(|([\w\-\.]+)@)((\w[\w\-]+\.)+[\w\-]+)$",
588                           recipient)
589
590         # label or alias, with address in brackets
591         match2 = re.match("(.*?)\s*\<([1-9A-HJ-NP-Za-km-z]{26,})\>",
592                           recipient)
593         
594         if match1:
595             dest_address = \
596                 self.wallet.get_alias(recipient, True, 
597                                       self.show_message, self.question)
598             return dest_address
599         elif match2:
600             return match2.group(2)
601         else:
602             return recipient
603
604     def is_valid(self, address):
605         """Check if bitcoin address is valid."""
606         return self.wallet.is_valid(address)
607
608     def acceptbit(self, currency):
609         master_pubkey = self.wallet.master_public_key.encode("hex")
610         url = "http://acceptbit.com/mpk/%s/%s" % (master_pubkey, currency)
611         webbrowser.open(url)
612
613     def show_seed_dialog(self):
614         gui_qt.ElectrumWindow.show_seed_dialog(self.wallet)
615
616     def quit(self):
617         sys.exit(0)
618
619 class MiniDriver(QObject):
620
621     INITIALIZING = 0
622     CONNECTING = 1
623     SYNCHRONIZING = 2
624     READY = 3
625
626     def __init__(self, wallet, window):
627         super(QObject, self).__init__()
628
629         self.wallet = wallet
630         self.window = window
631
632         self.wallet.register_callback(self.update_callback)
633
634         self.state = None
635
636         self.initializing()
637         self.connect(self, SIGNAL("updatesignal()"), self.update)
638         self.update_callback()
639
640     # This is a hack to workaround that Qt does not like changing the
641     # window properties from this other thread before the runloop has
642     # been called from.
643     def update_callback(self):
644         self.emit(SIGNAL("updatesignal()"))
645
646     def update(self):
647         if not self.wallet.interface:
648             self.initializing()
649         elif not self.wallet.interface.is_connected:
650             self.connecting()
651         elif not self.wallet.blocks == -1:
652             self.connecting()
653         elif not self.wallet.is_up_to_date:
654             self.synchronizing()
655         else:
656             self.ready()
657
658         if self.wallet.up_to_date:
659             self.update_balance()
660             self.update_completions()
661             self.update_history()
662
663     def initializing(self):
664         if self.state == self.INITIALIZING:
665             return
666         self.state = self.INITIALIZING
667         self.window.deactivate()
668
669     def connecting(self):
670         if self.state == self.CONNECTING:
671             return
672         self.state = self.CONNECTING
673         self.window.deactivate()
674
675     def synchronizing(self):
676         if self.state == self.SYNCHRONIZING:
677             return
678         self.state = self.SYNCHRONIZING
679         self.window.deactivate()
680
681     def ready(self):
682         if self.state == self.READY:
683             return
684         self.state = self.READY
685         self.window.activate()
686
687     def update_balance(self):
688         conf_balance, unconf_balance = self.wallet.get_balance()
689         balance = D(conf_balance + unconf_balance)
690         self.window.set_balances(balance)
691
692     def update_completions(self):
693         completions = []
694         for addr, label in self.wallet.labels.items():
695             if addr in self.wallet.addressbook:
696                 completions.append("%s <%s>" % (label, addr))
697         completions = completions + self.wallet.aliases.keys()
698         self.window.update_completions(completions)
699
700     def update_history(self):
701         tx_history = self.wallet.get_tx_history()
702         self.window.update_history(tx_history)
703
704 if __name__ == "__main__":
705     app = QApplication(sys.argv)
706     with open(rsrc("style.css")) as style_file:
707         app.setStyleSheet(style_file.read())
708     mini = MiniWindow()
709     sys.exit(app.exec_())
710