Exemplo n.º 1
0
    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)

        if self.is_disabled():
            color = dialog.theme['dropdown']['disabled_color']
        else:
            color = dialog.theme['dropdown']['gui_color']

        if self.field is None:
            self.field = dialog.theme['dropdown']['image'].generate(
                color, dialog.batch, dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(
                self.selected,
                font_name=dialog.theme['dropdown']['font'],
                font_size=dialog.theme['dropdown']['font_size'],
                color=dialog.theme['dropdown']['text_color'],
                batch=dialog.batch,
                group=dialog.fg_group)
        font = self.label.document.get_font()
        height = font.ascent - font.descent
        self.width, self.height = self.field.get_needed_size(
            self.label.content_width, height)
Exemplo n.º 2
0
    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_selected:
            path = ['menuoption', 'selection']
        else:
            path = ['menuoption']
        if self.label is None:
            if self.is_disabled():
                color = dialog.theme[path]['disabled_color']
            else:
                color = dialog.theme[path]['text_color']
            self.label = KyttenLabel(self.text,
                                     color=color,
                                     font_name=dialog.theme[path]['font'],
                                     font_size=dialog.theme[path]['font_size'],
                                     batch=dialog.batch,
                                     group=dialog.fg_group)
            font = self.label.document.get_font()
            self.width = self.label.content_width + self.option_padding_x
            self.height = font.ascent - font.descent + self.option_padding_y

        if self.background is None:
            if self.is_selected:
                self.background = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['gui_color'],
                        dialog.batch,
                        dialog.bg_group)
        if self.highlight is None:
            if self.is_highlight():
                self.highlight = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['highlight_color'],
                        dialog.batch,
                        dialog.highlight_group)
Exemplo n.º 3
0
 def size(self, dialog):
     if dialog is None:
         return
     Widget.size(self, dialog)
     if self.label is None:
         self.label = KyttenLabel(
             self.text,
             bold=self.bold,
             italic=self.italic,
             color=self.color or dialog.theme[self.path + ['gui_color']],
             font_name=self.font_name or dialog.theme[self.path + ['font']],
             font_size=self.font_size
             or dialog.theme[self.path + ['font_size']],
             batch=dialog.batch,
             group=dialog.fg_group)
         font = self.label.document.get_font()
         self.width = self.label.content_width
         self.height = font.ascent - font.descent  # descent is negative
Exemplo n.º 4
0
    def size(self, dialog):
        """
        Sizes the Button.  If necessary, creates the graphic elements.

        @param dialog Dialog which contains the Button
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_pressed:
            path = ['button', 'down']
        else:
            path = ['button', 'up']
        if self.is_disabled():
            color = dialog.theme[path]['disabled_color']
        else:
            color = dialog.theme[path]['gui_color']
        if self.button is None:
            self.button = dialog.theme[path]['image'].generate(
                color, dialog.batch, dialog.bg_group)
        if self.highlight is None and self.is_highlight():
            self.highlight = dialog.theme[path]['highlight']['image'].\
                generate(dialog.theme[path]['highlight_color'],
                         dialog.batch,
                         dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(self.text,
                                     font_name=dialog.theme[path]['font'],
                                     font_size=dialog.theme[path]['font_size'],
                                     color=dialog.theme[path]['text_color'],
                                     batch=dialog.batch,
                                     group=dialog.fg_group)

        # Treat the height of the label as ascent + descent
        font = self.label.document.get_font()
        height = font.ascent - font.descent  # descent is negative
        self.width, self.height = self.button.get_needed_size(
            self.label.content_width, height)
Exemplo n.º 5
0
    def size(self, dialog):
        """
        Sizes the Checkbox.  If necessary, creates the graphic elements.

        @param dialog Dialog which contains the Checkbox
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_checked:
            path = ['checkbox', 'checked']
        else:
            path = ['checkbox', 'unchecked']
        if self.is_disabled():
            color = dialog.theme[path]['disabled_color']
        else:
            color = dialog.theme[path]['gui_color']
        if self.checkbox is None:
            self.checkbox = dialog.theme[path]['image'].generate(
                color, dialog.batch, dialog.bg_group)
        if self.highlight is None and self.is_highlight():
            self.highlight = dialog.theme[path]['highlight']['image'].generate(
                dialog.theme[path]['highlight_color'], dialog.batch,
                dialog.bg_group)
        if self.label is None:
            self.label = KyttenLabel(self.text,
                                     font_name=dialog.theme[path]['font'],
                                     font_size=dialog.theme[path]['font_size'],
                                     color=color,
                                     batch=dialog.batch,
                                     group=dialog.fg_group)

        # Treat the height of the label as ascent + descent
        font = self.label.document.get_font()
        height = font.ascent - font.descent  # descent is negative
        self.width = self.checkbox.width + self.padding + \
            self.label.content_width
        self.height = max(self.checkbox.height, height)
