Skip to content

Commit

Permalink
Merge branch 'main' into 311-add-configurable-ruler-in-the-ttktextedit
Browse files Browse the repository at this point in the history
  • Loading branch information
ceccopierangiolieugenio committed Jan 23, 2025
2 parents 6148ecb + 7050c8f commit e8cea12
Show file tree
Hide file tree
Showing 117 changed files with 462 additions and 170 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"name": "Python: DumbPaintTool",
"type": "debugpy",
"request": "launch",
"program": "tools/dumbPaintTool.py",
"program": "apps/dumbPaintTool.py",
"console": "integratedTerminal",
"justMyCode": true,
"env": {
Expand All @@ -73,7 +73,7 @@
"name": "Python: DumbPaintTool File",
"type": "debugpy",
"request": "launch",
"program": "tools/dumbPaintTool.py",
"program": "apps/dumbPaintTool.py",
"console": "integratedTerminal",
"justMyCode": true,
"env": {
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ Be inspired by [the Tutorials](https://github.com/ceccopierangiolieugenio/pyTerm
## [Api Definitions](https://ceccopierangiolieugenio.github.io/pyTermTk-Docs/index.html#api-reference)
Don't get bored by the [Api Definitions](https://ceccopierangiolieugenio.github.io/pyTermTk-Docs/index.html#api-reference)

## [ttkDesigner](https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/tools/ttkDesigner)
## [ttkDesigner](https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/apps/ttkDesigner)
Smell deliciousness with the official [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) tool for designing and building Text-based user interfaces ([TUI](https://en.wikipedia.org/wiki/Text-based_user_interface)s)

## [theDumbPaintTool](https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/tools/dumbPaintTool)
## [theDumbPaintTool](https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/apps/dumbPaintTool)
Unravel your inner artist with [The Terminal ASCII Photoshop](https://ceccopierangiolieugenio.itch.io/dumb-paint-tool)

---
Expand Down Expand Up @@ -100,7 +100,7 @@ python3 tests/test.ui.018.TextEdit.Pygments.py README.md
---

## Projects using [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk)
- [ttkDesigner](https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/tools/ttkDesigner) - the official [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) tool for designing and building Text-based user interfaces ([TUI](https://en.wikipedia.org/wiki/Text-based_user_interface)s)
- [ttkDesigner](https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/apps/ttkDesigner) - the official [pyTermTk](https://github.com/ceccopierangiolieugenio/pyTermTk) tool for designing and building Text-based user interfaces ([TUI](https://en.wikipedia.org/wiki/Text-based_user_interface)s)
- [the DumbPaintTool](https://ceccopierangiolieugenio.itch.io/dumb-paint-tool) - The Terminal ASCII Photoshop
- [tlogg](https://github.com/ceccopierangiolieugenio/tlogg) - A fast, advanced log explorer.
- [ttkode](https://github.com/ceccopierangiolieugenio/ttkode) - TerminalToolKit (Studio) Code (editor)
Expand Down
2 changes: 1 addition & 1 deletion TermTk/TTkAbstract/abstractscrollview.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ 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
2 changes: 1 addition & 1 deletion TermTk/TTkCore/TTkTerm/inputmouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, x: int, y: int, key: int, evt: int, mod: int, tap: int, raw:
self.mod = mod
self.raw = raw
self.tap = tap

def pos(self) -> tuple[int,int]:
'''
Returns the position of the mouse cursor relative to the current widget.
Expand Down
2 changes: 1 addition & 1 deletion TermTk/TTkCore/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def drawTTkString(self, pos, text, width=None, color=TTkColor.RST, alignment=TTk
self._data[y][x+a:x+b] = txt[a:b]
if forceColor:
colors=[color]*len(colors)
else:
else:
for i in range(a,b):
if color != TTkColor.RST:
self._colors[y][x+i] = (colors[i] | color).mod(x+i,y)
Expand Down
2 changes: 1 addition & 1 deletion TermTk/TTkCore/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def __or__(self, other):
c = self.copy()
c._clean = False
return other + c

# self + other
def __add__(self, other):
# TTkLog.debug("__add__")
Expand Down
19 changes: 9 additions & 10 deletions TermTk/TTkCore/filebuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@
from TermTk.TTkCore.log import TTkLog
from TermTk.TTkCore.signal import pyTTkSignal

'''
w1 w3 w2 w5
Buffer |----|----|----|----| cache buffer
| \ / \
| x \
| / \ \
Pages | 0 | 2 | 1 |None| 3 |None| index to buffer
File |----|----|----|----|----|----| view as list of windows
w1 w2 w3 w4 w5 w6
'''
# w1 w3 w2 w5
# Buffer |----|----|----|----| cache buffer
# | \ / \
# | x \
# | / \ \
# Pages | 0 | 2 | 1 |None| 3 |None| index to buffer
# File |----|----|----|----|----|----| view as list of windows
# w1 w2 w3 w4 w5 w6

class TTkFileBuffer():
class _Page:
__slots__ = ('_page', '_size', '_buffer')
Expand Down
2 changes: 1 addition & 1 deletion TermTk/TTkCore/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _process_msg(mode: int, msg: str):
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe,1)
if len(calframe) > 2:
ctx = _TTkContext(calframe[2])
ctx = _TTkContext(calframe[2])
for txt in str(msg).split('\n'):
cb(mode, ctx, txt)

Expand Down
38 changes: 33 additions & 5 deletions TermTk/TTkCore/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,29 @@
__all__ = ['pyTTkSlot', 'pyTTkSignal']

# from typing import TypeVar, TypeVarTuple, Generic, List
from inspect import getfullargspec
from inspect import getfullargspec, iscoroutinefunction
from types import LambdaType
from threading import Lock
import asyncio

import importlib.util

if importlib.util.find_spec('pyodideProxy'):
def _run_coroutines(coros):
for call in coros:
asyncio.create_task(call)
else:
from threading import Thread
import asyncio

def _async_runner(coros):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(asyncio.gather(*coros))
loop.close()

def _run_coroutines(coros):
Thread(target=_async_runner, args=(coros,)).start()

def pyTTkSlot(*args):
def pyTTkSlot_d(func):
Expand All @@ -73,7 +93,7 @@ def pyTTkSlot_d(func):
# class pyTTkSignal(Generic[*Ts]):
class pyTTkSignal():
_signals = []
__slots__ = ('_types', '_connected_slots', '_mutex')
__slots__ = ('_types', '_connected_slots', '_connected_async_slots', '_mutex')
def __init__(self, *args, **kwargs) -> None:
# ref: http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html#PyQt5.QtCore.pyqtSignal

Expand All @@ -87,6 +107,7 @@ def __init__(self, *args, **kwargs) -> None:
# an unbound signal
self._types = args
self._connected_slots = {}
self._connected_async_slots = {}
self._mutex = Lock()
pyTTkSignal._signals.append(self)

Expand Down Expand Up @@ -122,8 +143,12 @@ def connect(self, slot):
if a!=b and not issubclass(a,b):
error = "Decorated slot has no signature compatible: "+slot.__name__+str(slot._TTkslot_attr)+" != signal"+str(self._types)
raise TypeError(error)
if slot not in self._connected_slots:
self._connected_slots[slot]=slice(nargs)
if iscoroutinefunction(slot):
if slot not in self._connected_async_slots:
self._connected_async_slots[slot]=slice(nargs)
else:
if slot not in self._connected_slots:
self._connected_slots[slot]=slice(nargs)

def disconnect(self, *args, **kwargs) -> None:
for slot in args:
Expand All @@ -137,6 +162,9 @@ def emit(self, *args, **kwargs) -> None:
raise TypeError(error)
for slot,sl in self._connected_slots.copy().items():
slot(*args[sl], **kwargs)
if self._connected_async_slots:
coros = [slot(*args[sl], **kwargs) for slot,sl in self._connected_async_slots.copy().items()]
_run_coroutines(coros)
self._mutex.release()

def clear(self):
Expand All @@ -150,4 +178,4 @@ def clearAll():
def forward(self):
def _ret(*args, **kwargs) -> None:
self.emit(*args, **kwargs)
return _ret
return _ret
2 changes: 1 addition & 1 deletion TermTk/TTkCore/ttk.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import threading
import platform

from TermTk.TTkCore.drivers import *
from TermTk.TTkCore.drivers import TTkSignalDriver
from TermTk.TTkCore.TTkTerm.input import TTkInput
from TermTk.TTkCore.TTkTerm.inputkey import TTkKeyEvent
from TermTk.TTkCore.TTkTerm.inputmouse import TTkMouseEvent
Expand Down
12 changes: 6 additions & 6 deletions TermTk/TTkGui/drag.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def data(self) -> Any:
:rtype: Any
'''
return self._data

def setHotSpot(self, pos:tuple[int,int]) -> None:
'''
Sets the position of the hot spot relative to the top-left corner of the pixmap used to the point specified by hotspot.
:param pos: the hotspot position
:type pos: tuple[int,int]
'''
'''
self._hotSpot = pos

def hotSpot(self) -> tuple[int,int]:
Expand All @@ -99,7 +99,7 @@ def hotSpot(self) -> tuple[int,int]:
:rtype: tuple[int,int]
'''
return self._hotSpot

class TTkDnDEvent(TTkDnD):
'''
Drag and Drop event class.
Expand All @@ -122,7 +122,7 @@ def pos(self) -> tuple[int,int]:
:rtype: tuple[int,int]
'''
return self._pos

class TTkDrag(TTkDnD):
__slots__ = ('_pixmap', '_showPixmap')
def __init__(self, **kwargs) -> None:
Expand Down Expand Up @@ -183,7 +183,7 @@ def exec(self) -> None:
Starts the drag operation.
'''
TTkHelper.dndInit(self)

def _toDropEvent(self, pos:tuple[int,int]) -> TTkDnDEvent:
ret = TTkDnDEvent(data=self._data, hotspot=self._hotSpot, pos=pos)
return ret
Expand Down Expand Up @@ -232,6 +232,6 @@ def getDropEvent(self, evt:TTkMouseEvent) -> TTkDnDEvent:
:type evt: :py:class:`TTkMouseEvent`
:return: The Drag and Drop event
:rtype: :py:class:`TTkDnDEvent`
:rtype: :py:class:`TTkDnDEvent`
'''
return self._toDropEvent((evt.x, evt.y))
4 changes: 2 additions & 2 deletions TermTk/TTkGui/textcursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def anchor(self) -> _CP:

def position(self) -> _CP:
return self._properties[self._cID].position

def cursors(self) -> list[_CP]:
return self._properties

Expand Down Expand Up @@ -601,7 +601,7 @@ def _getBlinkingCursors(self, fr:int, to:int, lines, color:TTkColor) -> list[TTk
if len(self._properties)>1:
for p in self._properties:
cp = p.position
if not 0<=(cp.line-fr)<len(ret): continue
if not 0<=(cp.line-fr)<len(ret): continue
ret[cp.line-fr] = ret[cp.line-fr].setColor(color=color+TTkColor.BLINKING, posFrom=cp.pos, posTo=cp.pos+1)
if cp.pos == len(ret[cp.line-fr]):
ret[cp.line-fr] = ret[cp.line-fr]+TTkString('↵',color+TTkColor.BLINKING)
Expand Down
2 changes: 1 addition & 1 deletion TermTk/TTkTestWidgets/testabstractscroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def paintEvent(self, canvas):

def mousePressEvent(self, evt:TTkMouseEvent) -> bool:
return True

def mouseReleaseEvent(self, evt:TTkMouseEvent) -> bool:
return True

Expand Down
2 changes: 1 addition & 1 deletion TermTk/TTkUiTools/uiloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class TTkUiLoader():
'''TTkUiLoader
.. _ttkDesigner: https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/tools/ttkDesigner
.. _ttkDesigner: https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/apps/ttkDesigner
`ttkdesigner Tutorial <https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit>`_
Expand Down
6 changes: 3 additions & 3 deletions TermTk/TTkWidgets/combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
class _TTkComboBoxPopup(TTkResizableFrame):
classStyle = TTkResizableFrame.classStyle
classStyle['default'] |= {'searchColor': TTkColor.fg("#FFFF00")}

__slots__ = ('_list',
#exportedMethods
'setCurrentRow',
Expand All @@ -57,13 +57,13 @@ def __init__(self, *, items:list[str], **kwargs) -> None:

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():
Expand Down
Loading

0 comments on commit e8cea12

Please sign in to comment.