Пример #1
0
    def DoSearch(self, next=True):
        """Do the search and move the selection
        @keyword next: search next or previous

        """
        s_cmd = wx.wxEVT_COMMAND_FIND
        if next:
            self.SetSearchFlag(wx.FR_DOWN)
        else:
            if wx.FR_DOWN & self._flags:
                self.ClearSearchFlag(wx.FR_DOWN)

        if self.GetValue() == self._last:
            s_cmd = wx.wxEVT_COMMAND_FIND_NEXT
        self.InsertHistoryItem(self.GetValue())

        self._last = self.GetValue()
        self.FindService.SetQueryString(self.GetValue())
        self.FindService.SetSearchFlags(self._flags)
        self.FindService.OnFind(wx.FindDialogEvent(s_cmd))

        # Give feedback on whether text was found or not
        if self.FindService.GetLastFound() < 0 and len(self.GetValue()) > 0:
            self.SetForegroundColour(wx.RED)
            wx.Bell()
        else:
            # ?wxBUG? cant set text back to black after changing color
            # But setting it to this almost black color works. Most likely its
            # due to bit masking but I havent looked at the source so I am not
            # sure
            self.SetForegroundColour(wx.ColorRGB(0 | 1 | 0))
        self.Refresh()
Пример #2
0
 def OnKeyDown(self, evt):
     keyCode = evt.GetKeyCode()
     if keyCode == wx.WXK_F3 and self.searchedNode == None:
         # key 'F3'
         findEvt = wx.FindDialogEvent()
         if evt.ShiftDown():
             self.OnFindPrev(findEvt)
         else:
             self.OnFindNext(findEvt)
     if evt.ControlDown():
         if keyCode == 70:
             # key 'f'
             self.OnSearch(evt)
     evt.Skip()
Пример #3
0
 def OnEnter(self, event):
     """Send a search event"""
     code = event.GetKeyCode()
     val = self.search.GetValue()
     if code == wx.WXK_RETURN and val:
         if val == self.lastfind:
             etype = wx.wxEVT_COMMAND_FIND
         else:
             etype = wx.wxEVT_COMMAND_FIND_NEXT
         fevent = wx.FindDialogEvent(etype)
         fevent.SetFindString(val)
         self.ProcessEvent(fevent)
         self.lastfind = val
     else:
         show = bool(val)
         self.search.ShowCancelButton(show)
Пример #4
0
    def ProcessEvent(self, evt):
        """Processes Events for the Search Control
        @param evt: the event that called this handler

        """
        e_type = evt.GetEventType()
        if e_type == wx.wxEVT_KEY_UP:
            e_key = evt.GetKeyCode()
            if e_key == wx.WXK_ESCAPE:
                # HACK change to more safely determine the context
                # Currently control is only used in command bar
                self.GetParent().Hide()
                return
            elif e_key == wx.WXK_SHIFT:
                self.SetSearchFlag(wx.FR_DOWN)
                return
            else:
                pass

            tmp = self.GetValue()
            # Dont do search
            if tmp == wx.EmptyString or \
               evt.CmdDown() or \
               e_key in [wx.WXK_COMMAND, wx.WXK_LEFT, wx.WXK_RIGHT,
                         wx.WXK_UP, wx.WXK_DOWN]:
                return

            if wx.Platform != '__WXMSW__' and len(self.GetValue()) > 0:
                self.ShowCancelButton(True)
            else:
                self.ShowCancelButton(False)

            if e_key == wx.WXK_RETURN:
                if evt.ShiftDown():
                    if wx.FR_DOWN & self._flags:
                        self.ClearSearchFlag(wx.FR_DOWN)
                else:
                    self.SetSearchFlag(wx.FR_DOWN)

                if self.GetValue() != self._last:
                    s_cmd = wx.wxEVT_COMMAND_FIND
                else:
                    s_cmd = wx.wxEVT_COMMAND_FIND_NEXT
                self.InsertHistoryItem(self.GetValue())
            else:
                self.SetSearchFlag(wx.FR_DOWN)
                s_cmd = wx.wxEVT_COMMAND_FIND

            self._last = self.GetValue()
            self.FindService.SetQueryString(self.GetValue())
            self.FindService.SetSearchFlags(self._flags)
            self.FindService.OnFind(wx.FindDialogEvent(s_cmd))
        else:
            evt.Skip()
            return

        # Give feedback on whether text was found or not
        if self.FindService.GetLastFound() < 0 and len(self.GetValue()) > 0:
            chgd = self.SetForegroundColour(wx.RED)
            if chgd:
                wx.Bell()  # Beep on the first not found char

        else:
            # ?wxBUG? cant set text back to black after changing color
            # But setting it to this almost black color works. Most likely its
            # due to bit masking but I havent looked at the source so I am not
            # sure
            chgd = self.SetForegroundColour(wx.ColorRGB(0 | 1 | 0))
        self.Refresh()