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 canvas_popup_menu(self
, x
, y
, time
):
57 items
= self
.cgraph
.get_data_items_at(x
, y
)
58 types
= set([di
[0] for di
in items
])
61 #add_option(menu, "-Port-", self.cgraph.delete_module_cb, (None, x, y))
62 elif 'module' in types
:
63 for mod
in [di
for di
in items
if di
[0] == "module"]:
64 add_option(menu
, "Delete "+mod
[1].plugin
.name
, self
.cgraph
.delete_module
, mod
[1])
66 for uri
in self
.lv2db
.getPluginList():
67 plugin
= self
.lv2db
.getPluginInfo(uri
)
68 add_option(menu
, plugin
.name
, self
.cgraph
.add_module_cb
, (plugin
, x
, y
))
70 menu
.popup(None, None, None, 3, time
)
73 self
.window
= gtk
.Window(gtk
.WINDOW_TOPLEVEL
)
74 self
.window
.connect("delete_event", self
.delete_event
)
75 self
.window
.connect("destroy", self
.destroy
)
76 self
.main_vbox
= gtk
.VBox()
77 self
.create_main_menu()
78 self
.scroll
= gtk
.ScrolledWindow()
79 self
.scroll
.add(self
.cgraph
.create())
80 self
.main_vbox
.pack_start(self
.menu_bar
, expand
= False, fill
= False)
81 self
.main_vbox
.add(self
.scroll
)
82 self
.window
.add(self
.main_vbox
)
83 self
.window
.show_all()
84 self
.main_vbox
.connect("popup-menu", self
.canvas_popup_menu_handler
)
85 self
.cgraph
.canvas
.connect("button-press-event", self
.canvas_button_press_handler
)
87 def create_main_menu(self
):
88 self
.menu_bar
= gtk
.MenuBar()
90 self
.file_menu
= add_submenu(self
.menu_bar
, "_File")
91 add_option(self
.file_menu
, "_Exit", self
.exit
)
92 self
.plugin_menu
= add_submenu(self
.menu_bar
, "_Plugins")
93 self
.submenus
= dict()
94 self
.category_to_path
= dict()
95 for (path
, uri
) in self
.lv2db
.get_categories():
98 parent_menu
= self
.plugin_menu
99 parent_path
= "/".join(path
[:-1])
100 if parent_path
in self
.submenus
:
101 parent_menu
= self
.submenus
[parent_path
]
102 self
.submenus
["/".join(path
)] = add_submenu(parent_menu
, path
[-1])
103 self
.category_to_path
[uri
] = path
104 for uri
in self
.lv2db
.getPluginList():
105 plugin
= self
.lv2db
.getPluginInfo(uri
)
106 parent_menu
= self
.plugin_menu
107 best_path
= self
.get_best_category(plugin
)
108 if best_path
in self
.submenus
:
109 parent_menu
= self
.submenus
[best_path
]
110 add_option(parent_menu
, plugin
.name
, self
.cgraph
.add_module_cb
, (plugin
, None, None))
112 def get_best_category(self
, plugin
):
115 for path
in [self
.category_to_path
[c
] for c
in plugin
.classes
if c
in self
.category_to_path
]:
116 if len(path
) > max_len
:
119 return "/".join(best_path
)
121 def exit(self
, data
):
122 self
.window
.destroy()
124 def delete_event(self
, widget
, data
= None):
126 def destroy(self
, widget
, data
= None):