Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-release > by-pkgid > f810b6f290c4f2e554d2854b85d84a44 > files > 8

perl-yui-1.0.4-0.git20140418.10.mga5.x86_64.rpm

#!/usr/bin/perl
#
# More advanced libyui example
#

use lib '../../../build/swig/perl';

use yui;

# yui::YUILog::setLogFileName( "/tmp/libyui-examples.log" );
# yui::YUILog::enableDebugLogging();

my $factory = yui::YUI::widgetFactory;
my $dialog = $factory->createPopupDialog;

my $vbox = $factory->createVBox( $dialog );

my $selBox = $factory->createSelectionBox( $vbox, "&Menu" );

$selBox->addItem( "Pizza Margherita" );
$selBox->addItem( "Pizza Capricciosa" );
$selBox->addItem( "Pizza Funghi" );
$selBox->addItem( "Pizza Prosciutto" );
$selBox->addItem( "Pizza Quattro Stagioni" );
$selBox->addItem( "Calzone" );

my $hbox = $factory->createHBox( $vbox );
$valueField  = $factory->createOutputField( $hbox, "<SelectionBox value unknown>" );
$valueField->setStretchable( $yui::YD_HORIZ, 1 ); # // allow stretching over entire dialog width

$valueButton = $factory->createPushButton( $hbox, "&Value" ); 
$factory->createVSpacing( $vbox, 0.3 );

$rightAlignment = $factory->createRight( $vbox );
$closeButton    = $factory->createPushButton( $rightAlignment, "&Close" );

#
# Event loop
#
while (1) {
  $event = $dialog->waitForEvent();
  if( not event ) {
    next
  }
  if ($event->eventType() == $yui::YEvent::CancelEvent) { # window manager "close window" button
    last;
  }
  $valueField->setValue( "???" );
  if ($event->widget() == $closeButton) {
    last;
  }

  if ( ($event->widget() == $valueButton) or ($event->widget() == $selBox )) {		# selBox will only send events with setNotify()
    $item = $selBox->selectedItem();
    if ($item) {
      $valueField->setValue( $item->label() );
    }
    else {
      $valueField->setValue( "<none>" );
    }
  }
}