Changeset 1590

Show
Ignore:
Timestamp:
11/28/2005 06:56:33 AM (3 years ago)
Author:
ed
Message:

Added constants needed to distinguish the Find/Replace dialog fields from each other.

Added the method 'addConnectFile()' to dApp. This allows you to pass a path to a cnxml file, and it will read in the connection information and add it to its dbConnectionDefs.

Modified the dToolForm class to use wx.MiniFrame? instead of a modified wx.Frame. I don't notice any change in behavior, but I figured that since this wx class is designed for just this purpose, it made more sense to use it. I left the old dToolForm code commented in case we find any problems with this new class.

Overhauled the Find/Replace logic in uiApp. It now works as expected (at least on OS X!), and is ready to be used as an integral part of the next iteration of the Designer, which will feature code editing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/dApp.py

    r1582 r1590  
    355355                name = "%s@%s" % (ci.User, ci.Host) 
    356356        self.dbConnectionDefs[name] = ci 
     357     
     358 
     359    def addConnectFile(self, connFile): 
     360        """Accepts a cnxml file path, and reads in the connections 
     361        defined in it, adding them to self.dbConnectionDefs. 
     362        """ 
     363        if os.path.exists(connFile): 
     364            connDefs = importConnections(connFile) 
     365            # For each connection definition, add an entry to  
     366            # self.dbConnectionDefs that contains a key on the  
     367            # name, and a value of a dConnectInfo object. 
     368            for k,v in connDefs.items(): 
     369                ci = dabo.db.dConnectInfo() 
     370                ci.setConnInfo(v) 
     371                self.dbConnectionDefs[k] = ci 
    357372     
    358373 
     
    376391    def onEditFind(self, evt): 
    377392        self.uiApp.onEditFind(evt) 
     393    def onEditFindAlone(self, evt): 
     394        self.uiApp.onEditFindAlone(evt) 
    378395    def onEditFindAgain(self, evt): 
    379396        self.uiApp.onEditFindAgain(evt) 
  • trunk/dabo/dConstants.py

    r1120 r1590  
    2828DLG_OK = 0 
    2929DLG_CANCEL = -1 
     30 
     31FIND_DIALOG_FINDTEXT = -210 
     32FIND_DIALOG_REPLACETEXT = -212 
  • trunk/dabo/ui/uiwx/dBaseMenuBar.py

    r1466 r1590  
    6464        self.appendSeparator() 
    6565 
    66         self.append(_("&Find") + "\tCtrl+F", bindfunc=app.onEditFind, bmp="find", 
    67                 help=_("Find text in the active window") ) 
     66        # By default, the Find and Replace functions use a single dialog. The 
     67        # commented lines below this enable the plain Find dialog call. 
     68        self.append(_("&Find / Replace") + "\tCtrl+F", bindfunc=app.onEditFind,  
     69                bmp="find", help=_("Find text in the active window") ) 
     70#       self.append(_("Find") + "\tShift+Ctrl+F", bindfunc=app.onEditFindAlone,  
     71#               bmp="find", help=_("Find text in the active window") ) 
    6872 
    6973        self.append(_("Find Again") + "\tCtrl+G", bindfunc=app.onEditFindAgain, bmp="", 
    7074                help=_("Repeat the last search") ) 
     75 
     76        self.append(_("&Find / Replace") + "\tCtrl+F", bindfunc=app.onEditFind,  
     77                bmp="find", help=_("Find text in the active window") ) 
    7178 
    7279        self.appendSeparator() 
  • trunk/dabo/ui/uiwx/dForm.py

    r1580 r1590  
    762762 
    763763 
    764 class dToolForm(dFormSDI): 
     764# class dToolForm(dFormSDI): 
     765class dToolForm(wx.MiniFrame, dFormBase): 
    765766    def __init__(self, parent=None, properties=None, *args, **kwargs): 
    766         style = self._extractKey(kwargs, "style", 0) 
    767         style = style | wx.FRAME_TOOL_WINDOW | wx.STAY_ON_TOP | wx.RESIZE_BORDER 
    768         kwargs["style"] = style  
     767        self._baseClass = dToolForm 
     768        preClass = wx.PreMiniFrame 
     769        self._mdi = False 
     770        kwargs["TinyTitleBar"] = True 
    769771        kwargs["ShowStatusBar"] = False 
    770772        kwargs["ShowToolBar"] = False 
    771         self.MenuBarClass = None 
     773        dFormBase.__init__(self, preClass, parent, properties, *args, **kwargs) 
     774#       style = self._extractKey(kwargs, "style", 0) 
     775#       style = style | wx.FRAME_TOOL_WINDOW | wx.STAY_ON_TOP | wx.RESIZE_BORDER 
     776#       kwargs["style"] = style  
     777#       kwargs["ShowStatusBar"] = False 
     778#       kwargs["ShowToolBar"] = False 
     779#       self.MenuBarClass = None 
    772780#       kwargs[""] =  
    773       super(dToolForm, self).__init__(parent=parent, properties=properties, *args, **kwargs) 
     781#         super(dToolForm, self).__init__(parent=parent, properties=properties, *args, **kwargs) 
    774782 
    775783             
  • trunk/dabo/ui/uiwx/uiApp.py

    r1585 r1590  
    66from dabo.dObject import dObject 
    77from dabo.dLocalize import _, n_ 
     8import dabo.dConstants as kons 
     9 
    810 
    911class uiApp(wx.App, dObject): 
     
    1618        self._noneDisp = _("<null>") 
    1719        self._drawSizerOutlines = False 
     20        # Various attributes used by the FindReplace dialog 
     21        self._findString = "" 
     22        self._replaceString = "" 
     23        self._findReplaceFlags = wx.FR_DOWN 
     24        self.findReplaceData = None 
     25        self.findDialog = None 
    1826         
    1927         
     
    9199         
    92100    def _onWxActivate(self, evt): 
    93         """ Raise the Dabo Activate or Deactivate appropriately. 
    94         """ 
     101        """ Raise the Dabo Activate or Deactivate appropriately.""" 
    95102        if bool(evt.GetActive()): 
    96103            self.raiseEvent(dEvents.Activate, evt) 
     
    235242 
    236243 
    237     def onEditFind(self, evt): 
    238         """ Display a Find dialog. """ 
     244    def onEditFindAlone(self, evt): 
     245        self.onEditFind(evt, False) 
     246         
     247         
     248    def onEditFind(self, evt, replace=True): 
     249        """ Display a Find dialog.  By default, both 'Find' and 'Find/Replace' 
     250        will be a single dialog. By calling this method with replace=False, 
     251        you will get a Find-only version of the dialog. 
     252        """ 
     253        if self.findDialog is not None: 
     254            self.findDialog.Raise() 
     255            return 
    239256        if self.ActiveForm: 
    240257            win = self.ActiveForm.ActiveControl 
    241258            if win: 
    242259                self.findWindow = win           # Save reference for use by self.OnFind() 
    243      
    244260                try: 
    245261                    data = self.findReplaceData 
     
    247263                    data = None 
    248264                if data is None: 
    249                     data = wx.FindReplaceData(wx.FR_DOWN) 
     265                    data = wx.FindReplaceData(self._findReplaceFlags) 
     266                    data.SetFindString(self._findString) 
     267                    data.SetReplaceString(self._replaceString) 
    250268                    self.findReplaceData = data 
    251                 dlg = wx.FindReplaceDialog(win, data, "Find") 
     269                if replace: 
     270                    dlg = wx.FindReplaceDialog(win, data, _("Find/Replace"),  
     271                            wx.FR_REPLACEDIALOG) 
     272                else: 
     273                    dlg = wx.FindReplaceDialog(win, data, _("Find")) 
    252274                 
    253275                # Map enter key to find button: 
     
    258280                dlg.Bind(wx.EVT_FIND, self.OnFind) 
    259281                dlg.Bind(wx.EVT_FIND_NEXT, self.OnFind) 
     282                dlg.Bind(wx.EVT_FIND_REPLACE, self.OnFindReplace) 
     283                dlg.Bind(wx.EVT_FIND_REPLACE_ALL, self.OnFindReplaceAll) 
    260284                dlg.Bind(wx.EVT_FIND_CLOSE, self.OnFindClose) 
    261285     
     
    275299        for kid in kids: 
    276300            if isinstance(kid, wx.TextCtrl): 
    277                 frd.SetFindString(kid.GetValue()) 
     301                if kid.GetId() == kons.FIND_DIALOG_FINDTEXT: 
     302                    frd.SetFindString(kid.GetValue()) 
     303                elif kid.GetId() == kons.FIND_DIALOG_REPLACETEXT: 
     304                    frd.SetReplaceString(kid.GetValue()) 
    278305            elif isinstance(kid, wx.CheckBox): 
    279306                lbl = kid.GetLabel() 
     
    295322    def onEditFindAgain(self, evt): 
    296323        """Repeat the last search.""" 
     324        if self.findReplaceData is None: 
     325            if self._findString: 
     326                data = wx.FindReplaceData(self._findReplaceFlags) 
     327                data.SetFindString(self._findString) 
     328                data.SetReplaceString(self._replaceString) 
     329                self.findReplaceData = data 
    297330        try: 
    298331            fd = self.findReplaceData 
    299332            self.OnFind(fd) 
    300         except AttributeError
     333        except AttributeError, e
    301334            self.onEditFind(None) 
    302335            return 
     
    305338    def OnFindClose(self, evt): 
    306339        """ User clicked the close button, so hide the dialog.""" 
     340        frd = self.findReplaceData 
     341        self._findString = frd.GetFindString() 
     342        self._replaceString = frd.GetReplaceString() 
     343        self._findReplaceFlags = frd.GetFlags() 
    307344        self.findReplaceData = None 
    308345        self.findDialog.Destroy() 
     346        self.findDialog = None 
    309347        evt.Skip() 
    310348 
    311  
    312     def OnFind(self, evt): 
     349     
     350    def OnFindReplace(self, evt): 
     351        self.OnFind(evt, action="Replace") 
     352         
     353         
     354    def OnFindReplaceAll(self, evt): 
     355        total = 0 
     356        wx.BeginBusyCursor() 
     357        while True: 
     358            ret = self.OnFind(evt, action="Replace") 
     359            if not ret: 
     360                break 
     361            total += 1 
     362        wx.EndBusyCursor() 
     363        # Tell the user what was done 
     364        msg = _("%s replacements were made") % total 
     365        if total == 1: 
     366            msg = _("1 replacement was made") 
     367        dabo.ui.info(msg, title=_("Replacement Complete")) 
     368         
     369         
     370    def OnFind(self, evt, action="Find"): 
    313371        """ User clicked the 'find' button in the find dialog. 
    314372        Run the search on the current control, if it is a text-based control. 
     
    317375        flags = self.findReplaceData.GetFlags() 
    318376        findString = self.findReplaceData.GetFindString() 
     377        replaceString = self.findReplaceData.GetReplaceString() 
     378        replaceString2 = self.findReplaceData.GetReplaceString() 
    319379        downwardSearch = (flags & wx.FR_DOWN) == wx.FR_DOWN 
    320380        wholeWord = (flags & wx.FR_WHOLEWORD) == wx.FR_WHOLEWORD 
    321381        matchCase = (flags & wx.FR_MATCHCASE) == wx.FR_MATCHCASE 
    322382 
     383        ret = None 
    323384        win = self.findWindow 
    324385        if win: 
    325386            if isinstance(win, wx.stc.StyledTextCtrl): 
    326387                # STC 
     388                if action == "Replace": 
     389                    # Make sure that there is something to replace 
     390                    selectPos = win.GetSelection() 
     391                    if selectPos[1] - selectPos[0] > 0:  
     392                        # There is something selected to replace 
     393                        win.ReplaceSelection(replaceString) 
     394 
     395                selectPos = win.GetSelection() 
    327396                if downwardSearch: 
    328                     start = win.GetSelection()[1] 
     397                    start = selectPos[1] 
    329398                    finish = win.GetTextLength() 
    330399                    pos = win.FindText(start, finish, findString, flags) 
    331400                else: 
    332                     start = win.GetSelection()[0] 
     401                    start = selectPos[0] 
    333402                    txt = win.GetText()[:start] 
    334403                    txRev = utils.reverseText(txt) 
     
    341410                    pos = len(txt) - posRev - len(fsRev) 
    342411                if pos > -1: 
     412                    ret = True 
    343413                    win.SetSelection(pos, pos+len(findString)) 
    344  
     414                return ret 
     415                 
    345416            else: 
    346417                try:  
     
    352423                    return 
    353424 
     425                if action == "Replace": 
     426                    # If we have a selection, replace it. 
     427                    selectPos = win.GetSelection() 
     428                    if selectPos[1] - selectPos[0] > 0: 
     429                        win.ReplaceSelection(replaceString) 
     430 
     431                selectPos = win.GetSelection() 
    354432                if downwardSearch: 
    355                     currentPos = win.GetSelection()[1] 
     433                    currentPos = selectPos[1] 
    356434                    value = win.GetValue()[currentPos:] 
    357435                else: 
    358                     currentPos = win.GetSelection()[0] 
     436                    currentPos = selectPos[0] 
    359437                    value = win.GetValue()[:currentPos] 
    360438                    value = utils.reverseText(value) 
     
    376454                else: 
    377455                    dabo.infoLog.write(_("Not found")) 
    378  
    379      
     456                 
     457 
    380458    def onShowSizerLines(self, evt): 
    381459        """Toggles whether sizer lines are drawn. This is simply a tool