[1198] | 1 | import tkinter as tk
|
---|
| 2 | import tkinter.ttk as ttk
|
---|
| 3 | from tkinter import simpledialog, filedialog
|
---|
| 4 |
|
---|
| 5 | class SliderDialogBox(simpledialog._QueryDialog):
|
---|
| 6 | def __init__(self, *args, **kw):
|
---|
| 7 | if "show" in kw:
|
---|
| 8 | self.__show = kw["show"]
|
---|
| 9 | del kw["show"]
|
---|
| 10 | else:
|
---|
| 11 | self.__show = None
|
---|
| 12 | if "min" in kw:
|
---|
| 13 | self.__min = kw["min"]
|
---|
| 14 | del kw["min"]
|
---|
| 15 | else:
|
---|
| 16 | self.__min = 0
|
---|
| 17 | if "max" in kw:
|
---|
| 18 | self.__max = kw["max"]
|
---|
| 19 | del kw["max"]
|
---|
| 20 | else:
|
---|
| 21 | self.__max = 100
|
---|
| 22 | if "interval" in kw:
|
---|
| 23 | self.__interval = kw["interval"]
|
---|
| 24 | del kw["interval"]
|
---|
| 25 | else:
|
---|
| 26 | self.__interval = 1
|
---|
| 27 | if "init_val" in kw:
|
---|
| 28 | self.__init_val = kw["init_val"]
|
---|
| 29 | del kw["init_val"]
|
---|
| 30 | else:
|
---|
| 31 | self.__init_val = None
|
---|
| 32 | if "hint" in kw:
|
---|
| 33 | self.hint = kw["hint"]
|
---|
| 34 | del kw["hint"]
|
---|
| 35 | else:
|
---|
| 36 | self.hint = None
|
---|
| 37 |
|
---|
| 38 | simpledialog._QueryDialog.__init__(self, *args, **kw)
|
---|
| 39 |
|
---|
| 40 | def body(self, master):
|
---|
| 41 | self.entry = tk.Scale(master=master, from_=self.__min, to=self.__max, orient=tk.HORIZONTAL, resolution=self.__interval)
|
---|
| 42 | if self.__init_val:
|
---|
| 43 | self.entry.set(self.__init_val)
|
---|
| 44 | if self.hint:
|
---|
| 45 | hint = tk.Label(master=master, text=self.hint)
|
---|
| 46 | hint.grid(row=0, padx=5, sticky="WE")
|
---|
| 47 | self.entry.grid(row=1, padx=5, sticky="WE")
|
---|
| 48 | if self.__show is not None:
|
---|
| 49 | self.entry.configure(show=self.__show)
|
---|
| 50 | return self.entry
|
---|
| 51 |
|
---|
| 52 | def getresult(self):
|
---|
| 53 | return self.entry.get()
|
---|
| 54 |
|
---|
| 55 | class ComboboxDialogBox(simpledialog._QueryDialog):
|
---|
| 56 | def __init__(self, *args, **kw):
|
---|
| 57 | if "show" in kw:
|
---|
| 58 | self.__show = kw["show"]
|
---|
| 59 | del kw["show"]
|
---|
| 60 | else:
|
---|
| 61 | self.__show = None
|
---|
| 62 | if "values" in kw:
|
---|
| 63 | self.__values = kw["values"]
|
---|
| 64 | del kw["values"]
|
---|
| 65 | else:
|
---|
| 66 | self.__ = None
|
---|
| 67 | if "init_val" in kw:
|
---|
| 68 | self.__init_val = kw["init_val"]
|
---|
| 69 | del kw["init_val"]
|
---|
| 70 | else:
|
---|
| 71 | self.__init_val = None
|
---|
| 72 | if "hint" in kw:
|
---|
| 73 | self.hint = kw["hint"]
|
---|
| 74 | del kw["hint"]
|
---|
| 75 | else:
|
---|
| 76 | self.hint = None
|
---|
| 77 |
|
---|
| 78 | simpledialog._QueryDialog.__init__(self, *args, **kw)
|
---|
| 79 |
|
---|
| 80 | def body(self, master):
|
---|
| 81 | self.entry = ttk.Combobox(master=master, values=self.__values, state="readonly")
|
---|
| 82 | if self.__init_val:
|
---|
| 83 | self.entry.set(self.__init_val)
|
---|
| 84 | if self.hint:
|
---|
| 85 | hint = tk.Label(master=master, text=self.hint)
|
---|
| 86 | hint.grid(row=0, padx=5, sticky="WE")
|
---|
| 87 | self.entry.grid(row=1, padx=5, sticky="WE")
|
---|
| 88 | if self.__show is not None:
|
---|
| 89 | self.entry.configure(show=self.__show)
|
---|
| 90 | return self.entry
|
---|
| 91 |
|
---|
| 92 | def getresult(self):
|
---|
| 93 | return self.entry.get()
|
---|
| 94 |
|
---|
| 95 | class DirectoryDialgoBox(simpledialog._QueryDialog):
|
---|
| 96 | def __init__(self, *args, **kw):
|
---|
| 97 | if "show" in kw:
|
---|
| 98 | self.__show = kw["show"]
|
---|
| 99 | del kw["show"]
|
---|
| 100 | else:
|
---|
| 101 | self.__show = None
|
---|
| 102 | if "mustexist" in kw:
|
---|
| 103 | self.__mustexist = kw["mustexist"]
|
---|
| 104 | del kw["mustexist"]
|
---|
| 105 | else:
|
---|
| 106 | self.__mustexist = None
|
---|
| 107 | if "init_val" in kw:
|
---|
| 108 | self.__init_val = kw["init_val"]
|
---|
| 109 | del kw["init_val"]
|
---|
| 110 | else:
|
---|
| 111 | self.__init_val = None
|
---|
| 112 |
|
---|
| 113 | self.path = ""
|
---|
| 114 |
|
---|
| 115 | simpledialog._QueryDialog.__init__(self, *args, **kw)
|
---|
| 116 |
|
---|
| 117 | def body(self, master):
|
---|
| 118 | self._pathField = tk.Entry(master, width=50)
|
---|
| 119 | self._pathButton = tk.Button(master, text="Browse", command=lambda:self.__askDirectory())
|
---|
| 120 |
|
---|
| 121 | self._pathField.grid(row=1, column=1, padx=5, sticky="WE")
|
---|
| 122 | self._pathButton.grid(row=1, column=2, sticky="WE")
|
---|
| 123 |
|
---|
| 124 | return self._pathField
|
---|
| 125 |
|
---|
| 126 | def __askDirectory(self):
|
---|
| 127 | self.path = filedialog.askdirectory(initialdir=self.__init_val, mustexist=self.__mustexist)
|
---|
| 128 | self._pathField.delete(0, tk.END)
|
---|
| 129 | self._pathField.insert(0, self.path)
|
---|
| 130 |
|
---|
| 131 | def getresult(self):
|
---|
| 132 | return self._pathField.get().strip()
|
---|
| 133 |
|
---|
| 134 | class FileOpenDialogBox(simpledialog._QueryDialog):
|
---|
| 135 | def __init__(self, *args, **kw):
|
---|
| 136 | if "show" in kw:
|
---|
| 137 | self.__show = kw["show"]
|
---|
| 138 | del kw["show"]
|
---|
| 139 | else:
|
---|
| 140 | self.__show = None
|
---|
| 141 | if "mustexist" in kw:
|
---|
| 142 | self.__mustexist = kw["mustexist"]
|
---|
| 143 | del kw["mustexist"]
|
---|
| 144 | else:
|
---|
| 145 | self.__mustexist = None
|
---|
| 146 | if "init_val" in kw:
|
---|
| 147 | self.__init_val = kw["init_val"]
|
---|
| 148 | del kw["init_val"]
|
---|
| 149 | else:
|
---|
| 150 | self.__init_val = None
|
---|
| 151 | if "filetypes" in kw:
|
---|
| 152 | self.__filetypes = kw["filetypes"]
|
---|
| 153 | del kw["filetypes"]
|
---|
| 154 | else:
|
---|
| 155 | self.__filetypes = None
|
---|
| 156 |
|
---|
| 157 | self.path = ""
|
---|
| 158 |
|
---|
| 159 | simpledialog._QueryDialog.__init__(self, *args, **kw)
|
---|
| 160 |
|
---|
| 161 | def body(self, master):
|
---|
| 162 | self._pathField = tk.Entry(master, width=50)
|
---|
| 163 | self._pathButton = tk.Button(master, text="Browse", command=lambda:self.__askFile())
|
---|
| 164 |
|
---|
| 165 | self._pathField.grid(row=1, column=1, padx=5, sticky="WE")
|
---|
| 166 | self._pathButton.grid(row=1, column=2, sticky="WE")
|
---|
| 167 |
|
---|
| 168 | return self._pathField
|
---|
| 169 |
|
---|
| 170 | def __askFile(self):
|
---|
| 171 | self.path = filedialog.askopenfilename(initialdir=self.__init_val, mustexist=self.__mustexist, filetypes=self.__filetypes)
|
---|
| 172 | self._pathField.delete(0, tk.END)
|
---|
| 173 | self._pathField.insert(0, self.path)
|
---|
| 174 |
|
---|
| 175 | def getresult(self):
|
---|
| 176 | return self._pathField.get().strip()
|
---|
| 177 |
|
---|
| 178 | class FileSaveDialogBox(simpledialog._QueryDialog):
|
---|
| 179 | def __init__(self, *args, **kw):
|
---|
| 180 | if "show" in kw:
|
---|
| 181 | self.__show = kw["show"]
|
---|
| 182 | del kw["show"]
|
---|
| 183 | else:
|
---|
| 184 | self.__show = None
|
---|
| 185 | if "mustexist" in kw:
|
---|
| 186 | self.__mustexist = kw["mustexist"]
|
---|
| 187 | del kw["mustexist"]
|
---|
| 188 | else:
|
---|
| 189 | self.__mustexist = None
|
---|
| 190 | if "init_val" in kw:
|
---|
| 191 | self.__init_val = kw["init_val"]
|
---|
| 192 | del kw["init_val"]
|
---|
| 193 | else:
|
---|
| 194 | self.__init_val = None
|
---|
| 195 | if "filetypes" in kw:
|
---|
| 196 | self.__filetypes = kw["filetypes"]
|
---|
| 197 | del kw["filetypes"]
|
---|
| 198 | else:
|
---|
| 199 | self.__filetypes = None
|
---|
| 200 |
|
---|
| 201 | self.path = ""
|
---|
| 202 |
|
---|
| 203 | simpledialog._QueryDialog.__init__(self, *args, **kw)
|
---|
| 204 |
|
---|
| 205 | def body(self, master):
|
---|
| 206 | self._pathField = tk.Entry(master, width=50)
|
---|
| 207 | self._pathButton = tk.Button(master, text="Browse", command=lambda:self.__askFile())
|
---|
| 208 |
|
---|
| 209 | self._pathField.grid(row=1, column=0, padx=5, sticky="WE")
|
---|
| 210 | self._pathButton.grid(row=1, column=1, sticky="WE")
|
---|
| 211 |
|
---|
| 212 | return self._pathField
|
---|
| 213 |
|
---|
| 214 | def __askFile(self):
|
---|
| 215 | self.path = filedialog.asksaveasfilename(initialdir=self.__init_val, mustexist=self.__mustexist, filetypes=self.__filetypes)
|
---|
| 216 | self._pathField.delete(0, tk.END)
|
---|
| 217 | self._pathField.insert(0, self.path)
|
---|
| 218 |
|
---|
| 219 | def getresult(self):
|
---|
| 220 | return self._pathField.get().strip() |
---|