Blender Documentation Volume II - Reference Guide: Last modified March 29 2004 S68 | ||
---|---|---|
<<< Previous | Python API Reference | Next >>> |
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 (print dir(Blender.Draw)).
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 # this is important: only re-register if an event was caught Draw.Register(gui, event, button_event) # re-register to stay in the loop # 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) else: Draw.Register(gui, event, button_event) # 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 callbacks |
Warning: Inside the windowing loop (after Draw.Register() has been executed and before Draw.Exit() is called), don't use the redraw functions from other modules (Blender and Window). The Draw submodule has its own Draw.Redraw() and Draw.Draw() functions that can be used inside the windowing loop.
Function Summary | ||
| Button(name, event, x, y, width, height, tooltip) Create a new (push) Button object. | |
Blender Button | Create(value) Create a default Button object. | |
| Draw() Force an immediate redraw. | |
| Exit() Exit the windowing interface. | |
int | GetStringWidth(string, fontsize) Get the width in pixels of a string. | |
Blender Button | Menu(name, event, x, y, width, height, default, tooltip) Create a new Menu Button object. | |
Blender Button | Number(name, event, x, y, width, height, initial, min, max, realtime, tooltip) Create a new Number Button object. | |
| Redraw(after) Queue a redraw event. | |
| Register(draw, event, button) Register callbacks for windowing. | |
Blender Button | Scrollbar(event, x, y, width, height, initial, min, max, realtime, tooltip) Create a new Scrollbar Button object. | |
Blender Button | Slider(name, event, x, y, width, height, initial, min, max, realtime, tooltip) Create a new Toggle Button object. | |
Blender Button | String(name, event, x, y, width, height, initial, length, tooltip) Create a new String Button object. | |
int | Text(string, fontsize) Draw a string on the screen. | |
Blender Button | Toggle(name, event, x, y, width, height, default, tooltip) Create a new Toggle Button object. |
Button(name, event, x, y, width, height, tooltip=None) Create a new (push) Button object.
|
Create(value) Create a default Button object.
|
Draw() Force an immediate redraw. Forced redraws are not buffered. In other words, the window is redrawn once every time this function is called. |
GetStringWidth(string, fontsize='normal') Get the width in pixels of a string.
|
Menu(name, event, x, y, width, height, default, tooltip=None) 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:
|
Number(name, event, x, y, width, height, initial, min, max, realtime=1, tooltip=None) Create a new Number Button object.
|
Redraw(after=0) Queue a redraw event. Redraw events are buffered so that, regardless of how many events are queued, the window only receives one redraw event.
|
Register(draw=None, event=None, button=None) Register callbacks for windowing.
|
Scrollbar(event, x, y, width, height, initial, min, max, realtime=1, tooltip=None) Create a new Scrollbar Button object.
|
Slider(name, event, x, y, width, height, initial, min, max, realtime=1, tooltip=None) Create a new Toggle Button object.
|
String(name, event, x, y, width, height, initial, length, tooltip=None) Create a new String Button object.
|
Text(string, fontsize='normal') Draw a string on the screen.
|
Toggle(name, event, x, y, width, height, default, tooltip=None) Create a new Toggle Button object.
|
<<< Previous | Home | Next >>> |
Module Draw | Up | Module Window |