Jump to content

Creating a Tool Window


RuschFX

Recommended Posts

hey guys,

I'm trying to build a tool for Houdini and I need to dynamically populate lists. I tried using hou to edit the otl's parameter interface but found it wasn't flexible enough. Now I'm using wx to create a popup window but it seems kind of buggy (likes to crash my Houdini). I'm on a 64 bit Linux machine running Houdini 9.5. Does anybody have any suggestions on how to go about creating a tool window in Houdini and is there anything else that would work better than wx? Any tips you might have would be a big help! Thanks...

- Jake

Link to comment
Share on other sites

There are some examples of creating custom dialogs using both wxPython and PyQt in the HOM Cookbook in the help. Also, recently a new hook to Houdini's event loop was added to make issues with threading and refreshing easier.

Link to comment
Share on other sites

If you're only doing lists, have you checked out hou.ui.selectFromList? It fills most of my list needs.

If not:

I found gtk to be a lot easier to implement than qt.

Here's an example scrpt. A lot of the comments are stripped from an example on pygtk I found online... I don't remember who the author was, but credit goes out to him... he might've just been the python docs though.

The script pops up a text input window, then creates an object and font sop displaying the entered text. (This was implemented as a shelf tool).

# example helloworld.py
import hou
#import pygtk_helper
import threading

global text
text = 'poop'

def RunHelloWorld():
  import pygtk
  pygtk.require('2.0')
  import gtk
  class HelloWorld(threading.Thread):

	# This is a callback function. The data arguments are ignored
	# in this example. More on callbacks below.
	def hello(self, widget, data=None):
		self.text = self.entry.get_text()
		#This is where I currently run the houdini code.  It's triggered when
		#the button is pressed and run before the gtk window closes.
		geo = hou.node('/obj').createNode('geo','Input_Font',run_init_scripts=False)
		font = geo.createNode('font','resulting_text')
		font.parm('text').set(self.text)
		font.setDisplayFlag(True)

	def delete_event(self, widget, event, data=None):
		# If you return FALSE in the "delete_event" signal handler,
		# GTK will emit the "destroy" signal. Returning TRUE means
		# you don't want the window to be destroyed.
		# This is useful for popping up 'are you sure you want to quit?'
		# type dialogs.
		print "delete event occurred"

		# Change FALSE to TRUE and the main window will not be destroyed
		# with a "delete_event".
		return False

	def destroy(self, widget, data=None):
		#print "destroy signal occurred"
		gtk.main_quit()

	def __init__(self):
		super(HelloWorld,self).__init__()
		#self.init_app()

		# create a new window
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

		# When the window is given the "delete_event" signal (this is given
		# by the window manager, usually by the "close" option, or on the
		# titlebar), we ask it to call the delete_event () function
		# as defined above. The data passed to the callback
		# function is NULL and is ignored in the callback function.
		self.window.connect("delete_event", self.delete_event)

		# Here we connect the "destroy" event to a signal handler.  
		# This event occurs when we call gtk_widget_destroy() on the window,
		# or if we return FALSE in the "delete_event" callback.
		self.window.connect("destroy", self.destroy)

		# Sets the border width of the window.
		self.window.set_border_width(10)

		self.vbox = gtk.VBox(False,0)
		self.window.add(self.vbox)
		self.vbox.show()

		self.entry = gtk.Entry()
		self.entry.set_max_length(0)
		self.entry.set_text("Enter Text Here")
		self.vbox.pack_start(self.entry,True,True,0)
		self.entry.show()

		# Creates a new button with the label "Hello World".
		self.button = gtk.Button("Print Text")

		# When the button receives the "clicked" signal, it will call the
		# function hello() passing it None as its argument.  The hello()
		# function is defined above.
		self.button.connect("clicked", self.hello, None)

		# This will cause the window to be destroyed by calling
		# gtk_widget_destroy(window) when "clicked".  Again, the destroy
		# signal could come from here, or the window manager.
		self.button.connect_object("clicked", gtk.Widget.destroy, self.window)

		# This packs the button into the window (a GTK container).
		self.vbox.pack_start(self.button,True,True,0)

		# The final step is to display this newly created widget.
		self.button.show()

		# and the window
		self.window.show()

	def run(self):
		# All PyGTK applications must have a gtk.main(). Control ends here
		# and waits for an event to occur (like a key press or mouse event).
		gtk.main()

  hello = HelloWorld()
  hello.start()


#
RunHelloWorld()

Edited by anakin78z
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...