Skip to content

Commit f4228e5

Browse files
buzzCraftfsmosca
authored andcommitted
Update python_easy_chess_gui.py
Fixed : UserWarning: Use of FindElement is not recommended. Either switch to the recommended window[key] format or the PEP8 compliant find_element
1 parent 7815103 commit f4228e5

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

python_easy_chess_gui.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ def update_text_box(self, window, msg, is_hide):
12631263
if 'info_all' in msg_str:
12641264
info_all = ' '.join(msg_str.split()[0:-1]).strip()
12651265
msg_line = '{}\n'.format(info_all)
1266-
window.FindElement('search_info_all_k').Update(
1266+
window.find_element('search_info_all_k').Update(
12671267
'' if is_hide else msg_line)
12681268
else:
12691269
# Best move can be None because engine dies
@@ -1308,13 +1308,13 @@ def set_new_game(self):
13081308

13091309
def clear_elements(self, window):
13101310
""" Clear movelist, score, pv, time, depth and nps boxes """
1311-
window.FindElement('search_info_all_k').Update('')
1312-
window.FindElement('_movelist_').Update(disabled=False)
1313-
window.FindElement('_movelist_').Update('', disabled=True)
1314-
window.FindElement('polyglot_book1_k').Update('')
1315-
window.FindElement('polyglot_book2_k').Update('')
1316-
window.FindElement('advise_info_k').Update('')
1317-
window.FindElement('comment_k').Update('')
1311+
window.find_element('search_info_all_k').Update('')
1312+
window.find_element('_movelist_').Update(disabled=False)
1313+
window.find_element('_movelist_').Update('', disabled=True)
1314+
window.find_element('polyglot_book1_k').Update('')
1315+
window.find_element('polyglot_book2_k').Update('')
1316+
window.find_element('advise_info_k').Update('')
1317+
window.find_element('comment_k').Update('')
13181318
window.Element('w_base_time_k').Update('')
13191319
window.Element('b_base_time_k').Update('')
13201320
window.Element('w_elapse_k').Update('')
@@ -1324,13 +1324,13 @@ def update_labels_and_game_tags(self, window, human='Human'):
13241324
""" Update player names """
13251325
engine_id = self.opp_id_name
13261326
if self.is_user_white:
1327-
window.FindElement('_White_').Update(human)
1328-
window.FindElement('_Black_').Update(engine_id)
1327+
window.find_element('_White_').Update(human)
1328+
window.find_element('_Black_').Update(engine_id)
13291329
self.game.headers['White'] = human
13301330
self.game.headers['Black'] = engine_id
13311331
else:
1332-
window.FindElement('_White_').Update(engine_id)
1333-
window.FindElement('_Black_').Update(human)
1332+
window.find_element('_White_').Update(engine_id)
1333+
window.find_element('_Black_').Update(human)
13341334
self.game.headers['White'] = engine_id
13351335
self.game.headers['Black'] = human
13361336

@@ -1412,7 +1412,7 @@ def change_square_color(self, window, row, col):
14121412
"""
14131413
Change the color of a square based on square row and col.
14141414
"""
1415-
btn_sq = window.FindElement(key=(row, col))
1415+
btn_sq = window.find_element(key=(row, col))
14161416
is_dark_square = True if (row + col) % 2 else False
14171417
bd_sq_color = self.move_sq_dark_color if is_dark_square else \
14181418
self.move_sq_light_color
@@ -1458,7 +1458,7 @@ def redraw_board(self, window):
14581458
color = self.sq_dark_color if (i + j) % 2 else \
14591459
self.sq_light_color
14601460
piece_image = images[self.psg_board[i][j]]
1461-
elem = window.FindElement(key=(i, j))
1461+
elem = window.find_element(key=(i, j))
14621462
elem.Update(button_color=('white', color),
14631463
image_filename=piece_image, )
14641464

@@ -1649,8 +1649,8 @@ def play_game(self, window, engine_id_name, board):
16491649
:param board: current board position
16501650
:return:
16511651
"""
1652-
window.FindElement('_movelist_').Update(disabled=False)
1653-
window.FindElement('_movelist_').Update('', disabled=True)
1652+
window.find_element('_movelist_').Update(disabled=False)
1653+
window.find_element('_movelist_').Update('', disabled=True)
16541654

16551655
is_human_stm = True if self.is_user_white else False
16561656

@@ -1713,7 +1713,7 @@ def play_game(self, window, engine_id_name, board):
17131713
# Mode: Play, Stm: computer (first move), Allow user to change settings.
17141714
# User can start the engine by Engine->Go.
17151715
if not is_engine_ready:
1716-
window.FindElement('_gamestatus_').Update(
1716+
window.find_element('_gamestatus_').Update(
17171717
'Mode Play, press Engine->Go')
17181718
while True:
17191719
button, value = window.Read(timeout=100)
@@ -1746,13 +1746,13 @@ def play_game(self, window, engine_id_name, board):
17461746
# If user is black and side to move is black
17471747
if not self.is_user_white and not board.turn:
17481748
is_human_stm = True
1749-
window.FindElement('_gamestatus_').Update(
1749+
window.find_element('_gamestatus_').Update(
17501750
'Mode Play')
17511751

17521752
# Elif user is black and side to move is white
17531753
elif not self.is_user_white and board.turn:
17541754
is_human_stm = False
1755-
window.FindElement('_gamestatus_').Update(
1755+
window.find_element('_gamestatus_').Update(
17561756
'Mode Play, press Engine->Go')
17571757

17581758
# When computer is to move in the first move, don't
@@ -1966,7 +1966,7 @@ def play_game(self, window, engine_id_name, board):
19661966
else:
19671967
is_human_stm = True
19681968
is_engine_ready = True
1969-
window.FindElement('_gamestatus_').Update(
1969+
window.find_element('_gamestatus_').Update(
19701970
'Mode Play, Engine is thinking ...')
19711971
break
19721972

@@ -1990,7 +1990,7 @@ def play_game(self, window, engine_id_name, board):
19901990
is_human_stm = True if board.turn else False
19911991
is_engine_ready = True if is_human_stm else False
19921992

1993-
window.FindElement('_gamestatus_').Update(
1993+
window.find_element('_gamestatus_').Update(
19941994
'Mode Play, side: {}'.format(
19951995
'white' if board.turn else 'black'))
19961996

@@ -2016,7 +2016,7 @@ def play_game(self, window, engine_id_name, board):
20162016
is_promote = False
20172017
move_to = button
20182018
to_row, to_col = move_to
2019-
button_square = window.FindElement(key=(fr_row, fr_col))
2019+
button_square = window.find_element(key=(fr_row, fr_col))
20202020

20212021
# If move is cancelled, pressing same button twice
20222022
if move_to == move_from:
@@ -2082,13 +2082,13 @@ def play_game(self, window, engine_id_name, board):
20822082
user_comment = value['comment_k']
20832083
self.update_game(move_cnt, user_move, time_left, user_comment)
20842084

2085-
window.FindElement('_movelist_').Update(disabled=False)
2086-
window.FindElement('_movelist_').Update('')
2087-
window.FindElement('_movelist_').Update(
2085+
window.find_element('_movelist_').Update(disabled=False)
2086+
window.find_element('_movelist_').Update('')
2087+
window.find_element('_movelist_').Update(
20882088
self.game.variations[0], append=True, disabled=True)
20892089

20902090
# Clear comment and engine search box
2091-
window.FindElement('comment_k').Update('')
2091+
window.find_element('comment_k').Update('')
20922092
window.Element('search_info_all_k').Update('')
20932093

20942094
# Change the color of the "fr" and "to" board squares
@@ -2158,7 +2158,7 @@ def play_game(self, window, engine_id_name, board):
21582158
search.get_board(board)
21592159
search.daemon = True
21602160
search.start()
2161-
window.FindElement('_gamestatus_').Update(
2161+
window.find_element('_gamestatus_').Update(
21622162
'Mode Play, Engine is thinking ...')
21632163

21642164
while True:
@@ -2310,9 +2310,9 @@ def play_game(self, window, engine_id_name, board):
23102310
engine_comment = ''
23112311
self.update_game(move_cnt, best_move, time_left, engine_comment)
23122312

2313-
window.FindElement('_movelist_').Update(disabled=False)
2314-
window.FindElement('_movelist_').Update('')
2315-
window.FindElement('_movelist_').Update(
2313+
window.find_element('_movelist_').Update(disabled=False)
2314+
window.find_element('_movelist_').Update('')
2315+
window.find_element('_movelist_').Update(
23162316
self.game.variations[0], append=True, disabled=True)
23172317

23182318
# Change the color of the "fr" and "to" board squares
@@ -2336,7 +2336,7 @@ def play_game(self, window, engine_id_name, board):
23362336
elapse_str = self.get_time_h_mm_ss(engine_timer.base)
23372337
window.Element(k2).Update(elapse_str)
23382338

2339-
window.FindElement('_gamestatus_').Update('Mode Play')
2339+
window.find_element('_gamestatus_').Update('Mode Play')
23402340

23412341
# Auto-save game
23422342
logging.info('Saving game automatically')
@@ -3502,7 +3502,7 @@ def main_loop(self):
35023502

35033503
# Mode: Neutral
35043504
if button == 'Flip':
3505-
window.FindElement('_gamestatus_').Update('Mode Neutral')
3505+
window.find_element('_gamestatus_').Update('Mode Neutral')
35063506
self.clear_elements(window)
35073507
window = self.create_new_window(window, True)
35083508
continue
@@ -3528,12 +3528,12 @@ def main_loop(self):
35283528
while True:
35293529
button, value = window.Read(timeout=100)
35303530

3531-
window.FindElement('_gamestatus_').Update('Mode Play')
3532-
window.FindElement('_movelist_').Update(disabled=False)
3533-
window.FindElement('_movelist_').Update('', disabled=True)
3531+
window.find_element('_gamestatus_').Update('Mode Play')
3532+
window.find_element('_movelist_').Update(disabled=False)
3533+
window.find_element('_movelist_').Update('', disabled=True)
35343534

35353535
start_new_game = self.play_game(window, engine_id_name, board)
3536-
window.FindElement('_gamestatus_').Update('Mode Neutral')
3536+
window.find_element('_gamestatus_').Update('Mode Neutral')
35373537

35383538
self.psg_board = copy.deepcopy(initial_board)
35393539
self.redraw_board(window)

0 commit comments

Comments
 (0)