-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathui.py
More file actions
76 lines (64 loc) · 1.87 KB
/
ui.py
File metadata and controls
76 lines (64 loc) · 1.87 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
"""
qtpy dialog that launches a worker and monitors its progress.
"""
#pylint: disable=no-name-in-module
#pylint: disable=too-few-public-methods
import time
from qtpy.QtWidgets import QWidget, QDialog, QLabel, QProgressBar, QVBoxLayout, QPushButton
from qtpy.QtCore import QThread, Signal
from pymxs import runtime as rt
MINRANGE = 1
MAXRANGE = 100
class Worker(QThread):
"""
Worker thread
"""
progress = Signal(int)
aborted = False
def __init__(self):
"""
Construct the worker
"""
QThread.__init__(self)
def run(self):
"""
Increment a counter an notify progress.
Abort if aborted is True
"""
for i in range(MINRANGE, MAXRANGE):
self.progress.emit(i)
time.sleep(0.5)
if self.aborted:
return
self.progress.emit(MAXRANGE)
def abort(self):
"""
Make the worker terminate before it's done.
"""
self.aborted = True
class PyMaxDialog(QDialog):
"""
Custom dialog attached to the 3ds Max main window
"""
def __init__(self, parent=QWidget.find(rt.windows.getMAXHWND())):
super().__init__(parent)
self.setWindowTitle('Progress')
main_layout = QVBoxLayout()
label = QLabel("Progress so far")
main_layout.addWidget(label)
# progress bar
progb = QProgressBar()
progb.minimum = MINRANGE
progb.maximum = MAXRANGE
main_layout.addWidget(progb)
# abort button
btn = QPushButton("abort")
main_layout.addWidget(btn)
self.setLayout(main_layout)
self.resize(250, 100)
# start the worker
self.worker = Worker()
self.worker.progress.connect(progb.setValue)
self.worker.start()
# connect abort button
btn.clicked.connect(self.worker.abort)