sidebar features
sidebar content

Go Back   Blender Artists Forums > General Forums > Python & Plugins

Reply
 
Thread Tools
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Hi.

I'm writing on some kind of API wrapper for blenders script-UI-functionallity.

To get this UI:
<obsolete>
(Note: you can scroll the long text ether by the two buttons "UP" and "DOWN" or by mousweel)

you have just to write that code:
<obsolete>

I use this (an older version of it) in TerryNoise allready and will release a more complete version tomorrow or in a few days.

Things I maybe add to ScriptUI:
  • WidgetList: a scrollable list of Widgets (maybe with support for list-in-list)
    (maybe some kind of collapse able widgetlist, too)
    Frame: a frame to put Widgets into
    improve TextRender: rename to SimpleText and add support for textcolor
    improve AdvancedText: add support for text- and backgroundcolor
#1   Old 02-Jul-05, 23:55   
Reply With Quote


panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Ok, the WidgetList isn't scrollable or collapsable, maybe there will follow such a WidgetList someday. But with the rest I'm happy.

Following example script produces following GUI:
<obsolete>

<obsolete>

You can download ScriptUI here.
#2   Old 03-Jul-05, 21:41   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
New version of ScriptUI!

Changelog:
version 0.4 19.07.2005
  • API Changes: EventManager has now factories for widget-generation
    Split code to 2 files: ScriptUI.py and ScriptUIWidgets.py
    New Widgets: fully wrapped all widgets except Image
    Popups: wrapped all popup dialogs

Download: ScriptUI 0.4 (zip, 7 KB)

I also added a right-click menu to the example-code:
<obsolete>
#3   Old 19-Jul-05, 21:26   
Reply With Quote
JA-forreal's Avatar
JA-forreal JA-forreal is offline
Member
 
Join Date: Sep 2003
Posts: 1,373
Thanks panzi. This is is really great.
............................................
“Blender, Alternative 3D”

-Itchy render fingers
#4   Old 19-Jul-05, 21:47   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Quote:
Originally Posted by JA-forreal
Thanks panzi. This is is really great.
Pleased to hear that.

Here is a new version of ScriptUI. It's API is not compatible to the old version. Don't expect the API to be frozen bevore version 1.0-final. (and don't ever expect a 1.0-final version )

Changelog:
  • Improved: design overhaul
    NEW: widgets: FileField, Spacer, PixelField, RenderField, MenuWidget, Image
    NEW: wrapped blender's popups: PupFloatInput, PupIntInput, PupStrInput, PupMenu, MsgBox (one-line PupMenu without title
    NEW: RGB-Color class with RGB <-> HSV conversion support)
    NEW: the 'simple' widgets are real classes now
    FIX: many minor fixes
    FIX: proper usage of begin_change() and end_change() by usage of the newly added MakeChanges class
    FIX: forgot to pack ScriptUIColor.py

Download: ScriptUI 0.5 (zip, 20KB)
#5   Old 23-Jul-05, 23:04   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Update to version 0.6 (26.07.2005):
Changelog:
  • Restructured ScriptUI to following moduls: ScriptUI, ScriptUI.Widgets, ScriptUI.Color
    Renamed Menu to MenuBase
    Renamed MenuWidget to Menu
    ADD: some few additions like get_scale_left() etc. for ContainerWidget
    FIX: som few fixes in ScriptUI.Color
    DOC: API-documentation with epydoc!

Download:
Example:

Following GUI is produced by following script:


