Darkbolt
04-03-2007, 12:27 PM
Hello there,
Ive begun poking my nose into gtk#...Not for any commercial reason, just because i'm bored
Ive written a hello world program that should also count the number of times a button has been pressed as well as be able to reset the counter. Rather straight forward, right?
It compiles fine, but when go to run it, absolutely nothing, no window, no error output, nothing.
Edit --
I should note that the functionality(none) is the same with or without the commented parts being commented.
I've searched around the mono documentation and nothing looks blatantly wrong to me..
Here are some references that I've used as well
http://www.mono-project.com/GtkSharpBeginnersGuide
http://www.mono-project.com/GtkSharp:_Hello_World
http://www.go-mono.com/docs/index.aspx?link=ecmaspec%3a17
Heres the C# source code
using System;
using Gtk;
using Glade;
public class hello_world
{
// Widget declarations
[Widget] Gtk.Label helloLbl;
[Widget] Gtk.Label countLbl;
// Unsure if these need to be declared or not
// [Widget] Gtk.Button whoBtn;
// [Widget] Gtk.Button resetBtn;
string updatedHelloText = "Hello World!";
string origonalText = "Hello...?";
string counterText = "This button has been clicked ";
string counterEnd = " times";
int count = 0;
public static void Main (string[] args)
{
new hello_world (args);
}
public hello_world (string[] args)
{
Application.Init();
Glade.XML gxml = new Glade.XML ("hello_world.glade", "mainWindow", null);
gxml.Autoconnect(this);
//Add the events
//I'm unsure if these events need to be added, seeing how they're declared in glade?
// whoBtn.Clicked += on_whoBtn_clicked;
// resetBtn.Clicked += on_resetBtn_clicked;
Application.Run();
}
public void on_resetBtn_clicked( object o, EventArgs e)
{
count = 0;
countLbl.Text = concatenateText();
helloLbl.Text = origonalText;
}
public void on_whoBtn_clicked( object o, EventArgs e)
{
count++;
countLbl.Text = concatenateText();
helloLbl.Text = updatedHelloText;
}
public void on_mainWindow_delete( object o, DeleteEventArgs args)
{
Application.Quit();
args.RetVal = true;
}
string concatenateText()
{
string returnString;
returnString = counterText;
returnString += count.ToString();
returnString += counterEnd;
return returnString;
}
}
Here's the glade file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.0 on Tue Apr 3 06:42:31 2007 by darkbolt@avalon-->
<glade-interface>
<widget class="GtkWindow" id="mainWindow">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="title" translatable="yes">Hello World</property>
<property name="resizable">False</property>
<child>
<widget class="GtkLayout" id="layout1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="helloLbl">
<property name="width_request">150</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Hello....?</property>
</widget>
</child>
<child>
<widget class="GtkLabel" id="countLbl">
<property name="width_request">280</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">This button has been pressed 0 times</property>
</widget>
<packing>
<property name="x">151</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="whoBtn">
<property name="width_request">100</property>
<property name="height_request">32</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Who's There
</property>
<signal name="clicked" handler="on_whoBtn_clicked"/>
</widget>
<packing>
<property name="x">41</property>
<property name="y">73</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="resetBtn">
<property name="width_request">100</property>
<property name="height_request">32</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Reset</property>
<signal name="clicked" handler="on_resetBtn_clicked"/>
</widget>
<packing>
<property name="x">247</property>
<property name="y">73</property>
</packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="x">93</property>
<property name="y">18</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
the command used to compile
mcs -pkg:glade-sharp-2.0 -resource:hello_world.glade hello_world.cs
the command used to run
mono hello_world.exe
Ive begun poking my nose into gtk#...Not for any commercial reason, just because i'm bored
Ive written a hello world program that should also count the number of times a button has been pressed as well as be able to reset the counter. Rather straight forward, right?
It compiles fine, but when go to run it, absolutely nothing, no window, no error output, nothing.
Edit --
I should note that the functionality(none) is the same with or without the commented parts being commented.
I've searched around the mono documentation and nothing looks blatantly wrong to me..
Here are some references that I've used as well
http://www.mono-project.com/GtkSharpBeginnersGuide
http://www.mono-project.com/GtkSharp:_Hello_World
http://www.go-mono.com/docs/index.aspx?link=ecmaspec%3a17
Heres the C# source code
using System;
using Gtk;
using Glade;
public class hello_world
{
// Widget declarations
[Widget] Gtk.Label helloLbl;
[Widget] Gtk.Label countLbl;
// Unsure if these need to be declared or not
// [Widget] Gtk.Button whoBtn;
// [Widget] Gtk.Button resetBtn;
string updatedHelloText = "Hello World!";
string origonalText = "Hello...?";
string counterText = "This button has been clicked ";
string counterEnd = " times";
int count = 0;
public static void Main (string[] args)
{
new hello_world (args);
}
public hello_world (string[] args)
{
Application.Init();
Glade.XML gxml = new Glade.XML ("hello_world.glade", "mainWindow", null);
gxml.Autoconnect(this);
//Add the events
//I'm unsure if these events need to be added, seeing how they're declared in glade?
// whoBtn.Clicked += on_whoBtn_clicked;
// resetBtn.Clicked += on_resetBtn_clicked;
Application.Run();
}
public void on_resetBtn_clicked( object o, EventArgs e)
{
count = 0;
countLbl.Text = concatenateText();
helloLbl.Text = origonalText;
}
public void on_whoBtn_clicked( object o, EventArgs e)
{
count++;
countLbl.Text = concatenateText();
helloLbl.Text = updatedHelloText;
}
public void on_mainWindow_delete( object o, DeleteEventArgs args)
{
Application.Quit();
args.RetVal = true;
}
string concatenateText()
{
string returnString;
returnString = counterText;
returnString += count.ToString();
returnString += counterEnd;
return returnString;
}
}
Here's the glade file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.0 on Tue Apr 3 06:42:31 2007 by darkbolt@avalon-->
<glade-interface>
<widget class="GtkWindow" id="mainWindow">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="title" translatable="yes">Hello World</property>
<property name="resizable">False</property>
<child>
<widget class="GtkLayout" id="layout1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="helloLbl">
<property name="width_request">150</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Hello....?</property>
</widget>
</child>
<child>
<widget class="GtkLabel" id="countLbl">
<property name="width_request">280</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">This button has been pressed 0 times</property>
</widget>
<packing>
<property name="x">151</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="whoBtn">
<property name="width_request">100</property>
<property name="height_request">32</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Who's There
</property>
<signal name="clicked" handler="on_whoBtn_clicked"/>
</widget>
<packing>
<property name="x">41</property>
<property name="y">73</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="resetBtn">
<property name="width_request">100</property>
<property name="height_request">32</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Reset</property>
<signal name="clicked" handler="on_resetBtn_clicked"/>
</widget>
<packing>
<property name="x">247</property>
<property name="y">73</property>
</packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="x">93</property>
<property name="y">18</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
the command used to compile
mcs -pkg:glade-sharp-2.0 -resource:hello_world.glade hello_world.cs
the command used to run
mono hello_world.exe