#!/usr/bin/perl # # More advanced libyui example # use lib '../../../build/swig/perl'; use yui; #segmentation fault #yui::YUILoader::loadUI(1); yui::YUILog::setLogFileName( "libyui-examples.log" ); yui::YUILog::enableDebugLogging(); my $factory = yui::YUI::widgetFactory; # yui.YUILoader.loadWE("mga", "_Z9createWEv") - _Z8createWEv is default #yui::YUILoader::loadExternalWidgets("mga"); #my $weFactory = yui::YExternalWidgets::externalWidgetFactory(); # #print "yui::YExternalWidgets::widgetExtensionFactory " . ref($weFactory) . "\n" ; # #$weFactory = bless( $weFactory, yui::YMGAWidgetFactory); #$weFactory = yui::YMGAWidgetFactory::getYMGAWidgetFactory(yui::YExternalWidgets::externalWidgetFactory()); #print "yui::YExternalWidgets::widgetExtensionFactory " . ref($weFactory) . "\n" ; my $dialog = $factory->createPopupDialog; my $vbox = $factory->createVBox( $dialog ); my $selBox = $factory->createSelectionBox( $vbox, "&Menu" ); my $coll = new yui::YItemCollection; my $item = new yui::YItem("Pizza Margherita" ); $coll->push($item); $item->DISOWN(); $item = new yui::YItem( "Pizza Capricciosa" ); $coll->push($item); $item->DISOWN(); $item = new yui::YItem( "Pizza Funghi" ); $coll->push($item); $item->DISOWN(); $item = new yui::YItem( "Pizza Prosciutto" ); $coll->push($item); $item->DISOWN(); $item = new yui::YItem( "Pizza Quattro Stagioni" ); $coll->push($item); $item->DISOWN(); $item = new yui::YItem( "Calzone" ); $coll->push($item); $item->DISOWN(); print "1\n"; $selBox->addItems($coll); print "2\n"; #$selBox->addItem( "Pizza Margherita" ); #$selBox->addItem( "Pizza Capricciosa" ); #$selBox->addItem( "Pizza Funghi" ); #$selBox->addItem( "Pizza Prosciutto" ); #$selBox->addItem( "Pizza Quattro Stagioni" ); #$selBox->addItem( "Calzone" ); $coll->clear(); 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" ); print "LOOOOOOOP\n"; # # Event loop # while (1) { $event = $dialog->waitForEvent(); if( not event ) { next } print "event " . ref($event) . "\n"; if ($event->eventType() == $yui::YEvent::CancelEvent) { # window manager "close window" button last; } elsif ($event->eventType() == $yui::YEvent::WidgetEvent) { my $we = yui::toYWidgetEvent($event); if ($we) { print ".... ". ref($we) . "\n";} } $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>" ); } } } $dialog->destroy();