Esempio n. 1
0
 def update(self, frame_no):
     (colour, attr,
      background) = self._frame.palette[self._pick_palette_key(
          "label", selected=False, allow_input_state=False)]
     for i, text in enumerate(
             _split_text(self._text, self._w, self._h,
                         self._frame.canvas.unicode_aware)):
         self._frame.canvas.paint(
             "{:{}{}}".format(text, self._align, self._w), self._x,
             self._y + i, colour, attr, background)
Esempio n. 2
0
    def _draw_label(self):
        """
        Draw the label for this widget if needed.
        """
        if self._label is not None:
            # Break the label up as required.
            if self._display_label is None:
                # noinspection PyTypeChecker
                self._display_label = _split_text(
                    self._label, self._offset, self._h, self._frame.canvas.unicode_aware)

            # Draw the  display label.
            (colour, attr, background) = self._frame.palette["label"]
            for i, text in enumerate(self._display_label):
                self._frame.canvas.paint(
                    text, self._x, self._y + i, colour, attr, background)
Esempio n. 3
0
    def __init__(self,
                 screen,
                 text,
                 buttons,
                 on_close=None,
                 has_shadow=False,
                 theme="warning"):
        """
        :param screen: The Screen that owns this dialog.
        :param text: The message text to display.
        :param buttons: A list of button names to display. This may be an empty list.
        :param on_close: Optional function to invoke on exit.
        :param has_shadow: optional flag to specify if dialog should have a shadow when drawn.
        :param theme: optional colour theme for this pop-up.  Defaults to the warning colours.

        The `on_close` method (if specified) will be called with one integer parameter that
        corresponds to the index of the button passed in the array of available `buttons`.

        Note that `on_close` must be a static method to work across screen resizing.  Either it
        is static (and so the dialog will be cloned) or it is not (and the dialog will disappear
        when the screen is resized).
        """
        # Remember parameters for cloning.
        self._text = text
        self._buttons = buttons
        self._on_close = on_close

        # Decide on optimum width of the dialog.  Limit to 2/3 the screen width.
        string_len = wcswidth if screen.unicode_aware else len
        width = max([string_len(x) for x in text.split("\n")])
        width = max(
            width + 2,
            sum([string_len(x) + 4 for x in buttons]) + len(buttons) + 5)
        width = min(width, screen.width * 2 // 3)

        # Figure out the necessary message and allow for buttons and borders
        # when deciding on height.
        delta_h = 4 if len(buttons) > 0 else 2
        self._message = _split_text(text, width - 2, screen.height - delta_h,
                                    screen.unicode_aware)
        height = len(self._message) + delta_h

        # Construct the Frame
        self._data = {"message": self._message}
        super(PopUpDialog, self).__init__(screen,
                                          height,
                                          width,
                                          self._data,
                                          has_shadow=has_shadow,
                                          is_modal=True)

        # Build up the message box
        layout = Layout([width - 2], fill_frame=True)
        self.add_layout(layout)
        text_box = TextBox(len(self._message), name="message")
        text_box.disabled = True
        layout.add_widget(text_box)
        layout2 = Layout([1 for _ in buttons])
        self.add_layout(layout2)
        for i, button in enumerate(buttons):
            func = partial(self._destroy, i)
            layout2.add_widget(Button(button, func), i)
        self.fix()

        # Ensure that we have the right palette in place
        self.set_theme(theme)