-
Notifications
You must be signed in to change notification settings - Fork 1
/
publisher.py
78 lines (66 loc) · 2.48 KB
/
publisher.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
# -*- coding: utf-8 -*-
# Adam Thompson 2018
import os
import sys
try:
# < Nuke 11
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
import PySide.QtGui as QtGuiWidgets
import PySide.QtUiTools as QtUiTools
except:
# >= Nuke 11
import PySide2.QtCore as QtCore
import PySide2.QtGui as QtGui
import PySide2.QtWidgets as QtGuiWidgets
import PySide2.QtUiTools as QtUiTools
class Publisher(QtGuiWidgets.QDialog):
""" Opens a window for publishing """
def __init__(self, pub_path, pub_name):
super(Publisher, self).__init__(QtGuiWidgets.QApplication.activeWindow())
self.pub_name = pub_name
self.pub_path = pub_path
self.init_ui()
self.on_name_change()
self.show()
def init_ui(self):
""" Initialize UI """
self.ok_button = QtGuiWidgets.QPushButton("OK")
self.ok_button.clicked.connect(self.accept)
self.cancel_button = QtGuiWidgets.QPushButton("Cancel")
self.cancel_button.clicked.connect(self.reject)
self.file_name_box = QtGuiWidgets.QLineEdit()
self.file_name_box.setText(self.pub_name)
self.file_name_box.textEdited.connect(self.on_name_change)
self.path_label = QtGuiWidgets.QLabel()
self.del_temp_checkbox = QtGuiWidgets.QCheckBox(
"Delete temporary file?")
self.del_temp_checkbox.setCheckState(QtCore.Qt.CheckState.Checked)
hbox = QtGuiWidgets.QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(self.ok_button)
hbox.addWidget(self.cancel_button)
vbox = QtGuiWidgets.QVBoxLayout()
vbox.addWidget(self.file_name_box)
vbox.addWidget(self.del_temp_checkbox)
vbox.addStretch(1)
vbox.addWidget(self.path_label)
vbox.addLayout(hbox)
self.setLayout(vbox)
# self.resize(500,500)
def get_del_state(self):
return self.del_temp_checkbox.isChecked()
def on_name_change(self):
""" When text box changes, edit path_label. """
self.path_label.setText(os.path.join(self.pub_path, self.file_name_box.text()))
def get_name(self):
""" Returns the name the file name the user chose. """
return self.file_name_box.text()
# Debugging -----------------------------------------------
if __name__== '__main__':
app = QtGuiWidgets.QApplication(sys.argv)
ex = Publisher('path/to/place', 'maya')
if ex.exec_():
name = ex.file_name_box.text()
print(name)
# app.exec_()