10 changed files with 377 additions and 30 deletions
@ -1,2 +1,3 @@
|
||||
from .abstractscrollarea import * |
||||
from .abstractitemmodel import * |
||||
from .abstractscrollview import TTkAbstractScrollViewInterface, TTkAbstractScrollView, TTkAbstractScrollViewGridLayout |
||||
from .abstractscrollarea import TTkAbstractScrollArea |
||||
from .abstractitemmodel import TTkAbstractItemModel |
||||
|
||||
@ -1,4 +1,5 @@
|
||||
from .logviewer import * |
||||
from .testwidget import * |
||||
from .testwidgetsizes import * |
||||
from .logviewer import TTkLogViewer |
||||
from .testwidget import TTkTestWidget |
||||
from .testwidgetsizes import TTkTestWidgetSizes |
||||
from .testabstractscroll import TTkTestAbstractScrollWidget |
||||
from .keypressview import TTkKeyPressView |
||||
|
||||
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3 |
||||
|
||||
# MIT License |
||||
# |
||||
# Copyright (c) 2021 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
# of this software and associated documentation files (the "Software"), to deal |
||||
# in the Software without restriction, including without limitation the rights |
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
# copies of the Software, and to permit persons to whom the Software is |
||||
# furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included in all |
||||
# copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
# SOFTWARE. |
||||
|
||||
from TermTk.TTkCore.signal import pyTTkSlot |
||||
from TermTk.TTkWidgets.frame import TTkFrame |
||||
from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView |
||||
|
||||
class TTkTestAbstractScrollWidget(TTkAbstractScrollView): |
||||
ID = 1 |
||||
__slots__ = ('_areaPos','_areaSize') |
||||
def __init__(self, *args, **kwargs): |
||||
super().__init__(*args, **kwargs) |
||||
self._name = kwargs.get('name' , f"TTkTestAbstractScrollWidget-{TTkTestAbstractScrollWidget.ID}" ) |
||||
self._areaSize = kwargs.get('areaSize',(10,10)) |
||||
self._areaPos = kwargs.get('areaPos',(0,0)) |
||||
TTkTestAbstractScrollWidget.ID+=1 |
||||
self.viewChanged.connect(self._viewChangedHandler) |
||||
|
||||
@pyTTkSlot() |
||||
def _viewChangedHandler(self): |
||||
self._areaPos = self.getViewOffsets() |
||||
self.update() |
||||
|
||||
def paintEvent(self): |
||||
self._canvas.drawBox(pos=(0,0),size=(self._width,self._height)) |
||||
t,_,l,_ = self.getPadding() |
||||
self._canvas.drawText(pos=(l+1,t+1+0), text=f"Test Widget [{self._name}]") |
||||
self._canvas.drawText(pos=(l+1,t+1+1), text=f"x,y ({self._x},{self._y})") |
||||
self._canvas.drawText(pos=(l+1,t+1+2), text=f"w,h ({self._width},{self._height})") |
||||
self._canvas.drawText(pos=(l+1,t+1+3), text=f"max w,h ({self._maxw},{self._maxh})") |
||||
self._canvas.drawText(pos=(l+1,t+1+4), text=f"min w,h ({self._minw},{self._minh})") |
||||
self._canvas.drawText(pos=(l+1,t+1+5), text=f"areaSize {self._areaSize}") |
||||
self._canvas.drawText(pos=(l+1,t+1+6), text=f"areaPos1 {self._areaPos}") |
||||
self._canvas.drawText(pos=(l+1,t+1+7), text=f"areaPos2 ({self._areaPos[0]+self._width},{self._areaPos[1]+self._height})") |
||||
|
||||
def mousePressEvent(self, evt): return True |
||||
def mouseReleaseEvent(self, evt): return True |
||||
|
||||
def viewFullAreaSize(self) -> (int, int): |
||||
return self._areaSize |
||||
|
||||
def viewDisplayedSize(self) -> (int, int): |
||||
return self.size() |
||||
|
||||
|
||||
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3 |
||||
|
||||
# MIT License |
||||
# |
||||
# Copyright (c) 2022 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
# of this software and associated documentation files (the "Software"), to deal |
||||
# in the Software without restriction, including without limitation the rights |
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
# copies of the Software, and to permit persons to whom the Software is |
||||
# furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included in all |
||||
# copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
# SOFTWARE. |
||||
|
||||
class A_Meta(type): |
||||
def __new__(mcs, name, bases, d): |
||||
print(f"{mcs=}") |
||||
print(f"{name=}") |
||||
print(f"{bases=}") |
||||
print(f"{d=}") |
||||
return type.__new__(mcs, name, bases, d) |
||||
|
||||
class A(metaclass=A_Meta): |
||||
def __init__(self, *args, **kwargs): |
||||
pass |
||||
def test(self): |
||||
pass |
||||
|
||||
print(f"{A=}") |
||||
|
||||
a = A(1,2,3,4) |
||||
|
||||
print(f"{a=}\n") |
||||
|
||||
class B(A_Meta): |
||||
def __init__(self, *args, **kwargs): |
||||
pass |
||||
def test(self): |
||||
pass |
||||
|
||||
b = B("NB",(),{}) |
||||
|
||||
print(f"{b=}\n") |
||||
|
||||
class C(): |
||||
def __init__(self) -> None: |
||||
print(f"C {type(self)=}") |
||||
class D(): |
||||
def __init__(self) -> None: |
||||
print(f"D {type(self)=}") |
||||
class E(C,D): |
||||
def __init__(self) -> None: |
||||
print(f"{super()=}") |
||||
super().__init__() |
||||
def pippo(self): |
||||
print(f"{super()=}") |
||||
|
||||
e = E() |
||||
e.pippo() |
||||
|
||||
print(f"{issubclass(E,D)=} {issubclass(E,C)=}") |
||||
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3 |
||||
|
||||
# MIT License |
||||
# |
||||
# Copyright (c) 2021 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
# of this software and associated documentation files (the "Software"), to deal |
||||
# in the Software without restriction, including without limitation the rights |
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
# copies of the Software, and to permit persons to whom the Software is |
||||
# furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included in all |
||||
# copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
# SOFTWARE. |
||||
|
||||
import sys, os, argparse, math, random |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'..')) |
||||
import TermTk as ttk |
||||
|
||||
class ScrollAreaTest(ttk.TTkAbstractScrollArea): |
||||
__slots__ = ('_areaView') |
||||
def __init__(self, *args, **kwargs): |
||||
super().__init__(*args, **kwargs) |
||||
if 'parent' in kwargs: kwargs.pop('parent') |
||||
self.setFocusPolicy(ttk.TTkK.ClickFocus) |
||||
self.setViewport(ttk.TTkTestAbstractScrollWidget(areaSize=(100,40), areaPos=(10,5))) |
||||
|
||||
def demoScrollArea(root= None): |
||||
scrollArea = ScrollAreaTest(parent=root) |
||||
return scrollArea |
||||
|
||||
def main(): |
||||
parser = argparse.ArgumentParser() |
||||
parser.add_argument('-f', help='Full Screen', action='store_true') |
||||
args = parser.parse_args() |
||||
|
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
if args.f: |
||||
rootGraph = root |
||||
root.setLayout(ttk.TTkGridLayout()) |
||||
else: |
||||
rootGraph = ttk.TTkWindow(parent=root,pos=(1,1), size=(50,20), title="Test Graph", border=True, layout=ttk.TTkGridLayout()) |
||||
demoScrollArea(rootGraph) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3 |
||||
|
||||
# MIT License |
||||
# |
||||
# Copyright (c) 2021 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
# of this software and associated documentation files (the "Software"), to deal |
||||
# in the Software without restriction, including without limitation the rights |
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
# copies of the Software, and to permit persons to whom the Software is |
||||
# furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included in all |
||||
# copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
# SOFTWARE. |
||||
|
||||
import sys, os, argparse, math, random |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'..')) |
||||
import TermTk as ttk |
||||
|
||||
class ScrollAreaTest(ttk.TTkAbstractScrollArea): |
||||
__slots__ = ('_areaView') |
||||
def __init__(self, *args, **kwargs): |
||||
super().__init__(*args, **kwargs) |
||||
if 'parent' in kwargs: kwargs.pop('parent') |
||||
self.setFocusPolicy(ttk.TTkK.ClickFocus) |
||||
scrollLayout = ttk.TTkAbstractScrollViewGridLayout() |
||||
w1 = ttk.TTkTestAbstractScrollWidget(areaSize=(100,40), areaPos=(10,5)) |
||||
w2 = ttk.TTkTestAbstractScrollWidget(areaSize=(100,40), areaPos=(10,5), maxWidth=30) |
||||
w3 = ttk.TTkTestAbstractScrollWidget(areaSize=( 50,20), areaPos=(10,5)) |
||||
scrollLayout.addWidget(w1,0,0,2,1) |
||||
scrollLayout.addWidget(w2,0,1) |
||||
scrollLayout.addWidget(w3,1,1) |
||||
self.setViewport(scrollLayout) |
||||
|
||||
def demoScrollArea(root= None): |
||||
scrollArea = ScrollAreaTest(parent=root) |
||||
return scrollArea |
||||
|
||||
def main(): |
||||
parser = argparse.ArgumentParser() |
||||
parser.add_argument('-f', help='Full Screen', action='store_true') |
||||
args = parser.parse_args() |
||||
|
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
if args.f: |
||||
rootGraph = root |
||||
root.setLayout(ttk.TTkGridLayout()) |
||||
else: |
||||
rootGraph = ttk.TTkWindow(parent=root,pos=(1,1), size=(55,20), title="Test Graph", border=True, layout=ttk.TTkGridLayout()) |
||||
demoScrollArea(rootGraph) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
Loading…
Reference in new issue