diff --git a/Makefile b/Makefile index 3abed263..32a45423 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: doc, runGittk, runDemo, build, deploy, buildTest, deployTest, +.PHONY: doc, runGittk, runDemo, build, deploy, buildTest, deployTest, .venv: python3 -m venv .venv diff --git a/README.md b/README.md index 6796c2e0..95b091e2 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,26 @@ + # [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) + +![Linux](https://img.shields.io/badge/-Linux-grey?logo=linux) +![Usage](https://img.shields.io/badge/Usage-Terminal%20User%20Interface-yellow) +![Python](https://img.shields.io/badge/Python-v3.8%5E-green?logo=python) +![pyTermTk_version](https://img.shields.io/github/v/tag/ceccopierangiolieugenio/pyTermTk?label=version) +[![Test Status](https://img.shields.io/github/workflow/status/ceccopierangiolieugenio/pyTermTk/Testing?label=tests)](https://github.com/ceccopierangiolieugenio/pyTermTk/actions?query=workflow%3Atesting) +[![pypi_version](https://img.shields.io/pypi/v/pyTermTk?label=pypi)](https://pypi.org/project/pyTermTk) + #### Python Terminal Toolkit Text-based user interface library ([TUI](https://en.wikipedia.org/wiki/Text-based_user_interface)) Evolved from the discontinued project [pyCuT](https://github.com/ceccopierangiolieugenio/pyCuT) and inspired by a mix of [Qt5](https://www.riverbankcomputing.com/static/Docs/PyQt5/),[GTK](https://pygobject.readthedocs.io/en/latest/), and [tkinter](https://docs.python.org/3/library/tkinter.html) api definition with a touch of personal interpretation -![](https://github.com/ceccopierangiolieugenio/binaryRepo/blob/master/pyTermTk/demo.001.gif?raw=true) +[![screenshot](https://github.com/ceccopierangiolieugenio/binaryRepo/blob/master/pyTermTk/demo.001.gif?raw=true)](https://pypi.org/project/pyTermTk) ## Features -- [x] Basic widgets for [TUI](https://en.wikipedia.org/wiki/Text-based_user_interface) development (Button, Label, checkbox, ...) -- [x] Specialized widgets to improve the usability (Windows, Frames, Tables, ...) -- [x] QT Like Layout system to help arrange the widgets in the terminal -- [ ] UTF-8 and true color support +- Basic widgets for [TUI](https://en.wikipedia.org/wiki/Text-based_user_interface) development (Button, Label, checkbox, ...) +- Specialized widgets to improve the usability (Windows, Frames, Tables, ...) +- QT Like Layout system to help arrange the widgets in the terminal +- True color support +- [TBD] Fullsize/Halfsize UTF-8 characters ## Limitations - Only the key combinations forwarded by the terminal emulator used are detected (ALT,CTRL may not be handled) diff --git a/TermTk/TTkWidgets/splitter.py b/TermTk/TTkWidgets/splitter.py index ddd1842f..b5b94899 100644 --- a/TermTk/TTkWidgets/splitter.py +++ b/TermTk/TTkWidgets/splitter.py @@ -83,6 +83,7 @@ class TTkSplitter(TTkFrame): return minsize, maxsize def _updateGeometries(self): + if not self.isVisible(): return _,_,w,h = self.geometry() sep = self._separators x,y=0,0 diff --git a/TermTk/TTkWidgets/treewidget.py b/TermTk/TTkWidgets/treewidget.py index 28109634..39ff4d9f 100644 --- a/TermTk/TTkWidgets/treewidget.py +++ b/TermTk/TTkWidgets/treewidget.py @@ -130,7 +130,7 @@ class TTkTreeWidget(TTkTableView): if item.parent() is None: self._topLevelItems.addChild(item) displayedItems = item.data().copy() - displayTreeItem = _TTkDisplayedTreeItem(text=displayedItems[0], id=0, depth=depth, treeWidgetItem=item) + displayTreeItem = _TTkDisplayedTreeItem(text=displayedItems[0], id=0, depth=depth, treeWidgetItem=item) displayTreeItem._clicked.connect(self._controlClicked) displayedItems[0] = displayTreeItem if index == -1: @@ -144,4 +144,4 @@ class TTkTreeWidget(TTkTableView): def setHeaderLabels(self, labels): columns = [-1]*len(labels) self.setColumnSize(columns) - self.setHeader(labels) \ No newline at end of file + self.setHeader(labels) diff --git a/TermTk/TTkWidgets/widget.py b/TermTk/TTkWidgets/widget.py index cdfdab62..3e106906 100644 --- a/TermTk/TTkWidgets/widget.py +++ b/TermTk/TTkWidgets/widget.py @@ -186,7 +186,7 @@ class TTkWidget(TMouseEvents,TKeyEvents): for child in item.zSortedItems: ix, iy, iw, ih = item.geometry() # child outside the bound - if ix+iw < lx and ix > lx+lw and iy+ih < ly and y > ly+lh: continue + if ix+iw < lx and ix > lx+lw and iy+ih < ly and iy > ly+lh: continue # Reduce the bound to the minimum visible bx = max(ix,lx) by = max(iy,ly) diff --git a/TermTk/libbpytop/colors.py b/TermTk/libbpytop/colors.py index 87791b35..d5b0464b 100644 --- a/TermTk/libbpytop/colors.py +++ b/TermTk/libbpytop/colors.py @@ -29,6 +29,7 @@ except Exception as e: from TermTk.libbpytop.term import Term from TermTk.TTkCore.constant import TTkK from TermTk.TTkCore.cfg import TTkCfg +from TermTk.TTkCore.log import TTkLog # Ansi Escape Codes: @@ -71,7 +72,7 @@ class Color: else: color = f'{Color.truecolor_to_256(rgb=(int(hexa[1:3], base=16), int(hexa[3:5], base=16), int(hexa[5:7], base=16)), depth=depth)}' except ValueError as e: - ttk.TTkLog.error(f'{e}') + TTkLog.error(f'{e}') else: if TTkCfg.color_depth is TTkK.DEP_24: diff --git a/demo/tlogg.py b/demo/tlogg.py index f0e12d2f..4062b728 100755 --- a/demo/tlogg.py +++ b/demo/tlogg.py @@ -89,10 +89,12 @@ class _FileBuffer(): return indexes class _FileViewer(TTkAbstractScrollView): - __slots__ = ('_fileBuffer', '_indexes', '_indexesMark') + __slots__ = ('_fileBuffer', '_indexes', '_indexesMark', '_indexexSearched', '_selected') def __init__(self, *args, **kwargs): self._indexes = None self._indexesMark = [] + self._indexesSearched = [] + self._selected = None TTkAbstractScrollView.__init__(self, *args, **kwargs) self._name = kwargs.get('name' , '_FileViewer' ) self._fileBuffer = kwargs.get('filebuffer') @@ -110,6 +112,9 @@ class _FileViewer(TTkAbstractScrollView): self._indexesMark = indexes self.viewChanged.emit() + def searchedIndexes(self, indexes): + self._indexesSearched = indexes + self.viewChanged.emit() def viewFullAreaSize(self) -> (int, int): if self._indexes is None: @@ -123,11 +128,16 @@ class _FileViewer(TTkAbstractScrollView): def viewDisplayedSize(self) -> (int, int): return self.size() + def mousePressEvent(self, evt): + x,y = evt.x, evt.y + ox,oy = self.getViewOffsets() + return False + def paintEvent(self): ox,oy = self.getViewOffsets() if self._indexes is None: - for i in range(self.height()): - if (i+oy) in self._indexesMark: + for i in range(min(self.height(),self._fileBuffer.getLen()-oy)): + if (i+oy) in self._indexesSearched: color = TTkColor.fg("#ff0000") else: color = TTkColor.fg("#0000ff") @@ -135,7 +145,7 @@ class _FileViewer(TTkAbstractScrollView): self.getCanvas().drawText(pos=(2,i), text=self._fileBuffer.getLine(i+oy).replace('\t',' ').replace('\n','') ) else: for i in range(min(self.height(),len(self._indexes))): - if self._indexes[i+oy] in self._indexesMark: + if self._indexes[i+oy] in self._indexesSearched: color = TTkColor.fg("#ff0000") else: color = TTkColor.fg("#0000ff") @@ -209,8 +219,8 @@ def main(): searchtext = self.tb.text() indexes = self.fb.search(searchtext) self.bvp.showIndexes(indexes) - self.bvp.markIndexes(indexes) - self.tvp.markIndexes(indexes) + self.bvp.searchedIndexes(indexes) + self.tvp.searchedIndexes(indexes) _s = _search(bls_textbox,fileBuffer,topViewer.viewport(),bottomViewport) bls_search.clicked.connect(_s.search) bls_textbox.returnPressed.connect(_s.search)