| 142 | class GenericInputDialog(wx.Frame) : |
| 143 | """Generic input dialog box.""" |
| 144 | def __init__(self, parent, id, labels, varnames, varvalues): |
| 145 | wx.Frame.__init__(self, parent, id, \ |
| 146 | _("PyKotIcon data input"), \ |
| 147 | size = (-1, -1), \ |
| 148 | style = wx.DEFAULT_FRAME_STYLE \ |
| 149 | | wx.SIZE_AUTO_HEIGHT \ |
| 150 | | wx.SIZE_AUTO_WIDTH \ |
| 151 | | wx.STAY_ON_TOP \ |
| 152 | | wx.NO_FULL_REPAINT_ON_RESIZE) |
| 153 | vsizer = wx.BoxSizer(wx.VERTICAL) |
| 154 | for i in range(len(varnames)) : |
| 155 | varname = varnames[i] |
| 156 | try : |
| 157 | label = labels[i] |
| 158 | except IndexError : |
| 159 | label = "" |
| 160 | labelid = wx.NewId() |
| 161 | varid = wx.NewId() |
| 162 | label = wx.StaticText(self, labelid, label) |
| 163 | variable = wx.TextCtrl(self, varid, varvalues.get(varname, "")) |
| 164 | hsizer = wx.BoxSizer(wx.HORIZONTAL) |
| 165 | hsizer.Add(label, 0, wx.ALIGN_CENTER | wx.ALIGN_RIGHT | wx.ALL, 5) |
| 166 | hsizer.Add(variable, 0, wx.ALIGN_CENTER | wx.ALIGN_LEFT | wx.ALL, 5) |
| 167 | vsizer.Add(hsizer, 0, wx.ALIGN_CENTER | wx.ALL, 5) |
| 168 | |
| 169 | buttonid = wx.NewId() |
| 170 | okbutton = wx.Button(self, buttonid, "OK") |
| 171 | wx.EVT_BUTTON(self, buttonid, self.OnOK) |
| 172 | |
| 173 | wx.EVT_CLOSE(self, self.OnClose) |
| 174 | |
| 175 | vsizer.Add(okbutton, 0, wx.ALIGN_CENTER | wx.ALL, 5) |
| 176 | self.SetAutoLayout(True) |
| 177 | self.SetSizerAndFit(vsizer) |
| 178 | self.Layout() |
| 179 | self.Show(True) |
| 180 | |
| 181 | def OnClose(self, event) : |
| 182 | """Closes the current frame.""" |
| 183 | self.Destroy() |
| 184 | |
| 185 | def OnOK(self, event) : |
| 186 | """Sets the variables values.""" |
| 187 | # TODO : do something |
| 188 | self.Close() |
| 189 | |
150 | | style = wxPython.wx.wxDEFAULT_FRAME_STYLE \ |
151 | | | wxPython.wx.wxSIZE_AUTO_HEIGHT \ |
152 | | | wxPython.wx.wxSIZE_AUTO_WIDTH \ |
153 | | | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) |
154 | | # try : |
155 | | # self.tbicon = wxPython.wx.wxTaskBarIcon() |
156 | | # except AttributeError : |
157 | | # self.tbicon = None # No taskbar icon facility, old wxWidgets maybe |
158 | | # |
159 | | # self.greenicon = wxPython.wx.wxIcon(os.path.join(iconsdir, "pykoticon-green.ico"), \ |
160 | | # wxPython.wx.wxBITMAP_TYPE_ICO) |
161 | | # self.redicon = wxPython.wx.wxIcon(os.path.join(iconsdir, "pykoticon-red.ico"), \ |
162 | | # wxPython.wx.wxBITMAP_TYPE_ICO) |
163 | | # |
164 | | # self.SetIcon(self.greenicon) |
165 | | # if self.tbicon is not None : |
166 | | # self.tbicon.SetIcon(self.greenicon, "PyKotIcon") |
167 | | # wxPython.wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) |
168 | | # wxPython.wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) |
169 | | # |
170 | | # self.TBMENU_RESTORE = wx.NewId() |
171 | | # self.TBMENU_CLOSE = wx.NewId() |
172 | | # wxPython.wx.EVT_MENU(self.tbicon, self.TBMENU_RESTORE, \ |
173 | | # self.OnTaskBarActivate) |
174 | | # wxPython.wx.EVT_MENU(self.tbicon, self.TBMENU_CLOSE, \ |
175 | | # self.OnTaskBarClose) |
176 | | # self.menu = wxPython.wx.wxMenu() |
177 | | # self.menu.Append(self.TBMENU_RESTORE, _("Show Print Quota")) |
178 | | # self.menu.Append(self.TBMENU_CLOSE, _("Quit")) |
179 | | # |
180 | | wxPython.wx.EVT_ICONIZE(self, self.OnIconify) |
181 | | wxPython.wx.EVT_CLOSE(self, self.OnClose) |
| 197 | style = wx.DEFAULT_FRAME_STYLE \ |
| 198 | | wx.SIZE_AUTO_HEIGHT \ |
| 199 | | wx.SIZE_AUTO_WIDTH \ |
| 200 | | wx.NO_FULL_REPAINT_ON_RESIZE) |
| 201 | try : |
| 202 | self.tbicon = wx.TaskBarIcon() |
| 203 | except AttributeError : |
| 204 | self.tbicon = None # No taskbar icon facility |
| 205 | |
| 206 | self.greenicon = wx.Icon(os.path.join(iconsdir, "pykoticon-green.ico"), \ |
| 207 | wx.BITMAP_TYPE_ICO) |
| 208 | self.redicon = wx.Icon(os.path.join(iconsdir, "pykoticon-red.ico"), \ |
| 209 | wx.BITMAP_TYPE_ICO) |
| 210 | |
| 211 | self.SetIcon(self.greenicon) |
| 212 | if self.tbicon is not None : |
| 213 | self.tbicon.SetIcon(self.greenicon, "PyKotIcon") |
| 214 | wx.EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate) |
| 215 | wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu) |
| 216 | |
| 217 | self.TBMENU_RESTORE = wx.NewId() |
| 218 | self.TBMENU_CLOSE = wx.NewId() |
| 219 | wx.EVT_MENU(self.tbicon, self.TBMENU_RESTORE, \ |
| 220 | self.OnTaskBarActivate) |
| 221 | wx.EVT_MENU(self.tbicon, self.TBMENU_CLOSE, \ |
| 222 | self.OnTaskBarClose) |
| 223 | self.menu = wx.wxMenu() |
| 224 | self.menu.Append(self.TBMENU_RESTORE, _("Show Print Quota")) |
| 225 | self.menu.Append(self.TBMENU_CLOSE, _("Quit")) |
| 226 | |
| 227 | wx.EVT_ICONIZE(self, self.OnIconify) |
| 228 | wx.EVT_CLOSE(self, self.OnClose) |
| 230 | |
| 231 | def OnIconify(self, event) : |
| 232 | if not self.IsIconized() : |
| 233 | self.Iconize(True) |
| 234 | #self.Hide() |
| 235 | |
| 236 | def OnTaskBarActivate(self, event) : |
| 237 | if self.IsIconized() : |
| 238 | self.Iconize(False) |
| 239 | if not self.IsShown() : |
| 240 | self.Show(True) |
| 241 | self.Raise() |
| 242 | |
| 243 | def OnClose(self, event) : |
| 244 | self.closeServer() |
| 245 | if hasattr(self, "menu") : |
| 246 | self.menu.Destroy() |
| 247 | del self.menu |
| 248 | if hasattr(self, "tbicon") and self.tbicon : |
| 249 | self.tbicon.Destroy() |
| 250 | del self.tbicon |
| 251 | self.Destroy() |
| 252 | |
| 253 | def OnTaskBarMenu(self, event) : |
| 254 | if self.tbicon : |
| 255 | self.tbicon.PopupMenu(self.menu) |
| 256 | |
| 257 | def OnTaskBarClose(self, event) : |
| 258 | self.Close() |
| 259 | |
| 260 | def showDialog(self, message, yesno) : |
| 261 | """Opens a notification dialog.""" |
| 262 | self.dialogAnswer = None |
| 263 | if yesno : |
| 264 | caption = _("Confirmation") |
| 265 | style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION |
| 266 | else : |
| 267 | caption = _("Information") |
| 268 | style = wx.OK | wx.ICON_INFORMATION |
| 269 | style |= wx.STAY_ON_TOP |
| 270 | dialog = wx.MessageDialog(self, message, caption, style) |
| 271 | self.dialogAnswer = ((dialog.ShowModal() == wx.ID_NO) and "CANCEL") or "OK" |
| 272 | dialog.Destroy() |
| 273 | |
| 274 | def askDatas(self, labels, varnames, varvalues) : |
| 275 | """Opens a dialog box asking for data entry.""" |
| 276 | # use it this way : self.askDatas(["Username", "Password", "Billing code"], ["username", "password", "billingcode"]) |
| 277 | frame = GenericInputDialog(self, wx.ID_ANY, labels, varnames, varvalues) |
| 278 | # TODO : wait for dialog to close, and return the values |
| 279 | return True |
204 | | def OnIconify(self, event) : |
205 | | self.Hide() |
206 | | |
207 | | def OnTaskBarActivate(self, event) : |
208 | | #if self.IsIconized() : |
209 | | # self.Iconize(False) |
210 | | if not self.IsShown() : |
211 | | self.Show(True) |
212 | | self.Raise() |
213 | | |
214 | | def OnClose(self, event) : |
215 | | sys.stderr.write("Close event !\n") |
216 | | self.closeServer() |
217 | | if hasattr(self, "menu") : |
218 | | self.menu.Destroy() |
219 | | del self.menu |
220 | | if hasattr(self, "tbicon") and self.tbicon : |
221 | | self.tbicon.Destroy() |
222 | | del self.tbicon |
223 | | self.Destroy() |
224 | | |
225 | | def OnTaskBarMenu(self, event) : |
226 | | #if self.tbicon : |
227 | | # self.tbicon.PopupMenu(self.menu) |
228 | | pass |
229 | | |
230 | | def OnTaskBarClose(self, event) : |
231 | | self.Close() |
232 | | |
233 | | def showDialog(self, message, yesno) : |
234 | | """Opens a notification dialog.""" |
235 | | self.dialogAnswer = None |
236 | | if yesno : |
237 | | caption = _("Confirmation") |
238 | | style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION |
239 | | else : |
240 | | caption = _("Information") |
241 | | style = wx.OK | wx.ICON_INFORMATION |
242 | | style |= wx.STAY_ON_TOP |
243 | | dialog = wx.MessageDialog(self, message, caption, style) |
244 | | self.dialogAnswer = ((dialog.ShowModal() == wx.ID_NO) and "CANCEL") or "OK" |
245 | | dialog.Destroy() |
246 | | |
247 | | def askDatas(self, labels, varnames, varvalues) : |
248 | | """Opens a dialog box asking for data entry.""" |
249 | | # use it this way : self.askDatas(["Username", "Password", "Billing code"], ["username", "password", "billingcode"]) |
250 | | frame = wx.Frame(self, wx.ID_ANY, \ |
251 | | _("Enter PyKota information"), \ |
252 | | size = (-1, -1), \ |
253 | | style = wxPython.wx.wxDEFAULT_FRAME_STYLE \ |
254 | | | wxPython.wx.wxSIZE_AUTO_HEIGHT \ |
255 | | | wxPython.wx.wxSIZE_AUTO_WIDTH \ |
256 | | | wxPython.wx.wxNO_FULL_REPAINT_ON_RESIZE) |
257 | | self.dialogAnswer = None |
258 | | values = {} |
259 | | vsizer = wx.BoxSizer(wx.VERTICAL) |
260 | | for i in range(len(varnames)) : |
261 | | varname = varnames[i] |
262 | | values[varname] = None |
263 | | try : |
264 | | label = labels[i] |
265 | | except IndexError : |
266 | | label = "" |
267 | | labelid = wx.NewId() |
268 | | varid = wx.NewId() |
269 | | label = wx.StaticText(frame, labelid, label) |
270 | | variable = wx.TextCtrl(frame, varid, varvalues.get(varname, "")) |
271 | | hsizer = wx.BoxSizer(wx.HORIZONTAL) |
272 | | hsizer.Add(label, 0, wx.ALIGN_CENTER | wx.ALIGN_RIGHT | wx.ALL, 5) |
273 | | hsizer.Add(variable, 0, wx.ALIGN_CENTER | wx.ALIGN_LEFT | wx.ALL, 5) |
274 | | vsizer.Add(hsizer, 0, wx.ALIGN_CENTER | wx.ALL, 5) |
275 | | okbutton = wx.Button(frame, wx.ID_ANY, "OK") |
276 | | vsizer.Add(okbutton, 0, wx.ALIGN_CENTER | wx.ALL, 5) |
277 | | frame.SetAutoLayout(True) |
278 | | frame.SetSizerAndFit(vsizer) |
279 | | frame.Layout() |
280 | | frame.Show(True) |