Browse Source

qml: map fields of tx history

master
Sander van Grieken 5 years ago
parent
commit
a3801ecae8
  1. 3
      electrum/gui/qml/qeqr.py
  2. 32
      electrum/gui/qml/qewallet.py

3
electrum/gui/qml/qeqr.py

@ -24,7 +24,7 @@ class QEQR(QObject):
self.scan_ready_changed.emit() self.scan_ready_changed.emit()
pilimage = self.convertToPILImage(image) pilimage = self.convertToPILImage(image)
parseQR(pilimage) self.parseQR(pilimage)
self._ready = True self._ready = True
@ -50,6 +50,7 @@ class QEQR(QObject):
return Image.frombytes('RGBA', (image.width(), image.height()), buf2, 'raw') return Image.frombytes('RGBA', (image.width(), image.height()), buf2, 'raw')
def parseQR(self, image): def parseQR(self, image):
# TODO
pass pass
@pyqtProperty(bool, notify=scan_ready_changed) @pyqtProperty(bool, notify=scan_ready_changed)

32
electrum/gui/qml/qewallet.py

@ -1,7 +1,7 @@
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl
from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex, QByteArray
from electrum.util import register_callback from electrum.util import register_callback, Satoshis
from electrum.logging import get_logger from electrum.logging import get_logger
from electrum.wallet import Wallet, Abstract_Wallet from electrum.wallet import Wallet, Abstract_Wallet
@ -10,16 +10,35 @@ class QETransactionsListModel(QAbstractListModel):
super().__init__(parent) super().__init__(parent)
self.tx_history = [] self.tx_history = []
_logger = get_logger(__name__)
# define listmodel rolemap
ROLES=('txid','fee_sat','height','confirmations','timestamp','monotonic_timestamp','incoming','bc_value',
'bc_balance','date','label','txpos_in_block','fee','inputs','outputs')
keys = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(ROLES))
ROLENAMES = [bytearray(x.encode()) for x in ROLES]
_ROLE_MAP = dict(zip(keys, ROLENAMES))
def rowCount(self, index): def rowCount(self, index):
return len(self.tx_history) return len(self.tx_history)
def roleNames(self):
return self._ROLE_MAP
def data(self, index, role): def data(self, index, role):
if role == Qt.DisplayRole: tx = self.tx_history[index.row()]
return str(self.tx_history[index.row()]['bc_value']) role_index = role - (Qt.UserRole + 1)
value = tx[self.ROLES[role_index]]
if isinstance(value, bool) or isinstance(value, list) or isinstance(value, int) or value is None:
return value
if isinstance(value, Satoshis):
return value.value
return str(value)
def set_history(self, history): def set_history(self, history):
self.beginInsertRows(QModelIndex(), 0, len(history) - 1) self.beginInsertRows(QModelIndex(), 0, len(history) - 1)
self.tx_history = history self.tx_history = history
self.tx_history.reverse()
self.endInsertRows() self.endInsertRows()
class QEWallet(QObject): class QEWallet(QObject):
@ -39,5 +58,10 @@ class QEWallet(QObject):
def get_history(self): def get_history(self):
history = self.wallet.get_detailed_history(show_addresses = True) history = self.wallet.get_detailed_history(show_addresses = True)
txs = history['transactions'] txs = history['transactions']
self._logger.info(txs)
# use primitives
for tx in txs:
for output in tx['outputs']:
output['value'] = output['value'].value
self._historyModel.set_history(txs) self._historyModel.set_history(txs)

Loading…
Cancel
Save