[anjuta] Add Python wizard to class-gen plugin



commit 75e25e0a0af9ea3465692dc813e14c76e54388f3
Author: Kenny Meyer <knny myer gmail com>
Date:   Sat Dec 18 17:21:09 2010 -0300

    Add Python wizard to class-gen plugin

 plugins/class-gen/anjuta-class-gen-plugin.ui |  400 +++++++++++++++++++++++---
 plugins/class-gen/anjuta-class-gen.plugin.in |    2 +-
 plugins/class-gen/plugin.c                   |   93 +++++--
 plugins/class-gen/templates/Makefile.am      |    3 +-
 plugins/class-gen/templates/py-source.tpl    |   43 +++
 plugins/class-gen/transform.c                |   59 ++++
 plugins/class-gen/transform.h                |    4 +
 plugins/class-gen/window.c                   |  128 ++++++++
 8 files changed, 667 insertions(+), 65 deletions(-)
---
diff --git a/plugins/class-gen/anjuta-class-gen-plugin.ui b/plugins/class-gen/anjuta-class-gen-plugin.ui
index 22c3d1b..5d8a470 100644
--- a/plugins/class-gen/anjuta-class-gen-plugin.ui
+++ b/plugins/class-gen/anjuta-class-gen-plugin.ui
@@ -1,41 +1,7 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy toplevel-contextual -->
-  <object class="GtkListStore" id="model1">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="no">public</col>
-      </row>
-      <row>
-        <col id="0" translatable="no">protected</col>
-      </row>
-      <row>
-        <col id="0" translatable="no">private</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model2">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">General Public License (GPL)</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Lesser General Public License (LGPL)</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">No License</col>
-      </row>
-    </data>
-  </object>
   <object class="GtkDialog" id="classgen_main">
     <property name="title" translatable="yes">Class Generator</property>
     <property name="default_height">582</property>
@@ -90,6 +56,7 @@
                                 <child>
                                   <object class="GtkEntry" id="cc_name">
                                     <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
                                     <property name="activates_default">True</property>
                                   </object>
                                   <packing>
@@ -113,6 +80,7 @@
                                 <child>
                                   <object class="GtkEntry" id="cc_base">
                                     <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
                                     <property name="activates_default">True</property>
                                   </object>
                                   <packing>
@@ -373,6 +341,7 @@
                                 <child>
                                   <object class="GtkEntry" id="go_name">
                                     <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
                                     <property name="activates_default">True</property>
                                   </object>
                                   <packing>
@@ -395,6 +364,7 @@
                                 <child>
                                   <object class="GtkEntry" id="go_base">
                                     <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
                                     <property name="activates_default">True</property>
                                     <property name="text">GObject</property>
                                   </object>
@@ -453,6 +423,7 @@
                                     <child>
                                       <object class="GtkEntry" id="go_prefix">
                                         <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
                                         <property name="activates_default">True</property>
                                         <property name="width_chars">6</property>
                                       </object>
@@ -474,6 +445,7 @@
                                     <child>
                                       <object class="GtkEntry" id="go_type">
                                         <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
                                         <property name="activates_default">True</property>
                                       </object>
                                       <packing>
@@ -504,6 +476,7 @@
                                 <child>
                                   <object class="GtkEntry" id="go_func_prefix">
                                     <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
                                     <property name="activates_default">True</property>
                                   </object>
                                   <packing>
@@ -812,13 +785,326 @@
                     <property name="tab_fill">False</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkVBox" id="vbox_python">
+                    <property name="visible">True</property>
+                    <property name="border_width">6</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkFrame" id="frame_python">
+                        <property name="visible">True</property>
+                        <property name="label_xalign">0</property>
+                        <property name="shadow_type">none</property>
+                        <child>
+                          <object class="GtkAlignment" id="alignment">
+                            <property name="visible">True</property>
+                            <property name="top_padding">6</property>
+                            <property name="left_padding">12</property>
+                            <child>
+                              <object class="GtkTable" id="table">
+                                <property name="visible">True</property>
+                                <property name="n_rows">4</property>
+                                <property name="n_columns">4</property>
+                                <property name="column_spacing">5</property>
+                                <property name="row_spacing">5</property>
+                                <child>
+                                  <object class="GtkLabel" id="label9">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Class Name:</property>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkEntry" id="py_name">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkEntry" id="py_base">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">3</property>
+                                    <property name="right_attach">4</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label10">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Base Class:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">2</property>
+                                    <property name="right_attach">3</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label11">
+                                    <property name="visible">True</property>
+                                    <property name="xalign">1</property>
+                                    <property name="label" translatable="yes">Source/Header Headings:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="top_attach">3</property>
+                                    <property name="bottom_attach">4</property>
+                                    <property name="x_options">GTK_FILL</property>
+                                    <property name="y_options">GTK_FILL</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkCheckButton" id="py_headings">
+                                    <property name="label" translatable="yes">Author/Date/Time</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="active">True</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
+                                    <property name="top_attach">3</property>
+                                    <property name="bottom_attach">4</property>
+                                    <property name="y_options">GTK_FILL</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                        <child type="label">
+                          <object class="GtkLabel" id="label99">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">General Class Properties</property>
+                            <attributes>
+                              <attribute name="weight" value="bold"/>
+                            </attributes>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkNotebook" id="notebook1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <child>
+                          <object class="GtkVBox" id="vbox2">
+                            <property name="visible">True</property>
+                            <property name="border_width">8</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkScrolledWindow" id="scrolledwindow1">
+                                <property name="height_request">100</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="hscrollbar_policy">automatic</property>
+                                <property name="vscrollbar_policy">automatic</property>
+                                <property name="shadow_type">in</property>
+                                <child>
+                                  <object class="GtkTreeView" id="py_methods">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkHButtonBox" id="hbuttonbox1">
+                                <property name="visible">True</property>
+                                <property name="spacing">6</property>
+                                <property name="layout_style">end</property>
+                                <child>
+                                  <object class="GtkButton" id="py_methods_remove">
+                                    <property name="label">gtk-remove</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                    <property name="use_stock">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkButton" id="py_methods_add">
+                                    <property name="label">gtk-add</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                    <property name="use_stock">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child>
+                        <child type="tab">
+                          <object class="GtkLabel" id="label1">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Class Methods</property>
+                          </object>
+                          <packing>
+                            <property name="tab_fill">False</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkVBox" id="vbox3">
+                            <property name="visible">True</property>
+                            <property name="border_width">8</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkScrolledWindow" id="scrolledwindow2">
+                                <property name="height_request">100</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="hscrollbar_policy">automatic</property>
+                                <property name="vscrollbar_policy">automatic</property>
+                                <property name="shadow_type">in</property>
+                                <child>
+                                  <object class="GtkTreeView" id="py_constvars">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkHButtonBox" id="hbuttonbox2">
+                                <property name="visible">True</property>
+                                <property name="spacing">6</property>
+                                <property name="layout_style">end</property>
+                                <child>
+                                  <object class="GtkButton" id="py_constvars_remove">
+                                    <property name="label">gtk-remove</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                    <property name="use_stock">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkButton" id="py_constvars_add">
+                                    <property name="label">gtk-add</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                    <property name="use_stock">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <object class="GtkLabel" id="label4">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Constants/Variables</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                            <property name="tab_fill">False</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child type="tab">
+                  <object class="GtkLabel" id="label80">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Python Class</property>
+                  </object>
+                  <packing>
+                    <property name="position">3</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="position">0</property>
               </packing>
             </child>
             <child>
-              <object class="GtkTable" id="table1">
+              <object class="GtkTable" id="table2">
                 <property name="visible">True</property>
                 <property name="n_rows">4</property>
                 <property name="n_columns">4</property>
@@ -827,6 +1113,7 @@
                 <child>
                   <object class="GtkEntry" id="author_email">
                     <property name="visible">True</property>
+                    <property name="can_focus">True</property>
                     <property name="activates_default">True</property>
                   </object>
                   <packing>
@@ -855,6 +1142,7 @@
                 <child>
                   <object class="GtkEntry" id="author_name">
                     <property name="visible">True</property>
+                    <property name="can_focus">True</property>
                     <property name="activates_default">True</property>
                   </object>
                   <packing>
@@ -911,7 +1199,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="label1">
+                  <object class="GtkLabel" id="label5">
                     <property name="visible">True</property>
                     <property name="xalign">1</property>
                     <property name="label" translatable="yes">Header File:</property>
@@ -928,6 +1216,7 @@
                     <child>
                       <object class="GtkEntry" id="header_file">
                         <property name="visible">True</property>
+                        <property name="can_focus">True</property>
                         <property name="activates_default">True</property>
                       </object>
                       <packing>
@@ -961,6 +1250,7 @@
                     <child>
                       <object class="GtkEntry" id="source_file">
                         <property name="visible">True</property>
+                        <property name="can_focus">True</property>
                         <property name="activates_default">True</property>
                       </object>
                       <packing>
@@ -1062,7 +1352,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label4">
+                      <object class="GtkLabel" id="label7">
                         <property name="visible">True</property>
                         <property name="label" translatable="yes">Create</property>
                       </object>
@@ -1093,4 +1383,38 @@
       <action-widget response="-3">create_button</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkListStore" id="model2">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">General Public License (GPL)</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Lesser General Public License (LGPL)</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">No License</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="model1">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0">public</col>
+      </row>
+      <row>
+        <col id="0">protected</col>
+      </row>
+      <row>
+        <col id="0">private</col>
+      </row>
+    </data>
+  </object>
 </interface>
diff --git a/plugins/class-gen/anjuta-class-gen.plugin.in b/plugins/class-gen/anjuta-class-gen.plugin.in
index d53a81e..19c018b 100644
--- a/plugins/class-gen/anjuta-class-gen.plugin.in
+++ b/plugins/class-gen/anjuta-class-gen.plugin.in
@@ -7,4 +7,4 @@ Interfaces=IAnjutaWizard
 UserActivatable=no
 
 [Wizard]
-_Title=C++/GObject Class
+_Title=Class Wizard
diff --git a/plugins/class-gen/plugin.c b/plugins/class-gen/plugin.c
index 6a4dbfe..1698bab 100644
--- a/plugins/class-gen/plugin.c
+++ b/plugins/class-gen/plugin.c
@@ -199,8 +199,19 @@ cg_plugin_add_to_project (AnjutaClassGenPlugin *plugin,
 	result = g_list_length (added_files) == 2;
 	if (result)
 	{
-		*new_header_file = g_file_get_path((GFile *)added_files->data);
-		*new_source_file = g_file_get_path((GFile *)g_list_next (added_files)->data);
+		/*
+		 * Check if we're dealing with a programming language not having header
+		 * files.
+		 */
+		if (strcmp (header_file, source_file) == 0)
+		{
+			*new_source_file = g_file_get_path((GFile *)g_list_next (added_files)->data);
+		}
+		else
+		{
+			*new_header_file = g_file_get_path((GFile *)added_files->data);
+			*new_source_file = g_file_get_path((GFile *)g_list_next (added_files)->data);
+		}
 	}
 
 	g_list_foreach (added_files, (GFunc)g_object_unref, NULL);
@@ -290,6 +301,7 @@ cg_plugin_generator_created_cb (CgGenerator *generator,
 	const gchar *header_file;
 	const gchar *source_file;
 	IAnjutaFileLoader *loader;
+        gboolean header_is_source = FALSE;
 
 	plugin = (AnjutaClassGenPlugin *) user_data;
 	header_file = cg_generator_get_header_destination (generator);
@@ -298,14 +310,30 @@ cg_plugin_generator_created_cb (CgGenerator *generator,
 	loader = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
 	                                     IAnjutaFileLoader, NULL);
 	
+        /*
+         * Check if we're workign with a programming language that
+         * doesn't need header files.  If yes, don't create two tabs,
+         * as the header and source will be the same file.
+         */
+        if (g_strcmp0 (header_file, source_file) == 0)
+        {
+                header_is_source = TRUE;
+        }
+
 	if (cg_window_get_add_to_project (plugin->window))
 	{
 		GFile* header = g_file_new_for_path (header_file);
 		GFile* source = g_file_new_for_path (source_file);
 		IAnjutaProjectManager *manager;
-
-		ianjuta_file_loader_load (loader, header, FALSE, NULL);
-		ianjuta_file_loader_load (loader, source, FALSE, NULL);
+		if (header_is_source == TRUE)
+		{
+			ianjuta_file_loader_load (loader, source, FALSE, NULL);
+		}
+		else
+		{
+			ianjuta_file_loader_load (loader, header, FALSE, NULL);
+			ianjuta_file_loader_load (loader, source, FALSE, NULL);
+		}
 
 		if (cg_window_get_add_to_repository (plugin->window))
 		{
@@ -315,8 +343,16 @@ cg_plugin_generator_created_cb (CgGenerator *generator,
 		manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaProjectManager, NULL);
 		if (manager)
 		{
-			g_signal_emit_by_name (G_OBJECT (manager), "element_added", header);
-			g_signal_emit_by_name (G_OBJECT (manager), "element_added", source);
+			if (header_is_source == TRUE)
+			{
+			    g_signal_emit_by_name (G_OBJECT (manager), "element_added", source);
+			}
+			else
+			{
+			    g_signal_emit_by_name (G_OBJECT (manager), "element_added", header);
+			    g_signal_emit_by_name (G_OBJECT (manager), "element_added", source);
+			}
+
 		}
 
 		g_object_unref (header);
@@ -324,11 +360,18 @@ cg_plugin_generator_created_cb (CgGenerator *generator,
 	}
 	else
 	{
-		/* We do not just use ianjuta_file_leader_load here to ensure that
-		 * the new documents are flagged as changed and no path is
-		 * already set. */
-		cg_plugin_load (plugin, generator, header_file, NULL);
-		cg_plugin_load (plugin, generator, source_file, NULL);
+		if (header_is_source == TRUE)
+		{
+			/* We do not just use ianjuta_file_leader_load here to ensure that
+			 * the new documents are flagged as changed and no path is
+			 * already set. */
+			cg_plugin_load (plugin, generator, source_file, NULL);
+		}
+		else
+		{
+			cg_plugin_load (plugin, generator, header_file, NULL);
+			cg_plugin_load (plugin, generator, source_file, NULL);
+		}
 	}
 
 	g_object_unref (G_OBJECT (plugin->window));
@@ -356,24 +399,24 @@ cg_plugin_window_response_cb (G_GNUC_UNUSED GtkDialog *dialog,
 
 	if (response_id == GTK_RESPONSE_ACCEPT)
 	{
-    	if (cg_window_get_add_to_project (plugin->window))
-	    {
-		    result = cg_plugin_add_to_project (
-		    	plugin, cg_window_get_header_file (plugin->window),
-				cg_window_get_source_file (plugin->window),
-				&header_file, &source_file);
+		if (cg_window_get_add_to_project (plugin->window))
+		{
+			result = cg_plugin_add_to_project (
+				plugin, cg_window_get_header_file (plugin->window),
+					cg_window_get_source_file (plugin->window),
+					&header_file, &source_file);
 		}
 		else
 		{
-		    header_file = g_build_filename (g_get_tmp_dir (),
-		    	cg_window_get_header_file (plugin->window), NULL);
-		    source_file = g_build_filename (g_get_tmp_dir (),
-		    	cg_window_get_source_file (plugin->window), NULL);
+			header_file = g_build_filename (g_get_tmp_dir (),
+				cg_window_get_header_file (plugin->window), NULL);
+			source_file = g_build_filename (g_get_tmp_dir (),
+				cg_window_get_source_file (plugin->window), NULL);
 
-		    result = TRUE;
+			result = TRUE;
 		}
-    	
-		if(result == TRUE)
+
+		if (result == TRUE)
 		{
 			values = cg_window_create_value_heap (plugin->window);
 
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/templates/py-source.tpl b/plugins/class-gen/templates/py-source.tpl
new file mode 100644
index 0000000..4bfa8e1
--- /dev/null
+++ b/plugins/class-gen/templates/py-source.tpl
@@ -0,0 +1,43 @@
+[+ AutoGen5 template
+##
+##  py-source.tpl
+##  Copyright (C) 2010 Kenny Meyer <knny myer gmail com>
+##
+##  This program is free software; you can redistribute it and/or modify
+##  it under the terms of the GNU General Public License as published by
+##  the Free Software Foundation; either version 2 of the License, or
+##  (at your option) any later version.
+##
+##  This program is distributed in the hope that it will be useful,
+##  but WITHOUT ANY WARRANTY; without even the implied warranty of
+##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
+##  GNU Library General Public License for more details.
+##
+##  You should have received a copy of the GNU General Public License
+##  along with this program; if not, write to the Free Software
+##  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
++]
+# -*- Mode: Python; Coding: utf-8; tab-width: 4 -*-
+#
+# [+ProjectName+][+IF (=(get "Headings") "1")+]
+# Copyright (C) [+AuthorName+] [+(shell "date +%Y")+] <[+AuthorEmail+]>[+ENDIF+]
+#
+[+CASE (get "License") +]
+[+ == "BSD"  +][+(bsd  (get "ProjectName") (get "AuthorName") "# ")+]
+[+ == "LGPL" +][+(lgpl (get "ProjectName") (get "AuthorName") "# ")+]
+[+ == "GPL"  +][+(gpl  (get "ProjectName")                    "# ")+]
+[+ESAC+]
+
+class [+ClassName+]([+IF (not (=(get "BaseClass") ""))+][+BaseClass+][+ENDIF+]):[+
+FOR Constvars +][+
+    IF (not (=(get "Name") "")) +]
+    [+Name+] = [+Value+][+
+    ENDIF +][+
+ENDFOR +][+
+FOR Methods +][+
+    IF (not (=(get "Name") "")) +]
+    def [+Name+][+Arguments+]:
+        pass
+[+
+    ENDIF +][+
+ENDFOR +]
diff --git a/plugins/class-gen/transform.c b/plugins/class-gen/transform.c
index 4d6bd3f..01d3fc4 100644
--- a/plugins/class-gen/transform.c
+++ b/plugins/class-gen/transform.c
@@ -437,6 +437,65 @@ cg_transform_arguments (GHashTable *table,
 	}
 }
 
+/** 
+ * Add a self reference to the arguments list, if necessary. Python only.
+ */
+void
+cg_transform_python_arguments (GHashTable *table,
+			       const gchar *index)
+{
+	gchar *arg_res;
+	gchar *arguments;
+	size_t len;
+
+	arguments = g_hash_table_lookup (table, index);
+
+	arg_res = NULL;
+	if (arguments != NULL)
+	{
+		g_strstrip (arguments);
+		len = strlen (arguments);
+		/* Do nothing if the field was left empty */
+		if (len > 0)
+		{
+			if (arguments[0] != '(')
+			{
+				/* Check if self is in arguments. If yes,
+				 * cg_transform_arguments will take care of the
+				 * rest, if not then add the self argument. */
+				if (g_strcmp0 (arguments, "self") != 0)
+				{
+					g_hash_table_insert (table, (gpointer) index,
+							     g_strdup_printf ("(self, %s)", arguments));
+
+					g_free (arg_res);
+					arg_res = NULL;
+				}
+			}
+			else
+			{
+				if (g_strcmp0 (arguments, "()") == 0)
+				{
+					g_hash_table_insert (table, (gpointer) index,
+							     g_strdup ("(self)"));
+
+					g_free (arg_res);
+					arg_res = NULL;
+				}
+			}
+		}
+		else
+		{
+			g_hash_table_insert (table, (gpointer) index,
+						     g_strdup_printf ("%s", "(self)"));
+			g_free (arg_res);
+			arg_res = NULL;
+		}
+	}
+
+	cg_transform_arguments (table, index, FALSE);
+}
+
 /* This function makes a valid C identifier out of a string. It does this
  * by ignoring anything but digits, letters, hyphens and underscores. Digits
  * at the beginning of the string are also ignored. Hpyhens are transformed
diff --git a/plugins/class-gen/transform.h b/plugins/class-gen/transform.h
index 818a0cb..33a0caa 100644
--- a/plugins/class-gen/transform.h
+++ b/plugins/class-gen/transform.h
@@ -70,6 +70,10 @@ cg_transform_arguments (GHashTable *table,
                         gboolean make_void);
 
 void
+cg_transform_python_arguments (GHashTable *table,
+                               const gchar *index);
+
+void
 cg_transform_string_to_identifier (GHashTable *table,
                                    const gchar *string_index,
                                    const gchar *identifier_index);
diff --git a/plugins/class-gen/window.c b/plugins/class-gen/window.c
index 7698898..94eaca3 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,8 @@ struct _CgWindowPrivate
 	CgElementEditor *editor_go_members;
 	CgElementEditor *editor_go_properties;
 	CgElementEditor *editor_go_signals;
+	CgElementEditor *editor_py_methods;
+	CgElementEditor *editor_py_constvars;
 	
 	CgValidator *validator;
 };
@@ -294,6 +298,35 @@ 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_header_file_entry_set_sensitive (gpointer user_data, gboolean sensitive)
+{
+	CgWindow *window;
+	CgWindowPrivate *priv;
+
+	GtkWidget *file_header;
+
+	window = CG_WINDOW (user_data);
+	priv = CG_WINDOW_PRIVATE (window);
+
+	file_header = GTK_WIDGET (gtk_builder_get_object (priv->bxml, "header_file"));
+
+	gtk_widget_set_sensitive (file_header, sensitive);
+}
+
+static void
 cg_window_top_notebook_switch_page_cb (G_GNUC_UNUSED GtkNotebook *notebook,
                                        G_GNUC_UNUSED GtkWidget *page,
                                        guint page_num,
@@ -305,11 +338,17 @@ cg_window_top_notebook_switch_page_cb (G_GNUC_UNUSED GtkNotebook *notebook,
 	switch(page_num)
 	{
 	case 0:
+		cg_window_header_file_entry_set_sensitive (user_data, TRUE);
 		cg_window_validate_cc (window);
 		break;
 	case 1:
+		cg_window_header_file_entry_set_sensitive (user_data, TRUE);
 		cg_window_validate_go (window);
 		break;
+	case 2: /* Python */
+		cg_window_header_file_entry_set_sensitive (user_data, FALSE);
+		cg_window_validate_py (window);
+		break;
 	default:
 		g_assert_not_reached ();
 		break;
@@ -452,6 +491,36 @@ 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_header;
+	GtkWidget *file_source;
+	gchar* str_filebase;
+	gchar* str_filesource;
+
+	window = CG_WINDOW (user_data);
+	priv = CG_WINDOW_PRIVATE (window);
+
+	file_header = GTK_WIDGET (gtk_builder_get_object (priv->bxml, "header_file"));
+	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_header), str_filesource);
+	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 +605,23 @@ cg_window_set_builder (CgWindow *window,
 		_("Flags"), CG_ELEMENT_EDITOR_COLUMN_FLAGS, GO_SIGNAL_FLAGS,
 		_("Marshaller"), CG_ELEMENT_EDITOR_COLUMN_STRING);
 
+	priv->editor_py_methods = cg_element_editor_new (
+		GTK_TREE_VIEW (gtk_builder_get_object (priv->bxml, "py_methods")),
+		GTK_BUTTON (gtk_builder_get_object (priv->bxml, "py_methods_add")),
+		GTK_BUTTON (gtk_builder_get_object (priv->bxml, "py_methods_remove")),
+		2,
+		_("Name"), CG_ELEMENT_EDITOR_COLUMN_STRING,
+		_("Arguments"), CG_ELEMENT_EDITOR_COLUMN_ARGUMENTS);
+
+	priv->editor_py_constvars = cg_element_editor_new (
+		GTK_TREE_VIEW (gtk_builder_get_object (priv->bxml, "py_constvars")),
+		GTK_BUTTON (gtk_builder_get_object (priv->bxml, "py_constvars_add")),
+		GTK_BUTTON (gtk_builder_get_object (priv->bxml, "py_constvars_remove")),
+		2,
+		_("Name"), CG_ELEMENT_EDITOR_COLUMN_STRING,
+		_("Value"), CG_ELEMENT_EDITOR_COLUMN_STRING);
+
+
 	/* Active item property in glade cannot be set because no GtkTreeModel
 	 * is assigned. */
 	gtk_combo_box_set_active (
@@ -544,6 +630,9 @@ cg_window_set_builder (CgWindow *window,
 	gtk_combo_box_set_active (
 		GTK_COMBO_BOX (gtk_builder_get_object (priv->bxml, "cc_inheritance")),
 		0);
+	g_signal_connect (
+		G_OBJECT (gtk_builder_get_object (priv->bxml, "py_name")), "changed",
+		G_CALLBACK (cg_window_py_name_changed_cb), window);
 
 	/* This revalidates the appropriate validator */
 	g_signal_connect (
@@ -668,6 +757,20 @@ cg_window_go_signals_transform_func (GHashTable *table,
 	cg_transform_flags (table, "Flags", GO_SIGNAL_FLAGS);
 }
 
+static void
+cg_window_py_methods_transform_func (GHashTable *table,
+			     G_GNUC_UNUSED gpointer user_data)
+{
+	cg_transform_python_arguments (table, "Arguments");
+}
+
+static void
+cg_window_py_constvars_transform_func (GHashTable *table,
+                                       G_GNUC_UNUSED gpointer user_data)
+{
+	cg_transform_string (table, "Value");
+}
+
 #if 0
 static gboolean
 cg_window_scope_condition_func (const gchar **elements,
@@ -715,6 +818,8 @@ cg_window_init (CgWindow *window)
 	priv->editor_go_members = NULL;
 	priv->editor_go_properties = NULL;
 	priv->editor_go_signals = NULL;
+	priv->editor_py_methods = NULL;
+	priv->editor_py_constvars = NULL;
 	
 	priv->validator = NULL;
 }
@@ -736,6 +841,10 @@ 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_methods != NULL)
+		g_object_unref (G_OBJECT (priv->editor_py_methods));
+	if (priv->editor_py_constvars != NULL)
+		g_object_unref (G_OBJECT (priv->editor_py_constvars));
 
 	if (priv->validator != NULL)
 		g_object_unref (G_OBJECT (priv->validator));
@@ -995,6 +1104,21 @@ 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");
+		cg_window_set_heap_value (window, values, G_TYPE_BOOLEAN,
+					  "Headings", "py_headings");
+		cg_element_editor_set_values (priv->editor_py_methods, "Methods", values,
+					      cg_window_py_methods_transform_func,
+                                              window, "Name", "Arguments");
+		cg_element_editor_set_values (priv->editor_py_constvars, "Constvars",
+					      values,
+					      cg_window_py_constvars_transform_func,
+					      window, "Name", "Value");
+		break;
 	default:
 		g_assert_not_reached ();
 		break;
@@ -1045,6 +1169,8 @@ cg_window_get_header_template (CgWindow *window)
 		return CC_HEADER_TEMPLATE;
 	case 1:
 		return GO_HEADER_TEMPLATE;
+	case 2: /* Python */
+		return PY_SOURCE_TEMPLATE;
 	default:
 		g_assert_not_reached ();
 		return NULL;
@@ -1082,6 +1208,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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]