Code:
#!BPY # vim:encoding=utf-8 """ Name: 'ScriptUI Test' Blender: 233 Group: 'Misc' Tooltip: '' """ import math from math import * import Blender import ScriptUI from ScriptUI import * import ScriptUI.Color from ScriptUI.Color import * text = """1 2 3 this is a very long text... bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla .\n.\n.\n.\n.\n.\n.\n.\n.\n.\n. foo bar baz 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 0123456789012345678901234567890123456789012345678901234567890123456789 \n\n\n\n\n\n\n\n end ____________________________________________""" em = EventManager() buttons1 = [ em.PushButton("1. foo", bevent = Functor(lambda pm: pm("Hello World!"),Blender.Draw.PupMenu)), em.PushButton("2. bar", bevent = Functor(lambda pm: pm("bla bla"),Blender.Draw.PupMenu)), em.PushButton("3. baz"), em.Number ("4. egg", initvalue = 0., min = -1., max = 1.), em.PushButton("5. spam") ] buttons2 = [ em.WidgetList(buttons1, 6, 4, -1, 25, True, False), em.PushButton("6. foo", bevent = Functor(lambda pm: pm("Hello Offworld!"),Blender.Draw.PupMenu)), em.Toggle ("7. bar", bevent = Functor(lambda pm: pm("dumdi dum"),Blender.Draw.PupMenu), initvalue = 0), em.String ("8. baz: ", length = 512, initvalue = "xxx") ] mnu = em.Menu("10. tomato", x = 80, y = 70, width = 100, height = 40) mnu.addItem("foo", Functor(lambda pm: pm("Menu item click!"),Blender.Draw.PupMenu)) mnu.addItem("bar") mnu.addItem("baz") mnu.addSep() mnu.addItem("egg") mnu.addItem("spam") pixfld1 = em.PixelField(x = 0, y = 250, width = 160, height = 80) pixfld2 = em.PixelField(x = 0, y = 340, width = 160, height = 30) col = Color() w = pixfld1.get_width() h = pixfld1.get_height() for x in xrange(w): for y in xrange(h): col.fromHSV(float(x)/w, float(y)/h, 1.) pixfld1.pixels[y][x][:] = col w = pixfld2.get_width() h = pixfld2.get_height() for x in xrange(w): v = float(x)/float(w) if v < .25: col.red = 1. col.green = v / .25 col.blue = 0. elif v < .5: col.red = (.25 - (v - .25)) / .25 col.green = 1. col.blue = 0. elif v < .75: col.red = 0. col.green = 1. col.blue = (v - .5) / .25 else: col.red = 0. col.green = (.25 - (v - .75)) / .25 col.blue = 1. for y in xrange(h): pixfld2.pixels[y][x][:] = col buttons3 = [ em.PushButton("9. egg", x = 0, y = 0, width = 90, height = 20), mnu, em.Slider ("11. spam", x = 150, y = 190, width = 210, height = 20, initvalue = 0., min = -10., max = 10.), em.Rect (BLUE, 300, 250, 40, 80), em.FileField (x = 0, y = 150), pixfld1, pixfld2 ] btnexit = em.PushButton("exit", 10, 420, 50, 20, em.exit, parent = em.root) smpltxt = em.SimpleText("USE MOUSEWEEL TO SCROLL!", "large", 15, True, RED, 10, 450, parent = em.root) advtxt = em.ScrollText(text, "small", 15, 6, BLACK, Color(.5,.6,.6,1.), 10, 10, 300, 400, parent = em.root) wdglst = em.WidgetList(buttons2, 6, 4, 110, -1, False, False, 310, 10, 200, 80, parent = em.root) wdgfra = em.WidgetFrame(buttons3, x = 330, y = 220, width = 400, height = 400, parent = em.root) pupmnu = PupMenu("PupMenu 1") pupmnu2 = PupMenu("PupMenu 2") pupstr = PupStrInput("str: ","") pupint = PupIntInput("int: ",0,-10,10) pupflo = PupFloatInput("float: ", 1., 0., 1., .01, 3) def str_inp(): val = pupstr.show() if val != None: Blender.Draw.PupMenu(val) def int_inp(): val = pupint.show() if val != None: Blender.Draw.PupMenu(str(val)) def flo_inp(): val = pupflo.show() if val != None: Blender.Draw.PupMenu(str(val)) pupmnu.addItem("self...", pupmnu) pupmnu.addItem("other...", pupmnu2) pupmnu.addSep() pupmnu.addItem("string input", str_inp) pupmnu.addItem("integer input", int_inp) pupmnu.addItem("float input", flo_inp) em.register_event(Blender.Draw.WHEELUPMOUSE, Functor(lambda at,evt,modi: at.scroll_up(),advtxt)) em.register_event(Blender.Draw.WHEELDOWNMOUSE, Functor(lambda at,evt,modi: at.scroll_down(),advtxt)) em.register_event(Blender.Draw.RIGHTMOUSE, Functor(lambda pm,evt,modi: pm.show(),pupmnu)) em.run()
#6   Old 26-Jul-05, 15:43   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Update to version 0.6.1 (27.07.2005):
Changelog:
  • corrected version number
    ADD: modul ScriptUI.Popups, moved all popups to it.
    renamed popups: removed 'Pup' prefix
    FIX: under some circumstances some widgets haven't been deleted properly
    FIX: FileField called 'action' to often
    ADD: FileField can now use Blender.Window.ImageSelector, too.
    ADD: CollapseWidget (dosen't has much use yet, because there is no CollapseList yet)

Download:
#7   Old 27-Jul-05, 19:40   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Update to version 0.6.2 (06.09.2005):
Changelog:
  • FIX: Widgets with parent = None could possible be not deleted on exit, because of ref-loops, when they have childs. Now their parent is em.noroot, wich is an second RootWidget which purpose is to unref() thees "parentless" Widgets on exit.
    ADD: It's now possible to change the order of child widgets by using the methods: up(), down(), bottom(), top()

Download:
#8   Old 06-Sep-05, 14:20   
Reply With Quote
Oyster Oyster is offline
Member
 
Join Date: Jul 2002
Posts: 377
whoa, a long time span between your updates
maybe i will use this in the future
............................................
My Blog in Chinese.
You can add comments in Chinese or English.
Hope you like it.
#9   Old 06-Sep-05, 14:52   
Reply With Quote
antont antont is offline
Member
 
Join Date: Jun 2003
Location: Oulu
Posts: 167
i think this, or something like this, should become a part of the official distribution. so that many scripts could use it then.

has this been used by others already? any observations by script authors? comments by bf-python admins?

~Toni
#10   Old 09-Sep-05, 10:22   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Quote:
Originally Posted by Oyster
whoa, a long time span between your updates
maybe i will use this in the future
Well, I tend to get bored when I spend too much time with one project.
But the main reason is, I have other work to do.

Quote:
Originally Posted by antont
i think this, or something like this, should become a part of the official distribution. so that many scripts could use it then.
I think this shouldn't hane been nesecarry, because such a API should be built in in blender (and not be a crappy wraper around blenders API).

Quote:
has this been used by others already? any observations by script authors? comments by bf-python admins?

~Toni
I know of at least one other, who uses it.
But the download rate ist'n very high (if my blog count's it correctly, I dunno if the counter is surpased by the link here):
0.6.2: none
0.6.1: 38 downloads
0.6: none
0.5: none
0.4: none
0.3: none
#11   Old 09-Sep-05, 22:44   
Reply With Quote
Sutabi's Avatar
Sutabi Sutabi is offline
Member
 
