Advertisement
Guest User

embedding blender using pygtk

a guest
Jul 19th, 2010
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. #!/usr/bin/python
  2. '''
  3. Embeding Blender in a PyGTK Window Demo
  4. Goathead - July 20, 2010
  5. Useage: (linux only)
  6.     1. Run this script "python embedblender-demo.py"
  7.     2. Blender will popup in a small window, you must click it within 5 seconds
  8.     3. The Blender window is moved to the GTK window,
  9.         you should be able to continue to interact with Blender
  10. Known Issues:
  11.     1. Losing window focus can disable mouse click input,
  12.         mouse wheel and keyboard seem to always work
  13.     2. Not clicking the Blender window when it first appears can cause it to not be
  14.        responsive when its embeded in the pygtk window.
  15. '''
  16.  
  17.  
  18. # change this path to your blender25 folder #
  19. PATH2BLENDER = 'Desktop/blender25'
  20. ''' Blender25 has a bug if you had "saved as default" your own startup blend
  21.  --window-geometry fails to be respected and blender opens a full screen window,
  22.   uncomment the line below to remove your startup blend so this demo can work properly. '''
  23. #os.system('mv $HOME/.blender/2.52/config/startup.blend $HOME/mystartup.blend')
  24.  
  25.  
  26.  
  27. ## end user options ##
  28. import os, sys, time
  29. import gtk
  30.  
  31. BWIDTH=640; BHEIGHT=480
  32. os.system('killall blender')
  33. os.system('%s/blender --window-geometry 10 10 %s %s &' %(PATH2BLENDER,BWIDTH,BHEIGHT)) 
  34. win = gtk.Window()
  35. win.connect('destroy', lambda w: gtk.main_quit())
  36. #win.set_size_request( 800, 500 )
  37. frame = gtk.Frame('embeding blender in gtk demo')
  38. frame.set_border_width( 20 )
  39. win.add(frame)
  40. soc = gtk.Socket()
  41. soc.set_border_width(10)
  42. frame.add( soc )
  43.  
  44. time.sleep(5)
  45. p =os.popen('xwininfo -int -name Blender')
  46. data = p.read().strip().splitlines()
  47. p.close()
  48. print( data )
  49. wid = long( data[0].split()[3] )
  50. print( 'embeding blender', wid )
  51. soc.add_id( wid )
  52.  
  53. pw = soc.get_plug_window()
  54. #BWIDTH,BHEIGHT = pw.get_size()
  55. soc.set_size_request( BWIDTH, BHEIGHT )
  56.  
  57. win.show_all()
  58. gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement