Product SiteDocumentation Site

6.2.2. Advanced features

The pyanaconda package contains several helper and utility functions and constructs which may be used by hubs and spokes and which have not been covered in the previous section. Most of them are located in pyanaconda.ui.gui.utils.
The sample Hello World add-on demonstrates usage of the englightbox content manager which is also used in Anaconda. This manager can put a window into a lightbox to increase its visibility and focus it and to prevent users interacting with the underlying window. To demonstrate this function, the sample add-on contains a button which opens a new dialog window; the dialog itself is a special HelloWorldDialog inheriting from the GUIObject class, which is defined in pyanaconda.ui.gui.__init__.
The dialog class defines the run method which runs and destroys an internal Gtk dialog accessible through the self.window attribute, which is populated using a mainWidgetName class attribute with the same meaning. Therefore, the code defining the dialog is very simple, as demonstrated in the following example:

Example 12. Defining a englightbox Dialog

        # 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 above 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 provided by Anaconda is the ability to define a spoke which will appear both during the installation and after the first reboot (in the Initial Setup utility described in Section 1.2, “Firstboot and Initial Setup”). To make a spoke available in both Anaconda and Initial Setup, you must inherit the special FirstbootSpokeMixIn (or, more precisely, mixin) as the first inherited class defined in the pyanaconda.ui.common module.
If you want to make a certain spoke available only in Initial Setup, you should instead inherit the FirstbootOnlySpokeMixIn class.
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 installer's sources for examples.