20 changed files with 971 additions and 132 deletions
@ -1 +1,2 @@
|
||||
from .abstractscrollarea import * |
||||
from .abstractitemmodel import * |
||||
|
||||
@ -0,0 +1,27 @@
|
||||
#!/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. |
||||
|
||||
class TTkAbstractItemModel(): |
||||
def __init__(self, *args, **kwargs): |
||||
pass |
||||
@ -0,0 +1,174 @@
|
||||
#!/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.constant import TTkConstant, TTkK |
||||
from TermTk.TTkCore.log import TTkLog |
||||
from TermTk.TTkCore.cfg import * |
||||
from TermTk.TTkCore.signal import pyTTkSlot, pyTTkSignal |
||||
from TermTk.TTkWidgets.widget import TTkWidget |
||||
from TermTk.TTkWidgets.spacer import TTkSpacer |
||||
from TermTk.TTkWidgets.frame import TTkFrame |
||||
from TermTk.TTkLayouts.gridlayout import TTkGridLayout |
||||
|
||||
|
||||
''' |
||||
_curentIndex = 2 |
||||
_labelPos = [0],[1], [2], [3], [4], |
||||
╭─┌──┌──────╔══════╗──────┬──────┐─╮ |
||||
_labels= │◀│La│Label1║Label2║Label3│Label4│▶│ |
||||
╞═══════════╩══════╩═══════════════╡ |
||||
leftscroller rightScroller |
||||
''' |
||||
class TTkTabWidget(TTkFrame): |
||||
__slots__ = ( |
||||
'_viewport', |
||||
'_tabColor', '_tabBorderColor', '_tabSelectColor', |
||||
'_tabWidgets', '_labels', '_labelsPos', |
||||
'_offset', '_currentIndex', |
||||
'_leftScroller', '_rightScroller', |
||||
'_tabMovable', '_tabClosable') |
||||
|
||||
def __init__(self, *args, **kwargs): |
||||
self._tabWidgets = [] |
||||
self._labels = [] |
||||
self._labelsPos = [] |
||||
self._currentIndex = 0 |
||||
self._offset = 0 |
||||
self._tabMovable = False |
||||
self._tabClosable = False |
||||
self._leftScroller = False |
||||
self._rightScroller = False |
||||
self._tabColor = TTkCfg.theme.tabColor |
||||
self._tabBorderColor = TTkCfg.theme.tabBorderColor |
||||
self._tabSelectColor = TTkCfg.theme.tabSelectColor |
||||
super().__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , 'TTkTabWidget') |
||||
self.setLayout(TTkGridLayout()) |
||||
self._viewport = TTkWidget(layout=TTkGridLayout()) |
||||
self.layout().addWidget(self._viewport,0,0) |
||||
#self.layout().addWidget(TTkSpacer(),0,1) |
||||
#self.layout().addWidget(TTkSpacer(),1,0) |
||||
|
||||
|
||||
if self.border(): |
||||
self.setPadding(3,1,1,1) |
||||
else: |
||||
self.setPadding(3,0,0,0) |
||||
self.setFocusPolicy(TTkK.ClickFocus) |
||||
|
||||
|
||||
def addTab(self, widget, label): |
||||
widget.hide() |
||||
self._tabWidgets.append(widget) |
||||
self._labels.append(label) |
||||
self._viewport.addWidget(widget) |
||||
self._updateTabs() |
||||
|
||||
def insertTab(self, index, widget, label): |
||||
widget.hide() |
||||
self._tabWidgets.insert(index, widget) |
||||
self._labels.insert(index, label) |
||||
self._viewport.addWidget(widget) |
||||
self._updateTabs() |
||||
|
||||
def _updateTabs(self): |
||||
xpos = 0+2 |
||||
w = self.width()-4 |
||||
self._labelsPos = [] |
||||
self._leftScroller = False |
||||
self._rightScroller = False |
||||
minLabelLen = 0 |
||||
for label in self._labels: |
||||
labelLen = len(label) |
||||
if xpos+labelLen > w: |
||||
xpos = w-labelLen |
||||
self._leftScroller = True |
||||
self._rightScroller = True |
||||
self._labelsPos.append(xpos) |
||||
xpos += labelLen+1 |
||||
if minLabelLen < labelLen: |
||||
minLabelLen = labelLen |
||||
self.setMinimumWidth(minLabelLen+2+4) |
||||
|
||||
for i, widget in enumerate(self._tabWidgets): |
||||
if self._currentIndex == i: |
||||
widget.show() |
||||
else: |
||||
widget.hide() |
||||
self.update() |
||||
|
||||
def resizeEvent(self, w, h): |
||||
self._updateTabs() |
||||
|
||||
def mousePressEvent(self, evt): |
||||
x,y = evt.x, evt.y |
||||
w = self.width() |
||||
offset = self._offset |
||||
if y>2: return False |
||||
# Check from the selected to the left and from selected+1 to the right |
||||
if self._leftScroller and x<2 and offset>0: |
||||
self._offset -= 1 |
||||
self._updateTabs() |
||||
return True |
||||
if self._rightScroller and x>w-3 and offset<len(self._labels)-1: |
||||
self._offset += 1 |
||||
self._updateTabs() |
||||
return True |
||||
for i in list(reversed(range(offset+1 )) ) + \ |
||||
list( range(offset+1, len(self._labels)) ) : |
||||
posx = self._labelsPos[i] |
||||
tablen = len(self._labels[i])+2 |
||||
if posx <= x < (posx+tablen): |
||||
self._currentIndex = i |
||||
self._offset = i |
||||
self._updateTabs() |
||||
return True |
||||
return False |
||||
|
||||
def mouseDragEvent(self, evt): |
||||
return False |
||||
|
||||
def wheelEvent(self, evt): |
||||
_,y = evt.x, evt.y |
||||
if y>2: return False |
||||
if evt.evt == TTkK.WHEEL_Down: |
||||
if self._currentIndex < len(self._labels)-1: |
||||
self._currentIndex += 1 |
||||
else: |
||||
if self._currentIndex > 0: |
||||
self._currentIndex -= 1 |
||||
self._offset = self._currentIndex |
||||
self._updateTabs() |
||||
return True |
||||
|
||||
def paintEvent(self): |
||||
if self.border(): |
||||
self._canvas.drawBox(pos=(0,2),size=(self._width,self._height-2), color=self._borderColor, grid=9) |
||||
self._canvas.drawTab( |
||||
pos=(0,0), size=self.size(), |
||||
labels=self._labels, labelsPos=self._labelsPos, |
||||
selected=self._currentIndex, offset=self._offset, |
||||
leftScroller=self._leftScroller, rightScroller=self._rightScroller, |
||||
color=self._tabColor, borderColor=self._tabBorderColor, selectColor=self._tabSelectColor) |
||||
|
||||
@ -0,0 +1,109 @@
|
||||
#!/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 |
||||
import 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 getSentence(a,b): |
||||
return " ".join([getWord() for i in range(0,random.randint(a,b))]) |
||||
|
||||
def demoFormWidgets(root=None): |
||||
win_form1_grid_layout = ttk.TTkGridLayout(columnMinWidth=1) |
||||
frame = ttk.TTkFrame(parent=root, layout=win_form1_grid_layout, border=0) |
||||
|
||||
win_form1_grid_layout.addWidget(ttk.TTkButton(text='Button 1'),0,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkButton(text='Button 2'),1,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkButton(text='Button 3'),0,2) |
||||
win_form1_grid_layout.addWidget(ttk.TTkButton(text='Button 4'),1,2) |
||||
row = 2 |
||||
|
||||
row +=1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Combo Box'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkComboBox(list=['One','Two','Some Long Sentence That Is Not a Written Number','Three']),row,2) |
||||
row +=1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Combo long Box'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkComboBox(list=[getSentence(1,4) for i in range(100)]),row,2) |
||||
|
||||
|
||||
row +=1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 1'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 1'),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 2'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 2'),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 3'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 3'),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 4'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 4'),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 5'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 5'),row,2) |
||||
|
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Input Number'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='123456', inputType=ttk.TTkK.Input_Number),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Input Wrong Number'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='No num Text', inputType=ttk.TTkK.Input_Number),row,2) |
||||
|
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Input Password'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Password', inputType=ttk.TTkK.Input_Password),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Number Password'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Password', inputType=ttk.TTkK.Input_Password+ttk.TTkK.Input_Number),row,2) |
||||
|
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Checkbox'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkCheckbox(),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Checkbox Checked'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkCheckbox(checked=True),row,2) |
||||
|
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Default)'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkRadioButton(),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Default)'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkRadioButton(),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Default)'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkRadioButton(),row,2) |
||||
|
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name One)'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name One"),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name One)'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name One"),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name Two)'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name Two"),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name One)'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name One"),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name Two)'),row,0) |
||||
win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name Two"),row,2) |
||||
row += 1; win_form1_grid_layout.addWidget(ttk.TTkSpacer(),row,0) |
||||
return frame |
||||
|
||||
|
||||
def main(): |
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
winForm = ttk.TTkWindow(parent=root,pos=(1,1), size=(60,40), title="Test Window 1", layout=ttk.TTkVBoxLayout(), border=True) |
||||
demoFormWidgets(winForm) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,80 @@
|
||||
#!/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 |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'../..')) |
||||
import TermTk as ttk |
||||
|
||||
|
||||
def demoLayout(root=None): |
||||
rightframe = ttk.TTkFrame(parent=root, border=True, title="V Box Layout", titleColor=ttk.TTkColor.BOLD+ttk.TTkColor.fg('#8888dd')) |
||||
rightframe.setLayout(ttk.TTkVBoxLayout()) |
||||
|
||||
gridFrame = ttk.TTkFrame(parent=rightframe, border=True, title="Grid Layout", titleColor=ttk.TTkColor.fg('#88dd88')) |
||||
gridFrame.setLayout(ttk.TTkGridLayout()) |
||||
ttk.TTkButton(parent=gridFrame, border=True, text="Button1") |
||||
ttk.TTkButton(parent=gridFrame, border=True, text="Button2") |
||||
gridFrame.layout().addWidget(ttk.TTkButton(border=True, text="Button (1,0)"),1,0) |
||||
ttk.TTkButton(parent=gridFrame, border=True, text="Button4") |
||||
gridFrame.layout().addWidget(ttk.TTkButton(border=True, text="Button (0,3)"),0,3) |
||||
gridFrame.layout().addWidget(ttk.TTkButton(border=True, text="Button (1,2)"),1,2) |
||||
# Test (add a widget to the same parent with a different layout params than the default) |
||||
gridFrame.layout().addWidget(ttk.TTkButton(parent=gridFrame, border=True, text="Button (2,1)"),2,1) |
||||
gridFrame.layout().addWidget(ttk.TTkButton(border=True, text="Button (5,5)"),5,5) |
||||
|
||||
gridFrame.layout().addWidget(ttk.TTkFrame(border=True,title="Frame1"),0,5) |
||||
gridFrame.layout().addWidget(ttk.TTkFrame(border=True,title="Frame2"),2,3) |
||||
gridFrame.layout().addWidget(ttk.TTkFrame(border=True,title="Frame3"),5,3) |
||||
gridFrame.layout().addWidget(ttk.TTkFrame(border=True,title="Frame4"),5,1) |
||||
|
||||
|
||||
centerrightframe=ttk.TTkFrame(parent=rightframe, border=True, title="H Box Layout", titleColor=ttk.TTkColor.fg('#dd88dd')) |
||||
centerrightframe.setLayout(ttk.TTkHBoxLayout()) |
||||
ttk.TTkTestWidget(parent=rightframe, border=True, title="Test Widget", titleColor=ttk.TTkColor.fg('#dddddd')) |
||||
|
||||
|
||||
smallframe = ttk.TTkFrame(parent=centerrightframe, border=True) |
||||
# smallframe.setLayout(ttk.TTkVBoxLayout()) |
||||
ttk.TTkTestWidget(parent=centerrightframe, border=True) |
||||
ttk.TTkFrame(parent=centerrightframe, border=True) |
||||
|
||||
ttk.TTkButton(parent=smallframe, x=3, y=1, width=20, height=1, text=" Ui.003 Button") |
||||
ttk.TTkTestWidget(parent=smallframe, x=3, y=2, width=50, height=8, border=True) |
||||
ttk.TTkTestWidget(parent=smallframe, x=-5, y=12, width=50, height=15, border=True) |
||||
return rightframe |
||||
|
||||
|
||||
|
||||
|
||||
def main(): |
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
root.setLayout(ttk.TTkHBoxLayout()) |
||||
demoLayout(root) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,53 @@
|
||||
#!/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 |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'../..')) |
||||
import TermTk as ttk |
||||
|
||||
|
||||
def demoSplitter(root=None): |
||||
vsplitter = ttk.TTkSplitter(parent=root, orientation=ttk.TTkK.VERTICAL) |
||||
ttk.TTkTestWidgetSizes(parent=vsplitter ,border=True, title="Frame1.1") |
||||
hsplitter = ttk.TTkSplitter(parent=vsplitter) |
||||
ttk.TTkTestWidgetSizes(parent=vsplitter ,border=True, title="Frame1.2") |
||||
ttk.TTkTestWidgetSizes(parent=vsplitter ,border=True, title="Frame1.3") |
||||
ttk.TTkTestWidgetSizes(parent=hsplitter ,border=True, title="Frame3") |
||||
ttk.TTkTestWidgetSizes(parent=hsplitter ,border=True, title="Frame2", minSize=(33,7), maxSize=(33,7)) |
||||
ttk.TTkTestWidgetSizes(parent=hsplitter ,border=True, title="Frame4") |
||||
return vsplitter |
||||
|
||||
|
||||
|
||||
def main(): |
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
winSplitter = ttk.TTkWindow(parent=root,pos = (10,5), size=(100,40), title="Test Splitter", border=True, layout=ttk.TTkGridLayout()) |
||||
demoSplitter(winSplitter) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -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 |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'../..')) |
||||
import TermTk as ttk |
||||
|
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
|
||||
def demoTab(root= None): |
||||
tabWidget1 = ttk.TTkTabWidget(parent=root, border=True) |
||||
tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.1"), "Label 1.1") |
||||
tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.2"), "Label 1.2") |
||||
tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.3"), "Label Test 1.3") |
||||
tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.4"), "Label 1.4") |
||||
tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.5"), "Label Test 1.5") |
||||
tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.6"), "Label 1.6") |
||||
return tabWidget1 |
||||
|
||||
def main(): |
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
fullscreen = False |
||||
|
||||
root = ttk.TTk() |
||||
if fullscreen: |
||||
rootTab = root |
||||
root.setLayout(ttk.TTkGridLayout()) |
||||
else: |
||||
rootTab = ttk.TTkWindow(parent=root,pos=(1,1), size=(100,40), title="Test Tab", border=True, layout=ttk.TTkGridLayout()) |
||||
demoTab(rootTab) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,95 @@
|
||||
#!/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 |
||||
import 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 getSentence(a,b): |
||||
return " ".join([getWord() for i in range(0,random.randint(a,b))]) |
||||
|
||||
table_ii = 1000 |
||||
|
||||
def demoTable(root=None): |
||||
frame = ttk.TTkFrame(parent=root, border=False, layout=ttk.TTkVBoxLayout()) |
||||
top = ttk.TTkFrame(parent=frame, border=False, layout=ttk.TTkHBoxLayout()) |
||||
btn1 = ttk.TTkButton(parent=top, maxHeight=3, border=True, text='Add') |
||||
btn2 = ttk.TTkButton(parent=top, maxHeight=3, border=True, text='Add Many') |
||||
|
||||
table1 = ttk.TTkTable(parent=frame, selectColor=ttk.TTkColor.bg('#882200')) |
||||
|
||||
table1.setColumnSize((5,10,-1,10,20)) |
||||
table1.setAlignment(( |
||||
ttk.TTkK.LEFT_ALIGN, |
||||
ttk.TTkK.RIGHT_ALIGN, |
||||
ttk.TTkK.LEFT_ALIGN, |
||||
ttk.TTkK.LEFT_ALIGN, |
||||
ttk.TTkK.CENTER_ALIGN |
||||
)) |
||||
table1.setHeader(("id","Name","Sentence","Word","center")) |
||||
table1.setColumnColors(( |
||||
ttk.TTkColor.fg('#888800', modifier=ttk.TTkColorGradient(increment=6)), |
||||
ttk.TTkColor.RST, |
||||
ttk.TTkColor.fg('#00dddd', modifier=ttk.TTkColorGradient(increment=-4)), |
||||
ttk.TTkColor.RST, |
||||
ttk.TTkColor.fg('#cccccc', modifier=ttk.TTkColorGradient(increment=-2)) |
||||
)) |
||||
table1.appendItem((" - ","","You see it's all clear, You were meant to be here, From the beginning","","")) |
||||
for i in range(0, 5): |
||||
table1.appendItem((str(i), getWord(), getSentence(8,30), getWord(), getWord())) |
||||
table1.appendItem((" - ","This is the end", "Beautiful friend, This is the end My only friend", "the end", "...")) |
||||
|
||||
# Attach the add Event |
||||
|
||||
def add(): |
||||
global table_ii |
||||
table_ii+=1 |
||||
table1.appendItem((str(table_ii), getWord(), getSentence(8,30), getWord(), getWord())) |
||||
btn1.clicked.connect(add) |
||||
|
||||
def addMany(): |
||||
global table_ii |
||||
for i in range(0, 500): |
||||
table_ii+=1 |
||||
table1.appendItem((str(table_ii), getWord(), getSentence(8,30), getWord(), getWord())) |
||||
table1.appendItem((" - ","This is the end", "Beautiful friend, This is the end My only friend", "the end", "...")) |
||||
btn2.clicked.connect(addMany) |
||||
|
||||
return frame |
||||
|
||||
def main(): |
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
win_table = ttk.TTkWindow(parent=root,pos = (3,3), size=(150,40), title="Test Table 1", layout=ttk.TTkHBoxLayout(), border=True) |
||||
demoTable(win_table) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,97 @@
|
||||
#!/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. |
||||
|
||||
# Demo inspired from: |
||||
# https://stackoverflow.com/questions/41204234/python-pyqt5-qtreewidget-sub-item |
||||
|
||||
import os |
||||
import sys |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'../..')) |
||||
import TermTk as ttk |
||||
|
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
def demoTree(root=None): |
||||
# tw = ttk.TTkTreeWidget(parent=rootTree1) |
||||
tw = ttk.TTkTree(parent=root) |
||||
tw.setHeaderLabels(["Column 1", "Column 2", "Column 3"]) |
||||
tw.setColumnSize((20,20,-1)) |
||||
tw.setColumnColors(( |
||||
ttk.TTkColor.RST, |
||||
ttk.TTkColor.fg('#00dddd', modifier=ttk.TTkColorGradient(increment=-4)), |
||||
ttk.TTkColor.fg('#cccc00', modifier=ttk.TTkColorGradient(increment=-2)) |
||||
)) |
||||
l1 = ttk.TTkTreeWidgetItem(["String A", "String B", "String C"]) |
||||
l2 = ttk.TTkTreeWidgetItem(["String AA", "String BB", "String CC"]) |
||||
l3 = ttk.TTkTreeWidgetItem(["String AAA", "String BBB", "String CCC"]) |
||||
l4 = ttk.TTkTreeWidgetItem(["String AAAA", "String BBBB", "String CCCC"]) |
||||
l5 = ttk.TTkTreeWidgetItem(["String AAAAA", "String BBBBB", "String CCCCC"]) |
||||
l2.addChild(l5) |
||||
|
||||
|
||||
for i in range(3): |
||||
l1_child = ttk.TTkTreeWidgetItem(["Child A" + str(i), "Child B" + str(i), "Child C" + str(i)]) |
||||
l1.addChild(l1_child) |
||||
|
||||
for j in range(2): |
||||
l2_child = ttk.TTkTreeWidgetItem(["Child AA" + str(j), "Child BB" + str(j), "Child CC" + str(j)]) |
||||
l2.addChild(l2_child) |
||||
|
||||
for j in range(2): |
||||
l3_child = ttk.TTkTreeWidgetItem(["Child AAA" + str(j), "Child BBB" + str(j), "Child CCC" + str(j)]) |
||||
l3.addChild(l3_child) |
||||
|
||||
for j in range(2): |
||||
l4_child = ttk.TTkTreeWidgetItem(["Child AAAA" + str(j), "Child BBBB" + str(j), "Child CCCC" + str(j)]) |
||||
l4.addChild(l4_child) |
||||
|
||||
for j in range(2): |
||||
l5_child = ttk.TTkTreeWidgetItem(["Child AAAAA" + str(j), "Child BBBBB" + str(j), "Child CCCCC" + str(j)]) |
||||
l5.addChild(l5_child) |
||||
|
||||
|
||||
tw.addTopLevelItem(l1) |
||||
tw.addTopLevelItem(l2) |
||||
tw.addTopLevelItem(l3) |
||||
tw.addTopLevelItem(l4) |
||||
return tw |
||||
|
||||
|
||||
def main(): |
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
fullscreen = False |
||||
|
||||
root = ttk.TTk() |
||||
if fullscreen: |
||||
rootTree1 = root |
||||
root.setLayout(ttk.TTkGridLayout()) |
||||
else: |
||||
rootTree1 = ttk.TTkWindow(parent=root,pos = (0,0), size=(150,50), title="Test Tree 1", layout=ttk.TTkGridLayout(), border=True) |
||||
demoTree(rootTree1) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,53 @@
|
||||
#!/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 |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'../..')) |
||||
import TermTk as ttk |
||||
|
||||
|
||||
def demoWindows(root=None): |
||||
frame = ttk.TTkFrame(parent=root, border=False) |
||||
|
||||
win2_1 = ttk.TTkWindow(parent=frame,pos = (3,3), size=(40,20), title="Test Window 2.1", border=True) |
||||
win2_1.setLayout(ttk.TTkHBoxLayout()) |
||||
ttk.TTkTestWidget(parent=win2_1, border=False) |
||||
|
||||
win2_2 = ttk.TTkWindow(parent=frame,pos = (5,5), size=(40,20), title="Test Window 2.2", border=True) |
||||
win2_2.setLayout(ttk.TTkHBoxLayout()) |
||||
ttk.TTkTestWidget(parent=win2_2, border=False) |
||||
return frame |
||||
|
||||
|
||||
|
||||
def main(): |
||||
ttk.TTkLog.use_default_file_logging() |
||||
root = ttk.TTk() |
||||
win1 = ttk.TTkWindow(parent=root,pos = (1,1), size=(60,30), title="Test Window 1", border=True, layout=ttk.TTkGridLayout()) |
||||
demoWindows(win1) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,43 @@
|
||||
#!/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 |
||||
|
||||
sys.path.append(os.path.join(sys.path[0],'..')) |
||||
import TermTk as ttk |
||||
|
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
|
||||
winTabbed1 = ttk.TTkWindow(parent=root,pos=(1,1), size=(100,40), title="Test Tab", border=True, layout=ttk.TTkGridLayout()) |
||||
tabWidget1 = ttk.TTkTabWidget(parent=winTabbed1, border=True) |
||||
tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.1"), "Label 1.1") |
||||
tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.2"), "Label 1.2") |
||||
tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.3"), "Label Test 1.3") |
||||
tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.4"), "Label 1.4") |
||||
tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.5"), "Label Test 1.5") |
||||
tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.6"), "Label 1.6") |
||||
|
||||
root.mainloop() |
||||
Loading…
Reference in new issue