View previous topic :: View next topic |
Author |
Message |
heromyth
Joined: 26 Nov 2006 Posts: 46
|
Posted: Sun Nov 02, 2008 9:33 pm Post subject: [Resolved]Help treeview with GdkPixbuf Cell Renderers |
|
|
I want to show a image in a TreeView, so I have a demo which is modified from gtkD-1.0\demos\gtkD\DemoMultiCellRenderer\DemoMultiCellRenderer.d. Here is it:
Code: |
module DemoMultiCellRenderer;
import gtk.Main;
import gdk.Event;
import gtk.Window;
import gtk.Widget;
import gtk.TreeIter;
import gtk.TreePath;
import gtk.TreeView;
import gtk.TreeViewColumn;
import gtk.CellRendererText;
import gtk.CellRendererToggle;
import gtk.CellRendererPixbuf;
import gtk.MessageDialog;
import gtk.ListStore;
import gtk.Button;
import gtk.VBox;
import gtk.Image;
import gdk.Pixbuf;
import std.stdio;
import std.c.stdlib;
import gobject.Value;
enum {
COLUMN_NAME,
COLUMN_TEXT,
COLUMN_TEXT_VISIBLE,
COLUMN_BOOL,
COLUMN_BOOL_VISIBLE,
COLUMN_PIXBUF
}
void main(){
Main.init(null);
ListStore store = new ListStore( [
GType.STRING,
GType.STRING,
GType.INT,
GType.INT,
GType.INT,
Pixbuf.getType()] );
void appendRecord( string name, string value, bool isBoolean, Value v ){
auto it = store.createIter();
store.setValue( it, COLUMN_NAME, name );
store.setValue( it, COLUMN_TEXT, value );
store.setValue( it, COLUMN_TEXT_VISIBLE, !isBoolean );
store.setValue( it, COLUMN_BOOL, value == "true" );
store.setValue( it, COLUMN_BOOL_VISIBLE, isBoolean );
store.setValue( it, COLUMN_PIXBUF, v );
}
// fill store with data
Pixbuf pbuf = new Pixbuf("test.png");
if(pbuf is null)
{
writefln("test.png is not exist!");
exit(1);
}
else
writefln("pbuf is not null.");
Value tempValue = new Value(pbuf);
appendRecord( "Loops", "10", false, tempValue );
appendRecord( "Name", "keinfarbton", false, tempValue );
appendRecord( "Verbose", "true", true, tempValue );
auto wnd = new Window( "Celleditor Demo" );
auto tv = new TreeView();
void popupMsg(Button button)
{
MessageDialog d = new MessageDialog(wnd, GtkDialogFlags.MODAL,
MessageType.INFO, ButtonsType.OK, "My name is " ~ button.getLabel());
d.run();
d.destroy();
}
//Button button = new Button("vvvv", &popupMsg);
// Pixbuf pbuf = new Pixbuf("test.png");
auto image = new Image(pbuf);
//auto image = new Image("test.gif");
VBox vbox = new VBox(true, 2);
vbox.packStartDefaults(tv);
vbox.packStartDefaults(image);
wnd.add(vbox);
// create first column with text renderer
TreeViewColumn column = new TreeViewColumn();
column.setTitle( "Name" );
tv.appendColumn(column);
CellRendererText cell_text = new CellRendererText();
column.packStart(cell_text, 0 );
column.addAttribute(cell_text, "text", COLUMN_NAME);
// create second column with two renderers
column = new TreeViewColumn();
column.setTitle( "Value" );
tv.appendColumn(column);
CellRendererToggle cell_bool = new CellRendererToggle();
column.packStart(cell_bool, 0 );
column.addAttribute(cell_bool, "active", COLUMN_BOOL);
column.addAttribute(cell_bool, "visible", COLUMN_BOOL_VISIBLE);
cell_text = new CellRendererText();
column.packStart(cell_text, 0 );
column.addAttribute(cell_text, "text", COLUMN_TEXT);
column.addAttribute(cell_text, "visible", COLUMN_TEXT_VISIBLE);
cell_text.setProperty( "editable", 1 );
// change value in store on toggle event
cell_bool.addOnToggled( delegate void(string p, CellRendererToggle){
auto path = new TreePath( p );
auto it = new TreeIter( store, path );
store.setValue(it, COLUMN_BOOL, it.getValueInt( COLUMN_BOOL ) ? 0 : 1 );
});
// change the text in the store on end of edit
cell_text.addOnEdited( delegate void(string p, string v, CellRendererText cell ){
auto path = new TreePath( p );
auto it = new TreeIter( store, path );
store.setValue( it, COLUMN_TEXT, v );
});
column = new TreeViewColumn();
column.setTitle( "Image" );
auto cell_pixbuf = new CellRendererPixbuf();
column.packStart(cell_pixbuf, false);
column.addAttribute(cell_pixbuf, "pixbuf", COLUMN_PIXBUF);
tv.appendColumn(column);
tv.setModel(store);
wnd.showAll();
wnd.addOnDelete( delegate bool (Event event, Widget widget) {
widget.destroy();
Main.quit();
return false;
});
Main.run();
}
|
It seems everything is OK. However, I can't see my image
And found some definitions are missing, for example:
Code: | GDK_TYPE_PIXBUF, GTK_TYPE_COMBO_BOX |
These can be used like this in gtk+:
Code: | store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, GTK_TYPE_COMBO_BOX); |
Thank you for any help!
Last edited by heromyth on Sat Nov 08, 2008 5:08 am; edited 2 times in total |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Tue Nov 04, 2008 1:00 pm Post subject: |
|
|
If i remember correctly the value GDK_TYPE_PIXBUF and GTK_TYPE_COMBO_BOX are defined at runtime. we'll probably need gtk_combo_box_get_type and gdk_pixbuf_get_type wrapped to get there values. |
|
Back to top |
|
|
heromyth
Joined: 26 Nov 2006 Posts: 46
|
Posted: Wed Nov 05, 2008 8:21 am Post subject: |
|
|
Mike Wey wrote: | If i remember correctly the value GDK_TYPE_PIXBUF and GTK_TYPE_COMBO_BOX are defined at runtime. we'll probably need gtk_combo_box_get_type and gdk_pixbuf_get_type wrapped to get there values. |
I got it!
In GTK\include\gtk-2.0\gdk-pixbuf\gdk-pixbuf-core.h, GDK_TYPE_PIXBUF has been defined as:
Code: | #define GDK_TYPE_PIXBUF (gdk_pixbuf_get_type ()) |
|
|
Back to top |
|
|
heromyth
Joined: 26 Nov 2006 Posts: 46
|
Posted: Wed Nov 05, 2008 8:37 am Post subject: |
|
|
Of course, there is a example in gtkD-1.0\demos\gtkD\TestWindow\TestTreeView1.d. It's also illustrated that how to using TreeView with GdkPixbuf Cell Renderers.
When running TestWindow.exe under WinXP SP2, the pictures are still missing. Is it a bug with gtkD? Sorry for that I'm not sure whether it works under Linux.
I have created a C program to test the GTK+'s DLL, and everything seems OK. |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Wed Nov 05, 2008 1:35 pm Post subject: |
|
|
It looks like Pixbuf.getType() is actually wrapped.
Quote: | When running TestWindow.exe under WinXP SP2, the pictures are still missing. Is it a bug with gtkD? Sorry for that I'm not sure whether it works under Linux. |
It works on Linux. |
|
Back to top |
|
|
heromyth
Joined: 26 Nov 2006 Posts: 46
|
Posted: Thu Nov 06, 2008 1:13 am Post subject: |
|
|
Mike Wey wrote: |
Quote: | When running TestWindow.exe under WinXP SP2, the pictures are still missing. Is it a bug with gtkD? Sorry for that I'm not sure whether it works under Linux. |
It works on Linux. |
Ok, I'll try to find out what happend. |
|
Back to top |
|
|
heromyth
Joined: 26 Nov 2006 Posts: 46
|
Posted: Sat Nov 08, 2008 5:06 am Post subject: |
|
|
I think I have found the reasons.
In gtkD, the output of GValue.sizeof is 20. However, in gtk, sizeof(GValue) is 24.
So I got rid of the align(4) in 'struct GValue' in gtkD-1.0\src\gtkc\gobjecttypes.d. It seems everythins is OK. Now, the GValue.sizeof is 24. Here is the new definition of 'struct GValue':
Code: | struct GValue
{
GType g_type;
union Data
{
gint v_int;
guint v_uint;
glong v_long;
gulong v_ulong;
gint64 v_int64;
guint64 v_uint64;
gfloat v_float;
gdouble v_double;
gpointer v_pointer;
};
Data data1;
Data data2;
} |
All are tested on WinXP. Sorry for no tests on Linux. |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sat Nov 08, 2008 7:52 am Post subject: |
|
|
added in svn r637
without the align(4) it stops working on linux. |
|
Back to top |
|
|
yinqiaol Guest
|
Posted: Thu Feb 10, 2011 7:45 pm Post subject: |
|
|
This is my first post on this forum so forgive any newbness pls
Like most I guess I've joined this site |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Mar 06, 2011 9:17 am Post subject: |
|
|
? |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|