| 280 | |
| 281 | |
| 282 | class GetKeysWindow(Toplevel): |
| 283 | |
| 284 | def __init__(self, parent, title, action, current_key_sequences, |
| 285 | *, _htest=False, _utest=False): |
| 286 | """ |
| 287 | parent - parent of this dialog |
| 288 | title - string which is the title of the popup dialog |
| 289 | action - string, the name of the virtual event these keys will be |
| 290 | mapped to |
| 291 | current_key_sequences - list, a list of all key sequence lists |
| 292 | currently mapped to virtual events, for overlap checking |
| 293 | _htest - bool, change box location when running htest |
| 294 | _utest - bool, do not wait when running unittest |
| 295 | """ |
| 296 | super().__init__(parent) |
| 297 | self.withdraw() # Hide while setting geometry. |
| 298 | self['borderwidth'] = 5 |
| 299 | self.resizable(height=False, width=False) |
| 300 | # Needed for winfo_reqwidth(). |
| 301 | self.update_idletasks() |
| 302 | # Center dialog over parent (or below htest box). |
| 303 | x = (parent.winfo_rootx() + |
| 304 | (parent.winfo_width()//2 - self.winfo_reqwidth()//2)) |
| 305 | y = (parent.winfo_rooty() + |
| 306 | ((parent.winfo_height()//2 - self.winfo_reqheight()//2) |
| 307 | if not _htest else 150)) |
| 308 | self.geometry(f"+{x}+{y}") |
| 309 | |
| 310 | self.title(title) |
| 311 | self.frame = frame = GetKeysFrame(self, action, current_key_sequences) |
| 312 | self.protocol("WM_DELETE_WINDOW", self.cancel) |
| 313 | frame_buttons = Frame(self) |
| 314 | self.button_ok = Button(frame_buttons, text='OK', |
| 315 | width=8, command=self.ok) |
| 316 | self.button_cancel = Button(frame_buttons, text='Cancel', |
| 317 | width=8, command=self.cancel) |
| 318 | self.button_ok.grid(row=0, column=0, padx=5, pady=5) |
| 319 | self.button_cancel.grid(row=0, column=1, padx=5, pady=5) |
| 320 | frame.pack(side='top', expand=True, fill='both') |
| 321 | frame_buttons.pack(side='bottom', fill='x') |
| 322 | |
| 323 | self.transient(parent) |
| 324 | _setup_dialog(self) |
| 325 | self.grab_set() |
| 326 | if not _utest: |
| 327 | self.deiconify() # Geometry set, unhide. |
| 328 | self.wait_window() |
| 329 | |
| 330 | @property |
| 331 | def result(self): |
| 332 | return self.frame.result |
| 333 | |
| 334 | @result.setter |
| 335 | def result(self, value): |
| 336 | self.frame.result = value |
| 337 | |
| 338 | def ok(self, event=None): |
| 339 | self.frame.ok() |
no outgoing calls
no test coverage detected
searching dependent graphs…