Пример #1
0
 def process_contents(self):
     BaseListUIElement.process_contents(self)
     # Replacing string-based entry labels with single-element lists
     for i, entry in enumerate(self.contents):
         if isinstance(entry, basestring):
             self.contents[i] = [entry]
     logger.debug("{}: contents processed".format(self.name))
Пример #2
0
    def __init__(self, *args, **kwargs):
        """Initialises the Listbox object.

        Args:

            * ``contents``: listbox contents
            * ``i``, ``o``: input&output device objects

        Kwargs:

            * ``name``: listbox name which can be used internally and for debugging.
            * ``selected``: value (that is, ``entry[1]``) of the element to be selected. If no element with this value is found, this is ignored.
            * ``entry_height``: number of display rows one listbox entry occupies.
            * ``append_exit``: appends an "Exit" entry to listbox.

        """
        selected = kwargs.pop("selected", None)
        exitable = kwargs.pop("exitable", None)
        BaseListUIElement.__init__(self, *args, **kwargs)
        if len(self.contents) == 0:
            raise ValueError("A listbox can't be empty!")
        if selected:
            self.go_to_value(selected)
        if exitable:
            logger.warning("Listbox ignores the 'exitable' argument!")
Пример #3
0
 def move_up(self):
     if self.entry_is_being_moved and self.contents[
             self.pointer] != self.accept_entry:
         if self.pointer > 0:
             logger.debug("{}: moved an entry up: {}".format( \
                           self.name, self.contents[self.pointer]))
             self.contents[self.pointer], self.contents[self.pointer-1] = \
              self.contents[self.pointer-1], self.contents[self.pointer]
     BaseListUIElement.move_up(self)
Пример #4
0
 def move_down(self):
     if self.entry_is_being_moved and self.contents[
             self.pointer] != self.accept_entry:
         if self.pointer < len(
                 self.contents) - 2:  # -1 for the "Accept" entry
             logger.debug("{}: moved an entry down: {}".format( \
                           self.name, self.contents[self.pointer]))
             self.contents[self.pointer], self.contents[self.pointer+1] = \
              self.contents[self.pointer+1], self.contents[self.pointer]
     BaseListUIElement.move_down(self)
Пример #5
0
    def __init__(self, *args, **kwargs):
        """Initialises the Listbox object.

        Args:

            * ``contents``: listbox contents
            * ``i``, ``o``: input&output device objects

        Kwargs:

            * ``name``: listbox name which can be used internally and for debugging.
            * ``entry_height``: number of display rows one listbox entry occupies.
            * ``append_exit``: appends an "Exit" entry to listbox.

        """
        BaseListUIElement.__init__(self, *args, **kwargs)
        if len(self.contents) == 0:
            raise ValueError("A listbox can't be empty!")
Пример #6
0
    def __init__(self, *args, **kwargs):
        """Initialises the OrderAdjust object.

        Args:

            * ``contents``: list of entries to adjust order for
            * ``i``, ``o``: input&output device objects

        Kwargs:

            * ``name``: UI element's name, to be used internally and for debugging.
            * ``entry_height``: number of display rows one entry occupies.

        """
        selected = kwargs.pop("selected", None)
        kwargs["append_exit"] = False
        kwargs["override_left"] = False
        BaseListUIElement.__init__(self, *args, **kwargs)
        if len(self.contents) == 0:
            raise ValueError("A listbox can't be empty!")
Пример #7
0
    def __init__(self, *args, **kwargs):
        """Args:

            * ``contents``: a list of element descriptions, which can be constructed as described in the Checkbox object's docstring.
            * ``i``, ``o``: input&output device objects

        Kwargs:

            * ``name``: Checkbox name which can be used internally and for debugging.
            * ``entry_height``: number of display rows that one checkbox element occupies.
            * ``default_state``: default state for each entry that doesn't have a state (entry[2]) specified in ``contents`` (default: ``False``)
            * ``final_button_name``: label for the last button that confirms the selection (default: ``"Accept"``)

        """
        self.default_state = kwargs.pop("default_state", False)
        if "final_button_name" in kwargs:
            # Avoid propagation of final button name into other Checkbox objects,
            # since exit_entry is modified in-place
            final_button_name = kwargs.pop("final_button_name")
            self.exit_entry = copy(self.exit_entry)
            self.exit_entry[0] = final_button_name
        BaseListUIElement.__init__(self, *args, **kwargs)
Пример #8
0
    def __init__(self, *args, **kwargs):
        """Initialises the Menu object.

        Args:

            * ``contents``: list of menu entries which was passed either to ``Menu`` constructor or to ``menu.set_contents()``.

              Simplest ``Menu`` entry is a list, where:
                 * ``entry[0]`` (entry label) is usually a string which will be displayed in the UI, such as "Menu entry 1". If ``entry_height`` > 1, can be a list of strings, each of those strings will be shown on a separate display row.
                 * ``entry[1]`` (entry callback) is a function which is called when the user presses Enter.

                   * Can be omitted if you don't need to have any actions taken upon activation of the entry.
                   * You can supply 'exit' (a string, not a function) if you want a menu entry that exits the menu when the user presses Enter.

                 * ``entry[2]`` (entry second callback) is a callback for the right key press.

              You can also pass ``Entry`` objects as entries - ``text`` will be used as label, ``cb`` will be used as first callback and ``cb2`` will be used as the second callback.

              If you want to set contents after the initialisation, please, use set_contents() method.*
            * ``i``, ``o``: input&output device objects

        Kwargs:

            * ``name``: Menu name which can be used internally and for debugging.
            * ``entry_height``: number of display rows one menu entry occupies.
            * ``append_exit``: Appends an "Exit" element to menu contents.
            * ``catch_exit``: If ``MenuExitException`` is received and catch_exit is False, it passes ``MenuExitException`` to the parent menu so that it exits, too. If catch_exit is True, MenuExitException is not passed along.
            * ``exitable``: Decides if menu can exit by pressing ``KEY_LEFT``. Set by default and disables ``KEY_LEFT`` callback if unset. Is used for ZPUI main menu, not advised to be used in other settings.
            * ``contents_hook``: A function that is called every time menu goes in foreground that returns new menu contents. Allows to almost-dynamically update menu contents.
            * ``on_contents_hook_fail``: A function that is called when ``contents_hook`` raises an exception or returns None. Will be passed two arguments: 1) arg ``self`` (``Menu`` object) 2) kwarg ``exception=bool`` (``True`` or ``False``, whether ``contents_hook`` raised an exception or not).

        """
        self.catch_exit = kwargs.pop("catch_exit", True)
        self.contents_hook = kwargs.pop("contents_hook", None)
        self.on_contents_hook_fail = kwargs.pop("on_contents_hook_fail", None)
        BaseListUIElement.__init__(self, *args, **kwargs)
Пример #9
0
 def generate_keymap(self):
     keymap = BaseListUIElement.generate_keymap(self)
     keymap["KEY_ENTER"] = "on_enter"
     keymap["KEY_LEFT"] = "on_left"
     keymap.pop("KEY_RIGHT")
     return keymap
Пример #10
0
 def before_activate(self):
     # Clearing flags
     BaseListUIElement.before_activate(self)
     self.accepted = False