Skip to content

Commit 107198a

Browse files
committed
Update python_easy_chess_gui.py
* When setting engine and/or setting book, use disable/enable on the main window.
1 parent 08e1da0 commit 107198a

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

python_easy_chess_gui.py

+24-31
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.73'
56+
APP_VERSION = 'v0.74'
5757
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)
5858

5959

@@ -953,6 +953,7 @@ def play_game(self, engine_id_name, board):
953953
]
954954

955955
w = sg.Window(BOX_TITLE, layout)
956+
self.window.Disable()
956957

957958
while True:
958959
e, v = w.Read(timeout=10)
@@ -978,11 +979,9 @@ def play_game(self, engine_id_name, board):
978979
self.is_random_book = v['random_move_k']
979980
logging.info('Book setting is OK')
980981
break
981-
982+
983+
self.window.Enable()
982984
w.Close()
983-
while True:
984-
button, value = self.window.Read(timeout=50)
985-
break
986985
continue
987986

988987
if button == 'New::new_game_k':
@@ -1031,6 +1030,7 @@ def play_game(self, engine_id_name, board):
10311030
]
10321031

10331032
w = sg.Window('Engine Settings', layout)
1033+
self.window.Disable()
10341034

10351035
while True:
10361036
e, v = w.Read(timeout=10)
@@ -1068,11 +1068,10 @@ def play_game(self, engine_id_name, board):
10681068
except:
10691069
pass
10701070
break
1071-
1071+
1072+
self.window.Enable()
10721073
w.Close()
1073-
while True:
1074-
button, value = self.window.Read(timeout=50)
1075-
break
1074+
10761075
self.update_labels_and_game_tags(human='Human',
10771076
engine_id=self.get_engine_id_name())
10781077
continue
@@ -1183,6 +1182,7 @@ def play_game(self, engine_id_name, board):
11831182
]
11841183

11851184
w = sg.Window('Engine Settings', layout)
1185+
self.window.Disable()
11861186

11871187
while True:
11881188
e, v = w.Read(timeout=10)
@@ -1220,11 +1220,10 @@ def play_game(self, engine_id_name, board):
12201220
except:
12211221
pass
12221222
break
1223-
1223+
1224+
self.window.Enable()
12241225
w.Close()
1225-
while True:
1226-
button, value = self.window.Read(timeout=50)
1227-
break
1226+
12281227
self.update_labels_and_game_tags(human='Human',
12291228
engine_id=self.get_engine_id_name())
12301229
continue
@@ -1255,6 +1254,7 @@ def play_game(self, engine_id_name, board):
12551254
]
12561255

12571256
w = sg.Window(BOX_TITLE, layout)
1257+
self.window.Disable()
12581258

12591259
while True:
12601260
e, v = w.Read(timeout=10)
@@ -1280,11 +1280,9 @@ def play_game(self, engine_id_name, board):
12801280
self.is_random_book = v['random_move_k']
12811281
logging.info('Book setting is OK')
12821282
break
1283-
1283+
1284+
self.window.Enable()
12841285
w.Close()
1285-
while True:
1286-
button, value = self.window.Read(timeout=50)
1287-
break
12881286
continue
12891287

12901288
if button is None:
@@ -1923,8 +1921,10 @@ def main_loop(self):
19231921
size=(8, 1), key='hash_k')],
19241922
[sg.OK(), sg.Cancel()]
19251923
]
1926-
1924+
1925+
# Create new window and disable the main window
19271926
w = sg.Window('Engine Settings', layout)
1927+
self.window.Disable()
19281928

19291929
while True:
19301930
e, v = w.Read(timeout=10)
@@ -1964,12 +1964,9 @@ def main_loop(self):
19641964
except:
19651965
pass
19661966
break
1967-
1968-
# Close the new window and restore/unhide the main window
1969-
w.Close()
1970-
while True:
1971-
button, value = self.window.Read(timeout=50)
1972-
break
1967+
1968+
self.window.Enable()
1969+
w.Close()
19731970

19741971
# Update the player box in main window
19751972
self.update_labels_and_game_tags(human='Human',
@@ -2010,6 +2007,7 @@ def main_loop(self):
20102007
]
20112008

20122009
w = sg.Window(BOX_TITLE, layout)
2010+
self.window.Disable()
20132011

20142012
while True:
20152013
e, v = w.Read(timeout=10)
@@ -2035,14 +2033,9 @@ def main_loop(self):
20352033
self.is_random_book = v['random_move_k']
20362034
logging.info('Book setting is OK')
20372035
break
2038-
2039-
w.Close()
20402036

2041-
# Disable any button presses by the user in the main window
2042-
# while the book setting window is active.
2043-
while True:
2044-
button, value = self.window.Read(timeout=50)
2045-
break
2037+
self.window.Enable()
2038+
w.Close()
20462039
continue
20472040

20482041
if button == 'Flip':

0 commit comments

Comments
 (0)