@@ -87,18 +87,18 @@ def __init__(self, gui):
87
87
def error (self , info , fatal = True ):
88
88
''' Prints non-fatal and fatal error messages to console'''
89
89
if self .gui :
90
- msg = ''
90
+ msg = [ '' ]
91
91
for info , line in enumerate (info ):
92
- msg += line + ' \n '
92
+ msg += [ line , ' \n ' ]
93
93
if not info :
94
94
warning = line
95
95
self .errors .append (line )
96
- print ('❌ ERROR: ' + line )
96
+ print ('❌ ERROR:' , line )
97
97
else :
98
98
self .errors .append (line )
99
- print ('• ' + line )
99
+ print ('•' , line )
100
100
if fatal :
101
- tk .messagebox .showerror ('Error' , msg )
101
+ tk .messagebox .showerror ('Error' , '' . join ( msg ) )
102
102
raise RuntimeError (warning )
103
103
else :
104
104
error_msg = tc .colored ('❌ ERROR:' , 'red' , attrs = ['reverse' , 'bold' ])
@@ -108,42 +108,45 @@ def error(self, info, fatal=True):
108
108
if not info :
109
109
self .errors .append (line )
110
110
line = tc .colored (line , 'red' )
111
- print (error_msg + ' ' + line )
111
+ print (error_msg , line )
112
112
else :
113
113
self .errors .append (line )
114
- print (e_bullet + ' ' + line )
114
+ print (e_bullet , line )
115
115
if fatal :
116
116
exit ()
117
117
118
118
def bad_kc (self , kc_type , code ):
119
119
""" Prints bad keycode warnings to console"""
120
120
if self .gui :
121
- message = 'Invalid ' + kc_type + ': ' + code
122
- bad_kc_msg = '❌ Invalid ' + kc_type + ':'
123
- print (bad_kc_msg + ' ' + code )
124
- self .errors .append (message )
121
+
122
+ bad_kc_msg = ['❌ ' , 'Invalid ' , kc_type , ': ' , code ]
123
+ print ('' .join (bad_kc_msg ))
124
+ del bad_kc_msg [0 ]
125
+ self .errors .append ('' .join (bad_kc_msg ))
125
126
else :
126
- message = 'Invalid ' + kc_type + ': ' + code
127
- bad_kc_msg = tc .colored ('❌ Invalid ' + kc_type + ':' , 'cyan' )
128
- print (bad_kc_msg + ' ' + code )
129
- self .errors .append (message )
127
+ message = ['❌ ' , 'Invalid ' , kc_type , ':' ]
128
+ bad_kc_msg = [ tc .colored ('' .join (message ), 'cyan' ) ]
129
+ bad_kc_msg += [' ' , code ]
130
+ print ('' .join (bad_kc_msg ))
131
+ message += [' ' , code ]
132
+ self .errors .append ('' .join (message ))
130
133
131
134
def warning (self , info , pause = False ):
132
135
""" Prints warnings and interactive warnings to console"""
133
136
134
137
if self .gui :
135
- msg = ''
138
+ msg = [ '' ]
136
139
for info , line in enumerate (info ):
137
- msg += line + ' \n '
140
+ msg += [ line , ' \n ' ]
138
141
if not info :
139
142
warning = line
140
143
self .errors .append (line )
141
- print ('▲ WARNING: ' + line )
144
+ print ('▲ WARNING:' , line )
142
145
else :
143
146
self .errors .append (line )
144
- print ('• ' + line )
147
+ print ('•' , line )
145
148
if pause :
146
- if not tk .messagebox .askyesno ('Warning' , msg + '\n Continue?' ):
149
+ if not tk .messagebox .askyesno ('Warning' , '' . join ( msg ) + '\n Continue?' ):
147
150
raise RuntimeWarning (warning )
148
151
149
152
else :
@@ -154,12 +157,12 @@ def warning(self, info, pause=False):
154
157
if not info :
155
158
self .errors .append (line )
156
159
line = tc .colored (line , 'yellow' )
157
- print (warning_msg + ' ' + line )
160
+ print (warning_msg , line )
158
161
else :
159
162
self .errors .append (line )
160
- print (w_bullet + ' ' + line )
163
+ print (w_bullet , line )
161
164
if pause :
162
- print (w_bullet + ' Press [ENTER] to continue' )
165
+ print (w_bullet , ' Press [ENTER] to continue' )
163
166
input ()
164
167
165
168
@@ -177,9 +180,9 @@ def note(self, info):
177
180
178
181
for info , line in enumerate (info ):
179
182
if not info :
180
- print (note_msg + ' ' + line )
183
+ print (note_msg , line )
181
184
else :
182
- print (n_bullet + ' ' + line )
185
+ print (n_bullet , line )
183
186
184
187
def clear (self ):
185
188
@@ -217,7 +220,9 @@ def layout_headers(data):
217
220
while tokens .name in names :
218
221
i += 1
219
222
if not tokens .name .endswith (')' ):
220
- tokens .name += '(' + str (i )+ ')'
223
+ dupl_name = [ tokens .name ]
224
+ dupl_name += ['(' , str (i ), ')' ]
225
+ tokens .name = '' .join (dupl_name )
221
226
else :
222
227
tokens .name = tokens .name [:- 2 ]+ str (i )+ ')'
223
228
names .append (tokens .name )
@@ -646,19 +651,21 @@ def __func(self, qmk_func, layer_names, functions, console):
646
651
elif qfunc in ref .keyp_mods .keys () and ')' in func_target :
647
652
target = func_target
648
653
# Init functions with the first function
649
- functions = ref .keyp_mods [qfunc ]
654
+ functions = [ ref .keyp_mods [qfunc ] ]
650
655
# Recursively pipe func into functions until no more functions are left.
651
656
while ')' in target :
652
657
br = target .index ('(' )+ 1
653
658
func = target [:br ]
654
659
target = target [br :- 1 ]
660
+
655
661
if func in ref .keyp_mods .keys ():
656
- functions += ref .keyp_mods [func ]
662
+ functions . append ( ref .keyp_mods [func ])
657
663
# Check that this LAST element is a keycode
658
664
if target in ref .keyp_kc .keys ():
659
665
final_kc = self .__keycode (target , functions , console , allow_quotes = False )
660
666
# Wrap with quotes -> '[func]' - note: keyplus Format is [TAP]>[HOLD]
661
- keyp_func = "'" + functions + '-' + final_kc + "'"
667
+ keyp_func_list = [ "'" , '' .join (functions ), '-' , final_kc , "'" ]
668
+ keyp_func = '' .join (keyp_func_list )
662
669
return keyp_func
663
670
664
671
# Legacy TMK-style QMK Functions e.g. FUNC(x)
@@ -1034,7 +1041,7 @@ def __validate_mcu(self, mcu_list, kbo, revo, DEBUG=False):
1034
1041
if revo .is_rev :
1035
1042
self .__console .warning ([os .path .join (kb_n , rev_n )+ ' might have invalid MCU(s) ' + ', ' .join (bad_mcu )])
1036
1043
else :
1037
- self .__console .warning ([kb_n + ' might have Invalid MCU(s) ' + ', ' .join (bad_mcu )])
1044
+ self .__console .warning ([kb_n + ' might have invalid MCU(s) ' + ', ' .join (bad_mcu )])
1038
1045
return True
1039
1046
1040
1047
else :
@@ -1047,7 +1054,7 @@ def __validate_mcu(self, mcu_list, kbo, revo, DEBUG=False):
1047
1054
if revo .is_rev :
1048
1055
self .__console .error ([os .path .join (kb_n , rev_n )+ ' has invalid MCU(s) ' + ', ' .join (bad_mcu )], fatal = False )
1049
1056
else :
1050
- self .__console .error ([kb_n + ' has Invalid MCU(s) ' + ', ' .join (bad_mcu )], fatal = False )
1057
+ self .__console .error ([kb_n + ' has invalid MCU(s) ' + ', ' .join (bad_mcu )], fatal = False )
1051
1058
return False
1052
1059
1053
1060
def __save_cache (self ):
@@ -1426,12 +1433,11 @@ def __get_keycodes(self, DEBUG=False):
1426
1433
# Todo: Implement in pyparsing instead (proper fix)
1427
1434
for i , element in enumerate (row ):
1428
1435
if ')' in element and '(' not in element :
1429
- func = ''
1430
- func = row [i - 1 ]+ ',' + row [i ]
1436
+ func = [ row [i - 1 ], ',' , row [i ] ]
1431
1437
del row [i - 1 ]
1432
1438
i -= 1
1433
1439
del row [i ]
1434
- row .insert (i , func )
1440
+ row .insert (i , '' . join ( func ) )
1435
1441
if len (row ) > curr_layer .matrix_cols :
1436
1442
num_col = len (row )
1437
1443
curr_layer .keymap += (list (row ))
@@ -1648,23 +1654,24 @@ def __create_keyplus_yaml(self, DEBUG=False):
1648
1654
1649
1655
# Can't simply dump to yaml as we want to keep layout (array) as a human readable matrix (2D 'array').
1650
1656
out_dir = self .dirs ['Keyplus YAML output' ]
1651
- kb_n = self .build_kb .name
1657
+ kb_n = self .build_kb .name . replace ( '/' , '_' ). replace ( ' \\ ' , '_' )
1652
1658
rev_n = self .build_rev .name
1653
1659
if rev_n == 'n/a' : rev_n = ''
1654
1660
keymap = self .build_kb .build_keymap
1655
1661
1656
1662
rev = self .build_rev
1657
1663
layers = rev .build_layout
1658
1664
1659
- errors = ''
1665
+ errors = [ '' ]
1660
1666
for error in self .console .errors :
1661
- errors += '# ' + error + '\n '
1667
+ error = '' .join (['# ' , error , '\n ' ])
1668
+ errors .append (error )
1662
1669
1663
1670
template_matrix = layers [0 ].matrix_map
1664
1671
if rev_n :
1665
- name = kb_n + '_' + rev_n
1672
+ name = [ kb_n , rev_n ]
1666
1673
else :
1667
- name = kb_n
1674
+ name = [ kb_n ]
1668
1675
1669
1676
if rev .build_m_row_pins and rev .build_m_col_pins :
1670
1677
rows = str (rev .build_m_row_pins )
@@ -1675,19 +1682,19 @@ def __create_keyplus_yaml(self, DEBUG=False):
1675
1682
cols = '# ------- Input col pins here ------- '
1676
1683
diodes = rev .build_diodes
1677
1684
1678
- template = ''
1685
+ template = [ '' ]
1679
1686
for i , row in enumerate (template_matrix ):
1680
1687
for col in row :
1681
- template += ( col + ', ' )
1688
+ template += [ col , ', ' ]
1682
1689
if i + 1 < len (template_matrix ):
1683
- template += '\n '
1690
+ template . append ( '\n ' )
1684
1691
1685
- layout = ''
1692
+ layout = [ '' ]
1686
1693
keycode_define = []
1687
1694
for i , layer in enumerate (layers ):
1688
- layout += ' [ # layer ' + str (i )+ '\n ['
1695
+ layout += [ ' [ # layer ' , str (i ), '\n [' ]
1689
1696
for row in layer .layout :
1690
- layout += '\n '
1697
+ layout . append ( '\n ' )
1691
1698
for keycode in row :
1692
1699
if len (keycode ) < 4 :
1693
1700
repeat = 4 - len (keycode )
@@ -1698,33 +1705,35 @@ def __create_keyplus_yaml(self, DEBUG=False):
1698
1705
if keycode not in keycode_define :
1699
1706
keycode_define .append (keycode )
1700
1707
1701
- layout += keycode + ', '
1702
- layout += '\n ]\n ],\n '
1708
+ layout += [ keycode , ', ' ]
1709
+ layout . append ( '\n ]\n ],\n ' )
1703
1710
1704
- keycodes = ''
1711
+ keycodes = [ '' ]
1705
1712
if keycode_define :
1706
- keycodes = 'keycodes:'
1713
+ keycodes . append ( 'keycodes:' )
1707
1714
for kc in keycode_define :
1708
1715
split = kc .split ('>' , 1 )
1709
- tap = split [0 ][1 :]
1710
- hold = split [1 ][:- 1 ]
1716
+ tap = split [0 ][1 :]
1717
+ hold = split [1 ][:- 1 ]
1718
+
1719
+ kc_template = ref .keyplus_yaml_keycode_template
1720
+ kc_template = kc_template .replace ('<KEYCODE>' , kc )
1721
+ kc_template = kc_template .replace ('<TAP>' , tap )
1722
+ kc_template = kc_template .replace ('<HOLD>' , hold )
1711
1723
1712
- keycodes += ref .keyplus_yaml_keycode_template
1713
- keycodes = keycodes .replace ('<KEYCODE>' , kc )
1714
- keycodes = keycodes .replace ('<TAP>' , tap )
1715
- keycodes = keycodes .replace ('<HOLD>' , hold )
1724
+ keycodes .append (kc_template )
1716
1725
1717
1726
# Load Template
1718
1727
output_yaml_info = ref .keyplus_yaml_template
1719
- output_yaml_info = output_yaml_info .replace ('<ERRORS>' , errors )
1720
- output_yaml_info = output_yaml_info .replace ('<KB_NAME>' , name )
1728
+ output_yaml_info = output_yaml_info .replace ('<ERRORS>' , '' . join ( errors ) )
1729
+ output_yaml_info = output_yaml_info .replace ('<KB_NAME>' , '_' . join ( name ) )
1721
1730
output_yaml_info = output_yaml_info .replace ('<LAYOUT_NAME>' , keymap )
1722
1731
output_yaml_info = output_yaml_info .replace ('<ROWS>' , rows )
1723
1732
output_yaml_info = output_yaml_info .replace ('<COLS>' , cols )
1724
1733
output_yaml_info = output_yaml_info .replace ('<DIODES>' , diodes )
1725
- output_yaml_info = output_yaml_info .replace ('<MATRIX_MAP>' , template )
1726
- output_yaml_info = output_yaml_info .replace ('<LAYOUT>' , layout )
1727
- output_yaml_info = output_yaml_info .replace ('<KEYCODES>' , keycodes )
1734
+ output_yaml_info = output_yaml_info .replace ('<MATRIX_MAP>' , '' . join ( template ) )
1735
+ output_yaml_info = output_yaml_info .replace ('<LAYOUT>' , '' . join ( layout ) )
1736
+ output_yaml_info = output_yaml_info .replace ('<KEYCODES>' , '' . join ( keycodes ) )
1728
1737
1729
1738
kblibs = self .build_kb .libs
1730
1739
if rev_n :
0 commit comments