qt history: minor clean-up and sanity checking

This commit is contained in:
SomberNight 2018-12-08 04:07:46 +01:00
parent e023d8abdd
commit 48e119b59e
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
5 changed files with 17 additions and 10 deletions

View file

@ -319,12 +319,12 @@ class Daemon(DaemonThread):
DaemonThread.stop(self)
def init_gui(self, config, plugins):
threading.current_thread().setName('GUI')
gui_name = config.get('gui', 'qt')
if gui_name in ['lite', 'classic']:
gui_name = 'qt'
gui = __import__('electrum.gui.' + gui_name, fromlist=['electrum'])
self.gui = gui.ElectrumGui(config, self, plugins)
threading.current_thread().setName('GUI')
try:
self.gui.main()
except BaseException as e:

View file

@ -97,6 +97,7 @@ class ElectrumGui(PrintError):
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
if hasattr(QGuiApplication, 'setDesktopFileName'):
QGuiApplication.setDesktopFileName('electrum.desktop')
self.gui_thread = threading.current_thread()
self.config = config
self.daemon = daemon
self.plugins = plugins

View file

@ -27,10 +27,12 @@ import webbrowser
import datetime
from datetime import date
from typing import TYPE_CHECKING, Tuple, Dict
import threading
from electrum.address_synchronizer import TX_HEIGHT_LOCAL
from electrum.i18n import _
from electrum.util import block_explorer_URL, profiler, print_error, TxMinedInfo
from electrum.util import (block_explorer_URL, profiler, print_error, TxMinedInfo,
PrintError)
from .util import *
@ -67,7 +69,8 @@ class HistorySortModel(QSortFilterProxyModel):
return False
return item1.value() < item2.value()
class HistoryModel(QAbstractItemModel):
class HistoryModel(QAbstractItemModel, PrintError):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
@ -171,6 +174,8 @@ class HistoryModel(QAbstractItemModel):
return self.parent.wallet.get_addresses()
def refresh(self, reason: str):
self.print_error(f"refreshing... reason: {reason}")
assert self.parent.gui_thread == threading.current_thread(), 'must be called from GUI thread'
selected = self.parent.history_list.selectionModel().currentIndex()
selected_row = None
if selected:
@ -288,7 +293,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
return True
return False
def __init__(self, parent, model):
def __init__(self, parent, model: HistoryModel):
super().__init__(parent, self.create_menu, 2)
self.hm = model
self.proxy = HistorySortModel(self)

View file

@ -114,6 +114,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
self.gui_object = gui_object
self.config = config = gui_object.config # type: SimpleConfig
self.gui_thread = gui_object.gui_thread
self.setup_exception_hook()

View file

@ -45,7 +45,7 @@ from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
format_satoshis, format_fee_satoshis, NoDynamicFeeEstimates,
WalletFileException, BitcoinException,
InvalidPassword, format_time, timestamp_to_datetime, Satoshis,
Fiat, bfh, bh2u)
Fiat, bfh, bh2u, TxMinedInfo)
from .bitcoin import (COIN, TYPE_ADDRESS, is_address, address_to_script,
is_minikey, relayfee, dust_threshold)
from .version import *
@ -523,11 +523,11 @@ class Abstract_Wallet(AddressSynchronizer):
return ', '.join(labels)
return ''
def get_tx_status(self, tx_hash, tx_mined_status):
def get_tx_status(self, tx_hash, tx_mined_info: TxMinedInfo):
extra = []
height = tx_mined_status.height
conf = tx_mined_status.conf
timestamp = tx_mined_status.timestamp
height = tx_mined_info.height
conf = tx_mined_info.conf
timestamp = tx_mined_info.timestamp
if conf == 0:
tx = self.transactions.get(tx_hash)
if not tx:
@ -554,7 +554,7 @@ class Abstract_Wallet(AddressSynchronizer):
elif height == TX_HEIGHT_UNCONFIRMED:
status = 0
else:
status = 2
status = 2 # not SPV verified
else:
status = 3 + min(conf, 6)
time_str = format_time(timestamp) if timestamp else _("unknown")