[SCM] calf/master: + Big Bull: added parsing of _:name, minor refactoring, initial work on wires (mouse dragging support only)

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


The following commit has been merged in the master branch:
commit 4fbceb73969d496948b9fb1dbc53bd3477bb2668
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date:   Fri Jul 4 23:22:48 2008 +0000

    + Big Bull: added parsing of _:name, minor refactoring, initial work on wires (mouse dragging support only)
    
    
    git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@224 78b06b96-2940-0410-b7fc-879d825d01d8

diff --git a/bigbull/lv2.py b/bigbull/lv2.py
index 3a35b37..a09591e 100644
--- a/bigbull/lv2.py
+++ b/bigbull/lv2.py
@@ -140,6 +140,8 @@ def parseTTL(uri, content, model, debug):
             prnot = x[1].split(":")
             if item != 0 and spo[0] == "@prefix":
                 spo[item] = x[1]
+            elif prnot[0] == "_":
+                spo[item] = uri + "#" + prnot[1]
             else:
                 spo[item] = prefixes[prnot[0]] + prnot[1]
             item += 1
diff --git a/bigbull/mainwin.py b/bigbull/mainwin.py
index f1f8833..ca46fde 100755
--- a/bigbull/mainwin.py
+++ b/bigbull/mainwin.py
@@ -9,9 +9,31 @@ import cairo
 import goocanvas
 import random
 
+def add_option(menu, option, handler, data = None):
+    item = gtk.MenuItem(option)
+    item.connect_object("activate", handler, data)
+    menu.add(item)
+
+def add_submenu(menu, option):
+    submenu = gtk.Menu()
+    item = gtk.MenuItem(option)
+    menu.append(item)
+    item.set_submenu(submenu)
+    return submenu
+        
+class Colors:
+    frame = 0xC0C0C0FF
+    text = 0xFFFFFFFF
+    box = 0x202020FF
+    defPort = 0x404040FF
+    audioPort = 0x000080FF
+    controlPort = 0x008000FF
+    eventPort = 0x800000FF
+
 class ModuleBox():
-    def __init__(self, parent, plugin):
+    def __init__(self, parent, plugin, graph):
         self.width = 200
+        self.graph = graph
         self.group = None
         self.parent = parent
         self.plugin = plugin
@@ -29,9 +51,8 @@ class ModuleBox():
         spacing = 6
         portBoxes = {}
         portTitles = {}
-        frameColor = 0xC0C0C0FF
-        textColor = 0xFFFFFFFF
-        self.title = goocanvas.Text(parent = self.group, font = fontName, text = "<b>" + self.plugin.name + "</b>", width = 100, x = 0, y = 0, alignment = "center", use_markup = True, fill_color_rgba = textColor)
+        portData = {}
+        self.title = goocanvas.Text(parent = self.group, font = fontName, text = "<b>" + self.plugin.name + "</b>", width = 100, x = 0, y = 0, alignment = "center", use_markup = True, fill_color_rgba = Colors.text)
         y = self.title.get_requested_height(ctx, width) + spacing
         for port in self.plugin.ports:
             al = "center"
@@ -39,72 +60,82 @@ class ModuleBox():
                 al = "left"
             elif port.isOutput:
                 al = "right"
-            title = goocanvas.Text(parent = self.group, text = port.name, font = fontName, width = width - 2 * margin, x = margin, y = y, alignment = al, fill_color_rgba = textColor)
+            title = goocanvas.Text(parent = self.group, text = port.name, font = fontName, width = width - 2 * margin, x = margin, y = y, alignment = al, fill_color_rgba = Colors.text)
             height = 1 + int(title.get_requested_height(ctx, width - 2 * margin))
             title.ensure_updated()
             bnds = title.get_bounds()
             bw = bnds.x2 - bnds.x1 + 2 * margin
-            color = 0x404040FF
+            color = Colors.defPort
             if port.isAudio:
-                color = 0x000080FF
+                color = Colors.audioPort
             if port.isControl:
-                color = 0x008000FF
+                color = Colors.controlPort
             if port.isEvent:
-                color = 0x800000FF
+                color = Colors.eventPort
             if port.isInput:
-                box = goocanvas.Rect(parent = self.group, x = 0, y = y - 1, width = bw, height = height + 2, line_width = 1, fill_color_rgba = color, stroke_color_rgba = frameColor)
+                box = goocanvas.Rect(parent = self.group, x = 0, y = y - 1, width = bw, height = height + 2, line_width = 1, fill_color_rgba = color, stroke_color_rgba = Colors.frame)
             elif port.isOutput:
