示例#1
0
    def size(self, dialog):
        """
        Creates scrollbar components.
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        dialog.set_wheel_hint(self)
        if self.left is None:
            if self.pos > 0.0:
                path = self.IMAGE_LEFT
            else:
                path = self.IMAGE_LEFTMAX
            self.left = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'], dialog.batch, dialog.fg_group)

            # Left button is our basis for minimum dimension
            self.width, self.height = self.left.width, self.left.height
        if self.space is None:
            path = self.IMAGE_SPACE
            self.space = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'], dialog.batch, dialog.fg_group)
        if self.bar is None:
            path = self.IMAGE_BAR
            self.bar = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'], dialog.batch, dialog.fg_group)
        if self.right is None:
            if self.pos < 1.0 - self.bar_width:
                path = self.IMAGE_RIGHT
            else:
                path = self.IMAGE_RIGHTMAX
            self.right = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'], dialog.batch, dialog.fg_group)
示例#2
0
 def size(self, dialog):
     """
     Creates slider components.
     """
     if dialog is None:
         return
     Control.size(self, dialog)
     if self.is_disabled():
         color = dialog.theme['slider']['disabled_color']
     else:
         color = dialog.theme['slider']['gui_color']
     if self.bar is None:
         path = self.IMAGE_BAR
         self.bar = dialog.theme[path]['image'].generate(
             color, dialog.batch, dialog.bg_group)
         self.padding = dialog.theme[path]['padding']
     if self.knob is None:
         path = self.IMAGE_KNOB
         self.knob = dialog.theme[path]['image'].generate(
             color, dialog.batch, dialog.highlight_group)
         self.offset = dialog.theme[path]['offset']
     if not self.markers and self.steps is not None:
         path = self.IMAGE_STEP
         for n in xrange(0, self.steps + 1):
             self.markers.append(dialog.theme[path]['image'].generate(
                 color, dialog.batch, dialog.fg_group))
         self.step_offset = dialog.theme[path]['offset']
     width, height = self.bar.get_needed_size(self.min_width, 0)
     left, right, top, bottom = self.padding
     self.width = width + left + right
     self.height = height + top + bottom
示例#3
0
    def __init__(self,
                 text="",
                 is_checked=False,
                 id=None,
                 align=HALIGN_RIGHT,
                 padding=4,
                 on_click=None,
                 disabled=False):
        """
        Creates a new checkbox.  The provided text will be used to caption the
        checkbox.

        @param text Label for the checkbox
        @param is_checked True if we should start checked
        @param id ID for value
        @param align HALIGN_RIGHT if label should be right of checkbox,
                     HALIGN_LEFT if label should be left of checkbox
        @param padding Space between checkbox and label
        @param on_click Callback for the checkbox
        @param disabled True if the checkbox should be disabled
        """
        assert align in [HALIGN_LEFT, HALIGN_RIGHT]
        Control.__init__(self, id=id, disabled=disabled)
        self.text = text
        self.is_checked = is_checked
        self.align = align
        self.padding = padding
        self.on_click = on_click
        self.label = None
        self.checkbox = None
        self.highlight = None
示例#4
0
    def size(self, dialog):
        if dialog is None:
            return

        Control.size(self, dialog)
        if not self.set_document_style:
            self.do_set_document_style(dialog)
        if self.content is None:
            self.content = pyglet.text.layout.IncrementalTextLayout(
                self.document,
                self.content_width,
                self.max_height,
                multiline=True,
                batch=dialog.batch,
                group=dialog.fg_group)
            if self.is_fixed_size or (
                    self.max_height
                    and self.content.content_height > self.max_height):
                self.height = self.max_height
            else:
                self.height = self.content.content_height
            self.content.height = self.height
        if self.always_show_scrollbar or \
           (self.max_height and self.content.content_height > self.max_height):
            if self.scrollbar is None:
                self.scrollbar = VScrollbar(self.max_height)
            self.scrollbar.size(dialog)
            self.scrollbar.set(self.max_height, self.content.content_height)
        if self.scrollbar is not None:
            self.width = self.content_width + self.scrollbar.width
        else:
            self.width = self.content_width
示例#5
0
    def size(self, dialog):
        if dialog is None:
            return

        Control.size(self, dialog)
        if not self.set_document_style:
            self.do_set_document_style(dialog)
        if self.content is None:
            self.content = pyglet.text.layout.IncrementalTextLayout(
                self.document,
                self.content_width,
                self.max_height,
                multiline=True, batch=dialog.batch, group=dialog.fg_group)
            if self.is_fixed_size or (self.max_height and
                self.content.content_height > self.max_height):
                self.height = self.max_height
            else:
                self.height = self.content.content_height
            self.content.height = self.height
        if self.always_show_scrollbar or \
           (self.max_height and self.content.content_height > self.max_height):
            if self.scrollbar is None:
                self.scrollbar = VScrollbar(self.max_height)
            self.scrollbar.size(dialog)
            self.scrollbar.set(self.max_height, self.content.content_height)
        if self.scrollbar is not None:
            self.width = self.content_width + self.scrollbar.width
        else:
            self.width = self.content_width
示例#6
0
    def __init__(self, value=0.0, min_value=0.0, max_value=1.0, steps=None,
                 width=100, id=None, on_set=None, disabled=False):
        """
        Creates a new slider.

        @param min_value Minimum value
        @param max_value Maximum value
        @param steps None if this slider should cover the range from 0.0 to
                     1.0 smoothly, otherwise we will divide the range
                     up into steps.  For instance, 2 steps would give the
                     possible values 0, 0.5, and 1.0 (then multiplied by scale)
        @param width Minimum width of the tracking area.  Note that this
                     is the interior length of the slider, not the overall
                     size.
        @param id ID for identifying this slider.
        @param on_set Callback function for when the value of this slider
                      changes.
        @param diasbled True if the slider should be disabled
        """
        Control.__init__(self, id=id, disabled=disabled)
        self.min_value = min_value
        self.max_value = max_value
        self.steps = steps
        self.min_width = width
        self.on_set = on_set
        self.bar = None
        self.knob = None
        self.markers = []
        self.pos = max(
            min(float(value - min_value) / (max_value - min_value), 1.0),
            0.0)
        self.offset = (0, 0)
        self.step_offset = (0, 0)
        self.padding = (0, 0, 0, 0)
        self.is_dragging = False
示例#7
0
    def __init__(self, text="", is_checked=False, id=None,
                 align=HALIGN_RIGHT, padding=4, on_click=None,
                 disabled=False):
        """
        Creates a new checkbox.  The provided text will be used to caption the
        checkbox.

        @param text Label for the checkbox
        @param is_checked True if we should start checked
        @param id ID for value
        @param align HALIGN_RIGHT if label should be right of checkbox,
                     HALIGN_LEFT if label should be left of checkbox
        @param padding Space between checkbox and label
        @param on_click Callback for the checkbox
        @param disabled True if the checkbox should be disabled
        """
        assert align in [HALIGN_LEFT, HALIGN_RIGHT]
        Control.__init__(self, id=id, disabled=disabled)
        self.text = text
        self.is_checked = is_checked
        self.align = align
        self.padding = padding
        self.on_click = on_click
        self.label = None
        self.checkbox = None
        self.highlight = None
示例#8
0
    def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER):
        Control.__init__(self)
        if align == HALIGN_LEFT:
            left_expand = False
            right_expand = True
        elif align == HALIGN_CENTER:
            left_expand = True
            right_expand = True
        else:  # HALIGN_RIGHT
            left_expand = True
            right_expand = False

        self.is_open = is_open
        self.folding_content = content
        self.book = Graphic(self._get_image_path())

        self.header = HorizontalLayout([
            Graphic(path=["section", "left"], is_expandable=left_expand),
            Frame(HorizontalLayout([
                self.book,
                Label(title, path=["section"]),
            ]),
                  path=["section", "center"],
                  use_bg_group=True),
            Graphic(path=["section", "right"], is_expandable=right_expand),
        ],
                                       align=VALIGN_BOTTOM,
                                       padding=0)
        layout = [self.header]
        if self.is_open:
            layout.append(content)

        VerticalLayout.__init__(self, content=layout, align=align)
示例#9
0
    def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER):
        Control.__init__(self)
        if align == HALIGN_LEFT:
            left_expand = False
            right_expand = True
        elif align == HALIGN_CENTER:
            left_expand = True
            right_expand = True
        else:  # HALIGN_RIGHT
            left_expand = True
            right_expand = False

        self.is_open = is_open
        self.folding_content = content
        self.book = Graphic(self._get_image_path())

        self.header = HorizontalLayout([
            Graphic(path=["section", "left"], is_expandable=left_expand),
            Frame(HorizontalLayout([
                      self.book,
                      Label(title, path=["section"]),
                  ]), path=["section", "center"],
                  use_bg_group=True),
            Graphic(path=["section", "right"], is_expandable=right_expand),
            ], align=VALIGN_BOTTOM, padding=0)
        layout = [self.header]
        if self.is_open:
            layout.append(content)

        VerticalLayout.__init__(self, content=layout, align=align)
示例#10
0
    def layout(self, x, y):
        """
        Places the Checkbox.

        @param x X coordinate of lower left corner
        @param y Y coordinate of lower left corner
        """
        Control.layout(self, x, y)
        if self.align == HALIGN_RIGHT:  # label goes on right
            self.checkbox.update(
                x, y + self.height / 2 - self.checkbox.height / 2,
                self.checkbox.width, self.checkbox.height)
            self.label.x = x + self.checkbox.width + self.padding
        else:  # label goes on left
            self.label.x = x
            self.checkbox.update(
                x + self.label.content_width + self.padding,
                y + self.height / 2 - self.checkbox.height / 2,
                self.checkbox.width, self.checkbox.height)

        if self.highlight is not None:
            self.highlight.update(self.x, self.y, self.width, self.height)

        font = self.label.document.get_font()
        height = font.ascent - font.descent
        self.label.y = y + self.height / 2 - height / 2 - font.descent
示例#11
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)
示例#12
0
 def size(self, dialog):
     """
     Creates slider components.
     """
     if dialog is None:
         return
     Control.size(self, dialog)
     if self.is_disabled():
         color = dialog.theme['slider']['disabled_color']
     else:
         color = dialog.theme['slider']['gui_color']
     if self.bar is None:
         path = self.IMAGE_BAR
         self.bar = dialog.theme[path]['image'].generate(
             color,
             dialog.batch, dialog.bg_group)
         self.padding = dialog.theme[path]['padding']
     if self.knob is None:
         path = self.IMAGE_KNOB
         self.knob = dialog.theme[path]['image'].generate(
             color,
             dialog.batch, dialog.highlight_group)
         self.offset = dialog.theme[path]['offset']
     if not self.markers and self.steps is not None:
         path = self.IMAGE_STEP
         for n in xrange(0, self.steps + 1):
             self.markers.append(
                 dialog.theme[path]['image'].generate(
                     color,
                     dialog.batch, dialog.fg_group))
         self.step_offset = dialog.theme[path]['offset']
     width, height = self.bar.get_needed_size(self.min_width, 0)
     left, right, top, bottom = self.padding
     self.width = width + left + right
     self.height = height + top + bottom
示例#13
0
    def __init__(self, width):
        """
        Creates a new scrollbar.

        @param width Width of the area for which we are a scrollbar
        """
        Control.__init__(self, width=width, height=0)
        self.__init2__(width)
示例#14
0
    def __init__(self, width):
        """
        Creates a new scrollbar.

        @param width Width of the area for which we are a scrollbar
        """
        Control.__init__(self, width=width, height=0)
        self.__init2__(width)
示例#15
0
    def __init__(self, height):
        """
        Creates a new scrollbar.  At the outset, we are presented with maximum
        height and the templates to use.

        @param height Height of the area for which we are a scrollbar
        """
        Control.__init__(self, width=0, height=height)
        self.__init2__(height)
示例#16
0
    def __init__(self, height):
        """
        Creates a new scrollbar.  At the outset, we are presented with maximum
        height and the templates to use.

        @param height Height of the area for which we are a scrollbar
        """
        Control.__init__(self, width=0, height=height)
        self.__init2__(height)
示例#17
0
    def layout(self, x, y):
        Control.layout(self, x, y)

        self.field.update(x, y, self.width, self.height)
        x, y, width, height = self.field.get_content_region()

        font = self.label.document.get_font()
        height = font.ascent - font.descent
        self.label.x = x
        self.label.y = y - font.descent
示例#18
0
文件: menu.py 项目: isS/sy-game
 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
示例#19
0
文件: menu.py 项目: isS/sy-game
    def layout(self, x, y):
        Control.layout(self, x, y)

        self.field.update(x, y, self.width, self.height)
        x, y, width, height = self.field.get_content_region()

        font = self.label.document.get_font()
        height = font.ascent - font.descent
        self.label.x = x
        self.label.y = y - font.descent
示例#20
0
 def on_lose_focus(self):
     Control.on_lose_focus(self)
     self.delete()
     if self.saved_dialog is not None:
         self.size(self.saved_dialog)
         self.layout(self.x, self.y)
     if self.on_input is not None:
         if self.id is not None:
             self.on_input(self.id, self.get_text())
         else:
             self.on_input(self.get_text())
示例#21
0
 def delete(self):
     """
     Clean up our graphic elements
     """
     Control.delete(self)
     if self.checkbox is not None:
         self.checkbox.delete()
         self.checkbox = None
     if self.label is not None:
         self.label.delete()
         self.label = None
     if self.highlight is not None:
         self.highlight.delete()
         self.highlight = None
示例#22
0
    def __init__(self):
        """
        Creates a new event manager for a dialog.

        @param content The Widget which we wrap
        """
        Control.__init__(self)
        self.controls = []
        self.control_areas = {}
        self.control_map = {}
        self.hover = None
        self.focus = None
        self.wheel_hint = None
        self.wheel_target = None
示例#23
0
 def delete(self):
     """
     Clean up our graphic elements
     """
     Control.delete(self)
     if self.checkbox is not None:
         self.checkbox.delete()
         self.checkbox = None
     if self.label is not None:
         self.label.delete()
         self.label = None
     if self.highlight is not None:
         self.highlight.delete()
         self.highlight = None
示例#24
0
    def __init__(self):
        """
        Creates a new event manager for a dialog.

        @param content The Widget which we wrap
        """
        Control.__init__(self)
        self.controls = []
        self.control_areas = {}
        self.control_map = {}
        self.hover = None
        self.focus = None
        self.wheel_hint = None
        self.wheel_target = None
示例#25
0
 def delete(self):
     """
     Clean up our graphic elements
     """
     Control.delete(self)
     if self.button is not None:
         self.button.delete()
         self.button = None
     if self.label is not None:
         self.label.delete()
         self.label = None
     if self.highlight is not None:
         self.highlight.delete()
         self.highlight = None
示例#26
0
 def delete(self):
     """
     Clean up our graphic elements
     """
     Control.delete(self)
     if self.button is not None:
         self.button.delete()
         self.button = None
     if self.label is not None:
         self.label.delete()
         self.label = None
     if self.highlight is not None:
         self.highlight.delete()
         self.highlight = None
示例#27
0
文件: menu.py 项目: isS/sy-game
    def __init__(self, options=[], selected=None, id=None,
                 max_height=400, align=VALIGN_TOP, on_select=None,
                 disabled=False):
        assert options
        Control.__init__(self, id=id, disabled=disabled)
        self.options = options
        self.selected = selected or options[0]
        assert self.selected in self.options
        self.max_height = max_height
        self.align = align
        self.on_select = on_select

        self.field = None
        self.label = None
        self.pulldown_menu = None
示例#28
0
文件: text_input.py 项目: isS/sy-game
 def __init__(self, id=None, text="", length=20, max_length=None, padding=0,
              on_input=None, disabled=False):
     Control.__init__(self, id=id, disabled=disabled)
     self.text = text
     self.length = length
     self.max_length = max_length
     self.padding = padding
     self.on_input = on_input
     self.document = pyglet.text.document.UnformattedDocument(text)
     self.document_style_set = False
     self.text_layout = None
     self.label = None
     self.caret = None
     self.field = None
     self.highlight = None
示例#29
0
    def layout(self, x, y):
        """
        Places the Button.

        @param x X coordinate of lower left corner
        @param y Y coordinate of lower left corner
        """
        Control.layout(self, x, y)
        self.button.update(self.x, self.y, self.width, self.height)
        if self.highlight is not None:
            self.highlight.update(self.x, self.y, self.width, self.height)
        x, y, width, height = self.button.get_content_region()
        font = self.label.document.get_font()
        self.label.x = x + width/2 - self.label.content_width/2
        self.label.y = y + height/2 - font.ascent/2 - font.descent
示例#30
0
    def layout(self, x, y):
        """
        Places the Button.

        @param x X coordinate of lower left corner
        @param y Y coordinate of lower left corner
        """
        Control.layout(self, x, y)
        self.button.update(self.x, self.y, self.width, self.height)
        if self.highlight is not None:
            self.highlight.update(self.x, self.y, self.width, self.height)
        x, y, width, height = self.button.get_content_region()
        font = self.label.document.get_font()
        self.label.x = x + width / 2 - self.label.content_width / 2
        self.label.y = y + height / 2 - font.ascent / 2 - font.descent
示例#31
0
    def __init__(self, text="", id=None, on_click=None, disabled=False):
        """
        Creates a new Button.  The provided text will be used to caption the
        button.

        @param text Label for the button
        @param on_click Callback for the button
        @param disabled True if the button should be disabled
        """
        Control.__init__(self, id=id, disabled=disabled)
        self.text = text
        self.on_click = on_click
        self.label = None
        self.button = None
        self.highlight = None
        self.is_pressed = False
示例#32
0
    def __init__(self, text="", id=None, on_click=None, disabled=False):
        """
        Creates a new Button.  The provided text will be used to caption the
        button.

        @param text Label for the button
        @param on_click Callback for the button
        @param disabled True if the button should be disabled
        """
        Control.__init__(self, id=id, disabled=disabled)
        self.text = text
        self.on_click = on_click
        self.label = None
        self.button = None
        self.highlight = None
        self.is_pressed = False
示例#33
0
 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
示例#34
0
 def delete(self):
     Control.delete(self)
     if self.caret is not None:
         self.caret.delete()
         self.caret = None
     if self.text_layout is not None:
         self.document.remove_handlers(self.text_layout)
         self.text_layout.delete()
         self.text_layout = None
     if self.label is not None:
         self.label.delete()
         self.label = None
     if self.field is not None:
         self.field.delete()
         self.field = None
     if self.highlight is not None:
         self.highlight.delete()
         self.highlight = None
示例#35
0
 def __init__(self, document, width=1000, height=5000,
              is_fixed_size=False, always_show_scrollbar=False):
     """
     Creates a new Document.
     """
     Control.__init__(self, width, height)
     self.max_height = height
     self.content_width = width
     if isinstance(document, basestring):
         self.document = pyglet.text.document.UnformattedDocument(document)
     else:
         self.document = document
     self.content = None
     self.content_width = width
     self.scrollbar = None
     self.set_document_style = False
     self.is_fixed_size = is_fixed_size
     self.always_show_scrollbar = always_show_scrollbar
     self.needs_layout = False
示例#36
0
    def __init__(self,
                 options=[],
                 selected=None,
                 id=None,
                 max_height=400,
                 align=VALIGN_TOP,
                 on_select=None,
                 disabled=False):
        assert options
        Control.__init__(self, id=id, disabled=disabled)
        self.options = options
        self.selected = selected or options[0]
        assert self.selected in self.options
        self.max_height = max_height
        self.align = align
        self.on_select = on_select

        self.field = None
        self.label = None
        self.pulldown_menu = None
示例#37
0
    def __init__(self,
                 value=0.0,
                 min_value=0.0,
                 max_value=1.0,
                 steps=None,
                 width=100,
                 id=None,
                 on_set=None,
                 disabled=False):
        """
        Creates a new slider.

        @param min_value Minimum value
        @param max_value Maximum value
        @param steps None if this slider should cover the range from 0.0 to
                     1.0 smoothly, otherwise we will divide the range
                     up into steps.  For instance, 2 steps would give the
                     possible values 0, 0.5, and 1.0 (then multiplied by scale)
        @param width Minimum width of the tracking area.  Note that this
                     is the interior length of the slider, not the overall
                     size.
        @param id ID for identifying this slider.
        @param on_set Callback function for when the value of this slider
                      changes.
        @param diasbled True if the slider should be disabled
        """
        Control.__init__(self, id=id, disabled=disabled)
        self.min_value = min_value
        self.max_value = max_value
        self.steps = steps
        self.min_width = width
        self.on_set = on_set
        self.bar = None
        self.knob = None
        self.markers = []
        self.pos = max(
            min(float(value - min_value) / (max_value - min_value), 1.0), 0.0)
        self.offset = (0, 0)
        self.step_offset = (0, 0)
        self.padding = (0, 0, 0, 0)
        self.is_dragging = False
示例#38
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)
示例#39
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)
示例#40
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)
示例#41
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)
示例#42
0
 def __init__(self,
              document,
              width=1000,
              height=5000,
              is_fixed_size=False,
              always_show_scrollbar=False):
     """
     Creates a new Document.
     """
     Control.__init__(self, width, height)
     self.max_height = height
     self.content_width = width
     if isinstance(document, basestring):
         self.document = pyglet.text.document.UnformattedDocument(document)
     else:
         self.document = document
     self.content = None
     self.content_width = width
     self.scrollbar = None
     self.set_document_style = False
     self.is_fixed_size = is_fixed_size
     self.always_show_scrollbar = always_show_scrollbar
     self.needs_layout = False
示例#43
0
文件: menu.py 项目: 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)
示例#44
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)
示例#45
0
    def size(self, dialog):
        """
        Creates scrollbar components.
        """
        if dialog is None:
            return
        Control.size(self, dialog)
        dialog.set_wheel_hint(self)
        if self.left is None:
            if self.pos > 0.0:
                path = self.IMAGE_LEFT
            else:
                path = self.IMAGE_LEFTMAX
            self.left = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'],
                dialog.batch, dialog.fg_group)

            # Left button is our basis for minimum dimension
            self.width, self.height = self.left.width, self.left.height
        if self.space is None:
            path = self.IMAGE_SPACE
            self.space = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'],
                dialog.batch, dialog.fg_group)
        if self.bar is None:
            path = self.IMAGE_BAR
            self.bar = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'],
                dialog.batch, dialog.fg_group)
        if self.right is None:
            if self.pos < 1.0 - self.bar_width:
                path = self.IMAGE_RIGHT
            else:
                path = self.IMAGE_RIGHTMAX
            self.right = dialog.theme[path]['image'].generate(
                dialog.theme[path]['gui_color'],
                dialog.batch, dialog.fg_group)
示例#46
0
    def layout(self, x, y):
        """
        Places the Checkbox.

        @param x X coordinate of lower left corner
        @param y Y coordinate of lower left corner
        """
        Control.layout(self, x, y)
        if self.align == HALIGN_RIGHT:  # label goes on right
            self.checkbox.update(x, y + self.height/2 - self.checkbox.height/2,
                                 self.checkbox.width, self.checkbox.height)
            self.label.x = x + self.checkbox.width + self.padding
        else: # label goes on left
            self.label.x = x
            self.checkbox.update(x + self.label.content_width + self.padding,
                                 y + self.height/2 - self.checkbox.height/2,
                                 self.checkbox.width, self.checkbox.height)

        if self.highlight is not None:
            self.highlight.update(self.x, self.y, self.width, self.height)

        font = self.label.document.get_font()
        height = font.ascent - font.descent
        self.label.y = y + self.height/2 - height/2 - font.descent
示例#47
0
文件: menu.py 项目: isS/sy-game
    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)
示例#48
0
 def teardown(self):
     self.on_input = False
     Control.teardown(self)
示例#49
0
 def _get_controls(self):
     controls = []
     if self.scrollbar:
         controls += self.scrollbar._get_controls()
     controls += Control._get_controls(self)
     return controls
示例#50
0
 def teardown(self):
     self.menu = None
     Control.teardown(self)
示例#51
0
 def on_lose_highlight(self):
     Control.on_lose_highlight(self)
     if self.highlight is not None:
         self.highlight.delete()
         self.highlight = None
示例#52
0
 def on_gain_highlight(self):
     Control.on_gain_highlight(self)
     self.set_highlight()
示例#53
0
 def teardown(self):
     self.on_set = None
     Control.teardown(self)
示例#54
0
 def teardown(self):
     self.on_click = None
     Control.teardown(self)
示例#55
0
 def disable(self):
     Control.disable(self)
     self.document_style_set = False
示例#56
0
 def enable(self):
     Control.enable(self)
     self.document_style_set = False
示例#57
0
 def teardown(self):
     self.on_select = False
     self._delete_pulldown_menu()
     Control.teardown(self)
示例#58
0
 def on_gain_focus(self):
     Control.on_gain_focus(self)
     self.delete()
     if self.saved_dialog is not None:
         self.size(self.saved_dialog)
         self.layout(self.x, self.y)
示例#59
0
 def on_gain_highlight(self):
     Control.on_gain_highlight(self)
     self.size(self.saved_dialog)
     if self.highlight is not None:
         self.highlight.update(self.x, self.y, self.width, self.height)