[Gtk-sharp-list] Glade# bug?
David Makovský (Yakeen)
yakeen@sannyas-on.net
Fri, 16 Jan 2004 13:20:41 +0100
--=-6ywOW/jkBUXh1u1vkLj7
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Hi all,
I found out strange behaviour of glade generated widget with Style.
I wrote a dialog class that fits better with HIG for my application.
In the time there was decision to run it withot windowmanager, so I had
to change color of dialog. After some time application fall with
NullReferenceException. I was uasing Glade for constructing widgets.
I rewrote this into native Gtk# classes and everithing was ok.
Now when I have more time to test it I made a test case (attachments),
with glade and native clasess.
I found out that everithing goes well until I use Style class.
When I run it Glade variant is going well till you run it for eight
time. Then it falls with:
Unhandled Exception: System.NullReferenceException: A null value was
found where an object instance was required
in (unmanaged) (wrapper managed-to-native) Gtk.Widget:gtk_widget_destroy
(intptr)
in <0x00004> (wrapper managed-to-native) Gtk.Widget:gtk_widget_destroy
(intptr)
in <0x0001f> Gtk.Widget:Destroy ()
in <0x001da> TestDialogs.GuiAlertGlade:.ctor (string,string)
in <0x00032> TestDialogs.TestWindow:GladeClicked
(object,System.EventArgs)
in <0x0006d> (wrapper delegate-invoke)
System.MulticastDelegate:invoke_void_object_EventArgs
(object,System.EventArgs)
in <0x0012b> GtkSharp.voidObjectSignal:voidObjectCallback (intptr,int)
in <0x00030> (wrapper native-to-managed)
GtkSharp.voidObjectSignal:voidObjectCallback (intptr,int)
in (unmanaged) (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00004> (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00007> Gtk.Application:Run ()
in <0x00228> TestDialogs.TestWindow:.ctor ()
in <0x00025> TestDialogs.Run:Main (string[])
That's strange why for eight time?
Can you try it and say if you see where is bug.
I want to be sure that it's not in my code before using bugzilla.
Thanks
--
David Makovský (Yakeen) <yakeen@sannyas-on.net>
--=-6ywOW/jkBUXh1u1vkLj7
Content-Disposition: attachment; filename=Dialogs.cs
Content-Type: text/x-csharp; name=Dialogs.cs; charset=UTF-8
Content-Transfer-Encoding: 8bit
//**********************************************************************
// Namespace TestDialogs
// Class GuiAlertNative, GuiAlertGlade
//
// Authors:
// David Makovský (yakeen@sannyas-on.net)
//
// You can use and redistribute this code under GPL2
//
//**********************************************************************
namespace TestDialogs{
using System;
using Gtk;
using GtkSharp;
public class GuiAlertNative : Gtk.Dialog {
const string MARKUP_PRE = "<span color='#000000' size='x-large' weight='bold'>";
const string MARKUP_POST = "</span>";
Style style;
public GuiAlertNative(string s, string m) : base () {
Title = "Warning";
WindowPosition = Gtk.WindowPosition.Center;
HasSeparator = false;
Resizable = false;
ActionArea.Layout = Gtk.ButtonBoxStyle.End;
Gtk.Button ok = new Button(Gtk.Stock.Ok);
AddActionWidget(ok, (int)Gtk.ResponseType.Ok);
Gtk.Table space = new Table (1, 1, false);
space.BorderWidth = 8;
VBox.Add(space);
Gtk.Table table = new Table (1, 2, false);
table.ColumnSpacing = 8;
space.Attach(table, 0, 1, 0, 1);
Gtk.Image image = new Image(Gtk.Stock.DialogWarning, Gtk.IconSize.Dialog);
table.Attach(image, 0, 1, 0, 1);
Gtk.Label label = new Gtk.Label(MARKUP_PRE + s + MARKUP_POST + "\n\n" + m);
label.UseMarkup = true;
table.Attach(label, 1, 2, 0, 1);
style = Style.Copy ();
Style = style;
StyleSet += new StyleSetHandler (NativeStyleSet);
ShowAll();
Run ();
Destroy ();
}
private void NativeStyleSet (object obj, StyleSetArgs args) {
style.SetBackgroundGC (StateType.Normal, Style.BackgroundGCs[1]);
}
}
public class GuiAlertGlade{
const string MARKUP_PRE = "<span color='#000000' size='x-large' weight='bold'>";
const string MARKUP_POST = "</span>";
Style style;
Glade.XML gxml;
[Glade.Widget] Gtk.Dialog hig_message_dialog;
[Glade.Widget] Gtk.Label info_label;
[Glade.Widget] Gtk.Image image;
public GuiAlertGlade(string s, string m){
string text = MARKUP_PRE + s + MARKUP_POST + "\n\n" + m;
gxml = new Glade.XML (null, "dialog.glade", "hig_message_dialog", null);
gxml.Autoconnect (this);
hig_message_dialog.Title = "Warning";
info_label.Text = text;
info_label.UseMarkup = true;
image.Stock = Gtk.Stock.DialogWarning;
hig_message_dialog.WindowPosition = Gtk.WindowPosition.Center;
style = hig_message_dialog.Style.Copy ();
hig_message_dialog.Style = style;
hig_message_dialog.StyleSet += new StyleSetHandler (GladeStyleSet);
GladeStyleSet (null, null);
hig_message_dialog.Run ();
hig_message_dialog.Destroy ();
}
private void GladeStyleSet (object obj, StyleSetArgs args) {
style.SetBackgroundGC (StateType.Normal, hig_message_dialog.Style.BackgroundGCs[1]);
}
}
}
--=-6ywOW/jkBUXh1u1vkLj7
Content-Disposition: attachment; filename=Makefile
Content-Type: text/x-sh; name=Makefile; charset=UTF-8
Content-Transfer-Encoding: 7bit
SHELL = /bin/sh
MCS=/usr/bin/mcs
RUNTIME=/usr/bin/mono
MONORESGEN=/usr/bin/monoresgen
srcdir = .
top_srcdir = .
prefix = /usr
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
sbindir = ${exec_prefix}/sbin
libexecdir = ${exec_prefix}/libexec
datadir = ${prefix}/share
sysconfdir = ${prefix}/etc
sharedstatedir = ${prefix}/com
localstatedir = ${prefix}/var
libdir = ${exec_prefix}/lib
infodir = ${prefix}/info
mandir = ${prefix}/man
includedir = ${prefix}/include
oldincludedir = /usr/include
pkgdatadir = $(datadir)/euwe
pkglibdir = $(libdir)/euwe
pkgincludedir = $(includedir)/euwe
top_builddir = .
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_SCRIPT = ${INSTALL}
INSTALL_HEADER = $(INSTALL_DATA)
transform = s,x,x,
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_alias =
build_triplet = i686-pc-linux-gnu
host_alias =
host_triplet = i686-pc-linux-gnu
target_alias =
target_triplet = i686-pc-linux-gnu
OBJEXT = o
PATH_SEPARATOR = :
EXEEXT = .exe
MCSFLAGS = --unsafe -codepage:utf8
#/d:DEBUG
ASSEMBLIES = pango-sharp\
gtk-sharp \
glib-sharp \
gdk-sharp \
glade-sharp \
gnome-sharp \
art-sharp \
System \
mscorlib
ASSEMBLIES_ALL = $(addsuffix .dll, $(addprefix /r:, $(ASSEMBLIES)))
FLAGS = $(MCSFLAGS) $(ASSEMBLIES_ALL)
COMPILE = $(MCS) $(FLAGS)
all: linux
linux: Dialogs.dll Test.exe
Dialogs.dll:
$(COMPILE) /target:library Dialogs.cs /resource:dialog.glade -o Dialogs.dll
Test.exe:
$(COMPILE) -r Dialogs.dll /target:winexe Test.cs -o Test.exe
clean:
rm -f *.exe
rm -f *.dll
--=-6ywOW/jkBUXh1u1vkLj7
Content-Disposition: attachment; filename=Test.cs
Content-Type: text/x-csharp; name=Test.cs; charset=UTF-8
Content-Transfer-Encoding: 8bit
//**********************************************************************
// Namespace TestDialogs
// Test Case
//
// Authors:
// David Makovský (yakeen@sannyas-on.net)
//
// You can use and redistribute this code under GPL2
//
//**********************************************************************
namespace TestDialogs{
using System;
using Gtk;
using GtkSharp;
//using Gnome;
class TestWindow {
public TestWindow() {
Application.Init ();
Window win = new Window ("Test App");
win.WindowPosition = Gtk.WindowPosition.Center;
win.Resizable = false;
win.DeleteEvent += new DeleteEventHandler (Destroy);
VBox vbox = new VBox(true, 8);
vbox.BorderWidth = 8;
win.Add(vbox);
Button native = new Button("Native dialog");
native.Clicked += new EventHandler (NativeClicked);
vbox.PackEnd(native);
Button glade = new Button("Glade dialog");
glade.Clicked += new EventHandler (GladeClicked);
vbox.PackEnd(glade);
win.ShowAll();
Application.Run ();
}
private static void NativeClicked (object obj, EventArgs args) {
GuiAlertNative alert = new GuiAlertNative ("Native C# way of Dialog", "some more desription...");
}
private static void GladeClicked (object obj, EventArgs args) {
GuiAlertGlade alert = new GuiAlertGlade ("Glade C# way of Dialog", "some more desription...");
}
private void Destroy (object obj, DeleteEventArgs args) {
Window win = (Window)obj;
win.Destroy();
Application.Quit();
}
}
class Run{
public static void Main(string [] args){
TestWindow win = new TestWindow();
return;
}
}
}
--=-6ywOW/jkBUXh1u1vkLj7
Content-Disposition: attachment; filename=dialog.glade
Content-Type: text/xml; name=dialog.glade; charset=UTF-8
Content-Transfer-Encoding: 7bit
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<requires lib="gnome"/>
<widget class="GtkDialog" id="hig_message_dialog">
<property name="visible">True</property>
<property name="title" translatable="yes">dialog1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="modal">False</property>
<property name="resizable">False</property>
<property name="destroy_with_parent">True</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox25">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area25">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="okbutton19">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table272">
<property name="border_width">8</property>
<property name="visible">True</property>
<property name="n_rows">1</property>
<property name="n_columns">1</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">0</property>
<child>
<widget class="GtkTable" id="table273">
<property name="border_width">8</property>
<property name="visible">True</property>
<property name="n_rows">1</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">8</property>
<child>
<widget class="GtkImage" id="image">
<property name="visible">True</property>
<property name="stock">gtk-dialog-warning</property>
<property name="icon_size">6</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="info_label">
<property name="visible">True</property>
<property name="label" translatable="yes"><span size='xx-large' weight='bold'>test text test text </span>
test text test text test text test text </property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">shrink|fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
--=-6ywOW/jkBUXh1u1vkLj7--