This repository was archived by the owner on Aug 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.cgx
More file actions
157 lines (140 loc) · 3.72 KB
/
Copy pathapp.cgx
File metadata and controls
157 lines (140 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<window unified-title-and-tool-bar-on-mac >
<menubar>
<menu title="File">
<action
v-for="toggle in ['dock', 'dock_content', 'dock_title', 'toolbar', 'action', 'statusbar']"
:text="f'Toggle {toggle}'"
:object-name="f'toggle_{toggle}'"
@triggered="partial(lambda toggle: toggle_item(toggle), toggle=toggle)"
/>
<action separator />
<action
text="&Quit"
:role="QtGui.QAction.QuitRole"
@triggered="quit"
/>
</menu>
<menu title="Status">
<action
text="Change text"
@triggered="update_status_bar"
/>
</menu>
</menubar>
<widget>
<label text="Main widget" />
<button @clicked="button_clicked" />
<qcombobox
:items="['foo', 'bar']"
@activated="on_combobox_changed"
/>
</widget>
<dock
v-if="toggles['show_dock']"
:area="docks['dock']"
object-name="dock"
@dock-location-changed="on_dock_location_changed"
>
<widget
v-if="toggles['show_dock_title']"
object-name="dock_title"
title
>
<label text="Title" />
</widget>
<widget
v-if="toggles['show_dock_content']"
object-name="dock_content"
>
<treeview>
<itemmodel :horizontal-header-labels="['Foo', 'Bar']">
<standarditem
v-for="item in standard_items"
v-bind="item"
/>
</itemmodel>
</treeview>
</widget>
</dock>
<dock :area="QtCore.Qt.RightDockWidgetArea">
<widget>
<label text="other" />
</widget>
</dock>
<toolbar
v-if="toggles['show_toolbar']"
object-name="toolbar"
>
<action
v-if="toggles['show_action']"
text="New"
object-name="action"
@triggered="on_new"
/>
</toolbar>
<statusbar
v-if="toggles['show_statusbar']"
object-name="statusbar"
:text="f'Hello there {name}', 2000"
/>
</window>
<script>
from functools import partial
from PySide6 import QtCore, QtGui, QtWidgets
import kolla
STATE_MAP = {
False: QtCore.Qt.Unchecked,
True: QtCore.Qt.Checked,
}
def quit():
QtWidgets.QApplication.instance().quit()
class App(kolla.Component):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.state['name'] = "handsome"
self.state["toggles"] = {
"show_dock": True,
"show_dock_title": True,
"show_dock_content": True,
"show_toolbar": True,
"show_action": True,
"show_statusbar": True,
}
self.state["items"] = [
[["Item", "Value"], False],
[["Foo", "Bar"], False],
]
self.state['docks'] = {
"dock": QtCore.Qt.LeftDockWidgetArea,
}
@property
def standard_items(self):
items = []
for row, (item, check_state) in enumerate(self.state["items"]):
for column, text in enumerate(item):
child_props = {
"text": text,
"model_index": (row, column),
"checkable": column == 0,
}
if column == 0:
child_props["check_state"] = STATE_MAP[check_state]
items.append(child_props)
return items
def update_status_bar(self):
self.state["name"] = "beautiful"
def on_combobox_changed(self, index):
pass
def on_dock_location_changed(self, area):
self.state['docks']['dock'] = area
def on_new(self):
pass
def on_import(self):
pass
def button_clicked(self):
pass
def toggle_item(self, name):
self.state["toggles"][f"show_{name}"] = not self.state["toggles"][
f"show_{name}"
]
</script>