Changeset - 2c02748847f0
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 20 years ago 2005-06-05 07:28:50
drewp@bigasterisk.com
refactor gradient() from dmxchanedit
1 file changed with 7 insertions and 5 deletions:
0 comments (0 inline, 0 general)
light9/dmxchanedit.py
Show inline comments
 
@@ -8,24 +8,30 @@ from __future__ import nested_scopes,div
 
import Tkinter as tk
 
import time
 
from light9 import Patch
 
from light9.uihelpers import make_frame, colorlabel, eventtoparent
 
from dispatch import dispatcher
 

	
 
# this font makes each label take 16ms to create, so startup is slow.
 
# with default font, each labl takes about .5ms to create.
 
stdfont = ('Arial', 12)
 
import tkFont
 
# see replacement stdfont below
 

	
 

	
 
def gradient(lev, low=(80,80,180), high=(255,55,50)):
 
     out = [int(l+lev*(h-l)) for h,l in zip(high,low)]
 
     col="#%02X%02X%02X" % tuple(out)
 
     return col
 

	
 
class Onelevel(tk.Frame):
 
    """a name/level pair"""
 
    def __init__(self, parent, channelnum):
 
        """channelnum is 1..68, like the real dmx"""
 
        tk.Frame.__init__(self,parent)
 

	
 
        self.channelnum=channelnum
 
        self.currentlevel=0 # the level we're displaying, 0..1
 
        
 
        # 3 widgets, left-to-right:
 

	
 
        # channel number -- will turn yellow when being altered
 
@@ -73,29 +79,25 @@ class Onelevel(tk.Frame):
 
            for e,func in (('<ButtonPress-1>',b1down),
 
                           ('<B1-Motion>',b1motion),
 
                           ('<ButtonRelease-1>',b1up),
 
                           ('<ButtonRelease-3>', b3up),
 
                           ('<ButtonPress-3>', b3down)):
 
                w.bind(e,func)
 
#                w.bind(e,lambda ev,e=e: eventtoparent(ev,e))
 
        
 
    def colorlabel(self):
 
        """color the level label based on its own text (which is 0..100)"""
 
        txt=self.level_lab['text'] or "0"
 
        lev=float(txt)/100
 
        low=(80,80,180)
 
        high=(255,55,050)
 
        out = [int(l+lev*(h-l)) for h,l in zip(high,low)]
 
        col="#%02X%02X%02X" % tuple(out)
 
        self.level_lab.config(bg=col)
 
        self.level_lab.config(bg=gradient(lev))
 

	
 
    def setlevel(self,newlev):
 
        """the main program is telling us to change our
 
        display. newlev is 0..1"""
 
        self.currentlevel=newlev
 
        newlev="%d"%(newlev*100)
 
        olddisplay=self.level_lab.cget('text')
 
        if newlev!=olddisplay:
 
            self.level_lab.config(text=newlev)
 
            self.colorlabel()
 

	
 
    def getlevel(self):
0 comments (0 inline, 0 general)