+ Presets: 3 new presets for Organ
[calf.git] / bigbull / mkskel.py
blobd776d25c9636e338097a9b6eb5dbcabe4c1f37e0
1 #!/usr/bin/python
3 templ_h = """// Header
4 #ifndef [PREF]_CTL_[TYPE]_H
5 #define [PREF]_CTL_[TYPE]_H
7 #include <gtk/gtk.h>
9 G_BEGIN_DECLS
11 #define [PREF]_TYPE_[TYPE] ([pref]_[type]_get_type())
12 #define [PREF]_[TYPE](obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), [PREF]_TYPE_[TYPE], [Pref][Type]))
13 #define [PREF]_IS_[TYPE](obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), [PREF]_TYPE_[TYPE]))
14 #define [PREF]_[TYPE]_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), [PREF]_TYPE_[TYPE], [Pref][Type]Class))
15 #define [PREF]_IS_[TYPE]_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), [PREF]_TYPE_[TYPE]))
17 /// Instance object for [Pref][Type]
18 struct [Pref][Type]
20 GtkWidget parent;
23 /// Class object for [Pref][Type]
24 struct [Pref][Type]Class
26 GtkWidgetClass parent_class;
29 /// Create new [Pref][Type]
30 extern GtkWidget *[pref]_[type]_new();
32 /// Get GObject type
33 extern GType [pref]_[type]_get_type();
35 G_END_DECLS
37 #endif
38 """
40 templ_cpp = """// Source
42 GtkWidget *
43 [preftype]_new()
45 GtkWidget *widget = GTK_WIDGET( g_object_new ([PREF]_TYPE_[TYPE], NULL ));
46 return widget;
49 static gboolean
50 [preftype]_expose (GtkWidget *widget, GdkEventExpose *event)
52 g_assert([PREF]_IS_[TYPE](widget));
54 [PrefType] *self = [PREFTYPE](widget);
55 GdkWindow *window = widget->window;
56 cairo_t *c = gdk_cairo_create(GDK_DRAWABLE(window));
57 cairo_destroy(c);
59 return TRUE;
62 static void
63 [preftype]_realize(GtkWidget *widget)
65 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
67 GdkWindowAttr attributes;
68 attributes.event_mask = GDK_EXPOSURE_MASK | GDK_BUTTON1_MOTION_MASK |
69 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
70 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
71 attributes.x = widget->allocation.x;
72 attributes.y = widget->allocation.y;
73 attributes.width = widget->allocation.width;
74 attributes.height = widget->allocation.height;
75 attributes.wclass = GDK_INPUT_OUTPUT;
76 attributes.window_type = GDK_WINDOW_CHILD;
78 widget->window = gdk_window_new(gtk_widget_get_parent_window (widget), &attributes, GDK_WA_X | GDK_WA_Y);
80 gdk_window_set_user_data(widget->window, widget);
81 widget->style = gtk_style_attach(widget->style, widget->window);
84 static void
85 [preftype]_size_request (GtkWidget *widget,
86 GtkRequisition *requisition)
88 g_assert([PREF]_IS_[TYPE](widget));
90 // width/height is hardwired at 40px now
91 requisition->width = ...;
92 requisition->height = ...;
95 static void
96 [preftype]_size_allocate (GtkWidget *widget,
97 GtkAllocation *allocation)
99 g_assert([PREF]_IS_[TYPE](widget));
101 widget->allocation = *allocation;
103 if (GTK_WIDGET_REALIZED(widget))
104 gdk_window_move_resize(widget->window, allocation->x, allocation->y, allocation->width, allocation->height );
107 static void
108 [preftype]_class_init ([PrefType]Class *klass)
110 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
111 widget_class->realize = [preftype]_realize;
112 widget_class->expose_event = [preftype]_expose;
113 widget_class->size_request = [preftype]_size_request;
114 widget_class->size_allocate = [preftype]_size_allocate;
115 // widget_class->button_press_event = [preftype]_button_press;
116 // widget_class->button_release_event = [preftype]_button_release;
117 // widget_class->motion_notify_event = [preftype]_pointer_motion;
118 // widget_class->key_press_event = [preftype]_key_press;
119 // widget_class->scroll_event = [preftype]_scroll;
122 static void
123 [preftype]_init ([PrefType] *self)
125 GtkWidget *widget = GTK_WIDGET(self);
126 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(self), GTK_CAN_FOCUS);
129 GType
130 [preftype]_get_type (void)
132 static GType type = 0;
133 if (!type) {
135 static const GTypeInfo type_info = {
136 sizeof([PrefType]Class),
137 NULL, /* base_init */
138 NULL, /* base_finalize */
139 (GClassInitFunc)[preftype]_class_init,
140 NULL, /* class_finalize */
141 NULL, /* class_data */
142 sizeof([PrefType]),
143 0, /* n_preallocs */
144 (GInstanceInitFunc)[preftype]_init
147 for (int i = 0; ; i++) {
148 char *name = g_strdup_printf("[PrefType]%u%d",
149 ((unsigned int)(intptr_t)[preftype]_class_init) >> 16, i);
150 if (g_type_from_name(name)) {
151 free(name);
152 continue;
154 type = g_type_register_static(GTK_TYPE_WIDGET,
155 name,
156 &type_info,
157 (GTypeFlags)0);
158 free(name);
159 break;
162 return type;
166 def subst(text, pref, type):
167 text = text.replace("[pref]", pref.lower()).replace("[PREF]", pref.upper()).replace("[Pref]", pref)
168 text = text.replace("[type]", type.lower()).replace("[TYPE]", type.upper()).replace("[Type]", type)
169 text = text.replace("[preftype]", pref.lower()+"_"+type.lower()).replace("[PrefType]", pref+type)
170 text = text.replace("[PREFTYPE]", pref.upper()+"_"+type.upper())
171 return text
173 print subst(templ_h, "Calf", "Led")
174 print subst(templ_cpp, "Calf", "Led")