Changeset - 43aa1ee8b3a9
[Not reviewed]
default
0 2 0
drewp - 22 years ago 2002-07-07 06:43:40

some comments and garbage cleanup
2 files changed with 16 insertions and 6 deletions:
0 comments (0 inline, 0 general)
light8/rsn.py
Show inline comments
 
@@ -22,94 +22,93 @@ else:
 
    window_title = "Light 8.8 (Bogus)"
 

	
 
root = Tk()
 
root.wm_title(window_title)
 
root.wm_geometry('+447+373')
 

	
 
import Subs, Patch
 

	
 
def get_data(*args):
 
    Subs.reload_data(DUMMY)
 
    Patch.reload_data(DUMMY)
 
    print "Patch:", Patch.patch
 
    print "Subs:", ', '.join(Subs.subs.keys())
 

	
 
get_data()
 

	
 
io.init(DUMMY)
 

	
 
channel_levels = []
 
scalelevels = {}
 
fades = {}
 

	
 
_oldlevels=[None] * 68
 

	
 
# this is called on a loop, and ALSO by the Scales
 
def changelevel(*args):
 
    'Amp trims slider'
 
    global _oldlevels
 

	
 
    levels = [0] * 68
 
    for name, s in Subs.subs.items():
 
        newlevels = s.get_levels(level=scalelevels[name].get())
 
        for (ch, fadelev) in newlevels.items():
 
            levels[ch-1] = max(levels[ch-1], fadelev)
 

	
 
    levels = [int(l) for l in levels]
 

	
 
    for lev,lab,oldlev in zip(levels, channel_levels, _oldlevels):
 
        if lev != oldlev:
 
            lab.config(text="%d" % lev)
 
            colorlabel(lab)
 

	
 
    _oldlevels = levels[:]
 
        
 
    io.sendlevels(levels)
 

	
 
def backgroundloop(*args):
 
    root.after(50, backgroundloop, ())
 
    changelevel()
 

	
 
buildinterface = None # temporary
 
def refresh(*args):
 
    get_data()
 
    buildinterface()
 
    bindkeys(root,'<Escape>', quit)
 

	
 
def quit(*args):
 
    filename = '/tmp/light9.prefs'
 
    if DUMMY:
 
        filename += '.dummy'
 
    print "Saving to", filename
 
    file = open(filename, 'w')
 
    cPickle.dump(Pickles(scalelevels), file)
 
    root.destroy()
 
    sys.exit()
 

	
 

	
 
xfader=Xfader(scalelevels)
 

	
 

	
 

	
 
def buildinterface(*args):
 
    global channel_levels, _oldlevels, leveldisplay, xfader
 
    for w in root.winfo_children():
 
        w.destroy()
 

	
 
    stage_tl=toplevelat(165,90)
 
    s=stage.Stage(stage_tl)
 
    stage.createlights(s)
 
    s.pack()
 

	
 
    sub_tl = toplevelat(0,0)
 
    effect_tl = toplevelat(0,352)
 

	
 
    Subpanels(sub_tl,effect_tl,scalelevels,Subs,xfader,changelevel)
 

	
 
    # def event_printer(evt):
 
        # print dir(evt)
 

	
 
    # sub_tl.bind('<b>', event_printer)
 
    leveldisplay=toplevelat(873,400)
 
    leveldisplay.bind('<Escape>', sys.exit)
 

	
 
    Leveldisplay(leveldisplay,_oldlevels,channel_levels)
 

	
 
@@ -170,28 +169,24 @@ def make_sub(name):
 
                linebuf = ''
 

	
 
            linebuf += ' "%s" : %d,' % (Patch.get_channel_name(i), l)
 
        i += 1
 
    st += linebuf + '}\n'
 
    if DUMMY:
 
        filename = 'ConfigDummy.py'
 
    else:
 
        filename = 'Config.py'
 
    f = open(filename, 'a')
 
    f.write(st)
 
    f.close()
 
    print 'Added sub:', st
 
    refresh()
 

	
 
load()
 
signal(SIGINT, quit)
 
bindkeys(root,'<Escape>', quit)
 

	
 
# bindkeys(root,'<q>', quit)
 
# bindkeys(root,'<r>', refresh)
 
# bindkeys(root,'<s>', make_sub)
 
backgroundloop()
 
root.mainloop() # Receiver switches main
 

	
 
