[SCM] calf/master: More jackvis cleaning.

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:40:15 UTC 2013


The following commit has been merged in the master branch:
commit 91ab970feb821a6dc0a042a041e0f1e0ec1f5292
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Wed May 12 20:48:15 2010 +0100

    More jackvis cleaning.
    
    * Move more wire code from Graph to its own class
    * Make JACKGraphParser more like a proper controller
    * Use different canvas items for permanent and temporary wires

diff --git a/bigbull/conndiagram.py b/bigbull/conndiagram.py
index 8b74a9e..ddd9fa2 100644
--- a/bigbull/conndiagram.py
+++ b/bigbull/conndiagram.py
@@ -41,16 +41,28 @@ class Colors:
     connectedWire = 0x808080FF
 
 class VisibleWire():
-    def __init__(self, src, dest, wire):
-        """src is source PortView, dst is destination PortView, wire is a goocanvas.Path"""
+    def __init__(self, src, dest):
+        """src is source PortView, dst is destination PortView"""
         self.src = src
         self.dest = dest
-        self.wire = wire
+        self.wire = goocanvas.Path(parent = src.get_graph().get_root())
+        self.wire.type = "wire"
+        self.wire.object = self
+        self.wire.props.stroke_color_rgba = Colors.connectedWire
+        self.update_shape()
+    
     def delete(self):
         self.wire.remove()
         self.src.module.remove_wire(self)
         self.dest.module.remove_wire(self)
 
+    def update_shape(self):
+        (x1, y1) = self.src.get_endpoint()
+        (x2, y2) = self.dest.get_endpoint()
+        xm = (x1 + x2) / 2
+        self.wire.props.data = "M %0.0f,%0.0f C %0.0f,%0.0f %0.0f,%0.0f %0.0f,%0.0f" % (x1, y1, xm, y1, xm, y2, x2, y2)
+        
+
 def path_move(x, y):
     return "M %s %s " % (x, y)
     
@@ -114,16 +126,12 @@ class Dragging():
         src, dst = self.port_view, self.connect_candidate
         self.get_graph().dragging = None
         src.update_style()
+        self.remove_wire()
         if dst is not None:
             # print "Connect: " + tuple[1] + " with " + self.connect_candidate.get_id()
             dst.update_style()
-            try:
-                self.get_graph().connect(src, dst, self.drag_wire)
-            except:
-                self.remove_wire()
-                raise
-        else:
-            self.remove_wire()
+            self.get_graph().get_parser().connect(src.model, dst.model)
+            self.get_graph().connect(src, dst)
     
     def remove_wire(self):
         self.drag_wire.remove()
@@ -162,7 +170,7 @@ class PortView():
         module = self.module
         (width, margin, spacing) = (module.width, module.margin, module.spacing)
         al = "left"
-        portName = self.get_parser().get_port_name(self.model)
+        portName = self.model.get_name()
         title = goocanvas.Text(parent = parent, text = portName, font = self.fontName, width = width - 2 * margin, x = margin, y = y, alignment = al, fill_color_rgba = Colors.text, hint_metrics = cairo.HINT_METRICS_ON, pointer_events = False, wrap = False)
         height = 1 + int(title.get_requested_height(ctx, width - 2 * margin))
         title.ensure_updated()
@@ -212,13 +220,13 @@ class ModuleView():
     spacing = 4
     fontName = "DejaVu Sans Bold 9"
 
-    def __init__(self, parser, parent, moduleData, graph):
+    def __init__(self, parser, parent, model, graph):
         self.parser = parser
         self.graph = graph
         self.group = None
         self.connect_candidate = None
         self.parent = parent
-        self.moduleData = moduleData
+        self.model = model
         self.group = goocanvas.Group(parent = self.parent)
         self.wires = []
         self.create_items()
@@ -231,17 +239,17 @@ class ModuleView():
         while self.group.get_n_children() > 0:
             self.group.remove_child(0)
         ctx = self.group.get_canvas().create_cairo_context()
-        self.title = self.get_parser().get_module_name(self.moduleData)
+        self.title = self.model.get_name()
         self.portDict = {}
         width = self.get_title_width(ctx)
-        for (id, model) in self.get_parser().get_module_port_list(self.moduleData):
+        for (id, model) in self.model.get_port_list():
             mport = self.create_port(id, model)
             new_width = mport.calc_width(ctx)
             if new_width > width:
                 width = new_width
         self.width = width
         y = self.render_title(ctx, 0.5)
-        for (id, model) in self.get_parser().get_module_port_list(self.moduleData):
+        for (id, model) in self.model.get_port_list():
             y = self.render_port(ctx, id, y)
         self.rect = goocanvas.Rect(parent = self.group, x = 0.5, width = self.width, height = y, line_width = 1, stroke_color_rgba = Colors.frame, fill_color_rgba = Colors.box, antialias = cairo.ANTIALIAS_GRAY)
         self.rect.lower(self.titleItem)
