Author
|
Message
|
Kelleytoons
|
Kelleytoons
Posted 5 Years Ago
|
Group: Forum Members
Last Active: Yesterday
Posts: 9.1K,
Visits: 21.7K
|
So I *know* UI ain't my strong point (in my decades as a dev and then as a project manager I always turned UI AND Print stuff over to other folks. Kind of hated input/output :> but I just need a simple integer dialog input and can't for the life of me find anything on the web that works. We have this example: import PySide2, RLPy from PySide2 import * from PySide2.shiboken2 import wrapInstance #-- Make a global variable contain dialog --# sample_dialog = None def run_script(): global sample_dialog sample_dialog = RLPy.RUi.CreateRDialog() sample_dialog.SetWindowTitle("Bump Weight") #-- Create Pyside layout for RDialog --# pyside_dialog = wrapInstance(int(sample_dialog.GetWindow()), QtWidgets.QDialog) pyside_dialog.setFixedWidth(200) sample_layout = pyside_dialog.layout() # #-- Add PushButton --# # pushbutton = QtWidgets.QPushButton("PushButton") # sample_layout.addWidget(pushbutton) # #-- Add ComboBox --# # combobox = QtWidgets.QComboBox() # combobox.addItem("test_01") # combobox.addItem("test_02") # sample_layout.addWidget(combobox) sample_dialog.Show()
which gives us a drop down and a push button, but I just want a @#$% integer input that I can then do something with. Sigh. I don't even want this for myself (for myself I'm happy with hardcoding the value) but it's those damn users... (jk).
Someone give me a clue.
Alienware Aurora R12, Win 10, i9-119000KF, 3.5GHz CPU, 128GB RAM, RTX 3090 (24GB), Samsung 960 Pro 4TB M-2 SSD, TB+ Disk space Mike "ex-genius" Kelley
|
|
|
Delerna
|
Delerna
Posted 5 Years Ago
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 1.5K,
Visits: 14.8K
|
If I understand your question then its something I have very recently started looking into learning to use in Python.....and I am still highly working on it.
Here is a script that works very basically for doing something when you click the button. IE, it just opens a message box when you click them at the moment. But adding code to do things in iClone should be easy enough. In run_Script I call functions that create the buttons rather than create the buttons directly inside run_Script. I only do that because its my preference because it makes it easier for me to find the particular code lines that doe certain things. I hate when all the code for a certain object don't all show up on the screen without having to scroll up and down. That's why I try to keep things in particular functions. Makes it easier for me in the future to remember which codes do certain things and don't end up looking at codes that don't do the particular option im working on. In the future I will probably make those AddButton functions a single function and make it so options can be passed to it. Im keeping them separate at the moment just so I can easily see which codes are doing which buttons
There are also several # lines that I need to look further into. Some work and some don't and I am still looking into them. I find how they work in Python itself but how Reallusion use them for iClone doesn't always work or probably I got its code wrong for how it works inside iClone. Also some of the # lines are similar to other lines. This is because I wrote something that worked but wanted to make it better. So I don't loose what I had originally I # it and wrote a new line. That way I can always get the original back if the new version doesn't work
Sorry for all the points I'm making here, just trying to make it easier for you to see why it is written the way I have done it
import RLPy, PySide2 from PySide2 import * from PySide2.shiboken2 import wrapInstance #from PyQt5.QtWidgets import QApplication, QWidget, QPushButton #Nextlime pushbutton2Choices = QtWidgets.QComboBox() def run_script(): CreateSelectionBox("CHOOSE THE CHANGES YOU WANT TO MAKE",800,200) AddButton1() AddButton2() #Display The Selection Box selectionBox.Show() def AddButton2(): global pushButton2 #Add Selection 2 That Includes Options The User Can Select pushButton2 = QtWidgets.QPushButton("The Functions Script Is Controlled According To Which Choice Got Selected By The User") #pushButton2.setStyleSheet("QPushButton { text-align: left; }") #pushButton2.setStyleSheet('QPushButton {background-color: #A3C1DA; color: red;}') #pushButton2.setStyleSheet("border: 10px solid black; background: white"); pushButton2.setStyleSheet("QPushButton{font-size: 18px;font-family: Arial;color: rgb(255, 255, 255);background-color: rgb(38,56,76); text-align: left;}"); sample_layout.addWidget(pushButton2) #Add selectable options for pushButton2 pushbutton2Choices.addItem("Selectable Choice 1") pushbutton2Choices.addItem("Selectable Choice 2")
sample_layout.addWidget(pushbutton2Choices) #Set what the button will do when the user clicks ir pushButton2.clicked.connect(ExecuteFunction2) def AddButton1(): global pushButton1 #sample_layout = QVBoxLayout() #Dosent work like this #Then Add The Selections To Get Displayed In The Selection Box #Add Selection 1 pushButton1 = QtWidgets.QPushButton("Effects Something Directly By The Functions Script") #pushButton1.move(32,32) #Doesnt do anything #pushButton1.setStyleSheet('QPushButton {background-color: #A3C1DA; color: red;}') pushButton1.setStyleSheet("QPushButton{font-size: 20px;font-family: Arial;color: rgb(255, 255, 255);background-color: rgb(38,56,76); text-align: left;}"); #pushButton1.toggle() #pushButton1.setEnabled(True) #pushButton1.setDefault(True) #pushButton1.setCheckable(True) #pushButton1.setIcon(QIcon(QPixmap("python.gif"))) #Dosent work like this sample_layout.addWidget(pushButton1) #Set what the button will do when the user clicks ir pushButton1.clicked.connect(ExecuteFunction1) def CreateSelectionBox(title,width,height): global selectionBox,selectionDialog,sample_layout #Create A Box So You Can Display Selections For The User selectionBox = RLPy.RUi.CreateRDialog() selectionBox.SetWindowTitle(title) selectionDialog = wrapInstance(int(selectionBox.GetWindow()), QtWidgets.QDialog) selectionDialog.setFixedWidth(width) #Sets the width of the selectionBox if height>0: selectionDialog.setFixedHeight(height) sample_layout = selectionDialog.layout() #Here Are The Functions That Get Called When The User Presses The PushButton They Want To Run def ExecuteFunction1(): RLPy.RUi.ShowMessageBox("First Pushbutton Clicked", "Execute Adjustments According To The Code In This Fuction", RLPy.EMsgButton_Ok) def ExecuteFunction2(): p=pushbutton2Choices.currentText() RLPy.RUi.ShowMessageBox("Second Pushbutton Clicked", 'Execute Adjustments According To The Code As Controlled By Users Option Named ' + p, RLPy.EMsgButton_Ok)
i7-3770 3.4GHz CPU 16 GB Ram GeForce GTX1080 TI 11GB Windows 10 Pro 64bit
Edited
5 Years Ago by
Delerna
|
|
|
Delerna
|
Delerna
Posted 5 Years Ago
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 1.5K,
Visits: 14.8K
|
By the way. This code I added has 2 buttons to click. The first one is meant to just does a single particular function The second one also has a set of selectable options under it (only 2 here but obviously as many as needed can be added). So select an option and then click the button and it shows which option you chose. So should be able to get a certain function to do something differently according to what option the user chose Also, I am testing how to get this to work in as many ways as possible just so when I want to write a proper code it will be written much better than this. At the moment Im not trying to get the code as perfect as possible. Im just trying to find how to get everything that is possible to work. I find great UI's are extremely important.
i7-3770 3.4GHz CPU 16 GB Ram GeForce GTX1080 TI 11GB Windows 10 Pro 64bit
Edited
5 Years Ago by
Delerna
|
|
|
Kelleytoons
|
Kelleytoons
Posted 5 Years Ago
|
Group: Forum Members
Last Active: Yesterday
Posts: 9.1K,
Visits: 21.7K
|
Sorry, I should have been clearer. I know all about creating dialogs and making buttons and drop downs (and even text input lines). What I do NOT know is a simple get integer function -- for some reason the examples I find just don't work and short of using the whole QT dialog setup (which I don't want to do) I'm stumped. It appears as if you're even further behind than I am (which is a bit scary considering how far behind I am :> . Perhaps someone else will jump in here with a simple example (it really should only be a one-line function call: something like i,okPressed = QInputDialog.getInt(self,"Get Integer", "Something",28,0,100,1) However, I can't get this to work properly.
Alienware Aurora R12, Win 10, i9-119000KF, 3.5GHz CPU, 128GB RAM, RTX 3090 (24GB), Samsung 960 Pro 4TB M-2 SSD, TB+ Disk space Mike "ex-genius" Kelley
|
|
|
4u2ges
|
4u2ges
Posted 5 Years Ago
|
Group: Forum Members
Last Active: 12 hours ago
Posts: 5.0K,
Visits: 15.9K
|
I understand we should probably be using Qt Designer to build UIs, but sometimes you need very simple layout and functionality. Thus more basic examples of UI controls classes (other than push button and drop-down) from QtWidgets module is due.
Edited
5 Years Ago by
4u2ges
|
|
|
videodv
|
videodv
Posted 5 Years Ago
|
Group: Forum Members
Last Active: Last Year
Posts: 342,
Visits: 12.0K
|
Hi Mike Im at work at the moment will have a look when I get home later this morning (its 2am here in london) in the meantime if you have a look at this Link or this Link it should help you on the way. Cheers Chris.
Edited
5 Years Ago by
videodv
|
|
|
videodv
|
videodv
Posted 5 Years Ago
|
Group: Forum Members
Last Active: Last Year
Posts: 342,
Visits: 12.0K
|
4u2ges (9/30/2019) I understand we should probably be using Qt Designer to build UIs, but sometimes you need very simple layout and functionality. Thus more basic examples of UI controls classes (other than push button and drop-down) from QtWidgets module is due.
Hi 4u2ges I found this site to be very usefull when working out QT Widgets ect tutorialspointCheers Chris.
Edited
5 Years Ago by
videodv
|
|
|
4u2ges
|
4u2ges
Posted 5 Years Ago
|
Group: Forum Members
Last Active: 12 hours ago
Posts: 5.0K,
Visits: 15.9K
|
videodv (9/30/2019)
4u2ges (9/30/2019) I understand we should probably be using Qt Designer to build UIs, but sometimes you need very simple layout and functionality. Thus more basic examples of UI controls classes (other than push button and drop-down) from QtWidgets module is due.
Hi 4u2ges I found this site to be very usefull when working out QT Widgets ect tutorialspointCheers Chris. Thanks Chris. It seems an *easy* implementation of the QT widgets. Though I am a bit confused. There are 2 versions of PyQt, namely 4 and 5. But all the doc references are for version 4. OK, so I installed 5 with pip3, but I am getting an error on importing PyQt5.QtCore Is it different from version 4? Which version are you using? Thanks, G
Edited
5 Years Ago by
4u2ges
|
|
|
videodv
|
videodv
Posted 5 Years Ago
|
Group: Forum Members
Last Active: Last Year
Posts: 342,
Visits: 12.0K
|
4u2ges (9/30/2019)
videodv (9/30/2019)
4u2ges (9/30/2019) I understand we should probably be using Qt Designer to build UIs, but sometimes you need very simple layout and functionality. Thus more basic examples of UI controls classes (other than push button and drop-down) from QtWidgets module is due.
Hi 4u2ges I found this site to be very usefull when working out QT Widgets ect tutorialspointCheers Chris. Thanks Chris. It seems an *easy* implementation of the QT widgets. Though I am a bit confused. There are 2 versions of PyQt, namely 4 and 5. But all the doc references are for version 4. OK, so I installed 5 with pip3, but I am getting an error on importing PyQt5.QtCore Is it different from version 4? Which version are you using? Thanks, G Hi Change the PyQt4 or PyQt5 to PySide2 as used by realusion scripts and all works fine. Cheers Chris
|
|
|
4u2ges
|
4u2ges
Posted 5 Years Ago
|
Group: Forum Members
Last Active: 12 hours ago
Posts: 5.0K,
Visits: 15.9K
|
Thanks, but it still does not work. Like Mike stated QInputDialog is not working (text or int). It gives class 'NameError' Working examples would be most welcomed
|
|
|