simplex-solver 3.2.2__cp39-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simplex_solver-3.2.2.dist-info/DELVEWHEEL +2 -0
- simplex_solver-3.2.2.dist-info/METADATA +94 -0
- simplex_solver-3.2.2.dist-info/RECORD +84 -0
- simplex_solver-3.2.2.dist-info/WHEEL +5 -0
- simplex_solver.libs/.load-order-simplex_solver-3.2.2 +1 -0
- simplex_solver.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
- simplexui/__init__.py +86 -0
- simplexui/_version.py +1 -0
- simplexui/channelBox.py +867 -0
- simplexui/comboCheckDialog.py +396 -0
- simplexui/commands/__init__.py +16 -0
- simplexui/commands/alembicCommon.py +1148 -0
- simplexui/commands/alembic_walker.py +299 -0
- simplexui/commands/applyCorrectives.py +452 -0
- simplexui/commands/correctiveInterface.py +259 -0
- simplexui/commands/expandedExport.py +434 -0
- simplexui/commands/hdf5Convert.py +62 -0
- simplexui/commands/mayaCorrectiveInterface.py +159 -0
- simplexui/commands/mayatonumpy.py +416 -0
- simplexui/commands/mesh.py +1085 -0
- simplexui/commands/poseblendlib.py +168 -0
- simplexui/commands/reorderSimplexPoints.py +102 -0
- simplexui/commands/replaceDefinitionJson.py +74 -0
- simplexui/commands/rigidAlign.py +97 -0
- simplexui/commands/unsubdivide.py +1222 -0
- simplexui/commands/uvTransfer.py +976 -0
- simplexui/dragFilter.py +334 -0
- simplexui/falloffDialog.py +504 -0
- simplexui/img/ChefHead.png +0 -0
- simplexui/img/frozen.png +0 -0
- simplexui/interface/__init__.py +30 -0
- simplexui/interface/dummyInterface.py +1313 -0
- simplexui/interface/mayaInterface.py +2294 -0
- simplexui/interfaceModel.py +655 -0
- simplexui/interfaceModelTrees.py +456 -0
- simplexui/items/__init__.py +50 -0
- simplexui/items/accessor.py +145 -0
- simplexui/items/combo.py +645 -0
- simplexui/items/dragItem.py +44 -0
- simplexui/items/falloff.py +748 -0
- simplexui/items/group.py +267 -0
- simplexui/items/progression.py +613 -0
- simplexui/items/shape.py +384 -0
- simplexui/items/simplex.py +1734 -0
- simplexui/items/slider.py +632 -0
- simplexui/items/stack.py +147 -0
- simplexui/items/traversal.py +780 -0
- simplexui/items/treeItem.py +441 -0
- simplexui/main.pyw +22 -0
- simplexui/menu/__init__.py +73 -0
- simplexui/menu/dummyPlugins/__init__.py +16 -0
- simplexui/menu/genericPlugins/__init__.py +16 -0
- simplexui/menu/genericPlugins/_builtins.py +270 -0
- simplexui/menu/genericPlugins/checkPossibleCombos.py +48 -0
- simplexui/menu/genericPlugins/exportSplit.py +67 -0
- simplexui/menu/genericPlugins/showFalloffs.py +26 -0
- simplexui/menu/genericPlugins/showTraversals.py +26 -0
- simplexui/menu/genericPlugins/simplexUvTransfer.py +106 -0
- simplexui/menu/genericPlugins/unsubdivide.py +72 -0
- simplexui/menu/mayaPlugins/__init__.py +16 -0
- simplexui/menu/mayaPlugins/exportOther.py +53 -0
- simplexui/menu/mayaPlugins/extractProgressives.py +68 -0
- simplexui/menu/mayaPlugins/freezeCombo.py +247 -0
- simplexui/menu/mayaPlugins/generateShapeIncrementals.py +99 -0
- simplexui/menu/mayaPlugins/importObjs.py +199 -0
- simplexui/menu/mayaPlugins/linearizeTraversal.py +60 -0
- simplexui/menu/mayaPlugins/makeShelfBtn.py +67 -0
- simplexui/menu/mayaPlugins/relaxToSelection.py +76 -0
- simplexui/menu/mayaPlugins/reloadDefinition.py +44 -0
- simplexui/menu/mayaPlugins/snapToNeutral.py +71 -0
- simplexui/menu/mayaPlugins/softSelectToCluster.py +201 -0
- simplexui/menu/mayaPlugins/tweakMix.py +136 -0
- simplexui/menu/mayaPlugins/updateRestShape.py +113 -0
- simplexui/pysimplex.lib +0 -0
- simplexui/pysimplex.pyd +0 -0
- simplexui/simplexDialog.py +1547 -0
- simplexui/travCheckDialog.py +419 -0
- simplexui/traversalDialog.py +299 -0
- simplexui/ui/comboCheckDialog.ui +475 -0
- simplexui/ui/falloffDialog.ui +243 -0
- simplexui/ui/simplexDialog.ui +1458 -0
- simplexui/ui/travCheckDialog.ui +488 -0
- simplexui/ui/traversalDialog.ui +532 -0
- simplexui/utils.py +307 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
# Copyright 2016, Blur Studio
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Simplex.
|
|
4
|
+
#
|
|
5
|
+
# Simplex is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Simplex is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Lesser General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with Simplex. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
"""A Qt model that stays out of the way of the hierarchy you want to make
|
|
18
|
+
Your objects don't need to know anything about Qt. They just expose the few methods
|
|
19
|
+
that are required for the rest of the model to work.
|
|
20
|
+
|
|
21
|
+
Why do this?
|
|
22
|
+
For some cases it makes sense to have a hierarchy built into your objects, but if you
|
|
23
|
+
don't want to tightly couple your hierarchy to Qt, you have limited choices on how to
|
|
24
|
+
proceed:
|
|
25
|
+
|
|
26
|
+
One way would be to write a translation system that can map between your objects and the
|
|
27
|
+
Qt standard item hierarchy. This can be done in a non-intrusive way, but it requires
|
|
28
|
+
building and maintaining maps between the two separate hierarchies, or discovering the
|
|
29
|
+
relationship dynamically. It's totally doable, but the mapping feels fragile and it's
|
|
30
|
+
duplicating data (which I don't like)
|
|
31
|
+
|
|
32
|
+
Another possible way is to create a custom model from your objects, which is extra work.
|
|
33
|
+
So I did that work and packaged it into this setup.
|
|
34
|
+
|
|
35
|
+
Just inherit from TreeItem and override the methods that expose the tree structure.
|
|
36
|
+
Then you can attach the root of your hierarchy to the Adapter model, which translates
|
|
37
|
+
between your hierarchy and Qt. The TreeItem itself has nothing to do with QT. It
|
|
38
|
+
communicates to Qt via the OverserverServer.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
I tried to plug as many leaks in this abstraction as I could, but there's still a couple
|
|
42
|
+
things that are required. You have to call self.notifyChanged() when a
|
|
43
|
+
value visible in the tree changes. And you have to use the managers when changing
|
|
44
|
+
the hierarchy. But I think that's it.
|
|
45
|
+
|
|
46
|
+
This model doesn't handle the full "each cell can have its own separate table of
|
|
47
|
+
children" thing that the full QAbstractItemModel allows for. It's closer to the
|
|
48
|
+
QTreeWidget's model where each item is its own row.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
from __future__ import annotations
|
|
52
|
+
|
|
53
|
+
import enum
|
|
54
|
+
import uuid
|
|
55
|
+
from contextlib import ExitStack, contextmanager
|
|
56
|
+
from typing import Any, Callable, Generator, Iterator, Literal, overload
|
|
57
|
+
|
|
58
|
+
from Qt.QtCore import QAbstractItemModel, QModelIndex, QObject, Qt
|
|
59
|
+
from Qt.QtGui import QIcon
|
|
60
|
+
from Qt.QtWidgets import QTreeView
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class CustomRoles(enum.IntEnum):
|
|
64
|
+
UID_ROLE = Qt.ItemDataRole.UserRole + 1
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
SimpleGenerator = Generator[None, None, None]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class ObserverServer: # it's just fun to say!
|
|
71
|
+
def __init__(self, model: AdapterModel) -> None:
|
|
72
|
+
self.model: AdapterModel = model
|
|
73
|
+
|
|
74
|
+
def valueObserver(self, item: TreeItem) -> None:
|
|
75
|
+
self.model.itemDataChanged(item)
|
|
76
|
+
|
|
77
|
+
@contextmanager
|
|
78
|
+
def insertManager(self, parent: TreeItem, row=-1) -> SimpleGenerator:
|
|
79
|
+
parIdx = self.model.indexFromItem(parent)
|
|
80
|
+
if row == -1:
|
|
81
|
+
row = parent.getItemAppendRow()
|
|
82
|
+
self.model.beginInsertRows(parIdx, row, row)
|
|
83
|
+
try:
|
|
84
|
+
yield
|
|
85
|
+
finally:
|
|
86
|
+
self.model.endInsertRows()
|
|
87
|
+
|
|
88
|
+
@contextmanager
|
|
89
|
+
def removeManager(self, item: TreeItem) -> SimpleGenerator:
|
|
90
|
+
idx = self.model.indexFromItem(item)
|
|
91
|
+
valid = idx.isValid()
|
|
92
|
+
if valid:
|
|
93
|
+
parIdx = idx.parent()
|
|
94
|
+
self.model.beginRemoveRows(parIdx, idx.row(), idx.row())
|
|
95
|
+
try:
|
|
96
|
+
yield
|
|
97
|
+
finally:
|
|
98
|
+
if valid:
|
|
99
|
+
self.model.endRemoveRows()
|
|
100
|
+
|
|
101
|
+
@contextmanager
|
|
102
|
+
def moveManager(
|
|
103
|
+
self, item: TreeItem, destPar: TreeItem, destRow: int = -1
|
|
104
|
+
) -> SimpleGenerator:
|
|
105
|
+
itemIdx = self.model.indexFromItem(item)
|
|
106
|
+
destParIdx = self.model.indexFromItem(destPar)
|
|
107
|
+
handled = False
|
|
108
|
+
if itemIdx.isValid() and destParIdx.isValid():
|
|
109
|
+
handled = True
|
|
110
|
+
srcParIdx = itemIdx.parent()
|
|
111
|
+
row = itemIdx.row()
|
|
112
|
+
if destRow == -1:
|
|
113
|
+
destRow = destPar.getItemAppendRow()
|
|
114
|
+
self.model.beginMoveRows(srcParIdx, row, row, destParIdx, destRow)
|
|
115
|
+
try:
|
|
116
|
+
yield
|
|
117
|
+
finally:
|
|
118
|
+
if handled:
|
|
119
|
+
self.model.endMoveRows()
|
|
120
|
+
|
|
121
|
+
@contextmanager
|
|
122
|
+
def resetManager(self) -> SimpleGenerator:
|
|
123
|
+
self.model.beginResetModel()
|
|
124
|
+
try:
|
|
125
|
+
yield
|
|
126
|
+
finally:
|
|
127
|
+
self.model.endResetModel()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class TreeItem:
|
|
131
|
+
classDepth = -1
|
|
132
|
+
|
|
133
|
+
def __init__(self, root: TreeRootItem) -> None:
|
|
134
|
+
self.root: TreeRootItem = root
|
|
135
|
+
self.uid: str = uuid.uuid4().hex # Unique identifier for tree expansion
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def observers(self) -> list[ObserverServer]:
|
|
139
|
+
return self.root.observerServers()
|
|
140
|
+
|
|
141
|
+
def notifyChanged(self) -> None:
|
|
142
|
+
"""Let the observers know that this item has changed"""
|
|
143
|
+
for ob in self.observers:
|
|
144
|
+
if ob.valueObserver is not None:
|
|
145
|
+
ob.valueObserver(self)
|
|
146
|
+
|
|
147
|
+
@contextmanager
|
|
148
|
+
def insertItemManager(self, item: TreeItem, row: int = -1):
|
|
149
|
+
with ExitStack() as stack:
|
|
150
|
+
for ob in self.observers:
|
|
151
|
+
stack.enter_context(ob.insertManager(item, row=row))
|
|
152
|
+
yield
|
|
153
|
+
|
|
154
|
+
@contextmanager
|
|
155
|
+
def removeItemManager(self, item: TreeItem):
|
|
156
|
+
with ExitStack() as stack:
|
|
157
|
+
for ob in self.observers:
|
|
158
|
+
stack.enter_context(ob.removeManager(item))
|
|
159
|
+
yield
|
|
160
|
+
|
|
161
|
+
@contextmanager
|
|
162
|
+
def moveItemManager(self, item: TreeItem, destPar: TreeItem, destRow: int = -1):
|
|
163
|
+
with ExitStack() as stack:
|
|
164
|
+
for ob in self.observers:
|
|
165
|
+
stack.enter_context(ob.moveManager(item, destPar, destRow=destRow))
|
|
166
|
+
yield
|
|
167
|
+
|
|
168
|
+
@contextmanager
|
|
169
|
+
def resetManager(self):
|
|
170
|
+
with ExitStack() as stack:
|
|
171
|
+
for ob in self.observers:
|
|
172
|
+
stack.enter_context(ob.resetManager())
|
|
173
|
+
yield
|
|
174
|
+
|
|
175
|
+
################
|
|
176
|
+
# Default implementations of the methods that are available to override
|
|
177
|
+
################
|
|
178
|
+
|
|
179
|
+
def getItemAppendRow(self) -> int:
|
|
180
|
+
"""Get the row to insert at to append a new item"""
|
|
181
|
+
return 0
|
|
182
|
+
|
|
183
|
+
def treeChild(self, row: int) -> TreeItem | None:
|
|
184
|
+
"""Return the child tree item at the given row if it exists"""
|
|
185
|
+
return None
|
|
186
|
+
|
|
187
|
+
def treeRow(self) -> int:
|
|
188
|
+
"""Return the row of the current item in the tree"""
|
|
189
|
+
return 0
|
|
190
|
+
|
|
191
|
+
def treeParent(self) -> TreeItem | None:
|
|
192
|
+
"""Return the parent of this TreeItem if it has one"""
|
|
193
|
+
return None
|
|
194
|
+
|
|
195
|
+
def treeChildCount(self) -> int:
|
|
196
|
+
"""Return the number of children this item has"""
|
|
197
|
+
return 0
|
|
198
|
+
|
|
199
|
+
def treeChecked(self) -> bool | None:
|
|
200
|
+
"""Return whether this item is checked"""
|
|
201
|
+
return None
|
|
202
|
+
|
|
203
|
+
def treeData(self, column: int) -> Any | None:
|
|
204
|
+
"""Return the data for the given column"""
|
|
205
|
+
return None
|
|
206
|
+
|
|
207
|
+
def icon(self) -> QIcon | None:
|
|
208
|
+
"""Return the icon of this item, if it has one"""
|
|
209
|
+
return None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class TreeRootItem(TreeItem):
|
|
213
|
+
def __init__(self, observerServers: list[ObserverServer] | None = None) -> None:
|
|
214
|
+
super().__init__(self)
|
|
215
|
+
# The root just keeps track of everybody's observers
|
|
216
|
+
if observerServers is None:
|
|
217
|
+
observerServers = []
|
|
218
|
+
self._observerServers: list[ObserverServer] = observerServers
|
|
219
|
+
|
|
220
|
+
def addObserver(self, observerServer: ObserverServer) -> None:
|
|
221
|
+
self._observerServers.append(observerServer)
|
|
222
|
+
|
|
223
|
+
def removeObserver(self, observerServer: ObserverServer) -> None:
|
|
224
|
+
self._observerServers.remove(observerServer)
|
|
225
|
+
|
|
226
|
+
def observerServers(self) -> list[ObserverServer]:
|
|
227
|
+
return self._observerServers[:] # Return a copy
|
|
228
|
+
|
|
229
|
+
# Override this
|
|
230
|
+
def columnCount(self) -> int:
|
|
231
|
+
return 1
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
class AdapterModel(QAbstractItemModel):
|
|
235
|
+
"""Model that adapts the values from the TreeItem to the AbstractItemModel interface"""
|
|
236
|
+
|
|
237
|
+
def __init__(
|
|
238
|
+
self, rootItem: TreeRootItem | None = None, parent: QObject | None = None
|
|
239
|
+
) -> None:
|
|
240
|
+
super().__init__(parent=parent)
|
|
241
|
+
self._rootItem: TreeRootItem | None = None
|
|
242
|
+
self.observer = ObserverServer(self)
|
|
243
|
+
if rootItem is not None:
|
|
244
|
+
self.setRootItem(rootItem)
|
|
245
|
+
|
|
246
|
+
def setRootItem(self, rootItem: TreeRootItem) -> None:
|
|
247
|
+
self.beginResetModel()
|
|
248
|
+
try:
|
|
249
|
+
if self._rootItem is not None:
|
|
250
|
+
self._rootItem.removeObserver(self.observer)
|
|
251
|
+
self._rootItem = rootItem
|
|
252
|
+
self._rootItem.addObserver(self.observer)
|
|
253
|
+
finally:
|
|
254
|
+
self.endResetModel()
|
|
255
|
+
|
|
256
|
+
def getItemRow(self, item: TreeItem | None) -> int | None:
|
|
257
|
+
if item is None:
|
|
258
|
+
return None
|
|
259
|
+
return item.treeRow()
|
|
260
|
+
|
|
261
|
+
def indexFromItem(self, item: TreeItem, column: int = 0) -> QModelIndex:
|
|
262
|
+
row = self.getItemRow(item)
|
|
263
|
+
if row is None:
|
|
264
|
+
return QModelIndex()
|
|
265
|
+
return self.createIndex(row, column, item)
|
|
266
|
+
|
|
267
|
+
def itemFromIndex(self, index: QModelIndex) -> TreeItem | None:
|
|
268
|
+
return index.internalPointer()
|
|
269
|
+
|
|
270
|
+
def itemDataChanged(self, item: TreeItem) -> None:
|
|
271
|
+
idx = self.indexFromItem(item)
|
|
272
|
+
self.emitDataChanged(idx)
|
|
273
|
+
|
|
274
|
+
def emitDataChanged(self, index: QModelIndex) -> None:
|
|
275
|
+
if index.isValid():
|
|
276
|
+
self.dataChanged.emit(index, index, [])
|
|
277
|
+
|
|
278
|
+
def getChildItem(self, parent: TreeItem | None, row: int) -> TreeItem | None:
|
|
279
|
+
if parent is None:
|
|
280
|
+
if row == 0:
|
|
281
|
+
return self._rootItem
|
|
282
|
+
else:
|
|
283
|
+
return None
|
|
284
|
+
return parent.treeChild(row)
|
|
285
|
+
|
|
286
|
+
def getParentItem(self, item: TreeItem | None) -> TreeItem | None:
|
|
287
|
+
if item is None:
|
|
288
|
+
return None
|
|
289
|
+
return item.treeParent()
|
|
290
|
+
|
|
291
|
+
def getItemRowCount(self, item: TreeItem | None) -> int:
|
|
292
|
+
if item is None:
|
|
293
|
+
# Null parent means return the only root item
|
|
294
|
+
ret = 1
|
|
295
|
+
else:
|
|
296
|
+
ret = item.treeChildCount()
|
|
297
|
+
return ret
|
|
298
|
+
|
|
299
|
+
def index(self, row: int, column: int, parIndex: QModelIndex) -> QModelIndex:
|
|
300
|
+
par = parIndex.internalPointer()
|
|
301
|
+
child = self.getChildItem(par, row)
|
|
302
|
+
if child is None:
|
|
303
|
+
return QModelIndex()
|
|
304
|
+
return self.createIndex(row, column, child)
|
|
305
|
+
|
|
306
|
+
def parent(self, index: QModelIndex) -> QModelIndex:
|
|
307
|
+
if not index.isValid():
|
|
308
|
+
return QModelIndex()
|
|
309
|
+
item = index.internalPointer()
|
|
310
|
+
if item is None:
|
|
311
|
+
return QModelIndex()
|
|
312
|
+
par = self.getParentItem(item)
|
|
313
|
+
if par is None:
|
|
314
|
+
return QModelIndex()
|
|
315
|
+
row = self.getItemRow(par)
|
|
316
|
+
if row is None:
|
|
317
|
+
return QModelIndex()
|
|
318
|
+
return self.createIndex(row, 0, par)
|
|
319
|
+
|
|
320
|
+
def rowCount(self, parIndex: QModelIndex) -> int:
|
|
321
|
+
parent = parIndex.internalPointer()
|
|
322
|
+
ret = self.getItemRowCount(parent)
|
|
323
|
+
return ret
|
|
324
|
+
|
|
325
|
+
def data(self, index: QModelIndex, role: int) -> Any:
|
|
326
|
+
if not index.isValid():
|
|
327
|
+
return None
|
|
328
|
+
item = index.internalPointer()
|
|
329
|
+
return self.getItemData(item, index.column(), role)
|
|
330
|
+
|
|
331
|
+
def columnCount(self, parIndex: QModelIndex) -> int:
|
|
332
|
+
if self._rootItem is None:
|
|
333
|
+
return 1
|
|
334
|
+
return self._rootItem.columnCount()
|
|
335
|
+
|
|
336
|
+
@overload
|
|
337
|
+
def getItemData(self, item: None, column: int, role: int) -> None: ...
|
|
338
|
+
|
|
339
|
+
@overload
|
|
340
|
+
def getItemData(
|
|
341
|
+
self,
|
|
342
|
+
item: TreeItem,
|
|
343
|
+
column: int,
|
|
344
|
+
role: Literal[Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole],
|
|
345
|
+
) -> str | None: ...
|
|
346
|
+
|
|
347
|
+
@overload
|
|
348
|
+
def getItemData(
|
|
349
|
+
self,
|
|
350
|
+
item: TreeItem,
|
|
351
|
+
column: int,
|
|
352
|
+
role: Literal[Qt.ItemDataRole.CheckStateRole],
|
|
353
|
+
) -> Qt.CheckState | None: ...
|
|
354
|
+
|
|
355
|
+
@overload
|
|
356
|
+
def getItemData(
|
|
357
|
+
self,
|
|
358
|
+
item: TreeItem,
|
|
359
|
+
column: int,
|
|
360
|
+
role: Literal[Qt.ItemDataRole.DecorationRole],
|
|
361
|
+
) -> QIcon | None: ...
|
|
362
|
+
|
|
363
|
+
@overload
|
|
364
|
+
def getItemData(
|
|
365
|
+
self,
|
|
366
|
+
item: TreeItem,
|
|
367
|
+
column: int,
|
|
368
|
+
role: Literal[CustomRoles.UID_ROLE],
|
|
369
|
+
) -> str | None: ...
|
|
370
|
+
|
|
371
|
+
def getItemData(self, item: TreeItem | None, column: int, role: int) -> Any | None:
|
|
372
|
+
if item is None:
|
|
373
|
+
return None
|
|
374
|
+
|
|
375
|
+
if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole):
|
|
376
|
+
return item.treeData(column)
|
|
377
|
+
|
|
378
|
+
elif role == Qt.ItemDataRole.CheckStateRole:
|
|
379
|
+
chk = None
|
|
380
|
+
if column == 0:
|
|
381
|
+
chk = item.treeChecked()
|
|
382
|
+
if chk is not None:
|
|
383
|
+
chk = Qt.CheckState.Checked if chk else Qt.CheckState.Unchecked
|
|
384
|
+
return chk
|
|
385
|
+
elif role == Qt.ItemDataRole.DecorationRole:
|
|
386
|
+
if column == 0:
|
|
387
|
+
return item.icon()
|
|
388
|
+
elif role == CustomRoles.UID_ROLE:
|
|
389
|
+
return item.uid
|
|
390
|
+
return None
|
|
391
|
+
|
|
392
|
+
def iterindices(
|
|
393
|
+
self, pred: Callable[[QModelIndex], bool] | None = None
|
|
394
|
+
) -> Iterator[QModelIndex]:
|
|
395
|
+
"""Iterate all indices of this model breadth-first"""
|
|
396
|
+
queue = [QModelIndex()]
|
|
397
|
+
while queue:
|
|
398
|
+
index = queue.pop()
|
|
399
|
+
if pred is None or pred(index):
|
|
400
|
+
yield index
|
|
401
|
+
for row in range(self.rowCount(index)):
|
|
402
|
+
queue.append(self.index(row, 0, index))
|
|
403
|
+
|
|
404
|
+
def iteritems(
|
|
405
|
+
self, pred: Callable[[TreeItem], bool] | None = None
|
|
406
|
+
) -> Iterator[TreeItem | None]:
|
|
407
|
+
"""Iterate all items of this model breadth-first"""
|
|
408
|
+
# The only way I could make the typechecker happy was by
|
|
409
|
+
# having 2 separate loops over self.iterindices
|
|
410
|
+
if pred is None:
|
|
411
|
+
for index in self.iterindices(pred=pred):
|
|
412
|
+
yield self.itemFromIndex(index)
|
|
413
|
+
return
|
|
414
|
+
|
|
415
|
+
def itempred(x) -> bool:
|
|
416
|
+
item = self.itemFromIndex(x)
|
|
417
|
+
return False if item is None else pred(item)
|
|
418
|
+
|
|
419
|
+
for index in self.iterindices(pred=itempred):
|
|
420
|
+
yield self.itemFromIndex(index)
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
def save_view_expansion_state(tree_view: QTreeView) -> set[str]:
|
|
424
|
+
expanded_uids = set()
|
|
425
|
+
model = tree_view.model()
|
|
426
|
+
assert isinstance(model, AdapterModel)
|
|
427
|
+
|
|
428
|
+
for index in model.iterindices(pred=lambda x: tree_view.isExpanded(x)):
|
|
429
|
+
uid = model.data(index, CustomRoles.UID_ROLE)
|
|
430
|
+
if uid:
|
|
431
|
+
expanded_uids.add(uid)
|
|
432
|
+
return expanded_uids
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def restore_view_expansion_state(tree_view: QTreeView, expanded_uids: set[str]) -> None:
|
|
436
|
+
model = tree_view.model()
|
|
437
|
+
assert isinstance(model, AdapterModel)
|
|
438
|
+
for index in model.iterindices(
|
|
439
|
+
pred=lambda x: model.data(x, CustomRoles.UID_ROLE) in expanded_uids
|
|
440
|
+
):
|
|
441
|
+
tree_view.setExpanded(index, True)
|
simplexui/main.pyw
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import blurdev
|
|
2
|
+
|
|
3
|
+
if __name__ == "__main__":
|
|
4
|
+
# Ensure that my custom Qt.py import uses PyQt5
|
|
5
|
+
import os
|
|
6
|
+
import json
|
|
7
|
+
pref = json.loads(os.environ.get("QT_PREFERRED_BINDING_JSON", "{}"))
|
|
8
|
+
pref.setdefault("simplexui.Qt", ["PyQt5", "PyQt4"])
|
|
9
|
+
os.environ["QT_PREFERRED_BINDING_JSON"] = json.dumps(pref)
|
|
10
|
+
os.environ["SIMPLEX_AT_BLUR"] = "true"
|
|
11
|
+
|
|
12
|
+
from simplexui.simplexDialog import SimplexDialog
|
|
13
|
+
import simplexui
|
|
14
|
+
dlg = blurdev.launch(SimplexDialog)
|
|
15
|
+
try:
|
|
16
|
+
# Store the last simplex launch in these module variables
|
|
17
|
+
simplexui.SIMPLEX_UI_ROOT = dlg.parent()
|
|
18
|
+
simplexui.SIMPLEX_UI = dlg
|
|
19
|
+
except RuntimeError:
|
|
20
|
+
# If dlg.parent() raises a runtime error, then the ui has already been deleted
|
|
21
|
+
# This happens if we're running externally instead of internally
|
|
22
|
+
pass
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Copyright 2016, Blur Studio
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Simplex.
|
|
4
|
+
#
|
|
5
|
+
# Simplex is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Simplex is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Lesser General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with Simplex. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import importlib
|
|
21
|
+
import os
|
|
22
|
+
import pkgutil
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
from Qt.QtWidgets import QMenu
|
|
26
|
+
|
|
27
|
+
from . import genericPlugins
|
|
28
|
+
from types import ModuleType
|
|
29
|
+
|
|
30
|
+
CONTEXT = os.path.basename(sys.executable)
|
|
31
|
+
if CONTEXT == "maya.exe":
|
|
32
|
+
from . import mayaPlugins as plugins
|
|
33
|
+
else:
|
|
34
|
+
from . import dummyPlugins as plugins
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _iter_namespace(ns_pkg):
|
|
38
|
+
# Specifying the second argument (prefix) to iter_modules makes the
|
|
39
|
+
# returned name an absolute name instead of a relative one. This allows
|
|
40
|
+
# import_module to work without having to do additional modification to
|
|
41
|
+
# the name.
|
|
42
|
+
return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# Registration class
|
|
46
|
+
def loadPlugins() -> tuple[list[ModuleType], list[ModuleType]]:
|
|
47
|
+
toolModules = []
|
|
48
|
+
contextModules = []
|
|
49
|
+
imod = sorted([i[1] for i in _iter_namespace(genericPlugins)])
|
|
50
|
+
imod += sorted([i[1] for i in _iter_namespace(plugins)])
|
|
51
|
+
|
|
52
|
+
plugs = [importlib.import_module(name) for name in imod]
|
|
53
|
+
for module in plugs:
|
|
54
|
+
if hasattr(module, "registerTool"):
|
|
55
|
+
toolModules.append(module)
|
|
56
|
+
if hasattr(module, "registerContext"):
|
|
57
|
+
contextModules.append(module)
|
|
58
|
+
|
|
59
|
+
return toolModules, contextModules
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def buildToolMenu(window, modules):
|
|
63
|
+
menu = window.menuBar.addMenu("Tools")
|
|
64
|
+
for m in modules:
|
|
65
|
+
m.registerTool(window, menu)
|
|
66
|
+
return menu
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def buildRightClickMenu(tree, indexes, modules) -> QMenu:
|
|
70
|
+
menu = QMenu()
|
|
71
|
+
for m in modules:
|
|
72
|
+
m.registerContext(tree, indexes, menu)
|
|
73
|
+
return menu
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2016, Blur Studio
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Simplex.
|
|
4
|
+
#
|
|
5
|
+
# Simplex is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Simplex is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Lesser General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with Simplex. If not, see <http://www.gnu.org/licenses/>.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2016, Blur Studio
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Simplex.
|
|
4
|
+
#
|
|
5
|
+
# Simplex is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Simplex is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Lesser General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with Simplex. If not, see <http://www.gnu.org/licenses/>.
|