mainWidgetName: メインウィンドウウィジェットの ID が含まれます。 [4].glade ファイルで定義されている設定
uiFile: .glade ファイルの名前が含まれます。
category: スポークが属するカテゴリーのクラスが含まれます。
icon: ハブ上のスポークに使用するアイコンの識別子が含まれます。
title: ハブ上のスポークに使用するタイトルを定義します。
以下に必須の定義すべてを含むモジュール例を示します。
例8 Normalspoke クラスに必須の属性の定義
will never be translated
_ = lambda x: x
N_ = lambda x: x
the path to addons is in sys.path so we can import things from org_fedora_hello_world
from org_fedora_hello_world.gui.categories.hello_world import HelloWorldCategory
from pyanaconda.ui.gui.spokes import NormalSpoke
export only the spoke, no helper functions, classes or constants
__all__ = ["HelloWorldSpoke"]
class HelloWorldSpoke(NormalSpoke):
"""
Class for the Hello world spoke. This spoke will be in the Hello world
category and thus on the Summary hub. It is a very simple example of
a unit for the Anaconda's graphical user interface.
:see: pyanaconda.ui.common.UIObject
:see: pyanaconda.ui.common.Spoke
:see: pyanaconda.ui.gui.GUIObject
"""
### class attributes defined by API ###
# list all top-level objects from the .glade file that should be exposed
# to the spoke or leave empty to extract everything
builderObjects = ["helloWorldSpokeWindow", "buttonImage"]
# the name of the main window widget
mainWidgetName = "helloWorldSpokeWindow"
# name of the .glade file in the same directory as this source
uiFile = "hello_world.glade"
# category this spoke belongs to
category = HelloWorldCategory
# spoke icon (will be displayed on the hub)
# preferred are the -symbolic icons as these are used in Anaconda's spokes
icon = "face-cool-symbolic"
# title of the spoke (will be displayed on the hub)
title = N_("_HELLO WORLD")
# will never be translated
_ = lambda x: x
N_ = lambda x: x
# the path to addons is in sys.path so we can import things from org_fedora_hello_world
from org_fedora_hello_world.gui.categories.hello_world import HelloWorldCategory
from pyanaconda.ui.gui.spokes import NormalSpoke
# export only the spoke, no helper functions, classes or constants
__all__ = ["HelloWorldSpoke"]
class HelloWorldSpoke(NormalSpoke):
"""
Class for the Hello world spoke. This spoke will be in the Hello world
category and thus on the Summary hub. It is a very simple example of
a unit for the Anaconda's graphical user interface.
:see: pyanaconda.ui.common.UIObject
:see: pyanaconda.ui.common.Spoke
:see: pyanaconda.ui.gui.GUIObject
"""
### class attributes defined by API ###
# list all top-level objects from the .glade file that should be exposed
# to the spoke or leave empty to extract everything
builderObjects = ["helloWorldSpokeWindow", "buttonImage"]
# the name of the main window widget
mainWidgetName = "helloWorldSpokeWindow"
# name of the .glade file in the same directory as this source
uiFile = "hello_world.glade"
# category this spoke belongs to
category = HelloWorldCategory
# spoke icon (will be displayed on the hub)
# preferred are the -symbolic icons as these are used in Anaconda's spokes
icon = "face-cool-symbolic"
# title of the spoke (will be displayed on the hub)
title = N_("_HELLO WORLD")
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Hello World アドオンの例では、これら 2 つのメソッドは以下のように定義されます (__init__ メソッドに渡される属性の数と記述に注意):
例9 __init__ および initialize メソッドの定義
def __init__(self, data, storage, payload, instclass):
"""
:see: pyanaconda.ui.common.Spoke.__init__
:param data: data object passed to every spoke to load/store data
from/to it
:type data: pykickstart.base.BaseHandler
:param storage: object storing storage-related information
(disks, partitioning, bootloader, etc.)
:type storage: blivet.Blivet
:param payload: object storing packaging-related information
:type payload: pyanaconda.packaging.Payload
:param instclass: distribution-specific information
:type instclass: pyanaconda.installclass.BaseInstallClass
"""
NormalSpoke.__init__(self, data, storage, payload, instclass)
def initialize(self):
"""
The initialize method that is called after the instance is created.
The difference between __init__ and this method is that this may take
a long time and thus could be called in a separated thread.
:see: pyanaconda.ui.common.UIObject.initialize
"""
NormalSpoke.initialize(self)
self._entry = self.builder.get_object("textEntry")
def __init__(self, data, storage, payload, instclass):
"""
:see: pyanaconda.ui.common.Spoke.__init__
:param data: data object passed to every spoke to load/store data
from/to it
:type data: pykickstart.base.BaseHandler
:param storage: object storing storage-related information
(disks, partitioning, bootloader, etc.)
:type storage: blivet.Blivet
:param payload: object storing packaging-related information
:type payload: pyanaconda.packaging.Payload
:param instclass: distribution-specific information
:type instclass: pyanaconda.installclass.BaseInstallClass
"""
NormalSpoke.__init__(self, data, storage, payload, instclass)
def initialize(self):
"""
The initialize method that is called after the instance is created.
The difference between __init__ and this method is that this may take
a long time and thus could be called in a separated thread.
:see: pyanaconda.ui.common.UIObject.initialize
"""
NormalSpoke.initialize(self)
self._entry = self.builder.get_object("textEntry")
Copy to ClipboardCopied!Toggle word wrapToggle overflow
data パラメーターが __init__ メソッドに渡されていることに留意してください。これは、すべてのデータが保存されている Kickstart ファイルのインメモリーのツリー構造を表します。ancestor の __init__ メソッドのいずれかで、self.data 属性に格納されます。これにより、クラス内の他のすべてのメソッドで構造の読み取りおよび修正が可能になります。
def refresh(self):
"""
The refresh method that is called every time the spoke is displayed.
It should update the UI elements according to the contents of
self.data.
:see: pyanaconda.ui.common.UIObject.refresh
"""
self._entry.set_text(self.data.addons.org_fedora_hello_world.text)
def apply(self):
"""
The apply method that is called when the spoke is left. It should
update the contents of self.data with values set in the GUI elements.
"""
self.data.addons.org_fedora_hello_world.text = self._entry.get_text()
def execute(self):
"""
The excecute method that is called when the spoke is left. It is
supposed to do all changes to the runtime environment according to
the values set in the GUI elements.
"""
# nothing to do here
pass
def refresh(self):
"""
The refresh method that is called every time the spoke is displayed.
It should update the UI elements according to the contents of
self.data.
:see: pyanaconda.ui.common.UIObject.refresh
"""
self._entry.set_text(self.data.addons.org_fedora_hello_world.text)
def apply(self):
"""
The apply method that is called when the spoke is left. It should
update the contents of self.data with values set in the GUI elements.
"""
self.data.addons.org_fedora_hello_world.text = self._entry.get_text()
def execute(self):
"""
The excecute method that is called when the spoke is left. It is
supposed to do all changes to the runtime environment according to
the values set in the GUI elements.
"""
# nothing to do here
pass
Copy to ClipboardCopied!Toggle word wrapToggle overflow
これらの属性はすべて、インストールプロセスの現在の状態に基づいて動的に決定する必要があります。以下は Hello World アドオンでのこれらの属性の実装例です。値によっては HelloWorldData クラスの text 属性で設定する必要があるものもあります。
例11 準備完了、完了、および必須メソッドの定義
@property
def ready(self):
"""
The ready property that tells whether the spoke is ready (can be visited)
or not. The spoke is made (in)sensitive based on the returned value.
:rtype: bool
"""
# this spoke is always ready
return True
@property
def completed(self):
"""
The completed property that tells whether all mandatory items on the
spoke are set, or not. The spoke will be marked on the hub as completed
or uncompleted acording to the returned value.
:rtype: bool
"""
return bool(self.data.addons.org_fedora_hello_world.text)
@property
def mandatory(self):
"""
The mandatory property that tells whether the spoke is mandatory to be
completed to continue in the installation process.
:rtype: bool
"""
# this is an optional spoke that is not mandatory to be completed
return False
@property
def ready(self):
"""
The ready property that tells whether the spoke is ready (can be visited)
or not. The spoke is made (in)sensitive based on the returned value.
:rtype: bool
"""
# this spoke is always ready
return True
@property
def completed(self):
"""
The completed property that tells whether all mandatory items on the
spoke are set, or not. The spoke will be marked on the hub as completed
or uncompleted acording to the returned value.
:rtype: bool
"""
return bool(self.data.addons.org_fedora_hello_world.text)
@property
def mandatory(self):
"""
The mandatory property that tells whether the spoke is mandatory to be
completed to continue in the installation process.
:rtype: bool
"""
# this is an optional spoke that is not mandatory to be completed
return False
Copy to ClipboardCopied!Toggle word wrapToggle overflow
@property
def status(self):
"""
The status property that is a brief string describing the state of the
spoke. It should describe whether all values are set and if possible
also the values themselves. The returned value will appear on the hub
below the spoke's title.
:rtype: str
"""
text = self.data.addons.org_fedora_hello_world.text
# If --reverse was specified in the kickstart, reverse the text
if self.data.addons.org_fedora_hello_world.reverse:
text = text[::-1]
if text:
return _("Text set: %s") % text
else:
return _("Text not set")
@property
def status(self):
"""
The status property that is a brief string describing the state of the
spoke. It should describe whether all values are set and if possible
also the values themselves. The returned value will appear on the hub
below the spoke's title.
:rtype: str
"""
text = self.data.addons.org_fedora_hello_world.text
# If --reverse was specified in the kickstart, reverse the text
if self.data.addons.org_fedora_hello_world.reverse:
text = text[::-1]
if text:
return _("Text set: %s") % text
else:
return _("Text not set")
Copy to ClipboardCopied!Toggle word wrapToggle overflow