17 from threading
import current_thread
21 from Tkinter
import (Button, Entry, Frame, Label, Listbox, TclError,
22 Toplevel, Tk, BOTH, END, LEFT, W)
24 from tkinter
import (Button, Entry, Frame, Label, Listbox, TclError,
25 Toplevel, Tk, BOTH, END, LEFT, W)
36 _right_button =
'Cancel'
38 def __init__(self, message, value=None, **extra):
41 Toplevel.__init__(self, self.
_parent_parent)
48 if 'linux' not in sys.platform
and current_thread().name !=
'MainThread':
49 raise RuntimeError(
'Dialogs library is not supported with '
50 'timeouts on Python on this platform.')
58 self.title(
'Robot Framework')
60 self.protocol(
"WM_DELETE_WINDOW", self.
_close_close)
61 self.bind(
"<Escape>", self.
_close_close)
67 maxtime = time.time() + timeout
68 while time.time() < maxtime:
71 return Toplevel.grab_set(self)
74 raise RuntimeError(
'Failed to open dialog in %s seconds. One possible '
75 'reason is holding down mouse button.' % timeout)
78 x = (self.winfo_screenwidth() - self.winfo_reqwidth()) // 2
79 y = (self.winfo_screenheight() - self.winfo_reqheight()) // 2
84 self.attributes(
'-topmost',
True)
85 self.after_idle(self.attributes,
'-topmost',
False)
89 Label(frame, text=message, anchor=W, justify=LEFT, wraplength=800).pack(fill=BOTH)
92 selector.pack(fill=BOTH)
94 frame.pack(padx=5, pady=5, expand=1, fill=BOTH)
109 button = Button(parent, text=label, width=10, command=callback)
110 button.pack(side=LEFT, padx=5, pady=5)
135 self.wait_window(self)
148 def __init__(self, message, default='', hidden=False):
149 _TkDialog.__init__(self, message, default, hidden=hidden)
152 self.
_entry_entry = Entry(parent, show=
'*' if hidden
else '')
153 self.
_entry_entry.insert(0, default)
154 self.
_entry_entry.select_range(0, END)
158 return self.
_entry_entry.get()
164 _TkDialog.__init__(self, message, values)
169 self.
_listbox_listbox.insert(END, item)
170 self.
_listbox_listbox.config(width=0)
174 return bool(self.
_listbox_listbox.curselection())
183 _TkDialog.__init__(self, message, values)
186 self.
_listbox_listbox = Listbox(parent, selectmode=
'multiple')
188 self.
_listbox_listbox.insert(END, item)
189 self.
_listbox_listbox.config(width=0)
193 selected_values = [self.
_listbox_listbox.get(i)
for i
in self.
_listbox_listbox.curselection()]
194 return selected_values
201 _left_button =
'PASS'
205 _right_button =
'FAIL'
def __init__(self, message, values)
def _create_selector(self, parent, values)
def _get_right_button_value(self)
def __init__(self, message, values)
def _validate_value(self)
def _create_selector(self, parent, values)
def _close(self, event=None)
def __init__(self, message, value=None, **extra)
def grab_set(self, timeout=30)
def _create_button(self, parent, label, callback)
def _get_right_button_value(self)
def _bring_to_front(self)
def _create_selector(self, frame, value)
def _create_body(self, message, value, **extra)
def _initialize_dialog(self)
def _validate_value(self)
def _get_center_location(self)
def _right_button_clicked(self, event=None)
def _prevent_execution_with_timeouts(self)
def _create_buttons(self)
def _left_button_clicked(self, event=None)