Join Date: Mar 2003
Location: Vista, CA, USA
Posts: 1,712
I am happy as it is I downloaded 6.2 a few times so maybe yur counter is broken? Anyways, even if this isn't developed any more I cant seem myself without this script.
............................................
______________________________________
Developing the imagination of art.
#12   Old 10-Sep-05, 06:15   
Reply With Quote
antont antont is offline
Member
 
Join Date: Jun 2003
Location: Oulu
Posts: 167
Quote:
I think this shouldn't hane been nesecarry, because such a API should be built in in blender (and not be a crappy wraper around blenders API).
yes it should be, and that is exactly why i'm interested in this. perhaps we can put this into Blender. a wrapper does not have to be crappy. and UI creation can well be done in Python, 'cause it is not CPU intensive, i.e. not done a million times a second etc.

~Toni
#13   Old 12-Sep-05, 10:03   
Reply With Quote
antont antont is offline
Member
 
Join Date: Jun 2003
Location: Oulu
Posts: 167
well now i need a gui, and decided to give this wrapper a shot. so far it seems great! made some changes, do you think these make sense:

if no parent is given for a eventmanager.SomeWidget() factory, the eventmanager.root is used by default. i just made all the factories look like this:

Code:
parent = parent or self.root return Slider(name,x,y,width,height,bevent,initvalue,min,max,realtime,tooltip,parent,self)
also, i added little 'intelligence' to the Slider constructor:

Code:
if initvalue > max: max = initvalue
these changes make this little test work, and me happy (except that the text does not show - why?):

Code:
import ScriptUI em = ScriptUI.EventManager() text = em.SimpleText("Hello Blender") amount = em.Slider("amount", initvalue=5., x=100) btnexit = em.PushButton("exit", x=300, bevent=em.exit) em.run()
i think i will propose the bf-python team to take a look at this, and consider inclusion to the official release. in fact i already put this in the release/scripts/bpymodules/ directory in my cvs working copy. of course that would not have to mean freezing at this point, 'cause the next release is still quite far a way - so even for that there'd be good time for experimenting, API changes etc. any thoughts on that?

~Toni
#14   Old 15-Sep-05, 09:42   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
It's cool that so many use my little wrapper!
Quote:
if no parent is given for a eventmanager.SomeWidget() factory, the eventmanager.root is used by default.
I didn't do that so I can pre-create widgets in the background, wich will not be drawn and be child to noone (well, they are childs of eventmngr.noroot, just to be deletet properly on eventmngr.exit()).

