6. Sample program

'Here' is a sample program that you can run to see Gnome2::Druid in action.

	  
  1 #!/usr/bin/perl -w
  2 
  3 use strict;
  4 use Glib qw/TRUE FALSE/;
  5 use Gnome2;
  6 use Cwd;
  7 
  8 my $logo = Gtk2::Gdk::Pixbuf->new_from_file("./faces/soccerball.png");
  9 my $watermark = Gtk2::Gdk::Pixbuf->new_from_file("faces/penguin.jpg");
 10 my $top_watermark = Gtk2::Gdk::Pixbuf->new_from_file("faces/tennis-ball.png");
 11 
 12 my $page_one_text = 
 13 "A Druid has a 'Start' and 'Finish' screen. They are blessed references to the Gnome2::DruidPageEdge class. This class looks different from the Gnome2::DruidPageStandard class.\n\nThe 'Start' screen usually contains a simple message telling you what the Druid is about.\n\nThe 'Finish' screen usually thank you for taking it and offers a 'Commit' type of button.\n\nThe pages in between should be blessed references to the Gnome2::DruidPageStandard class. This class can contain more complex child classes. They are used to gather information from the user.\n\nGnome2::DruidPageStandard and Gnome2::DruidPageEdge are both sub classes of Gnome2::DruidPage.\n\nGnome2::DruidPage should never be created directly. It will implicitly be created when Gnome2::DruidPageStandard or Gnome2::DruidPageEdge gets created.";
 14 
 15 my $end_page_text = 
 16 "Thank you for taking this Druid!. We trust that you now know a bit more about Gnome2::Druid and the classes used with it.";
 17 
 18 Gnome2::Program->init ('DruidTest', '1.0beta', 'libgnomeui');
 19 
 20 
 21 #returns a druid and a window
 22 my ($druid, $window) = Gnome2::Druid->new_with_window ("Gnome2 Druid Tutorial", undef, TRUE);
 23 
 24 #this will set the label on the finish button to "Finish", default is "Apply"
 25 $druid->finish->set_label ("_Finish");
 26 
 27 #When we click the "Finish" button, we exit
 28 $druid->finish->signal_connect (clicked => sub { Gtk2->main_quit ; 1 });
 29 
 30 #PAGES:
 31 #Pages gets added to the druid, you start and end with a Gnome::DruidPageEdge
 32 #the rest should be Gnome2::DruidPageStandard pages.
 33 
 34 	#--------------------------
 35 	# START PAGE
 36 	#--------------------------
 37 	my $druid_page_start = Gnome2::DruidPageEdge->new_with_vals ('start', FALSE,
 38 		"Welcome to the Druid Start Page",
 39 		$page_one_text,
 40 		$logo,
 41 		$watermark,
 42 		$top_watermark);
 43 
 44 	#Connect to the 'next' signal to do error checking
 45 	$druid_page_start->signal_connect('next' => sub { 
 46 	
 47 		my $retval = &show_message_dialog($window,'question',"This does a check, continue?",'yes-no');
 48 		warn $retval."\n";
 49 		#If the return value is boolean TRUE, the event signal will be stopped from propagating,
 50 		# but if it is boolean FALSE, it will continue with the propagation of the signal
 51 
 52 		return FALSE if $retval =~ /yes/i;
 53 		return TRUE if $retval =~ /no/i;		
 54 	});
 55 
 56 #add the page to the druid
 57 $druid->append_page ($druid_page_start);
 58 
 59 #customize the page
 60 $druid_page_start->set_bg_color (Gtk2::Gdk::Color->new(60000,0,0));
 61 $druid_page_start->set_textbox_color (Gtk2::Gdk::Color->new(60000,60000,0));
 62 
 63 
 64 	#--------------------------
 65 	#Middle page:
 66 	#--------------------------
 67 	my $druid_page_middle = Gnome2::DruidPageStandard->new_with_vals ('Middle Standard Page', $logo, $top_watermark);
 68 
 69 	#convenience method - part of Gnome2::DruidPageStandard
 70 	$druid_page_middle->append_item ('Do you like sport?', Gtk2::CheckButton->new('Yes'), '(click if you do)');
 71 
 72 #add the page to the druid
 73 $druid->append_page ($druid_page_middle);
 74 
 75 
 76 	#--------------------------
 77 	#End Page:
 78 	#--------------------------
 79 	#this shows the default values
 80 	my $druid_page_end = Gnome2::DruidPageEdge->new_with_vals ('finish', FALSE,
 81 		"Goodbye",
 82 		$end_page_text,
 83 		undef,
 84 		undef,
 85 		undef);
 86 
 87 #add the page to the druid
 88 $druid->append_page ($druid_page_end);
 89 
 90 $window->set_position('center-always');
 91 
 92 $window->show_all;
 93 $window->signal_connect (destroy => sub { Gtk2->main_quit; 1 });
 94 
 95 Gtk2->main;
 96 
 97 #_____________________________________________________
 98 
 99 
100 sub show_message_dialog {
101 
102 #you tell it what to display, and how to display it
103 #$parent is the parent window, or "undef"
104 #$icon can be one of the following:	a) 'info'
105 #					b) 'warning'
106 #					c) 'error'
107 #					d) 'question'
108 #$text can be pango markup text, or just plain text, IE the message
109 #$button_type can be one of the following: 	a) 'none'
110 #						b) 'ok'
111 #						c) 'close'
112 #						d) 'cancel'
113 #						e) 'yes-no'
114 #						f) 'ok-cancel'
115 
116 my ($parent,$icon,$text,$button_type) = @_;
117   
118 my $dialog = Gtk2::MessageDialog->new_with_markup ($parent,
119 					[qw/modal destroy-with-parent/],
120 					$icon,
121 					$button_type,
122 					sprintf "$text");						
123 	my $retval = $dialog->run;
124 	$dialog->destroy;
125 	return $retval;
126 }