YaST/python-bindings-UI
From openSUSE
< YaST
Contents |
[edit]
Using UI from YaST
There are several important function and defined types for using UI from YaST in python:
- init_ui() - init function for selecting UI e.g. qt or ncurses
- Term - specific type in python for YaST terms
- Symbol - specific type in python for YaST symbol
[edit]
The basic working with UI:
#!/usr/bin/env python
# import python module for YaST
import ycp
# init qt for UI
ycp.init_ui('qt')
# import UI functions from YaST
ycp.import_module('UI')
if __name__ == "__main__":
# display push button
ycp.UI.OpenDialog(ycp.Term('PushButton','&OK'))
# waiting for user input
ycp.UI.UserInput()
# closing dialog
ycp.UI.CloseDialog()
Result of running script
[edit]
UI after hackweek:
I made support for calling standard widgets from YaST UI in ycp (module in python) namespace. There can be conflict with names of widget and names of YaST module. For example YaST includes module Wizard and also includes widget with name of Wizard For adding standard widgets into python were defined new functions:
- widget_names([namespace]) Import the widget names (InputField, VBox, Label, ...) into ycp.namespace, or directly into ycp if namespace is not specified
- __change_widget_name(current, new [, original]) Resolve conflict between YaST library modules and YaST widgets by renaming a widget. Suggested changes are __change_widget_name('Label', 'Text') and __change_widget_name('Wizard', 'Gandalf') and after that __change_widget_name('Gandalf', 'Mithrandir', 'Wizard')
[edit]
widget_names() in script
#!/usr/bin/env python
# import python module for YaST
import ycp
# adding widgets names from YaST to ycp (module in python)
ycp.widget_names()
# init qt for UI
ycp.init_ui('qt')
# import UI functions from YaST
ycp.import_module('UI')
if __name__ == "__main__":
# display push button
ycp.UI.OpenDialog(ycp.PushButton('&OK'))
# waiting for user input
ycp.UI.UserInput()
# closing dialog
ycp.UI.CloseDialog()
Result of running script
[edit]
widget_names() in script with using namespace 'WN'
#!/usr/bin/env python
# import python module for YaST
import ycp
# adding widgets names from YaST to ycp (module in python)
# there will be added new namespace "WN" after that is not
# necessary doing renaming via __change_widget_name()
ycp.widget_names('WN')
# init qt for UI
ycp.init_ui('qt')
# import UI functions from YaST
ycp.import_module('UI')
if __name__ == "__main__":
# display push button
ycp.UI.OpenDialog(ycp.WN.PushButton('&OK'))
# waiting for user input
ycp.UI.UserInput()
# closing dialog
ycp.UI.CloseDialog()
Result of running script
[edit]
widget_names() in script - little trick
#!/usr/bin/env python
# import python module for YaST
import ycp
# adding widgets names from YaST to ycp (module in python)
ycp.widget_names()
# init qt for UI
ycp.init_ui('qt')
# import UI functions from YaST
ycp.import_module('UI')
from ycp import *
if __name__ == "__main__":
# display push button
UI.OpenDialog(PushButton('&OK'))
# waiting for user input
UI.UserInput()
# closing dialog
UI.CloseDialog()
Result of running script
[edit]
__change_widget_name() in script
#!/usr/bin/env python
# import python module for YaST
import ycp
# adding widgets names from YaST to ycp (module in python)
ycp.widget_names()
# renaming widget names - widget name Label is known as Text now
ycp.__change_widget_name('Label', 'Text')
# init qt for UI
ycp.init_ui('qt')
# import UI functions from YaST
ycp.import_module('UI')
# import YaST module Label
ycp.import_module('Label')
from ycp import *
if __name__ == "__main__":
UI.OpenDialog(
VBox(
# using Label widget known as Text now
Text('Simple example'),
Frame('CPU &Speed',
RadioButtonGroup(
VBox(
Left(RadioButton('Normal')),
Left(RadioButton('Overclocked')),
Left(RadioButton('Red Hot')),
Left(RadioButton('Melting', True))
)
)
),
PushButton(Label.AcceptButton()) # PushButton(_('Accept'))
)
)
UI.UserInput()
UI.CloseDialog()
Result of running script
Categories: YaST | Development | Python



