Gtk.ProgressBar Sample, Gtk# and Mono

Hi, I start a new series of posts about C#, Mono and Gtk#…I find really good examples over internet but in this blog I want to share my experiences about these tools…By the way bear in mimd that I am a newbie Mono Developer!

First cool staff about this subject can be found at: http://www.mono-project.com by using search in the right top…

In my first post I will discuss about how to achieve splash screens in Gtk#:

Add references: atk-sharp, gdk-sharp, glade-sharp, glib-sharp,gtk-dotnet,gtk-sharp,System

using GLib;
using Gtk;
using System;

class ProgressBarSample {
 public struct ProgressData {
 public Gtk.Window window;
 public Gtk.ProgressBar pbar;
 public uint timer;
 public bool activity_mode;

 }
 public struct afterSplash {
 public Gtk.Window mainWindow;

 }

 static ProgressData pdata;
 static afterSplash main;
 static double new_val;

 /* Update the value of the progress bar so that we get
 * some movement */
 static bool progress_timeout()
 {

 if (pdata.activity_mode)
 pdata.pbar.Pulse();
 else {
 /* Calculate the value of the progress bar using the
 * value range set in the adjustment object */
 new_val = pdata.pbar.Fraction + 0.01;
 if (new_val > 1.0)
 new_val = 0.0;

 /* Set the new value */
 pdata.pbar.Fraction = new_val;
 pdata.pbar.Text = "Loading...";

 if(new_val>0.98){
 pdata.window.Destroy();

 main.mainWindow.ShowAll();

 GLib.Source.Remove (pdata.timer);
 }

 }

 /* As this is a timeout function, return TRUE so that it
 * continues to get called */

 return true;
 }

 /* Callback that toggles the activity mode of the progress bar */
 static void toggle_activity_mode (object obj, EventArgs args)
 {
 pdata.activity_mode = !pdata.activity_mode;
 if (pdata.activity_mode)
 pdata.pbar.Pulse();
 else
 pdata.pbar.Fraction = 0.0;
 }

 static void destroy_progress (object obj, DeleteEventArgs args)
 {
 app_quit();
 }

 static void app_quit() {
 GLib.Source.Remove (pdata.timer);
 pdata.timer = 0;
 Application.Quit ();
 }

 static void Main()
 {

 Gtk.VBox vbox;

 Application.Init ();

 main=new afterSplash();
 main.mainWindow=new Window("Deneme_Splash");
 main.mainWindow.SetSizeRequest(500, 500);
 main.mainWindow.SetPosition(WindowPosition.Center);
 Button de=new Button();
 de.Label="deneme";
 Fixed d=new Fixed();
 d.Put(de,0,0);
 main.mainWindow.Add(d);

 /* Allocate memory for the data that is passed to the callbacks*/
 pdata = new ProgressData();
 pdata.activity_mode = false;
 pdata.window = new Gtk.Window(Gtk.WindowType.Popup);
 pdata.window.Resizable = true;
 pdata.window.SetPosition(WindowPosition.Center);

 pdata.window.DeleteEvent += destroy_progress;
 pdata.window.Title = "GtkProgressBar";
 pdata.window.BorderWidth = 0;

 vbox = new Gtk.VBox(false, 5);
 vbox.BorderWidth = 10;
 pdata.window.Add(vbox);
 vbox.Show();

 /* Create a centering alignment object */
 Gtk.Alignment align = new Gtk.Alignment( 1, 1, 0, 0);
 vbox.PackStart(align, false, false, 5);
 align.Show();

 /* Create the GtkProgressBar */
 pdata.pbar = new Gtk.ProgressBar();
 pdata.pbar.Text = "";
 align.Add(pdata.pbar);
 pdata.pbar.Show();

 /* Add a timer callback to update the value of the progress bar*/
 //1 second (s) = 1000 milliseconds
 pdata.timer = GLib.Timeout.Add(10, new GLib.TimeoutHandler (progress_timeout) );

 pdata.window.ShowAll();

 Application.Run ();
 }
}
<pre>

Output:

loadinginGTK

Thats all folks for this post!



kick it on DotNetKicks.com

About these ads