3 UIs for the price of one code
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

3 UIs for the price of one code

on

  • 3,694 views

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

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

Statistics

Views

Total Views
3,694
Views on SlideShare
3,680
Embed Views
14

Actions

Likes
2
Downloads
39
Comments
0

2 Embeds 14

http://www.slideshare.net 13
http://us-w1.rockmelt.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Now we'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.

3 UIs for the price of one code Presentation Transcript

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