28 changed files with 876 additions and 227 deletions
@ -1,2 +1 @@
|
||||
from .viewitem import * |
||||
from .treewidgetitem import * |
||||
from .viewitem import * |
||||
@ -0,0 +1,6 @@
|
||||
from .table import * |
||||
from .tableview import * |
||||
from .tree import * |
||||
from .treeview import * |
||||
from .treewidget import * |
||||
from .treewidgetitem import * |
||||
@ -0,0 +1,61 @@
|
||||
#!/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.Fancy.treewidget import TTkFancyTreeWidget |
||||
from TermTk.TTkLayouts.gridlayout import TTkGridLayout |
||||
from TermTk.TTkAbstract.abstractscrollarea import TTkAbstractScrollArea |
||||
|
||||
class TTkFancyTree(TTkAbstractScrollArea): |
||||
__slots__ = ( |
||||
'_treeView', 'activated', |
||||
# Forwarded Methods |
||||
'setAlignment', 'setHeader', 'setHeaderLabels', 'setColumnSize', 'setColumnColors', 'appendItem', 'addTopLevelItem' ) |
||||
|
||||
def __init__(self, *args, **kwargs): |
||||
TTkAbstractScrollArea.__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , 'TTkFancyTree' ) |
||||
if 'parent' in kwargs: kwargs.pop('parent') |
||||
self._treeView = TTkFancyTreeWidget(*args, **kwargs) |
||||
# Forward the signal |
||||
self.activated = self._treeView.activated |
||||
|
||||
self.setFocusPolicy(TTkK.ClickFocus) |
||||
self.setViewport(self._treeView) |
||||
|
||||
# Forwarded Methods |
||||
self.setAlignment = self._treeView.setAlignment |
||||
self.setHeader = self._treeView.setHeader |
||||
self.setHeaderLabels = self._treeView.setHeaderLabels |
||||
self.setColumnSize = self._treeView.setColumnSize |
||||
self.setColumnColors = self._treeView.setColumnColors |
||||
self.appendItem = self._treeView.appendItem |
||||
self.addTopLevelItem = self._treeView.addTopLevelItem |
||||
|
||||
|
||||
|
||||
@ -0,0 +1,157 @@
|
||||
#!/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.checkbox import TTkCheckbox |
||||
from TermTk.TTkLayouts.gridlayout import TTkGridLayout |
||||
from TermTk.TTkWidgets.Fancy.tableview import TTkFancyTableView |
||||
from TermTk.TTkWidgets.Fancy.treewidgetitem import TTkFancyTreeWidgetItem |
||||
|
||||
class _TTkDisplayedTreeItemControl(TTkCheckbox): |
||||
def __init__(self, *args, **kwargs): |
||||
super().__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , '_TTkDisplayedTreeItemControl' ) |
||||
self.setMinimumSize(1, 1) |
||||
|
||||
def paintEvent(self): |
||||
if self._checked: |
||||
self._canvas.drawText(pos=(0,0), text="▼") |
||||
else: |
||||
self._canvas.drawText(pos=(0,0), text="▶") |
||||
|
||||
|
||||
class _TTkDisplayedTreeItem(TTkWidget): |
||||
__slots__ = ('_depth', '_control', '_text', '_id', '_clicked', '_treeWidgetItem', '_isLeaf' ) |
||||
def __init__(self, *args, **kwargs): |
||||
super().__init__(self, *args, **kwargs) |
||||
#Signals |
||||
self._clicked = pyTTkSignal(bool, _TTkDisplayedTreeItem, TTkFancyTreeWidgetItem) |
||||
|
||||
self._name = kwargs.get('name' , '_TTkDisplayedTreeItem' ) |
||||
self._depth = kwargs.get('depth' , 0 ) |
||||
self._text = kwargs.get('text' , "" ) |
||||
self._id = kwargs.get('id' , 0 ) |
||||
self._treeWidgetItem = kwargs.get('treeWidgetItem', None) |
||||
self._isLeaf = self._treeWidgetItem.childIndicatorPolicy() == TTkK.DontShowIndicator |
||||
self._isLeaf |= self._treeWidgetItem.childIndicatorPolicy() == TTkK.DontShowIndicatorWhenChildless and not self._treeWidgetItem.children() |
||||
if self._isLeaf: |
||||
self._control = None |
||||
else: |
||||
self._control = _TTkDisplayedTreeItemControl(parent=self, checked=self._treeWidgetItem.expand()) |
||||
self._control.setGeometry(self._depth, 0, 1, 1) |
||||
self._control.clicked.connect(self._controlClicked) |
||||
|
||||
@pyTTkSlot(bool) |
||||
def _controlClicked(self, status): |
||||
self._clicked.emit(status, self, self._treeWidgetItem) |
||||
|
||||
def paintEvent(self): |
||||
if self._isLeaf: |
||||
self._canvas.drawText(pos=(self._depth, 0), text="•") |
||||
self._canvas.drawText(pos=(self._depth+2, 0), text=self._text) |
||||
|
||||
|
||||
class TTkFancyTreeWidget(TTkFancyTableView): |
||||
__slots__ = ( '_topLevelItems') |
||||
|
||||
def __init__(self, *args, **kwargs): |
||||
super().__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , 'TTkFancyTreeView' ) |
||||
self._topLevelItems = TTkFancyTreeWidgetItem(None) |
||||
self.doubleClicked.connect(self._doubleClickItem) |
||||
# if 'parent' in kwargs: kwargs.pop('parent') |
||||
|
||||
def _expand(self, item, depth): |
||||
item.setExpand(True) |
||||
item.refresh() |
||||
toExpand = [] |
||||
index = self.indexOf(item.data())+1 |
||||
if index != 0: |
||||
for child in item.children(): |
||||
self._addTreeWidgetItem(item=child, depth=depth, index=index) |
||||
index+=1 |
||||
if child.expand(): |
||||
toExpand.append(child) |
||||
for child in toExpand: |
||||
self._expand(item=child, depth=(depth+1)) |
||||
|
||||
|
||||
def _shrink(self, item): |
||||
item.setExpand(False) |
||||
item.refresh() |
||||
index = self.indexOf(item.data()) |
||||
parent = item.parent() |
||||
if item == parent.children()[-1]: |
||||
self.removeItemsFrom(index+1) |
||||
else: |
||||
nextItemIndex = parent.children().index(item) |
||||
nextItem = parent.children()[nextItemIndex+1] |
||||
indexTo = self.indexOf(nextItem.data()) |
||||
for id in reversed(range(index+1,indexTo)): |
||||
self.removeItemAt(id) |
||||
|
||||
@pyTTkSlot(int) |
||||
def _doubleClickItem(self, index): |
||||
if not (item := self.itemAt(index)): return |
||||
if item[0]._isLeaf: return |
||||
if not item[0]._treeWidgetItem.expand(): # we need to expand the TTkFancyTreeWidgetItem |
||||
self._expand(item=item[0]._treeWidgetItem, depth=item[0]._depth+1) |
||||
else: # we need to shrink the TTkFancyTreeWidgetItem |
||||
self._shrink(item=item[0]._treeWidgetItem) |
||||
|
||||
|
||||
@pyTTkSlot(bool, _TTkDisplayedTreeItem, TTkFancyTreeWidgetItem) |
||||
def _controlClicked(self, status, widget, item): |
||||
TTkLog.debug(f"{status} {widget._name}") |
||||
if status: # we need to expand the TTkFancyTreeWidgetItem |
||||
self._expand(item=item, depth=(widget._depth+1)) |
||||
else: # we need to shrink the TTkFancyTreeWidgetItem |
||||
self._shrink(item=item) |
||||
|
||||
def _addTreeWidgetItem(self, item, depth=0, index=-1): |
||||
if not isinstance(item, TTkFancyTreeWidgetItem): |
||||
raise TypeError("TTkFancyTreeWidgetItem is required in TTkFancyTreeWidget.addTopLevelItem(item)") |
||||
if item.parent() is None: |
||||
self._topLevelItems.addChild(item) |
||||
displayedItems = item.data().copy() |
||||
displayTreeItem = _TTkDisplayedTreeItem(text=displayedItems[0], id=0, depth=depth, treeWidgetItem=item) |
||||
displayTreeItem._clicked.connect(self._controlClicked) |
||||
displayedItems[0] = displayTreeItem |
||||
if index == -1: |
||||
self.appendItem(item=displayedItems, id=item.data()) |
||||
else: |
||||
self.insertItem(item=displayedItems, id=item.data(), index=index, ) |
||||
|
||||
def addTopLevelItem(self, item): |
||||
self._addTreeWidgetItem(item) |
||||
|
||||
def setHeaderLabels(self, labels): |
||||
columns = [-1]*len(labels) |
||||
self.setColumnSize(columns) |
||||
self.setHeader(labels) |
||||
@ -1 +1,2 @@
|
||||
from .colorpicker import * |
||||
from .colorpicker import * |
||||
from .filepicker import * |
||||
@ -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. |
||||
|
||||
from os import walk |
||||
|
||||
from TermTk.TTkWidgets.window import TTkWindow |
||||
from TermTk.TTkWidgets.Fancy.treewidgetitem import TTkFancyTreeWidgetItem |
||||
|
||||
class _FileWidgetItem(TTkFancyTreeWidgetItem): |
||||
def __init__(self, *args, **kwargs): |
||||
TTkFancyTreeWidgetItem.__init__(self, *args, **kwargs) |
||||
|
||||
class TTkFileDialogPicker(TTkWindow): |
||||
def __init__(self, *args, **kwargs): |
||||
TTkWindow.__init__(self, *args, **kwargs) |
||||
self._name = kwargs.get('name' , 'TTkFileDialogPicker' ) |
||||
|
||||
''' |
||||
for (dirpath, dirnames, filenames) in walk('/tmp'): |
||||
print(f"{dirpath} {dirnames} {filenames}") |
||||
break |
||||
''' |
||||
@ -1,29 +1,28 @@
|
||||
from .widget import * |
||||
from .spacer import * |
||||
from .frame import * |
||||
from .widget import * |
||||
from .spacer import * |
||||
from .frame import * |
||||
from .resizableframe import * |
||||
from .splitter import * |
||||
from .label import * |
||||
from .button import * |
||||
from .checkbox import * |
||||
from .radiobutton import * |
||||
from .combobox import * |
||||
from .lineedit import * |
||||
from .texedit import * |
||||
from .scrollbar import * |
||||
from .scrollarea import * |
||||
from .window import * |
||||
from .tabwidget import * |
||||
from .list_ import * |
||||
from .listwidget import * |
||||
from .table import * |
||||
from .tableview import * |
||||
from .tree import * |
||||
from .treeview import * |
||||
from .treewidget import * |
||||
from .graph import * |
||||
from .menubar import * |
||||
from .TTkPickers import * |
||||
from .spinbox import * |
||||
from .image import TTkImage |
||||
from .about import TTkAbout |
||||
from .splitter import * |
||||
from .label import * |
||||
from .button import * |
||||
from .checkbox import * |
||||
from .radiobutton import * |
||||
from .combobox import * |
||||
from .lineedit import * |
||||
from .texedit import * |
||||
from .scrollbar import * |
||||
from .scrollarea import * |
||||
from .window import * |
||||
from .tabwidget import * |
||||
from .list_ import * |
||||
from .listwidget import * |
||||
from .graph import * |
||||
from .menubar import * |
||||
from .TTkPickers import * |
||||
from .spinbox import * |
||||
from .image import TTkImage |
||||
from .about import TTkAbout |
||||
from .tree import TTkTree |
||||
from .treewidget import TTkTreeWidget |
||||
from .treewidgetitem import TTkTreeWidgetItem |
||||
from .Fancy import * |
||||
|
||||
@ -0,0 +1,100 @@
|
||||
#!/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.TTkAbstract.abstractitemmodel import TTkAbstractItemModel |
||||
|
||||
|
||||
class TTkTreeWidgetItem(TTkAbstractItemModel): |
||||
__slots__ = ('_parent', '_data', '_children', '_expanded', '_selected', |
||||
'_childIndicatorPolicy', |
||||
# Signals |
||||
'refreshData') |
||||
|
||||
def __init__(self, *args, **kwargs): |
||||
# Signals |
||||
self.refreshData = pyTTkSignal(TTkTreeWidgetItem) |
||||
super().__init__(self, *args, **kwargs) |
||||
self._children = [] |
||||
self._data = args[0] if len(args)>0 and type(args[0])==list else None |
||||
self._parent = kwargs.get('parent', None) |
||||
self._childIndicatorPolicy = kwargs.get('childIndicatorPolicy', TTkK.DontShowIndicatorWhenChildless) |
||||
self._expanded = False |
||||
self._selected = False |
||||
self._parent = kwargs.get("parent", None) |
||||
|
||||
def addChild(self, child): |
||||
self._children.append(child) |
||||
child._parent = self |
||||
child.dataChanged.connect(self.emitDataChanged) |
||||
self.dataChanged.emit() |
||||
|
||||
def addChildren(self, children): |
||||
for child in children: |
||||
self.addChild(child) |
||||
|
||||
def child(self, index): |
||||
if 0 <= index < len(self._children): |
||||
return self._children[index] |
||||
return None |
||||
|
||||
def children(self): |
||||
return self._children |
||||
|
||||
def data(self, column, role=None): |
||||
if column >= len(self._data): |
||||
return None |
||||
return self._data[column] |
||||
|
||||
@pyTTkSlot() |
||||
def emitDataChanged(self): |
||||
self.dataChanged.emit() |
||||
|
||||
# def setDisabled(disabled): |
||||
# pass |
||||
|
||||
def setExpanded(self, expand): |
||||
self._expanded = expand |
||||
self.emitDataChanged() |
||||
|
||||
def setSelected(self, select): |
||||
self._selected = select |
||||
|
||||
# def isDisabled(): |
||||
# pass |
||||
|
||||
def isExpanded(self): |
||||
return self._expanded |
||||
|
||||
def isSelected(self): |
||||
return self._selected |
||||
|
||||
def size(self): |
||||
if self._expanded: |
||||
return 1 + sum([c.size() for c in self._children]) |
||||
else: |
||||
return 1 |
||||
@ -0,0 +1,119 @@
|
||||
#!/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 |
||||
import random |
||||
import argparse |
||||
|
||||
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 demoFancyTree(root=None): |
||||
# tw = ttk.TTkFancyTreeWidget(parent=rootTree1) |
||||
tw = ttk.TTkFancyTree(parent=root) |
||||
tw.setHeaderLabels(["Column 1", "Column 2", "Column 3"]) |
||||
tw.setColumnSize((-1,20,20)) |
||||
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.TTkFancyTreeWidgetItem(["String A", "String B", "String C"]) |
||||
l2 = ttk.TTkFancyTreeWidgetItem(["String AA", "String BB", "String CC"]) |
||||
l3 = ttk.TTkFancyTreeWidgetItem(["String AAA", "String BBB", "String CCC"]) |
||||
l4 = ttk.TTkFancyTreeWidgetItem(["String AAAA", "String BBBB", "String CCCC"]) |
||||
l5 = ttk.TTkFancyTreeWidgetItem(["String AAAAA", "String BBBBB", "String CCCCC"]) |
||||
|
||||
l2.addChild(l5) |
||||
|
||||
for i in range(3): |
||||
l1_child = ttk.TTkFancyTreeWidgetItem(["Child A" + str(i), "Child B" + str(i), "Child C" + str(i)]) |
||||
l1.addChild(l1_child) |
||||
|
||||
for j in range(2): |
||||
l2_child = ttk.TTkFancyTreeWidgetItem(["Child AA" + str(j), "Child BB" + str(j), "Child CC" + str(j)]) |
||||
l2.addChild(l2_child) |
||||
|
||||
for j in range(2): |
||||
l3_child = ttk.TTkFancyTreeWidgetItem(["Child AAA" + str(j), "Child BBB" + str(j), "Child CCC" + str(j)]) |
||||
l3.addChild(l3_child) |
||||
|
||||
for j in range(2): |
||||
l4_child = ttk.TTkFancyTreeWidgetItem(["Child AAAA" + str(j), "Child BBBB" + str(j), "Child CCCC" + str(j)]) |
||||
l4.addChild(l4_child) |
||||
|
||||
for j in range(2): |
||||
l5_child = ttk.TTkFancyTreeWidgetItem(["Child AAAAA" + str(j), "Child BBBBB" + str(j), "Child CCCCC" + str(j)]) |
||||
l5.addChild(l5_child) |
||||
|
||||
l6 = ttk.TTkFancyTreeWidgetItem(["RND", "RND", "RND"], childIndicatorPolicy=ttk.TTkK.ShowIndicator) |
||||
|
||||
def updateChildren(item): |
||||
if item.children(): return |
||||
for _ in range(0,random.randint(3,8)): |
||||
child = ttk.TTkFancyTreeWidgetItem([getWord(),getWord(),getWord()]) |
||||
if random.randint(0,10)>5: |
||||
child.setChildIndicatorPolicy(ttk.TTkK.ShowIndicator) |
||||
child.refreshData.connect(updateChildren) |
||||
item.addChild(child) |
||||
|
||||
|
||||
l6.refreshData.connect(updateChildren) |
||||
|
||||
tw.addTopLevelItem(l1) |
||||
tw.addTopLevelItem(l2) |
||||
tw.addTopLevelItem(l3) |
||||
tw.addTopLevelItem(l4) |
||||
tw.addTopLevelItem(l6) |
||||
|
||||
return tw |
||||
|
||||
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: |
||||
rootTree1 = root |
||||
root.setLayout(ttk.TTkGridLayout()) |
||||
else: |
||||
rootTree1 = ttk.TTkWindow(parent=root,pos = (0,0), size=(70,40), title="Test Tree 1", layout=ttk.TTkGridLayout(), border=True) |
||||
demoFancyTree(rootTree1) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -0,0 +1,88 @@
|
||||
#!/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() |
||||
|
||||
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) |
||||
|
||||
# tw = ttk.TTkFancyTreeWidget(parent=rootTree1) |
||||
tw = ttk.TTkFancyTree(parent=rootTree1) |
||||
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.TTkFancyTreeWidgetItem(["String A", "String B", "String C"]) |
||||
l2 = ttk.TTkFancyTreeWidgetItem(["String AA", "String BB", "String CC"]) |
||||
l3 = ttk.TTkFancyTreeWidgetItem(["String AAA", "String BBB", "String CCC"]) |
||||
l4 = ttk.TTkFancyTreeWidgetItem(["String AAAA", "String BBBB", "String CCCC"]) |
||||
l5 = ttk.TTkFancyTreeWidgetItem(["String AAAAA", "String BBBBB", "String CCCCC"]) |
||||
l2.addChild(l5) |
||||
|
||||
|
||||
for i in range(3): |
||||
l1_child = ttk.TTkFancyTreeWidgetItem(["Child A" + str(i), "Child B" + str(i), "Child C" + str(i)]) |
||||
l1.addChild(l1_child) |
||||
|
||||
for j in range(2): |
||||
l2_child = ttk.TTkFancyTreeWidgetItem(["Child AA" + str(j), "Child BB" + str(j), "Child CC" + str(j)]) |
||||
l2.addChild(l2_child) |
||||
|
||||
for j in range(2): |
||||
l3_child = ttk.TTkFancyTreeWidgetItem(["Child AAA" + str(j), "Child BBB" + str(j), "Child CCC" + str(j)]) |
||||
l3.addChild(l3_child) |
||||
|
||||
for j in range(2): |
||||
l4_child = ttk.TTkFancyTreeWidgetItem(["Child AAAA" + str(j), "Child BBBB" + str(j), "Child CCCC" + str(j)]) |
||||
l4.addChild(l4_child) |
||||
|
||||
for j in range(2): |
||||
l5_child = ttk.TTkFancyTreeWidgetItem(["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) |
||||
|
||||
root.mainloop() |
||||
Loading…
Reference in new issue