0
3 UIs for the price of one code with YaST's libyui  Katarína Machálková Software Engineer (YaST) [email_address]
 
Talk outline Introduction – why libyui (Hello World!) Brief Tour de Libyui internals My first libyui application Introduci...
Intro & Motivation
The most famous app of all times  ☺
Hello World in Qt ... int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton hw("Hello World!&q...
…  in Gtk ... int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *button; gtk_init (&argc, &argv); window = ...
… and in ncurses ... int main(void) { WINDOW * mainwin; if ( (mainwin = initscr()) == NULL ) { exit(EXIT_FAILURE); } mvadd...
One code, three user interfaces! #include "YUI.h" #include "YWidgetFactory.h" #include "YDialog.h...
Libyui from the inside
Introducing libyui <ul><li>Library written in C++
Provides abstraction from GUI and TUI toolkits (Qt, Gtk, ncurses) in terms of widgets (UI elements) and events
YaST user interface engine
Independent of YCP (after major rewrite in 2006)
Independent of YaST core libraries and libzypp (dtto)
Dialogs, widgets + event handling </li></ul>
YaST UI Architecture
Widgets (dialog building blocks) <ul><li>Parent widget
Properties (get/set) </li><ul><li>Value (string, integer)
Items
Label
Current item
… </li></ul><li>Widget id (optional) </li></ul>
Types of widgets <ul><li>Simple </li><ul><li>CheckBox, Label, InputField, PushButton, ... </li></ul><li>Layout aids </li><...
Events (user input results) <ul><li>Sample event loop </li><ul><li>while(true)
{
YEvent *ev = dialog->waitForEvent();
do_something (ev);
} </li></ul><li>User interaction with dialog causes waitForEvent (blocking call) to return
Each event has </li><ul><li>Type (cancel event, widget event,...)
Reason (selection changed, widget was activated,...)
Pointer (or id) of the widget that broke the event loop </li></ul></ul>
What libyui does not support <ul><li>Multiple threads
Signals, slots, callbacks,...
Advanced graphics (3D, animations,...)
Non-blocking event handling </li></ul>
Upcoming SlideShare
Loading in...5
×

3 UIs for the price of one code

2,487

Published on

Introduction to programming with libyui (widget abstraction library providing Qt, Gtk and ncurses frontends with single code base)

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,487
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
39
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • Now we&apos;ll move onto the different scripts you can run at different times. Followed by some example of the kind of thing that can be done in the scripts.
  • Trouble shooting an Aytoyast seutp can be tricky. There are several places where things can go wrong, and debugging post install scripts can require a reinstall each time. However, there are some places to find information.
  • Transcript of "3 UIs for the price of one code"

    1. 1. 3 UIs for the price of one code with YaST's libyui Katarína Machálková Software Engineer (YaST) [email_address]
    2. 3. Talk outline Introduction – why libyui (Hello World!) Brief Tour de Libyui internals My first libyui application Introducing different language bindings Sample non-C++ libyui application Documentation, useful links Questions, answers, ...
    3. 4. Intro & Motivation
    4. 5. The most famous app of all times ☺
    5. 6. Hello World in Qt ... int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton hw(&quot;Hello World!&quot;); hw.resize(75, 30); QObject::connect(&hw, SIGNAL(clicked()), &app, SLOT(quit())); hw.show(); return app.exec(); }
    6. 7. … in Gtk ... int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *button; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (window), &quot;destroy&quot;, GTK_SIGNAL_FUNC (destroy), NULL); gtk_container_border_width (GTK_CONTAINER (window), 10); button = gtk_button_new_with_label (&quot;Hello World&quot;); gtk_signal_connect (GTK_OBJECT (button), &quot;clicked&quot;, GTK_SIGNAL_FUNC (hello), NULL); gtk_signal_connect_object (GTK_OBJECT (button), &quot;clicked&quot;, GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (window)); gtk_container_add (GTK_CONTAINER (window), button); gtk_widget_show (button); gtk_widget_show (window); gtk_main (); return 0; }
    7. 8. … and in ncurses ... int main(void) { WINDOW * mainwin; if ( (mainwin = initscr()) == NULL ) { exit(EXIT_FAILURE); } mvaddstr(13, 33, &quot;Hello, world!&quot;); refresh(); sleep(3); delwin(mainwin); endwin(); refresh(); return EXIT_SUCCESS; }
    8. 9. One code, three user interfaces! #include &quot;YUI.h&quot; #include &quot;YWidgetFactory.h&quot; #include &quot;YDialog.h&quot; #include &quot;YLayoutBox.h&quot; #include &quot;YEvent.h&quot; int main( int argc, char **argv ) { YDialog *dialog = YUI::widgetFactory()->createPopupDialog(); YLayoutBox *vbox = YUI::widgetFactory()->createVBox( dialog); YUI::widgetFactory()->createLabel( vbox, &quot;Hello, World!&quot; ); YUI::widgetFactory()->createPushButton( vbox, &quot;&OK&quot; ); dialog->waitForEvent(); dialog->destroy(); }
    9. 10. Libyui from the inside
    10. 11. Introducing libyui <ul><li>Library written in C++
    11. 12. Provides abstraction from GUI and TUI toolkits (Qt, Gtk, ncurses) in terms of widgets (UI elements) and events
    12. 13. YaST user interface engine
    13. 14. Independent of YCP (after major rewrite in 2006)
    14. 15. Independent of YaST core libraries and libzypp (dtto)
    15. 16. Dialogs, widgets + event handling </li></ul>
    16. 17. YaST UI Architecture
    17. 18. Widgets (dialog building blocks) <ul><li>Parent widget
    18. 19. Properties (get/set) </li><ul><li>Value (string, integer)
    19. 20. Items
    20. 21. Label
    21. 22. Current item
    22. 23. … </li></ul><li>Widget id (optional) </li></ul>
    23. 24. Types of widgets <ul><li>Simple </li><ul><li>CheckBox, Label, InputField, PushButton, ... </li></ul><li>Layout aids </li><ul><li>VBox, HBox, VStretch,... </li></ul><li>One-of-many, N-of-many “selectors” </li><ul><li>ComboBox, SelectionBox, Table, Tree,... </li></ul></ul>
    24. 25. Events (user input results) <ul><li>Sample event loop </li><ul><li>while(true)
    25. 26. {
    26. 27. YEvent *ev = dialog->waitForEvent();
    27. 28. do_something (ev);
    28. 29. } </li></ul><li>User interaction with dialog causes waitForEvent (blocking call) to return
    29. 30. Each event has </li><ul><li>Type (cancel event, widget event,...)
    30. 31. Reason (selection changed, widget was activated,...)
    31. 32. Pointer (or id) of the widget that broke the event loop </li></ul></ul>
    32. 33. What libyui does not support <ul><li>Multiple threads
    33. 34. Signals, slots, callbacks,...
    34. 35. Advanced graphics (3D, animations,...)
    35. 36. Non-blocking event handling </li></ul>
    36. 37. My first libyui application
    37. 38. Developer's check-list <ul><li>Header files( yast2-libyui-devel )
    38. 39. Compiler ( gcc-c++ )
    39. 40. YaST UI package ( yast2-[qt|gtk|ncurses] )
    40. 41. Favourite text editor / IDE :) </li></ul>
    41. 42. Code it ... #include &quot;YUI.h&quot; #include &quot;YWidgetFactory.h&quot; #include &quot;YDialog.h&quot; #include &quot;YLayoutBox.h&quot; #include &quot;YEvent.h&quot; int main( int argc, char **argv ) { YDialog *dialog = YUI::widgetFactory()->createPopupDialog(); YLayoutBox *vbox = YUI::widgetFactory()->createVBox( dialog); YUI::widgetFactory()->createLabel( vbox, &quot;Hello, World!&quot; ); YUI::widgetFactory()->createPushButton( vbox, &quot;&OK&quot; ); dialog->waitForEvent(); dialog->destroy(); }
    42. 43. Compile & run it <ul><li>' g++ -I/usr/include/YaST2/libyui -lyui
    43. 44. HelloWorld.cc -o HelloWorld'
    44. 45. Get Qt: </li><ul><li>'./HelloWorld ' </li></ul><li>Get Gtk ( new in 11.2 ) </li><ul><li>'./HelloWorld --gtk' </li></ul><li>Get ncurses: </li><ul><li>'unset DISPLAY; ./HelloWorld ' </li></ul></ul>Include libyui headers Link with libyui This emulates text-mode only env.
    45. 46. Hello World dissected, part I int main( int argc, char **argv ) { YDialog *dialog = YUI::widgetFactory()->createPopupDialog(); YLayoutBox *vbox = YUI::widgetFactory()->createVBox( dialog); 1 st call creates UI instance and w.factory instance Get widget pointer from w.factory Widget container (layout aid) Child of the main dialog
    46. 47. Hello World dissected, part II YUI::widgetFactory()->createLabel( vbox, &quot;Hello, World!&quot; ); YUI::widgetFactory()->createPushButton( vbox, &quot;&OK&quot; ); Create new widget, specify parent + property (string) Vert. container can have many children
    47. 48. Hello World dissected, part III dialog->waitForEvent(); dialog->destroy(); } Wait for user input Use this in event loops Close the dialog, do the final cleanup
    48. 49. But I don't speak C++ … ?
    49. 50. Other scripting language bindings Python Ruby Perl C++ bindings
    50. 51. Enter perl/python/ruby bindings <ul><li>Independence on YCP and YaST core
    51. 52. Standard C++ (STL) data types (std::string, std::list,...)
    52. 53. Easy way to swig-generated language bindings
    53. 54. Currently for perl, python and ruby
    54. 55. ' zypper in [perl|python|ruby]-yui ' (that's it ☺ ) </li></ul>
    55. 56. Hello World with perl-yui !/usr/bin/perl # # Trivial read-write (not write-only :) # example of libyui used from Perl # use yui; my $factory = yui::YUI::widgetFactory; my $dialog = $factory->createPopupDialog; my $vbox = $factory->createVBox( $dialog ); $factory->createLabel( $vbox, &quot;Hello,World!&quot;); $factory->createPushButton( $vbox, &quot;&OK&quot; ); my $event = $dialog->waitForEvent(); $dialog->destroy();
    56. 57. Hello World with python-yui # Trivial usage of libyui # in pretty the same way # in python # #!/usr/bin/python import sys import yui factory = yui.YUI.widgetFactory() dialog = factory.createPopupDialog() vbox = factory.createVBox( dialog ) factory.createLabel( vbox, &quot;Hello, World!&quot; ) factory.createPushButton( vbox, &quot;&OK&quot; ) event = dialog.waitForEvent() dialog.destroy()
    57. 58. More complex non-C++ application
    58. 59. Simple zypp.conf editor with perl-yui (live demonstration)
    59. 60. When things don't work ...
    60. 61. Logs, debugging & co. <ul><li>Redirect logs to file (avoid noise on stdout): </li><ul><li>'yui::YUILog::setLogFileName( &quot;/tmp/libyui-example.log&quot; );' </li></ul><li>Make logging more verbose </li><ul><li>' yui::YUILog::enableDebugLogging(); ' </li></ul><li>Usual suspects: gdb, valgrind,...
    61. 62. Found a bug in libyui-(bindings)? </li><ul><li>http://bugzilla.novell.com , YaST component </li></ul></ul>
    62. 63. More Information
    63. 64. Where to get more information? On line dokumentace: http://www.suse.de/~ug/ On line dokumentace: http://www.suse.de/~ug/ On line dokumentace: http://www.suse.de/~ug/ On line dokumentace: http://www.suse.de/~ug/ On line dokumentace: http://www.suse.de/~ug/ *-yui package doc with examples: /usr/share/doc/packages/*-yui On line dokumentace: http://www.suse.de/~ug/ On line dokumentace: http://www.suse.de/~ug/ On line dokumentace: http://www.suse.de/~ug/ On line dokumentace: http://www.suse.de/~ug/ On line dokumentace: http://www.suse.de/~ug/ YaST development mailing list: [email_address] General YaST doc (incl. widget reference): http://forgeftp.novell.com/yast/doc/SL11 .1
    64. 65. Development tips & tricks
    65. 66. Questions & (maybe) answers
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×