# Loading a Qt Designer UI file and editing the loaded widget
import os
import functools
from PySide2 import QtWidgets, QtCore, QtUiTools, QtGui
from shiboken2 import wrapInstance
import maya.cmds as mc
import maya.OpenMayaUI as omui
import makeRobotBug, makeSpiralStairs, randomlyPlace
'''
import thisModule
reload (thisModule)
thisModule.run()
'''
def getMayaWindow():
''' pointer to the maya main window '''
ptr = omui.MQtUtil.mainWindow()
if ptr:
return wrapInstance(long(ptr), QtWidgets.QMainWindow)
def run():
''' builds our UI '''
global win
win = GeometryGenerator(parent=getMayaWindow())
#win.show()
class GeometryGenerator(QtWidgets.QDialog):
def __init__(self,parent=None):
super(GeometryGenerator,self).__init__(parent)
#self.resize(400, 300)
## From Pysideuic compiled code goes here
#############################################################
self.gridLayout = QtWidgets.QGridLayout()
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setContentsMargins(5, 5, 5, 5)
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setContentsMargins(5, 5, 5, 5)
self.pushBtn_makeRobot = QtWidgets.QPushButton("MAKE ROBOT")
self.verticalLayout_3.addWidget(self.pushBtn_makeRobot)
self.verticalLayout.addLayout(self.verticalLayout_3)
self.verticalLayout_4 = QtWidgets.QVBoxLayout()
self.verticalLayout_4.setContentsMargins(5, 5, 5, 5)
self.pushBtn_makeStairs = QtWidgets.QPushButton("MAKE STAIRS")
self.verticalLayout_4.addWidget(self.pushBtn_makeStairs)
self.verticalLayout.addLayout(self.verticalLayout_4)
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setContentsMargins(5, 5, 5, 5)
self.pushBtn_randomlyDistribute = QtWidgets.QPushButton("RANDOMLY DISTRIBUTE ROBOT AND STAIRS")
self.verticalLayout_2.addWidget(self.pushBtn_randomlyDistribute)
self.verticalLayout.addLayout(self.verticalLayout_2)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setContentsMargins(5, 5, 5, 5)
self.radioBtn_YES = QtWidgets.QRadioButton("YES")
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.radioBtn_YES.sizePolicy().hasHeightForWidth())
self.radioBtn_YES.setSizePolicy(sizePolicy)
self.radioBtn_YES.setLayoutDirection(QtCore.Qt.LeftToRight)
self.radioBtn_YES.setAutoFillBackground(False)
self.horizontalLayout.addWidget(self.radioBtn_YES)
self.radioBtn_MAYBE = QtWidgets.QRadioButton("MABEY")
self.horizontalLayout.addWidget(self.radioBtn_MAYBE)
self.radioBtn_NO = QtWidgets.QRadioButton("NO")
self.horizontalLayout.addWidget(self.radioBtn_NO)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setContentsMargins(5, 5, 5, 5)
self.chkBox_CustomGreeting = QtWidgets.QCheckBox("Custom Greeting")
self.horizontalLayout_2.addWidget(self.chkBox_CustomGreeting)
self.lineEdit_CustomGreeting = QtWidgets.QLineEdit()
self.horizontalLayout_2.addWidget(self.lineEdit_CustomGreeting)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.verticalLayout_6 = QtWidgets.QVBoxLayout()
self.verticalLayout_6.setContentsMargins(5, 5, 5, 5)
self.pushBtn_GenerateGreating = QtWidgets.QPushButton("Generate Greating")
self.verticalLayout_6.addWidget(self.pushBtn_GenerateGreating)
self.verticalLayout.addLayout(self.verticalLayout_6)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
##############################################################
self.setWindowTitle("WIN CONTROLLED IN PYTHON")
self.setLayout(self.gridLayout)
self.show()
self.makeConnections()
self.initialUiState()
def initialUiState(self):
self.pushBtn_makeRobot.toggle()
self.pushBtn_makeStairs.toggle()
self.pushBtn_randomlyDistribute.toggle()
#self.radioBtn_HELLO.toggle()
self.greetingType = "HELLO WORLD"
self.lineEdit_CustomGreeting.setEnabled(False)
self.lineEdit_CustomGreeting.setPlaceholderText("BLAH BLAH BLAH")
def radioChange(self,greetingType):
self.greetingType = greetingType
#print("greatingType: {0}".format(greetingType))
def makeConnections(self):
''' connect events in out UI '''
self.pushBtn_makeRobot.clicked.connect( self.makeRobotBug )
self.pushBtn_makeStairs.clicked.connect(self.makeSpiralStairs)
self.pushBtn_randomlyDistribute.clicked.connect(self.randomlyPlaceA)
# self.radioBtn_YES.clicked.connect(self.radioChange('YES'))
# self.radioBtn_MAYBE.clicked.connect(self.radioChange('MAYBE'))
# self.radioBtn_NO.clicked.connect(self.radioChange('NO'))
self.pushBtn_GenerateGreating.clicked.connect(self.printGreeting)
self.radioBtn_YES.clicked.connect(functools.partial(self.radioChange,'YES'))
self.radioBtn_MAYBE.clicked.connect(functools.partial(self.radioChange,'MAYBE'))
self.radioBtn_NO.clicked.connect(functools.partial(self.radioChange,'NO'))
#self.chkBox_CustomGreeting.isChecked.connect(functools.partial(self.radioChange,'CUSTOM NAME'))
self.chkBox_CustomGreeting.stateChanged.connect(self.lineEdit_CustomGreeting.setEnabled)
def makeRobotBug(self):
makeRobotBug.makeRobotBug()
def makeSpiralStairs(self):
makeSpiralStairs.makeSpiralStairs()
def randomlyPlaceA(self):
randomlyPlace.randomlyPlace()
def printGreeting(self):
if self.greetingType != "HELLO WORLD":
print ( "I SAY: {0}".format(self.greetingType) )
elif self.chkBox_CustomGreeting.isChecked():
print ( "I SAY: {0}".format(self.lineEdit_CustomGreeting.text()) )#stateChanged is not triggering when it is not a tristate checkbox need to use toggled
self.chkBox_CustomGreeting.stateChanged.connect(self.lineEdit_CustomGreeting.setEnabled)
#change to
self.chkBox_CustomGreeting.toggled.connect(self.lineEdit_CustomGreeting.setEnabled)
not meaning this in a mean way or to discourage you asking questions here but are you trying google searches first for things like "qcheckbox toggle connect" before writing the group? I know questions lkike this have been asked and answered many times before
plus web search is a strong and necessary tool for learning to script/program, there is not always a email forum for things
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f2b02dc2-53f9-4d5d-a069-2a0d557f4111%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yes, agreed. If you want to learn, this isn’t the best way to do it. When you stumble into a problem, take at least a day to think about it and research on your own. If you still can’t figure it out, come back here and tell us what you tried and what didn’t work. And reduce your problem; I bet a majority of the code you posted are unrelated to the problem. Find a way to boil it down to just the lines involved in the problem.
OT: @damon about the <div title="MDH:PGRpdiBk.. junk, I also got that a lot when using MarkdownHere. I found that if I delete the original message from my new message it didn’t happen as often. Mad bug!