openSUSE Lizards

Authors
Adrian Schröter (2)
Agustin Chavarria (1)
Akhil Laddha
Alexander Naumov
Alexander Orlovskyy (3)
Alexey Eromenko
Alin M Elena (2)
Andrea Florio (5)
Andreas Jaeger (26)
Andreas van dem Helge
Andrej Semen
Andrew Wafaa (24)
Arvin Schnell (4)
Bharath Acharya
Brian G. Merrell
Carl Fletcher
Casual Programmer
Christoph Thiel
Christopher Hobbs (15)
Ciaran Farrell (2)
Coly Li
Cristian Rodríguez
Daniel Bornkessel
David C. Rankin
Dean Hilkewich
Dinar Valeev (5)
Dirk Müller (1)
Dmitry Serpokryl (4)
Duncan Mac-Vicar
Eugene Pivnev
Fabio Mucciante
Gabriele Mohr
Gerrit Beine
Helman Rene Taleno Martinez
Helmut Schaa
Henne (5)
Herbert Graeber
Holgi
Hubert Mantel (1)
J. Daniel Schmidt (1)
James Tremblay (5)
Jan Blunck (4)
Jan Madsen (1)
Jan Nieuwenhuizen
Jan-Christoph Bornschlegel (3)
Jan-Simon Möller (18)
Javier Llorente
Jigish Gohil (10)
Jiri Srain (1)
Jiří Suchomel (1)
Johan Kotze (5)
John Terpstra
Joop Boonen
Josef Reidinger (7)
Juergen Weigert (1)
Julio Vannini (7)
Justin Haygood
Kálmán Kéménczy
Kevin Yeaux (9)
Klaas Freitag (14)
Klara Cihlarova
Klaus Kämpf
Klaus Singvogel
kl_eisbaer (10)
Lars Marowsky-Bree
Ludwig Nussel (3)
M. Edwin Zakaria
Manuel Trujillo
Marcus Hüwe (6)
Marcus Meissner (1)
Marcus Moeller (1)
Marcus Schaefer (1)
Martin Lasarsch (8)
Martin Mohring (8)
Martin Schmidkunz
Masim "Vavai" Sugianto (20)
Matt Sealey
Mauro Parra-Miranda
Michael Andres (1)
Michael Skiba
Michal Marek (3)
Michal Vyskocil (6)
Michal Zugec
mrdocs
Nikanth Karthikesan
Oswin Zulu
Peter Nixon
Peter Pöml (3)
Petr Mladek (23)
Petr Uzel
Philipp Thomas
Pragnesh Radadiya
Ray Chen
Ray Wang (1)
Ricardo Varas Santana (3)
Richard Bos (3)
Robert Lihm
Roman Drahtmueller
Rossana Motta (1)
Rupert Horstkötter (7)
Sascha Manns (33)
Sebastian Schöbinger (3)
Stanislav Visnovsky (7)
Stefan Haas (1)
Stefan Hundhammer (5)
Stefan Schubert (3)
Steffen Winterfeldt (4)
Stephan Kulow (8)
Suman Manjunath
Susanne Oberhauser (2)
Syamsul Qamar Ngabito
Thomas Göttlicher (4)
Thomas Schraitle (11)
Thruth Wang
Tuukka (11)
Ulrich Hecht
Wilken Gottwalt
Xin Wei Hu





 

Developing with libyui/libzypp & python - part2

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.00 out of 5)
Loading ... Loading ...
Tuesday, September 23rd, 2008 by Jan-Simon Möller Digg!

In part 1 we installed and tested libyui and its python binding. Now let’s take a closer look at its usage.



A start is the “Hello World!” app we already know. The code is:
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()

In detail and with comments:
a) Initialization
import yui # import the module
#
factory = yui.YUI.widgetFactory() #create a widgetFactory object, mandatory
dialog = factory.createPopupDialog() #create a dialog, mandatory, Popup&Main available

b) Construct GUI
vbox = factory.createVBox( dialog )
# dialog can hold 1 widget, to hold a button and a label we create a vertically stacking box
factory.createLabel( vbox, "Hello, World!" ) # add a Label to the vbox
factory.createPushButton( vbox, "&OK" ) # add a Button to the vbox, will be placed below the label

c) Event handling
(in this simple case without loop)
event = dialog.waitForEvent() # wait for next event
dialog.destroy() # destroy dialog window

Let’s create an more usefull application - e.g. a “repository lister”. It takes a openSUSE BuildService Repository URL as input and lists the available packages. For now, we’ll do the GUI and the rpm magic later in part 3 and 4.
Our GUI should look like this:

Code could look like this: (note: indentations not shown here!)

#coding:utf-8
import yui
#
factory = yui.YUI.widgetFactory()
dialog = factory.createMainDialog()
#
# What do we need ?
# a VBOX ! dialog can hold only 1 widget, a VBox stacks multiple widgets vertically


mainVBox = factory.createVBox(dialog)
#
# a HBox for the upper part

upperHBox = factory.createHBox(mainVBox)
upperHBox.setWeight(1, 10) # 1 = vertical, 10 % size
#
# a Logwindow for the output


lowerLog = factory.createLogView(mainVBox, "Output", 4, 200)
lowerLog.setWeight(1, 90) # 1 = vertical, 90 % size
#
# let's add the input/combo/buttons to #1
#
# Input
myInput = factory.createInputField(upperHBox, "Repository URL")
myInput.setValue("http://software.opensuse.org/repositories/home:/dl9pf:/yuitest/openSUSE_11.0/")
myInput.setStretchable( 0, True ) # stretch the inputbox (0 = horizontally)
#
# ComboBox
myComboBox = factory.createComboBox(upperHBox, "Repository type")
myComboBox.addItem("RPM-MD")
myComboBox.setNotify()
#
# "Go"-Button
myGO = factory.createPushButton(upperHBox, "GO!")
myGO.setStretchable( 1, True ) # strech it vertically
#
# Close
Close = factory.createPushButton(mainVBox, "Close")


The event-code for the while-loop could look like:

# wait for the next event and return it
event = dialog.waitForEvent()
if not event: # no event ? skip !
continue
if event.eventType() == yui.YEvent.CancelEvent: # [x] in the top right corner ;)
dialog.destroy() # bail out
break
#
# check widgets …
#
if event.widget() == myGO:
# read input again
repoString = myInput.value()
lowerLog.appendLines( str( “Repository URL set to : “+str(repoString) ) )
lowerLog.appendLines(”\n”)
#todo:
#checkRepo()
#getRepoData()
#listRepo()
#
if event.widget() == Close:
dialog.destroy() # bail out
break

Code can be downloaded here,

Pictures were taken using YDialogSpy by Stefan Hundhammer. Tnx to Klaus Kaempf for the libyui-bindings.


Comments

No comments yet.

Sorry, the comment form is closed at this time.