while 1:
 
    for lev in range(0,255,25)+range(255,0,-25):
 
        sleep(.2)
light8/stage.py
Show inline comments
 
@@ -10,48 +10,62 @@ def printevent(ev):
 

	
 
textstyle={'font':'arial 7','fill':'white'}
 

	
 

	
 
class Stage(Canvas):
 
    
 
    """a fancy widget that shows light locations (and optionally their
 
    aim locations on an image of the stage. you can select or
 
    multiselect lights and drag them up or down to change their
 
    brightness.
 

	
 
    ctrl-a is select all,
 
    ctrl-shift-a or clicking on no light deselects all,
 
    re-clicking a light with shift key down toggles whether it's in the selection.
 
    ctrl-drag-rectangle deselects the lights in the rectangle,
 
    shift-drag-rectangle selects the lights in the rectangle,
 
    drag-rectangle selects only the lights in the rectangle.
 

	
 
    a light can be selected on its location point, its aim point
 
    (which may or may not be present), or its name.
 

	
 
    lights should be able to be interactively 'locked', which blocks
 
    them from being selected. 
 

	
 
    API:
 
      __init__(parent,**kw)
 
        put pass any canvas options you want
 
        
 
      setimage(stageimage)
 
        sets image to given filename (ppm, gif, etc) and resizes the canvas to the image size
 

	
 
      addlight(name, location, aim=None)
 
        location and aim are pixel coord tuples. name will be passed back to you in the callback (see below)
 

	
 
      setlightchangecb(cb)
 
        give a function which will be called like this: cb(list_of_light_names, delta)
 
      
 

	
 
    """
 
    def __init__(self,parent,**kw):
 
        Canvas.__init__(self,parent,**kw)
 

	
 
        self.bind("<ButtonPress-1>", self.leftpress)
 
        self.bind("<B1-Motion>", self.leftmotion)
 
        self.bind("<ButtonRelease-1>", self.leftrelease)
 
        
 
        self.halo=11 # search radius for clicked items
 

	
 
        self.lmbstate=None # as you perform with LMB, this goes from None to 'pressed','rectangle','levelchange'
 

	
 
        self.alllights=[]
 
        self.selectedlights=[]
 
        self.alllighttags={} # tag: name lookup
 

	
 

	
 
    def setimage(self,stageimage):
 
        img = Image('photo',file=stageimage)
 
        self.img=img # can't lose this!
 
        print img.width()
 
        self.create_image(0,0,anchor='nw',image=img)
 
        self.config(width=img.width(),height=img.height())
 
        
 
@@ -109,48 +123,49 @@ class Stage(Canvas):
 
            if not shifted and not control and len(self.selectedlights)>0:
 
                # either a deselect (if no motion) or a level change (if motion)
 
                self.lmbstate = 'deselect-or-level'
 
            if shifted or control or len(self.selectedlights)==0:
 
                # with shift/control, add/subtract lights to selection
 
                self.lmbstate='rectangle'
 

	
 
        else:
 
            # clicked a selectable object
 
            # toggle selection
 
            if touching[0] in self.selectedlights:
 
                if shifted:
 
                    # deselect
 
                    self.select(touching[0],0)
 
                    # and do nothing else
 
                    self.lmbstate=None
 
                else:
 
                    # select only this light
 
                    self.clearselection()
 
                    self.select(touching[0])
 
                    # and adjust its level
 
                    self.lmbstate='levelchange'
 
                    
 
            else:
 
                # clicked a light that wasn't selected
 
                if not shifted:
 
                    self.clearselection()
 
                self.select(touching[0])
 
                # and adjust levels now
 
                self.lmbstate='levelchange'
 
                
 
        if self.lmbstate=='rectangle':
 
            self.markfordynselection()
 
    def leftmotion(self,ev):
 

	
 
        coords=(ev.x,ev.y)
 

	
 
        shifted=ev.state & 1
 
        control=ev.state & 4
 

	
 
        if self.lmbstate=='deselect-or-level':
 
            if (coords[0]-self.lmbstart[0])**2+(coords[1]-self.lmbstart[1])**2>self.halo**2:
 
                # they moved enough, it's a level change
 
                self.lmbstate='levelchange'
 

	
 
        if self.lmbstate=='levelchange':
 
            delta = self.lmbstart[1]-ev.y
 
            print "change by",delta
 

	
0 comments (0 inline, 0 general)