[Glade-users] Using Glade with Clist

Andrae Muys amuys@shortech.com.au
Tue, 06 Feb 2001 15:04:33 +1000


This is a multi-part message in MIME format.
--------------76BA38D4A2CE3C64946DB9A3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

RJ Krawchuk wrote:
> 
> Hi,
> 
> No matter what I do, I can not add rows to the clist widget. I have gone
> through the FAQ, Beginning GTK+/Gnome Programming book from Wrox, Web sites.
> I am stuck at this point. If anyone could help me or point me in the right
> direction to find how I could do this, I would really appreciate it.
> 
What is the error you're getting?  I just quickly knocked up a test
application that does exactly what your sample code does.  It's only 35
lines of code including whitespace so it should be easy enough to
understand.

Code and supporting Makefile/.glade file attached.

Andrae
--------------76BA38D4A2CE3C64946DB9A3
Content-Type: text/plain; charset=us-ascii;
 name="clisttest.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="clisttest.c"

/*
 * File : clisttest.c
 *
 * Description : Simple application to demonstrate the use of CList's and 
 *         libglade.
 *
 * Dependencies : clisttest.glade
 *
 * Author : Andrae Muys <andrae@humbug.org.au>
 *
 * Date : 6th Feburary 2001
 *
 * License : GPL.
 *
 */

#include <gtk/gtk.h>
#include <glade/glade.h>

#define FILENAME "clisttest.glade"

GladeXML *xml;

int main(int argc, char *argv[]) {
	gtk_init(&argc, &argv);
	glade_init();

	xml = glade_xml_new(FILENAME, "mainWindow");
	if(!xml) {
		g_warning("Could not load interface.");
		return 1;
	}

	glade_xml_signal_autoconnect(xml);
	gtk_object_unref(GTK_OBJECT(xml));

	gtk_main();

	return 0;
}

//static gchar *row[4] = { "Test 1", "Test 2", "Test 3", "Test 4" };

void on_clist_realize(GtkWidget *widget, gpointer data) {
	gchar *row[4];

	row[0] = "Test 1";
	row[1] = "Test 2";
	row[2] = "Test 3";
	row[3] = "Test 4";

	gtk_clist_append(GTK_CLIST(widget), row);
}

--------------76BA38D4A2CE3C64946DB9A3
Content-Type: text/html; charset=us-ascii;
 name="clisttest.glade"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="clisttest.glade"

<?xml version="1.0"?>
<GTK-Interface>

<project>
  <name>clisttest</name>
  <program_name>clisttest</program_name>
  <directory></directory>
  <source_directory>src</source_directory>
  <pixmaps_directory>pixmaps</pixmaps_directory>
  <language>C</language>
  <gnome_support>True</gnome_support>
  <gettext_support>True</gettext_support>
</project>

