Changeset - 0b8fc64a896c
[Not reviewed]
default
0 3 0
Drew Perttula - 13 years ago 2012-06-08 07:54:32
drewp@bigasterisk.com
goocanvas drawing a little
Ignore-this: aae191151f454a98caa671b65d080029
3 files changed with 29 insertions and 15 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -48,32 +48,32 @@ def makeGraph():
 
class Main(object):
 
    def __init__(self, graph, opts, song, curveset, subterms):
 
        self.graph = graph
 
        wtree = gtk.Builder()
 
        wtree.add_from_file(sibpath(__file__, "../light9/curvecalc/curvecalc.glade"))
 
        mainwin = wtree.get_object("MainWindow")
 
        mainwin.connect("destroy", gtk.main_quit)
 
        wtree.connect_signals(self)
 
        mainwin.show_all()
 

	
 
        mainwin.connect("delete-event", lambda *args: reactor.crash())
 
        mainwin.set_title("curvecalc - %s" % graph.label(song))
 
        mainwin.parse_geometry("1000x1000")
 
        
 
        self.add_subterms_for_song(song, curveset, subterms,
 
                                   wtree.get_object("subterms")
 
                                   )
 

	
 

	
 
        curvesetView = Curvesetview(wtree.get_object("curves"), curveset)
 
        self.curvesetView = curvesetView # mem problem; don't let this get lost
 

	
 
        # curvesetview must already exist, since this makes 'add_curve'
 
        # signals for all the initial curves
 
        curveset.load(basename=os.path.join(
 
            showconfig.curvesDir(),
 
            showconfig.songFilenameFromURI(song)),
 
                      skipMusic=opts.skip_music)
 
        # this is scheduled after some tk shuffling, to try to minimize
 
        # the number of times we redraw the curve at startup. If tk is
 
        # very slow, it's ok. You'll just get some wasted redraws.
 
        curvesetView.goLive()
 
        
light9/curvecalc/curvecalc.glade
Show inline comments
 
<?xml version="1.0" encoding="UTF-8"?>
 
<interface>
 
  <!-- interface-requires gtk+ 3.0 -->
 
  <object class="GtkWindow" id="MainWindow">
 
    <property name="width_request">530</property>
 
    <property name="height_request">380</property>
 
    <property name="can_focus">False</property>
 
    <child>
 
      <object class="GtkVBox" id="vbox1">
 
        <property name="visible">True</property>
 
        <property name="can_focus">False</property>
 
        <child>
 
          <object class="GtkMenuBar" id="menubar1">
 
            <property name="visible">True</property>
 
            <property name="can_focus">False</property>
 
            <child>
 
              <object class="GtkMenuItem" id="menuitem1">
 
                <property name="use_action_appearance">False</property>
 
@@ -201,29 +199,30 @@
 
                </child>
 
              </object>
 
            </child>
 
          </object>
 
          <packing>
 
            <property name="expand">False</property>
 
            <property name="fill">True</property>
 
            <property name="position">0</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkVPaned" id="paned1">
 
            <property name="height_request">200</property>
 
            <property name="height_request">600</property>
 
            <property name="visible">True</property>
 
            <property name="can_focus">True</property>
 
            <child>
 
              <object class="GtkExpander" id="expander2">
 
                <property name="height_request">400</property>
 
                <property name="visible">True</property>
 
                <property name="can_focus">True</property>
 
                <property name="expanded">True</property>
 
                <child>
 
                  <object class="GtkVBox" id="vbox4">
 
                    <property name="height_request">100</property>
 
                    <property name="visible">True</property>
 
                    <property name="can_focus">False</property>
 
                    <child>
 
                      <object class="GtkHBox" id="hbox9">
 
                        <property name="visible">True</property>
 
                        <property name="can_focus">False</property>
 
@@ -302,24 +301,25 @@
 
                    <property name="can_focus">False</property>
 
                    <property name="label" translatable="yes">Curves</property>
 
                  </object>
 
                </child>
 
              </object>
 
              <packing>
 
                <property name="resize">False</property>
 
                <property name="shrink">True</property>
 
              </packing>
 
            </child>
 
            <child>
 
              <object class="GtkExpander" id="expander1">
 
                <property name="height_request">120</property>
 
                <property name="visible">True</property>
 
                <property name="can_focus">True</property>
 
                <property name="expanded">True</property>
 
                <child>
 
                  <object class="GtkVBox" id="box1">
 
                    <property name="visible">True</property>
 
                    <property name="can_focus">False</property>
 
                    <child>
 
                      <object class="GtkScrolledWindow" id="scrolledwindow2">
 
                        <property name="visible">True</property>
 
                        <property name="can_focus">True</property>
 
                        <property name="vscrollbar_policy">always</property>
 
