Ejemplo n.º 1
0
    def test_category_sorting(self):
        """Test category sorting works as expected."""

        category_list = [BbbCategory, CccCategory, AaaCategory]
        # We expect the C category to be dorted first due to sort order and
        # then A & B as they have the same sort order but A comes before B
        # on the alphabet.
        expected_category_list = [CccCategory, AaaCategory, BbbCategory]
        assert sort_categories(category_list) == expected_category_list
Ejemplo n.º 2
0
    def setup(self, args="anaconda"):
        TUIObject.setup(self, args)
        environment = args
        cats_and_spokes = self._collectCategoriesAndSpokes()
        categories = cats_and_spokes.keys()

        # display categories by sort order or class name if their
        # sort order is the same
        for c in common.sort_categories(categories):

            hub_spokes = []
            for spoke_class in cats_and_spokes[c]:
                # Do the checks for the spoke and create the spoke
                if spoke_class.should_run(environment, self.data):
                    spoke = spoke_class(self.data, self.storage, self.payload)

                    if spoke.showable:
                        spoke.initialize()
                    else:
                        log.warning("Spoke %s initialization failure!",
                                    spoke.__class__.__name__)
                        del spoke
                        continue

                    if spoke.indirect:
                        continue

                    hub_spokes.append(spoke)

            # sort created spokes and add them to result structures
            for spoke in sorted(hub_spokes, key=lambda s: s.title):

                self._spoke_count += 1
                self._spokes_map.append(spoke)
                self._spokes[spoke.__class__.__name__] = spoke

        if self._spoke_count:
            # initialization of all expected spokes has been started, so notify the controller
            hub_controller = lifecycle.get_controller_by_name(
                self.__class__.__name__)
            if hub_controller:
                hub_controller.all_modules_added()
            else:
                log.error(
                    "Initialization controller for hub %s expected but missing.",
                    self.__class__.__name__)

        # only schedule the hub if it has some spokes
        return self._spoke_count != 0
Ejemplo n.º 3
0
    def _createBox(self):
        """Create and fill the list of categories and spokes."""
        import gi

        gi.require_version("Gtk", "3.0")
        gi.require_version("AnacondaWidgets", "3.3")

        from gi.repository import Gtk, AnacondaWidgets

        cats_and_spokes = self._collectCategoriesAndSpokes()
        categories = cats_and_spokes.keys()

        grid = Gtk.Grid(row_spacing=18,
                        column_spacing=18,
                        column_homogeneous=True,
                        margin_bottom=12,
                        margin_left=12,
                        margin_right=12,
                        halign=Gtk.Align.CENTER,
                        valign=Gtk.Align.CENTER,
                        row_homogeneous=True)

        col = 0

        row_in_column = [-1] * self._gridColumns

        for category in common.sort_categories(categories):
            selectors = []
            for spokeClass in sorted(cats_and_spokes[category],
                                     key=lambda s: s.title):
                # Check if this spoke is to be shown in the supported environments
                if not any(
                        spokeClass.should_run(environ, self.data)
                        for environ in flags.environs):
                    continue

                # Create the new spoke and populate its UI with whatever data.
                # From here on, this Spoke will always exist.
                spoke = spokeClass(self.data, self.storage, self.payload)
                spoke.window.set_beta(self.window.get_beta())
                spoke.window.set_property("distribution", distributionText())

                # If a spoke is not showable, it is unreachable in the UI.  We
                # might as well get rid of it.
                #
                # NOTE:  Any kind of spoke can be unshowable.
                if not spoke.showable:
                    del (spoke)
                    continue

                # This allows being able to jump between two spokes without
                # having to directly involve the hub.
                self._spokes[spokeClass.__name__] = spoke

                # If a spoke is indirect, it is reachable but not directly from
                # a hub.  This is for things like the custom partitioning spoke,
                # which you can only get to after going through the initial
                # storage configuration spoke.
                #
                # NOTE:  This only makes sense for NormalSpokes.  Other kinds
                # of spokes do not involve a hub.
                if spoke.indirect:
                    spoke.initialize()
                    continue

                spoke.selector = AnacondaWidgets.SpokeSelector(
                    C_("GUI|Spoke", spoke.title), spoke.icon)

                # Set all selectors to insensitive before initialize runs.  The call to
                # _updateCompleteness later will take care of setting it straight.
                spoke.selector.set_sensitive(False)
                spoke.initialize()

                if not spoke.ready:
                    self._notReadySpokes.append(spoke)

                # Set some default values on the associated selector that
                # affect its display on the hub.
                self._updateCompleteness(spoke, update_continue=False)
                spoke.selector.connect("button-press-event",
                                       self._on_spoke_clicked, spoke)
                spoke.selector.connect("key-release-event",
                                       self._on_spoke_clicked, spoke)
                selectors.append(spoke.selector)

            if not selectors:
                continue

            # category handling

            # excape unwanted markup
            cat_title = escape_markup(category.get_title())
            # generate pango markup
            cat_label = '<span size="larger" weight="bold">{}</span>'.format(
                cat_title)
            # setup the category label
            label = Gtk.Label(label=cat_label,
                              use_markup=True,
                              halign=Gtk.Align.START,
                              valign=Gtk.Align.END,
                              margin_bottom=6,
                              wrap=True,
                              xalign=0.0)

            grid.attach(label, col, row_in_column[col], 1, 1)
            row_in_column[col] += 1

            for selector in selectors:
                grid.attach(selector, col, row_in_column[col], 1, 1)
                row_in_column[col] += 1

            col = (col + 1) % self._gridColumns

        # initialization of all expected spokes has been started, so notify the controller
        hub_controller = lifecycle.get_controller_by_name(
            self.__class__.__name__)
        if hub_controller:
            hub_controller.all_modules_added()
        else:
            log.error(
                "Initialization controller for hub %s expected but missing.",
                self.__class__.__name__)

        spokeArea = self.window.get_spoke_area()
        viewport = Gtk.Viewport()
        viewport.add(grid)
        spokeArea.add(viewport)

        self._updateContinue()