From 543860692bc7e9c369c2143262c03f4c48637302 Mon Sep 17 00:00:00 2001 From: Kenny Meyer Date: Sun, 12 Dec 2010 21:37:38 -0300 Subject: [PATCH] Add Python wizard to class-gen wizard --- plugins/class-gen/anjuta-class-gen-plugin.ui | 266 +++++++++++++++++++++++++- plugins/class-gen/templates/Makefile.am | 3 +- plugins/class-gen/window.c | 98 ++++++++++ 3 files changed, 359 insertions(+), 8 deletions(-) diff --git a/plugins/class-gen/anjuta-class-gen-plugin.ui b/plugins/class-gen/anjuta-class-gen-plugin.ui index 22c3d1b..d9e28e4 100644 --- a/plugins/class-gen/anjuta-class-gen-plugin.ui +++ b/plugins/class-gen/anjuta-class-gen-plugin.ui @@ -1,4 +1,4 @@ - + @@ -9,13 +9,13 @@ - public + public - protected + protected - private + private @@ -90,6 +90,7 @@ True + False True @@ -113,6 +114,7 @@ True + False True @@ -373,6 +375,7 @@ True + False True @@ -395,6 +398,7 @@ True + False True GObject @@ -453,6 +457,7 @@ True + False True 6 @@ -474,6 +479,7 @@ True + False True @@ -504,6 +510,7 @@ True + False True @@ -812,13 +819,254 @@ False + + + True + 6 + 6 + + + True + 0 + none + + + True + 6 + 12 + + + True + 4 + 4 + 5 + 5 + + + True + Class Name: + + + + + True + True + + + 1 + 2 + + + + + True + True + + + 3 + 4 + + + + + True + Base Class: + + + 2 + 3 + + + + + True + 1 + Source/Header Headings: + + + 3 + 4 + GTK_FILL + GTK_FILL + + + + + Author/Date/Time + True + True + False + True + True + + + 1 + 2 + 3 + 4 + GTK_FILL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + General Class Properties + + + + + + + + False + 0 + + + + + True + 0 + none + + + True + 6 + 12 + + + True + 6 + + + 100 + True + False + automatic + automatic + in + + + True + + + + + 0 + + + + + True + 6 + end + + + gtk-remove + True + False + False + True + + + False + False + 0 + + + + + gtk-add + True + False + False + True + + + False + False + 1 + + + + + False + 1 + + + + + + + + + True + Class Elements + + + + + + + + 1 + + + + + 2 + + + + + True + Python Class + + + 3 + False + + 0 - + True 4 4 @@ -827,6 +1075,7 @@ True + False True @@ -855,6 +1104,7 @@ True + False True @@ -911,7 +1161,7 @@ - + True 1 Header File: @@ -928,6 +1178,7 @@ True + False True @@ -961,6 +1212,7 @@ True + False True @@ -1062,7 +1314,7 @@ - + True Create diff --git a/plugins/class-gen/templates/Makefile.am b/plugins/class-gen/templates/Makefile.am index 7ffbc7e..d4838ae 100644 --- a/plugins/class-gen/templates/Makefile.am +++ b/plugins/class-gen/templates/Makefile.am @@ -4,7 +4,8 @@ clsgen_appdata_DATA = \ cc-header.tpl \ cc-source.tpl \ go-header.tpl \ - go-source.tpl + go-source.tpl \ + py-source.tpl EXTRA_DIST = \ $(clsgen_appdata_DATA) diff --git a/plugins/class-gen/window.c b/plugins/class-gen/window.c index 402c7d8..c6550fe 100644 --- a/plugins/class-gen/window.c +++ b/plugins/class-gen/window.c @@ -36,6 +36,8 @@ #define GO_HEADER_TEMPLATE PACKAGE_DATA_DIR"/class-templates/go-header.tpl" #define GO_SOURCE_TEMPLATE PACKAGE_DATA_DIR"/class-templates/go-source.tpl" +#define PY_SOURCE_TEMPLATE PACKAGE_DATA_DIR"/class-templates/py-source.tpl" + typedef struct _CgWindowPrivate CgWindowPrivate; struct _CgWindowPrivate { @@ -46,6 +48,7 @@ struct _CgWindowPrivate CgElementEditor *editor_go_members; CgElementEditor *editor_go_properties; CgElementEditor *editor_go_signals; + CgElementEditor *editor_py; CgValidator *validator; }; @@ -100,6 +103,13 @@ static const gchar *GO_PARAMSPEC_LIST[] = NULL }; +static const gchar *PY_IMPLEMENTATION_LIST[] = +{ + "Method", + "Variable/Constant", + NULL +}; + static const CgElementEditorFlags GO_PROPERTY_FLAGS[] = { { "G_PARAM_READABLE", "R" }, @@ -294,6 +304,18 @@ cg_window_validate_go (CgWindow *window) } static void +cg_window_validate_py (CgWindow *window) +{ + CgWindowPrivate *priv; + priv = CG_WINDOW_PRIVATE (window); + + if (priv->validator != NULL) g_object_unref (G_OBJECT (priv->validator)); + + priv->validator = cg_validator_new ( + GTK_WIDGET (gtk_builder_get_object (priv->bxml, "create_button")), + GTK_ENTRY (gtk_builder_get_object (priv->bxml, "py_name")), NULL); +} +static void cg_window_top_notebook_switch_page_cb (G_GNUC_UNUSED GtkNotebook *notebook, G_GNUC_UNUSED GtkNotebookPage *page, guint page_num, @@ -310,6 +332,9 @@ cg_window_top_notebook_switch_page_cb (G_GNUC_UNUSED GtkNotebook *notebook, case 1: cg_window_validate_go (window); break; + case 2: + cg_window_validate_py (window); + break; default: g_assert_not_reached (); break; @@ -452,6 +477,33 @@ cg_window_go_name_changed_cb (GtkEntry *entry, g_free (str_filesource); } +static void +cg_window_py_name_changed_cb (GtkEntry *entry, + gpointer user_data) +{ + CgWindow *window; + CgWindowPrivate *priv; + + GtkWidget *file_source; + gchar* str_filebase; + gchar* str_filesource; + + window = CG_WINDOW (user_data); + priv = CG_WINDOW_PRIVATE (window); + + file_source = GTK_WIDGET (gtk_builder_get_object (priv->bxml, "source_file")); + + str_filebase = cg_window_class_name_to_file_name ( + gtk_entry_get_text (GTK_ENTRY (entry))); + + str_filesource = g_strconcat (str_filebase, ".py", NULL); + g_free (str_filebase); + + gtk_entry_set_text (GTK_ENTRY (file_source), str_filesource); + + g_free (str_filesource); +} + #if 0 static void cg_window_associate_browse_button (GladeXML *xml, @@ -536,6 +588,16 @@ cg_window_set_builder (CgWindow *window, _("Flags"), CG_ELEMENT_EDITOR_COLUMN_FLAGS, GO_SIGNAL_FLAGS, _("Marshaller"), CG_ELEMENT_EDITOR_COLUMN_STRING); + priv->editor_py = cg_element_editor_new ( + GTK_TREE_VIEW (gtk_builder_get_object (priv->bxml, "py_elements")), + GTK_BUTTON (gtk_builder_get_object (priv->bxml, "py_elements_add")), + GTK_BUTTON (gtk_builder_get_object (priv->bxml, "py_elements_remove")), + 3, + /* Implementation sounds really confusing */ + _("Implementation"), CG_ELEMENT_EDITOR_COLUMN_LIST, PY_IMPLEMENTATION_LIST, + _("Name"), CG_ELEMENT_EDITOR_COLUMN_STRING, + _("Arguments"), CG_ELEMENT_EDITOR_COLUMN_ARGUMENTS); + /* Active item property in glade cannot be set because no GtkTreeModel * is assigned. */ gtk_combo_box_set_active ( @@ -560,6 +622,10 @@ cg_window_set_builder (CgWindow *window, G_CALLBACK (cg_window_cc_name_changed_cb), window); g_signal_connect ( + G_OBJECT (gtk_builder_get_object (priv->bxml, "py_name")), "changed", + G_CALLBACK (cg_window_py_name_changed_cb), window); + + g_signal_connect ( G_OBJECT (gtk_builder_get_object (priv->bxml, "add_project")), "toggled", G_CALLBACK (cg_window_add_project_toggled_cb), window); @@ -668,6 +734,13 @@ cg_window_go_signals_transform_func (GHashTable *table, cg_transform_flags (table, "Flags", GO_SIGNAL_FLAGS); } +static void +cg_window_py_transform_func (GHashTable *table, + G_GNUC_UNUSED gpointer user_data) +{ + cg_transform_arguments (table, "Arguments", FALSE); +} + #if 0 static gboolean cg_window_scope_condition_func (const gchar **elements, @@ -715,6 +788,7 @@ cg_window_init (CgWindow *window) priv->editor_go_members = NULL; priv->editor_go_properties = NULL; priv->editor_go_signals = NULL; + priv->editor_py = NULL; priv->validator = NULL; } @@ -736,6 +810,8 @@ cg_window_finalize (GObject *object) g_object_unref (G_OBJECT (priv->editor_go_properties)); if (priv->editor_go_signals != NULL) g_object_unref (G_OBJECT (priv->editor_go_signals)); + if (priv->editor_py != NULL) + g_object_unref (G_OBJECT (priv->editor_py)); if (priv->validator != NULL) g_object_unref (G_OBJECT (priv->validator)); @@ -995,6 +1071,24 @@ cg_window_create_value_heap (CgWindow *window) "Flags", "Marshaller"); break; + case 2: /* Python */ + cg_window_set_heap_value (window, values, G_TYPE_STRING, + "ClassName", "py_name"); + cg_window_set_heap_value (window, values, G_TYPE_STRING, + "BaseClass", "py_base"); + /* g_window_set_heap_value (window, values, G_TYPE_STRING, + "Inheritance", "cc_inheritance"); + cg_window_set_heap_value (window, values, G_TYPE_BOOLEAN, + "Headings", "cc_headings"); + cg_window_set_heap_value (window, values, G_TYPE_BOOLEAN, + "Inline", "cc_inline"); + */ + + cg_element_editor_set_values (priv->editor_py, "Elements", values, + cg_window_py_transform_func, window, + "Implementation", "Name", "Arguments"); + + break; default: g_assert_not_reached (); break; @@ -1045,6 +1139,8 @@ cg_window_get_header_template (CgWindow *window) return CC_HEADER_TEMPLATE; case 1: return GO_HEADER_TEMPLATE; + //case 2: + // return ""; default: g_assert_not_reached (); return NULL; @@ -1082,6 +1178,8 @@ cg_window_get_source_template(CgWindow *window) return CC_SOURCE_TEMPLATE; case 1: return GO_SOURCE_TEMPLATE; + case 2: + return PY_SOURCE_TEMPLATE; default: g_assert_not_reached (); return NULL; -- 1.7.3.2