Skip to content

Commit cf9dd22

Browse files
committed
Refactor, use f string instead of .format
1 parent 55e566b commit cf9dd22

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

python_easy_chess_gui.py

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262

6363

6464
APP_NAME = 'Python Easy Chess GUI'
65-
APP_VERSION = 'v1.18'
66-
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)
65+
APP_VERSION = 'v1.18.1'
66+
BOX_TITLE = f'{APP_NAME} {APP_VERSION}'
6767

6868

6969
platform = sys.platform
@@ -1302,11 +1302,12 @@ def update_text_box(self, window, msg, is_hide):
13021302
best_move = chess.Move.from_uci(msg.split()[1])
13031303
except Exception:
13041304
logging.exception('Engine sent {}.'.format(best_move))
1305-
sg.Popup('Engine error, it sent a {} bestmove.\n'.format(
1306-
best_move) + 'Back to Neutral mode, it is better to '
1307-
'change engine {}.'.format(
1308-
self.opp_id_name), icon=ico_path[platform]['pecg'],
1309-
title=BOX_TITLE)
1305+
sg.Popup(
1306+
f'Engine error, it sent a {best_move} bestmove.\n \
1307+
Back to Neutral mode, it is better to change engine {self.opp_id_name}.',
1308+
icon=ico_path[platform]['pecg'],
1309+
title=BOX_TITLE
1310+
)
13101311

13111312
return best_move
13121313

@@ -1640,9 +1641,10 @@ def get_promo_piece(self, move, stm, human):
16401641
def set_depth_limit(self):
16411642
""" Returns max depth based from user setting """
16421643
user_depth = sg.PopupGetText(
1643-
'Current depth is {}\n\nInput depth [{} to {}]'.format(
1644-
self.max_depth, MIN_DEPTH, MAX_DEPTH), title=BOX_TITLE,
1645-
icon=ico_path[platform]['pecg'])
1644+
f'Current depth is {self.max_depth}\n\nInput depth [{MIN_DEPTH} to {MAX_DEPTH}]',
1645+
title=BOX_TITLE,
1646+
icon=ico_path[platform]['pecg']
1647+
)
16461648

16471649
try:
16481650
user_depth = int(user_depth)
@@ -1871,12 +1873,13 @@ def play_game(self, window, engine_id_name, board):
18711873
window.Element('advise_info_k').Update(msg_line)
18721874
except Exception:
18731875
logging.exception('Adviser engine error')
1874-
sg.Popup('Adviser engine {} error.\n'.format(
1875-
self.adviser_id_name) + \
1876-
'It is better to change this engine.\n' +
1877-
'Change to Neutral mode first.',
1878-
icon=ico_path[platform]['pecg'],
1879-
title=BOX_TITLE)
1876+
sg.Popup(
1877+
f'Adviser engine {self.adviser_id_name} error.\n \
1878+
It is better to change this engine.\n \
1879+
Change to Neutral mode first.',
1880+
icon=ico_path[platform]['pecg'],
1881+
title=BOX_TITLE
1882+
)
18801883
break
18811884

18821885
search.join()
@@ -2661,11 +2664,12 @@ def main_loop(self):
26612664
pgn = v['pgn_k']
26622665
if pgn == '':
26632666
logging.info('Missing pgn file.')
2664-
sg.Popup('Please locate your pgn file by pressing '
2665-
'the Browse button followed by Display '
2666-
'Players.',
2667-
title=win_title,
2668-
icon=ico_path[platform]['pecg'])
2667+
sg.Popup(
2668+
'Please locate your pgn file by pressing \
2669+
the Browse button followed by Display Players.',
2670+
title=win_title,
2671+
icon=ico_path[platform]['pecg']
2672+
)
26692673
break
26702674

26712675
t1 = time.perf_counter()
@@ -2977,16 +2981,13 @@ def main_loop(self):
29772981
new_engine_id_name = v1['engine_id_name_k']
29782982
if new_engine_id_name != '':
29792983
# Check if new_engine_id_name is already existing
2980-
if self.is_name_exists(
2981-
new_engine_id_name):
2984+
if self.is_name_exists(new_engine_id_name):
29822985
sg.Popup(
2983-
'{} is existing. Please '
2984-
'modify the name! You can '
2985-
'modify the config later thru '
2986-
'Engine->Manage->Edit'.format(
2987-
new_engine_id_name),
2988-
title=button_title,
2989-
icon=ico_path[platform]['pecg'])
2986+
f'{new_engine_id_name} is existing. Please modify the name! \
2987+
You can modify the config later thru Engine->Manage->Edit',
2988+
title=button_title,
2989+
icon=ico_path[platform]['pecg']
2990+
)
29902991
continue
29912992
break
29922993
else:
@@ -3020,10 +3021,11 @@ def main_loop(self):
30203021
t.join()
30213022

30223023
if msg == 'Failure':
3023-
sg.Popup('Failed to add {} in config '
3024-
'file!'.format(new_engine_id_name),
3025-
title=button_title,
3026-
icon=ico_path[platform]['pecg'])
3024+
sg.Popup(
3025+
f'Failed to add {new_engine_id_name} in config file!',
3026+
title=button_title,
3027+
icon=ico_path[platform]['pecg']
3028+
)
30273029

30283030
self.engine_id_name_list = \
30293031
self.get_engine_id_name_list()

0 commit comments

Comments
 (0)