@@ -362,24 +362,30 @@
 
                                <child>
 
                                  <placeholder/>
 
                                </child>
 
                                <child>
 
                                  <placeholder/>
 
                                </child>
 
                                <child>
 
                                  <placeholder/>
 
                                </child>
 
                                <child>
 
                                  <placeholder/>
 
                                </child>
 
                                <child>
 
                                  <placeholder/>
 
                                </child>
 
                                <child>
 
                                  <placeholder/>
 
                                </child>
 
                              </object>
 
                            </child>
 
                          </object>
 
                        </child>
 
                      </object>
 
                      <packing>
 
                        <property name="expand">True</property>
 
                        <property name="fill">True</property>
 
                        <property name="position">0</property>
 
                      </packing>
 
                    </child>
 
                    <child>
 
@@ -481,24 +487,30 @@
 
                    <child>
 
                      <placeholder/>
 
                    </child>
 
                    <child>
 
                      <placeholder/>
 
                    </child>
 
                    <child>
 
                      <placeholder/>
 
                    </child>
 
                    <child>
 
                      <placeholder/>
 
                    </child>
 
                    <child>
 
                      <placeholder/>
 
                    </child>
 
                    <child>
 
                      <placeholder/>
 
                    </child>
 
                  </object>
 
                </child>
 
                <child type="label">
 
                  <object class="GtkLabel" id="label1">
 
                    <property name="visible">True</property>
 
                    <property name="can_focus">False</property>
 
                    <property name="label" translatable="yes">Status</property>
 
                    <property name="use_markup">True</property>
 
                  </object>
 
                </child>
 
              </object>
 
              <packing>
light9/curvecalc/curveview.py
Show inline comments
 
@@ -66,45 +66,47 @@ class Sketch:
 
                self.curveview.add_point(p)
 
            
 
        self.curveview.update_curve()
 

	
 
class Curveview(object):
 
    """
 
    graphical curve widget only. Please pack .widget
 
    """
 
    def __init__(self, curve, knobEnabled=False, isMusic=False, **kw):
 
        """knobEnabled=True highlights the previous key and ties it to a
 
        hardware knob"""
 
        self.widget = goocanvas.Canvas()
 
        self.widget.set_property("background-color", "black")
 
        self.widget.set_size_request(-1, 130)
 
        self.root = self.widget.get_root_item()
 

	
 
        self.redrawsEnabled = False
 
        self.curve = curve
 
        self.knobEnabled = knobEnabled
 
        self._isMusic = isMusic
 
        self._time = 0
 
        self.last_mouse_world = None
 
        self.selected_points=[] # idx of points being dragged
 
        # self.bind("<Enter>",self.focus)
 
        dispatcher.connect(self.input_time, "input time")
 
        dispatcher.connect(self.update_curve, "zoom changed")
 
        dispatcher.connect(self.update_curve, "points changed",
 
                           sender=self.curve)
 
        dispatcher.connect(self.update_curve, "mute changed", 
 
                           sender=self.curve)
 
        dispatcher.connect(self.select_between, "select between")
 
        if self.knobEnabled:
 
            dispatcher.connect(self.knob_in, "knob in")
 
            dispatcher.connect(self.slider_in, "set key")
 
        print "setup alloc", self.__dict__
 

	
 
        self.widget.connect("size-allocate", self.update_curve)
 
        if 0:
 

	
 
            for x in range(1, 6):
 
                def add_kb_marker_point(evt, x=x):
 
                    self.add_point((self.current_time(), (x - 1) / 4.0))
 

	
 
                self.bind("<Key-%s>" % x, add_kb_marker_point)
 

	
 

	
 
            for butnum,factor in (5, 1.5),(4, 1/1.5):
 
                def onMouseWheel(ev,factor=factor):
 
@@ -274,26 +276,25 @@ class Curveview(object):
 
        if self.knobEnabled:
 
            self.delete('knob')
 
            prevKey = self.curve.point_before(t)
 
            if prevKey is not None:
 
                pos = self.screen_from_world(prevKey)
 
                self.create_oval(pos[0] - 8, pos[1] - 8,
 
                                 pos[0] + 8, pos[1] + 8,
 
                                 outline='#800000',
 
                                 tags=('knob',))
 
                dispatcher.send("knob out", value=prevKey[1], curve=self.curve)
 
        
 
    def update_curve(self, _widget=None, _rect=None):
 
        print "update curve on", self, id(self), self.__dict__
 
        if not getattr(self, 'redrawsEnabled', False):
 
        if not self.redrawsEnabled:
 
            return
 
        self.size = self.widget.get_allocation()
 

	
 
        self.zoom = 0, 3#dispatcher.send("zoom area")[0][1]
 
        cp = self.curve.points
 

	
 
        visible_x = (self.world_from_screen(0,0)[0],
 
                     self.world_from_screen(self.size.width, 0)[0])
 

	
 
        visible_idxs = self.curve.indices_between(visible_x[0], visible_x[1],
 
                                                  beyond=1)
 
        visible_points = [cp[i] for i in visible_idxs]
 
