Browse Source

Fix Test Error, tuned the search string

pull/305/head
Eugenio Parodi 🌶️ 1 year ago
parent
commit
d8587db294
  1. 8
      TermTk/TTkWidgets/combobox.py
  2. 2
      TermTk/TTkWidgets/list_.py
  3. 30
      TermTk/TTkWidgets/listwidget.py

8
TermTk/TTkWidgets/combobox.py

@ -68,11 +68,13 @@ class _TTkComboBoxPopup(TTkResizableFrame):
super().paintEvent(canvas)
if text := self._list.search():
w = self.width()-6
if len(text) > w:
text = f"...{text[w-3:]}"
color = self.currentStyle()['searchColor']
if len(text) > w:
text = TTkString("",TTkColor.BG_BLUE+TTkColor.FG_CYAN)+TTkString(text[-w+1:],color)
else:
text = TTkString(text,color)
canvas.drawText(pos=(1,0), text=f"{text}")
canvas.drawText(pos=(3,0), text=text,color=color)
canvas.drawTTkString(pos=(3,0), text=text)
class TTkComboBox(TTkContainer):
''' TTkComboBox:

2
TermTk/TTkWidgets/list_.py

@ -52,6 +52,7 @@ class TTkList(TTkAbstractScrollArea):
listWidget:TTkListWidget=None,
selectionMode:int=TTkK.SingleSelection,
dragDropMode:TTkK.DragDropMode=TTkK.DragDropMode.NoDragDrop,
showSearch:bool=True,
**kwargs) -> None:
'''
:param listWidget: a custom List Widget to be used instead of the default one.
@ -60,6 +61,7 @@ class TTkList(TTkAbstractScrollArea):
self._listView = listWidget if listWidget else TTkListWidget(
selectionMode=selectionMode,
dragDropMode=dragDropMode,
showSearch=showSearch,
**kwargs|{'parent':None,'visible':True})
super().__init__(**kwargs)
self.setViewport(self._listView)

30
TermTk/TTkWidgets/listwidget.py

@ -521,13 +521,28 @@ class TTkListWidget(TTkAbstractScrollView):
if self._highlighted:
# TTkLog.debug(self._highlighted)
self._highlighted.listItemClicked.emit(self._highlighted)
elif evt.type == TTkK.Character:
# Add this char to the search text
self._searchText += evt.key
self.update()
self.searchModified.emit(self._searchText)
elif evt.type == TTkK.SpecialKey:
if evt.key == TTkK.Key_Tab:
return False
elif ( evt.type == TTkK.SpecialKey and
evt.key == TTkK.Key_Tab ):
return False
elif ( evt.type == TTkK.SpecialKey and
evt.key in (TTkK.Key_Delete,TTkK.Key_Backspace) and
self._searchText ):
# Handle the backspace to remove the last char from the search text
self._searchText = self._searchText[:-1]
self.update()
self.searchModified.emit(self._searchText)
elif ( evt.type == TTkK.SpecialKey and
self._filteredItems):
# Handle the arrow/movement keys
index = 0
if self._highlighted:
self._highlighted._setHighlighted(False)
@ -560,6 +575,7 @@ class TTkListWidget(TTkAbstractScrollView):
self._highlighted = self._filteredItems[index]
self._highlighted._setHighlighted(True)
self._moveToHighlighted()
else:
return False
return True
@ -591,12 +607,12 @@ class TTkListWidget(TTkAbstractScrollView):
def paintEvent(self, canvas):
if self._searchVisibility and self._searchText:
w,h = self.size()
color = self.currentStyle()['searchColor']
if len(self._searchText) > w:
text = f"...{self._searchText[-w-3:]}"
text = TTkString("",TTkColor.BG_BLUE+TTkColor.FG_CYAN)+TTkString(self._searchText[-w+1:],color)
else:
text = self._searchText
color = self.currentStyle()['searchColor']
canvas.drawText(pos=(0,0),text=text, color=color, width=w)
text = TTkString(self._searchText,color)
canvas.drawTTkString(pos=(0,0),text=text, color=color, width=w)

Loading…
Cancel
Save