tags:

views:

159

answers:

2

I've been trying to get started with Mono & GTK# (I come from a background of Qt/C++ GUI programming) and decided to start with a very simple test GUI.

I installed the MS Windows Mono/GTK# installer and then, upon finding that the Start menu link to Glade didn't work (as it didn't appear to be included in the package), I used the "Glade with GTK+" Windows binary installer from the Glade website.

I then created a very simple GUI in Glade (at the bottom of this post) and wrote my first bit of C# code to display it. However, it doesn't seem to be working properly.

The "Hello, World!" is printed to the console correctly and then the program hangs without the window appearing or any error messages being printed. It seems as if the window has been created and the event loop has started but that it is not being made visible. I've tried removing the first null from the new Glade.XML line and not including the glade file as a resource, but that made no difference.

I've also tried replacing the Glade GUI xml with the one on the GtkSharpBeginnersGuide on the mono website (and changing wndTestWindow to window1 in the C# code) and it seems to work perfectly implying that there's a problem with my Glade XML. However, I'm finding it hard to figure out what's wrong with the XML created by my Glade installation. Can anyone offer any suggestions?

Glade GUI:

<?xml version="1.0"?>
<glade-interface>
  <!-- interface-requires gtk+ 2.12 -->
  <!-- interface-naming-policy project-wide -->
  <widget class="GtkWindow" id="wndTestWindow">
    <property name="title" translatable="yes">Test Window</property>
    <property name="window_position">center</property>
    <child>
      <widget class="GtkVBox" id="vboxTopLevel">
        <property name="visible">True</property>
        <property name="orientation">vertical</property>
        <child>
          <widget class="GtkHBox" id="hboxComboList">
            <property name="visible">True</property>
            <child>
              <widget class="GtkLabel" id="lblList">
                <property name="visible">True</property>
                <property name="label" translatable="yes">Here's a list:</property>
              </widget>
              <packing>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <widget class="GtkComboBox" id="cmbList">
                <property name="visible">True</property>
              </widget>
              <packing>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <widget class="GtkButton" id="btnList">
                <property name="label" translatable="yes">Do something</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
              </widget>
              <packing>
                <property name="position">2</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <widget class="GtkHButtonBox" id="hbtnboxButtonRow">
            <property name="visible">True</property>
            <child>
              <widget class="GtkButton" id="btnOK">
                <property name="label">gtk-ok</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </widget>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <widget class="GtkButton" id="btnCancel">
                <property name="label">gtk-cancel</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </widget>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">1</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>

C# Test Code:

using Glade;
using Gtk;
using System;

class TestApplication
{
    static void Main(string[] args)
    {
        System.Console.Write("Hello, World!\n");
        new TestApplication(args);
    }

    public TestApplication(string[] args)
    {
        Gtk.Application.Init();

        Glade.XML gxml = new Glade.XML(null, "test_mono.glade", "wndTestWindow", null);
        gxml.Autoconnect(this);
        Gtk.Application.Run();
    }
}

Compiled and run with:

mcs -pkg:glade-sharp-2.0 -resource:test_mono.glade test_mono.cs
mono .\test_mono.exe

Versions:

Windows: XP Service Pack 3 Glade: 3.6.7 MCS Version 2.6.7.0 Mono & GTK# installed using mono-2.6.7-gtksharp-2.12.10-win32-2.exe from the Mono website.

Compiled & tested both using cygwin and the "Mono-2.6.7 Command Prompt".

+1  A: 

You might want to look at downloading MonoDevelop for Windows. Gtk# hasn't really used Glade in a long time. Generally it uses Stetic, which has a designer built into MonoDevelop.

http://monodevelop.com/

jpobst
Thanks, but it looks like Stetic is very difficult to use unless you want to use MonoDevelop for everything (which I don't). I tried loading it to just create a GUI with Stetic, but couldn't find a way of doing so without creating a whole project. I'm quite happy with the IDE I use: I don't like having to use a different IDE for different languages.
NPB
+3  A: 

Try adding <property name="visible">True</property> to your root widget so that it reads:

<?xml version="1.0"?>
<glade-interface>
  <!-- interface-requires gtk+ 2.12 -->
  <!-- interface-naming-policy project-wide -->
  <widget class="GtkWindow" id="wndTestWindow">
    <property name="visible">True</property>
    <property name="title" translatable="yes">Test Window</property>
    <property name="window_position">center</property>
    <child>

In Glade the property can be found under the Common properties tab for the window.

stoft
Brilliant, that was it: thank you. I don't have enough reputation to vote, but I've accepted the answer.
NPB