10 from calfgtkutils
import *
11 Colors
= conndiagram
.Colors
13 class LV2GraphParser():
14 def get_port_color(self
, portData
):
15 color
= Colors
.defPort
17 color
= Colors
.audioPort
18 if portData
.isControl
:
19 color
= Colors
.controlPort
21 color
= Colors
.eventPort
23 def is_port_input(self
, portData
):
24 return portData
.isInput
25 def get_port_name(self
, portData
):
27 def get_port_id(self
, portData
):
29 def get_module_name(self
, moduleData
):
30 return moduleData
.name
31 def get_module_port_list(self
, moduleData
):
32 return [(port
.uri
, port
) for port
in moduleData
.ports
if lv2
.epi
+ "notAutomatic" not in port
.properties
]
33 def can_connect(self
, first
, second
):
34 return first
.connectableTo(second
)
35 def connect(self
, first
, second
):
36 print "Connection not implemented yet"
42 self
.lv2db
= lv2
.LV2DB()
43 self
.parser
= LV2GraphParser()
44 self
.cgraph
= conndiagram
.ConnectionGraphEditor(self
, self
.parser
)
46 def canvas_popup_menu_handler(self
, widget
):
47 self
.canvas_popup_menu(0, 0, 0)
50 def canvas_button_press_handler(self
, widget
, event
):
52 self
.canvas_popup_menu(event
.x
, event
.y
, event
.time
)
55 def add_module_cb(self
, params
):
56 self
.cgraph
.add_module(*params
)
58 def canvas_popup_menu(self
, x
, y
, time
):
60 items
= self
.cgraph
.get_data_items_at(x
, y
)
61 types
= set([di
[0] for di
in items
])
64 #add_option(menu, "-Port-", self.cgraph.delete_module_cb, (None, x, y))
65 elif 'module' in types
:
66 for mod
in [di
for di
in items
if di
[0] == "module"]:
67 add_option(menu
, "Delete "+mod
[1].plugin
.name
, self
.cgraph
.delete_module
, mod
[1])
69 for uri
in self
.lv2db
.getPluginList():
70 plugin
= self
.lv2db
.getPluginInfo(uri
)
71 add_option(menu
, plugin
.name
, self
.add_module_cb
, (plugin
, x
, y
))
73 menu
.popup(None, None, None, 3, time
)
76 self
.window
= gtk
.Window(gtk
.WINDOW_TOPLEVEL
)
77 self
.window
.connect("delete_event", self
.delete_event
)
78 self
.window
.connect("destroy", self
.destroy
)
79 self
.main_vbox
= gtk
.VBox()
80 self
.create_main_menu()
81 self
.scroll
= gtk
.ScrolledWindow()
82 self
.scroll
.add(self
.cgraph
.create())
83 self
.main_vbox
.pack_start(self
.menu_bar
, expand
= False, fill
= False)
84 self
.main_vbox
.add(self
.scroll
)
85 self
.window
.add(self
.main_vbox
)
86 self
.window
.show_all()
87 self
.main_vbox
.connect("popup-menu", self
.canvas_popup_menu_handler
)
88 self
.cgraph
.canvas
.connect("button-press-event", self
.canvas_button_press_handler
)
90 def create_main_menu(self
):
91 self
.menu_bar
= gtk
.MenuBar()
93 self
.file_menu
= add_submenu(self
.menu_bar
, "_File")
94 add_option(self
.file_menu
, "_Exit", self
.exit
)
95 self
.plugin_menu
= add_submenu(self
.menu_bar
, "_Plugins")
96 self
.submenus
= dict()
97 self
.category_to_path
= dict()
98 for (path
, uri
) in self
.lv2db
.get_categories():
101 parent_menu
= self
.plugin_menu
102 parent_path
= "/".join(path
[:-1])
103 if parent_path
in self
.submenus
:
104 parent_menu
= self
.submenus
[parent_path
]
105 self
.submenus
["/".join(path
)] = add_submenu(parent_menu
, path
[-1])
106 self
.category_to_path
[uri
] = path
107 for uri
in self
.lv2db
.getPluginList():
108 plugin
= self
.lv2db
.getPluginInfo(uri
)
109 parent_menu
= self
.plugin_menu
110 best_path
= self
.get_best_category(plugin
)
111 if best_path
in self
.submenus
:
112 parent_menu
= self
.submenus
[best_path
]
113 add_option(parent_menu
, plugin
.name
, self
.add_module_cb
, (plugin
, None, None))
115 def get_best_category(self
, plugin
):
118 for path
in [self
.category_to_path
[c
] for c
in plugin
.classes
if c
in self
.category_to_path
]:
119 if len(path
) > max_len
:
122 return "/".join(best_path
)
124 def exit(self
, data
):
125 self
.window
.destroy()
127 def delete_event(self
, widget
, data
= None):
129 def destroy(self
, widget
, data
= None):