-                box = goocanvas.Rect(parent = self.group, x = bnds.x2 - margin, y = y - 1, width = width - bnds.x2 + margin, height = height + 2, line_width = 1, fill_color_rgba = color, stroke_color_rgba = frameColor)
+                box = goocanvas.Rect(parent = self.group, x = bnds.x2 - margin, y = y - 1, width = width - bnds.x2 + margin, height = height + 2, line_width = 1, fill_color_rgba = color, stroke_color_rgba = Colors.frame)
+            else:
+                continue
             box.lower(title)
             y += height + spacing
             portBoxes[port.uri] = box
             portTitles[port.uri] = title
+            portData[port.uri] = port
             box.uri = port.uri
             box.connect_object("button-press-event", self.port_button_press, port.uri)
             title.connect_object("button-press-event", self.port_button_press, port.uri)
-        self.rect = goocanvas.Rect(parent = self.group, width = 100, height = y, line_width = 1, stroke_color_rgba = frameColor, fill_color_rgba = 0x202020FF)
+        self.rect = goocanvas.Rect(parent = self.group, width = 100, height = y, line_width = 1, stroke_color_rgba = Colors.frame, fill_color_rgba = Colors.box)
         self.rect.lower(self.title)
         self.portBoxes = portBoxes
         self.portTitles = portTitles
+        self.portData = portData
         self.group.ensure_updated()
+        self.wire = None
         
     def delete_items(self):
         self.group.remove()
         
     def port_button_press(self, port_uri, box, event):
         if event.button == 1:
+            pb = self.portBoxes[port_uri]
+            bounds = pb.get_bounds()
+            if self.portData[port_uri].isOutput:
+                x = bounds.x2
+            elif self.portData[port_uri].isInput:
+                x = bounds.x1
+            y = (bounds.y1 + bounds.y2) / 2
+            self.drag_wire = goocanvas.Path(parent = self.parent, stroke_color_rgba = Colors.frame)
+            self.drag_wire.raise_(None)
+            self.graph.dragging = (self, port_uri, self.drag_wire, x, y)
+            self.update_wire(self.graph.dragging, x, y)
             print "Port URI is " + port_uri
             return True
+            
+    def dragging(self, tuple, x2, y2):
+        boundsGrp = self.group.get_bounds()
+        self.update_wire(tuple, x2 + boundsGrp.x1, y2 + boundsGrp.y1)
+        
+    def dragged(self, tuple, x2, y2):
+        # self.update_wire(tuple, x2, y2)
+        tuple[2].remove()
+        self.graph.dragging = None
+        
+    def update_wire(self, tuple, x2, y2):
+        (x, y, dx, dy) = (tuple[3], tuple[4], x2 - tuple[3], y2 - tuple[4])
+        tuple[2].props.data = "M %0.0f,%0.0f C %0.0f,%0.0f %0.0f,%0.0f %0.0f,%0.0f" % (x, y, x+dx/2, y, x+dx/2, y+dy, x+dx, y+dy)
 
-class App:
-    def __init__(self):
-        fakeserv.start()
-        self.lv2db = lv2.LV2DB()
+class ConnectionGraphEditor:
+    def __init__(self, app):
+        self.app = app
+        self.moving = None
+        self.dragging = None
+        pass
         
     def create(self):
-        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-        self.window.connect("delete_event", self.delete_event)
-        self.window.connect("destroy", self.destroy)
-        self.main_vbox = gtk.VBox()
-        self.create_main_menu()
-        self.scroll = gtk.ScrolledWindow()
         self.create_canvas()
-        self.scroll.add(self.canvas)
-        self.main_vbox.pack_start(self.menu_bar, expand = False, fill = False)
-        self.main_vbox.add(self.scroll)
-        self.window.add(self.main_vbox)
-        self.window.show_all()
-        self.moving = None
-        
-    def create_main_menu(self):
-        self.menu_bar = gtk.MenuBar()
-        
-        self.file_menu = self.add_submenu(self.menu_bar, "_File")
-        self.add_option(self.file_menu, "_Exit", self.exit)
-        self.plugin_menu = self.add_submenu(self.menu_bar, "_Plugins")
-        for uri in self.lv2db.getPluginList():
-            plugin = self.lv2db.getPluginInfo(uri)
-            self.add_option(self.plugin_menu, plugin.name, self.add_plugin, (plugin, None, None))
+        return self.canvas
         
     def create_canvas(self):
         self.canvas = goocanvas.Canvas()
@@ -116,39 +147,40 @@ class App:
         #self.canvas.props.integer_layout = True
         self.canvas.update()
         self.canvas.get_root_item().connect("button-press-event", self.canvas_button_press)
-        
-    def add_submenu(self, menu, option):
-        submenu = gtk.Menu()
-        item = gtk.MenuItem(option)
-        menu.append(item)
-        item.set_submenu(submenu)
-        return submenu
-    
-    def add_option(self, menu, option, handler, data = None):
-        item = gtk.MenuItem(option)
-        item.connect_object("activate", handler, data)
-        menu.add(item)
+        self.canvas.get_root_item().connect("motion-notify-event", self.canvas_motion_notify)
+        self.canvas.get_root_item().connect("button-release-event", self.canvas_button_release)
         
     def add_plugin(self, params):
         (plugin, x, y) = params
-        mbox = ModuleBox(self.canvas.get_root_item(), plugin)
+        mbox = ModuleBox(self.canvas.get_root_item(), plugin, self)
         bounds = self.canvas.get_bounds()
         if x == None:
-            (x, y) = (random.randint(bounds[0], bounds[2] - 100), random.randint(bounds[1], bounds[3] - 50))
+            (x, y) = (int(random.uniform(bounds[0], bounds[2] - 100)), int(random.uniform(bounds[1], bounds[3] - 50)))
         mbox.group.translate(x, y)
         mbox.group.connect("button-press-event", self.box_button_press)
-        mbox.group.connect("button-release-event", self.box_button_release)
         mbox.group.connect("motion-notify-event", self.box_motion_notify)
+        mbox.group.connect("button-release-event", self.box_button_release)
         
+    def delete_plugin(self, data):
+        data.delete_items()
+
     def canvas_button_press(self, widget, item, event):
         if event.button == 3:
             menu = gtk.Menu()
-            for uri in self.lv2db.getPluginList():
-                plugin = self.lv2db.getPluginInfo(uri)
-                self.add_option(menu, plugin.name, self.add_plugin, (plugin, event.x, event.y))
+            for uri in self.app.lv2db.getPluginList():
+                plugin = self.app.lv2db.getPluginInfo(uri)
+                add_option(menu, plugin.name, self.add_plugin, (plugin, event.x, event.y))
             menu.show_all()
             menu.popup(None, None, None, event.button, event.time)
         
+    def canvas_motion_notify(self, group, widget, event):
+        if self.dragging != None:
+            self.dragging[0].dragging(self.dragging, event.x, event.y)
+
+    def canvas_button_release(self, group, widget, event):
+        if self.dragging != None and event.button == 1:
+            self.dragging[0].dragged(self.dragging, event.x, event.y)
+
     def box_button_press(self, group, widget, event):
         if event.button == 1:
             self.moving = group
@@ -157,7 +189,7 @@ class App:
             return True
         elif event.button == 3:
             menu = gtk.Menu()
-            self.add_option(menu, "Delete", self.delete_block, group.module)
+            add_option(menu, "Delete", self.delete_plugin, group.module)
             menu.show_all()
             menu.popup(None, None, None, event.button, event.time)
             return True
@@ -169,13 +201,39 @@ class App:
     def box_motion_notify(self, group, widget, event):
         if self.moving == group:
             self.moving.translate(event.x - self.motion_x, event.y - self.motion_y)
-    
+            
+class App:
+    def __init__(self):
+        fakeserv.start()
+        self.lv2db = lv2.LV2DB()
+        self.cgraph = ConnectionGraphEditor(self)
+        
+    def create(self):
+        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+        self.window.connect("delete_event", self.delete_event)
+        self.window.connect("destroy", self.destroy)
+        self.main_vbox = gtk.VBox()
+        self.create_main_menu()
+        self.scroll = gtk.ScrolledWindow()
+        self.scroll.add(self.cgraph.create())
+        self.main_vbox.pack_start(self.menu_bar, expand = False, fill = False)
+        self.main_vbox.add(self.scroll)
+        self.window.add(self.main_vbox)
+        self.window.show_all()
+        
+    def create_main_menu(self):
+        self.menu_bar = gtk.MenuBar()
+        
+        self.file_menu = add_submenu(self.menu_bar, "_File")
+        add_option(self.file_menu, "_Exit", self.exit)
+        self.plugin_menu = add_submenu(self.menu_bar, "_Plugins")
+        for uri in self.lv2db.getPluginList():
+            plugin = self.lv2db.getPluginInfo(uri)
+            add_option(self.plugin_menu, plugin.name, self.cgraph.add_plugin, (plugin, None, None))
+        
     def exit(self, data):
         self.window.destroy()
         
-    def delete_block(self, data):
-        data.delete_items()
-
     def delete_event(self, widget, data = None):
         gtk.main_quit()
     def destroy(self, widget, data = None):

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list