From f0bbbe9955d2ccbfb410ce18de4ce086e295c8a0 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 25 Apr 2023 13:22:34 +0200 Subject: [PATCH] qml: consistency camelcase public slots listmodels --- electrum/gui/qml/components/Addresses.qml | 4 +- .../gui/qml/components/ChannelDetails.qml | 4 +- electrum/gui/qml/components/Invoices.qml | 4 +- .../gui/qml/components/OpenChannelDialog.qml | 2 +- .../controls/HistoryItemDelegate.qml | 4 +- electrum/gui/qml/qeaddresslistmodel.py | 6 +-- electrum/gui/qml/qechannellistmodel.py | 10 ++-- electrum/gui/qml/qeinvoicelistmodel.py | 4 +- electrum/gui/qml/qeserverlistmodel.py | 10 ++-- electrum/gui/qml/qetransactionlistmodel.py | 46 +++++++++---------- electrum/gui/qml/qewallet.py | 12 ++--- 11 files changed, 53 insertions(+), 53 deletions(-) diff --git a/electrum/gui/qml/components/Addresses.qml b/electrum/gui/qml/components/Addresses.qml index 935b5710d..91d7e20be 100644 --- a/electrum/gui/qml/components/Addresses.qml +++ b/electrum/gui/qml/components/Addresses.qml @@ -36,7 +36,7 @@ Pane { var page = app.stack.push(Qt.resolvedUrl('AddressDetails.qml'), {'address': model.address}) page.addressDetailsChanged.connect(function() { // update listmodel when details change - listview.model.update_address(model.address) + listview.model.updateAddress(model.address) }) } } @@ -74,6 +74,6 @@ Pane { } Component.onCompleted: { - Daemon.currentWallet.addressModel.init_model() + Daemon.currentWallet.addressModel.initModel() } } diff --git a/electrum/gui/qml/components/ChannelDetails.qml b/electrum/gui/qml/components/ChannelDetails.qml index e614f0246..9c386ef72 100644 --- a/electrum/gui/qml/components/ChannelDetails.qml +++ b/electrum/gui/qml/components/ChannelDetails.qml @@ -290,8 +290,8 @@ Pane { dialog.accepted.connect(function() { channeldetails.deleteChannel() app.stack.pop() - Daemon.currentWallet.historyModel.init_model(true) // needed here? - Daemon.currentWallet.channelModel.remove_channel(channelid) + Daemon.currentWallet.historyModel.initModel(true) // needed here? + Daemon.currentWallet.channelModel.removeChannel(channelid) }) dialog.open() } diff --git a/electrum/gui/qml/components/Invoices.qml b/electrum/gui/qml/components/Invoices.qml index 9d7bc6086..d947aa84e 100644 --- a/electrum/gui/qml/components/Invoices.qml +++ b/electrum/gui/qml/components/Invoices.qml @@ -52,7 +52,7 @@ Pane { onClicked: { var dialog = app.stack.getRoot().openInvoice(model.key) dialog.invoiceAmountChanged.connect(function () { - Daemon.currentWallet.invoiceModel.init_model() + Daemon.currentWallet.invoiceModel.initModel() }) listview.currentIndex = -1 } @@ -106,7 +106,7 @@ Pane { onClicked: { var dialog = app.stack.getRoot().openInvoice(listview.currentItem.getKey()) dialog.invoiceAmountChanged.connect(function () { - Daemon.currentWallet.invoiceModel.init_model() + Daemon.currentWallet.invoiceModel.initModel() }) } } diff --git a/electrum/gui/qml/components/OpenChannelDialog.qml b/electrum/gui/qml/components/OpenChannelDialog.qml index 5ef5a2fcc..8c3e13816 100644 --- a/electrum/gui/qml/components/OpenChannelDialog.qml +++ b/electrum/gui/qml/components/OpenChannelDialog.qml @@ -252,7 +252,7 @@ ElDialog { + qsTr('This channel will be usable after %1 confirmations').arg(min_depth) if (!tx_complete) { message = message + '\n\n' + qsTr('Please sign and broadcast the funding transaction.') - channelopener.wallet.historyModel.init_model(true) // local tx doesn't trigger model update + channelopener.wallet.historyModel.initModel(true) // local tx doesn't trigger model update } app.channelOpenProgressDialog.state = 'success' app.channelOpenProgressDialog.info = message diff --git a/electrum/gui/qml/components/controls/HistoryItemDelegate.qml b/electrum/gui/qml/components/controls/HistoryItemDelegate.qml index 28e26cfcc..3eec740b3 100644 --- a/electrum/gui/qml/components/controls/HistoryItemDelegate.qml +++ b/electrum/gui/qml/components/controls/HistoryItemDelegate.qml @@ -27,13 +27,13 @@ Item { var page = app.stack.push(Qt.resolvedUrl('../LightningPaymentDetails.qml'), {'key': model.key}) page.detailsChanged.connect(function() { // update listmodel when details change - visualModel.model.update_tx_label(model.key, page.label) + visualModel.model.updateTxLabel(model.key, page.label) }) } else { var page = app.stack.push(Qt.resolvedUrl('../TxDetails.qml'), {'txid': model.key}) page.detailsChanged.connect(function() { // update listmodel when details change - visualModel.model.update_tx_label(model.key, page.label) + visualModel.model.updateTxLabel(model.key, page.label) }) } } diff --git a/electrum/gui/qml/qeaddresslistmodel.py b/electrum/gui/qml/qeaddresslistmodel.py index 29c2cb900..5ecf18975 100644 --- a/electrum/gui/qml/qeaddresslistmodel.py +++ b/electrum/gui/qml/qeaddresslistmodel.py @@ -25,7 +25,7 @@ class QEAddressListModel(QAbstractListModel): super().__init__(parent) self.wallet = wallet self.setDirty() - self.init_model() + self.initModel() def rowCount(self, index): return len(self.receive_addresses) + len(self.change_addresses) @@ -68,7 +68,7 @@ class QEAddressListModel(QAbstractListModel): # initial model data @pyqtSlot() - def init_model(self): + def initModel(self): if not self._dirty: return @@ -97,7 +97,7 @@ class QEAddressListModel(QAbstractListModel): self._dirty = False @pyqtSlot(str) - def update_address(self, address): + def updateAddress(self, address): for i, a in enumerate(itertools.chain(self.receive_addresses, self.change_addresses)): if a['address'] == address: self.do_update(i,a) diff --git a/electrum/gui/qml/qechannellistmodel.py b/electrum/gui/qml/qechannellistmodel.py index 52582bf81..a58019f8f 100644 --- a/electrum/gui/qml/qechannellistmodel.py +++ b/electrum/gui/qml/qechannellistmodel.py @@ -27,7 +27,7 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): def __init__(self, wallet, parent=None): super().__init__(parent) self.wallet = wallet - self.init_model() + self.initModel() # To avoid leaking references to "self" that prevent the # window from being GC-ed when closed, callbacks should be @@ -44,7 +44,7 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): @qt_event_listener def on_event_channels_updated(self, wallet): if wallet == self.wallet: - self.init_model() + self.initModel() def on_destroy(self): self.unregister_callbacks() @@ -108,7 +108,7 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): return sum([1 if x['state_code'] == ChannelState.OPEN else 0 for x in self.channels]) @pyqtSlot() - def init_model(self): + def initModel(self): self._logger.debug('init_model') if not self.wallet.lnworker: self._logger.warning('lnworker should be defined') @@ -149,7 +149,7 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): self.numOpenChannelsChanged.emit() @pyqtSlot(str) - def new_channel(self, cid): + def newChannel(self, cid): self._logger.debug('new channel with cid %s' % cid) lnchannels = self.wallet.lnworker.channels for channel in lnchannels.values(): @@ -163,7 +163,7 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): return @pyqtSlot(str) - def remove_channel(self, cid): + def removeChannel(self, cid): self._logger.debug('remove channel with cid %s' % cid) for i, channel in enumerate(self.channels): if cid == channel['cid']: diff --git a/electrum/gui/qml/qeinvoicelistmodel.py b/electrum/gui/qml/qeinvoicelistmodel.py index 551b17d0c..ca017836c 100644 --- a/electrum/gui/qml/qeinvoicelistmodel.py +++ b/electrum/gui/qml/qeinvoicelistmodel.py @@ -35,7 +35,7 @@ class QEAbstractInvoiceListModel(QAbstractListModel): self._timer.timeout.connect(self.updateStatusStrings) try: - self.init_model() + self.initModel() except Exception as e: self._logger.error(f'{repr(e)}') raise e @@ -63,7 +63,7 @@ class QEAbstractInvoiceListModel(QAbstractListModel): self.endResetModel() @pyqtSlot() - def init_model(self): + def initModel(self): invoices = [] for invoice in self.get_invoice_list(): item = self.invoice_to_model(invoice) diff --git a/electrum/gui/qml/qeserverlistmodel.py b/electrum/gui/qml/qeserverlistmodel.py index 97a635b85..b5733d0bd 100644 --- a/electrum/gui/qml/qeserverlistmodel.py +++ b/electrum/gui/qml/qeserverlistmodel.py @@ -26,24 +26,24 @@ class QEServerListModel(QAbstractListModel, QtEventListener): self._chaintips = 0 self.network = network - self.init_model() + self.initModel() self.register_callbacks() self.destroyed.connect(lambda: self.unregister_callbacks()) @qt_event_listener def on_event_network_updated(self): self._logger.info(f'network updated') - self.init_model() + self.initModel() @qt_event_listener def on_event_blockchain_updated(self): self._logger.info(f'blockchain updated') - self.init_model() + self.initModel() @qt_event_listener def on_event_default_server_changed(self): self._logger.info(f'default server changed') - self.init_model() + self.initModel() def rowCount(self, index): return len(self.servers) @@ -81,7 +81,7 @@ class QEServerListModel(QAbstractListModel, QtEventListener): return chains @pyqtSlot() - def init_model(self): + def initModel(self): self.clear() servers = [] diff --git a/electrum/gui/qml/qetransactionlistmodel.py b/electrum/gui/qml/qetransactionlistmodel.py index 24af49ede..9ae055970 100644 --- a/electrum/gui/qml/qetransactionlistmodel.py +++ b/electrum/gui/qml/qetransactionlistmodel.py @@ -36,10 +36,10 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): self.register_callbacks() self.destroyed.connect(lambda: self.on_destroy()) - self.requestRefresh.connect(lambda: self.init_model()) + self.requestRefresh.connect(lambda: self.initModel()) self.setDirty() - self.init_model() + self.initModel() def on_destroy(self): self.unregister_callbacks() @@ -60,6 +60,25 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): self._update_future_txitem(i) return + @qt_event_listener + def on_event_fee_histogram(self, histogram): + self._logger.debug(f'fee histogram updated') + for i, tx_item in enumerate(self.tx_history): + if 'height' not in tx_item: # filter to on-chain + continue + if tx_item['confirmations'] > 0: # filter out already mined + continue + txid = tx_item['txid'] + tx = self.wallet.db.get_transaction(txid) + if not tx: + continue + txinfo = self.wallet.get_tx_info(tx) + status, status_str = self.wallet.get_tx_status(txid, txinfo.tx_mined_status) + tx_item['date'] = status_str + index = self.index(i, 0) + roles = [self._ROLE_RMAP['date']] + self.dataChanged.emit(index, index, roles) + def rowCount(self, index): return len(self.tx_history) @@ -180,7 +199,7 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): # initial model data @pyqtSlot() @pyqtSlot(bool) - def init_model(self, force: bool = False): + def initModel(self, force: bool = False): # only (re)construct if dirty or forced if not self._dirty and not force: return @@ -237,7 +256,7 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): self.dataChanged.emit(index, index, roles) @pyqtSlot(str, str) - def update_tx_label(self, key, label): + def updateTxLabel(self, key, label): for i, tx in enumerate(self.tx_history): if tx['key'] == key: tx['label'] = label @@ -257,22 +276,3 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): self.dataChanged.emit(index, index, roles) elif tx_item['height'] in (TX_HEIGHT_FUTURE, TX_HEIGHT_LOCAL): self._update_future_txitem(i) - - @qt_event_listener - def on_event_fee_histogram(self, histogram): - self._logger.debug(f'fee histogram updated') - for i, tx_item in enumerate(self.tx_history): - if 'height' not in tx_item: # filter to on-chain - continue - if tx_item['confirmations'] > 0: # filter out already mined - continue - txid = tx_item['txid'] - tx = self.wallet.db.get_transaction(txid) - if not tx: - continue - txinfo = self.wallet.get_tx_info(tx) - status, status_str = self.wallet.get_tx_status(txid, txinfo.tx_mined_status) - tx_item['date'] = status_str - index = self.index(i, 0) - roles = [self._ROLE_RMAP['date']] - self.dataChanged.emit(index, index, roles) diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index 6eb7cb5ed..f26e7b85b 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -168,7 +168,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): # TODO: only update if it was paid over lightning, # and even then, we can probably just add the payment instead # of recreating the whole history (expensive) - self.historyModel.init_model(True) + self.historyModel.initModel(True) @event_listener def on_event_invoice_status(self, wallet, key, status): @@ -196,7 +196,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): if wallet == self.wallet: self._logger.info(f'removed transaction {tx.txid()}') self.addressModel.setDirty() - self.historyModel.init_model(True) #setDirty() + self.historyModel.initModel(True) #setDirty() self.balanceChanged.emit() @qt_event_listener @@ -206,7 +206,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): self.balanceChanged.emit() self.synchronizing = not wallet.is_up_to_date() if not self.synchronizing: - self.historyModel.init_model() # refresh if dirty + self.historyModel.initModel() # refresh if dirty @event_listener def on_event_channel(self, wallet, channel): @@ -224,7 +224,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): def on_event_payment_succeeded(self, wallet, key): if wallet == self.wallet: self.paymentSucceeded.emit(key) - self.historyModel.init_model(True) # TODO: be less dramatic + self.historyModel.initModel(True) # TODO: be less dramatic @event_listener def on_event_payment_failed(self, wallet, key, reason): @@ -527,7 +527,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): self.broadcast(tx) else: # not broadcasted, so refresh history here - self.historyModel.init_model(True) + self.historyModel.initModel(True) return True @@ -589,7 +589,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): return self.wallet.save_db() self.saveTxSuccess.emit(tx.txid()) - self.historyModel.init_model(True) + self.historyModel.initModel(True) return True except AddTransactionException as e: self.saveTxError.emit(tx.txid(), 'error', str(e))