Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

UI::Dialog fselect

by stangoesagain (Acolyte)
on Apr 21, 2016 at 06:57 UTC ( [id://1161064]=perlquestion: print w/replies, xml ) Need Help??

stangoesagain has asked for the wisdom of the Perl Monks concerning the following question:

I'm using UI::Dialog to select a file for processing. When I get to this point:

#!/usr/bin/perl use strict; use warnings; use 5.010; use UI::Dialog; my $d = new UI::Dialog ( title => 'SelectFile', order => [ 'kdialog', 'zenity', 'xdialog' ] ); my $fileIn = $d->fselect( path => '/path/to/my/files/' ); say "Selected: $fileIn";

The selected file name prints to the terminal but $fileIn in say "Selected: $fileIn"; line is empty. I swear it worked just a few months ago when I first created this script.

If I initialize $fileIn first and assign it some value, "test", for example, fselect still makes it empty again.

What gives? Is it something system related? I got it working with Tk but Tk doesn't look as nice as KDE's native file selection dialog.

UPDATE: As a workaround I used Capture::Tiny, put fselect into a sub, and chomped the return.

#!/usr/bin/perl use strict; use warnings; use 5.010; use UI::Dialog; use Capture::Tiny ':all'; my $d = new UI::Dialog ( title => 'SelectFile', order => [ 'kdialog', 'zenity', 'xdialog' ] ); sub filename{ my $selected = $d->fselect( path => '/path/to/my/files/' ); return $selected; } my $fileIn = capture_stdout \&filename; chomp $fileIn; #because there's newline at the end of stdout say "Selected: $fileIn";

Replies are listed 'Best First'.
Re: UI::Dialog fselect
by Marshall (Canon) on Apr 21, 2016 at 12:09 UTC
    I installed UI::Dialog and got the following results, something is wrong as shown below... Missing module?
    #!/usr/bin/perl use strict; use warnings; use 5.010; use UI::Dialog; my $d = new UI::Dialog ( backtitle => 'Demo', title => 'Default', height => 20, width => 65 , listheight => 5, ## this is a problem ### order => [ 'zenity', 'xdialog' ] ); ); # Either a Zenity or Xdialog msgbox widget should popup, # with a preference for Zenity. $d->msgbox( title => 'Welcome!', text => 'Welcome one and all!' ); __END__ Prints: +------------------------------------------------------------------- +----------+ | Demo + | +------------------------------------------------------------------- +----------+ | + | | +----------------------------------------------------------------- +--------+ | | | Welcome! + | | | +----------------------------------------------------------------- +--------+ | | | Welcome one and all! + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | +----------------------------------------------------------------- +--------+ | | + | +------------------------------------------------------------------- +----------+ [ Press Enter to Continue ] Process completed successfully

      That's an idea - I've tried with zenity being preferred and fselect assigns value to variable as expected. I don't have xdialog installed so if I try xdialog I get "unable to load suitable backend" but not terminal output like yours.

      I suspect kdialog part of UI::Dialog hasn't been updated to work with latest KDE. On my system there was a jump from 4 to 5, not sure about exact version when it got broken. I use kdialog for file selection all the time and it works flawlessly when evoked by bash scripts.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1161064]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-18 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found