Create modal popup, return when destroyed. Additional subclass init must be done before this unless _utest=True is passed to suppress wait_window(). title - string, title of popup dialog message - string, informational message to display text0 - initial valu
(self, parent, title, message, *, text0='', used_names={},
_htest=False, _utest=False)
| 36 | For this base class, accept any non-blank string. |
| 37 | """ |
| 38 | def __init__(self, parent, title, message, *, text0='', used_names={}, |
| 39 | _htest=False, _utest=False): |
| 40 | """Create modal popup, return when destroyed. |
| 41 | |
| 42 | Additional subclass init must be done before this unless |
| 43 | _utest=True is passed to suppress wait_window(). |
| 44 | |
| 45 | title - string, title of popup dialog |
| 46 | message - string, informational message to display |
| 47 | text0 - initial value for entry |
| 48 | used_names - names already in use |
| 49 | _htest - bool, change box location when running htest |
| 50 | _utest - bool, leave window hidden and not modal |
| 51 | """ |
| 52 | self.parent = parent # Needed for Font call. |
| 53 | self.message = message |
| 54 | self.text0 = text0 |
| 55 | self.used_names = used_names |
| 56 | |
| 57 | Toplevel.__init__(self, parent) |
| 58 | self.withdraw() # Hide while configuring, especially geometry. |
| 59 | self.title(title) |
| 60 | self.transient(parent) |
| 61 | if not _utest: # Otherwise fail when directly run unittest. |
| 62 | self.grab_set() |
| 63 | |
| 64 | _setup_dialog(self) |
| 65 | if self._windowingsystem == 'aqua': |
| 66 | self.bind("<Command-.>", self.cancel) |
| 67 | self.bind('<Key-Escape>', self.cancel) |
| 68 | self.protocol("WM_DELETE_WINDOW", self.cancel) |
| 69 | self.bind('<Key-Return>', self.ok) |
| 70 | self.bind("<KP_Enter>", self.ok) |
| 71 | |
| 72 | self.create_widgets() |
| 73 | self.update_idletasks() # Need here for winfo_reqwidth below. |
| 74 | self.geometry( # Center dialog over parent (or below htest box). |
| 75 | "+%d+%d" % ( |
| 76 | parent.winfo_rootx() + |
| 77 | (parent.winfo_width()/2 - self.winfo_reqwidth()/2), |
| 78 | parent.winfo_rooty() + |
| 79 | ((parent.winfo_height()/2 - self.winfo_reqheight()/2) |
| 80 | if not _htest else 150) |
| 81 | ) ) |
| 82 | self.resizable(height=False, width=False) |
| 83 | |
| 84 | if not _utest: |
| 85 | self.deiconify() # Unhide now that geometry set. |
| 86 | self.entry.focus_set() |
| 87 | self.wait_window() |
| 88 | |
| 89 | def create_widgets(self, ok_text='OK'): # Do not replace. |
| 90 | """Create entry (rows, extras, buttons. |
no test coverage detected