Browse Source

tw.view: new `squeezed_format_line`, `detail_format_line` methods

The MMGen Project 2 years ago
parent
commit
9800e67dea
4 changed files with 37 additions and 35 deletions
  1. 24 27
      mmgen/tw/addresses.py
  2. 2 2
      mmgen/tw/txhistory.py
  3. 2 2
      mmgen/tw/unspent.py
  4. 9 4
      mmgen/tw/view.py

+ 24 - 27
mmgen/tw/addresses.py

@@ -40,9 +40,11 @@ class TwAddresses(TwView):
 
 
 		class squeezed(TwView.display_type.squeezed):
 		class squeezed(TwView.display_type.squeezed):
 			cols = ('num','mmid','used','addr','comment','amt','date')
 			cols = ('num','mmid','used','addr','comment','amt','date')
+			fmt_method = 'gen_display'
 
 
 		class detail(TwView.display_type.detail):
 		class detail(TwView.display_type.detail):
 			cols = ('num','mmid','used','addr','comment','amt','block','date_time')
 			cols = ('num','mmid','used','addr','comment','amt','block','date_time')
+			fmt_method = 'gen_display'
 
 
 	class TwAddress(MMGenListItem):
 	class TwAddress(MMGenListItem):
 		valid_attrs = {'twmmid','addr','al_id','confs','comment','amt','recvd','date','skip'}
 		valid_attrs = {'twmmid','addr','al_id','confs','comment','amt','recvd','date','skip'}
@@ -176,26 +178,29 @@ class TwAddresses(TwView):
 			b  = 'Block',
 			b  = 'Block',
 			D  = 'Date/Time' )
 			D  = 'Date/Time' )
 
 
-	def gen_squeezed_display(self,data,cw,fs,color):
-
-		yes,no = (red('Yes '),green('No  ')) if color else ('Yes ','No  ')
-		id_save = data[0].al_id
+	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 )
+		)
 
 
-		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 ),
-				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_detail_display(self,data,cw,fs,color):
+	def gen_display(self,data,cw,fs,color,fmt_method):
 
 
 		yes,no = (red('Yes '),green('No  ')) if color else ('Yes ','No  ')
 		yes,no = (red('Yes '),green('No  ')) if color else ('Yes ','No  ')
 		id_save = data[0].al_id
 		id_save = data[0].al_id
@@ -204,15 +209,7 @@ class TwAddresses(TwView):
 			if id_save != d.al_id:
 			if id_save != d.al_id:
 				id_save = d.al_id
 				id_save = d.al_id
 				yield ''
 				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):
 	async def set_dates(self,addrs):
 		if not self.dates_set:
 		if not self.dates_set:

+ 2 - 2
mmgen/tw/txhistory.py

@@ -123,7 +123,7 @@ class TwTxHistory(TwView):
 
 
 		return '\n'.join(gen()) + '\n\n'
 		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):
 		for n,d in enumerate(data,1):
 			yield fs.format(
 			yield fs.format(
@@ -135,7 +135,7 @@ class TwTxHistory(TwView):
 				o = d.vouts_disp( 'outputs', width=cw.outputs, color=color ),
 				o = d.vouts_disp( 'outputs', width=cw.outputs, color=color ),
 				c = d.comment.fmt( width=cw.comment, color=color, nullrepl='-' ) )
 				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("""
 		fs = fmt("""
 		{n}
 		{n}

+ 2 - 2
mmgen/tw/unspent.py

@@ -178,7 +178,7 @@ class TwUnspentOutputs(TwView):
 			D = 'Date/Time',
 			D = 'Date/Time',
 			c = 'Comment' )
 			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):
 		for n,d in enumerate(data):
 			yield fs.format(
 			yield fs.format(
@@ -196,7 +196,7 @@ class TwUnspentOutputs(TwView):
 				d = self.age_disp(d,self.age_fmt),
 				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):
 		for n,d in enumerate(data):
 			yield fs.format(
 			yield fs.format(

+ 9 - 4
mmgen/tw/view.py

@@ -39,6 +39,7 @@ class TwView(MMGenObject,metaclass=AsyncInit):
 		class squeezed:
 		class squeezed:
 			detail = False
 			detail = False
 			fmt_method = 'gen_squeezed_display'
 			fmt_method = 'gen_squeezed_display'
+			line_fmt_method = 'squeezed_format_line'
 			hdr_fmt_method = 'squeezed_col_hdr'
 			hdr_fmt_method = 'squeezed_col_hdr'
 			need_column_widths = True
 			need_column_widths = True
 			item_separator = '\n'
 			item_separator = '\n'
@@ -47,6 +48,7 @@ class TwView(MMGenObject,metaclass=AsyncInit):
 		class detail:
 		class detail:
 			detail = True
 			detail = True
 			fmt_method = 'gen_detail_display'
 			fmt_method = 'gen_detail_display'
+			line_fmt_method = 'detail_format_line'
 			hdr_fmt_method = 'detail_col_hdr'
 			hdr_fmt_method = 'detail_col_hdr'
 			need_column_widths = True
 			need_column_widths = True
 			item_separator = '\n'
 			item_separator = '\n'
@@ -56,8 +58,8 @@ class TwView(MMGenObject,metaclass=AsyncInit):
 
 
 		class print:
 		class print:
 			color = False
 			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_wallet  = True
 	has_amt2    = False
 	has_amt2    = False
@@ -121,6 +123,9 @@ class TwView(MMGenObject,metaclass=AsyncInit):
 		Please resize your screen to at least {} characters and hit any key:
 		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):
 	def __new__(cls,proto,*args,**kwargs):
 		return MMGenObject.__new__(proto.base_proto_subclass(cls,cls.mod_subpath))
 		return MMGenObject.__new__(proto.base_proto_subclass(cls,cls.mod_subpath))
 
 
@@ -357,9 +362,9 @@ class TwView(MMGenObject,metaclass=AsyncInit):
 
 
 			def get_body(method):
 			def get_body(method):
 				if line_processing:
 				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:
 				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(
 			self._display_data[display_type] = '{a}{b}\n{c}{d}\n'.format(
 				a = self.header(color),
 				a = self.header(color),