[Gtk-sharp-list] Frame in Frame assertion errors

vanosten rick@vanosten.net
07 Jan 2003 18:00:14 +0100


Hi

I am observing a strange behaviour in my application: I get assertion
errors in some situations when a Frame is inside a Frame
To better describe the problem (it took me hours to get to the point) I
made a sample application, which is a very stripped down version of mye
original app.

# When the program is compiled as is then everything works fine (i.e. a
click on MenuItem "Replace" replaces the central widget with a new one.
# When line 96 is no more commented then I get the following error in
the command window, but everything else works as expected:
(<unknown>:26766): Gtk-CRITICAL **: file gtkcontainer.c: line 845
(gtk_container_add): assertion `GTK_IS_CONTAINER (container)' failed
# When additionally line 83 instead of line 84 is commented out then I
both get the following assertion errors and the label "Smile" is not
shown (instead of label "Look"):
(<unknown>:26770): Gtk-CRITICAL **: file gtkcontainer.c: line 845
(gtk_container_add): assertion `GTK_IS_CONTAINER (container)' failed

(<unknown>:26770): Gtk-CRITICAL **: file gtkbox.c: line 359
(gtk_box_pack_start): assertion `GTK_IS_WIDGET (child)' failed

=> Does this mean that the use of Frame inside of Frame is a bad idea?
What should I use instead? (Ultimately the method
"EditView::InitializeMainF" should be abstract and WelcomeView would
implement it - but this is another story ;-)


I am using gtk# 0.6, mono 0.17 in debian unstable (i386).

using System;
using System.Collections;
using System.Text;

using Gtk;
using GtkSharp;

public class MyApp : Window {

    private Widget mainWidget;
    private VBox mainBox;
    private int count = 1;

    public MyApp(string title) : base(title) {
        this.SetDefaultSize(800, 600); //width, height
        this.DeleteEvent += new DeleteEventHandler(OnWindowDelete);
        mainBox = new VBox(false, 2);
        
        //menu bar with one menu
        MenuBar mb = new MenuBar();
        Menu fileMenu = new Menu();
        MenuItem fileMenuMI = new MenuItem("_File");
        MenuItem replaceMI = new MenuItem("_Replace");
        replaceMI.Activated += new EventHandler(OnReplace);
        mb.Append(fileMenuMI);
        fileMenuMI.Submenu = fileMenu;
        fileMenu.Append(replaceMI);
        mainBox.PackStart(mb, false, false, 0);
        
        //rest of gui
        this.SetMainView(new WelcomeView(count));
        this.Add(mainBox);
        this.ShowAll();
    } //END public DMyApp(string)

    public static int Main(string[] args) {
        Application.Init();
        MyApp app = new MyApp("Hello");
        Application.Run();
        return 0;
    } //END public static int Main(string[])

    private void SetMainView(Frame aFrame) {
        //remove existing
        if (null != mainWidget) {
            mainBox.Remove(mainWidget);
            Console.WriteLine("Removed widget");
        }
        mainWidget = aFrame;
        //add new
        mainBox.PackStart(aFrame, true, true, 0);
        Console.WriteLine("Added frame");
        aFrame.ShowAll();
    } //private void SetMainView(Frame)

    //---- EventHandlers -------------------------------------/
    
    private void OnWindowDelete(object obj, DeleteEventArgs args) {
        Application.Quit();
        args.RetVal = true;
    }   //END private void OnWindowDelete(object, DeleteEventArgs)
    
    private void OnReplace(object o, EventArgs args) {
        count++;
        this.SetMainView(new WelcomeView(count));;
    } //private void OnReplace(object, EventArgs)
} //END public class MyApp : Window

public class WelcomeView : EditView {
    
    public WelcomeView(int aCount) : base("Replace me: " + aCount) {
    } //END public WelcomeView()
} //END public class WelcomeView : EditView

public class EditView : Frame {
    
    private Frame mainF;
        
    public EditView(string aTitle) : base(aTitle) {
        VBox vbox = new VBox(false, 5);
        mainF = new Frame();
        InitializeMainF();
        vbox.PackStart (new Label("Look"), true, true, 5);
        //vbox.PackStart (mainF, true, true, 5);
        
        //ButtonBox
        HButtonBox buttonBox = new HButtonBox();
        Button addB = new Button("_Add");
        buttonBox.Add(addB);
        vbox.PackStart(buttonBox, true, false, 5);

        this.Add(vbox);
    } //END public WelcomeView()
    
    private void InitializeMainF() {
        //mainF.Add(new Label("Smile"));
    } //END private void InitializeMainF()
} //END public EditView : Frame