<widget>
  <class>GtkWindow</class>
  <name>mainWindow</name>
  <width>400</width>
  <height>150</height>
  <signal>
    <name>delete_event</name>
    <handler>gtk_main_quit</handler>
    <last_modification_time>Tue, 06 Feb 2001 04:46:42 GMT</last_modification_time>
  </signal>
  <title>window1</title>
  <type>GTK_WINDOW_TOPLEVEL</type>
  <position>GTK_WIN_POS_NONE</position>
  <modal>False</modal>
  <allow_shrink>False</allow_shrink>
  <allow_grow>True</allow_grow>
  <auto_shrink>False</auto_shrink>

  <widget>
    <class>GtkVBox</class>
    <name>vbox1</name>
    <homogeneous>False</homogeneous>
    <spacing>0</spacing>

    <widget>
      <class>GtkScrolledWindow</class>
      <name>scrolledwindow1</name>
      <hscrollbar_policy>GTK_POLICY_ALWAYS</hscrollbar_policy>
      <vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy>
      <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
      <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
      <child>
	<padding>0</padding>
	<expand>True</expand>
	<fill>True</fill>
      </child>

      <widget>
	<class>GtkCList</class>
	<name>clist</name>
	<can_focus>True</can_focus>
	<columns>4</columns>
	<column_widths>80,80,80,80</column_widths>
	<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
	<show_titles>True</show_titles>
	<shadow_type>GTK_SHADOW_IN</shadow_type>

	<widget>
	  <class>GtkLabel</class>
	  <child_name>CList:title</child_name>
	  <name>label1</name>
	  <label>label1</label>
	  <justify>GTK_JUSTIFY_CENTER</justify>
	  <wrap>False</wrap>
	  <xalign>0.5</xalign>
	  <yalign>0.5</yalign>
	  <xpad>0</xpad>
	  <ypad>0</ypad>
	</widget>

	<widget>
	  <class>GtkLabel</class>
	  <child_name>CList:title</child_name>
	  <name>label2</name>
	  <label>label2</label>
	  <justify>GTK_JUSTIFY_CENTER</justify>
	  <wrap>False</wrap>
	  <xalign>0.5</xalign>
	  <yalign>0.5</yalign>
	  <xpad>0</xpad>
	  <ypad>0</ypad>
	</widget>

	<widget>
	  <class>GtkLabel</class>
	  <child_name>CList:title</child_name>
	  <name>label3</name>
	  <label>label3</label>
	  <justify>GTK_JUSTIFY_CENTER</justify>
	  <wrap>False</wrap>
	  <xalign>0.5</xalign>
	  <yalign>0.5</yalign>
	  <xpad>0</xpad>
	  <ypad>0</ypad>
	</widget>

	<widget>
	  <class>GtkLabel</class>
	  <child_name>CList:title</child_name>
	  <name>label4</name>
	  <label>label4</label>
	  <justify>GTK_JUSTIFY_CENTER</justify>
	  <wrap>False</wrap>
	  <xalign>0.5</xalign>
	  <yalign>0.5</yalign>
	  <xpad>0</xpad>
	  <ypad>0</ypad>
	</widget>
      </widget>
    </widget>

    <widget>
      <class>GtkHButtonBox</class>
      <name>hbuttonbox1</name>
      <layout_style>GTK_BUTTONBOX_SPREAD</layout_style>
      <spacing>30</spacing>
      <child_min_width>85</child_min_width>
      <child_min_height>27</child_min_height>
      <child_ipad_x>7</child_ipad_x>
      <child_ipad_y>0</child_ipad_y>
      <child>
	<padding>0</padding>
	<expand>False</expand>
	<fill>False</fill>
      </child>

      <widget>
	<class>GtkButton</class>
	<name>button1</name>
	<can_default>True</can_default>
	<can_focus>True</can_focus>
	<signal>
	  <name>clicked</name>
	  <handler>on_clist_realize</handler>
	  <object>clist</object>
	  <last_modification_time>Tue, 06 Feb 2001 04:51:06 GMT</last_modification_time>
	</signal>
	<label>Append</label>
      </widget>

      <widget>
	<class>GtkButton</class>
	<name>button2</name>
	<can_default>True</can_default>
	<can_focus>True</can_focus>
	<signal>
	  <name>clicked</name>
	  <handler>gtk_main_quit</handler>
	  <last_modification_time>Tue, 06 Feb 2001 04:49:36 GMT</last_modification_time>
	</signal>
	<label>Quit</label>
      </widget>
    </widget>
  </widget>
</widget>

</GTK-Interface>

--------------76BA38D4A2CE3C64946DB9A3
Content-Type: text/plain; charset=us-ascii;
 name="Makefile"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Makefile"

CC=gcc
DEBUG=-g
CFLAGS=$(DEBUG) -W -Wall -ansi-pedantic `gnome-config --cflags glib gtk libglade`
LDFLAGS=`gnome-config --libs glib gtk libglade`

all: clisttest

clisttest: clisttest.o
	$(CC) $(LDFLAGS) -o $@ $^

--------------76BA38D4A2CE3C64946DB9A3--