Adding support for ctrl+backspace in searchbars
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import wx
|
||||
import gui.utils.color as colorUtils
|
||||
import gui.utils.draw as drawUtils
|
||||
from gui.utils.helpers_wxPython import HandleCtrlBackspace
|
||||
|
||||
SearchButton, EVT_SEARCH_BTN = wx.lib.newevent.NewEvent()
|
||||
CancelButton, EVT_CANCEL_BTN = wx.lib.newevent.NewEvent()
|
||||
@@ -55,7 +56,7 @@ class PFSearchBox(wx.Window):
|
||||
|
||||
self.EditBox.Bind(wx.EVT_SET_FOCUS, self.OnEditSetFocus)
|
||||
self.EditBox.Bind(wx.EVT_KILL_FOCUS, self.OnEditKillFocus)
|
||||
|
||||
self.EditBox.Bind(wx.EVT_KEY_DOWN, self.OnKeyPress)
|
||||
self.EditBox.Bind(wx.EVT_TEXT, self.OnText)
|
||||
self.EditBox.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter)
|
||||
|
||||
@@ -83,6 +84,12 @@ class PFSearchBox(wx.Window):
|
||||
self.Clear()
|
||||
event.Skip()
|
||||
|
||||
def OnKeyPress(self, event):
|
||||
if event.RawControlDown() and event.GetKeyCode() == wx.WXK_BACK:
|
||||
HandleCtrlBackspace(self.EditBox)
|
||||
else:
|
||||
event.Skip()
|
||||
|
||||
def Clear(self):
|
||||
self.EditBox.Clear()
|
||||
# self.EditBox.ChangeValue(self.descriptiveText)
|
||||
|
||||
@@ -11,6 +11,7 @@ import gui.utils.fonts as fonts
|
||||
from .events import FitSelected, SearchSelected, ImportSelected, Stage1Selected, Stage2Selected, Stage3Selected
|
||||
from gui.bitmap_loader import BitmapLoader
|
||||
from service.fit import Fit
|
||||
from gui.utils.helpers_wxPython import HandleCtrlBackspace
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
@@ -72,7 +73,7 @@ class NavigationPanel(SFItem.SFBrowserItem):
|
||||
|
||||
# self.BrowserSearchBox.Bind(wx.EVT_TEXT_ENTER, self.OnBrowserSearchBoxEnter)
|
||||
# self.BrowserSearchBox.Bind(wx.EVT_KILL_FOCUS, self.OnBrowserSearchBoxLostFocus)
|
||||
self.BrowserSearchBox.Bind(wx.EVT_KEY_DOWN, self.OnBrowserSearchBoxEsc)
|
||||
self.BrowserSearchBox.Bind(wx.EVT_KEY_DOWN, self.OnBrowserSearchBoxKeyPress)
|
||||
self.BrowserSearchBox.Bind(wx.EVT_TEXT, self.OnScheduleSearch)
|
||||
|
||||
self.SetMinSize(size)
|
||||
@@ -103,9 +104,11 @@ class NavigationPanel(SFItem.SFBrowserItem):
|
||||
def OnBrowserSearchBoxLostFocus(self, event):
|
||||
self.BrowserSearchBox.Show(False)
|
||||
|
||||
def OnBrowserSearchBoxEsc(self, event):
|
||||
def OnBrowserSearchBoxKeyPress(self, event):
|
||||
if event.GetKeyCode() == wx.WXK_ESCAPE:
|
||||
self.BrowserSearchBox.Show(False)
|
||||
elif event.RawControlDown() and event.GetKeyCode() == wx.WXK_BACK:
|
||||
HandleCtrlBackspace(self.BrowserSearchBox)
|
||||
else:
|
||||
event.Skip()
|
||||
|
||||
|
||||
@@ -6,3 +6,23 @@ def YesNoDialog(question='Are you sure you want to do this?', caption='Yes or no
|
||||
result = dlg.ShowModal() == wx.ID_YES
|
||||
dlg.Destroy()
|
||||
return result
|
||||
|
||||
|
||||
def HandleCtrlBackspace(textControl):
|
||||
"""
|
||||
Handles the behavior of Windows ctrl+space
|
||||
deletes everything from the cursor to the left,
|
||||
up to the next whitespace.
|
||||
"""
|
||||
curPos = textControl.GetInsertionPoint()
|
||||
searchText = textControl.GetValue()
|
||||
foundChar = False
|
||||
for startIndex in range(curPos, -1, -1):
|
||||
if startIndex - 1 < 0:
|
||||
break
|
||||
if searchText[startIndex - 1] != " ":
|
||||
foundChar = True
|
||||
elif foundChar:
|
||||
break
|
||||
textControl.Remove(startIndex, curPos)
|
||||
textControl.SetInsertionPoint(startIndex)
|
||||
Reference in New Issue
Block a user