Re: Freeze screen



On Thu, 28 Sep 2006 16:59:20 +0200
Dieter Schicker <dieter schicker uni-graz at> wrote:

Hi,

how can I "freeze" (and "unfreeze") the screen like it is done when the
user is asked for his password when he wants to perform an
administrative task?

Thanks in advance
Dieter

I'm not sure exactly what you mean by freeze screen, but
for passwords look at the 
Gtk2::Ex::Dialogs 
module. 
Check out the examples/demo.pl  and click the 'question'
button.
That freezes the mainwindow until you get an answer from the
dialog popup.

Or you can make your own. Here is one I hacked up from
some previous examples and snippets. Notice the signal
connect in the entry for activate, it allows the Return key to
submit the entry, so you don't really need the  'ok' and 'cancel'
buttons.

#!/usr/bin/perl
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 'init';

my $mw = Gtk2::Window->new ('toplevel');
$mw->set_position('center-always');
$mw->signal_connect (delete_event => sub { Gtk2->main_quit });
#$mw->set_size_request(300,200);

my $vbox = Gtk2::VBox->new( FALSE, 5 );
$mw->add($vbox);

my $res_mes = 'Current Value:';
my $result = 'yadda yadda yadda';

my $label = Gtk2::Label->new();
set_label($result);

$vbox->pack_start( $label, FALSE, FALSE, 0 );

my $button = Gtk2::Button->new ('Get Password');
$button->signal_connect (clicked => \&clicked );
$vbox->pack_start( $button, FALSE, FALSE, 0 );

$mw->show_all;
Gtk2->main;
################################################################
sub clicked {

my $dialog = Gtk2::Dialog->new('Get Password',
                              undef,
                              [qw/modal destroy-with-parent/],
                              'gtk-cancel' => 'cancel',
                              'Ok'      => 'ok',
                              );
                              
$dialog->set_response_sensitive ('reject', FALSE);
$dialog->set_response_sensitive ('accept', FALSE);
$dialog->signal_connect('delete-event'=> sub {$dialog->destroy });
$dialog->set_position('center-always');

&fill_dialog($dialog);
$dialog->show();
}
##########################################################################
sub fill_dialog {

my ($dialog) = @_;

my $vbox = $dialog->vbox;
$vbox->set_border_width(5);
        #-------------------------------------
        my $table = Gtk2::Table->new (1, 2, FALSE);
                my $label = Gtk2::Label->new_with_mnemonic("_Enter Password: ");
                #$misc->set_alignment ($xalign, $yalign) 
                $label->set_alignment(1,0.5);
        $table->attach_defaults ($label, 0, 1, 0,1);
                my $entry = Gtk2::Entry->new();
                $entry->set_text('');
                $label->set_mnemonic_widget ($entry);
                
        #set it up so an enter will submit the password
                $entry->signal_connect ('activate' => sub { 
                        my $new_val = $entry->get_text();
                        print "password: $new_val\n";
                        $dialog->destroy;
                        set_label($new_val);                                            
                      });
        
        $table->attach_defaults($entry,1,2,0,1);
        #---------------------------------------
$vbox->pack_start($table,0,0,4);

        #this is a nifty thing :) from the documentation:
        #response (Gtk2::Dialog, integer) - thus the second element generated during the signal emitting
        #will be the button's name
        $dialog->signal_connect(response => sub {
                
               if($_[1] =~ m/ok/){
                print "YOU CLICKED: ".$_[1]."\n";
                my $new_val = $entry->get_text();
                print "password: $new_val\n";
                $dialog->destroy;
                set_label($new_val);                                            
                }
                
                if($_[1] =~ m/cancel/){
                        $dialog->destroy;
                     }          
        });

        $vbox->show_all();
return $vbox;
}
######################################################################
sub set_label{
my $new_val = shift;

$label->set_markup("<span foreground=\"blue\" size=\"x-large\">
$res_mes\n</span><span weight='heavy' size = '20000' foreground = 'forestgreen' style ='italic'>$new_val 
\n</span>");

}
#####################################################################
__END__


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]