window height

how can i get the height of the current python running window?

I was once going to post just the relavant code, but here is my (new) starting point for scripts with user interfaces (I will work on them more over the break if I have time)

""" 
NOT NAMED
Nick Winters (z3r0_d)

[short description]

to run press load this file into a text window, and press alt+p
with your cursor in that window
"""

from Blender import *
from Blender.BGL import *

#GLOBALS (varibles used in multiple functions

#BUTTON GLOBALS (numbers corresponding to buttons)

#for window-releated operations (they are set properly on redraw)
winwidth = 50
winheight = 50

def handleEvent(eventNum, value):
	# define global variables here
	#
	if eventNum == Draw.ESCKEY or eventNum == Draw.RIGHTMOUSE:
		Draw.Exit()
		Draw.Redraw()
		print "---------SCRIPTEND---------
"
	pass

def handleButton(buttonNum):
	# define global variables here
	#
	# define button handlers here
	pass

def redraw():
	# define global variables here
	global winwidth 
	global winheight
	#
	# change color to suit needs...
	glClearColor(0.25, 0.25, 0.25, 0.0)
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
	# the following gets the window size and sets winwidth and winheight correctly
	viewportvaluebuffer = Buffer(GL_FLOAT, 4) 
	glGetFloatv(GL_VIEWPORT, viewportvaluebuffer)
	# now, in viewportvaluebuffer are [x, y, width, height]
	winwidth = int(viewportvaluebuffer[2])
	winheight = int(viewportvaluebuffer[3])
	# this is a text color... (shall I draw text)
	glColor3f(1.0, 1.0, 1.0)
	# example drawing text:
	glRasterPos2i(winwidth/2 - 225/2, 2)
	# the following text is about 225 pixels wide, I want it centered
	Draw.Text("RIGHT CLICK OR PRESS ESC TO QUIT")
	#
	# DRAW THE BUTTONS HERE!
	Draw.Button("BLAH", 1234567, 20, 20, winwidth-40, winheight-40, "3nVy M3 4Nd 0ur 1337 t00lt1p!!!1")


print "---------SCRIPTSTART---------"
# start the ui
Draw.Register(redraw, handleEvent, handleButton)

so the relavant part is glGetFloatv(GL_VIEWPORT, A_4_ELEMENT_BUFFER_OF_FLOATS) and the various values in that buffer
getIntegerv(…) probably would have worked just as well, considering how blender does this (the buffer would need to be of GL_INT too)
(iirc it is [x, y, width, height]

wow - thats fantastic, cheers

now if you could give me an example for a scrolling frame in the window you would really make my day :wink:

i have a situation with an unknown amount of attributes that need to be displayed ( quite often more that i have room for in the window ). so i need some sort of scrolling area. my (limited) collection of blender python scripts doesnt seem to include any such thing.

One script that I know has a scrollbar is the docbrowser - I modeled a custom scrollbar after it. It’s not terribly easy, you’ve got to draw the scrollbar using GLRects and the scroll cursor as another GLRect which is attached to some kind of scrollbar value. The scrollbar value (which represents a percent) shows the attributes at a certain point in a list. For example, if the value of the scrollbar is 50% and there are 22 items, your list will start at item 11. The trick is that the origin of Blender’s GUI coordinates is in the lower left of the screen, so you’ll have to invert some values so that 0 % is the top of the bar and 100% is at the bottom. Then you need to put MOUSEX / MOUSEY / LEFTMOUSE events in the input event handler. It might be dirty.

P.S. I tried using the Draw module’s builtin scrollbar. I haven’t a clue how it works.

ah! youve just reminded me of the the city generator - it has scrollbar box for buildings.

hack hack hack… :slight_smile: