tw.view: improve gen_subheader(), col_hdr implementation
This commit is contained in:
parent
08d78d46ad
commit
65c0652ff5
4 changed files with 39 additions and 40 deletions
|
|
@ -23,7 +23,7 @@ class EthereumTwView(TwView):
|
|||
def get_disp_prec(self,wide):
|
||||
return self.proto.coin_amt.max_prec if wide else 8
|
||||
|
||||
def gen_subheader(self,color):
|
||||
def gen_subheader(self,cw,color):
|
||||
if self.disp_prec == 8:
|
||||
yield 'Balances truncated to 8 decimal points'
|
||||
if g.cached_balances:
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class TwAddresses(TwView):
|
|||
wide = wide,
|
||||
)
|
||||
|
||||
def gen_subheader(self,color):
|
||||
def gen_subheader(self,cw,color):
|
||||
if self.minconf:
|
||||
yield f'Displaying balances with at least {self.minconf} confirmation{suf(self.minconf)}'
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ class TwTxHistory(TwView):
|
|||
|
||||
class squeezed(TwView.display_type.squeezed):
|
||||
cols = ('num','txid','date','inputs','amt','outputs','comment')
|
||||
hdr_fmt_method = 'squeezed_hdr'
|
||||
subhdr_fmt_method = 'gen_squeezed_subheader'
|
||||
|
||||
class detail(TwView.display_type.detail):
|
||||
need_column_widths = False
|
||||
hdr_fmt_method = 'detail_hdr'
|
||||
subhdr_fmt_method = 'gen_detail_subheader'
|
||||
item_separator = '\n\n'
|
||||
|
||||
has_wallet = False
|
||||
|
|
@ -91,37 +91,32 @@ class TwTxHistory(TwView):
|
|||
|
||||
return self.compute_column_widths(widths,maxws,minws,maxws_nice,wide=wide)
|
||||
|
||||
def squeezed_hdr(self,cw,fs,color):
|
||||
def gen_squeezed_subheader(self,cw,color):
|
||||
if self.sinceblock:
|
||||
yield f'Displaying transactions since block {self.sinceblock.hl(color=color)}'
|
||||
yield 'Only wallet-related outputs are shown'
|
||||
yield 'Comment is from first wallet address in outputs or inputs'
|
||||
if (cw.inputs < self.varcol_maxwidths['inputs'] or
|
||||
cw.outputs < self.varcol_maxwidths['outputs'] ):
|
||||
yield 'Due to screen width limitations, not all addresses could be displayed'
|
||||
|
||||
def gen():
|
||||
if self.sinceblock:
|
||||
yield f'Displaying transactions since block {self.sinceblock.hl(color=color)}'
|
||||
yield 'Only wallet-related outputs are shown'
|
||||
yield 'Comment is from first wallet address in outputs or inputs'
|
||||
if (cw.inputs < self.varcol_maxwidths['inputs'] or
|
||||
cw.outputs < self.varcol_maxwidths['outputs'] ):
|
||||
yield 'Due to screen width limitations, not all addresses could be displayed'
|
||||
yield ''
|
||||
def gen_detail_subheader(self,cw,color):
|
||||
if self.sinceblock:
|
||||
yield f'Displaying transactions since block {self.sinceblock.hl(color=color)}'
|
||||
yield 'Only wallet-related outputs are shown'
|
||||
|
||||
yield fs.format(
|
||||
n = '',
|
||||
t = 'TxID',
|
||||
d = self.age_hdr,
|
||||
i = 'Inputs',
|
||||
A = 'Amt({})'.format('TX' if self.show_total_amt else 'Wallet'),
|
||||
o = 'Outputs',
|
||||
c = 'Comment' )
|
||||
def squeezed_col_hdr(self,cw,fs,color):
|
||||
return fs.format(
|
||||
n = '',
|
||||
t = 'TxID',
|
||||
d = self.age_hdr,
|
||||
i = 'Inputs',
|
||||
A = 'Amt({})'.format('TX' if self.show_total_amt else 'Wallet'),
|
||||
o = 'Outputs',
|
||||
c = 'Comment' )
|
||||
|
||||
return '\n'.join(gen())
|
||||
|
||||
def detail_hdr(self,cw,fs,color):
|
||||
|
||||
def gen():
|
||||
if self.sinceblock:
|
||||
yield f'Displaying transactions since block {self.sinceblock.hl(color=color)}'
|
||||
yield 'Only wallet-related outputs are shown'
|
||||
|
||||
return '\n'.join(gen()) + '\n\n'
|
||||
def detail_col_hdr(self,cw,fs,color):
|
||||
return ''
|
||||
|
||||
def gen_squeezed_display(self,data,cw,fs,color,fmt_method):
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ class TwView(MMGenObject,metaclass=AsyncInit):
|
|||
detail = False
|
||||
fmt_method = 'gen_squeezed_display'
|
||||
line_fmt_method = 'squeezed_format_line'
|
||||
hdr_fmt_method = 'squeezed_col_hdr'
|
||||
subhdr_fmt_method = 'gen_subheader'
|
||||
colhdr_fmt_method = 'squeezed_col_hdr'
|
||||
need_column_widths = True
|
||||
item_separator = '\n'
|
||||
print_header = '[screen print truncated to width {}]\n'
|
||||
|
|
@ -54,7 +55,8 @@ class TwView(MMGenObject,metaclass=AsyncInit):
|
|||
detail = True
|
||||
fmt_method = 'gen_detail_display'
|
||||
line_fmt_method = 'detail_format_line'
|
||||
hdr_fmt_method = 'detail_col_hdr'
|
||||
subhdr_fmt_method = 'gen_subheader'
|
||||
colhdr_fmt_method = 'detail_col_hdr'
|
||||
need_column_widths = True
|
||||
item_separator = '\n'
|
||||
print_header = ''
|
||||
|
|
@ -302,7 +304,7 @@ class TwView(MMGenObject,metaclass=AsyncInit):
|
|||
else:
|
||||
return do_ret(get_freews(self.cols,varws,varw,minw))
|
||||
|
||||
def gen_subheader(self,color):
|
||||
def gen_subheader(self,cw,color):
|
||||
return ()
|
||||
|
||||
def gen_footer(self,color):
|
||||
|
|
@ -348,12 +350,14 @@ class TwView(MMGenObject,metaclass=AsyncInit):
|
|||
if hasattr(self,'total'):
|
||||
yield 'Total {}: {}'.format( self.proto.dcoin, self.total.hl(color=color) )
|
||||
|
||||
yield from self.gen_subheader(color)
|
||||
yield from getattr(self,dt.subhdr_fmt_method)(cw,color)
|
||||
|
||||
yield ''
|
||||
|
||||
if data:
|
||||
yield getattr(self,dt.hdr_fmt_method)(cw,hdr_fs,color)
|
||||
res = getattr(self,dt.colhdr_fmt_method)(cw,hdr_fs,color)
|
||||
if res:
|
||||
yield res
|
||||
|
||||
self.disp_prec = self.get_disp_prec(wide=dt.detail)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue