Skip to content

Instantly share code, notes, and snippets.

@anaselli
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anaselli/d2f4b029c7058f819719 to your computer and use it in GitHub Desktop.
Save anaselli/d2f4b029c7058f819719 to your computer and use it in GitHub Desktop.
diff --git a/swig/yui.i b/swig/yui.i
index ec38584..8373555 100644
--- a/swig/yui.i
+++ b/swig/yui.i
@@ -270,6 +270,15 @@ class Exception;
}
#endif
+%extend YItem {
+#if defined(SWIGPERL5)
+ int __eq__( YItem *i )
+ { return ($self == i); }
+ int __ne__( YItem *i )
+ { return ($self != i); }
+#endif
+}
+
namespace std {
%template(YItemCollection) vector<YItem *>;
}
@@ -343,6 +352,14 @@ YItemIterator incrYItemIterator( YItemIterator currentIterator) {
return ++currentIterator;
}
+YItemIterator beginYItemCollection( YItemCollection *coll) {
+ return coll->begin();
+}
+
+YItemIterator endYItemCollection( YItemCollection *coll) {
+ return coll->end();
+}
+
YTableCellIterator incrYTableCellIterator(YTableCellIterator currentIterator) {
return ++currentIterator;
}
#!/usr/bin/perl
use yui;
my $factory = yui::YUI::widgetFactory;
my $dialog = $factory->createPopupDialog;
my $vbox = $factory->createVBox( $dialog );
my $menu_example = $factory->createMenuButton($vbox, "Menu Example");
$menu_example->addItem(new yui::YMenuItem("Example 1"));
$menu_example->addItem(new yui::YMenuItem("Example 2"));
$menu_example->rebuildMenuTree();
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 );
$hbox = $factory->createHBox( $vbox );
my $itemAddress = $factory->createOutputField( $hbox, "<selected item value reference value>" );
$itemAddress->setStretchable( $yui::YD_HORIZ, 1 );
$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
}
my $eventType = $event->eventType();
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::MenuEvent) {
my $item = $event->item();
if ($item) {
$valueField->setValue( $item->label() );
$itemAddress->setValue ( "addr: " . int($item) . " index " . $item->index() );
}
else {
$valueField->setValue( "<none>" );
$itemAddress->setValue("<none>");
}
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
$valueField->setValue( "???" );
if ($event->widget() == $closeButton) {
last;
}
elsif ( ($event->widget() == $valueButton) or ($event->widget() == $selBox )) {
$item = $selBox->selectedItem();
if ($item) {
$valueField->setValue( $item->label() );
$itemAddress->setValue ( "addr: " . int($item) . " index " . $item->index() );
}
else {
$valueField->setValue( "<none>" );
$itemAddress->setValue("<none>");
}
}
}
}
$dialog->destroy();
1;
#!/usr/bin/perl
#uncomment next if you're testing int libyui-bindings swig/perl/examples
#use lib '../../../build/swig/perl';
use yui;
my $factory = yui::YUI::widgetFactory;
my $dialog = $factory->createPopupDialog;
my $vbox = $factory->createVBox( $dialog );
my $menu_example = $factory->createMenuButton($vbox, "Menu Example");
my $menu1 = new yui::YMenuItem("Example 1");
$menu_example->addItem($menu1);
my $menu2 = new yui::YMenuItem("Example 2");
$menu_example->addItem($menu2);
$menu_example->rebuildMenuTree();
my $selBox = $factory->createSelectionBox( $vbox, "&Menu" );
my $itemColl = new yui::YItemCollection;
my $pizza_margherita = new yui::YItem("Pizza Margherita");
$itemColl->push($pizza_margherita);
$pizza_margherita->DISOWN();
my $pizza_capricciosa = new yui::YItem( "Pizza Capricciosa" );
$itemColl->push($pizza_capricciosa);
$pizza_capricciosa->DISOWN();
my $pizza_funghi = new yui::YItem( "Pizza Funghi" );
$itemColl->push($pizza_funghi);
$pizza_funghi->DISOWN();
my $pizza_prosciutto = new yui::YItem( "Pizza Prosciutto" );
$itemColl->push($pizza_prosciutto);
$pizza_prosciutto->DISOWN();
my $pizza_4stagioni = new yui::YItem( "Pizza Quattro Stagioni" );
$itemColl->push($pizza_4stagioni);
$pizza_4stagioni->DISOWN();
my $pizza_calzone = new yui::YItem( "Calzone" );
$itemColl->push($pizza_calzone);
$pizza_calzone->DISOWN();
$selBox->addItems( $itemColl );
my $hbox = $factory->createHBox( $vbox );
$valueField = $factory->createOutputField( $hbox, "<SelectionBox value unknown>" );
$valueField->setStretchable( $yui::YD_HORIZ, 1 );
$hbox = $factory->createHBox( $vbox );
my $itemAddress = $factory->createOutputField( $hbox, "<selected item value reference value>" );
$itemAddress->setStretchable( $yui::YD_HORIZ, 1 );
$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
}
my $eventType = $event->eventType();
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::MenuEvent) {
my $item = $event->item();
if ($item) {
$valueField->setValue( $item->label() );
$itemAddress->setValue ( "addr: " . int($item) . " index " . $item->index() );
if ($item == $menu1) {
print " Menu 1 found!\n";
}
elsif ($item == $menu2) {
print " Menu 2 found!\n";
}
else {
print "no menu found! :(\n"
}
}
else {
$valueField->setValue( "<none>" );
$itemAddress->setValue("<none>");
}
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
$valueField->setValue( "???" );
if ($event->widget() == $closeButton) {
last;
}
elsif ( ($event->widget() == $valueButton) or ($event->widget() == $selBox )) {
$item = $selBox->selectedItem();
if ($item) {
$valueField->setValue( $item->label() );
$itemAddress->setValue ( "addr: " . int($item) . " index " . $item->index() );
if ($item == $pizza_margherita) {
print "Pizza Margherita chosen!\n";
}
my $it = yui::beginYItemCollection($itemColl);
print "looking for the chosen item from YItemCollection\n";
while ($it = yui::incrYItemIterator($it)) {
my $currentItem = eval {yui::toYItem($it)};
last if !$currentItem;
if ($item == $currentItem) {
print "Selected item is " . $currentItem->label . "\n";
last;
}
}
}
else {
$valueField->setValue( "<none>" );
$itemAddress->setValue("<none>");
}
}
}
}
$dialog->destroy();
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment