+ VU meter: move to separate header to enable reuse, modify falloff behaviour, add...
[calf.git] / bigbull / mainwin.py
blob93124241d73e701b466e163787f9d488460f6460
1 #!/usr/bin/python
2 import pygtk
3 pygtk.require('2.0')
4 import gtk
5 import lv2
6 import fakeserv
7 import client
8 import calfpytools
9 import conndiagram
10 from calfgtkutils import *
11 Colors = conndiagram.Colors
13 class LV2GraphParser():
14 def get_port_color(self, portData):
15 color = Colors.defPort
16 if portData.isAudio:
17 color = Colors.audioPort
18 if portData.isControl:
19 color = Colors.controlPort
20 if portData.isEvent:
21 color = Colors.eventPort
22 return color
23 def is_port_input(self, portData):
24 return portData.isInput
25 def get_port_name(self, portData):
26 return portData.name
27 def get_port_id(self, portData):
28 return portData.uri
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"
37 pass
39 class App:
40 def __init__(self):
41 fakeserv.start()
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)
48 return True
50 def canvas_button_press_handler(self, widget, event):
51 if event.button == 3:
52 self.canvas_popup_menu(event.x, event.y, event.time)
53 return True
55 def canvas_popup_menu(self, x, y, time):
56 menu = gtk.Menu()
57 items = self.cgraph.get_data_items_at(x, y)
58 types = set([di[0] for di in items])
59 if 'port' in types:
60 pass
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])
65 else:
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))
69 menu.show_all()
70 menu.popup(None, None, None, 3, time)
72 def create(self):
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():
96 if path == []:
97 continue;
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):
113 max_len = -1
114 best_path = []
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:
117 best_path = path
118 max_len = len(path)
119 return "/".join(best_path)
121 def exit(self, data):
122 self.window.destroy()
124 def delete_event(self, widget, data = None):
125 gtk.main_quit()
126 def destroy(self, widget, data = None):
127 gtk.main_quit()
129 app = App()
130 app.create()
131 gtk.main()