@@ -283,7 +291,7 @@ class ModuleView():
             
     def update_wires(self):
         for wire in self.wires:
-            self.graph.update_wire(wire)
+            wire.update_shape()
             
     def remove_wire(self, wire):
         self.wires = [w for w in self.wires if w != wire]
@@ -344,8 +352,8 @@ class ConnectionGraphEditor:
     def add_module_cb(self, params):
         self.add_module(*params)
 
-    def add_module(self, moduleData, x, y):
-        mbox = ModuleView(self.parser, self.canvas.get_root_item(), moduleData, self)
+    def add_module(self, model, x, y):
+        mbox = ModuleView(self.parser, self.canvas.get_root_item(), model, self)
         self.modules.add(mbox)
         bounds = self.canvas.get_bounds()
         if x == None:
@@ -391,12 +399,7 @@ class ConnectionGraphEditor:
             self.moving.translate(event.x - self.motion_x, event.y - self.motion_y)
             group.module.update_wires()
                         
-    def update_wire(self, wire):
-        (x1, y1) = wire.src.get_endpoint()
-        (x2, y2) = wire.dest.get_endpoint()
-        xm = (x1 + x2) / 2
-        wire.wire.props.data = "M %0.0f,%0.0f C %0.0f,%0.0f %0.0f,%0.0f %0.0f,%0.0f" % (x1, y1, xm, y1, xm, y2, x2, y2)
-        
+    # Connect elements visually (but not logically, that's what controller/parser is for)
     def connect(self, p1, p2, wireitem = None):
         # p1, p2 are PortView objects
         # if wireitem is set, then this is manual connection, and parser.connect() is called
@@ -405,17 +408,9 @@ class ConnectionGraphEditor:
             (src, dest) = (p1, p2)
         else:
             (dest, src) = (p1, p2)
-        if wireitem == None:
-            wireitem = goocanvas.Path(parent = self.canvas.get_root_item())
-        else:
-            self.get_parser().connect(src.model, dest.model)
-        wire = VisibleWire(src, dest, wireitem)
-        wireitem.type = "wire"
-        wireitem.object = wire
-        wireitem.props.stroke_color_rgba = Colors.connectedWire
+        wire = VisibleWire(src, dest)
         src.module.wires.append(wire)
         dest.module.wires.append(wire)
-        self.update_wire(wire)
         
     def seg_distance(self, min1, max1, min2, max2):
         if min1 > min2:
diff --git a/bigbull/jackvis.py b/bigbull/jackvis.py
index f18efc3..eab24c9 100755
--- a/bigbull/jackvis.py
+++ b/bigbull/jackvis.py
@@ -46,6 +46,8 @@ class JACKClientInfo(object):
         self.id = id
         self.name = name
         self.ports = [JACKPortInfo("%s:%s" % (name, p[1]), *p) for p in ports]
+    def get_name(self):
+        return self.name
     
 class JACKGraphInfo(object):
     version = 0
@@ -86,13 +88,8 @@ class JACKGraphParser(object):
         return portData.get_name()
     def get_port_id(self, portData):
         return portData.get_full_name()
-    def get_module_name(self, moduleData):
-        return moduleData.name
     def fetch_graph(self):
         self.graph = JACKGraphInfo(*self.patchbay.GetGraph(self.graph.known_version if self.graph is not None else 0))
-    def get_module_port_list(self, moduleData):
-        g = self.graph.client_map[moduleData.name]
-        return [(port.get_full_name(), port) for port in g.ports if moduleData.checker(port)]
     def can_connect(self, first, second):
         if self.is_port_input(first) == self.is_port_input(second):
             return False
@@ -108,9 +105,13 @@ class JACKGraphParser(object):
         second = name_second.split(":", 1)
         self.patchbay.DisconnectPortsByName(first[0], first[1], second[0], second[1])
         
-class ClientBoxInfo():
-    def __init__(self, name, checker):
-        (self.name, self.checker) = (name, checker)
+class ClientModuleModel():
+    def __init__(self, client, checker):
+        (self.client, self.checker) = (client, checker)
+    def get_name(self):
+        return self.client.get_name()
+    def get_port_list(self):
+        return [(port.get_full_name(), port) for port in self.client.ports if self.checker(port)]
 
 class App:
     def __init__(self):
@@ -169,7 +170,7 @@ class App:
         margin = 10
         mwidth = 0
         for cl in self.parser.graph.clients:
-            mod = self.cgraph.add_module(ClientBoxInfo(cl.name, checker), x, y)
+            mod = self.cgraph.add_module(ClientModuleModel(cl, checker), x, y)
             y += mod.rect.props.height + margin
             if mod.rect.props.width > mwidth:
                 mwidth = mod.rect.props.width

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list