3 uis for the price of one code

Download 3 UIs for the price of one code

If you can't read please download the document

Upload: hedgehogpainter

Post on 16-Apr-2017

2.963 views

Category:

Technology


1 download

TRANSCRIPT

3 UIs for the price of one code
with YaST's libyui

Katarna MachlkovSoftware Engineer (YaST)[email protected]

Talk outline

Introduction why libyui (Hello World!)Brief Tour de Libyui internalsMy first libyui applicationIntroducing different language bindingsSample non-C++ libyui applicationDocumentation, useful linksQuestions, answers, ...

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!"); hw.resize(75, 30);

QObject::connect(&hw, SIGNAL(clicked()), &app, SLOT(quit())); hw.show(); return app.exec();

}

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;}

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;}

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();}

Libyui from the inside

Introducing libyui

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

YaST UI Architecture

Widgets (dialog building blocks)

Parent widget

Properties (get/set)Value (string, integer)

Items

Label

Current item

Widget id (optional)

Types of widgets

SimpleCheckBox, Label, InputField, PushButton, ...

Layout aidsVBox, HBox, VStretch,...

One-of-many, N-of-many selectorsComboBox, SelectionBox, Table, Tree,...

Events (user input results)

Sample event loop while(true){ YEvent *ev = dialog->waitForEvent(); do_something (ev);}

User interaction with dialog causes waitForEvent (blocking call) to return

Each event hasType (cancel event, widget event,...)

Reason (selection changed, widget was activated,...)

Pointer (or id) of the widget that broke the event loop

What libyui does not support

Multiple threads

Signals, slots, callbacks,...

Advanced graphics (3D, animations,...)

Non-blocking event handling

My first libyui application

Developer's check-list

Header files( yast2-libyui-devel)

Compiler (gcc-c++)

YaST UI package ( yast2-[qt|gtk|ncurses] )

Favourite text editor / IDE :)

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();}

Compile & run it

'g++ -I/usr/include/YaST2/libyui -lyui HelloWorld.cc -o HelloWorld'

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.

Hello World dissected, part I

int main( int argc, char **argv ){ YDialog *dialog = YUI::widgetFactory()->createPopupDialog();

YLayoutBox *vbox = YUI::widgetFactory()->createVBox( dialog);

1st call creates UI instance and w.factory instance

Get widget pointer from w.factory

Widget container(layout aid)

Child of the main dialog

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

Hello World dissected, part III

dialog->waitForEvent();

dialog->destroy();

}

Wait for user inputUse this in event loops

Close the dialog, do the final cleanup

But I don't speak C++ ?

Other scripting language bindings

Python

Ruby

Perl

C++ bindings

Enter perl/python/ruby bindings

Independence on YCP and YaST core

Standard C++ (STL) data types (std::string, std::list,...)

Easy way to swig-generated language bindings

Currently for perl, python and ruby

'zypper in [perl|python|ruby]-yui' (that's it )

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();

Hello World with python-yui

# Trivial usage of libyui # in pretty the same way# in python##!/usr/bin/python

import sysimport 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()

More complex non-C++ application

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.

Simple zypp.conf editor with perl-yui

(live demonstration)

When things don't work ...

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.

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,...

Found a bug in libyui-(bindings)?http://bugzilla.novell.com, YaST component

More Information

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

General YaST doc (incl. widget reference):http://forgeftp.novell.com/yast/doc/SL11.1

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 protected]

Development tips & tricks

Questions & (maybe) answers

Click to enter the title (44pt)
Second line or subtitle (22pt)

Presenter Name (16pt)Presenter Title (14pt)Company/email (14pt)

Click to Edit Section Break Text (32pt)
Right Justified

piece in master that I can't get rid of

Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level

Click to edit the title text format

Click to edit the title text format (32pt)

Click to edit the outline text format (24pt)Second Outline Level (20pt)Third Outline Level (16 pt)Fourth Outline Level (14pt)Fifth Outline Level (12pt)

Novell Inc. All rights reserved

Click to edit the title text format

Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline Level

Hello, World!