Skip to content

Commit 08e1da0

Browse files
committed
Update python_easy_chess_gui.py
* In polyglot column header, change weight to score. Polyglot move scoring on book building is 2 points for a win and 0.5 point for a draw. * When user presses Set Engine or Set Book, it will create a new window and hide the main window so that user cannot interact with it. But this time main window is not hidden and any interaction to the main window will be ignored.
1 parent beee953 commit 08e1da0

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

python_easy_chess_gui.py

Lines changed: 27 additions & 19 deletions
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.72'
56+
APP_VERSION = 'v0.73'
5757
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)
5858

5959

@@ -247,14 +247,14 @@ def get_book_move(self):
247247
def get_all_moves(self):
248248
is_found = False
249249
if os.path.isfile(self.book_file):
250-
moves = '{:5s} {:<}\n'.format('move', 'weight')
250+
moves = '{:5s} {:<}\n'.format('move', 'score')
251251
with chess.polyglot.open_reader(self.book_file) as reader:
252252
for entry in reader.find_all(self.board):
253253
is_found = True
254254
san_move = self.board.san(entry.move)
255255
moves += '{:5s} {:<}\n'.format(san_move, entry.weight)
256256
else:
257-
moves = '{:5s} {:<}\n'.format('move', 'weight')
257+
moves = '{:5s} {:<}\n'.format('move', 'score')
258258

259259
return moves, is_found
260260

@@ -951,8 +951,7 @@ def play_game(self, engine_id_name, board):
951951
default = True if self.is_random_book else False)],
952952
[sg.OK(), sg.Cancel()],
953953
]
954-
955-
self.window.Hide()
954+
956955
w = sg.Window(BOX_TITLE, layout)
957956

958957
while True:
@@ -981,7 +980,9 @@ def play_game(self, engine_id_name, board):
981980
break
982981

983982
w.Close()
984-
self.window.UnHide()
983+
while True:
984+
button, value = self.window.Read(timeout=50)
985+
break
985986
continue
986987

987988
if button == 'New::new_game_k':
@@ -1029,7 +1030,6 @@ def play_game(self, engine_id_name, board):
10291030
[sg.OK(), sg.Cancel()]
10301031
]
10311032

1032-
self.window.Hide()
10331033
w = sg.Window('Engine Settings', layout)
10341034

10351035
while True:
@@ -1070,7 +1070,9 @@ def play_game(self, engine_id_name, board):
10701070
break
10711071

10721072
w.Close()
1073-
self.window.UnHide()
1073+
while True:
1074+
button, value = self.window.Read(timeout=50)
1075+
break
10741076
self.update_labels_and_game_tags(human='Human',
10751077
engine_id=self.get_engine_id_name())
10761078
continue
@@ -1180,7 +1182,6 @@ def play_game(self, engine_id_name, board):
11801182
[sg.OK(), sg.Cancel()]
11811183
]
11821184

1183-
self.window.Hide()
11841185
w = sg.Window('Engine Settings', layout)
11851186

11861187
while True:
@@ -1221,7 +1222,9 @@ def play_game(self, engine_id_name, board):
12211222
break
12221223

12231224
w.Close()
1224-
self.window.UnHide()
1225+
while True:
1226+
button, value = self.window.Read(timeout=50)
1227+
break
12251228
self.update_labels_and_game_tags(human='Human',
12261229
engine_id=self.get_engine_id_name())
12271230
continue
@@ -1250,8 +1253,7 @@ def play_game(self, engine_id_name, board):
12501253
default = True if self.is_random_book else False)],
12511254
[sg.OK(), sg.Cancel()],
12521255
]
1253-
1254-
self.window.Hide()
1256+
12551257
w = sg.Window(BOX_TITLE, layout)
12561258

12571259
while True:
@@ -1280,7 +1282,9 @@ def play_game(self, engine_id_name, board):
12801282
break
12811283

12821284
w.Close()
1283-
self.window.UnHide()
1285+
while True:
1286+
button, value = self.window.Read(timeout=50)
1287+
break
12841288
continue
12851289

12861290
if button is None:
@@ -1919,9 +1923,7 @@ def main_loop(self):
19191923
size=(8, 1), key='hash_k')],
19201924
[sg.OK(), sg.Cancel()]
19211925
]
1922-
1923-
# Hide the main window temporarily and build a new one.
1924-
self.window.Hide()
1926+
19251927
w = sg.Window('Engine Settings', layout)
19261928

19271929
while True:
@@ -1965,7 +1967,9 @@ def main_loop(self):
19651967

19661968
# Close the new window and restore/unhide the main window
19671969
w.Close()
1968-
self.window.UnHide()
1970+
while True:
1971+
button, value = self.window.Read(timeout=50)
1972+
break
19691973

19701974
# Update the player box in main window
19711975
self.update_labels_and_game_tags(human='Human',
@@ -2005,7 +2009,6 @@ def main_loop(self):
20052009
[sg.OK(), sg.Cancel()],
20062010
]
20072011

2008-
self.window.Hide()
20092012
w = sg.Window(BOX_TITLE, layout)
20102013

20112014
while True:
@@ -2034,7 +2037,12 @@ def main_loop(self):
20342037
break
20352038

20362039
w.Close()
2037-
self.window.UnHide()
2040+
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
20382046
continue
20392047

20402048
if button == 'Flip':

0 commit comments

Comments
 (0)