Exemplo n.º 6
0
Arquivo: menu.py Projeto: isS/sy-game
    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_selected:
            path = ['menuoption', 'selection']
        else:
            path = ['menuoption']
        if self.label is None:
            if self.is_disabled():
                color = dialog.theme[path]['disabled_color']
            else:
                color = dialog.theme[path]['text_color']
            self.label = KyttenLabel(self.text,
                color=color,
                font_name=dialog.theme[path]['font'],
                font_size=dialog.theme[path]['font_size'],
                batch=dialog.batch,
                group=dialog.fg_group)
            font = self.label.document.get_font()
            self.width = self.label.content_width
            self.height = font.ascent - font.descent

        if self.background is None:
            if self.is_selected:
                self.background = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['gui_color'],
                        dialog.batch,
                        dialog.bg_group)
        if self.highlight is None:
            if self.is_highlight():
                self.highlight = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['highlight_color'],
                        dialog.batch,
                        dialog.highlight_group)
Exemplo n.º 7
0
Arquivo: menu.py Projeto: isS/sy-game
class MenuOption(Control):
    """
    MenuOption is a choice within a menu.  When selected, it inverts
    (inverted color against text-color background) to indicate that it
    has been chosen.
    """
    def __init__(self, text="", anchor=ANCHOR_CENTER, menu=None,
                 disabled=False):
        Control.__init__(self, disabled=disabled)
        self.text = text
        self.anchor = anchor
        self.menu = menu
        self.label = None
        self.background = None
        self.highlight = None
        self.is_selected = False

    def delete(self):
        if self.label is not None:
            self.label.delete()
            self.label = None
        if self.background is not None:
            self.background.delete()
            self.background = None
        if self.highlight is not None:
            self.highlight.delete()
            self.highlight = None

    def expand(self, width, height):
        self.width = width
        self.height = height

    def is_expandable(self):
        return True

    def layout(self, x, y):
        self.x, self.y = x, y
        if self.background is not None:
            self.background.update(x, y, self.width, self.height)
        if self.highlight is not None:
            self.highlight.update(x, y, self.width, self.height)
        font = self.label.document.get_font()
        height = font.ascent - font.descent
        x, y = GetRelativePoint(self, self.anchor,
                                Widget(self.label.content_width, height),
                                self.anchor, (0, 0))
        self.label.x = x
        self.label.y = y - font.descent

    def on_gain_highlight(self):
        Control.on_gain_highlight(self)
        self.size(self.saved_dialog)  # to set up the highlight
        if self.highlight is not None:
            self.highlight.update(self.x, self.y,
                                  self.menu.width, self.height)

    def on_lose_highlight(self):
        Control.on_lose_highlight(self)
        if self.highlight is not None:
            self.highlight.delete()
            self.highlight = None

    def on_mouse_release(self, x, y, button, modifiers):
        self.menu.select(self.text)

    def select(self):
        if self.is_disabled():
            return  # disabled options can't be selected

        self.is_selected = True
        if self.label is not None:
            self.label.delete()
            self.label = None
        self.saved_dialog.set_needs_layout()

    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_selected:
            path = ['menuoption', 'selection']
        else:
            path = ['menuoption']
        if self.label is None:
            if self.is_disabled():
                color = dialog.theme[path]['disabled_color']
            else:
                color = dialog.theme[path]['text_color']
            self.label = KyttenLabel(self.text,
                color=color,
                font_name=dialog.theme[path]['font'],
                font_size=dialog.theme[path]['font_size'],
                batch=dialog.batch,
                group=dialog.fg_group)
            font = self.label.document.get_font()
            self.width = self.label.content_width
            self.height = font.ascent - font.descent

        if self.background is None:
            if self.is_selected:
                self.background = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['gui_color'],
                        dialog.batch,
                        dialog.bg_group)
        if self.highlight is None:
            if self.is_highlight():
                self.highlight = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['highlight_color'],
                        dialog.batch,
                        dialog.highlight_group)

    def unselect(self):
        self.is_selected = False
        if self.label is not None:
            self.label.delete()
            self.label = None
        if self.background is not None:
            self.background.delete()
            self.background = None
        self.saved_dialog.set_needs_layout()

    def teardown(self):
        self.menu = None
        Control.teardown(self)
