Skip to content

Commit

Permalink
Merge pull request #95 from ceccopierangiolieugenio/TTkTreeDom
Browse files Browse the repository at this point in the history
Dom Tree Viewer
  • Loading branch information
ceccopierangiolieugenio authored Jan 10, 2023
2 parents e432f52 + d889773 commit 5626955
Show file tree
Hide file tree
Showing 40 changed files with 1,229 additions and 282 deletions.
14 changes: 7 additions & 7 deletions TermTk/TTkCore/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ def drawBoxTitle(self, pos, size, text, align=TTkK.CENTER_ALIGN, color=TTkColor.
if w < 4: return
gg = TTkCfg.theme.grid[grid]

if len(text) > w-4:
text = text[:w-4]
if text.termWidth() > w-4:
text = text.substring(to=w-4)
if align == TTkK.CENTER_ALIGN:
l = (w-2-len(text))//2
l = (w-2-text.termWidth())//2
elif align == TTkK.LEFT_ALIGN:
l=1
else:
l = w-2-len(text)
r = l+len(text)+1
l = w-2-text.termWidth()
r = l+text.termWidth()+1

self._set(y,l, gg[7], color)
self._set(y,r, gg[6], color)
Expand Down Expand Up @@ -583,14 +583,14 @@ def execPaint(self, winw, winh):
self._canvas: |----|xxxxxx|----------|
'''
def paintCanvas(self, canvas, geom, slice, bound):
# TTkLog.debug(f"PaintCanvas:{(x,y,w,h)}")
# TTkLog.debug(f"PaintCanvas:{geom=} {bound=} {self._widget._name=} {self._data[0] if self._data else 1234}")
x, y, w, h = geom
bx,by,bw,bh = bound
# out of bound
if not self._visible: return
if not canvas._visible: return
if canvas._width==0 or canvas._height==0: return
if x+w < bx or y+h<by or bx+bw-1<x or by+bh-1<y:
if x+w<=bx or y+h<=by or bx+bw-1<x or by+bh-1<y:
return

x = min(x,self._width-1)
Expand Down
59 changes: 34 additions & 25 deletions TermTk/TTkCore/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TTkConstant:
DEP_24: int = 0x18

# Color Type
class ColorType:
class ColorType(int):
Foreground = 0x01
Background = 0x02
Modifier = 0x03
Expand Down Expand Up @@ -78,7 +78,7 @@ class ColorType:
HORIZONTAL = 0x01
VERTICAL = 0x02

class ScrollBarPolicy:
class ScrollBarPolicy(int):
ScrollBarAsNeeded = 0x00
ScrollBarAlwaysOff = 0x01
ScrollBarAlwaysOn = 0x02
Expand All @@ -87,7 +87,7 @@ class ScrollBarPolicy:
ScrollBarAlwaysOff = ScrollBarPolicy.ScrollBarAlwaysOff
ScrollBarAlwaysOn = ScrollBarPolicy.ScrollBarAlwaysOn

class CheckState:
class CheckState(int):
''' This class type is used to describe the check status.
.. autosummary::
Expand All @@ -103,16 +103,25 @@ class CheckState:
PartiallyChecked = CheckState.PartiallyChecked
Checked = CheckState.Checked

class InsertPolicy:
NoInsert = 0x00 # The string will not be inserted into the combobox.
InsertAtTop = 0x01 # The string will be inserted as the first item in the combobox.
# InsertAtCurrent = 0x02 # The current item will be replaced by the string.
InsertAtBottom = 0x03 # The string will be inserted after the last item in the combobox.
# InsertAfterCurrent = 0x04 # The string is inserted after the current item in the combobox.
# InsertBeforeCurrent = 0x05 # The string is inserted before the current item in the combobox.
# InsertAlphabetically = 0x06 # The string is inserted in the alphabetic order in the combobox.

class ChildIndicatorPolicy:
class InsertPolicy(int):
'''Specifies what the :class:`~TermTk.TTkWidgets.combobox.TTkComboBox` should do when a new string is entered by the user.
'''
NoInsert = 0x00
'''The string will not be inserted into the combobox.'''
InsertAtTop = 0x01
'''The string will be inserted as the first item in the combobox.'''
# InsertAtCurrent = 0x02
# '''The current item will be replaced by the string.'''
InsertAtBottom = 0x03
'''The string will be inserted after the last item in the combobox.'''
# InsertAfterCurrent = 0x04
# '''The string is inserted after the current item in the combobox.'''
# InsertBeforeCurrent = 0x05
# '''The string is inserted before the current item in the combobox.'''
# InsertAlphabetically = 0x06
# '''The string is inserted in the alphabetic order in the combobox.'''

class ChildIndicatorPolicy(int):
ShowIndicator = 0x00 #The controls for expanding and collapsing will be shown for this item even if there are no children.
DontShowIndicator = 0x01 #The controls for expanding and collapsing will never be shown even if there are children. If the node is forced open the user will not be able to expand or collapse the item.
DontShowIndicatorWhenChildless = 0x02 #The controls for expanding and collapsing will be shown if the item contains children.
Expand All @@ -121,7 +130,7 @@ class ChildIndicatorPolicy:
DontShowIndicator = ChildIndicatorPolicy.DontShowIndicator
DontShowIndicatorWhenChildless = ChildIndicatorPolicy.DontShowIndicatorWhenChildless

class SortOrder:
class SortOrder(int):
AscendingOrder = 0x00
DescendingOrder = 0x01

Expand All @@ -137,7 +146,7 @@ class SortOrder:
# InsertAlphabetically = InsertPolicy.InsertAlphabetically

# Keys
class MouseKey():
class MouseKey(int):
'''Input Mouse Key
Events reported by :class:`~TermTk.TTkCore.TTkTerm.inputmouse.TTkMouseEvent` -> :class:`~TermTk.TTkCore.TTkTerm.inputmouse.TTkMouseEvent.key`
Expand Down Expand Up @@ -165,7 +174,7 @@ class MouseKey():
MiddleButton = MouseKey.MiddleButton
Wheel = MouseKey.Wheel

class WrapMode():
class WrapMode(int):
'''Those constants describes how text is wrapped in a document.'''
# NoWrap = 0x00
# '''Text is not wrapped at all.'''
Expand All @@ -184,7 +193,7 @@ class WrapMode():
WrapAnywhere = WrapMode.WrapAnywhere
WrapAtWordBoundaryOrAnywhere = WrapMode.WrapAtWordBoundaryOrAnywhere

class LineWrapMode():
class LineWrapMode(int):
NoWrap = 0x00
WidgetWidth = 0x01
FixedWidth = 0x03
Expand All @@ -195,7 +204,7 @@ class LineWrapMode():


# Events
class MouseEvent():
class MouseEvent(int):
'''Input Mouse Event
Events reported by :class:`~TermTk.TTkCore.TTkTerm.inputmouse.TTkMouseEvent` -> :class:`~TermTk.TTkCore.TTkTerm.inputmouse.TTkMouseEvent.evt`
Expand Down Expand Up @@ -231,8 +240,8 @@ class MouseEvent():
Input_Password = 0x04

# Alignment
class Alignment:
''' This class type is used to describe alignment.
class Alignment(int):
''' This type is used to describe alignment.
.. autosummary::
NONE
Expand All @@ -257,7 +266,7 @@ class Alignment:
CENTER_ALIGN = Alignment.CENTER_ALIGN
JUSTIFY = Alignment.JUSTIFY

class FileMode():
class FileMode(int):
AnyFile = 0 #The name of a file, whether it exists or not.
# ExistingFile = 1 #The name of a single existing file.
Directory = 2 #The name of a directory. Both files and directories are displayed. However, the native Windows file dialog does not support displaying files in the directory chooser.
Expand All @@ -269,7 +278,7 @@ class FileMode():
# ExistingFiles = FileMode.ExistingFiles

# LayoutItem Types
class LayoutItemTypes:
class LayoutItemTypes(int):
'''Types used internally in :mod:`~TermTk.TTkLayouts`'''
LayoutItem = 0x01
'''Item Type Layout'''
Expand All @@ -280,7 +289,7 @@ class LayoutItemTypes:
LayoutItem = LayoutItemTypes.LayoutItem
WidgetItem = LayoutItemTypes.WidgetItem

class WindowFlag:
class WindowFlag(int):
# FramelessWindowHint = 0x00000800
# ''' Produces a borderless window.'''
# CustomizeWindowHint = 0x02000000
Expand Down Expand Up @@ -308,7 +317,7 @@ class WindowFlag:
# WindowStaysOnBottomHint = 0x04000000
# ''' Informs the window system that the window should stay on bottom of all other windows.'''

class KeyType():
class KeyType(int):
'''Input Key Types
Key type reported by :class:`~TermTk.TTkCore.TTkTerm.inputkey.TTkKeyEvent` -> :class:`~TermTk.TTkCore.TTkTerm.inputkey.TTkKeyEvent.key`
Expand All @@ -322,7 +331,7 @@ class KeyType():
SpecialKey = KeyType.SpecialKey


class KeyModifier():
class KeyModifier(int):
'''Input :class:`~TermTk.TTkCore.constant.TTkConstant.KeyType.SpecialKey` modifiers
Modifier reported by :class:`~TermTk.TTkCore.TTkTerm.inputkey.TTkKeyEvent` -> :class:`~TermTk.TTkCore.TTkTerm.inputkey.TTkKeyEvent.mod`
Expand Down
7 changes: 3 additions & 4 deletions TermTk/TTkCore/ttk.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _mouseCursor(TTkWidget):
__slots__ = ('_cursor','_color')
def __init__(self, input):
super().__init__()
self._name = 'mouseCursor'
self._name = 'MouseCursor'
self._cursor = '✠'
self._color = TTkColor.RST
self.resize(1,1)
Expand Down Expand Up @@ -85,8 +85,7 @@ def paintEvent(self):
'_lastMultiTap')

