7
7
from os import sep
8
8
import glob
9
9
10
- # local
10
+ # local
11
11
from . import config
12
12
from . import command
13
13
@@ -85,46 +85,51 @@ def draw_cheat(win, cheat, selected):
85
85
prompt = '> '
86
86
max_width = win_width - len (prompt ) - len ("\n " )
87
87
88
- col4_size = math .floor (max_width * 14 / 100 )
89
- col3_size = math .floor (max_width * 8 / 100 )
90
- col1_size = math .floor (max_width * 23 / 100 )
91
- col2_size = math .floor (max_width * 55 / 100 )
92
- # col0_size = math.floor(max_width * 20 / 100)
93
-
94
88
title = cheat .tags if cheat .tags != '' else cheat .str_title
95
89
96
90
tags = cheat .get_tags ()
97
91
92
+ columns_list = ["title" , "name" , "description" ]
93
+ if Gui .with_tags :
94
+ columns_list = ["tags" ] + columns_list
95
+
96
+ get_col_size = lambda ratio : math .floor ( (max_width * ratio ) / 100 )
97
+ ratios = Gui .get_ratios_for_column (columns_list )
98
+
99
+ columns = {
100
+ "tags" : {
101
+ "width" : get_col_size (ratios .get ("tags" , 0 )),
102
+ "val" : tags ,
103
+ "color" : Gui .COL4_COLOR_SELECT if selected else Gui .COL4_COLOR
104
+ },
105
+ "title" : {
106
+ "width" : get_col_size (ratios .get ("title" , 0 )),
107
+ "val" : cheat .str_title ,
108
+ "color" : Gui .COL3_COLOR_SELECT if selected else Gui .COL1_COLOR
109
+ },
110
+ "name" : {
111
+ "width" : get_col_size (ratios .get ("name" , 0 )),
112
+ "val" : cheat .name ,
113
+ "color" : Gui .COL2_COLOR_SELECT if selected else Gui .COL2_COLOR
114
+ },
115
+ "description" : {
116
+ "width" : get_col_size (ratios .get ("description" , 0 )),
117
+ "val" : cheat .printable_command ,
118
+ "color" : Gui .COL3_COLOR_SELECT if selected else Gui .COL3_COLOR
119
+ }
120
+ }
121
+
98
122
if selected :
99
123
win .addstr (prompt , curses .color_pair (Gui .CURSOR_COLOR_SELECT ))
100
- win .addstr ("{:{}s}" .format (Gui .draw_string (tags , col4_size ), col4_size ),
101
- curses .color_pair (Gui .COL4_COLOR_SELECT ))
102
- win .addstr ("{:{}s}" .format (Gui .draw_string (cheat .str_title , col3_size ), col3_size ),
103
- curses .color_pair (Gui .COL3_COLOR_SELECT ))
104
- win .addstr ("{:{}s}" .format (Gui .draw_string (cheat .name , col1_size ), col1_size ),
105
- curses .color_pair (Gui .COL2_COLOR_SELECT ))
106
- win .addstr ("{:{}s}" .format (Gui .draw_string (cheat .printable_command , col2_size ), col2_size ),
107
- curses .color_pair (Gui .COL3_COLOR_SELECT ))
108
- # win.addstr("{:{}s}".format(Gui.draw_string(title, col0_size), col0_size),
109
- # curses.color_pair(Gui.COL1_COLOR_SELECT))
110
- win .addstr ("\n " )
111
124
else :
112
125
win .addstr (' ' * len (prompt ), curses .color_pair (Gui .BASIC_COLOR ))
113
- if tags .startswith ('[W]' ):
114
- win .addstr ("{:{}s}" .format (Gui .draw_string (tags , col4_size ), col4_size ),
115
- curses .color_pair (Gui .COL5_COLOR ))
116
- else :
117
- win .addstr ("{:{}s}" .format (Gui .draw_string (tags , col4_size ), col4_size ),
118
- curses .color_pair (Gui .COL4_COLOR ))
119
- win .addstr ("{:{}s}" .format (Gui .draw_string (cheat .str_title , col3_size ), col3_size ),
120
- curses .color_pair (Gui .COL1_COLOR ))
121
- win .addstr ("{:{}s}" .format (Gui .draw_string (cheat .name , col1_size ), col1_size ),
122
- curses .color_pair (Gui .COL2_COLOR ))
123
- win .addstr ("{:{}s}" .format (Gui .draw_string (cheat .printable_command , col2_size ), col2_size ),
124
- curses .color_pair (Gui .COL3_COLOR ))
125
- # win.addstr("{:{}s}".format(Gui.draw_string(title, col0_size), col0_size),
126
- # curses.color_pair(Gui.COL1_COLOR))
127
- win .addstr ("\n " )
126
+
127
+ for column_name in columns_list :
128
+ win .addstr ("{:{}s}" .format (Gui .draw_string (columns [column_name ]["val" ],
129
+ columns [column_name ]["width" ]),
130
+ columns [column_name ]["width" ]),
131
+ curses .color_pair (columns [column_name ]["color" ]))
132
+ win .addstr ("\n " )
128
133
129
134
def draw_cheatslistbox (self ):
130
135
"""
@@ -784,6 +789,9 @@ class Gui:
784
789
INFO_CMD_COLOR = 0
785
790
ARG_NAME_COLOR = 5
786
791
loaded_menu = False
792
+ with_tags = False
793
+
794
+ DEFAULT_RATIOS = {"tags" : 14 , "title" : 8 , "name" : 23 , "description" : 55 }
787
795
788
796
def __init__ (self ):
789
797
self .cheats_menu = None
@@ -796,6 +804,27 @@ def init_colors():
796
804
for i in range (0 , 255 ):
797
805
curses .init_pair (i + 1 , i , - 1 )
798
806
807
+ @classmethod
808
+ def get_ratios_for_column (cls , columns_in_use ):
809
+ """
810
+ Calculate the column size from the column to print
811
+
812
+ :param columns_in_use: List of the column to print when drawing the
813
+ cheat
814
+ :return: The updated ratios size of each columns
815
+ """
816
+ missing_ratio = 0
817
+ for col in cls .DEFAULT_RATIOS .keys ():
818
+ if col not in columns_in_use :
819
+ missing_ratio += cls .DEFAULT_RATIOS .get (col )
820
+ if not missing_ratio :
821
+ return cls .DEFAULT_RATIOS
822
+
823
+ new_ratio = {}
824
+ for column in columns_in_use :
825
+ new_ratio [column ] = math .floor (cls .DEFAULT_RATIOS [column ] + missing_ratio / len (columns_in_use ))
826
+ return new_ratio
827
+
799
828
@staticmethod
800
829
def draw_string (str_value , max_size ):
801
830
"""
0 commit comments