Browse Source

qt AddressDialog: separate parent and window

master
SomberNight 3 years ago
parent
commit
53ca75d878
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 24
      electrum/gui/qt/address_dialog.py
  2. 3
      electrum/gui/qt/custom_model.py
  3. 38
      electrum/gui/qt/history_list.py
  4. 4
      electrum/gui/qt/main_window.py

24
electrum/gui/qt/address_dialog.py

@ -38,8 +38,8 @@ if TYPE_CHECKING:
class AddressHistoryModel(HistoryModel):
def __init__(self, parent: 'ElectrumWindow', address):
super().__init__(parent)
def __init__(self, window: 'ElectrumWindow', address):
super().__init__(window)
self.address = address
def get_domain(self):
@ -51,13 +51,15 @@ class AddressHistoryModel(HistoryModel):
class AddressDialog(WindowModalDialog):
def __init__(self, parent: 'ElectrumWindow', address: str):
def __init__(self, window: 'ElectrumWindow', address: str, *, parent=None):
if parent is None:
parent = window
WindowModalDialog.__init__(self, parent, _("Address"))
self.address = address
self.parent = parent
self.config = parent.config
self.wallet = parent.wallet
self.app = parent.app
self.window = window
self.config = window.config
self.wallet = window.wallet
self.app = window.app
self.saved = True
self.setMinimumWidth(700)
@ -101,18 +103,18 @@ class AddressDialog(WindowModalDialog):
vbox.addWidget(der_path_e)
vbox.addWidget(QLabel(_("History")))
addr_hist_model = AddressHistoryModel(self.parent, self.address)
self.hw = HistoryList(self.parent, addr_hist_model)
addr_hist_model = AddressHistoryModel(self.window, self.address)
self.hw = HistoryList(self.window, addr_hist_model)
addr_hist_model.set_view(self.hw)
vbox.addWidget(self.hw)
vbox.addLayout(Buttons(CloseButton(self)))
self.format_amount = self.parent.format_amount
self.format_amount = self.window.format_amount
addr_hist_model.refresh('address dialog constructor')
def show_qr(self):
text = self.address
try:
self.parent.show_qrcode(text, 'Address', parent=self)
self.window.show_qrcode(text, 'Address', parent=self)
except Exception as e:
self.show_message(repr(e))

3
electrum/gui/qt/custom_model.py

@ -3,9 +3,10 @@
from PyQt5 import QtCore, QtWidgets
class CustomNode:
def __init__(self, model, data):
def __init__(self, model: 'CustomModel', data):
self.model = model
self._data = data
self._children = []

38
electrum/gui/qt/history_list.py

