Changeset - 76e326329610
[Not reviewed]
default
0 1 1
drewp@bigasterisk.com - 20 years ago 2005-06-13 03:15:10
drewp@bigasterisk.com
working on changing cursors in curvecalc. nothing to see yet
2 files changed with 39 insertions and 12 deletions:
0 comments (0 inline, 0 general)
light9/cursors.py
Show inline comments
 
new file 100644
 

	
 
import logging
 
log = logging.getLogger("cursors")
 

	
 
# accept ascii images, read file images, add hotspots, read xbm as
 
# cursor with @filename form
 

	
 
_pushed = {} # widget : [old, .., newest]
 
def push(widget,new_cursor):
 
    global _pushed
 
    _pushed.setdefault(widget,[]).append(widget.cget("cursor"))
 

	
 
def pop(widget):
 
    global _pushed
 
    try:
 
        c = _pushed[widget].pop(-1)
 
    except IndexError:
 
        log.debug("cursor pop from empty stack")
 
        return
 
    widget.config(cursor=c)
 
    
 
    
light9/curve.py
Show inline comments
 
@@ -2,13 +2,13 @@ from __future__ import division
 
import sys,math,glob,random,os
 
from bisect import bisect_left,bisect,bisect_right
 
import Tkinter as tk
 
from dispatch import dispatcher
 

	
 
import run_local
 
from light9 import Submaster, dmxclient, networking
 
from light9 import Submaster, dmxclient, networking, cursors
 
from light9.TLUtility import make_attributes_from_args
 
from light9.dmxchanedit import gradient
 

	
 
class Curve:
 
    """curve does not know its name. see Curveset"""
 
    points = None # x-sorted list of (x,y)
 
@@ -54,39 +54,42 @@ class RegionZoom:
 
    def __init__(self, canvas, world_from_screen, screen_from_world):
 
        self.canvas, self.world_from_screen = canvas, world_from_screen
 
        self.screen_from_world = screen_from_world
 

	
 
        for evtype, method in [("ButtonPress-1",self.press),
 
                               ("Motion",self.motion),
 
                               ("ButtonRelease",self.release)]:
 
                               ("ButtonRelease-1",self.release)]:
 
            canvas.bind("<Control-Alt-%s>" % evtype, method)
 
            if evtype != "ButtonPress-1":
 
                canvas.bind("<%s>" % evtype, method)
 
        canvas.bind("<Leave>", self.finish)
 
        self.start_t = None
 
        self.start_t = self.old_cursor = None
 
        self.state = None
 

	
 
    def press(self,ev):
 
        if self.start_t is not None:
 
        if self.state is not None:
 
            self.finish()
 
        self.state = "buttonpress"
 
            
 
        self.start_t = self.end_t = self.world_from_screen(ev.x,0)[0]
 
        self.start_x = ev.x
 
        can = self.canvas
 

	
 
        for pos in ('start_t','end_t','hi','lo'):
 
            can.create_line(0,0,50,50, width=3, fill='black',
 
                            tags=("regionzoom",pos))
 
        # if updatelines isn't called here, subsequent updatelines
 
        # will fail for reasons i don't understand
 
        self.updatelines()
 

	
 
        self.old_cursor = can.cget("cursor")
 
        #xcursorgen
 
        can.config(cursor="@/home/drewp/projects/light9/cout red")
 
        cursors.push(can, "@/home/drewp/projects/light9/cursor1.xbm")
 
        
 
    def updatelines(self):
 

	
 
        # better would be a gray25 rectangle over the region
 
        
 
        can = self.canvas
 
        pos_x = {}
 
        height = can.winfo_height()
 
        for pos in ('start_t', 'end_t'):
 
            pos_x[pos] = x = self.screen_from_world((getattr(self,pos),0))[0]
 
            cid = can.find_withtag("regionzoom && %s" % pos)
 
@@ -95,20 +98,20 @@ class RegionZoom:
 
        for tag,frac in [('hi',.1),('lo',.9)]:
 
            cid = can.find_withtag("regionzoom && %s" % tag)
 
            can.coords(cid, pos_x['start_t'], frac * height,
 
                       pos_x['end_t'], frac * height)
 

	
 
    def motion(self,ev):
 
        if self.start_t is None:
 
        if self.state != "buttonpress":
 
            return
 

	
 
        self.end_t = self.world_from_screen(ev.x,0)[0]
 
        self.updatelines()
 

	
 
    def release(self,ev):
 
        if self.start_t is None:
 
        if self.state != "buttonpress":
 
            return
 
        
 
        if abs(self.start_x - ev.x) < 10:
 
            # clicked
 
            factor = 1/1.5
 
            if ev.state & 1:
 
@@ -123,15 +126,17 @@ class RegionZoom:
 
        dispatcher.send("zoom to range",
 
                        start=min(self.start_t, self.end_t),
 
                        end=max(self.start_t, self.end_t))
 
        self.finish()
 
        
 
    def finish(self, *ev):
 
        self.canvas.delete("regionzoom")
 
        self.start_t = None
 
        self.canvas.config(cursor=self.old_cursor)
 
        if self.state is not None:
 
            self.state = None
 
            self.canvas.delete("regionzoom")
 
            self.start_t = None
 
            cursors.pop(self.canvas)
 

	
 
class Curveview(tk.Canvas):
 
    def __init__(self,master,curve,**kw):
 
        self.curve=curve
 
        self._time = 0
 
        tk.Canvas.__init__(self,master,width=10,height=10,
0 comments (0 inline, 0 general)