@@ -349,71 +350,72 @@ class Curveview(object):
 
                startColor = color
 

	
 
        if startColor is not None:
 
            self._draw_gradient_slice(startX, self.size.width, startColor)
 
            rects += 1
 
        log.debug("redraw %s rects in %.02f ms", rects, 1000 * (time.time()-t1))
 

	
 
    def _draw_gradient_slice(self, x1, x2, color):
 
        self.create_rectangle(x1, 0, x2, 40,
 
                              fill=color, width=0, tags='curve')        
 

	
 
    def _draw_markers(self,visible_x):
 
        return
 
        mark = self._draw_one_marker
 

	
 
        mark(0,"0")
 
        t1,t2=visible_x
 
        if t2-t1<30:
 
            for t in range(int(t1),int(t2)+1):
 
                mark(t,str(t))
 
        mark(introPad, str(introPad))
 

	
 
        endtimes = dispatcher.send("get max time")
 
        if endtimes:
 
            endtime = endtimes[0][1]
 
            mark(endtime,"end %.1f"%endtime)
 
            mark(endtime - postPad, "post %.1f" % (endtime - postPad))
 
        
 
    def _draw_one_marker(self,t,label):
 
        x = self.screen_from_world((t,0))[0]
 
        ht = self.size.height
 
        if not 0 <= x < self.size.width:
 
            return
 
        x = max(5, x) # cheat left-edge stuff onscreen
 
        self.create_line(x, ht,
 
        goocanvas.polyline_new_line(self.curveGroup,
 
                                    x, ht,
 
                         x, ht - 20,
 
                         fill='white', tags=('curve',))
 
        self.create_text(x, ht-20, text=label, anchor='s', fill='white',
 
                         font="arial 7", tags=('curve',))
 

	
 
                                    stroke_color='white')
 
        goocanvas.Text(parent=self.curveGroup,
 
                       fill_color="white",
 
                       x=x, y=ht-20,
 
                       text=label)
 

	
 
    def _draw_line(self,visible_points):
 
        linepts=[]
 
        step=1
 
        linewidth=2
 
        # 800? maybe this should be related to self.width
 
        if len(visible_points)>800:
 
            step = int(len(visible_points)/800)
 
            linewidth=1
 
        for p in visible_points[::step]:
 
            linepts.append(self.screen_from_world(p))
 
        if len(linepts)<4:
 
            return
 
        if self.curve.muted:
 
            fill = 'grey34'
 
        else:
 
            fill = 'white'
 

	
 
        goocanvas.Polyline(parent=self.curveGroup,
 
        self.pl = goocanvas.Polyline(parent=self.curveGroup,
 
                           points=goocanvas.Points(linepts),
 
                           width=linewidth,
 
                           stroke_color=fill,
 
                           )
 
            
 
        # canvas doesnt have keyboard focus, so i can't easily change the
 
        # cursor when ctrl is pressed
 
        #        def curs(ev):
 
        #            print ev.state
 
        #        self.bind("<KeyPress>",curs)
 
        #        self.bind("<KeyRelease-Control_L>",lambda ev: curs(0))
 
        if 0:
 
@@ -688,22 +690,22 @@ class Curvesetview(object):
 
        dispatcher.connect(focus_entry, "focus new curve", weak=False)
 

	
 
    def new_curve(self, event):
 
        self.curveset.new_curve(self.newcurvename.get())
 
        self.newcurvename.set('')
 
        
 
    def add_curve(self, name, slider=None, knobEnabled=False):
 
        curve = self.curveset.curves[name]
 
        f = CurveRow(name, curve, slider, knobEnabled)
 
        self.curvesVBox.pack_end(f.box)
 
        f.box.show_all()
 
        self.allCurveRows.add(f)
 
        f.curveView.goLive()
 
        #f.curveView.goLive()
 

	
 

	
 
    def goLive(self):
 
        """for startup performance, none of the curves redraw
 
        themselves until this is called once (and then they're normal)"""
 
        
 
        for cr in self.allCurveRows:
 
            cr.curveView.goLive()
 

	
0 comments (0 inline, 0 general)