Exemplo n.º 8
0
class MenuOption(Control):
    """
    MenuOption is a choice within a menu.  When selected, it inverts
    (inverted color against text-color background) to indicate that it
    has been chosen.
    """
    def __init__(self,
                 text="",
                 anchor=ANCHOR_CENTER,
                 menu=None,
                 disabled=False,
                 option_padding_x=0,
                 option_padding_y=0):
        Control.__init__(self, disabled=disabled)
        self.text = text
        self.anchor = anchor
        self.menu = menu
        self.label = None
        self.background = None
        self.highlight = None
        self.is_selected = False
        self.option_padding_x = option_padding_x
        self.option_padding_y = option_padding_y

    def delete(self):
        if self.label is not None:
            self.label.delete()
            self.label = None
        if self.background is not None:
            self.background.delete()
            self.background = None
        if self.highlight is not None:
            self.highlight.delete()
            self.highlight = None

    def expand(self, width, height):
        self.width = width
        self.height = height

    def is_expandable(self):
        return True

    def layout(self, x, y):
        self.x, self.y = x, y
        if self.background is not None:
            self.background.update(x, y, self.width, self.height)
        if self.highlight is not None:
            self.highlight.update(x, y, self.width, self.height)
        font = self.label.document.get_font()
        height = font.ascent - font.descent
        x, y = GetRelativePoint(self, self.anchor,
                                Widget(self.label.content_width, height),
                                self.anchor, (0, 0))
        self.label.x = x
        self.label.y = y - font.descent

    def on_gain_highlight(self):
        Control.on_gain_highlight(self)
        self.size(self.saved_dialog)  # to set up the highlight
        if self.highlight is not None:
            self.highlight.update(self.x, self.y, self.menu.width, self.height)

    def on_lose_highlight(self):
        Control.on_lose_highlight(self)
        if self.highlight is not None:
            self.highlight.delete()
            self.highlight = None

    def on_mouse_release(self, x, y, button, modifiers):
        self.menu.select(self.text)

    def select(self):
        if self.is_disabled():
            return  # disabled options can't be selected

        self.is_selected = True
        if self.label is not None:
            self.label.delete()
            self.label = None
        self.saved_dialog.set_needs_layout()

    def size(self, dialog):
        if dialog is None:
            return
        Control.size(self, dialog)
        if self.is_selected:
            path = ['menuoption', 'selection']
        else:
            path = ['menuoption']
        if self.label is None:
            if self.is_disabled():
                color = dialog.theme[path]['disabled_color']
            else:
                color = dialog.theme[path]['text_color']
            self.label = KyttenLabel(self.text,
                                     color=color,
                                     font_name=dialog.theme[path]['font'],
                                     font_size=dialog.theme[path]['font_size'],
                                     batch=dialog.batch,
                                     group=dialog.fg_group)
            font = self.label.document.get_font()
            self.width = self.label.content_width + self.option_padding_x
            self.height = font.ascent - font.descent + self.option_padding_y

        if self.background is None:
            if self.is_selected:
                self.background = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['gui_color'],
                        dialog.batch,
                        dialog.bg_group)
        if self.highlight is None:
            if self.is_highlight():
                self.highlight = \
                    dialog.theme[path]['highlight']['image'].generate(
                        dialog.theme[path]['highlight_color'],
                        dialog.batch,
                        dialog.highlight_group)

    def unselect(self):
        self.is_selected = False
        if self.label is not None:
            self.label.delete()
            self.label = None
        if self.background is not None:
            self.background.delete()
            self.background = None
        self.saved_dialog.set_needs_layout()

    def teardown(self):
        self.menu = None
        Control.teardown(self)