gtk-sharpGtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details.GLib.ApplicationApplication class
Provides the initialization and event loop iteration related
methods for the Gtk# widget library. Since Gtk# is an event
driven toolkit, Applications register callbacks against various
events to handle user input. These callbacks are invoked from
the main event loop when events are detected.
using Gtk;
using System;
using GLib;
public class HelloWorld {
public static int Main (string[] args)
{
Application.Init ();
Gtk.Window win = new Gtk.Window ("Gtk# Hello World");
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
win.ShowAll ();
Application.Run ();
return 0;
}
static void Window_Delete (object obj, DeleteEventArgs args)
{
SignalArgs sa = (SignalArgs) args;
Application.Quit ();
sa.RetVal = true;
}
}
Constructor
Native object pointer.
Internal constructorThis is not typically used by C# code. Exposed primarily for use by language bindings to wrap native object instances.Constructor
To be added.
To be added.
To be added.To be added.MethodSystem.Void
To be added.
To be added.To be added.PropertyGdk.EventReturns the event currently taking place.a MethodSystem.BooleanWhether there are events on the queue if events are available to be processed, otherwise
Checks if any events are pending. This can be used to
update the GUI and invoke timeouts etc. while doing some
time intensive computation.
void LongComputation ()
{
while (!done){
ComputationChunk ();
// Flush pending events to keep the GUI reponsive
while (Application.EventsPending ())
Application.RunIteration ();
}
}
PropertyGLib.GTypeGType Property.The native value.Returns the native value for .MethodSystem.VoidInitializes GTK+ for operation.
Call this function before using any other Gtk# functions
in your GUI applications. It will initialize everything
needed to operate the toolkit.
This function will terminate your program if it was unable
to initialize the GUI for some reason. If you want your
program to fall back to a textual interface you want to
call instead.
If you want to pass arguments from the command line use
the
method instead.
MethodSystem.Void
The name of the program.
An string array with the parameters given to the program.
Call this method before using any other GTK# method in your GUI applications.
It will initialize everything needed to operate the toolkit and parses some standard command line options, is adjusted accordingly so your code will never see those standard arugments.
Note that there are some alternative ways to initialize GTK#, if you are calling or you don't have to call .
MethodSystem.Boolean
The name of the program.
An string array with the parameters given to the program.
This method does the same work as with only a single change, it does not terminate the program if the GUI can't be initialized. Instead it returns on failure. if the GUI has been succesfully initialized, otherwise .This way the application can fall back to some toher means of communication with the user, for example a curses or command line interface.MethodSystem.Void
An event handler to invoke on the main thread.
Invoke the given EventHandler in the GUI thread.
Use this method to invoke the given delegate code in the
main thread. This is necessary since Gtk# does not allow
multiple threads to perform operations on Gtk objects as it
the toolkit is not thread-safe.
This mechanism is simpler to use than since it does not require the
creation of a notifier per event.
This is particularly useful with C# 2.0 as it is possible
to use anonymous methods with it, for example:
using Gtk;
using Gdk;
using System;
using System.Threading;
public class HelloThreads {
static Label msg;
static Button but;
static int count;
static Thread thr;
public static int Main (string[] args)
{
Application.Init ();
Gtk.Window win = new Gtk.Window ("Gtk# Threaded Counter");
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
msg = new Label ("Click to quit");
but = new Button (msg);
but.Clicked += delegate { thr.Abort (); Application.Quit (); };
win.Add (but);
win.ShowAll ();
thr = new Thread (ThreadMethod);
thr.Start ();
Application.Run ();
return 0;
}
static void ThreadMethod ()
{
Console.WriteLine ("Starting thread");
while (true){
count++;
Thread.Sleep (500);
Application.Invoke (delegate {
msg.Text = String.Format ("Click to Quit ({0})", count);
});
}
}
static void Window_Delete (object obj, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
MethodSystem.Void
The sender to pass to the event handler..
The argument to pass to the event handler.
An event handler to invoke on the main thread.
Invoke the given EventHandler in the GUI thread.
Use this method to invoke the given delegate code in the
main thread. This is necessary since Gtk# does not allow
multiple threads to perform operations on Gtk objects as it
the toolkit is not thread-safe.
This mechanism is simpler to use than since it does not require the
creation of a notifier per event.
This is particularly useful with C# 2.0 as it is possible
to use anonymous methods with it, for example:
using Gtk;
using Gdk;
using System;
using System.Threading;
public class HelloThreads {
static Label msg;
static Button but;
static int count;
static Thread thr;
public static int Main (string[] args)
{
Application.Init ();
Gtk.Window win = new Gtk.Window ("Gtk# Threaded Counter");
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
msg = new Label ("Click to quit");
but = new Button (msg);
but.Clicked += delegate { thr.Abort (); Application.Quit (); };
win.Add (but);
win.ShowAll ();
thr = new Thread (ThreadMethod);
thr.Start ();
Application.Run ();
return 0;
}
static void ThreadMethod ()
{
Console.WriteLine ("Starting thread");
while (true){
count++;
Thread.Sleep (500);
Application.Invoke (delegate {
msg.Text = String.Format ("Click to Quit ({0})", count);
});
}
}
static void Window_Delete (object obj, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
MethodSystem.VoidQuits the current main loop
Makes the innermost invocation of the main loop return when it regains control.
MethodSystem.Void
To be added.
To be added.To be added.MethodSystem.VoidRuns the main loop
Runs the main loop until is called. You can nest
calls to . In that
case will make the
innermost invocation of the main loop return.
MethodSystem.VoidRuns a single iteration of the main loop.
Runs a single iteration of the main loop. If no events are
waiting to be processed Gtk# will block until the next
event is noticed. If you do not want to block look at or check if
any events are pending with first.
MethodSystem.Boolean
A boolean value, whether the iteration should block or not
Runs a single iteration of the main loop. if has been called in the innermost main loop.
Runs a single iteration of the main loop. If is , then if no events are
waiting to be processed Gtk# will block until the next event is noticed; If is ,
then it if no events are waiting to be processed Gtk#, routine will return immediately.
PropertyGtk.Window[]To be added.To be added.To be added.