2003-06-28 07:38:21 +00:00
|
|
|
# Blender.Window module and the Window PyType object
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
The Blender.Window submodule.
|
|
|
|
|
|
|
|
|
|
Window
|
|
|
|
|
======
|
|
|
|
|
|
|
|
|
|
This module provides access to B{Window} functions in Blender.
|
|
|
|
|
|
BPython: cleaning some bug tracker entries:
(excuse me for doing all in a single commit, but they are tiny
fixes and it's bpython, that dark corner ...)
#1025 - FileSelector SEGV on dynamic callback Category:
Can't reproduce with current cvs, I'd say recent changes to fix
another crash related to FileSelector in gui-less scripts solved this
one, too.
#1028 - Reserved button event number:
Menu choices generate two events, one extra related to the menu
itself, with value=4. Made bpython ignore this extra event.
#1068 - FileSelector No file extension support:
As Ton wrote there, Blender itself doesn't support this yet. But the
requester also wanted Window.File/ImageSelector to accept a pathname. Done. Also updated doc.
#959 - Segfault on background rendering:
This happened in bg mode (blender -b filename -a, for example) when
a script with the line "Blender.Redraw()" was linked to FRAMECHANGED events. As reported in the bug page, it was because curarea is NULL in bg mode. Made Redraw() check for this and not call functions that expected curarea in Redraw, like one to swap buffers.
#1072 - Blender.Redraw() Segfault:
Good catch : ). Scripts called from the scripts win that called
Blender.Redraw() or Blender.Window.Redraw() would crash Blender because of a dirty pointer in Spacescript->script. Fixed.
2004-04-11 04:41:33 +00:00
|
|
|
B{New}: file and image selectors accept a filename now.
|
|
|
|
|
|
2003-06-28 07:38:21 +00:00
|
|
|
Example:
|
|
|
|
|
--------
|
|
|
|
|
|
|
|
|
|
FileSelector::
|
|
|
|
|
|
|
|
|
|
import Blender
|
|
|
|
|
from Blender import Window
|
|
|
|
|
#
|
|
|
|
|
def my_callback(filename): # callback for the FileSelector
|
|
|
|
|
print "You chose the file:", filename # do something with the chosen file
|
|
|
|
|
#
|
|
|
|
|
Window.FileSelector (my_callback, "Choose one!")
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
--------
|
|
|
|
|
|
|
|
|
|
DrawProgressBar::
|
|
|
|
|
|
|
|
|
|
import Blender
|
|
|
|
|
from Blender.Window import DrawProgressBar
|
|
|
|
|
#
|
|
|
|
|
# substitute the bogus_*() function calls for your own, of course.
|
|
|
|
|
#
|
|
|
|
|
DrawProgressBar (0.0, "Importing data ...")
|
|
|
|
|
bogus_importData()
|
|
|
|
|
DrawProgressBar (0.3, "Building something")
|
|
|
|
|
bogus_build()
|
|
|
|
|
DrawProgressBar (0.8, "Updating Blender")
|
|
|
|
|
bogus_update()
|
|
|
|
|
DrawProgressBar (1.0, "Finished")
|
|
|
|
|
#
|
|
|
|
|
# another example:
|
|
|
|
|
#
|
|
|
|
|
number = 1
|
|
|
|
|
while number < 20:
|
|
|
|
|
file = filename + "00%d" % number
|
|
|
|
|
DrawProgressBar (number / 20.0, "Loading texture: %s" % file)
|
|
|
|
|
Blender.Image.Load(file)
|
|
|
|
|
number += 1
|
|
|
|
|
|
|
|
|
|
DrawProgressBar (1.0, "Finished loading")
|
|
|
|
|
|
2003-07-22 00:27:03 +00:00
|
|
|
|
|
|
|
|
@type Types: readonly dictionary
|
|
|
|
|
@var Types: The available Window Types.
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
- ACTION
|
2003-07-22 00:27:03 +00:00
|
|
|
- BUTS
|
|
|
|
|
- FILE
|
|
|
|
|
- IMAGE
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
- IMASEL
|
2003-07-22 00:27:03 +00:00
|
|
|
- INFO
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
- IPO
|
|
|
|
|
- NLA
|
|
|
|
|
- OOPS
|
|
|
|
|
- SCRIPT
|
2003-07-22 00:27:03 +00:00
|
|
|
- SEQ
|
|
|
|
|
- SOUND
|
|
|
|
|
- TEXT
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
- VIEW3D
|
2003-06-28 07:38:21 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def Redraw ():
|
|
|
|
|
"""
|
2003-07-22 00:27:03 +00:00
|
|
|
Force a redraw of a specific Window Type (see L{Types}).
|
2003-06-28 07:38:21 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def RedrawAll ():
|
|
|
|
|
"""
|
|
|
|
|
Redraw all windows.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def QRedrawAll ():
|
|
|
|
|
"""
|
|
|
|
|
Redraw all windows by queue event.
|
|
|
|
|
"""
|
|
|
|
|
|
BPython: cleaning some bug tracker entries:
(excuse me for doing all in a single commit, but they are tiny
fixes and it's bpython, that dark corner ...)
#1025 - FileSelector SEGV on dynamic callback Category:
Can't reproduce with current cvs, I'd say recent changes to fix
another crash related to FileSelector in gui-less scripts solved this
one, too.
#1028 - Reserved button event number:
Menu choices generate two events, one extra related to the menu
itself, with value=4. Made bpython ignore this extra event.
#1068 - FileSelector No file extension support:
As Ton wrote there, Blender itself doesn't support this yet. But the
requester also wanted Window.File/ImageSelector to accept a pathname. Done. Also updated doc.
#959 - Segfault on background rendering:
This happened in bg mode (blender -b filename -a, for example) when
a script with the line "Blender.Redraw()" was linked to FRAMECHANGED events. As reported in the bug page, it was because curarea is NULL in bg mode. Made Redraw() check for this and not call functions that expected curarea in Redraw, like one to swap buffers.
#1072 - Blender.Redraw() Segfault:
Good catch : ). Scripts called from the scripts win that called
Blender.Redraw() or Blender.Window.Redraw() would crash Blender because of a dirty pointer in Spacescript->script. Fixed.
2004-04-11 04:41:33 +00:00
|
|
|
def FileSelector (callback, title = 'SELECT FILE', filename = '<default>'):
|
2003-06-28 07:38:21 +00:00
|
|
|
"""
|
|
|
|
|
Open the file selector window in Blender. After the user selects a filename,
|
|
|
|
|
it is passed as parameter to the function callback given to FileSelector().
|
|
|
|
|
Example::
|
|
|
|
|
import Blender
|
|
|
|
|
#
|
|
|
|
|
def my_function(filename):
|
|
|
|
|
print 'The selected file was:', filename
|
|
|
|
|
#
|
|
|
|
|
Blender.Window.FileSelector (my_function, 'SAVE FILE')
|
|
|
|
|
@type callback: function that accepts a string: f(str)
|
|
|
|
|
@param callback: The function that must be provided to FileSelector() and
|
|
|
|
|
will receive the selected filename as parameter.
|
|
|
|
|
@type title: string
|
|
|
|
|
@param title: The string that appears in the button to confirm the selection
|
|
|
|
|
and return from the file selection window.
|
BPython: cleaning some bug tracker entries:
(excuse me for doing all in a single commit, but they are tiny
fixes and it's bpython, that dark corner ...)
#1025 - FileSelector SEGV on dynamic callback Category:
Can't reproduce with current cvs, I'd say recent changes to fix
another crash related to FileSelector in gui-less scripts solved this
one, too.
#1028 - Reserved button event number:
Menu choices generate two events, one extra related to the menu
itself, with value=4. Made bpython ignore this extra event.
#1068 - FileSelector No file extension support:
As Ton wrote there, Blender itself doesn't support this yet. But the
requester also wanted Window.File/ImageSelector to accept a pathname. Done. Also updated doc.
#959 - Segfault on background rendering:
This happened in bg mode (blender -b filename -a, for example) when
a script with the line "Blender.Redraw()" was linked to FRAMECHANGED events. As reported in the bug page, it was because curarea is NULL in bg mode. Made Redraw() check for this and not call functions that expected curarea in Redraw, like one to swap buffers.
#1072 - Blender.Redraw() Segfault:
Good catch : ). Scripts called from the scripts win that called
Blender.Redraw() or Blender.Window.Redraw() would crash Blender because of a dirty pointer in Spacescript->script. Fixed.
2004-04-11 04:41:33 +00:00
|
|
|
@type filename: string
|
|
|
|
|
@param filename: A filename. This defaults to Blender.Get('filename').
|
2003-06-28 07:38:21 +00:00
|
|
|
"""
|
|
|
|
|
|
BPython: cleaning some bug tracker entries:
(excuse me for doing all in a single commit, but they are tiny
fixes and it's bpython, that dark corner ...)
#1025 - FileSelector SEGV on dynamic callback Category:
Can't reproduce with current cvs, I'd say recent changes to fix
another crash related to FileSelector in gui-less scripts solved this
one, too.
#1028 - Reserved button event number:
Menu choices generate two events, one extra related to the menu
itself, with value=4. Made bpython ignore this extra event.
#1068 - FileSelector No file extension support:
As Ton wrote there, Blender itself doesn't support this yet. But the
requester also wanted Window.File/ImageSelector to accept a pathname. Done. Also updated doc.
#959 - Segfault on background rendering:
This happened in bg mode (blender -b filename -a, for example) when
a script with the line "Blender.Redraw()" was linked to FRAMECHANGED events. As reported in the bug page, it was because curarea is NULL in bg mode. Made Redraw() check for this and not call functions that expected curarea in Redraw, like one to swap buffers.
#1072 - Blender.Redraw() Segfault:
Good catch : ). Scripts called from the scripts win that called
Blender.Redraw() or Blender.Window.Redraw() would crash Blender because of a dirty pointer in Spacescript->script. Fixed.
2004-04-11 04:41:33 +00:00
|
|
|
def ImageSelector (callback, title = 'SELECT IMAGE', filename = '<default>'):
|
2003-06-28 07:38:21 +00:00
|
|
|
"""
|
|
|
|
|
Open the image selector window in Blender. After the user selects a filename,
|
|
|
|
|
it is passed as parameter to the function callback given to ImageSelector().
|
|
|
|
|
Example::
|
|
|
|
|
import Blender
|
|
|
|
|
#
|
|
|
|
|
def my_function(imagename):
|
|
|
|
|
print 'The selected image was:', imagename
|
|
|
|
|
#
|
|
|
|
|
Blender.Window.ImageSelector (my_function, 'LOAD IMAGE')
|
|
|
|
|
@type callback: function that accepts a string: f(str)
|
|
|
|
|
@param callback: The function that must be provided to ImageSelector() and
|
|
|
|
|
will receive the selected filename as parameter.
|
|
|
|
|
@type title: string
|
|
|
|
|
@param title: The string that appears in the button to confirm the selection
|
|
|
|
|
and return from the image selection window.
|
BPython: cleaning some bug tracker entries:
(excuse me for doing all in a single commit, but they are tiny
fixes and it's bpython, that dark corner ...)
#1025 - FileSelector SEGV on dynamic callback Category:
Can't reproduce with current cvs, I'd say recent changes to fix
another crash related to FileSelector in gui-less scripts solved this
one, too.
#1028 - Reserved button event number:
Menu choices generate two events, one extra related to the menu
itself, with value=4. Made bpython ignore this extra event.
#1068 - FileSelector No file extension support:
As Ton wrote there, Blender itself doesn't support this yet. But the
requester also wanted Window.File/ImageSelector to accept a pathname. Done. Also updated doc.
#959 - Segfault on background rendering:
This happened in bg mode (blender -b filename -a, for example) when
a script with the line "Blender.Redraw()" was linked to FRAMECHANGED events. As reported in the bug page, it was because curarea is NULL in bg mode. Made Redraw() check for this and not call functions that expected curarea in Redraw, like one to swap buffers.
#1072 - Blender.Redraw() Segfault:
Good catch : ). Scripts called from the scripts win that called
Blender.Redraw() or Blender.Window.Redraw() would crash Blender because of a dirty pointer in Spacescript->script. Fixed.
2004-04-11 04:41:33 +00:00
|
|
|
@type filename: string
|
|
|
|
|
@param filename: A filename. This defaults to Blender.Get('filename').
|
2003-06-28 07:38:21 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def DrawProgressBar (done, text):
|
|
|
|
|
"""
|
|
|
|
|
Draw a progress bar in the upper right corner of the screen. To cancel it
|
2003-07-12 18:02:54 +00:00
|
|
|
prematurely, users can press the "Esc" key. Start it with done = 0 and end
|
|
|
|
|
it with done = 1.
|
2003-06-28 07:38:21 +00:00
|
|
|
@type done: float
|
2003-07-12 18:02:54 +00:00
|
|
|
@param done: A float in [0.0, 1.0] that tells the advance in the progress
|
2003-06-28 07:38:21 +00:00
|
|
|
bar.
|
|
|
|
|
@type text: string
|
|
|
|
|
@param text: Info about what is currently being done "behind the scenes".
|
|
|
|
|
"""
|
2003-09-03 04:04:17 +00:00
|
|
|
|
|
|
|
|
def GetCursorPos ():
|
|
|
|
|
"""
|
|
|
|
|
Get the current 3d cursor position.
|
|
|
|
|
@rtype: list of three floats
|
|
|
|
|
@return: the current position: [x, y, z].
|
|
|
|
|
"""
|
2003-09-18 00:54:43 +00:00
|
|
|
def SetCursorPos (coords):
|
|
|
|
|
"""
|
|
|
|
|
Change the 3d cursor position. Note: if visible, the 3d window must be
|
|
|
|
|
redrawn to display the change. This can be done with
|
|
|
|
|
L{Redraw}(L{Types}['VIEW3D']), for example.
|
|
|
|
|
@type coords: 3 floats or a list of 3 floats
|
|
|
|
|
@param coords: The new x, y, z coordinates.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def GetViewVector ():
|
|
|
|
|
"""
|
|
|
|
|
Get the current 3d view vector.
|
|
|
|
|
@rtype: list of three floats
|
|
|
|
|
@return: the current vector: [x, y, z].
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def GetViewMatrix ():
|
|
|
|
|
"""
|
|
|
|
|
Get the current 3d view matrix.
|
|
|
|
|
@rtype: 4x4 float matrix
|
|
|
|
|
@return: the current matrix.
|
|
|
|
|
"""
|