
| ホーム | ツリー | 索引 | ヘルプ |
|
|---|
| Module Draw |
|
events callbacks;
Text and GetStringWidth.
PupBlock
ColorPicker
このモジュールを使えばBlenderのGUIにアクセスできます。 Widgetとして色々なボタンが用意されています: 押しボタン、トグルボタン、メニューボタン、数値ボタン、文字列ボタン、スライダーボタン、スクロールバーボタン。これに加えて文字列の描画もサポートします。 また、キーボードのキーコードとマウスのボタンコードの値を収めた辞書も用意されています。辞書の内容は、Exampleのあとに載せています。
Example:
import Blender
from Blender import Draw, BGL
mystring = ""
mymsg = ""
toggle = 0
def event(evt, val): # 入力イベントをハンドルする関数
global mystring, mymsg
if not val: # val = 0: キー/マウスボタンを離したことを示します
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() # ユーザーが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 # 何も変更がなければ、再描画(Redraw)する必要はありません
Draw.Redraw(1)
def button_event(evt): # Drawボタンイベントをハンドルする関数
global mymsg, toggle
if evt == 1:
mymsg = "You pressed the toggle button."
toggle = 1 - toggle
Draw.Redraw(1)
def gui(): # 画面を描画する関数
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) # 3つのコールバック関数を登録する
全イベントのリスト:
Warnings:
# メモリーリークを引き起こすのでこれはダメ: Draw.Toggle(...) Draw.Number(...) Draw.String(...) # これが正しい(変数はグローバル変数に限る): my_toggle_button = Draw.Toggle(...) my_int_button = Draw.Number(...) my_str_button = Draw.String(...)
Note: function Button has an alias: PushButton.
| クラス | |
|---|---|
Button |
BlenderのGUIのボタンを表すオブジェクトです。 |
| 関数の概要 | |
|---|---|
この関数の使用後は、ボタンが整列して描画されます。 | |
| Blender Button |
Color Pickerボタンオブジェクトを新しく作ります。 |
| Blender Button |
デフォルトボタンオブジェクトを新しく作ります。 |
強制的にすぐさま再描画します。 | |
BeginAlign()のあと、ボタンの整列をやめたいときに使います。 | |
GUIを終了します。 | |
| int |
文字列の幅をピクセル値で取得します。 |
画面に画像を描画します。 | |
| Blender Button |
メニューボタンオブジェクトを新しく作ります。 |
| Blender Button |
Normal(法線)ボタンを新しく作ります。 |
| Blender Button |
数値ボタンオブジェクトを新しく作ります。 |
| int |
ポップアップ・ブロックを表示します。 |
| float |
float値用のポップアップ入力欄を作ります。 |
| int |
int値用のポップアップ入力欄を作ります。 |
| int |
ポップアップメニューを作ります。 |
| string |
文字列用のポップアップ入力欄を作ります。 |
押しボタンオブジェクトを新しく作ります。 | |
再描画イベントをキューに追加します。 | |
GUIのためのコールバック関数を登録します。 | |
| Blender Button |
スライダーボタンオブジェクトを新しく作ります。 |
| Blender Button |
文字列ボタンオブジェクトを新しく作ります。 |
| int |
画面上に文字列を描画します。 |
| Blender Button |
トグルボタンオブジェクトを新しく作ります。 |
| 関数の詳細 |
|---|
BeginAlign()この関数の使用後は、ボタンが整列して描画されます。 (button layout only). |
ColorPicker(event, x, y, width, height, initial, tooltip=None)Color Pickerボタンオブジェクトを新しく作ります。
|
Create(value)デフォルトボタンオブジェクトを新しく作ります。
|
Draw()強制的にすぐさま再描画します。強制再描画はバッファに貯められません。 別の言い方をすると、この関数を呼ぶたびに、すぐにウィンドウが再描画されます。 |
EndAlign()BeginAlign()のあと、ボタンの整列をやめたいときに使います。 (button layout only). |
Exit()GUIを終了します。 |
GetStringWidth(string, fontsize='normal')文字列の幅をピクセル値で取得します。
|
Image(image, x, y, zoomx=1.0, zoomy=1.0, clipx=0, clipy=0, clipw=-1, cliph=-1)画面に画像を描画します。 (x,y)で指定した位置に画像を描画します。 x,y方向それぞれに拡大率(zoom)を設定できます。 画像の一部分だけを描画できるように、 画像の切り抜き範囲(clip)を設定できます。 切り抜き範囲は、画像の座標空間で指定します。 画像の座標空間では、左下が原点となり、x座標は右に伸び、 y座標は上に伸びています。 切り抜き範囲の設定に関わらず、 画像の左下のピクセルは、指定した(x,y)座標に描画されます。 切り抜き範囲を大きく指定しても、画像の大きさに合わせて範囲が抑えられます。 切り抜き範囲の指定で幅(width)や高さ(height)を負の値にすると、 それぞれの方向をできるだけ大きく取って、 画像の多くの領域を含むようになります。 画像を描画するときに背景にアルファ・ブレンディングする場合は、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)
|
Menu(name, event, x, y, width, height, default, tooltip=None)メニューボタンオブジェクトを新しく作ります。 メニューの項目は、ボタンの'name'引数によって指定します。 項目のあとに書式コードを書き、'|'文字で項目同士を分けます。 有効な書式コード:
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.") # 注:default = 3なので、"Third Entry"項目が # メニューのデフォルトの選択項目として表示されます。
|
Normal(event, x, y, width, height, initial, tooltip=None)Normal(法線)ボタンを新しく作ります。球を回転させて3次元ベクトルをセットできます。
|
Number(name, event, x, y, width, height, initial, min, max, tooltip=None)数値ボタンオブジェクトを新しく作ります。
|
PupBlock(title, sequence)ポップアップ・ブロックを表示します。 以下の書式で、sequence引数で項目を指定します。Possible formats for the items in the sequence parameter. (Value are objects created withCreate)
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
|
PupFloatInput(text, default, min, max, clickStep, floatLen)float値用のポップアップ入力欄を作ります。 Blenderのポップアップ入力欄をスクリプトから使えます。 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'
|
PupIntInput(text, default, min, max)int値用のポップアップ入力欄を作ります。 Blenderのポップアップ入力欄をスクリプトから使えます。 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'
|
PupMenu(name, maxrow=None)ポップアップメニューを作ります。 メニューの項目は、Menuと同様に、ボタンの'name'引数によって指定します。
項目のあとに書式コードを書き、'|'文字で項目同士を分けます。
有効な書式コード:
name = "OK?%t|QUIT BLENDER" # %xNの指定がなければ、項目番号を1から順に付けます。
result = Draw.PupMenu(name)
if result:
Draw.PupMenu("Really?%t|Yes|No")
|
PupStrInput(text, default, max=20)文字列用のポップアップ入力欄を作ります。 Blenderのポップアップ文字列入力欄をスクリプトから使えます。 Example:
Blender.Draw.PupStrInput("Name:", "untitled", 25)
|
PushButton(name, event, x, y, width, height, tooltip=None)押しボタンオブジェクトを新しく作ります。
|
Redraw(after=0)再描画イベントをキューに追加します。再描画イベントは一旦バッファに貯められます。 キューに追加したイベントの数に関わらず、ウィンドウは1つの再描画イベントしか受け取らないからです。
|
Register(draw=None, event=None, button=None)GUIのためのコールバック関数を登録します。
|
Slider(name, event, x, y, width, height, initial, min, max, realtime=1, tooltip=None)スライダーボタンオブジェクトを新しく作ります。
|
String(name, event, x, y, width, height, initial, length, tooltip=None)文字列ボタンオブジェクトを新しく作ります。
|
Text(string, fontsize='normal')画面上に文字列を描画します。 文字列の描画位置は、描画前にOpenGLのラスタ位置関数 BGL.glColorを使って設定します。
|
Toggle(name, event, x, y, width, height, default, tooltip=None)トグルボタンオブジェクトを新しく作ります。
|
| ホーム | ツリー | 索引 | ヘルプ |
|
|---|
| Generated by Epydoc 2.1 (modified by morita) on Tue Feb 27 21:06:22 2007 | http://epydoc.sf.net |