Skip to content

Commit e0ea9f1

Browse files
committed
Update python_easy_chess_gui.py
* Remove Hide/Unhide sub-menu in engine menu, this is now replaced by just pressing the ENGINE SEARCH INFO text to hide/unhide search info. * By default book1 and book2 are hidden. * Change color of book1, book2 and engine search info texts, depending on whether it is hidden or not, to unhide the info press the green text, to unhide the info press the red text.
1 parent fd638a7 commit e0ea9f1

File tree

1 file changed

+67
-85
lines changed

1 file changed

+67
-85
lines changed

python_easy_chess_gui.py

+67-85
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454

5555
APP_NAME = 'Python Easy Chess GUI'
56-
APP_VERSION = 'v0.74'
56+
APP_VERSION = 'v0.75'
5757
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)
5858

5959

@@ -150,7 +150,7 @@
150150
1. Copy exe file in the engines directory
151151
152152
(H) To show engine search info
153-
1. Engine->Unhide Search Info
153+
1. Press the ENGINE SEARCH INFO text
154154
155155
(I) To hide Book 1 and Book 2
156156
1. Press the Book 1 or Book 2 text
@@ -212,8 +212,7 @@
212212
'User Draws::user_draws_k']],
213213
['FEN', ['Paste']],
214214
['&Engine', ['Go', 'Move Now', 'Set Engine', 'Set Depth',
215-
'Set Movetime', 'Get Settings::engine_info_k',
216-
'Unhide Search Info']],
215+
'Set Movetime', 'Get Settings::engine_info_k']],
217216
['&Book', ['Set Book::book_set_k']],
218217
['&Help', ['About']],
219218
]
@@ -414,30 +413,6 @@ def __init__(self, gui_book_file, computer_book_file, human_book_file,
414413
self.psg_board = None
415414
self.engine_list = self.get_engines()
416415
self.menu_elem = None
417-
418-
def update_play_menu(self, menu, hide):
419-
""" Change menu entry, Hide/Unhide Search Info """
420-
new_menu = []
421-
new_entry = 'Hide Search Info' if hide else 'Unhide Search Info'
422-
hide = not hide
423-
424-
# Modify menu and save it to new menu
425-
for e in menu:
426-
# Find the engine menu and modify its sub-menu
427-
if e[0] == 'Engine':
428-
sub_menu = e[1]
429-
430-
# Update the last entry of sub_menu, since the entry that we
431-
# are going to update is found last in the engine sub-menu.
432-
sub_menu[len(sub_menu)-1] = new_entry
433-
434-
# Rebuild the engine menu
435-
new_menu.append([e[0], sub_menu])
436-
else:
437-
# Just append the other menu that is not affected
438-
new_menu.append(e)
439-
440-
return new_menu, hide
441416

442417
def update_engine_selection(self, engine_filename):
443418
""" """
@@ -871,8 +846,7 @@ def play_game(self, engine_id_name, board):
871846

872847
# For saving game
873848
move_cnt = 0
874-
875-
is_hide_engine_search_info = True
849+
876850
is_user_resigns = False
877851
is_user_wins = False
878852
is_user_draws = False
@@ -882,8 +856,13 @@ def play_game(self, engine_id_name, board):
882856
is_search_stop_for_resign = False
883857
is_search_stop_for_user_wins = False
884858
is_search_stop_for_user_draws = False
885-
is_hide_book1 = False
886-
is_hide_book2 = False
859+
is_hide_book1 = True
860+
is_hide_book2 = True
861+
is_hide_search_info = True
862+
863+
self.window.Element('book1_k').Update(text_color='green' if is_hide_book1 else 'red')
864+
self.window.Element('book2_k').Update(text_color='green' if is_hide_book2 else 'red')
865+
self.window.Element('search_info_k').Update(text_color='green' if is_hide_search_info else 'red')
887866

888867
# Game loop
889868
while not board.is_game_over(claim_draw=True):
@@ -918,14 +897,6 @@ def play_game(self, engine_id_name, board):
918897
while True:
919898
button, value = self.window.Read(timeout=100)
920899

921-
# User can hide/unhide search info when engine is to move
922-
# on its first move in Play mode
923-
if button == 'Hide Search Info' or button == 'Unhide Search Info':
924-
new_menu, is_hide_engine_search_info = self.update_play_menu(
925-
menu_def_play, is_hide_engine_search_info)
926-
self.menu_elem.Update(new_menu)
927-
continue
928-
929900
# Allow user to change book settings when engine is to move
930901
# on its first move in Play mode
931902
if button == 'Set Book::book_set_k':
@@ -1137,21 +1108,21 @@ def play_game(self, engine_id_name, board):
11371108
if not is_human_stm:
11381109
break
11391110

1111+
if button == 'search_info_k':
1112+
is_hide_search_info = not is_hide_search_info
1113+
self.window.Element('search_info_k').Update(text_color='green' if is_hide_search_info else 'red')
1114+
break
1115+
11401116
if button == 'book1_k':
11411117
is_hide_book1 = not is_hide_book1
1118+
self.window.Element('book1_k').Update(text_color='green' if is_hide_book1 else 'red')
11421119
break
11431120

11441121
if button == 'book2_k':
11451122
is_hide_book2 = not is_hide_book2
1123+
self.window.Element('book2_k').Update(text_color='green' if is_hide_book2 else 'red')
11461124
break
11471125

1148-
# User can hide/unhide search info when user is to move on Play mode
1149-
if button == 'Hide Search Info' or button == 'Unhide Search Info':
1150-
new_menu, is_hide_engine_search_info = self.update_play_menu(
1151-
menu_def_play, is_hide_engine_search_info)
1152-
self.menu_elem.Update(new_menu)
1153-
continue
1154-
11551126
if button == 'Get Settings::engine_info_k':
11561127
self.get_engine_settings(engine_id_name)
11571128
break
@@ -1306,12 +1277,6 @@ def play_game(self, engine_id_name, board):
13061277
if button == 'New::new_game_k' or is_search_stop_for_new_game:
13071278
is_new_game = True
13081279
self.clear_elements()
1309-
1310-
# Restore to hide by default
1311-
if not is_hide_engine_search_info:
1312-
new_menu, is_hide_engine_search_info = self.update_play_menu(
1313-
menu_def_play, is_hide_engine_search_info)
1314-
self.menu_elem.Update(new_menu)
13151280
break
13161281

13171282
if button == 'Save::save_game_k':
@@ -1349,12 +1314,6 @@ def play_game(self, engine_id_name, board):
13491314
if button == 'Neutral' or is_search_stop_for_neutral:
13501315
is_exit_game = True
13511316
self.clear_elements()
1352-
1353-
# Restore to hide by default
1354-
if not is_hide_engine_search_info:
1355-
new_menu, is_hide_engine_search_info = self.update_play_menu(
1356-
menu_def_play, is_hide_engine_search_info)
1357-
self.menu_elem.Update(new_menu)
13581317
break
13591318

13601319
if button == 'About':
@@ -1537,30 +1496,46 @@ def play_game(self, engine_id_name, board):
15371496
while True:
15381497
button, value = self.window.Read(timeout=10)
15391498

1499+
# Hide/Unhide engine searching info while engine is thinking
1500+
if button == 'search_info_k':
1501+
is_hide_search_info = not is_hide_search_info
1502+
self.window.Element('search_info_k').Update(text_color='green' if is_hide_search_info else 'red')
1503+
1504+
# Hide/Unhide book 1 while engine is searching
1505+
if button == 'book1_k':
1506+
is_hide_book1 = not is_hide_book1
1507+
self.window.Element('book1_k').Update(text_color='green' if is_hide_book1 else 'red')
1508+
1509+
if is_hide_book1:
1510+
self.window.Element('polyglot_book1_k').Update('')
1511+
else:
1512+
ref_book1 = GuiBook(self.computer_book_file, board, self.is_random_book)
1513+
all_moves, is_found = ref_book1.get_all_moves()
1514+
if is_found:
1515+
self.window.Element('polyglot_book1_k').Update(all_moves)
1516+
else:
1517+
self.window.Element('polyglot_book1_k').Update('no book moves')
1518+
1519+
# Hide/Unhide book 2 while engine is searching
1520+
if button == 'book2_k':
1521+
is_hide_book2 = not is_hide_book2
1522+
self.window.Element('book2_k').Update(text_color='green' if is_hide_book2 else 'red')
1523+
1524+
if is_hide_book2:
1525+
self.window.Element('polyglot_book2_k').Update('')
1526+
else:
1527+
ref_book2 = GuiBook(self.human_book_file, board, self.is_random_book)
1528+
all_moves, is_found = ref_book2.get_all_moves()
1529+
if is_found:
1530+
self.window.Element('polyglot_book2_k').Update(all_moves)
1531+
else:
1532+
self.window.Element('polyglot_book2_k').Update('no book moves')
1533+
15401534
# Exit app while engine is thinking
15411535
if button == 'Exit':
15421536
search.stop()
15431537
logging.info('Exit app while engine is searching')
15441538
is_search_stop_for_exit = True
1545-
1546-
# Get the engine search info and display it in GUI text boxes
1547-
try:
1548-
msg = self.queue.get_nowait()
1549-
except:
1550-
continue
1551-
1552-
msg_str = str(msg)
1553-
best_move = self.update_text_box(msg, is_hide_engine_search_info)
1554-
if 'bestmove' in msg_str:
1555-
logging.info('engine msg: {}'.format(msg_str))
1556-
break
1557-
1558-
# User can hide/unhide search info while engine is thinking on Play mode
1559-
if button == 'Hide Search Info' or button == 'Unhide Search Info':
1560-
new_menu, is_hide_engine_search_info = self.update_play_menu(
1561-
menu_def_play, is_hide_engine_search_info)
1562-
self.menu_elem.Update(new_menu)
1563-
continue
15641539

15651540
# Forced engine to move now and create a new game
15661541
if button == 'New::new_game_k':
@@ -1587,6 +1562,18 @@ def play_game(self, engine_id_name, board):
15871562
if button == 'User Draws::user_draws_k':
15881563
search.stop()
15891564
is_search_stop_for_user_draws = True
1565+
1566+
# Get the engine search info and display it in GUI text boxes
1567+
try:
1568+
msg = self.queue.get_nowait()
1569+
except:
1570+
continue
1571+
1572+
msg_str = str(msg)
1573+
best_move = self.update_text_box(msg, is_hide_search_info)
1574+
if 'bestmove' in msg_str:
1575+
logging.info('engine msg: {}'.format(msg_str))
1576+
break
15901577

15911578
search.join()
15921579
search.quit_engine()
@@ -1676,12 +1663,6 @@ def play_game(self, engine_id_name, board):
16761663

16771664
self.clear_elements()
16781665

1679-
# Restore to hide by default
1680-
if not is_hide_engine_search_info:
1681-
new_menu, is_hide_engine_search_info = self.update_play_menu(
1682-
menu_def_play, is_hide_engine_search_info)
1683-
self.menu_elem.Update(new_menu)
1684-
16851666
return False if is_exit_game else is_new_game
16861667

16871668
def save_game(self):
@@ -1824,7 +1805,8 @@ def build_main_layout(self):
18241805
sg.Multiline('', do_not_clear=True, autoscroll=False, size=(2, 12),
18251806
font=('Consolas', 10), key='polyglot_book2_k', disabled=True)],
18261807

1827-
[sg.Text('ENGINE SEARCH INFO', font=('Consolas', 10), size=(28, 1))],
1808+
[sg.Text('ENGINE SEARCH INFO', font=('Consolas', 10), size=(28, 1),
1809+
click_submits=True, key='search_info_k')],
18281810
[sg.Text('', key='info_score_k', size=(8, 1), background_color = bc),
18291811
sg.Text('', key='info_pv_k', size=(28, 1), background_color = bc)],
18301812

0 commit comments

Comments
 (0)