Product SiteDocumentation Site

6.2.2. Advanced features

Because many spokes have a lot in common, the pyanaconda package contains a lot of helper and utility functions and constructs, that may be used by hubs and spokes. Majority of them are available in the pyanaconda.ui.gui.utils module. The Hello world addon demonstrates usage of the utility, that is used in a number of Anaconda's GUI code — the englightbox context manager, that puts a window into a lightbox to make it better visible, focused and to prevent users from interaction with the underlying window. To demonstrate such functionality, the Hello world addon's GUI contains a button that runs a dialog. The dialog itself is a special class HelloWorldDialog inheriting from the GUIObject class defined in the pyanaconda.ui.gui.__init__ module. The dialog class defines the run method that runs and destroys an internal Gtk dialog accessible through the self.window attribute that is populated thanks to the mainWidgetName class attribute with the same meaning as in case of the spoke. The code running the dialog within a lightbox is then very simple:
        # every GUIObject gets ksdata in __init__
        dialog = HelloWorldDialog(self.data)

        # show dialog above the lightbox
        with enlightbox(self.window, dialog.window):
            dialog.run()
The code simply creates an instance of the dialog and then uses the enlightbox context manager to run the dialog within a lightbox. The context manager needs a reference to the window of the spoke and to the dialog's window to instantiate the lightbox for them.
Another useful feature of the Anaconda's codebase is a possibility to define a spoke that will appear in the installation process as well as in the first boot when the Initial Setup tool reusing the pyanaconda package runs. All that is needed to make spoke available in the Initial Setup is to inherit the special FirstbootSpokeMixIn class (or more precisely mixin) as the first inherited class. The other option is the FirstbootOnlySpokeMixIn [6] class/mixin which, as its name suggests, make spoke appear only in the Initial Setup utility.
There are many more advanced features provided by the pyanaconda package (like the @gtk_action_wait and @gtk_action_nowait decorators), but they are out of scope of this guide. Readers are recommended to go through the Anaconda installer's sources that contain a lot of examples.


[6] both those classes are defined in the pyanaconda.ui.common module