Changeset - 0bf7e664f913
[Not reviewed]
default
0 3 0
dmcc - 22 years ago 2002-07-09 09:27:47

window pos saving
3 files changed with 45 insertions and 12 deletions:
0 comments (0 inline, 0 general)
light8/Lightboard.py
Show inline comments
 
from __future__ import nested_scopes
 

	
 
from Tix import *
 
from time import sleep
 
from signal import signal, SIGINT
 
import sys, cPickle
 
import shelve
 

	
 
import io
 
from uihelpers import *
 
from panels import *
 
from Xfader import *
 
from subediting import Subediting
 
from Fader import Fader
 
import stage
 
import Subs, Patch
 

	
 
class Pickles:
 
    def __init__(self, scalelevels, subs=None):
 
    def __init__(self, scalelevels, subs=None, windowpos=None):
 
        self.scalelevels = dict([(name, lev.get()) 
 
            for name, lev in scalelevels.items()])
 
        self.substate = dict([(name, subobj.get_state())
 
            for name, subobj in subs])
 
        # print "substate", self.substate 
 
        self.windowpos = windowpos
 

	
 
class Lightboard:
 
    def __init__(self, master, parportdmx, DUMMY):
 
        self.master = master
 
        self.parportdmx = parportdmx
 
        self.DUMMY = DUMMY
 

	
 
        self.channel_levels = []
 
        self.scalelevels = {}
 
        self.xfader = Xfader(self.scalelevels) # doesn't draw any UI yet-- look for self.xfader.setupwidget()
 
        self.oldlevels = [None] * 68 # never replace this; just clear it
 
        self.subediting = Subediting(currentoutputlevels=self.oldlevels)
 

	
 
        self.shelf = shelve.open('/tmp/light9.newprefs')
 
        self.windowpos = self.shelf.get('window', {})
 
        self.get_data()
 
        self.buildinterface()
 
        self.load()
 
        self.backgroundloop()
 
        self.updatestagelevels()
 
        
 
    def buildinterface(self):
 
        for w in self.master.winfo_children():
 
            w.destroy()
 

	
 
        stage_tl = toplevelat(22,30)
 
        stage_tl = toplevelat('stage', self.windowpos)
 
        s = stage.Stage(stage_tl)
 
        stage.createlights(s)
 
        s.setsubediting(self.subediting)
 
        s.pack()
 
        self.stage = s # save it
 

	
 
        sub_tl = toplevelat(0,0,w=440,h=610)
 
        effect_tl = toplevelat(462,4)
 
        sub_tl = toplevelat('sub', self.windowpos)
 
        effect_tl = toplevelat('effect', self.windowpos)
 

	
 
        self.subpanels = Subpanels(sub_tl, effect_tl, self, self.scalelevels,
 
                                   Subs, self.xfader, self.changelevel,
 
                                   self.subediting, Subs.longestsubname())
 

	
 
        leveldisplay_tl = toplevelat(873,400)
 
        leveldisplay_tl = toplevelat('leveldisplay', self.windowpos)
 
        leveldisplay_tl.bind('<Escape>', sys.exit)
 

	
 
        self.leveldisplay = Leveldisplay(leveldisplay_tl, self.channel_levels)
 
        for i in range(0,len(self.channel_levels)):
 
            self.channel_levels[i].config(text=self.oldlevels[i])
 
            colorlabel(self.channel_levels[i])
 

	
 
        Console(self)
 

	
 
        # root frame
 
        controlpanel = Controlpanel(self.master, self.xfader, self.refresh, self.quit)
 
        
 
        xf=Frame(self.master)
 
        xf.pack(side='right')
 

	
 
        self.master.bind('<q>', self.quit)
 
        self.master.bind('<r>', self.refresh)
 
        leveldisplay_tl.bind('<q>', self.quit)
 
        leveldisplay_tl.bind('<r>', self.refresh)
 

	
 
        self.xfader.setupwidget(xf)
 
        controlpanel.pack()
 

	
 
        cuefader_tl = toplevelat(78, 480)
 
        cuefader_tl = toplevelat('cuefader', self.windowpos)
 
        cuefader = Fader(cuefader_tl, Subs.cues, self.scalelevels)
 
        cuefader.pack()
 

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

	
 
    def refresh(self, *args):
 
        'rebuild interface, reload data'
 
        self.get_data()
 