def __init__(self, *args, **kwargs):
TTkWidget.__init__(self, *args, **kwargs)
self._name = kwargs.get('name' , 'TTk' )
super().__init__(*args, **kwargs)
self._input = TTkInput()
self._input.inputEvent.connect(self._processInput)
self._title = kwargs.get('title','TermTk')
Expand Down Expand Up @@ -290,4 +289,4 @@ def _SIGINT(self, signum, frame):
self.quit()

def isVisibleAndParent(self):
return self.isVisible()
return self.isVisible()
42 changes: 0 additions & 42 deletions TermTk/TTkTemplates/color.py

This file was deleted.

1 change: 1 addition & 0 deletions TermTk/TTkTestWidgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .testwidgetsizes import TTkTestWidgetSizes
from .testabstractscroll import TTkTestAbstractScrollWidget
from .keypressview import TTkKeyPressView
from .tominspector import TTkTomInspector
11 changes: 5 additions & 6 deletions TermTk/TTkTestWidgets/testwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ def __init__(self, *args, **kwargs):

def paintEvent(self):
TTkFrame.paintEvent(self)
self._l[0].text=f"Test Widget [{self._name}]"
self._l[1].text=f"x,y ({self._x},{self._y})"
self._l[2].text=f"w,h ({self._width},{self._height})"
self._l[3].text=f"max w,h ({self._maxw},{self._maxh})"
self._l[4].text=f"min w,h ({self._minw},{self._minh})"

self._l[0].setText(f"Test Widget [{self._name}]")
self._l[1].setText(f"x,y ({self._x},{self._y})")
self._l[2].setText(f"w,h ({self._width},{self._height})")
self._l[3].setText(f"max w,h ({self._maxw},{self._maxh})")
self._l[4].setText(f"min w,h ({self._minw},{self._minh})")

def mousePressEvent(self, evt):
TTkLog.debug(f"{self._name} Test Mouse {evt}")
Expand Down
Loading

0 comments on commit 5626955

Please sign in to comment.