This behavior could also be achieved by making such rootless widgets invisible instead. But this way was easyer in my TerryNoiseUI.

Anyway, there should be more widgets, e.g. a colapsable list similar to the list used in blender for object-constraints and some kind of option-field would also be nice. A Scrollbar to scroll through a list or text would be great, but I don't know how to do this with blenders API. Well maybe... (thinking) maybe there is a way.

I will work on ScriptUi when ever I have time and when ever I feel like it. In the summer I had other work to do and now the uni begins again, so I dunno how much time I will have. But I'm almost certain when it comes to learning for the test, I will feel like working on ScriptUI (as allways).
#15   Old 20-Sep-05, 13:41   
Reply With Quote
antont antont is offline
Member
 
Join Date: Jun 2003
Location: Oulu
Posts: 167
surely the non-parenting way that you needed can be preserved as an option. i guess that'd be ok?

dunno how the ui programming things in blender will go, hopefully in some good direction..

~Toni
#16   Old 21-Sep-05, 19:31   
Reply With Quote
SHABA1 SHABA1 is offline
Member
 
Join Date: Mar 2002
Location: California
Posts: 1,457
Am I to understand that this script is a GUI contruction kit? One thing I did note is the text in the screen shot that said use mousewheel to scroll. If this would be possible to put into the interface of various scripts it would make my life using blender a lot easier. I am stuck with and 800X600 screen on my laptop and often when I run a script in my standard 3 3d windows,script window and the button window at the bottom the top of some scripts interface gets cut off.
#17   Old 21-Sep-05, 19:49   
Reply With Quote
Sutabi's Avatar
Sutabi Sutabi is offline
Member
 
Join Date: Mar 2003
Location: Vista, CA, USA
Posts: 1,712
If there is every a chance of spear time, It would be cool to have bitmap buttons ^_-, im sure that probably out the question though hehe.
............................................
______________________________________
Developing the imagination of art.
#18   Old 07-Oct-05, 22:12   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Quote:
Originally Posted by Sutabi
If there is every a chance of spear time, It would be cool to have bitmap buttons ^_-, im sure that probably out the question though hehe.
Well, this is not possible with a simple wrapper to blenders python-GUI-API.
#19   Old 08-Oct-05, 16:30   
Reply With Quote
panzi panzi is offline
Member
 
