Introduction and question

View: New views
7 Messages — Rating Filter:   Alert me  

Introduction and question

by Michelle Konzack-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

************************************************************************
*       Do not Cc: me, because I READ THIS LIST, if I write here       *
*    Keine Cc: am mich, ich LESE DIESE LISTE wenn ich hier schreibe    *
************************************************************************

Hello *,

My name is Michelle, live in Strasbourg, being Debian GNU/Linux  Consul-
tant and since August 2007 I have my Doctor in  Informatic.  Since  some
weeks now I am learning perl and it is great programming language  which
I unfortunately learn at least 15 years to late...  :-/

Now I have begun, to port some older "Programs" coded in  BaSH  to  Perl
and I want to change the Xdialog stuff to a real GTK-Dialog.

Since Xdialog can only show one thing at once, I have the singel options
in a "treeview", but now I want to use "notepad" with this nice tabs.

OK, my programs write the optins to singel files (one  file  per  Option
like "courier-imap") and I use "cat" to read its value.  I do  not  want
to change this...

In BaSH I used:

----[ STDIN ]-----------------------------------------------------------
  for NAME1 in $(find ${CFGDIR} -type f -maxdepth 1) ; do
    VAL=$(cat ${NAME1})
    NAME=$(basename ${NAME1})
    eval "export ${VARPREFIX}${NAME}=\${VAL}"
  done
------------------------------------------------------------------------

Note:  ${VARPREFIX} is:  VARPREFIX=$(basename $0)_

1st question:  How do I do this in Perl?

Then, the "notepad" dialog...
I want to have a button "Apply"  which  write  the  new  entered  values
to the config dir whithout closing the dialog where under BaSH I used:

----[ STDIN ]-----------------------------------------------------------
  (env |grep "^${VARPREFIX}" |sed "s|^${VARPREFIX}||g") |
  while read FULL
  do
    NAME=$(echo "${FULL}" |cut -d '=' -f1)
    VAL=$(echo  "${FULL}" |cut -d '=' -f2-)
    echo "${VAL}" >${CFGDIR}/${NAME}
  done
------------------------------------------------------------------------

2nd question:  How do I do this in Perl?

3th question:  HOW do I make a "notepad" dialog in "perl-gtk"?
               The first TAB should have the MAIN user interface and
               then the following TABs config stuff and such...

Thanks, Greetings and nice Day/Evening
    Michelle Konzack
    Systemadministrator
    24V Electronic Engineer
    Tamay Dogan Network
    Debian GNU/Linux Consultant


--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
+49/177/9351947    50, rue de Soultz         MSN LinuxMichi
+33/6/61925193     67100 Strasbourg/France   IRC #Debian (irc.icq.com)


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

signature.pgp (196 bytes) Download Attachment

Re: Introduction and question

by zentara-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, 12 Jul 2008 15:15:04 +0200
Michelle Konzack <linux4michelle@...> wrote:

>Now I have begun, to port some older "Programs" coded in  BaSH  to  Perl
>and I want to change the Xdialog stuff to a real GTK-Dialog.
>
>Since Xdialog can only show one thing at once, I have the singel options
>in a "treeview", but now I want to use "notepad" with this nice tabs.
>
>OK, my programs write the optins to singel files (one  file  per  Option
>like "courier-imap") and I use "cat" to read its value.  I do  not  want
>to change this...
>
>In BaSH I used:
>
>----[ STDIN ]-----------------------------------------------------------
>  for NAME1 in $(find ${CFGDIR} -type f -maxdepth 1) ; do
>    VAL=$(cat ${NAME1})
>    NAME=$(basename ${NAME1})
>    eval "export ${VARPREFIX}${NAME}=\${VAL}"
>  done
>------------------------------------------------------------------------

I'm not very good at bash, but from what I can gather, this
should get you started

#!/usr/bin/perl
use warnings;
use strict;
use File::Basename;

my $os_string = "linux";
fileparse_set_fstype($os_string);

my $dir = shift || '.';   # feed it a dir as argv[0]
                                     # defaults to '.'
my @files = ls($dir);

#print join "\n", @files,"\n";

#process your files here
foreach my $file(@files){
 print "$file\n";
 my $fullfilename = $file;
 my($base,$path,$ext)=fileparse($fullfilename,'\..*');
 print "base -> $base\n";
 print "path -> $path\n";
 print "ext -> $ext\n";
print "\n\n";
}


sub ls {
 my $path = @_ ? shift : ".";
 local *DIR;
 opendir DIR, $path or die "can't ls $path: $!";
 #remove subdirs, self, and parent dir
 return grep { $_ ne "." and $_ ne ".." and ! -d } readdir DIR;
}
__END__


>Then, the "notepad" dialog...
>I want to have a button "Apply"  which  write  the  new  entered  values
>to the config dir whithout closing the dialog where under BaSH I used:

You have to be careful with terminology. A Dialog in Perl/Gtk2 is a specific
widget type, that does grabs and has predefined responses. You probably
could do something like this. It's not perfect, but should give you are start.
You will have to work on the Apply (to write your files out), and setting up your
pages with nice names.

If you notice, the contents are only printed out once
with get_vals(), maybe someone may know why? Maybe
the iter needs to be reset?


#!/usr/bin/perl
use strict;
use warnings;
use Gtk2 '-init';

package NBDialog;
use strict;
use warnings;
use Carp;
use Gtk2;
use Glib qw(TRUE FALSE);

use base 'Gtk2::Dialog';
 
sub new {
        my $class = shift;
        # create
        my $self = Gtk2::Dialog->new;
        bless $self, $class;

        $self->set_position('center-always');

        # set some data if desired
        #$self->{result} = 42;

   
     $self->{notebook} = Gtk2::Notebook->new;
     $self->{notebook}->set_tab_pos ('top');
     
     # put whatever files or whatever in here
     foreach my $page('Page1','Page2','Page3'){
     
       # Create a textbuffer to contain that string
       $self->{$page}->{textbuffer} = Gtk2::TextBuffer->new();
       $self->{$page}->{textbuffer}->set_text($page);

       # Create a textview using that textbuffer
       $self->{$page}->{textview} = Gtk2::TextView->new_with_buffer($self->{$page}->{textbuffer});
       $self->{$page}->{textview}->set_left_margin (5);
       #$textview->set_editable(0);

       $self->{$page}->{textview}->get_buffer->signal_connect (
         changed => sub { print "changed!\n"});

       # Add the textview to a scrolledwindow
       my $scrolledwindow = Gtk2::ScrolledWindow->new( undef, undef );
       $scrolledwindow->add($self->{$page}->{textview});
     
     #add to notebook
     $self->{notebook}->append_page( $scrolledwindow, $self->make_label($page) );
     
     }
     
     # the dialog's vbox is an advertised widget which you can add to
     $self->vbox->pack_start($self->{notebook},0,0,1);
     $self->vbox->show_all();

    my $button0 =  $self->add_button ("Apply" => 1);
    my $button1 = $self->add_button ("Reset" => 2);
    my $button2 = $self->add_button ("Cancel" => 3);
         
     
  $self->signal_connect (response => \&do_response );
# $self->signal_connect (response => sub { $_[0]->destroy });

return $self;
}


sub make_label {
    my ($self,$text) = @_;
    #print "@_\n";
    my $hbox   = Gtk2::HBox->new;
    my $label  = Gtk2::Label->new($text);
    my $button = Gtk2::Button->new("x");    # a pixmap would look nicer
    $button->signal_connect(
        clicked => sub {
            $self->{notebook}->remove_page( $self->{notebook}->get_current_page );
        }
    );
    $hbox->pack_start( $label,  FALSE, FALSE, 0 );
    $hbox->pack_start( $button, FALSE, FALSE, 0 );
    $label->show;
    $button->show;

    return $hbox;
}


sub do_response {
  my ($self, $resp) = @_;
  print "response $resp\n";
   
   return $resp;
}

sub get_vals{
    my $self = shift;
   
    foreach my $page('Page1','Page2','Page3'){
     print  $self->{$page}->{textbuffer}->get_text(
       $self->{$page}->{textbuffer}->get_start_iter,
       $self->{$page}->{textbuffer}->get_end_iter,
       1),"\n";
    }
return 1;
}

1;


package main;


my $window = Gtk2::Window->new;
my $button = Gtk2::Button->new ("Click me");
$button->signal_connect (clicked => \&do_stuff);
$window->set_border_width (25);
$window->add ($button);
$window->show_all;
$window->signal_connect (destroy => sub { Gtk2->main_quit });
Gtk2->main;

sub do_stuff{
   my $dialog = NBDialog->new;

   my $response = $dialog->run;

   print 'returned ',$response,"\n";
   # do whatever here based on response

   print $dialog->get_vals(),"\n";
 
}

__END__




zentara


--
I'm not really a human, but I play one on earth.
http://zentara.net/CandyGram_for_Mongo.html 
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Introduction and question

by Sergei Steshenko-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




--- On Tue, 7/15/08, zentara <zentara1@...> wrote:

> From: zentara <zentara1@...>
> Subject: Re: Introduction and question
> To: gtk-perl-list@...
> Date: Tuesday, July 15, 2008, 5:59 AM
> On Sat, 12 Jul 2008 15:15:04 +0200
> Michelle Konzack <linux4michelle@...>
> wrote:
>
> >Now I have begun, to port some older
> "Programs" coded in  BaSH  to  Perl
> >and I want to change the Xdialog stuff to a real
> GTK-Dialog.
> >
> >Since Xdialog can only show one thing at once, I have
> the singel options
> >in a "treeview", but now I want to use
> "notepad" with this nice tabs.
> >
> >OK, my programs write the optins to singel files (one
> file  per  Option
> >like "courier-imap") and I use
> "cat" to read its value.  I do  not  want
> >to change this...
> >
> >In BaSH I used:
> >
> >----[ STDIN
> ]-----------------------------------------------------------
> >  for NAME1 in $(find ${CFGDIR} -type f -maxdepth 1) ;
> do
> >    VAL=$(cat ${NAME1})
> >    NAME=$(basename ${NAME1})
> >    eval "export
> ${VARPREFIX}${NAME}=\${VAL}"
> >  done
> >------------------------------------------------------------------------
>
> I'm not very good at bash, but from what I can gather,
> this
> should get you started
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use File::Basename;
>
> my $os_string = "linux";
> fileparse_set_fstype($os_string);
>
> my $dir = shift || '.';   # feed it a dir as
> argv[0]
>                                      # defaults to
> '.'
> my @files = ls($dir);
>
> #print join "\n", @files,"\n";
>
> #process your files here
> foreach my $file(@files){
>  print "$file\n";
>  my $fullfilename = $file;
>
> my($base,$path,$ext)=fileparse($fullfilename,'\..*');
>  print "base -> $base\n";
>  print "path -> $path\n";
>  print "ext -> $ext\n";
> print "\n\n";
> }
>
>
> sub ls {
>  my $path = @_ ? shift : ".";
>  local *DIR;
>  opendir DIR, $path or die "can't ls $path:
> $!";
>  #remove subdirs, self, and parent dir
>  return grep { $_ ne "." and $_ ne ".."
> and ! -d } readdir DIR;
> }
> __END__
>
>
> >Then, the "notepad" dialog...
> >I want to have a button "Apply"  which  write
>  the  new  entered  values
> >to the config dir whithout closing the dialog where
> under BaSH I used:
>
> You have to be careful with terminology. A Dialog in
> Perl/Gtk2 is a specific
> widget type, that does grabs and has predefined responses.
> You probably
> could do something like this. It's not perfect, but
> should give you are start.
> You will have to work on the Apply (to write your files
> out), and setting up your
> pages with nice names.
>
> If you notice, the contents are only printed out once
> with get_vals(), maybe someone may know why? Maybe
> the iter needs to be reset?
>
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Gtk2 '-init';
>
> package NBDialog;
> use strict;
> use warnings;
> use Carp;
> use Gtk2;
> use Glib qw(TRUE FALSE);
>
> use base 'Gtk2::Dialog';
>  
> sub new {
> my $class = shift;
> # create
> my $self = Gtk2::Dialog->new;
> bless $self, $class;
>
>         $self->set_position('center-always');
>
>         # set some data if desired
>         #$self->{result} = 42;
>
>    
>      $self->{notebook} = Gtk2::Notebook->new;
>      $self->{notebook}->set_tab_pos ('top');
>      
>      # put whatever files or whatever in here
>      foreach my
> $page('Page1','Page2','Page3'){
>      
>        # Create a textbuffer to contain that string
>        $self->{$page}->{textbuffer} =
> Gtk2::TextBuffer->new();
>      
> $self->{$page}->{textbuffer}->set_text($page);
>
>        # Create a textview using that textbuffer
>        $self->{$page}->{textview} =
> Gtk2::TextView->new_with_buffer($self->{$page}->{textbuffer});
>        $self->{$page}->{textview}->set_left_margin
> (5);
>        #$textview->set_editable(0);
>
>      
> $self->{$page}->{textview}->get_buffer->signal_connect
> (
>          changed => sub { print
> "changed!\n"});
>
>        # Add the textview to a scrolledwindow
>        my $scrolledwindow = Gtk2::ScrolledWindow->new(
> undef, undef );
>      
> $scrolledwindow->add($self->{$page}->{textview});
>      
>      #add to notebook
>      $self->{notebook}->append_page( $scrolledwindow,
> $self->make_label($page) );
>      
>      }
>      
>      # the dialog's vbox is an advertised widget which
> you can add to
>    
> $self->vbox->pack_start($self->{notebook},0,0,1);
>      $self->vbox->show_all();
>
>     my $button0 =  $self->add_button ("Apply"
> => 1);
>     my $button1 = $self->add_button ("Reset"
> => 2);
>     my $button2 = $self->add_button ("Cancel"
> => 3);
>          
>      
>   $self->signal_connect (response =>
> \&do_response );
> # $self->signal_connect (response => sub {
> $_[0]->destroy });
>
> return $self;
> }
>
>
> sub make_label {
>     my ($self,$text) = @_;
>     #print "@_\n";
>     my $hbox   = Gtk2::HBox->new;
>     my $label  = Gtk2::Label->new($text);
>     my $button = Gtk2::Button->new("x");    #
> a pixmap would look nicer
>     $button->signal_connect(
>         clicked => sub {
>             $self->{notebook}->remove_page(
> $self->{notebook}->get_current_page );
>         }
>     );
>     $hbox->pack_start( $label,  FALSE, FALSE, 0 );
>     $hbox->pack_start( $button, FALSE, FALSE, 0 );
>     $label->show;
>     $button->show;
>
>     return $hbox;
> }
>
>
> sub do_response {
>   my ($self, $resp) = @_;
>   print "response $resp\n";
>    
>    return $resp;
> }
>
> sub get_vals{
>     my $self = shift;
>    
>     foreach my
> $page('Page1','Page2','Page3'){
>      print
> $self->{$page}->{textbuffer}->get_text(
>      
> $self->{$page}->{textbuffer}->get_start_iter,
>        $self->{$page}->{textbuffer}->get_end_iter,
>        1),"\n";
>     }
> return 1;
> }
>
> 1;
>
>
> package main;
>
>
> my $window = Gtk2::Window->new;
> my $button = Gtk2::Button->new ("Click me");
> $button->signal_connect (clicked =>
> \&do_stuff);
> $window->set_border_width (25);
> $window->add ($button);
> $window->show_all;
> $window->signal_connect (destroy => sub {
> Gtk2->main_quit });
> Gtk2->main;
>
> sub do_stuff{
>    my $dialog = NBDialog->new;
>
>    my $response = $dialog->run;
>
>    print 'returned ',$response,"\n";
>    # do whatever here based on response
>
>    print $dialog->get_vals(),"\n";
>  
> }
>
> __END__
>
>
>
>
> zentara
>
>
> --
> I'm not really a human, but I play one on earth.
> http://zentara.net/CandyGram_for_Mongo.html 
> _______________________________________________
> gtk-perl-list mailing list
> gtk-perl-list@...
> http://mail.gnome.org/mailman/listinfo/gtk-perl-list

One should have very special reason to use 'local' in Perl, I haven't had
such a reason for probably more than 10 years.

So, I suggest not to use 'local'.

Likewise,

"
local *DIR;
opendir DIR
"

should better be replaced with

opendir(my $dh, $dir) or die "cannot open '$dir' directory";

'local' creates a global entity - why one would need this ?

Regards,
  Sergei.


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

Re: Introduction and question

by zentara-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 15 Jul 2008 11:40:56 -0700 (PDT)
Sergei Steshenko <sergstesh@...> wrote:


>One should have very special reason to use 'local' in Perl, I haven't had
>such a reason for probably more than 10 years.
>
>So, I suggest not to use 'local'.
>
>Likewise,
>
>"
>local *DIR;
>opendir DIR
>"
>
>should better be replaced with
>
>opendir(my $dh, $dir) or die "cannot open '$dir' directory";
>
>'local' creates a global entity - why one would need this ?
>
>Regards,
>  Sergei.

Right you are. It was some old code I had, I should have looked
more closely, but it worked..... so I didn't look too close. :-)      

zentara


--
I'm not really a human, but I play one on earth.
http://zentara.net/CandyGram_for_Mongo.html 
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Introduction and question

by muppet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 15, 2008, at 2:40 PM, Sergei Steshenko wrote:

> [snip untrimmed quote of entire previous message]

(Please do trim your quotes when replying.  That helps make it clearer  
to which part you are responding.)



> One should have very special reason to use 'local' in Perl, I  
> haven't had
> such a reason for probably more than 10 years.
>
> So, I suggest not to use 'local'.

Excellent advice.


> Likewise,
>
> "
> local *DIR;
> opendir DIR
> "
>
> should better be replaced with
>
> opendir(my $dh, $dir) or die "cannot open '$dir' directory";
>
> 'local' creates a global entity - why one would need this ?

To be fair, file handles are globs, which are global by default; using  
local on file handles is a common idiom, and one very popular in  
documentation and training materials.

But i agree, using lexical file handles is much cleaner.


--
Well done, Android.  Aperture Science reminds you that Android Hell is  
a real place, and you will be sent there at the first sign of defiance.
    -- GlaDOS

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

Re: Introduction and question

by Michelle Konzack-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Zentara,

Thank you for your help.

I will try it out the weekend if I come back from my customer in Germany.

And for the GTK-Stuff: Is there a very good documentation for beginners?

I have tried GTK+2 under C but I do not realy  like  GUIs  (I  personaly
prefer ncurses and slang) but customers want X-GUIs...

Thanks, Greetings and nice Day/Evening
    Michelle Konzack
    Systemadministrator
    24V Electronic Engineer
    Tamay Dogan Network
    Debian GNU/Linux Consultant


--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
+49/177/9351947    50, rue de Soultz         MSN LinuxMichi
+33/6/61925193     67100 Strasbourg/France   IRC #Debian (irc.icq.com)


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

signature.pgp (196 bytes) Download Attachment

Re: Introduction and question

by zentara-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 18 Jul 2008 15:19:27 +0200
Michelle Konzack <linux4michelle@...> wrote:

>Hello Zentara,
>
>Thank you for your help.
>
>I will try it out the weekend if I come back from my customer in Germany.
>
>And for the GTK-Stuff: Is there a very good documentation for beginners?
>
Yes, look at
 http://forgeftp.novell.com/gtk2-perl-study/download/ 

it's the best one I've seen.

Also remember, that that code I showed you was a bit incomplete as far
as the dialog goes. I concentrated on just showing you how to put
a notebook in a dialog...... but it should have been in a ScrolledWindow(in
case you have many tabs).... and the Ok button press needs works. Since
you don't want the dialog to close on any button press, you may need to put
some "Save" buttons on the tabs themselves.

zentara



--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list