@ -116,12 +116,14 @@ def get_item_key(tx_item):
class HistoryNode(CustomNode):
model: 'HistoryModel'
def get_data_for_role(self, index: QModelIndex, role: Qt.ItemDataRole) -> QVariant:
# note: this method is performance-critical.
# it is called a lot, and so must run extremely fast.
assert index.isValid()
col = index.column()
window = self.model.parent
window = self.model.window
tx_item = self.get_data()
is_lightning = tx_item.get('lightning', False)
timestamp = tx_item['timestamp']
@ -228,10 +230,10 @@ class HistoryNode(CustomNode):
class HistoryModel(CustomModel, Logger):
def __init__(self, parent: 'ElectrumWindow'):
CustomModel.__init__(self, parent, len(HistoryColumns))
def __init__(self, window: 'ElectrumWindow'):
CustomModel.__init__(self, window, len(HistoryColumns))
Logger.__init__(self)
self.parent = parent
self.window = window
self.view = None # type: HistoryList
self.transactions = OrderedDictWithIndex()
self.tx_status_cache = {} # type: Dict[str, Tuple[int, str]]
@ -244,14 +246,14 @@ class HistoryModel(CustomModel, Logger):
def update_label(self, index):
tx_item = index.internalPointer().get_data()
tx_item['label'] = self.parent.wallet.get_label_for_txid(get_item_key(tx_item))
tx_item['label'] = self.window.wallet.get_label_for_txid(get_item_key(tx_item))
topLeft = bottomRight = self.createIndex(index.row(), HistoryColumns.DESCRIPTION)
self.dataChanged.emit(topLeft, bottomRight, [Qt.DisplayRole])
self.parent.utxo_list.update()
self.window.utxo_list.update()
def get_domain(self):
"""Overridden in address_dialog.py"""
return self.parent.wallet.get_addresses()
return self.window.wallet.get_addresses()
def should_include_lightning_payments(self) -> bool:
"""Overridden in address_dialog.py"""
@ -260,7 +262,7 @@ class HistoryModel(CustomModel, Logger):
@profiler
def refresh(self, reason: str):
self.logger.info(f"refreshing... reason: {reason}")
assert self.parent.gui_thread == threading.current_thread(), 'must be called from GUI thread'
assert self.window.gui_thread == threading.current_thread(), 'must be called from GUI thread'
assert self.view, 'view not set'
if self.view.maybe_defer_update():
return
@ -268,12 +270,12 @@ class HistoryModel(CustomModel, Logger):
selected_row = None
if selected:
selected_row = selected.row()
fx = self.parent.fx
fx = self.window.fx
if fx: fx.history_used_spot = False
wallet = self.parent.wallet
wallet = self.window.wallet
self.set_visibility_of_columns()
transactions = wallet.get_full_history(
self.parent.fx,
self.window.fx,
onchain_domain=self.get_domain(),
include_lightning=self.should_include_lightning_payments())
if transactions == self.transactions:
@ -347,7 +349,7 @@ class HistoryModel(CustomModel, Logger):
for txid, tx_item in self.transactions.items():
if not tx_item.get('lightning', False):
tx_mined_info = self.tx_mined_info_from_tx_item(tx_item)
self.tx_status_cache[txid] = self.parent.wallet.get_tx_status(txid, tx_mined_info)
self.tx_status_cache[txid] = self.window.wallet.get_tx_status(txid, tx_mined_info)
def set_visibility_of_columns(self):
def set_visible(col: int, b: bool):
@ -355,8 +357,8 @@ class HistoryModel(CustomModel, Logger):
# txid
set_visible(HistoryColumns.TXID, False)
# fiat
history = self.parent.fx.show_history()
cap_gains = self.parent.fx.get_history_capital_gains_config()
history = self.window.fx.show_history()
cap_gains = self.window.fx.get_history_capital_gains_config()
set_visible(HistoryColumns.FIAT_VALUE, history)
set_visible(HistoryColumns.FIAT_ACQ_PRICE, history and cap_gains)
set_visible(HistoryColumns.FIAT_CAP_GAINS, history and cap_gains)
@ -366,8 +368,8 @@ class HistoryModel(CustomModel, Logger):
txid = tx_item['txid']
fee = tx_item.get('fee')
value = tx_item['value'].value
fiat_fields = self.parent.wallet.get_tx_item_fiat(
tx_hash=txid, amount_sat=value, fx=self.parent.fx, tx_fee=fee.value if fee else None)
fiat_fields = self.window.wallet.get_tx_item_fiat(
tx_hash=txid, amount_sat=value, fx=self.window.fx, tx_fee=fee.value if fee else None)
tx_item.update(fiat_fields)
self.dataChanged.emit(idx, idx, [Qt.DisplayRole, Qt.ForegroundRole])
@ -377,7 +379,7 @@ class HistoryModel(CustomModel, Logger):
tx_item = self.transactions[tx_hash]
except KeyError:
return
self.tx_status_cache[tx_hash] = self.parent.wallet.get_tx_status(tx_hash, tx_mined_info)
self.tx_status_cache[tx_hash] = self.window.wallet.get_tx_status(tx_hash, tx_mined_info)
tx_item.update({
'confirmations': tx_mined_info.conf,
'timestamp': tx_mined_info.timestamp,
@ -402,7 +404,7 @@ class HistoryModel(CustomModel, Logger):
assert orientation == Qt.Horizontal
if role != Qt.DisplayRole:
return None
fx = self.parent.fx
fx = self.window.fx
fiat_title = 'n/a fiat value'
fiat_acq_title = 'n/a fiat acquisition price'
fiat_cg_title = 'n/a fiat capital gains'

4
electrum/gui/qt/main_window.py

@ -1060,9 +1060,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
l.show_toolbar(toolbar_shown)
return tab
def show_address(self, addr):
def show_address(self, addr: str, *, parent: QWidget = None):
from . import address_dialog
d = address_dialog.AddressDialog(self, addr)
d = address_dialog.AddressDialog(self, addr, parent=parent)
d.exec_()
def show_channel_details(self, chan):

Loading…
Cancel
Save