Skip to content

Instantly share code, notes, and snippets.

@anaselli
Last active September 13, 2015 13:20
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/bbdee6ddb590b58af958 to your computer and use it in GitHub Desktop.
Save anaselli/bbdee6ddb590b58af958 to your computer and use it in GitHub Desktop.
multiplication tables with libyui
#
# Copyright (C) 2015, Angelo Naselli.
#
# TThis program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
#
use yui;
my $factory = yui::YUI::widgetFactory;
# Create Dialog
my $dialog = $factory->createMainDialog;
# Start Dialog layout:
my $layout = $factory->createVBox($dialog);
my $hbox = $factory->createHBox($layout);
my $f1 = $factory->createLabel($hbox, "0000");
$factory->createHSpacing($hbox, 1);
$factory->createLabel($hbox, " X ");
$factory->createHSpacing($hbox, 1);
my $f2 = $factory->createLabel($hbox, "0000");
$factory->createHSpacing($hbox, 1);
$factory->createLabel($hbox, " = ");
$factory->createHSpacing($hbox, 1);
my $inResult = $factory->createInputField($hbox, "", 0);
my $Result = $factory->createPushButton($hbox, "Result");
my $message = $factory->createLabel($layout, "..............................");
$factory->createVSpacing($layout, 2);
my $Exit = $factory->createPushButton($factory->createRight($layout), "Exit");
my $n1 = int(rand(10)) + 1;
my $n2 = int(rand(10)) + 1;
$f1->setLabel(" $n1 ");
$f2->setLabel(" $n2 ");
$dialog->setDefaultButton($Result);
$inResult->setKeyboardFocus();
while(1) {
my $event = $dialog->waitForEvent();
my $eventType = $event->eventType();
#event type checking
if ($eventType == $yui::YEvent::CancelEvent) {
last;
}
elsif ($eventType == $yui::YEvent::WidgetEvent) {
### widget
my $widget = $event->widget();
if ($widget == $Exit) {
last;
}
elsif ($widget == $Result) {
my $res = int($inResult->value());
print "Inseriti $n1 x $n2 = $res\n";
if ($res == $n1 * $n2) {
$dialog->startMultipleChanges();
$message->setLabel("Great!");
$n1 = int(rand(10)) + 1;
$n2 = int(rand(10)) + 1;
$f1->setLabel(" $n1 ");
$f2->setLabel(" $n2 ");
$inResult->setValue("");
$dialog->setDefaultButton($Result);
$inResult->setKeyboardFocus();
$dialog->doneMultipleChanges();
}
else {
$dialog->startMultipleChanges();
$message->setLabel("Check better!");
$dialog->doneMultipleChanges();
}
}
}
}
destroy $dialog;
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment