Making an increment bar????

HI,

Does anyone have any suggestions on how to make an increment bar work on the gui?

Similar to a windows installer bar, I’d like to have one on my import /export scripts.

I’d tried several ways, but repeatedly get "referenced before assignment "errors.

Any suggestions welcome (and pointers to scripts with ones).

Cheers Stephen

actually its kinda simple, divide your process into how many incriments, then at the end of that much code have it stick an incriment amoutn in the bar, i don’t know anyone with that, or a way of doign it myself since i havent gotten into gui programming

MacBlender

Thanks, I’d got that bit, I just can’t get the thing to show up or refresh!!!

Here is the code I’m playing with, any suggestions???


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

incW = 0
incMAX = 300.00

def gui():
    global incW
    glClearColor(0.5,0.5,0.75, 0.0)
    glClear(GL_COLOR_BUFFER_BIT)
    DrawglBOX(100,200,incW,50)
    Button("Exit", 1, 100, 100, 100, 50, "Exit")
    Button("Go", 2, 200, 100, 100, 50, "Go")
    
def DrawglBOX(x1,y1,W,H):
    x2 = x1 + W
    y2 = y1 + H
    glColor3f (0.0, 0.0, 0.0);
    glLineWidth (1);
    glBegin (GL_LINE_LOOP);
    glVertex2f (x1, y1);
    glVertex2f (x2, y1);
    glVertex2f (x2, y2);
    glVertex2f (x1, y2);
    glEnd ();

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

def bevent(evt):
    if (evt == 1): Exit()
    if (evt == 2):
        for x in range(300):
            incW = int((x/incMAX) * incMAX)
            print x,incMAX, incW
            Redraw(1) #Tried Redraw() and Draw()

Register(gui, event, bevent)


def bevent(evt):
    global incW, incMAX
    if (evt == 1): Exit()
    if (evt == 2):
        for x in range(300):
            incW = int((x/incMAX) * incMAX)
            print x,incMAX, incW
            Redraw(1) #Tried Redraw() and Draw() 

You forgot to reference your two varaibles with the Global keyword since you need to access it from another namespace.

Martin

Hi,

Thanks for that - works well now :stuck_out_tongue:

here is the complete test code, if anyone wants to play with it:

Cheers Stephen


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

incW = 0
incMAX = 296.00
objno = 300

def gui():
    glClearColor(0.5,0.5,0.75, 0.0)
    glClear(GL_COLOR_BUFFER_BIT)
    DrawglBOX(0,100,200,300,50)
    DrawglBOX(1,102,202,incW,46)
    Button("Exit", 1, 100, 100, 100, 50, "Exit")
    Button("Go", 2, 200, 100, 100, 50, "Go")
    
def DrawglBOX(type,x1,y1,W,H):
    x2 = x1 + W
    y2 = y1 + H
    glColor3f (0.0, 0.0, 0.7);
    glLineWidth (1);
    if (type == 0):
        glBegin (GL_LINE_LOOP);
    elif (type == 1):
        glBegin (GL_POLYGON);
    else:
        glBegin (GL_POLYGON);
    glVertex2f (x1, y1);
    glVertex2f (x2, y1);
    glVertex2f (x2, y2);
    glVertex2f (x1, y2);
    glEnd ();

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

def bevent(evt):
    global incW, incMAX, objno
    if (evt == 1): Exit()
    if (evt == 2):
        for x in range(objno):
            incW = int(((x+1.0)/float(objno)) * incMAX)
            print objno, x,incMAX, incW
            Redraw() #To test use 'Draw()' - much slower!

Register(gui, event, bevent)