Mailinglist Archive: yast-devel (191 mails)

< Previous Next >
Re: [yast-devel] Perl YUI TextEntry
  • From: Martin Vidner <mvidner@xxxxxxx>
  • Date: Wed, 26 Mar 2008 12:48:26 +0100
  • Message-id: <20080326114826.GA5515@xxxxxxxxxxxxxxxx>
On Tue, Mar 25, 2008 at 07:59:41PM -0400, Justin Haygood wrote:
I'm trying to get the value of a YUI TextEntry (all in Perl).

I created the TextEntry via:

my $TextInput = TextEntry("Some Text","");

This let me add it to the VBOX:

my $c = VBox(
$TextInput,
PushButton("&OK")
);

UI->OpenDialog($c);
UI->UserInput();
UI->CloseDialog();

However, you can't get the value from either:

$value = $TextInput->Value; // Most Logical
$value = UI->QueryWidget( $TextInput, "Value" ); // Second Most Logical

What do I have to do in order to do this? Is this just incomplete Perl
bindings?

Hi Justin,

my $TextInput = TextEntry(id("Input"), "Some Text","");

This does not create the widget. It only creates a recipe (a term) for the
widget. So $TextInput->Value does not work. However,
$TextInput->name returns "TextEntry". Same with all the other
widgets.

The widgets only live in the dialogs, and you do not get objects
representing them. You can only access them via UI functions using
their ids as handles.
So UI->QueryWidget( $TextInput, "Value" ) does not work either, but
UI->QueryWidget(id("Input"), Symbol("Value") ) does.
(The "Symbol" is a necessity that I forgot to do away with. In YCP
it is just `Value vs "Value")

The fact that widgets only live inside dialogs also means that after
you close a dialog, you can no longer query its widgets. So
QueryWidget must come before CloseDialog.

Attached is a working version.

--
Martin Vidner, YaST developer
http://en.opensuse.org/User:Mvidner

Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
#!/usr/bin/perl
use YaST::YCP qw(:DATA :UI);
YaST::YCP::debug (1);
YaST::YCP::Import "UI";
YaST::YCP::init_ui ($ARGV[0] || "gtk");

my $c = VBox(
TextEntry( id("Input"), "Type Some Text",""),
PushButton(opt("default"), "&OK")
);

UI->OpenDialog($c);
UI->UserInput();
my $text = UI->QueryWidget(id("Input"),Symbol("Value"));
UI->CloseDialog();

print "It is '$text'\n";
< Previous Next >
Follow Ups