MHGUI: a Blender python quick GUI (UPDATE)


(Manuel) #1

Hi…this is a first beta of MHGUI,
a GUI lib developed for MakeHuman, but
thinked for general use.

http://www.kino3d.com/~Ken75/makehuman/MH_GUIbeta005.zip

I can’ t have a time to write doc,
but the client code is very simple.

in the blender textwindow, you can see
the Thanks to Eeshlo, Jms,Theeth :slight_smile:
and other:

-GPL license-
-SAMPLE_move: a sample code to move two windows
-SAMPLE_doc: a sample code to visualize an external text, for example a help
-SAMPLE_image: a sample code to put quickly square tga picture
-SAMPLE_menu: a sample code to put quickly a menu window
-SAMPLE_message: a sample code to put quickly a message window
-SAMPLE_time: a sample code to put quickly a status bar
-SAMPLE_menu: a sample code to put quickly a menu window
-SAMPLE_button: a sample code to put quickly a button window
-SAMPLE_slider: a sample code to put quickly a slider window
-SAMPLE_tree: a sample code to put quickly a hierarchy tree window (mhh…can be changed)
-SAMPLE_file: a sample code to put quickly a little file window
-SAMPLE_common: the common metod in the base class
-SAMPLE_bckg: a sample code to set a simple (actually) background


(wiensta) #2

looks great


(Manuel) #3

Have you seen my problem with button transparency…
:frowning:
I’ve tried to include the button declaration into
gl blend enadled routine…but the result is the same…

How I can enable the alpha for button?

Cheers,

     Manuel

(theeth) #4

you can’t do transparency for buttons unless you make your owns, of course.

Martin


(Manuel) #5

you can’t do transparency for buttons unless you make your owns, of course.

Martin[/quote]

Ok…
But why the button is always in first level?
in your GUI a rectangle on a button hide the button…(a draw.button I suppose)

How I can do this…?

Ciao,

           Manuel

(Manuel) #6

An Update of Treewin:

http://www.kino3d.com/~Ken75/makehuman/screenshot_bezier.jpg

Interactive Bezier line.

http://www.kino3d.com/~Ken75/makehuman/MH_GUIbeta016.zip

Testing please!

ah…another question…

What you think about this?
Can be usefull work or not?


(BaDbOyHeRe) #7

that gui is really coming togather. the transparency is way cool!!! I did notice the curve’s edges breaking a little when the curve is sharp. I think you got me wanting to try this. have alot to learn…thanks


(theeth) #8

it’s a little secret trick. instead of drawing all the interface in one pass, the function is called in a loop, but without clearing the screen between passes, so that the buttons and GL effects are drawn on the of the ones from previous pass. The problem main problem with that technique is that events from buttons are only registered for the last pass, so you have to do some sort of get_focus event to switch the focus from one window to another. It probably sounds complicate for nothing, but it’s the only way to draw things on top of one another (that I know of, of course).

I suggest you have a look at the GuiC.py and Gui.py files included with the Dynamica release, it could possibly help you.

Martin
PS: the OO structure in you script looks very nice an clean.


(Manuel) #9

This PS comment for me is really significant: you are
a GUI guru…thanks! This is a great encouragement…

Now I’m working to improve
and refine this little GUI lib (I’ve a “free time” because
I’m waiting the Env base mesh for makeHuman)


(theeth) #10

well thank you, this kind of reply means a lot for me :slight_smile:

Now I’m working to improve
and refine this little GUI lib (I’ve a “free time” because
I’m waiting the Env base mesh for makeHuman)

If you need more help, don’t be afraid to e-mail me directly.

Also, you can copy some parts from GuiC.py, if they can be of any use to you.

good luck!

Martin


(Manuel) #11

This is an update :slight_smile:
ALT-P on SAMPLE_tree …
Please, don’t use this code when it is in beta
version: I’ve in mind a little improvement,
like item.visibility , item.expand and item.collapse…
Try the SAMPLE_move too: is a sample code to move
a general window…

http://www.kino3d.com/~Ken75/makehuman/screenshot_bezier2.jpg

I’ve killed the g “grab” button: you can select the window
simply left click on it, and deselect with right click. Now we have more
space to image and symbols…

http://www.kino3d.com/~Ken75/makehuman/MH_GUIbeta028.zip

The sketch style is more clear …


(theeth) #12

it’s problem a problem with my OpenGL drivers, but the bezier connections are not as thick as your screenshot shows (they are only 1 pixel thick).

also, I have two little suggestions:

  • for the window moving, instead of using left and right click, you could use left mouse button press and left mouse button release. You probably already know how to distinguish the two, but if you don’t the second argument of the keypress function is the state of the button: 1 -> pressed, 0 -> depressed

  • instead of moving the window directly to where the pointer is, you could offset the window position by the variation in X and Y of the pointer. To do this, you’d have to keep track of the (X,Y) position of the pointer (which would be a good idea anyway, if you want to eventually make your own tooltip text) and then calculate the variation when needed

I hope that helps.

You’re doing a good job, progressing really fast.

Martin


(dotblend) #13

this is so friggin cool!

keep up the cool works!


(Manuel) #14

Thanks for suggestion! Now I’m going to change the script
to use the button press and release event. :smiley: I look about
the pointer offset too…

Mhh…the problem with your openGL is a hard
for me. I’m not openGL expert, and for this reason
I’ve used a very standard code to assign a custom
width to line:

def drawBezier(self,x1,y1,x2,y2,x3,y3,x4,y4,r,g,b,width,alpha,point,lines):	
...bla...bla...bla...

		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
		glEnable(GL_LINE_SMOOTH)
		glLineWidth(width)
		glColor4f(r,g,b,alpha)
		glBegin(GL_LINE_STRIP)

...bla...bla...bla...the glVertex2d(X, Y); ...bla..bla..
			
		glEnd()
		glDisable(GL_LINE_SMOOTH)
		glDisable(GL_BLEND)

The only command that affect the line width is

glLineWidth(width)

You can see the entire function in the BaseWindowClass
module. Now Im going to test this under my RH7.3…

Can you tell me the OS that you use?

Cheers,

                Manuel

(Manuel) #15

Mhh…under my RH7.3 with default lib and Blender2.25 I can see
the correct width, but the draw of Bezier is really slow…

I’m used a Bezier equation and a simple line to draw
it (one bezier line is composed by 20 simple and short line).

I must try the alternative metod of OpenGL evaluator …

I’ve try this, but I don’t know how declare a points buffer:
this code give me an error:


Traceback (most recent call last):
  File "Text", line 7, in ?
TypeError: size mismatch in assignment

the line 7 is

Points[:]= [[-3.0, -3.0, 0.0], [-3.0, 1.5, 0.0],
[4.0, -2.0, 0.0], [2.0, 2.0, 0.0]];

from this code


import Blender
from Blender import *
from Blender.BGL import *

Points = Buffer(GL_FLOAT,(3,3,3,3))

Points[:]= [[-3.0, -3.0, 0.0], [-3.0, 1.5, 0.0],
                      [4.0, -2.0, 0.0], [2.0, 2.0, 0.0]];

glColor3f(1.0, 1.0, 1.0);
 
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, Points[0][0]);

glEnable(GL_MAP1_VERTEX_3);

glBegin(GL_LINE_STRIP);

for i in range(100):
	glEvalCoord1f(i/100.0);
glEnd();
glPointSize(4.0);
glBegin(GL_POINTS);

for j in range(3):
	glVertex3fv(Points[j][0]);
glEnd();

this is a poor transalion from this C code:


