[yast-commit] r63458 - /trunk/libyui-bindings/swig/perl/examples/twitter.pl
Author: mvidner Date: Tue Feb 22 14:46:58 2011 New Revision: 63458 URL: http://svn.opensuse.org/viewcvs/yast?rev=63458&view=rev Log: A simple dialog that posts to Twitter. Written by Bubli for her Linux Tag 2010 talk: http://www.linuxtag.org/2010/en/program/free-conference/popup/details-talkid... Added: trunk/libyui-bindings/swig/perl/examples/twitter.pl Added: trunk/libyui-bindings/swig/perl/examples/twitter.pl URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui-bindings/swig/perl/examples/twitter.pl?rev=63458&view=auto ============================================================================== --- trunk/libyui-bindings/swig/perl/examples/twitter.pl (added) +++ trunk/libyui-bindings/swig/perl/examples/twitter.pl Tue Feb 22 14:46:58 2011 @@ -0,0 +1,115 @@ +#!/usr/bin/perl + +use yui; +use Data::Dumper; +use Net::Twitter::Lite; + +my $nt; +my $factory = yui::YUI::widgetFactory; + +sub login { + my $username = shift; + my $password = shift; + + $nt = Net::Twitter::Lite->new( + username => $username, + password => $password, + ); +} + +sub post { + my $newdialog = $factory->createPopupDialog; + + my $min = $factory->createMinWidth($newdialog, 45); + my $vvbox = $factory->createVBox( $min ); + my $textbox = $factory->createMultiLineEdit($vvbox, "What's up?"); + + my $hbox = $factory->createHBox( $vvbox ); + + my $left = $factory->createLeft( $hbox ); + my $statuslabel = $factory->createLabel($left, "Ready ..."); + my $right = $factory->createRight( $hbox ); + my $update = $factory->createPushButton( $right, "Post Update..." ); + my $cruft = $factory->createVSpacing($vvbox, 1); + my $cancel = $factory->createPushButton( $vvbox, "Quit" ); + + while ( 1 ) { + $event = $newdialog->waitForEvent(); + + if ( not event) { + next + } + + # break the loop, quit + + if ($event->widget() == $cancel ) { + last; + } + + # post an update + + if ($event->widget() == $update ) { + my $text = $textbox->value(); + eval { $nt->update($text) }; + + if ( $@ ) { + $statuslabel->setValue( "Update failed!" ); + } + else { + $statuslabel->setValue( "Update OK :)"); + $textbox->setValue(""); + } + next; + } + } + # clean up + $newdialog->destroy(); +} + +my $dialog = $factory->createPopupDialog; + +#################################################### +# # +# dialog # +# vbox # +# label # +# input field # +# passwd field # +# spacing # +# hbox # +# pushbutton # +# pushbutton # +# # +#################################################### + +my $vbox = $factory->createVBox( $dialog ); +my $label = $factory->createLabel( $vbox, "Login to your Twitter account"); +my $username = $factory->createInputField($vbox, "User"); +$username->setStretchable( $yui::YD_HORIZ, 1 ); +my $pass = $factory->createPasswordField($vbox,"Password"); +$pass->setStretchable( $yui::YD_HORIZ, 1 ); + +my $fillup = $factory->createVSpacing($vbox, 1); +my $buttonbox = $factory->createHBox( $vbox ); +my $cancel = $factory->createPushButton( $buttonbox, "Cancel" ); +my $login = $factory->createPushButton( $buttonbox, "Login" ); + +while ( 1 ) { + $event = $dialog->waitForEvent(); + if ( not event ) { + next + } + + if ($event->widget() == $cancel ) { + $dialog->destroy(); + last; + } + + if ($event->widget() == $login ) { + login( $username->value(), $pass->value() ); + $dialog->destroy(); + post; + last; + } +} + -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
mvidner@svn2.opensuse.org