-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuiTest.py
112 lines (78 loc) · 3.37 KB
/
uiTest.py
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
# PySide 2
from PySide2.QtUiTools import QUiLoader
import PySide2.QtWidgets as QtW
from PySide2.QtCore import QFile
import MaxPlus
import sys
import os
# For 3ds Max - Temporarily add this file's directory to PATH
sys.path.append(os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))))
import util_pymxs as util
# Utility functions
max_out = util.max_out
class MaxDialogStarter(QtW.QDialog):
def __init__(self, ui_file, parent=MaxPlus.GetQMaxMainWindow()):
"""
The Initialization of the main UI class
:param ui_file: The path to the .UI file from QDesigner
:param parent: The main Max Window
"""
super(MaxDialogStarter, self).__init__(parent)
# ---------------------------------------------------
# Variables
# ---------------------------------------------------
self._ui_file_string = ui_file
self._parent = parent
# ---------------------------------------------------
# Main Init
# ---------------------------------------------------
# UI Loader
ui_file = QFile(self._ui_file_string)
ui_file.open(QFile.ReadOnly)
loader = QUiLoader()
self._widget = loader.load(ui_file)
ui_file.close()
# Attaches loaded UI to the dialog box
main_layout = QtW.QVBoxLayout()
main_layout.addWidget(self._widget)
self.setLayout(main_layout)
# Titling
# self._window_title = "Optional Custom Title"
# self.setWindowTitle(self._window_title)
# ---------------------------------------------------
# Widget Definitions
# ---------------------------------------------------
self._test_debug_layer = self.findChild(QtW.QLineEdit, 'jh_debug_layer')
self._test_debug_light = self.findChild(QtW.QLineEdit, 'jh_debug_light')
self._test_thing1_btn = self.findChild(QtW.QPushButton, 'jh_thing1_btn')
self._test_thing2_btn = self.findChild(QtW.QPushButton, 'jh_thing2_btn')
self._test_lineprint_btn = self.findChild(QtW.QPushButton, 'jh_lineprint_btn')
self._test_lineprint_input = self.findChild(QtW.QLineEdit, 'jh_lineprint_input')
# ---------------------------------------------------
# Function Definitions
# ---------------------------------------------------
self._test_thing1_btn.clicked.connect(self._test_do_thing1) # Can't easily pass arguments, so call thing1 or
self._test_thing2_btn.clicked.connect(self._test_do_thing2) # thing2 directly.
self._test_lineprint_btn.clicked.connect(self._test_lineprint)
def _test_do_thing1(self):
max_out('Thing 1')
return
def _test_do_thing2(self):
max_out('Thing 2')
return
def _test_lineprint(self):
max_out(self._test_lineprint_input.text()) # Get the contents of the line edit textbox with its .text() method
return
# Code for opening the dialog
app = MaxPlus.GetQMaxMainWindow()
ui = MaxDialogStarter(uif, app)
# Path to UI file
uif = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) + "\\qtDesignerTest.ui"
# Destroys instances of the dialog before recreating it
# noinspection PyBroadException
try:
# noinspection PyUnboundLocalVariable
ui.close()
except:
pass
ui.show()