Join Date: Feb 2005
Posts: 413
Update to version 0.6.3+0.6.3a (17.02.2006):
Changelog:
  • FIX: Typo in Popups.py
    FIX: Color.__imul__ etc. now returns self. (but e.g. col *= 2. still don't work. any hint why this could be?)
    ADD: new popup: Block

Download:
New Testcode:
Code:
#!BPY # vim:encoding=utf-8 """ Name: 'ScriptUI Test' Blender: 233 Group: 'Misc' Tooltip: '' """ import math from math import * import Blender import ScriptUI from ScriptUI import * import ScriptUI.Color from ScriptUI.Color import * from ScriptUI.Popups import * text = """1 2 3 this is a very long text... bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla .\n.\n.\n.\n.\n.\n.\n.\n.\n.\n. foo bar baz 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 0123456789012345678901234567890123456789012345678901234567890123456789 \n\n\n\n\n\n\n\n end ____________________________________________""" em = EventManager() buttons1 = [ em.PushButton("1. foo", bevent = Functor(lambda pm: pm("Hello World!"),Blender.Draw.PupMenu)), em.PushButton("2. bar", bevent = Functor(lambda pm: pm("bla bla"),Blender.Draw.PupMenu)), em.PushButton("3. baz"), em.Number ("4. egg", initvalue = 0., min = -1., max = 1.), em.PushButton("5. spam") ] buttons2 = [ em.WidgetList(buttons1, 6, 4, -1, 25, True, False), em.PushButton("6. foo", bevent = Functor(lambda pm: pm("Hello Offworld!"),Blender.Draw.PupMenu)), em.Toggle ("7. bar", bevent = Functor(lambda pm: pm("dumdi dum"),Blender.Draw.PupMenu), initvalue = 0), em.String ("8. baz: ", length = 512, initvalue = "xxx") ] tgl = em.Toggle("toggle") ival = em.Number("integer",initvalue=0,min=-10,max=10) fval = em.Number("float",initvalue=0.,min=-1.,max=1.) blkmnu = Block("block",[tgl,ival,fval]) def blk(): ret = blkmnu.show() Blender.Draw.PupMenu( '|'.join( ("return value = " + repr(ret), "toggle = " + repr(tgl.get_value()), "integer = " + repr(ival.get_value()), "float = " + repr(fval.get_value()) )) ) mnu = em.Menu("10. tomato", x = 80, y = 70, width = 100, height = 40) mnu.addItem("foo", Functor(lambda pm: pm("Menu item click!"),Blender.Draw.PupMenu)) mnu.addItem("bar") mnu.addItem("baz") mnu.addSep() mnu.addItem("egg") mnu.addItem("spam") pixfld1 = em.PixelField(x = 0, y = 250, width = 160, height = 80) pixfld2 = em.PixelField(x = 0, y = 340, width = 160, height = 30) def recolor(): col = Color() w = pixfld1.get_width() h = pixfld1.get_height() for x in xrange(w): for y in xrange(h): col.fromHSV(float(x)/w, float(y)/h, 1.) col.__imul__(sld.get_value()) #col *= sld.get_value() pixfld1.pixels[y][x][:] = col Blender.Draw.Redraw() sld = em.Slider("11. bright", x = 150, y = 190, width = 210, height = 20, initvalue = 1., min = 0., max = 2., bevent = recolor) recolor() col = Color() w = pixfld2.get_width() h = pixfld2.get_height() for x in xrange(w): v = float(x)/float(w) if v < .25: col.red = 1. col.green = v / .25 col.blue = 0. elif v < .5: col.red = (.25 - (v - .25)) / .25 col.green = 1. col.blue = 0. elif v < .75: col.red = 0. col.green = 1. col.blue = (v - .5) / .25 else: col.red = 0. col.green = (.25 - (v - .75)) / .25 col.blue = 1. for y in xrange(h): pixfld2.pixels[y][x][:] = col buttons3 = [ em.PushButton("9. egg", x = 0, y = 0, width = 90, height = 20), mnu, sld, em.Rect (BLUE, 300, 250, 40, 80), em.FileField (x = 0, y = 150), pixfld1, pixfld2 ] btnexit = em.PushButton("exit", 10, 420, 50, 20, em.exit, parent = em.root) smpltxt = em.SimpleText("USE MOUSEWEEL TO SCROLL!", "large", 15, True, RED, 10, 450, parent = em.root) advtxt = em.ScrollText(text, "small", 15, 6, BLACK, Color(.5,.6,.6,1.), 10, 10, 300, 400, parent = em.root) wdglst = em.WidgetList(buttons2, 6, 4, 110, -1, False, False, 310, 10, 200, 80, parent = em.root) wdgfra = em.WidgetFrame(buttons3, x = 330, y = 220, width = 400, height = 400, parent = em.root) pupmnu = Menu("PupMenu 1") pupmnu2 = Menu("PupMenu 2") pupstr = StrInput("str: ","") pupint = IntInput("int: ",0,-10,10) pupflo = FloatInput("float: ", 1., 0., 1., .01, 3) def str_inp(): val = pupstr.show() if val != None: Blender.Draw.PupMenu(val) def int_inp(): val = pupint.show() if val != None: Blender.Draw.PupMenu(str(val)) def flo_inp(): val = pupflo.show() if val != None: Blender.Draw.PupMenu(str(val)) pupmnu.addItem("self...", pupmnu) pupmnu.addItem("other...", pupmnu2) pupmnu.addItem("block...", blk) pupmnu.addSep() pupmnu.addItem("string input", str_inp) pupmnu.addItem("integer input", int_inp) pupmnu.addItem("float input", flo_inp) em.register_event(Blender.Draw.WHEELUPMOUSE, Functor(lambda at,evt,modi: at.scroll_up(),advtxt)) em.register_event(Blender.Draw.WHEELDOWNMOUSE, Functor(lambda at,evt,modi: at.scroll_down(),advtxt)) em.register_event(Blender.Draw.RIGHTMOUSE, Functor(lambda pm,evt,modi: pm.show(),pupmnu)) em.run()
Edit:
Made a bugfix, thanks to jms.
#20   Old 17-Feb-06, 15:36   
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 11:48.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Logo and website design copyright © 2006 by froodee design bureau. All rights reserved.
Other Blender Sites
new icon Blender Homepage »
The official Blender homepage
new icon BlenderNation »
Fresh Blender News, Every Day
new icon Blenderart Magazine »
Blender articles, tutorials and images.
Blender Headlines
Featured Artwork
Short animation: Barrel by Phlopper
Woolly mammoth by sebastian_k
Photorealistic classic furniture by eMirage
Social BlenderArtists