Re: Gtk2::TreeModel - foreach

2009-11-20 Thread Zettai Muri


 If you supply $user_data - then you it will be passed in as the last argument 
 to 
 the ForEach function.
 
 
 
 $model-foreach(
 sub {
 my($model,$path,$iter,$user_data -) = @_;
 my($item)  = $model-get($iter, 0);
 
 print $item\n;
 
 # return TRUE to end
 return FALSE;
 }, $user_data --- ???
 );
 
 
 Here is an example that searches for a name in model:
 
 sub search {
 my($model,$path,$iter,$search_string) = @_;
   my($item) = $model-get($iter, 0);
 
 if ($item =~ /$search_string/) {
   print FOUND\n;
   return TRUE;
   }
   else {
   return FALSE;
   }
 }
 
 $model-foreach(\search, 'Bob');
 $model-foreach(\search, 'Billy');


Thank you!

I was just wondering, is there a return value of some sort or a way to
get the return TRUE from the search sub, so that it is possible to then
do something like:

if ( $model-foreach(\search, 'Bob') )
{
print (Welcome back!\n);
}
else
{
print (Who are you?\n);
}

I have tried the above but my output is always:
FOUND
Who are you?

I was going to add after the print FOUND\n; line something like:
$my_global_var = 'FOUND';

and then use that to test against, and it's only for me to use in my
own program but global variables are supposed to be avoided aren't they?

Thanks again for any input.


  
__
Win 1 of 4 Sony home entertainment packs thanks to Yahoo!7.
Enter now: http://au.docs.yahoo.com/homepageset/

___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


RE: Gtk2::TreeModel - foreach

2009-11-20 Thread Jeff Hallock


-Original Message-
From: Martin Schlemmer [mailto:martin.schlem...@nwu.ac.za]
Sent: Friday, November 20, 2009 6:48 AM
To: gtk-perl-list@gnome.org; Martin Schlemmer; Jeff Hallock; Zettai Muri
Subject: Re: Gtk2::TreeModel - foreach

 On 2009/11/20 at 11:41 AM, Zettai Muri zettaim...@ymail.com wrote:
 I was just wondering, is there a return value of some sort or a way to
 get the return TRUE from the search sub, so that it is possible to then
 do something like:

 if ( $model-foreach(\search, 'Bob') )
 {
 print (Welcome back!\n);
 }
 else
 {
 print (Who are you?\n);
 }

 I have tried the above but my output is always:
 FOUND
 Who are you?


Use pass a hash or other reference to the foreach():


Or here is an alternative that doesn't use the foreach method.


sub search {
my ($model, $search_string) = @_;
my $iter  = $model-iter_first;
my $found;

do {
  if ($model-get($iter, 0) ~= /$search_string/) {
 $found = 1;
  } else {
 $iter  = $model-iter_next;
  }
} while (! $found  $iter);

return $found;
}


if ( search($model, 'bob') ) {
print (Welcome back!\n);
} else {
   print (Who are you!\n);
}






___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk2::TreeModel - foreach

2009-11-20 Thread Zettai Muri


 Use pass a hash or other reference to the foreach():

Martin, very cool!  I sure have a long way to go before I can even imagine a 
solution like this.

 
 Or here is an alternative that doesn't use the foreach method.
 
 
 sub search {
 my ($model, $search_string) = @_;
 my $iter  = $model-iter_first;
 my $found;
 
 do {
   if ($model-get($iter, 0) ~= /$search_string/) {
  $found = 1;
   } else {
  $iter  = $model-iter_next;
   }
 } while (! $found  $iter);
 
 return $found;
 }
 
 
 if ( search($model, 'bob') ) {
 print (Welcome back!\n);
 } else {
print (Who are you!\n);
 }

Jeff, thank you for keeping it simple and offering an alternative.

You guys make it look so easy.

ZM.


  
__
Win 1 of 4 Sony home entertainment packs thanks to Yahoo!7.
Enter now: http://au.docs.yahoo.com/homepageset/

___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Gtk2::MessageDialog title

2009-11-20 Thread Zettai Muri
Hi All,

Is it possible to set the title of a MessageDialog?

I have the following:

sub show_duplicate_dialog
{
#
# A modal dialog.  Note that the message is a printf-style format.
#
my($duplicate) = @_;
my($dialog) = Gtk2::MessageDialog-new (undef,
'destroy-with-parent',
'error', # message type
'ok', # which set of buttons?
#printf format:
\%s\ already selected., 
$duplicate);
my($response) = $dialog-run;
$dialog-destroy;

}

But can't work out how to add a title to the dialog box that appears.

Many thanks,

ZM.


  
__
Win 1 of 4 Sony home entertainment packs thanks to Yahoo!7.
Enter now: http://au.docs.yahoo.com/homepageset/___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk2::MessageDialog title

2009-11-20 Thread muppet


On Nov 20, 2009, at 11:01 PM, Zettai Muri wrote:


Is it possible to set the title of a MessageDialog?


Of course.  Gtk2::MessageDialog isa Gtk2::Dialog isa Gtk2::Window, so  
just just Gtk2::Window::set_title().  See below.



But beware that the gnome human interface guidelines say that alert  
windows should have no title, as the title would normally just  
duplicate the text of the message...  so, depending on what you're  
doing, you might actually want to blank out the title.


http://library.gnome.org/devel/hig-book/stable/windows-alert.html.en



I have the following:

sub show_duplicate_dialog
{
#
# A modal dialog.  Note that the message is a printf-style format.
#
my($duplicate) = @_;
my($dialog) = Gtk2::MessageDialog-new (undef,
'destroy-with-parent',
'error', # message type
'ok', # which set of buttons?
#printf format:
\%s\ already selected.,
$duplicate);


$dialog-set_title (Fooo);


my($response) = $dialog-run;
$dialog-destroy;

}

But can't work out how to add a title to the dialog box that appears.


For each widget in Gtk2 there is a man page; each man page has a  
HIERARCHY section, which shows the class ancestry for that type. Or  
you can look at the C api reference on gtk.org, which has the same  
info in a different format.


--
Applause is an addiction, like heroin or checking your email.
  -- Sideshow Mel

___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk2::MessageDialog title

2009-11-20 Thread Zettai Muri


 Of course.  Gtk2::MessageDialog isa Gtk2::Dialog isa Gtk2::Window, so just 
 just 
 Gtk2::Window::set_title().  See below.

I did actually look at Gtk2::Dialog but didn't see it there either.  Should 
have just kept moving up?/down? the hierarchy.
 
 
 But beware that the gnome human interface guidelines say that alert windows 
 should have no title, as the title would normally just duplicate the text of 
 the 
 message...  so, depending on what you're doing, you might actually want to 
 blank 
 out the title.
 
 http://library.gnome.org/devel/hig-book/stable/windows-alert.html.en
 
 

Thank you very much for this, will check out the rest of the HIG to make sure 
I'm staying on track.

 
 For each widget in Gtk2 there is a man page; each man page has a HIERARCHY 
 section, which shows the class ancestry for that type. Or you can look at the 
 C 
 api reference on gtk.org, which has the same info in a different format.

Wasn't aware I could also refer to the C api reference.  Thanks again.


  
__
Win 1 of 4 Sony home entertainment packs thanks to Yahoo!7.
Enter now: http://au.docs.yahoo.com/homepageset/

___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list