From 3aed085021a91ba98a42728c46bba5fbd9c3258b Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 26 May 2025 09:39:11 +0000 Subject: [PATCH] proto.eth.tw.unspent: implement `get_column_widths()` in parent cls --- mmgen/proto/btc/tw/unspent.py | 2 ++ mmgen/proto/btc/tw/view.py | 15 ++++++++++++++- mmgen/proto/eth/tw/unspent.py | 29 ----------------------------- mmgen/tw/unspent.py | 21 +++++++++++++-------- mmgen/tw/view.py | 16 ++++++++++------ 5 files changed, 39 insertions(+), 44 deletions(-) diff --git a/mmgen/proto/btc/tw/unspent.py b/mmgen/proto/btc/tw/unspent.py index 24e94067..83927cc4 100755 --- a/mmgen/proto/btc/tw/unspent.py +++ b/mmgen/proto/btc/tw/unspent.py @@ -43,6 +43,8 @@ class BitcoinTwUnspentOutputs(BitcoinTwView, TwUnspentOutputs): has_age = True can_group = True + disp_spc = 5 + vout_w = 4 hdr_lbl = 'unspent outputs' desc = 'unspent outputs' item_desc = 'unspent output' diff --git a/mmgen/proto/btc/tw/view.py b/mmgen/proto/btc/tw/view.py index de15e1d1..40e5cdca 100755 --- a/mmgen/proto/btc/tw/view.py +++ b/mmgen/proto/btc/tw/view.py @@ -13,4 +13,17 @@ proto.btc.tw.view: Bitcoin base protocol base class for tracking wallet view cla """ class BitcoinTwView: - pass + + txid_w = 64 + txid_max_w = {'txid': 64} + txid_min_w = {'txid': 7} + txid_nice_w = {'txid': 12} + nice_addr_w = {'addr': 16} + + age_col_params = { + 'confs': (7, 'Confs'), + 'block': (8, 'Block'), + 'days': (6, 'Age(d)'), + 'date': (8, 'Date'), + 'date_time': (16, 'Date/Time'), + } diff --git a/mmgen/proto/eth/tw/unspent.py b/mmgen/proto/eth/tw/unspent.py index 173c393a..755c0d23 100755 --- a/mmgen/proto/eth/tw/unspent.py +++ b/mmgen/proto/eth/tw/unspent.py @@ -36,35 +36,6 @@ class EthereumTwUnspentOutputs(EthereumTwView, TwUnspentOutputs): item_desc = 'account' item_desc_pl = 'accounts' - def get_column_widths(self, data, *, wide, interactive): - # min screen width: 80 cols - # num addr [mmid] [comment] amt [amt2] - return self.compute_column_widths( - widths = { # fixed cols - 'num': max(2, len(str(len(data)))+1), - 'mmid': max(len(d.twmmid.disp) for d in data) if self.show_mmid else 0, - 'amt': self.amt_widths['amt'], - 'amt2': self.amt_widths.get('amt2', 0), - 'spc': (5 if self.show_mmid else 3) + self.has_amt2, # 5(3) spaces in fs - 'txid': 0, - 'vout': 0, - 'block': 0, - 'date': 0, - 'date_time': 0, - }, - maxws = { # expandable cols - 'addr': max(len(d.addr) for d in data), - 'comment': max(d.comment.screen_width for d in data) if self.show_mmid else 0, - }, - minws = { - 'addr': 10, - 'comment': len('Comment') if self.show_mmid else 0, - }, - maxws_nice = {'addr': 14} if self.show_mmid else {}, - wide = wide, - interactive = interactive, - ) - def do_sort(self, key=None, *, reverse=False): if key == 'txid': return diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index 5c020d81..1a8b4d30 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -39,6 +39,9 @@ class TwUnspentOutputs(TwView): has_age = False can_group = False show_mmid = True + hdr_lbl = 'tracked addresses' + desc = 'address balances' + item_desc = 'address' item_desc_pl = 'addresses' no_rpcdata_errmsg = """ No spendable outputs found! Import addresses with balances into your @@ -67,6 +70,8 @@ class TwUnspentOutputs(TwView): extra_key_mappings = { 'D':'i_addr_delete', 'R':'i_balance_refresh'} + disp_spc = 3 + vout_w = 0 class display_type(TwView.display_type): @@ -142,30 +147,30 @@ class TwUnspentOutputs(TwView): show_mmid = self.show_mmid or wide - # num txid vout addr [mmid] [comment] amt [amt2] date return self.compute_column_widths( widths = { # fixed cols 'num': max(2, len(str(len(data)))+1), - 'vout': 4, + 'txid': 0, + 'vout': self.vout_w, 'mmid': max(len(d.twmmid.disp) for d in data) if show_mmid else 0, 'amt': self.amt_widths['amt'], 'amt2': self.amt_widths.get('amt2', 0), 'block': self.age_col_params['block'][0] if wide else 0, 'date_time': self.age_col_params['date_time'][0] if wide else 0, 'date': self.age_w, - 'spc': 7 if show_mmid else 5, # 7(5) spaces in fs + 'spc': self.disp_spc + (2 * show_mmid) + self.has_amt2 }, maxws = { # expandable cols - 'txid': self.txid_w, 'addr': max(len(d.addr) for d in data), 'comment': max(d.comment.screen_width for d in data) if show_mmid else 0, - }, + } | self.txid_max_w, minws = { - 'txid': 7, 'addr': 10, 'comment': len('Comment') if show_mmid else 0, - }, - maxws_nice = {'txid':12, 'addr':16} if show_mmid else {'txid':12}, + } | self.txid_min_w, + maxws_nice = ( + self.nice_addr_w if show_mmid else {} + ) | self.txid_nice_w, wide = wide, interactive = interactive, ) diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index b73e2a21..69dccf97 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -87,7 +87,11 @@ class TwView(MMGenObject, metaclass=AsyncInit): group = False use_cached = False minconf = 1 - txid_w = 64 + txid_w = 0 + txid_max_w = {} + txid_min_w = {} + txid_nice_w = {} + nice_addr_w = {'addr': 14} sort_key = 'age' display_hdr = () display_body = () @@ -127,11 +131,11 @@ class TwView(MMGenObject, metaclass=AsyncInit): bch_addr_fmts = ('cashaddr', 'legacy') age_col_params = { - 'confs': (7, 'Confs'), - 'block': (8, 'Block'), - 'days': (6, 'Age(d)'), - 'date': (8, 'Date'), - 'date_time': (16, 'Date/Time'), + 'confs': (0, 'Confs'), + 'block': (0, 'Block'), + 'days': (0, 'Age(d)'), + 'date': (0, 'Date'), + 'date_time': (0, 'Date/Time'), } date_formatter = {