Users browsing this thread: 1 Guest(s)
Another UMC side-thread
#9
thanks, and while I could kinda get a PyQt gui going, I asked for Tk Tongue
but even still, screw that ;P
I'm going full-out with OpenGL, I just need a little help porting the widgets to classes so I'll have less work to do. Cute
(all I need to know is the hierarchy for building a proper GUI and I'll be set) Smile

but as for right now, here's the code for my simplest widget: (the Toggle-Button)
Code:
def __RemoveTButton(Na,priority=0):
    global Widgets,layer
    try:
        Widgets[Na].hitdef.enabled=False #disable the hitdef (save the state)
        tbna='TButton%sQuad'%Na
        tbfna='TButton%sText'%Na
        tbfbgna='TButton%sText'%Na
        p2 = priority+2
        if layer[0].stack[p2].HasPrimitive(tbna):
            layer[0].stack[p2].RemovePrimitive(tbna)
            layer[0].stack[p2].RemoveString(tbfna)
            layer[0].stack[p2].RemovePrimitive(tbfbgna)
    except: pass

def __TButton(X,Y,Na,St=False,Text='',fontcolor=(0,0,0,220),priority=0):
    global Widgets,layer, AllowHitUpdates

    #minor pre-calculations
    X2,Y2=X+20.,Y+20.
    fx,fy=X+25.,Y+2.
    
    #verify the widget exists
    try: W=Widgets[Na]
    except KeyError:
        Widgets[Na]=__Widget()
        W=Widgets[Na]

        W.info=St #toggle state
        W.hitdef.x=X; W.hitdef.y=Y; W.hitdef.X=X2; W.hitdef.Y=Y2
        
    #update the HitDef if changed by an outside function
    if AllowHitUpdates!=W.hitdef.enabled: W.hitdef.enabled=AllowHitUpdates
    
    #drawing data:
    tbna='TButton%sQuad'%Na
    tbfna='TButton%sText'%Na
    #tbfbgna='TButton%sText'%Na
    p2 = priority+2
    if not layer[0].stack[p2].HasPrimitive(tbna): #don't draw if we already have
        layer[0].stack[p2].AddQuad(tbna,[X,Y],[X2,Y],[X2,Y2],[X,Y2],(95,95,95,180))
        layer[0].stack[priority].AddString(tbfna,Text,0.667,fx,fy,None,None,fontcolor)
        fxtbfw = fx+layer[0].stack[priority].strings[tbfna].w
        fytbfh = fy+layer[0].stack[priority].strings[tbfna].h
        #layer[0].stack[p2].AddQuad(tbfbgna,[fx,fy],[fxtbfw,fy],[fxtbfw,fytbfh],[fx,fytbfh],(127,127,127,200))
    
    TB = layer[0].stack[p2].primitives[tbna]
    TBF = layer[0].stack[priority].strings[tbfna]
    #TBFBG = layer[0].stack[p2].primitives[tbfbgna]

    #Positioning Verification
    if TB.Position([X,Y],[X2,Y],[X2,Y2],[X,Y2]):
        TBF.Position(fx,fy,None,None)
        fxtbfw,fytbfh = fx+TBF.w,fy+TBF.h
        #TBFBG.Position([fx,fy],[fxtbfw,fy],[fxtbfw,fytbfh],[fx,fytbfh])

    #HitDef
    if W.hitdef.x!=X: W.hitdef.x=X; W.hitdef.X=X2
    if W.hitdef.y!=Y: W.hitdef.y=Y; W.hitdef.Y=Y2

    #Widget logic
    if W.info:
        if W.event.hasFocus: #change the color if the mouse is over the selection box
            if W.event.clickL or W.event.holdL: #change the color if the selection box is clicked or held
                TB.Color(79,79,79,180)
            else: TB.Color(95,95,95,180)
        else: TB.Color(79,79,79,180)
    else:  
        if W.event.hasFocus:
            if W.event.clickL or W.event.holdL:
                TB.Color(79,79,79,180)
            else: TB.Color(111,111,111,180)
        else: TB.Color(95,95,95,180)

    if W.event.releaseL: W.info=(False if W.info else True)

    return W.info

yea, everything's just functions, except for the main layer and widget classes.
the original design of the GUI (as those 2 classes are modifications) consisted of nothing but functions as I didn't know how to work classes, or even decorators back then.

decorators are easy Smile
they're just special wrapper functions:

def wrapper(f,v): f(*v) # I think this is right?? >.>
@wrapper
def func(v): pass

func(1)

is the same thing as:

def wrapper(f,*v): f(*v) # I think this is right?? >.>
def func(v): pass

wrapper(func,1)

EDIT:
also, some useful info for functions Cute

>>> def f(a,b,c): print a,b,c

>>> d={'a':0,'c':1,'b':2}
>>> d
{'a': 0, 'c': 1, 'b': 2}
>>> f(**d)
0 2 1
>>>


I don't always syntax highlight, but I often try to. Wink

that syntax style can be found in IDLE, Python's native IDE
Reply
Thanked by:


Messages In This Thread
Another UMC side-thread - by Tcll - 12-13-2014, 01:18 AM
RE: Another UMC side-thread - by Tcll - 12-13-2014, 11:44 PM
RE: Another UMC side-thread - by Struggleton! - 12-13-2014, 11:44 PM
RE: Another UMC side-thread - by Tcll - 12-14-2014, 12:30 AM
RE: Another UMC side-thread - by Tcll - 12-15-2014, 09:56 PM
RE: Another UMC side-thread - by Tcll - 12-17-2014, 03:17 PM
RE: Another UMC side-thread - by puggsoy - 12-17-2014, 08:39 PM
RE: Another UMC side-thread - by Struggleton! - 12-17-2014, 09:15 PM
RE: Another UMC side-thread - by Tcll - 12-17-2014, 11:34 PM
RE: Another UMC side-thread - by Tcll - 12-18-2014, 01:55 AM
RE: Another UMC side-thread - by Tcll - 12-27-2014, 02:57 AM
RE: Another UMC side-thread - by Struggleton! - 12-29-2014, 12:37 AM
RE: Another UMC side-thread - by Tcll - 12-29-2014, 12:43 AM
RE: Another UMC side-thread - by Tcll - 01-01-2015, 01:59 PM
RE: Another UMC side-thread - by Tcll - 01-29-2015, 12:26 AM
RE: Another UMC side-thread - by Tcll - 01-30-2015, 01:22 AM
RE: Another UMC side-thread - by Tcll - 02-14-2015, 07:02 PM
RE: Another UMC side-thread - by Tcll - 02-15-2015, 03:37 PM
RE: Another UMC side-thread - by Tcll - 02-28-2015, 09:03 AM
RE: Another UMC side-thread - by Tcll - 03-10-2015, 09:11 AM
RE: Another UMC side-thread - by Tcll - 03-22-2015, 08:59 AM
RE: Another UMC side-thread - by Tcll - 03-31-2015, 12:54 AM
RE: Another UMC side-thread - by Tcll - 04-04-2015, 09:58 PM
RE: Another UMC side-thread - by Tcll - 04-11-2015, 09:23 AM
RE: Another UMC side-thread - by Tcll - 04-14-2015, 01:19 AM
RE: Another UMC side-thread - by Manki - 04-14-2015, 07:37 PM
RE: Another UMC side-thread - by Tcll - 04-14-2015, 08:54 PM
RE: Another UMC side-thread - by Tcll - 06-14-2015, 03:43 PM
RE: Another UMC side-thread - by Tcll - 06-18-2015, 09:20 AM
RE: Another UMC side-thread - by Tcll - 06-21-2015, 09:22 AM
RE: Another UMC side-thread - by Tcll - 07-09-2015, 01:27 PM
RE: Another UMC side-thread - by Tcll - 07-09-2015, 11:43 PM
RE: Another UMC side-thread - by Tcll - 08-10-2015, 10:26 PM

Forum Jump: