Skip to content

Commit

Permalink
Merge pull request #302 from ceccopierangiolieugenio/301-interactive-…
Browse files Browse the repository at this point in the history
…string-filter-in-the-list-widget

301 interactive string filter in the list widget
  • Loading branch information
ceccopierangiolieugenio authored Jan 7, 2025
2 parents 1e0bab1 + 0877efc commit 3fae6f5
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 73 deletions.
9 changes: 9 additions & 0 deletions TermTk/TTkAbstract/abstractscrollview.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ def __init__(self, **kwargs) -> None:
def viewDisplayedSize(self) -> tuple[int,int]:
return self.size()

def viewFullAreaSize(self) -> tuple[int,int]:
t,b,l,r = self.getPadding()
_,_,w,h = self.layout().fullWidgetAreaGeometry()
return w+l+r, h+t+b

@pyTTkSlot(int, int)
def viewMoveTo(self, x: int, y: int):
fw, fh = self.viewFullAreaSize()
Expand Down Expand Up @@ -216,6 +221,10 @@ def update(self, repaint=True, updateLayout=False, updateParent=False):
self.viewChanged.emit()
return super().update(repaint, updateLayout, updateParent)

def setPadding(self, top, bottom, left, right) -> None:
super().setPadding(top, bottom, left, right)
self.viewChanged.emit()

class TTkAbstractScrollViewLayout(TTkLayout, TTkAbstractScrollViewInterface):
'''
:py:class:`TTkAbstractScrollViewLayout`
Expand Down
4 changes: 0 additions & 4 deletions TermTk/TTkWidgets/TTkPickers/textpicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ def _viewChangedHandler(self):
x,y = self.getViewOffsets()
self.layout().setOffset(-x,-y)

def viewFullAreaSize(self) -> tuple[int,int]:
_,_,w,h = self.layout().fullWidgetAreaGeometry()
return w , h

def maximumWidth(self): return 0x10000
def maximumHeight(self): return 0x10000
def minimumWidth(self): return 0
Expand Down
56 changes: 49 additions & 7 deletions TermTk/TTkWidgets/combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,41 @@
from TermTk.TTkWidgets.lineedit import TTkLineEdit
from TermTk.TTkWidgets.resizableframe import TTkResizableFrame


class _TTkComboBoxPopup(TTkResizableFrame):
classStyle = TTkResizableFrame.classStyle
classStyle['default'] |= {'searchColor': TTkColor.fg("#FFFF00")}

__slots__ = ('_list',
#exportedMethods
'setCurrentRow',
#exportedSignals
'textClicked')
def __init__(self, *, items:list[str], **kwargs) -> None:
super().__init__(**kwargs|{'layout':TTkGridLayout()})
self._list:TTkList = TTkList(parent=self, showSearch=False)
self._list.addItems(items)
self._list.searchModified.connect(self.update)

self.textClicked = self._list.textClicked
self.setCurrentRow = self._list.setCurrentRow

# def setFocus(self) -> None:
# self._list.viewport().setFocus()

def keyEvent(self, evt:TTkKeyEvent) -> bool:
return self._list.viewport().keyEvent(evt)

def paintEvent(self, canvas:TTkCanvas) -> None:
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']
canvas.drawText(pos=(1,0), text=f"╼ {text} ╾")
canvas.drawText(pos=(3,0), text=text,color=color)

class TTkComboBox(TTkContainer):
''' TTkComboBox:
Expand Down Expand Up @@ -333,16 +368,23 @@ def _pressEvent(self) -> bool:
if frameHeight > 20: frameHeight = 20
if frameWidth < 20: frameWidth = 20

self._popupFrame = TTkResizableFrame(layout=TTkGridLayout(), size=(frameWidth,frameHeight))
self._popupFrame = _TTkComboBoxPopup(items=self._list, size=(frameWidth,frameHeight))
TTkHelper.overlay(self, self._popupFrame, 0, 0)
listw = TTkList(parent=self._popupFrame)
# TTkLog.debug(f"{self._list}")
listw.addItems(self._list)
if self._id != -1:
listw.setCurrentRow(self._id)
listw.textClicked.connect(self._callback)
listw.viewport().setFocus()
self._popupFrame.setCurrentRow(self._id)
self._popupFrame.textClicked.connect(self._callback)
self.update()

# self._popupFrame = TTkResizableFrame(layout=TTkGridLayout(), size=(frameWidth,frameHeight))
# TTkHelper.overlay(self, self._popupFrame, 0, 0)
# listw = TTkList(parent=self._popupFrame)
# # TTkLog.debug(f"{self._list}")
# listw.addItems(self._list)
# if self._id != -1:
# listw.setCurrentRow(self._id)
# listw.textClicked.connect(self._callback)
# listw.viewport().setFocus()
# self.update()
return True

def wheelEvent(self, evt:TTkMouseEvent) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion TermTk/TTkWidgets/list_.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ class TTkList(TTkAbstractScrollArea):
__slots__ = tuple(
['_listView'] +
(_forwardedSignals:=[ # Forwarded Signals From TTkTable
'itemClicked', 'textClicked']) +
'itemClicked', 'textClicked', 'searchModified']) +
(_forwardedMethods:=[ # Forwarded Methods From TTkTable
'items',
'dragDropMode', 'setDragDropMode',
'addItem', 'addItemAt', 'addItems', 'addItemsAt',
'indexOf', 'itemAt', 'moveItem',
'removeAt', 'removeItem', 'removeItems',
'selectionMode', 'setSelectionMode', 'selectedItems', 'selectedLabels',
'search', 'setSearch', 'searchVisibility', 'setSearchVisibility',
'setCurrentRow', 'setCurrentItem'])
)
_forwardWidget = TTkListWidget
Expand Down
Loading

0 comments on commit 3fae6f5

Please sign in to comment.