Using TTkAppTemplate #498
Replies: 4 comments 19 replies
-
|
In my application I use different HEADER widget for each different mode of the program, and I found the similar issue as you describe so I had to place the widgets inside a TTkContainer and then place that into the TTkAppTemplate() using the position argument, such as... If nothing was placed there at first then nothing shows up when it's later changed, but putting everything inside different Container widgets solves it. I assume it has the same behaviour for MAIN as for the HEADER position, except if your widget is scrollable then you might also need to handle |
Beta Was this translation helpful? Give feedback.
-
|
@lucaminifreelance-art I am not completely sure about your request, can you provide me a simple drawing of the results? Are you interested in something like this? Screen.Recording.2025-10-29.at.14.42.37.002.movthe menu at the top-left is a custom widget so it is not what you are asking for (unless you want to implement something similar) the menu at the center instead are 3 menu with zero items each. I just attached a switching routine at their keypress. the trick is normally to use The switch happen hiding all of them and show only the one that need to be shown. widget.setVisible(visible)
panel.layout.addWidget(widget)
panel.widgets.append(widget)
mb = panel.menuBar.addMenu(name, alignment=ttk.TTkK.LEFT_ALIGN)
@ttk.pyTTkSlot()
def _showBottomTab():
for _w in self._panels[self.Position.BOTTOM].widgets:
_w.hide()
widget.show()
mb.menuButtonClicked.connect(_showBottomTab) |
Beta Was this translation helpful? Give feedback.
-
|
For the example I need more time...this is a video for the issue: |
Beta Was this translation helpful? Give feedback.
-
|
Unfortunately it is quite hard to spot what could have gone wrong in your files. So far everything looks ok, I suspected that the focus of the table could have influenced the behavior so, I wrote a simple example where I emulate your widgets allocation, but I am not able to reproduce the issue. I added few extra cleanup steps (i.e. I ensure the previous terminal closed before spawning another one) Screen.Recording.2025-10-31.at.10.21.41.002.movHave a look: import sys, os
from dataclasses import dataclass
from typing import Optional
import TermTk as ttk
class TestForm(ttk.TTkGridLayout):
def __init__(self):
super().__init__()
splitter = ttk.TTkSplitter()
model = ttk.TTkTableModelList(data=[[f"{_c},{_r}" for _c in range(10)] for _r in range(10)])
self._table = table = ttk.TTkTable(tableModel=model)
self._tree = tree = ttk.TTkTree()
tree.setHeaderLabels(["Column 1", "Column 2", "Column 3"])
splitter.addWidget(table)
splitter.addWidget(tree)
self.addWidget(splitter)
table.cellClicked.connect(self._populateTree)
@ttk.pyTTkSlot(int,int)
def _populateTree(self, row:int, col:int) -> None:
data = self._table.model().data(row=row, col=col)
l0 = ttk.TTkTreeWidgetItem([f"{data}", f"{data}", f"{data}"])
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"])
self._tree.clear()
self._tree.addTopLevelItems(items=[l0,l1,l2,l3,l4,l5])
root = ttk.TTk()
btn_term = ttk.TTkButton(parent=root, pos=( 0,0), text='Term', border=True)
btn_form = ttk.TTkButton(parent=root, pos=( 8,0), text='Table/Tree', border=True)
ttk.TTkButton(parent=root, pos=(32,0), text='Quit', border=True).clicked.connect(ttk.TTkHelper.quit)
winLog=ttk.TTkWindow(parent=root, pos=(0,3), size=(100,30), border=True, layout=ttk.TTkGridLayout())
ttk.TTkLogViewer(parent=winLog)
win=ttk.TTkWindow(parent=root, pos=(5,6), size=(100,30), border=True, layout=ttk.TTkGridLayout())
app=ttk.TTkAppTemplate(parent=win)
app.setWidget(widget=ttk.TTkTestWidgetSizes(), position=app.LEFT, size=30)
app.setWidget(widget=ttk.TTkTestWidgetSizes(), position=app.MAIN)
menu_bar = ttk.TTkMenuBarLayout()
app.setMenuBar(menu_bar, app.LEFT)
menu = menu_bar.addMenu('Menu')
menu_term = menu.addMenu("Term")
menu_form = menu.addMenu("Form")
@dataclass
class _TermState():
term:Optional[ttk.TTkTerminal] = None
def close_term(self) -> None:
if self.term:
self.term.close()
self.term = None
termState = _TermState()
@ttk.pyTTkSlot()
def _set_terminal() -> None:
termState.close_term()
termState.term = term = ttk.TTkTerminal()
app.setWidget(widget=term, position=app.MAIN)
th = ttk.TTkTerminalHelper(term=term)
th.runShell()
@ttk.pyTTkSlot()
def _set_form() -> None:
termState.close_term()
new_form = TestForm()
app.setItem(item=new_form, position=app.MAIN)
btn_form.clicked.connect(_set_form)
btn_term.clicked.connect(_set_terminal)
menu_form.menuButtonClicked.connect(_set_form)
menu_term.menuButtonClicked.connect(_set_terminal)
root.mainloop() |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to use the TTkAppTemplate to make my application. I would like to load in the main panel many kind of widget depending on the menu voice selected. For example one time I want to have a terminal, another time I would load a table splitted with a property editor made with tree and so on. I tried to do it, but if I load the table with property editor i I don't touch anything it can be changed in a terminal, but if I touch a scroll bar, select something in the table, I can't change it. I don't see any changes. Log is enabled but I don't see any error. I tried the removeItem/removeWidget too without success. Which is the right way to load different widget in MAIN panel?
If it can help I could make a video of the issue.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions