in reply to chooseDirectory set Default
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::JPEG; use Tk::Dialog; my $def_path; #defaults to current dir in DATA # read last stored value while(<DATA>){ if($_ =~ /^DIR:(.*)$/){ $def_path = $1 } } my $mw = MainWindow->new; # make sure def_dir gets written when program closes $SIG{INT} = sub { &close_it_up }; $mw->protocol('WM_DELETE_WINDOW' => sub { &close_it_up }); my $c = $mw->Canvas( # -tile => $tile, qw/-width 1500 -height 750/)->pack(-side => 'left'); my $path = $c->Label(-text => "Default Path For Saving Input Files", #-font => 'Arial 18 bold' )->place(-relx => 0.23, -rely => 0.4); my $path_text = $c->Entry(-textvariable => \$def_path, -width => 50)->place(-relx => 0.4, -rely => 0.4); my $path_button = $c->Button(-text => "Browse", #-font => 'Arial 8 bold', -width => 5, -command => [\&browse, $def_path])->place(-relx => 0.65, -r +ely => 0.4); MainLoop; sub browse { my $init_dir = shift; $def_path = $mw->chooseDirectory(-title => 'Select directory', -initialdir => $init_di +r, #-mustexist => 1 # scre +ws up on linux ); } sub close_it_up{ open(SELF,"+<$0")||die $!; while(<SELF>){last if /^__DATA__/} truncate(SELF,tell SELF); $def_path ||='.'; print SELF 'DIR:'; print SELF "$def_path"; print SELF $/; truncate(SELF,tell SELF); close SELF; Tk::exit; exit; } ############################################################ __END__ __DATA__ DIR:'.'
|
|---|