From 9800e67dea59077c2fd5a101133495c6cd6c6b24 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 1 Dec 2022 12:32:32 +0000 Subject: [PATCH] tw.view: new `squeezed_format_line`, `detail_format_line` methods --- mmgen/tw/addresses.py | 55 ++++++++++++++++++++----------------------- mmgen/tw/txhistory.py | 4 ++-- mmgen/tw/unspent.py | 4 ++-- mmgen/tw/view.py | 13 ++++++---- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index 390cd4c2..19541fdf 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -40,9 +40,11 @@ class TwAddresses(TwView): class squeezed(TwView.display_type.squeezed): cols = ('num','mmid','used','addr','comment','amt','date') + fmt_method = 'gen_display' class detail(TwView.display_type.detail): cols = ('num','mmid','used','addr','comment','amt','block','date_time') + fmt_method = 'gen_display' class TwAddress(MMGenListItem): valid_attrs = {'twmmid','addr','al_id','confs','comment','amt','recvd','date','skip'} @@ -176,7 +178,29 @@ class TwAddresses(TwView): b = 'Block', D = 'Date/Time' ) - def gen_squeezed_display(self,data,cw,fs,color): + def squeezed_format_line(self,n,d,cw,fs,color,yes,no): + return fs.format( + n = str(n) + ')', + m = d.twmmid.fmt( width=cw.mmid, color=color ), + u = yes if d.recvd else no, + a = d.addr.fmt( color=color, width=cw.addr ), + c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ), + A = d.amt.fmt( color=color, iwidth=cw.iwidth, prec=self.disp_prec ), + d = self.age_disp( d, self.age_fmt ) + ) + + def detail_format_line(self,n,d,cw,fs,color,yes,no): + return fs.format( + n = str(n) + ')', + m = d.twmmid.fmt( width=cw.mmid, color=color ), + u = yes if d.recvd else no, + a = d.addr.fmt( color=color, width=cw.addr ), + c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ), + A = d.amt.fmt( color=color, iwidth=cw.iwidth, prec=self.disp_prec ), + b = self.age_disp( d, 'block' ), + D = self.age_disp( d, 'date_time' )) + + def gen_display(self,data,cw,fs,color,fmt_method): yes,no = (red('Yes '),green('No ')) if color else ('Yes ','No ') id_save = data[0].al_id @@ -185,34 +209,7 @@ class TwAddresses(TwView): if id_save != d.al_id: id_save = d.al_id yield '' - yield fs.format( - n = str(n) + ')', - m = d.twmmid.fmt( width=cw.mmid, color=color ), - u = yes if d.recvd else no, - a = d.addr.fmt( color=color, width=cw.addr ), - c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ), - A = d.amt.fmt( color=color, iwidth=cw.iwidth, prec=self.disp_prec ), - d = self.age_disp( d, self.age_fmt ) - ) - - def gen_detail_display(self,data,cw,fs,color): - - yes,no = (red('Yes '),green('No ')) if color else ('Yes ','No ') - id_save = data[0].al_id - - for n,d in enumerate(data,1): - if id_save != d.al_id: - id_save = d.al_id - yield '' - yield fs.format( - n = str(n) + ')', - m = d.twmmid.fmt( width=cw.mmid, color=color ), - u = yes if d.recvd else no, - a = d.addr.fmt( color=color, width=cw.addr ), - c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ), - A = d.amt.fmt( color=color, iwidth=cw.iwidth, prec=self.disp_prec ), - b = self.age_disp( d, 'block' ), - D = self.age_disp( d, 'date_time' )) + yield fmt_method(n,d,cw,fs,color,yes,no) async def set_dates(self,addrs): if not self.dates_set: diff --git a/mmgen/tw/txhistory.py b/mmgen/tw/txhistory.py index 3e9061fa..5e1d8837 100755 --- a/mmgen/tw/txhistory.py +++ b/mmgen/tw/txhistory.py @@ -123,7 +123,7 @@ class TwTxHistory(TwView): return '\n'.join(gen()) + '\n\n' - def gen_squeezed_display(self,data,cw,fs,color): + def gen_squeezed_display(self,data,cw,fs,color,fmt_method): for n,d in enumerate(data,1): yield fs.format( @@ -135,7 +135,7 @@ class TwTxHistory(TwView): o = d.vouts_disp( 'outputs', width=cw.outputs, color=color ), c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ) ) - def gen_detail_display(self,data,cw,fs,color): + def gen_detail_display(self,data,cw,fs,color,fmt_method): fs = fmt(""" {n} diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index 44f418d2..c639f4b3 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -178,7 +178,7 @@ class TwUnspentOutputs(TwView): D = 'Date/Time', c = 'Comment' ) - def gen_squeezed_display(self,data,cw,fs,color): + def gen_squeezed_display(self,data,cw,fs,color,fmt_method): for n,d in enumerate(data): yield fs.format( @@ -196,7 +196,7 @@ class TwUnspentOutputs(TwView): d = self.age_disp(d,self.age_fmt), ) - def gen_detail_display(self,data,cw,fs,color): + def gen_detail_display(self,data,cw,fs,color,fmt_method): for n,d in enumerate(data): yield fs.format( diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index e11222fa..85fafcdd 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -39,6 +39,7 @@ class TwView(MMGenObject,metaclass=AsyncInit): class squeezed: detail = False fmt_method = 'gen_squeezed_display' + line_fmt_method = 'squeezed_format_line' hdr_fmt_method = 'squeezed_col_hdr' need_column_widths = True item_separator = '\n' @@ -47,6 +48,7 @@ class TwView(MMGenObject,metaclass=AsyncInit): class detail: detail = True fmt_method = 'gen_detail_display' + line_fmt_method = 'detail_format_line' hdr_fmt_method = 'detail_col_hdr' need_column_widths = True item_separator = '\n' @@ -56,8 +58,8 @@ class TwView(MMGenObject,metaclass=AsyncInit): class print: color = False - def do(method,data,cw,fs,color): - return [l.rstrip() for l in method(data,cw,fs,color)] + def do(method,data,cw,fs,color,fmt_method): + return [l.rstrip() for l in method(data,cw,fs,color,fmt_method)] has_wallet = True has_amt2 = False @@ -121,6 +123,9 @@ class TwView(MMGenObject,metaclass=AsyncInit): Please resize your screen to at least {} characters and hit any key: """ + squeezed_format_line = None + detail_format_line = None + def __new__(cls,proto,*args,**kwargs): return MMGenObject.__new__(proto.base_proto_subclass(cls,cls.mod_subpath)) @@ -357,9 +362,9 @@ class TwView(MMGenObject,metaclass=AsyncInit): def get_body(method): if line_processing: - return lp_cls.do(method,data,cw,fs,color) + return lp_cls.do(method,data,cw,fs,color,getattr(self,dt.line_fmt_method)) else: - return method(data,cw,fs,color) + return method(data,cw,fs,color,getattr(self,dt.line_fmt_method)) self._display_data[display_type] = '{a}{b}\n{c}{d}\n'.format( a = self.header(color),