Trees | Indices | Help |
|
---|
|
This module provides access to a windowing interface in Blender. Its widgets include many kinds of buttons: push, toggle, menu, number, string, slider, scrollbar, plus support for text drawing. It also includes keyboard keys and mouse button code values in its dictionary, see a list after this example.
Example:import Blender from Blender import Draw, BGL mystring = "" mymsg = "" toggle = 0 def event(evt, val): # the function to handle input events global mystring, mymsg if not val: # val = 0: it's a key/mbutton release if evt in [Draw.LEFTMOUSE, Draw.MIDDLEMOUSE, Draw.RIGHTMOUSE]: mymsg = "You released a mouse button." Draw.Redraw(1) return if evt == Draw.ESCKEY: Draw.Exit() # exit when user presses ESC return elif Draw.AKEY <= evt <= Draw.ZKEY: mystring += chr(evt) elif evt == Draw.SPACEKEY: mystring += ' ' elif evt == Draw.BACKSPACEKEY and len(mystring): mystring = mystring[:-1] else: return # no need to redraw if nothing changed Draw.Redraw(1) def button_event(evt): # the function to handle Draw Button events global mymsg, toggle if evt == 1: mymsg = "You pressed the toggle button." toggle = 1 - toggle Draw.Redraw(1) def gui(): # the function to draw the screen global mystring, mymsg, toggle if len(mystring) > 90: mystring = "" BGL.glClearColor(0,0,1,1) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) BGL.glColor3f(1,1,1) Draw.Toggle("Toggle", 1, 10, 10, 55, 20, toggle,"A toggle button") BGL.glRasterPos2i(72, 16) if toggle: toggle_state = "down" else: toggle_state = "up" Draw.Text("The toggle button is %s." % toggle_state, "small") BGL.glRasterPos2i(10, 230) Draw.Text("Type letters from a to z, ESC to leave.") BGL.glRasterPos2i(20, 200) Draw.Text(mystring) BGL.glColor3f(1,0.4,0.3) BGL.glRasterPos2i(340, 70) Draw.Text(mymsg, "tiny") Draw.Register(gui, event, button_event) # registering the 3 callbacksAll available events:
Note: function Button has an alias: PushButton.
Warnings:# avoid this, it can cause memory leaks: Draw.Toggle(...) Draw.Number(...) Draw.String(...) # this is correct -- assuming the variables are globals: my_toggle_button = Draw.Toggle(...) my_int_button = Draw.Number(...) my_str_button = Draw.String(...)
|
|||
Button This object represents a button in Blender's GUI. |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Blender Button |
|
||
|
|||
int |
|
||
int |
|
||
int |
|
||
float |
|
||
string |
|
||
int |
|
||
Blender Button |
|
||
Blender Button |
|
||
Blender Button |
|
||
Blender Button |
|
||
Blender Button |
|
||
Blender Button |
|
||
Blender Button |
|
||
int |
|
||
int |
|
||
None |
|
||
|
|
Notes:
Warning: Menu will not work properly within a UIBlock, this is a limitation with blenders user interface internals. |
Notes:
|
|
|
Note: String values must have less then 400 characters. |
Note: This function used to be called only "Button". We added an alternative alias to avoid a name clash with the Button class/type that caused trouble in this documentation's generation. The old name shouldn't be deprecated, use Button or PushButton (better) at your choice. |
Create a pop-up menu. The menu options are specified through the 'name' parameter, like with Menu: options are followed by a format code and separated by the '|' character. Valid format codes are:
name = "OK?%t|QUIT BLENDER" # if no %xN int is set, indices start from 1 result = Draw.PupMenu(name) if result: Draw.PupMenu("Really?%t|Yes|No")
|
Create a popup menu tree. Each item in the list is: a menu item - (str, event); a separator - None; or submenu - (str, [...]). Submenus list uses the same syntax as the menu list. To add a title to the main menu, end the first entry str with '%t' - the event is ignored. Example:result = Draw.PupTreeMenu( [ ("Title%t", 0), ("Menu Item 1", 10), ("Menu Item 2", 12), ("SubMenu", [("Menu Item 3", 100), ("MenuItem4", 101) ] ) ] )
|
Create an integer number input pop-up. This allows python to use Blender's integer number pop-up input. Example:default = 50 min = 0 max = 100 msg = "Set this value between 0 and 100" result = Draw.PupIntInput(msg, default, min, max) if result != None: print result else: print 'no user input'
|
Create a floating point number input pop-up. This allows python to use Blender's floating point pop-up input. Example:default = 50 min = 0.0 max = 10.0 clickStep = 100 floatLen = 3 msg = "Set this value between 0 and 100" result = Draw.PupFloatInput(msg, default, min, max, clickStep, floatLen) if result != None: print result else: print 'no user input'
|
Create a string input pop-up. This allows python to use Blender's string pop-up input. Example:Blender.Draw.PupStrInput("Name:", "untitled", 25)
|
Display a pop-up block. Possible formats for the items in the sequence parameter. (Value are objects created with Create)
import Blender text = Blender.Draw.Create("short text") f = Blender.Draw.Create(1.0) i = Blender.Draw.Create(2) tog = Blender.Draw.Create(0) block = [] block.append(("Name: ", text, 0, 30, "this is some tool tip")) block.append("Some Label") block.append(("Value: ", f, 0.0, 100.0)) block.append(("Value: ", i, 0, 100)) block.append(("Option", tog, "another tooltip")) retval = Blender.Draw.PupBlock("PupBlock test", block) print "PupBlock returned", retval print "text\t", text print "float\t", f print "int\t", i print "toggle\t", tog
Warning: On cancel, the Value objects are brought back to there initial values except for string values which will still contain the modified values. |
Create a new Menu Button object. The menu options are specified through the 'name' of the button. Options are followed by a format code and separated by the '|' (pipe) character. Valid format codes are:
name = "The Title %t|First Entry %x1|Second Entry %x2|Third Entry %x3" menu = Draw.Menu(name, 2, 60, 120, 200, 40, 3, "Just a test menu.") # note that, since default = 3, the "Third Entry" # will appear as the default choice in the Menu.
|
|
Note: slider callbacks will not work if the realtime setting is enabled. |
Notes:
|
Notes:
|
|
|
|
Draw a string on the screen. Text location is set using the OpenGL raster location functions BGL.glRasterPos before the text is drawn. This sets the text location from the lower left corner of the current window. Text color is set using the OpenGL color functions BGL.glColor before the text is drawn.
Note: For drawing text in the 3d view see the workaround in BGL.glRasterPos |
|
Draw an image on the screen. The image is drawn at the location specified by the coordinates (x,y). A pair of optional zoom factors (in horizontal and vertical directions) can be applied to the image as it is drawn, and an additional clipping rectangle can be applied to extract a particular sub-region of the image to draw. Note that the clipping rectangle is given in image space coordinates. In image space, the origin is located at the bottom left, with x coordinates increasing to the right and y coordinates increasing upwards. No matter where the clipping rectangle is placed in image space, the lower-left pixel drawn on the screen is always placed at the coordinates (x,y). The clipping rectangle is itself clipped to the dimensions of the image. If either the width or the height of the clipping rectangle are negative then the corresponding dimension (width or height) is set to include as much of the image as possible. For drawing images with alpha blending with the background you will need to enable blending as shown in the example. Example:import Blender from Blender import BGL, Image, Draw myimage = Image.Load('myimage.png') def gui(): BGL.glEnable( BGL.GL_BLEND ) # Only needed for alpha blending images with background. BGL.glBlendFunc(BGL.GL_SRC_ALPHA, BGL.GL_ONE_MINUS_SRC_ALPHA) Draw.Image(myimage, 50, 50) BGL.glDisable( BGL.GL_BLEND ) def event(evt, val): if evt == Draw.ESCKEY: Draw.Exit() Draw.Register(gui, event, None)
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Sat Sep 19 13:57:27 2009 | http://epydoc.sourceforge.net |