Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
0
Arquivo: menu.py Projeto: 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
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
0
Arquivo: menu.py Projeto: 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
Exemplo n.º 14
0
 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
Exemplo n.º 15
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
Exemplo n.º 16
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
Exemplo n.º 17
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
Exemplo n.º 18
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
Exemplo n.º 19
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
Exemplo n.º 20
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
Exemplo n.º 21
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