[Gtk-sharp-list] Change a Gtk.Label in a Gtk.MenuItem
Richard Torkar
richard.torkar@htu.se
Wed, 01 Oct 2003 09:54:28 +0200
Hi,
I'm a bit stunned here so I thought I better ask the developers on the
list directly and so that the answers to this mail will be archived for
future reference to help others.
Q: How do I change the Gtk.Label in a Gtk.MenuItem?
I have a MenuItem hidden (using .Hide()) in my application.
When an event is initiated from GConf# it means that the application
should update the MenuItem by changing the label and do a .Show ().
if (stringArray [0] != "") {
/*Show a separator in the menu*/
mySeparator.Show ();
/* It bails here the second time:(*/
foreach (Label l in myMenuItem.Children)
l.Text = stringArray [0];
myMenuItem.Show ();
}
The strange thing is that it works the _first_ time when the application
starts. It populates the MenuItem according to the setting in GConf#.
But the second time, when I use gconf-editor and change a value, thus
throwing an event, it crashes miserably (output below).
The line "Label l in myMenuItem.Children" is obviously wrong but how?
I also tried doing a:
((Label) myMenuItem.Child).Text = "foo";
But that evidently fails since Child is write-only...
I noticed that Gtk#.Button has a property Label, shouldn't this be the
case with Gtk#.MenuItem also?
(I'm well aware that Gtk does not have a gtk_menu_item_set_label)
Crash output:
(myApp:5993): GLib-GObject-WARNING **: instance of invalid
non-instantiatable type `<invalid>'
(myApp:5993): GLib-GObject-CRITICAL **: file gsignal.c: line 2490
(g_signal_emit_valist): assertion `G_TYPE_CHECK_INSTANCE (instance)'
failed
(myApp:5993): GLib-GObject-WARNING **: instance with invalid (NULL)
class pointer
(myApp:5993): GLib-GObject-CRITICAL **: file gsignal.c: line 2056
(g_signal_handlers_destroy): assertion `G_TYPE_CHECK_INSTANCE
(instance)' failed
Unhandled Exception: System.NullReferenceException: A null value was
found where an object instance was required
in (unmanaged) (wrapper managed-to-native) GLib.Object:g_object_unref
(intptr)
in <0x00004> (wrapper managed-to-native) GLib.Object:g_object_unref
(intptr)
in <0x000df> GLib.Object:GetObject (intptr,bool)
in <0x00178> .ListEnumerator:get_Current ()
in <0x00148> myApp.Replica.AbstractApp:SetUpMenu (string[])
in <0x00211> myApp.Replica.TextApp:OnPreferenceChanged
(object,System.ComponentModel.PropertyChangedEventArgs)
in <0x0005a> (wrapper delegate-invoke)
System.MulticastDelegate:invoke_void_object_PropertyChangedEventArgs
(object,System.ComponentModel.PropertyChangedEventArgs)
in <0x00046> myApp.Preferences:OnRecentDocumentsNotify
(object,GConf.NotifyEventArgs)
in <0x0005a> (wrapper delegate-invoke)
System.MulticastDelegate:invoke_void_object_NotifyEventArgs
(object,GConf.NotifyEventArgs)
in <0x00118> GConf.NotifyWrapper:NotifyCB (intptr,uint,intptr,intptr)
in <0x00047> (wrapper native-to-managed) GConf.NotifyWrapper:NotifyCB
(intptr,uint,intptr,intptr)
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 <0x00007> Gnome.Program:Run ()
in <0x00195> myApp:Main (string[])
Grateful for any explanation... I'm going nuts.
/Richard
--
"UNIX is basically a simple operating system,
but you have to be a genius to understand the simplicity."