27 changed files with 695 additions and 128 deletions
@ -1,2 +1,3 @@
|
||||
from .logviewer import * |
||||
from .testwidget import * |
||||
from .testwidgetsizes import * |
||||
|
||||
@ -0,0 +1,98 @@
|
||||
#!/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 os |
||||
from TermTk.TTkCore.constant import TTkK |
||||
from TermTk.TTkCore.log import TTkLog |
||||
from TermTk.TTkCore.color import TTkColor |
||||
from TermTk.TTkWidgets.frame import TTkFrame |
||||
from TermTk.TTkTemplates.color import TColor |
||||
from TermTk.TTkTemplates.text import TText |
||||
from TermTk.TTkCore.signal import pyTTkSlot, pyTTkSignal |
||||
from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea |
||||
from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView |
||||
|
||||
class _TTkLogViewer(TTkAbstractScrollView): |
||||
__slots__ = ('_color', '_text', '_messages', '_cwd') |
||||
def __init__(self, *args, **kwargs): |
||||
TTkAbstractScrollView.__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , '_TTkLogViewer' ) |
||||
self._messages = [""] |
||||
self._cwd = os.getcwd() |
||||
TTkLog.installMessageHandler(self.loggingCallback) |
||||
self.viewChanged.connect(self._viewChangedHandler) |
||||
|
||||
@pyTTkSlot() |
||||
def _viewChangedHandler(self): |
||||
self.update() |
||||
|
||||
def viewFullAreaSize(self) -> (int, int): |
||||
w = max([ len(m) for m in self._messages]) |
||||
h = len(self._messages) |
||||
return w , h |
||||
|
||||
def viewDisplayedSize(self) -> (int, int): |
||||
return self.size() |
||||
|
||||
def loggingCallback(self, mode, context, message): |
||||
logType = "NONE" |
||||
if mode == TTkLog.InfoMsg: logType = "INFO " |
||||
elif mode == TTkLog.DebugMsg: logType = "DEBUG" |
||||
elif mode == TTkLog.ErrorMsg: logType = "ERROR" |
||||
elif mode == TTkLog.FatalMsg: logType = "FATAL" |
||||
elif mode == TTkLog.WarningMsg: logType = "WARNING " |
||||
elif mode == TTkLog.CriticalMsg: logType = "CRITICAL" |
||||
self._messages.append(f"{logType}: {context.file}:{context.line} {message}".replace(self._cwd,"_")) |
||||
offx, offy = self.getViewOffsets() |
||||
_,h = self.size() |
||||
if offy == len(self._messages)-h-1: |
||||
offy = len(self._messages)-h |
||||
self.viewMoveTo(offx, offy) |
||||
self.viewChanged.emit() |
||||
self.update() |
||||
|
||||
def paintEvent(self): |
||||
ox,oy = self.getViewOffsets() |
||||
y = 0 |
||||
_,h = self.size() |
||||
offset = max(0,ox) |
||||
for message in self._messages[oy:]: |
||||
self._canvas.drawText(pos=(0,y),text=message[ox:]) |
||||
c = TTkColor.RST |
||||
if message.startswith("INFO ") : c = TTkColor.fg("#00ff00") |
||||
elif message.startswith("DEBUG") : c = TTkColor.fg("#00ffff") |
||||
elif message.startswith("ERROR") : c = TTkColor.fg("#ff0000") |
||||
elif message.startswith("FATAL") : c = TTkColor.fg("#ff0000") |
||||
self._canvas.drawText(pos=(-ox,y),text=message[:5], color=c) |
||||
y+=1 |
||||
|
||||
class TTkLogViewer(TTkAbstractScrollArea): |
||||
__slots__ = ('_logView') |
||||
def __init__(self, *args, **kwargs): |
||||
TTkAbstractScrollArea.__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , 'TTkLogViewer' ) |
||||
if 'parent' in kwargs: kwargs.pop('parent') |
||||
self._logView = _TTkLogViewer(*args, **kwargs) |
||||
self.setFocusPolicy(TTkK.ClickFocus) |
||||
self.setViewport(self._logView) |
||||
@ -0,0 +1,50 @@
|
||||
#!/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.cfg import TTkCfg |
||||
from TermTk.TTkCore.constant import TTkK |
||||
from TermTk.TTkCore.log import TTkLog |
||||
from TermTk.TTkCore.signal import pyTTkSlot, pyTTkSignal |
||||
from TermTk.TTkWidgets.listwidget import TTkListWidget |
||||
from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea |
||||
|
||||
class TTkList(TTkAbstractScrollArea): |
||||
__slots__ = ('_listView', 'itemClicked', 'textClicked') |
||||
def __init__(self, *args, **kwargs): |
||||
TTkAbstractScrollArea.__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , 'TTkList' ) |
||||
if 'parent' in kwargs: kwargs.pop('parent') |
||||
self._listView = TTkListWidget(*args, **kwargs) |
||||
self.setFocusPolicy(TTkK.ClickFocus) |
||||
self.setViewport(self._listView) |
||||
self.itemClicked = self._listView.itemClicked |
||||
self.textClicked = self._listView.textClicked |
||||
|
||||
def addItem(self, *args, **kwargs): |
||||
return self._listView.addItem(*args, **kwargs) |
||||
def setSelectionMode(self, *args, **kwargs): |
||||
return self._listView.setSelectionMode(*args, **kwargs) |
||||
def selectedLabels(self, *args, **kwargs): |
||||
return self._listView.selectedLabels(*args, **kwargs) |
||||
|
||||
@ -0,0 +1,126 @@
|
||||
#!/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.cfg import TTkCfg |
||||
from TermTk.TTkCore.constant import TTkK |
||||
from TermTk.TTkCore.log import TTkLog |
||||
from TermTk.TTkCore.signal import pyTTkSlot, pyTTkSignal |
||||
from TermTk.TTkCore.color import TTkColor |
||||
from TermTk.TTkWidgets.widget import TTkWidget |
||||
from TermTk.TTkWidgets.label import TTkLabel |
||||
from TermTk.TTkTestWidgets.testwidgetsizes import TTkTestWidgetSizes |
||||
from TermTk.TTkAbstract.abstractscrollview import TTkAbstractScrollView |
||||
|
||||
class _TTkListWidgetText(TTkLabel): |
||||
__slots__ = ('selected', '_selected') |
||||
def __init__(self, *args, **kwargs): |
||||
TTkLabel.__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , '_TTkListWidgetText' ) |
||||
# Define Signals |
||||
self.selected = pyTTkSignal(_TTkListWidgetText) |
||||
self._selected = False |
||||
|
||||
def mouseReleaseEvent(self, evt): |
||||
self.selected.emit(self) |
||||
return True |
||||
|
||||
class TTkListWidget(TTkAbstractScrollView): |
||||
__slots__ = ('itemClicked', 'textClicked', '_color', '_selectedColor', '_selectedItems', '_selectionMode') |
||||
def __init__(self, *args, **kwargs): |
||||
# Default Class Specific Values |
||||
self._selectionMode = kwargs.get("selectionMode", TTkK.SingleSelection) |
||||
self._selectedItems = [] |
||||
self._color = TTkCfg.theme.listColor |
||||
self._selectedColor = TTkCfg.theme.listColorSelected |
||||
# Signals |
||||
self.itemClicked = pyTTkSignal(TTkWidget) |
||||
self.textClicked = pyTTkSignal(str) |
||||
# Init Super |
||||
TTkAbstractScrollView.__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , 'TTkListWidget' ) |
||||
self.viewChanged.connect(self._viewChangedHandler) |
||||
|
||||
@pyTTkSlot() |
||||
def _viewChangedHandler(self): |
||||
x,y = self.getViewOffsets() |
||||
self.layout().groupMoveTo(-x,-y) |
||||
|
||||
@pyTTkSlot(_TTkListWidgetText) |
||||
def _labelSelectedHandler(self, label): |
||||
if self._selectionMode == TTkK.SingleSelection: |
||||
for i in self._selectedItems: |
||||
i._selected = False |
||||
i.color = TTkCfg.theme.listColor |
||||
label._selected = True |
||||
elif self._selectionMode == TTkK.MultiSelection: |
||||
label._selected = not label._selected |
||||
if label._selected: |
||||
self._selectedItems.append(label) |
||||
else: |
||||
self._selectedItems.remove(label) |
||||
if label._selected: |
||||
label.color = TTkCfg.theme.listColorSelected |
||||
else: |
||||
label.color = TTkCfg.theme.listColor |
||||
|
||||
self.textClicked.emit(label.text) |
||||
|
||||
def setSelectionMode(self, mode): |
||||
self._selectionMode = mode |
||||
|
||||
def selectedLabels(self): |
||||
return [i.text for i in self._selectedItems] |
||||
|
||||
def resizeEvent(self, w, h): |
||||
maxw = 0 |
||||
for item in self.layout().children(): |
||||
maxw = max(maxw,item.minimumWidth()) |
||||
maxw = max(self.width(),maxw) |
||||
for item in self.layout().children(): |
||||
x,y,_,h = item.geometry() |
||||
item.setGeometry(x,y,maxw,h) |
||||
self.viewChanged.emit() |
||||
|
||||
def viewFullAreaSize(self) -> (int, int): |
||||
_,_,w,h = self.layout().fullWidgetAreaGeometry() |
||||
return w , h |
||||
|
||||
def viewDisplayedSize(self) -> (int, int): |
||||
return self.size() |
||||
|
||||
def addItem(self, item): |
||||
if isinstance(item, str): |
||||
label = _TTkListWidgetText(text=item, width=max(len(item),self.width())) |
||||
label.selected.connect(self._labelSelectedHandler) |
||||
return self.addItem(label) |
||||
_,y,_,h = self.layout().fullWidgetAreaGeometry() |
||||
self.addWidget(item) |
||||
item.move(0,y+h) |
||||
_,_,fw,_ = self.layout().fullWidgetAreaGeometry() |
||||
w = self.width() |
||||
for item in self.layout().children(): |
||||
x,y,_,h = item.geometry() |
||||
minw = item.minimumWidth() |
||||
item.setGeometry(x,y,max(w-1,fw),h) |
||||
self.viewChanged.emit() |
||||
@ -1,62 +0,0 @@
|
||||
#!/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 os |
||||
from TermTk.TTkCore.log import TTkLog |
||||
from TermTk.TTkWidgets.widget import * |
||||
from TermTk.TTkTemplates.color import TColor |
||||
from TermTk.TTkTemplates.text import TText |
||||
|
||||
class TTkLogViewer(TTkWidget): |
||||
__slots__ = ('_color', '_text', '_messages', '_cwd') |
||||
def __init__(self, *args, **kwargs): |
||||
TTkWidget.__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , 'TTkLabel' ) |
||||
self._messages = [] |
||||
self._cwd = os.getcwd() |
||||
TTkLog.installMessageHandler(self.loggingCallback) |
||||
|
||||
|
||||
def loggingCallback(self, mode, context, message): |
||||
logType = "NONE" |
||||
if mode == TTkLog.InfoMsg: logType = "INFO" |
||||
elif mode == TTkLog.DebugMsg: logType = "DEBUG" |
||||
elif mode == TTkLog.WarningMsg: logType = "WARNING" |
||||
elif mode == TTkLog.CriticalMsg: logType = "CRITICAL" |
||||
elif mode == TTkLog.FatalMsg: logType = "FATAL" |
||||
elif mode == TTkLog.ErrorMsg: logType = "ERROR" |
||||
self._messages.append(f"{logType}: {context.file}:{context.line} {message}".replace(self._cwd,"_")) |
||||
self.update() |
||||
|
||||
def paintEvent(self): |
||||
y = 0 |
||||
_,h = self.size() |
||||
offset = len(self._messages)-h |
||||
if offset<0: offset = 0 |
||||
for message in self._messages[offset:]: |
||||
self._canvas.drawText(pos=(0,y),text=message) |
||||
y+=1 |
||||
|
||||
|
||||
|
||||
@ -0,0 +1,92 @@
|
||||
#!/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 |
||||
|
||||
words = ["Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", "commodo", "consequat.", "Duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint", "occaecat", "cupidatat", "non", "proident,", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum."] |
||||
def getWord(): |
||||
return random.choice(words) |
||||
|
||||
def demoList(root= None): |
||||
# Define the main Layout |
||||
splitter = ttk.TTkSplitter(parent=root, orientation=ttk.TTkK.HORIZONTAL) |
||||
frame2 = ttk.TTkFrame(parent=splitter, border=0, layout=ttk.TTkVBoxLayout()) |
||||
frame1 = ttk.TTkFrame(parent=splitter, border=0, layout=ttk.TTkVBoxLayout()) |
||||
frame3 = ttk.TTkFrame(parent=splitter, border=0, layout=ttk.TTkVBoxLayout()) |
||||
|
||||
# Multi Selection List |
||||
ttk.TTkLabel(parent=frame1, text="[ MultiSelect ]",maxHeight=2) |
||||
listWidgetMulti = ttk.TTkList(parent=frame1, maxWidth=40, minWidth=10, selectionMode=ttk.TTkK.MultiSelection) |
||||
|
||||
# Single Selection List |
||||
ttk.TTkLabel(parent=frame2, text="[ SingleSelect ]",maxHeight=2) |
||||
listWidgetSingle = ttk.TTkList(parent=frame2, maxWidth=40, minWidth=10) |
||||
|
||||
# Log Viewer |
||||
label1 = ttk.TTkLabel(parent=frame3, text="[ list1 ]",maxHeight=2) |
||||
label2 = ttk.TTkLabel(parent=frame3, text="[ list2 ]",maxHeight=2) |
||||
ttk.TTkLogViewer(parent=frame3)#, border=True) |
||||
|
||||
@ttk.pyTTkSlot(str) |
||||
def _listCallback1(label): |
||||
ttk.TTkLog.info(f"Clicked label1: {label}") |
||||
label1.text = f"[ list1 ] clicked {label}" |
||||
|
||||
@ttk.pyTTkSlot(str) |
||||
def _listCallback2(label): |
||||
ttk.TTkLog.info(f"Clicked label2: {label} - selected: {listWidgetMulti.selectedLabels()}") |
||||
label2.text = f"[ list2 ] {listWidgetMulti.selectedLabels()}" |
||||
|
||||
# Connect the signals to the 2 slots defines |
||||
listWidgetSingle.textClicked.connect(_listCallback1) |
||||
listWidgetMulti.textClicked.connect(_listCallback2) |
||||
|
||||
# populate the lists with random entries |
||||
for i in range(100): |
||||
listWidgetSingle.addItem(f"{i}) {getWord()} {getWord()}") |
||||
listWidgetMulti.addItem(f"{getWord()} {getWord()}") |
||||
|
||||
return splitter |
||||
|
||||
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=(100,40), title="Test List", border=True, layout=ttk.TTkGridLayout()) |
||||
demoList(rootGraph) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,77 @@
|
||||
#!/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 graphTimerEvent(): |
||||
def __init__(self, w, delay): |
||||
self.timer = ttk.TTkTimer() |
||||
self.val = 10 |
||||
self.delay = delay |
||||
self.w = w |
||||
self.timer.timeout.connect(self.timerEvent) |
||||
self.timer.start(1) |
||||
@ttk.pyTTkSlot() |
||||
def timerEvent(self): |
||||
plot = [ math.sin( self.val *math.pi/40)*4*10 , |
||||
math.sin((self.val+15)*math.pi/40)*4*7, |
||||
math.sin((self.val+20)*math.pi/30)*4*5,] |
||||
self.val+=1 |
||||
self.w.addValue(plot) |
||||
self.timer.start(self.delay) |
||||
|
||||
def demoScrollArea(root= None): |
||||
scrollArea = ttk.TTkScrollArea(parent=root) |
||||
ttk.TTkTestWidgetSizes(pos=(0,0) , size=(50,25), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(10,25) , size=(40,20), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(20,50) , size=(60,10), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(50,0) , size=(40,10), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(100,0) , size=(40,10), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(150,0) , size=(40,10), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(50,31) , size=(60,10), parent=scrollArea.viewport(), border=True) |
||||
graph = ttk.TTkGraph( pos=(50,11) , size=(150,20), parent=scrollArea.viewport(), color=ttk.TTkColor.fg('#ff8800', modifier=ttk.TTkColorGradient(increment= 40))) |
||||
graphTimerEvent(graph, 0.1) |
||||
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=(100,40), title="Test Graph", border=True, layout=ttk.TTkGridLayout()) |
||||
demoScrollArea(rootGraph) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,92 @@
|
||||
#!/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 |
||||
|
||||
words = ["Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", "commodo", "consequat.", "Duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint", "occaecat", "cupidatat", "non", "proident,", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum."] |
||||
def getWord(): |
||||
return random.choice(words) |
||||
|
||||
def demoList(root= None): |
||||
# Define the main Layout |
||||
splitter = ttk.TTkSplitter(parent=root, orientation=ttk.TTkK.HORIZONTAL) |
||||
frame2 = ttk.TTkFrame(parent=splitter, border=0, layout=ttk.TTkVBoxLayout()) |
||||
frame1 = ttk.TTkFrame(parent=splitter, border=0, layout=ttk.TTkVBoxLayout()) |
||||
frame3 = ttk.TTkFrame(parent=splitter, border=0, layout=ttk.TTkVBoxLayout()) |
||||
|
||||
# Multi Selection List |
||||
ttk.TTkLabel(parent=frame1, text="[ MultiSelect ]",maxHeight=2) |
||||
listWidgetMulti = ttk.TTkList(parent=frame1, maxWidth=40, minWidth=10, selectionMode=ttk.TTkK.MultiSelection) |
||||
|
||||
# Single Selection List |
||||
ttk.TTkLabel(parent=frame2, text="[ SingleSelect ]",maxHeight=2) |
||||
listWidgetSingle = ttk.TTkList(parent=frame2, maxWidth=40, minWidth=10) |
||||
|
||||
# Log Viewer |
||||
label1 = ttk.TTkLabel(parent=frame3, text="[ list1 ]",maxHeight=2) |
||||
label2 = ttk.TTkLabel(parent=frame3, text="[ list2 ]",maxHeight=2) |
||||
ttk.TTkLogViewer(parent=frame3)#, border=True) |
||||
|
||||
@ttk.pyTTkSlot(str) |
||||
def _listCallback1(label): |
||||
ttk.TTkLog.info(f"Clicked label1: {label}") |
||||
label1.text = f"[ list1 ] clicked {label}" |
||||
|
||||
@ttk.pyTTkSlot(str) |
||||
def _listCallback2(label): |
||||
ttk.TTkLog.info(f"Clicked label2: {label} - selected: {listWidgetMulti.selectedLabels()}") |
||||
label2.text = f"[ list2 ] {listWidgetMulti.selectedLabels()}" |
||||
|
||||
# Connect the signals to the 2 slots defines |
||||
listWidgetSingle.textClicked.connect(_listCallback1) |
||||
listWidgetMulti.textClicked.connect(_listCallback2) |
||||
|
||||
# populate the lists with random entries |
||||
for i in range(100): |
||||
listWidgetSingle.addItem(f"{i}) {getWord()} {getWord()}") |
||||
listWidgetMulti.addItem(f"{getWord()} {getWord()}") |
||||
|
||||
return splitter |
||||
|
||||
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=(100,40), title="Test List", border=True, layout=ttk.TTkGridLayout()) |
||||
demoList(rootGraph) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,58 @@
|
||||
#!/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 |
||||
|
||||
def demoScrollArea(root= None): |
||||
scrollArea = ttk.TTkScrollArea(parent=root) |
||||
ttk.TTkTestWidgetSizes(pos=(0,0) , size=(40,20), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(10,25) , size=(40,20), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(20,50) , size=(60,10), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(50,0) , size=(40,10), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(100,0) , size=(40,10), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(150,0) , size=(40,10), parent=scrollArea.viewport(), border=True) |
||||
ttk.TTkTestWidgetSizes(pos=(60,30) , size=(60,10), parent=scrollArea.viewport(), border=True) |
||||
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=(100,40), title="Test Graph", border=True, layout=ttk.TTkGridLayout()) |
||||
demoScrollArea(rootGraph) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
Loading…
Reference in new issue