Run Python Tool as Subprocess

   2188   7   5
User Avatar
Member
1 posts
Joined: 3月 2020
Offline
Hi all!

I am new to scripting and I am creating a tool with 2 buttons. When I run the script and click a button to create a cube, it is not created until I close the tool window.

I am researching and I believe the keyword I am looking for is “subprocess”. I want to be able to run the tool script I made as a subprocess and not have Houdini freeze until I close that window. The goal is to be able to go back and forth between the tool and Houdini without a problem.

I am using tkinter to create the GUI.

Does anyone know how to make his happen?


Thank you!!
User Avatar
Member
311 posts
Joined:
Offline
You might want the Python “threading” module, but not necessarily. I recall some discussion here:

https://forums.odforce.net/topic/21949-pythons-multiprocessing/?tab=comments#comment-130738 [forums.odforce.net]
User Avatar
Member
28 posts
Joined: 6月 2019
Offline
Was a solution to this ever found? I have the same issue with customtkinter and am trying to resolve it. I want live feedback for my sliders and such.
User Avatar
Member
377 posts
Joined: 4月 2017
Offline
Honestly the best solution would be to skip tkinter entirely and use PySide2. It's way faster and it's built into Houdini. I realize it's a big package to learn but it's worth it considering how broadly applicable it is in VFX (Houdini, Maya, Nuke among others use Qt and include PyQt / PySide bindings).
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
16 posts
Joined: 6月 2018
Offline
This may be helpfull: Video [youtu.be]. Paul shows how to use threading to eliminate houdini freeze when sequences of images start to show up.
Senior Technical Artist at Cloud Imperium Games
User Avatar
Member
28 posts
Joined: 6月 2019
Offline
Hey all, thanks for the responses!

I was mostly looking into using customtkinter due to its out of the gate stylesheeting which makes the UI look nice, I'm guessing PySide2 is just as capable of doing styling?

Funny enough, I tried Paul's technique before finding that video, it seemed like it was working, but the data is still only pushed after closing the UI and not while the UI is open.
User Avatar
Member
377 posts
Joined: 4月 2017
Offline
PySide / Qt is very capable of styling via QSS (basically Qt's custom implementation of CSS, with similar syntax), and QDialogs created as child dialogs of the main Houdini process will inherit Houdini's stylesheet by default. It's definitely a bit more boilerplate to deal with than tkinter but it's much more powerful and you don't have to deal with this threading business.
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
274 posts
Joined: 7月 2013
Offline
If you want to make UI panels that are native Houdini panels, use the windows->python panel editor.


Create a new interface and give it a name, also paste the code in there found at the bottom of this post.



and make to sure to add it to the pane tab menu:



You can then use the "+" on the panetab headers to add it to the UI:



Cubes are created instantly when you push the button and I've added some random styles to it for reference how to do that. Without styling it just looks like native houdini.


    
from PySide2 import QtCore, QtGui, QtWidgets


class MyPanel(QtWidgets.QWidget):


def __init__(self, paneTab):
QtWidgets.QWidget.__init__(self)
self.paneTab = paneTab
uiscale = hou.ui.globalScaleFactor() #this is here to compensate for difference UI scaling / dpi settings.


#global style sheet for entire panel
self.setStyleSheet("QPushButton {padding: "+str(20*uiscale)+"px "+str(40*uiscale)+"px; } ")

self.but_a = QtWidgets.QPushButton(self)
self.but_a.setText('Add Cube')
self.but_a.setStyleSheet("QPushButton {color: #ff0000}") #custom CSS for this button
self.but_a.move(QtCore.QPoint(10*uiscale,10*uiscale))
self.but_a.clicked.connect(self.but_a_pushed) # connect click handler

self.but_a = QtWidgets.QPushButton(self)
self.but_a.setText('Button B')
self.but_a.setStyleSheet("QPushButton {color: #00ff00}")
self.but_a.move(QtCore.QPoint(10*uiscale,75*uiscale))
self.but_a.clicked.connect(self.but_a_pushed)


def but_a_pushed(self):

#create a cube
c=hou.node("/obj").createNode("geo", "newCube")
c.createNode("box", "box")
print(f"Added box {c.path()}")
pass

def but_b_pushed(self):
print("Button B pushed")
pass


def onCreateInterface():
return MyPanel(kwargs['paneTab'])
Edited by Jonathan de Blok - 2023年3月13日 09:41:34

Attachments:
panel_0.jpg (112.7 KB)
panel_1.jpg (191.8 KB)
panel_a.jpg (17.0 KB)

More code, less clicks.
  • Quick Links