// white color.
   glColor3f(1.0, 1.0, 1.0);

   // Move the scene before drawing.
   glTranslatef(0.0f, 0.0f, -13.0f);

   // This will set up the Bezier curve.  glMap1f defines a 1D evaluator.
   // The prototype is...
   // void glMap1f(GLenum target, float u1, float u2, int stride,
   //              int order, const float *points).
   
   // target defines the vertex coordinates (ex. x, y, z), the u1 and u2
   // define the range for the u parameter.  Stride defines the distance
   // between each point in the curve. and points is the array of points.
   // Check the MSDN for a better explanation if you seek one.
   glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &points[0][0]);

   // Here we enable the GL_MAP1_VERTEX_3.
   glEnable(GL_MAP1_VERTEX_3);

   // Now lets draw the curve using line strips.  All you need is to
   // call glEvalCoord1f() to draw the curve and thats it.
   glBegin(GL_LINE_STRIP);

      for(int i = 0; i < 100; i++)
         {
            // Here you we are drawing 100 points along the curve to
            // make the line.  To do so you send in glEvalCoord1f
            // and send to it i divided by 100.0f (don't forget to cast).
            glEvalCoord1f((float)i/100.0f);
         }

   glEnd();

   // And that is it.  Here I will draw the points big so the user (you) can
   // see them and where they are.

   // glPointSize() will increase the size of a point (which is the size of a pixel)
   // to whether size you would like.  This is done here so you can see the points.
   glPointSize(4.0);

   glBegin(GL_POINTS);

   for(int j = 0; j < 4; j++)
      {
         // Instead of using glVertex3f (which takes in three values) we use
         // glVertex3fv which takes three dimensional arrays.
         glVertex3fv(&points[j][0]);
      }

   glEnd();

Where is the error?

thx,

            Manuel

(theeth) #16

I’m under XP.

Martin


(Manuel) #17

:o
It’s strange…I’m testing on Win 2000, 98, RH7.3
Mhh…I’ve found this notice on OpenGL site:

Q. Is OpenGL compatible with Windows Me, Windows 2000 and Windows XP?

A. Yes, it is completely compatible. Windows (all recent versions) ships with the OpenGL 1.1 runtime library. However, it does not include any hardware drivers for individual video boards. You can you can download the drivers directly from the Web site of the company that manufactured your hardware. Most hardware manufacturers have updated their hardware drivers to run under Windows ME, 2000 and XP.


I’m using only 1.1 method… :-?
Can be a hardware driver problem?
For example when I using K3D under win2000,
I can’t see the GLpoint size, because my old ATI rage 128
have this bug in the driver…

There are other XP users that can test the scrip???
Please, help me…


(theeth) #18

like I said, it’s probably a problem with my graphic card.

Martin


(eeshlo) #19

I had no problems with your script, win98, Geforce3.

As for your bezier curve:


import Blender 
from Blender import *
from Blender.BGL import *
from Blender.Draw import *

def gui():
	
	# Clear screen
	glClearColor(0.0, 0.0, 0.0, 0.0)
	glClear(GL_COLOR_BUFFER_BIT)

	# Create two dimensional buffer of 4 vectors with 3 elements
	Points = Buffer(GL_FLOAT, (4,3)) 

	# assign vectors
	Points[0][:] = [-3.0, -3.0, 0.0]
	Points[1][:] = [-3.0, 1.5, 0.0,]
	Points[2][:] = [4.0, -2.0, 0.0]
	Points[3][:] = [2.0, 2.0, 0.0]

	glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, Points)

	glEnable(GL_MAP1_VERTEX_3)

	# get the window viewport size to scale the curve
	wsize = Buffer(GL_INT, 4)
	glGetIntegerv(GL_VIEWPORT, wsize)

	# translate to midpoints of screen
	glTranslatef(wsize[2]*0.5, wsize[3]*0.5, 0.0)
	# scale to 1/10 the width and height of the screen
	glScalef(wsize[2]*0.1, wsize[3]*0.1, 1.0)

	# draw the curve in white
	glColor3f(1.0, 1.0, 1.0)
	glBegin(GL_LINE_STRIP)
	for i in range(100): 
		glEvalCoord1f(float(i)*0.01)
	glEnd()

	# draw control points (green)
	glColor3f(0.0, 1.0, 0.0)
	glPointSize(5.0)
	glBegin(GL_POINTS)
	for j in range(4):
		glVertex3fv(Points[j])
	glEnd()

def event(evt, val):
	if evt == QKEY and not val:
		Exit()

Register(gui, event)


(Manuel) #20

Script update.
Now to move the windows left click
and drag. Furthmore now I’ve
calculate the offset of the window position
by the variation in X and Y of the pointer.

http://www.kino3d.com/~Ken75/makehuman/MH_GUIbeta030.zip

Thx Eeshlo!! :smiley: