| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Editra
Revision: 55460
Author: CJP
Date: 04 Sep 2008 16:48:16
Changes:Add optional parameter to allow for setting multiple titles for the dialog so that all modes can have their own title that will be set when switching between them. The original behavior when just one string is set is still preserved.
Files:| ... | ...@@ -248,7 +248,9 @@ | |
| 248 | 248 | """Advanced FindReplaceDialog. Create and return the requested dialog type |
| 249 | 249 | @param parent: parent |
| 250 | 250 | @param fdata: FindReplaceData |
| 251 | @param title: Dialog Title | |
| 251 | @param title: Dialog Title. Pass a single string to set the title for both | |
| 252 | modes of the dialog or a tuple of two strings to set the title | |
| 253 | for (find, replace) modes. | |
| 252 | 254 | @keyword style: Dialog Style and type |
| 253 | 255 | @note: this is a function not a class |
| 254 | 256 | |
| ... | ...@@ -267,8 +269,17 @@ | |
| 267 | 269 | |
| 268 | 270 | """ |
| 269 | 271 | def __init__(self, parent, fdata, title, style=AFR_STYLE_FINDDIALOG): |
| 270 | """Create the base object""" | |
| 272 | """Create the base object | |
| 273 | @param title: string or tuple (findstr, replacestr) | |
| 274 | ||
| 275 | """ | |
| 271 | 276 | # Attributes |
| 277 | if isinstance(title, basestring): | |
| 278 | self._ftitle = title | |
| 279 | self._rtitle = title | |
| 280 | else: | |
| 281 | self._ftitle, self._rtitle = title[:2] | |
| 282 | ||
| 272 | 283 | self._box = FindBox(self, fdata, style=style) |
| 273 | 284 | self._panel = self._box.GetWindow() |
| 274 | 285 | self._accl = wx.AcceleratorTable([(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, wx.ID_CLOSE),]) |
| ... | ...@@ -276,8 +287,13 @@ | |
| 276 | 287 | |
| 277 | 288 | # Layout |
| 278 | 289 | self.__DoLayout() |
| 290 | tmp_title = self._ftitle | |
| 291 | if style & AFR_STYLE_REPLACEDIALOG: | |
| 292 | tmp_title = self._rtitle | |
| 293 | self.SetTitle(tmp_title) | |
| 279 | 294 | |
| 280 | 295 | # Event handlers |
| 296 | # self.Bind(_EVT_MODE_CHANGE, self._OnModeChange) | |
| 281 | 297 | self.Bind(wx.EVT_MENU, lambda evt: self._SendCloseEvent(), id=wx.ID_CLOSE) |
| 282 | 298 | self.Bind(wx.EVT_SET_FOCUS, |
| 283 | 299 | lambda evt: self._panel.SetFocus() and evt.Skip()) |
| ... | ...@@ -299,6 +315,14 @@ | |
| 299 | 315 | wx.PostEvent(self.GetParent(), evt) |
| 300 | 316 | self.Hide() |
| 301 | 317 | |
| 318 | def _OnModeChange(self, evt): | |
| 319 | """Update the the dialog when the mode changes""" | |
| 320 | self.Fit() | |
| 321 | title = self._ftitle | |
| 322 | if self.GetDialogMode() != AFR_STYLE_FINDDIALOG: | |
| 323 | title = self._rtitle | |
| 324 | self.SetTitle(title) | |
| 325 | ||
| 302 | 326 | def GetData(self): |
| 303 | 327 | """Get the FindReplaceData used by this dialog""" |
| 304 | 328 | return self._panel.GetData() |
| ... | ...@@ -394,11 +418,13 @@ | |
| 394 | 418 | """Create the Dialog |
| 395 | 419 | @param parent: Parent Window |
| 396 | 420 | @param fdata: wx.FindReplaceData |
| 397 | @param title: Dialog Title | |
| 421 | @param title: Dialog Title. Pass a single string to set the title for | |
| 422 | both modes of the dialog or a tuple of two strings to set | |
| 423 | the title for (find, replace) modes. | |
| 398 | 424 | @keyword style: Dialog Style |
| 399 | 425 | |
| 400 | 426 | """ |
| 401 | wx.MiniFrame.__init__(self, parent, wx.ID_ANY, title, | |
| 427 | wx.MiniFrame.__init__(self, parent, wx.ID_ANY, u'', | |
| 402 | 428 | style=wx.DEFAULT_DIALOG_STYLE) |
| 403 | 429 | FindReplaceDlgBase.__init__(self, parent, fdata, title, style) |
| 404 | 430 | |
| ... | ...@@ -416,11 +442,13 @@ | |
| 416 | 442 | """Create the Dialog |
| 417 | 443 | @param parent: Parent Window |
| 418 | 444 | @param fdata: wx.FindReplaceData |
| 419 | @param title: Dialog Title | |
| 445 | @param title: Dialog Title can be a string to set the title for both | |
| 446 | modes or a tuple of two strings to set the (find, replace) | |
| 447 | mode titles. | |
| 420 | 448 | @keyword style: Dialog Style |
| 421 | 449 | |
| 422 | 450 | """ |
| 423 | wx.Dialog.__init__(self, parent, wx.ID_ANY, title, | |
| 451 | wx.Dialog.__init__(self, parent, wx.ID_ANY, u'', | |
| 424 | 452 | style=wx.DEFAULT_DIALOG_STYLE) |
| 425 | 453 | FindReplaceDlgBase.__init__(self, parent, fdata, title, style) |
| 426 | 454 | |
| ... | ...@@ -494,7 +522,8 @@ | |
| 494 | 522 | """ |
| 495 | 523 | self._fpanel.SetFindMode(find) |
| 496 | 524 | self.Layout() |
| 497 | self.GetParent().Fit() | |
| 525 | evt = _DlgModeChange(self.GetId(), _edEVT_MODE_CHANGE) | |
| 526 | wx.PostEvent(self.GetParent(), evt) | |
| 498 | 527 | |
| 499 | 528 | def SetReplaceBitmap(self, bmp): |
| 500 | 529 | """Set the bitmap of the Replace Button |
| ... | ...@@ -948,3 +977,14 @@ | |
| 948 | 977 | self.Layout() |
| 949 | 978 | |
| 950 | 979 | #--------------------------------------------------------------------------# |
| 980 | # Private Module Api | |
| 981 | ||
| 982 | _edEVT_MODE_CHANGE = wx.NewEventType() | |
| 983 | _EVT_MODE_CHANGE = wx.PyEventBinder(_edEVT_MODE_CHANGE, 1) | |
| 984 | ||
| 985 | class _DlgModeChange(wx.PyEvent): | |
| 986 | def __init__(self, winid=wx.ID_ANY, etype=wx.wxEVT_NULL): | |
| 987 | """Create the Event""" | |
| 988 | wx.PyEvent.__init__(self, winid, etype) | |
| 989 | ||
| 990 | #--------------------------------------------------------------------------# |