@@ -190,21 +193,42 @@ class Lightboard:
 
            print "EOFrror: Couldn't load prefs (%s): %s" % (filename,e)
 
        except Exception,e:
 
            print "Couldn't load prefs (%s): %s" % (filename,e)
 

	
 
    def backgroundloop(self, *args):
 
        self.master.after(50, self.backgroundloop, ())
 
        self.changelevel()
 
    def quit(self, *args):
 
        self.save()
 
        self.master.destroy()
 
        sys.exit()
 
    def save(self, *args):
 

	
 

	
 
        filename = '/tmp/light9.prefs'
 
        if self.DUMMY:
 
            filename += '.dummy'
 
        print "Saving to", filename
 
        file = open(filename, 'w')
 

	
 
        # {name : (tkname, geom)}
 
        windowitems = self.windowpos.items()
 
        windowmapping = dict([(pair[0], name) for name, pair in windowitems])
 
        # print "windowmapping", windowmapping
 
        # print "windowpos", self.windowpos
 

	
 
        for w in self.master.winfo_children():
 
            tkname, geom = str(w), w.winfo_geometry()
 
            try:
 
                name = windowmapping[tkname]
 
                self.windowpos[name] = (tkname, geom)
 
                # print name, "geom is", geom
 
            except:
 
                # print "failed to save windowpos"
 
                pass
 
        self.shelf['window'] = self.windowpos
 
        self.shelf.close()
 

	
 
        try:
 
            cPickle.dump(Pickles(self.scalelevels, Subs.subs.items()), file)
 
        except cPickle.UnpickleableError:
 
            print "UnpickleableError!  There's yer problem."
light8/panels.py
Show inline comments
 
@@ -19,25 +19,25 @@ class Controlpanel(Frame):
 
            ('Refresh',    refresh_cb),
 
            ('Clear all', xfader.clearallbuttons),
 
            ('On -> X',     lambda: xfader.grab('x')),
 
            ('Clear X',     lambda: xfader.clearallbuttons('x')),
 
            ('On -> Y',     lambda: xfader.grab('y')),
 
            ('Clear Y',     lambda: xfader.clearallbuttons('y'))):
 
            Button(controlpanel, text=txt, command=cmd).pack(side='top', 
 
                fill='x')
 

	
 
class Console:
 
    def __init__(self,lightboard):
 
        print "Light 8: Everything's under control"
 
        t=toplevelat(267,717,w=599,h=19)
 
        t=toplevelat('console', lightboard.windowpos)
 
        self.frame = Frame(t)
 
        self.entry=Entry(self.frame)
 
        self.entry.pack(expand=1, fill='x')
 
        self.entry.bind('<Return>',
 
                        lambda evt: self.execute(evt, self.entry.get()))
 
        self.frame.pack(fill=BOTH, expand=1)
 
        self.lightboard=lightboard
 
    
 
    def execute(self, evt, str):
 
        if str[0] == '*': # make a new sub from the current levels
 
            self.lightboard.save_sub(str,self.lightboard.stageassub())
 
        else:
light8/uihelpers.py
Show inline comments
 
@@ -6,30 +6,39 @@ from Tix import *
 
from types import StringType
 

	
 
def make_frame(parent):
 
    f = Frame(parent, bd=0)
 
    f.pack(side='left')
 
    return f
 

	
 
def bindkeys(root,key, func):
 
    root.bind(key, func)
 
    for w in root.winfo_children():
 
        w.bind(key, func)
 

	
 
def toplevelat(x,y,w=None,h=None):
 
# def toplevelat(x,y,w=None,h=None):
 
def toplevelat(name, windowpos):
 
    tl = Toplevel()
 
    if w and h:
 
        tl.wm_geometry("%dx%d+%d+%d" % (w,h,x,y))
 

	
 
    if name in windowpos:
 
        tkname, geom = windowpos[name]
 
        tl.wm_geometry(geom)
 
        windowpos[name] = str(tl), geom
 
    else:
 
        tl.wm_geometry("+%d+%d" % (x,y))
 
        windowpos[name] = str(tl), '+0+0'
 

	
 
    # if w and h:
 
        # tl.wm_geometry("%dx%d+%d+%d" % (w,h,x,y))
 
    # else:
 
        # tl.wm_geometry("+%d+%d" % (x,y))
 
    return tl
 

	
 
def toggle_slider(s):
 
    if s.get() == 0:
 
        s.set(100)
 
    else:
 
        s.set(0)
 

	
 
# for lambda callbacks    
 
def printout(t):
 
    print t
 

	
0 comments (0 inline, 0 general)