How to add a scrollbar in a script?

Hi all, I didn’t find how to add a scrollbar to a blender python script. Googling seems to not help me. I tried to understand the system adopted by the doc browser and the interactive console scripts, but with no success.
There is a simple example of doing it?

There is no automatic way that I’m aware of. But I could be wrong, even though I don’t think I am. You’ll have to code that yourself. The OpenGL drawing commands can be used to draw the a scrollbar-esque control.

I wish there was something built it for that and in some ways am suprised there is not. Especially now that the menus contain the hooks for running the various script categories.

Nope, no automatic way to do this.

The simplest way would probably have everything be drawn relative to one offset variable and as you scroll you either increment or decrement the offset as necessary. You’ll needs bound checking to make sure your center and/or top and/or bottom bounds stay where they should be and you don’t get an infinite scroll.

The way things get drawn will take care of clipping (although you will be drawing things that won’t be seen, unless you’re doing something that’s very interface heavy with lots of drawing command calls it shouldn’t slow down on most systems).

Right. And don’t forget to add scrollwheel events too that control the starting drawing offset. That way users can scroll through the interface without having to touch the scrolling control (although the control will still give them the visual cue of how much is above and/or below what they presently see).

Doh! Ok, but as a newbie I think the simplest solution will be simply incrementing/decrementing one pixel the h position of all gui widget pressing a button or the like. Is it too lame?

EDIT: I didn’t viewed your last two replies before posting

Ok, I’ll have to experiment a bit

Now it work… Ideas for quick improvements?

# Scrollbar emulation test N°2



import Blender

from Blender.BGL import *

from Blender.Draw import *



h=[1]



def draw():

	Button('^', 1, 122, 62, 20, 20)

	Button('v', 2, 122, 40, 20, 20)

	Button('Exit', 3, 20, 50+h[0], 100, 20)



def event(evt, val):

	if evt== ESCKEY: Exit()

	if evt== WHEELUPMOUSE:

		h[0]=h[0]+10 ; Redraw(1)

	if evt == WHEELDOWNMOUSE:

		h[0] = h[0]-10 ; Redraw(1)



def bevent(evt):

	if evt == 1: h[0]=h[0]+5 ; print h

	if evt == 2: h[0]=h[0]-5 ; print h

	if evt == 3: Exit()



	Blender.Redraw()



Register(draw, event, bevent)

How did you end up with this gls? Any progress?

I conducted a test on the “Tree from Curves” script using one of my current projects.

Specifically I modified the line “from Blender import Draw” to “import DrawX as Draw” and this was the result… a functional scrollbar (no other script changes were made):

http://www.fourmadmen.com/blender/misc/treecurv_scroll1.jpg

http://www.fourmadmen.com/blender/misc/treecurv_scroll2.jpg