Browse Source

Improved tlogg

pull/5/head
Eugenio Parodi 5 years ago
parent
commit
2a7d75836c
  1. 2
      Makefile
  2. 20
      README.md
  3. 1
      TermTk/TTkWidgets/splitter.py
  4. 4
      TermTk/TTkWidgets/treewidget.py
  5. 2
      TermTk/TTkWidgets/widget.py
  6. 3
      TermTk/libbpytop/colors.py
  7. 22
      demo/tlogg.py

2
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

20
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)

1
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

4
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)
self.setHeader(labels)

2
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)

3
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:

22
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)

Loading…
Cancel
Save