Example #1
0
    def __init__(self, parent, border=None, color=None, bgcolor=None,
            active_bgcolor=None, font_size=None, is_active=False,
            alt_bgcolor=None, id=None, width='100%', **kw):
        self.is_active = is_active
        assert 'text' in kw, 'text required for Option'

        # default styling and width to parent settings
        select = parent.getParent('selection, combo-box')
        if color is None:
            color = select.color

        if bgcolor is None:
            self.bgcolor = select.bgcolor
        else:
            self.bgcolor = util.parse_color(bgcolor)
        if alt_bgcolor is None:
            self.alt_bgcolor = select.alt_bgcolor
        else:
            self.alt_bgcolor = util.parse_color(alt_bgcolor)
        if active_bgcolor is None:
            self.active_bgcolor = select.active_bgcolor
        else:
            self.active_bgcolor = util.parse_color(active_bgcolor)

        if self.alt_bgcolor:
            n = len(parent.children)
            bgcolor = (self.bgcolor, self.alt_bgcolor)[n%2]

        if font_size is None: font_size = select.font_size
        if id is None: id = kw['text']

        super(Option, self).__init__(parent, border=border, bgcolor=bgcolor,
            font_size=font_size, color=color, id=id, width=width, **kw)
Example #2
0
    def __init__(self, parent, size=None, is_exclusive=False,
            color=(0, 0, 0, 1), bgcolor=(1, 1, 1, 1),
            alt_bgcolor=(.9, .9, .9, 1), active_bgcolor=(1, .8, .8, 1),
            x=0, y=0, z=0, width='100%', height=None, **kw):
        font_size = parent.getStyle().font_size
        size = util.parse_value(size, None)
        if size is not None:
            height = (size + 1) * font_size

        self.is_exclusive = is_exclusive

        super(Table, self).__init__(parent, x, y, z, width, height,
            bgcolor=bgcolor, **kw)

        # rows go in under the heading
        #self.contents = TableContainer(self)
        self.contents = ContainerFrame(self)
        self.contents.layout = layouts.Layout(self.contents)
        self.contents.checkForScrollbars()

        # specific attributes for rows
        self.color = util.parse_color(color)
        self.base_bgcolor = self.bgcolor
        self.alt_bgcolor = util.parse_color(alt_bgcolor)
        self.active_bgcolor = util.parse_color(active_bgcolor)
Example #3
0
    def __init__(self,
                 parent,
                 minimum,
                 maximum,
                 value,
                 step=1,
                 bar_size=None,
                 show_value=False,
                 bar_text_color='white',
                 bar_color=(.3, .3, .3, 1),
                 x=None,
                 y=None,
                 z=None,
                 width=SliderCommon.slider_size,
                 height='100%',
                 bgcolor='gray',
                 **kw):

        self.minimum = util.parse_value(minimum, 0)
        self.type = type(self.minimum)
        self.maximum = util.parse_value(maximum, 0)
        self.range = self.maximum - self.minimum
        self._value = util.parse_value(value, 0)
        self.step = util.parse_value(step, 0)
        self.show_value = show_value
        self.bar_spec = bar_size
        self.bar_color = util.parse_color(bar_color)
        self.bar_text_color = util.parse_color(bar_text_color)
        self.bar = self.dbut = self.ubut = None

        super().__init__(parent, x, y, z, width, height, bgcolor=bgcolor, **kw)
Example #4
0
    def __init__(self, parent, items, font_size=None, border="black",
                 color='black', bgcolor='white', alt_bgcolor='eee',
                 active_bgcolor='ffc', item_pad=0, **kw):
        super().__init__(parent, **kw)

        # specific attributes for Options
        self.color = util.parse_color(color)
        self.base_bgcolor = self.bgcolor
        self.alt_bgcolor = util.parse_color(alt_bgcolor)
        self.active_bgcolor = util.parse_color(active_bgcolor)
        self.font_size = font_size

        lf = Frame(self)
        lf.layout = layouts.Horizontal(lf, halign='left', valign='top')

        # TODO: add a an editable flag, and use a TextInput if it's true
        self.label = Label(lf, items[0][0], font_size=font_size,
                           color=color, bgcolor=bgcolor, border=border)
        Image(lf, self.arrow, color=(0, 0, 0, 1), bgcolor=bgcolor,
              border=border)

        # set up the popup item - try to make it appear in front
        self.contents = Frame(self, is_visible=False,
                              bgcolor=bgcolor, border=border, z=.5)
        self.contents.layout = layouts.Vertical(self.contents)
        self.layout.ignore = set([self.contents])

        # add the options
        for label, id, kw in items:
            Option(self.contents, text=label, id=id, **kw)

        self.value = self.contents.children[0].id
Example #5
0
File: table.py Project: pyzh/pyglet
    def __init__(self,
                 parent,
                 size=None,
                 is_exclusive=False,
                 color=(0, 0, 0, 1),
                 bgcolor=(1, 1, 1, 1),
                 alt_bgcolor=(.9, .9, .9, 1),
                 active_bgcolor=(1, .8, .8, 1),
                 x=0,
                 y=0,
                 z=0,
                 width='100%',
                 height=None,
                 **kw):
        font_size = parent.getStyle().font_size
        size = util.parse_value(size, None)
        if size is not None:
            height = (size + 1) * font_size

        self.is_exclusive = is_exclusive

        super().__init__(parent, x, y, z, width, height, bgcolor=bgcolor, **kw)

        # rows go in under the heading
        # self.contents = TableContainer(self)
        self.contents = ContainerFrame(self)
        self.contents.layout = layouts.Layout(self.contents)
        self.contents.checkForScrollbars()

        # specific attributes for rows
        self.color = util.parse_color(color)
        self.base_bgcolor = self.bgcolor
        self.alt_bgcolor = util.parse_color(alt_bgcolor)
        self.active_bgcolor = util.parse_color(active_bgcolor)
Example #6
0
    def __init__(self,
                 parent,
                 x,
                 y,
                 z,
                 width,
                 height,
                 padding=0,
                 border=None,
                 bgcolor=None,
                 is_visible=True,
                 is_enabled=True,
                 is_transparent=False,
                 children=None,
                 id=None,
                 classes=()):
        self.parent = parent
        self.id = id or self.allocateID()
        self.classes = classes
        self.children = children or list()

        # colors, border and padding
        self.bgcolor = util.parse_color(bgcolor)
        self.border = util.parse_color(border)
        self._padding = util.parse_value(padding)
        if border:
            # force enough room to see the border
            self._padding += 1

        # save off the geometry specifications
        self.x_spec = util.Position(x, self, parent, 'width')
        self.y_spec = util.Position(y, self, parent, 'height')
        self._z = util.parse_value(z) or 0
        self.width_spec = util.Dimension(width, self, parent, 'width')
        self.height_spec = util.Dimension(height, self, parent, 'height')

        # attempt to calculate now what we can
        if self.x_spec.is_fixed:
            self.x = self.x_spec.calculate()
        if self.y_spec.is_fixed:
            self.y = self.y_spec.calculate()
        if self.width_spec.is_fixed:
            self.width = self.width_spec.calculate()
        if self.height_spec.is_fixed:
            self.height = self.height_spec.calculate()

        self.is_visible = is_visible
        self.is_enabled = is_enabled
        self.is_modal = False
        self.is_transparent = is_transparent

        self._event_handlers = dict()

        # add this new element to its parent
        self.parent.addChild(self)

        # indicate we need geometry calculation
        self.resetGeometry()
Example #7
0
    def __init__(self,
                 parent,
                 items=list(),
                 size=None,
                 is_exclusive=False,
                 color='black',
                 bgcolor='white',
                 is_vertical=True,
                 alt_bgcolor='eee',
                 active_bgcolor='ffc',
                 item_pad=0,
                 is_transparent=True,
                 scrollable=True,
                 font_size=None,
                 **kw):
        self.is_vertical = is_vertical
        self.is_exclusive = is_exclusive

        if font_size is None:
            font_size = parent.getStyle().font_size
        else:
            font_size = util.parse_value(font_size, None)

        size = util.parse_value(size, None)

        if is_vertical:
            if size is not None:
                kw['height'] = size * font_size
        else:
            if size is not None:
                kw['width'] = size * font_size

        super().__init__(parent,
                         bgcolor=bgcolor,
                         scrollable=scrollable,
                         scrollable_resize=scrollable,
                         is_transparent=is_transparent,
                         **kw)
        if scrollable:
            f = self.contents
        else:
            f = self
        if is_vertical:
            f.layout = layouts.Vertical(f, padding=item_pad)
        else:
            f.layout = layouts.Horizontal(f, padding=item_pad)

        # specific attributes for Options
        self.color = util.parse_color(color)
        self.base_bgcolor = self.bgcolor
        self.alt_bgcolor = util.parse_color(alt_bgcolor)
        self.active_bgcolor = util.parse_color(active_bgcolor)
        self.font_size = font_size

        for label, id, kw in items:
            self.addOption(label, id, **kw)
    def __init__(self,
                 parent,
                 items,
                 font_size=None,
                 border="black",
                 color='black',
                 bgcolor='white',
                 alt_bgcolor='eee',
                 active_bgcolor='ffc',
                 item_pad=0,
                 **kw):
        super(ComboBox, self).__init__(parent, **kw)

        # specific attributes for Options
        self.color = util.parse_color(color)
        self.base_bgcolor = self.bgcolor
        self.alt_bgcolor = util.parse_color(alt_bgcolor)
        self.active_bgcolor = util.parse_color(active_bgcolor)
        self.font_size = font_size

        lf = Frame(self)
        lf.layout = layouts.Horizontal(lf, halign='left', valign='top')

        # XXX add a an editable flag, and use a TextInput if it's true
        self.label = Label(lf,
                           items[0][0],
                           font_size=font_size,
                           color=color,
                           bgcolor=bgcolor,
                           border=border)
        Image(lf,
              self.arrow,
              color=(0, 0, 0, 1),
              bgcolor=bgcolor,
              border=border)

        # set up the popup item - try to make it appear in front
        self.contents = Frame(self,
                              is_visible=False,
                              bgcolor=bgcolor,
                              border=border,
                              z=.5)
        self.contents.layout = layouts.Vertical(self.contents)
        self.layout.ignore = set([self.contents])

        # add the options
        for label, id, kw in items:
            Option(self.contents, text=label, id=id, **kw)

        self.value = self.contents.children[0].id
Example #9
0
    def __init__(self,
                 parent,
                 border=None,
                 color=None,
                 bgcolor=None,
                 active_bgcolor=None,
                 font_size=None,
                 is_active=False,
                 alt_bgcolor=None,
                 id=None,
                 width='100%',
                 **kw):
        self.is_active = is_active
        assert 'text' in kw, 'text required for Option'

        # default styling and width to parent settings
        select = parent.getParent('selection, combo-box')
        if color is None:
            color = select.color

        if bgcolor is None:
            self.bgcolor = select.bgcolor
        else:
            self.bgcolor = util.parse_color(bgcolor)
        if alt_bgcolor is None:
            self.alt_bgcolor = select.alt_bgcolor
        else:
            self.alt_bgcolor = util.parse_color(alt_bgcolor)
        if active_bgcolor is None:
            self.active_bgcolor = select.active_bgcolor
        else:
            self.active_bgcolor = util.parse_color(active_bgcolor)

        if self.alt_bgcolor:
            n = len(parent.children)
            bgcolor = (self.bgcolor, self.alt_bgcolor)[n % 2]

        if font_size is None:
            font_size = select.font_size
        if id is None:
            id = kw['text']

        super().__init__(parent,
                         border=border,
                         bgcolor=bgcolor,
                         font_size=font_size,
                         color=color,
                         id=id,
                         width=width,
                         **kw)
Example #10
0
    def __init__(self, parent, text, bgcolor='white', color='black',
                 border='black', focus_border=(.3, .3, .7, 1),
                 pressed_bgcolor=(1, .9, .9, 1), over_bgcolor=(.9, .9, 1, 1),
                 **kw):

        super().__init__(parent, text, bgcolor=bgcolor,
                         color=color, border=border, **kw)

        # colouring attributes
        self.base_bgcolor = self.bgcolor
        self.pressed_bgcolor = util.parse_color(pressed_bgcolor)
        self.over_bgcolor = util.parse_color(over_bgcolor)
        self.base_border = self.border
        self.focus_border = util.parse_color(focus_border)
Example #11
0
    def __init__(self,
                 parent,
                 border=None,
                 color=None,
                 bgcolor=None,
                 active_bgcolor=None,
                 is_active=False,
                 width='100%',
                 **kw):
        self.is_active = is_active

        # default styling and width to parent settings
        n = len(parent.children)
        table = parent.parent
        if color is None:
            color = table.color
        if bgcolor is None:
            bgcolor = (table.bgcolor, table.alt_bgcolor)[n % 2]
        if active_bgcolor is None:
            self.active_bgcolor = table.active_bgcolor
        else:
            self.active_bgcolor = util.parse_color(active_bgcolor)

        font_size = parent.getStyle().font_size
        kw['y'] = n * font_size
        kw['height'] = font_size
        super(Row, self).__init__(parent,
                                  border=border,
                                  bgcolor=bgcolor,
                                  width=width,
                                  **kw)
        self.base_bgcolor = bgcolor
Example #12
0
    def __init__(
        self,
        parent,
        image,
        text=None,
        pressed_image=None,
        over_image=None,
        is_blended=True,
        font_size=None,
        color=(0, 0, 0, 1),
        x=0,
        y=0,
        z=0,
        width=None,
        height=None,
        **kw
    ):
        super(Button, self).__init__(parent, x, y, z, width, height, is_blended=is_blended, **kw)

        if image is None:
            raise ValueError, "image argument is required"

        self.setImage(image)
        self.setPressedImage(pressed_image)
        self.setOverImage(over_image)
        self.color = util.parse_color(color)

        if text:
            self.font_size = int(font_size or self.getStyle().font_size)
            self.bg = self.base_image
            self.over_bg = self.over_image
            self.pressed_bg = self.pressed_image
            # clear so we don't delete these
            self.base_image = self.over_image = self.pressed_image = None
        self.text = text
Example #13
0
 def __init__(self,
              parent,
              text,
              x=None,
              y=None,
              z=None,
              width=None,
              height=None,
              font_size=None,
              valign='top',
              halign='left',
              color='black',
              rotate=0,
              **kw):
     self.valign = valign
     self.halign = halign
     self.font_size = int(font_size or parent.getStyle().font_size)
     self.color = util.parse_color(color)
     self.rotate = util.parse_value(rotate, 0)
     assert self.rotate in (0, 90, 180, 270), \
         'rotate must be one of 0, 90, 180, 270, not %r'%(self.rotate, )
     # set parent now so style is available
     self.parent = parent
     super(LabelCommon, self).__init__(parent, x, y, z, width, height, **kw)
     self.text = text
Example #14
0
    def __init__(self,
                 parent,
                 value=0.0,
                 show_value=True,
                 bar_color='gray',
                 bgcolor=(.3, .3, .3, 1),
                 color='white',
                 width=None,
                 height=16,
                 halign='center',
                 valign='center',
                 **kw):

        self._value = util.parse_value(value, 0)
        self.show_value = show_value
        self.bar_color = util.parse_color(bar_color)

        super().__init__(parent,
                         ' ',
                         width=width,
                         height=height,
                         bgcolor=bgcolor,
                         color=color,
                         halign=halign,
                         valign=valign,
                         **kw)

        if self.show_value:
            self.text = '%d%%' % (value * 100)
Example #15
0
    def __init__(self, parent, x, y, z, width, height, padding=0,
                 border=None, bgcolor=None, is_visible=True, is_enabled=True,
                 is_transparent=False, children=None, id=None, classes=()):
        self.parent = parent
        self.id = id or self.allocateID()
        self.classes = classes
        self.children = children or list()

        # colors, border and padding
        self.bgcolor = util.parse_color(bgcolor)
        self.border = util.parse_color(border)
        self._padding = util.parse_value(padding)
        if border:
            # force enough room to see the border
            self._padding += 1

        # save off the geometry specifications
        self.x_spec = util.Position(x, self, parent, 'width')
        self.y_spec = util.Position(y, self, parent, 'height')
        self._z = util.parse_value(z) or 0
        self.width_spec = util.Dimension(width, self, parent, 'width')
        self.height_spec = util.Dimension(height, self, parent, 'height')

        # attempt to calculate now what we can
        if self.x_spec.is_fixed:
            self.x = self.x_spec.calculate()
        if self.y_spec.is_fixed:
            self.y = self.y_spec.calculate()
        if self.width_spec.is_fixed:
            self.width = self.width_spec.calculate()
        if self.height_spec.is_fixed:
            self.height = self.height_spec.calculate()

        self.is_visible = is_visible
        self.is_enabled = is_enabled
        self.is_modal = False
        self.is_transparent = is_transparent

        self._event_handlers = dict()

        # add this new element to its parent
        self.parent.addChild(self)

        # indicate we need geometry calculation
        self.resetGeometry()
Example #16
0
    def __init__(self, parent, items=list(), size=None, is_exclusive=False,
                 color='black', bgcolor='white', is_vertical=True,
                 alt_bgcolor='eee', active_bgcolor='ffc', item_pad=0,
                 is_transparent=True, scrollable=True, font_size=None, **kw):
        self.is_vertical = is_vertical
        self.is_exclusive = is_exclusive

        if font_size is None:
            font_size = parent.getStyle().font_size
        else:
            font_size = util.parse_value(font_size, None)

        size = util.parse_value(size, None)

        if is_vertical:
            if size is not None:
                kw['height'] = size * font_size
        else:
            if size is not None:
                kw['width'] = size * font_size

        super().__init__(parent, bgcolor=bgcolor,
                         scrollable=scrollable,
                         scrollable_resize=scrollable,
                         is_transparent=is_transparent, **kw)
        if scrollable:
            f = self.contents
        else:
            f = self
        if is_vertical:
            f.layout = layouts.Vertical(f, padding=item_pad)
        else:
            f.layout = layouts.Horizontal(f, padding=item_pad)

        # specific attributes for Options
        self.color = util.parse_color(color)
        self.base_bgcolor = self.bgcolor
        self.alt_bgcolor = util.parse_color(alt_bgcolor)
        self.active_bgcolor = util.parse_color(active_bgcolor)
        self.font_size = font_size

        for label, id, kw in items:
            self.addOption(label, id, **kw)
Example #17
0
    def __init__(self, parent, minimum, maximum, value, step=1,
                 bar_size=None, show_value=False, bar_text_color='white',
                 bar_color=(.3, .3, .3, 1), x=None, y=None, z=None,
                 width=SliderCommon.slider_size, height='100%',
                 bgcolor='gray', **kw):

        self.minimum = util.parse_value(minimum, 0)
        self.type = type(self.minimum)
        self.maximum = util.parse_value(maximum, 0)
        self.range = self.maximum - self.minimum
        self._value = util.parse_value(value, 0)
        self.step = util.parse_value(step, 0)
        self.show_value = show_value
        self.bar_spec = bar_size
        self.bar_color = util.parse_color(bar_color)
        self.bar_text_color = util.parse_color(bar_text_color)
        self.bar = self.dbut = self.ubut = None

        super().__init__(parent, x, y, z, width, height,
                         bgcolor=bgcolor, **kw)
    def __init__(self,
                 parent,
                 minimum,
                 maximum,
                 value,
                 step=1,
                 bar_size=None,
                 show_value=False,
                 bar_text_color='white',
                 bar_color=(.3, .3, .3, 1),
                 x=None,
                 y=None,
                 z=None,
                 width='100%',
                 height=SliderCommon.slider_size,
                 bgcolor='gray',
                 **kw):

        self.minimum = util.parse_value(minimum, 0)
        self.type = type(self.minimum)
        self.maximum = util.parse_value(maximum, 0)
        self.range = self.maximum - self.minimum
        self._value = util.parse_value(value, 0)
        self.step = util.parse_value(step, 0)
        self.show_value = show_value
        self.bar_spec = bar_size
        self.bar_color = util.parse_color(bar_color)
        self.bar_text_color = util.parse_color(bar_text_color)
        self.bar = self.lbut = self.rbut = None

        # for step repeat when clicking in the bar
        self.delay_timer = None

        super(HorizontalSlider, self).__init__(parent,
                                               x,
                                               y,
                                               z,
                                               width,
                                               height,
                                               bgcolor=bgcolor,
                                               **kw)
Example #19
0
    def __init__(
        self,
        parent,
        text,
        bgcolor="white",
        color="black",
        border="black",
        focus_border=(0.3, 0.3, 0.7, 1),
        pressed_bgcolor=(1, 0.9, 0.9, 1),
        over_bgcolor=(0.9, 0.9, 1, 1),
        **kw
    ):

        super(TextButton, self).__init__(parent, text, bgcolor=bgcolor, color=color, border=border, **kw)

        # colouring attributes
        self.base_bgcolor = self.bgcolor
        self.pressed_bgcolor = util.parse_color(pressed_bgcolor)
        self.over_bgcolor = util.parse_color(over_bgcolor)
        self.base_border = self.border
        self.focus_border = util.parse_color(focus_border)
Example #20
0
    def __init__(self, parent, minimum, maximum, value, step=1,
            bar_size=None, show_value=False, bar_text_color='white',
            bar_color=(.3, .3, .3, 1), x=None, y=None, z=None, width='100%',
            height=SliderCommon.slider_size, bgcolor='gray', **kw):

        self.minimum = util.parse_value(minimum, 0)
        self.type = type(self.minimum)
        self.maximum = util.parse_value(maximum, 0)
        self.range = self.maximum - self.minimum
        self._value = util.parse_value(value, 0)
        self.step = util.parse_value(step, 0)
        self.show_value = show_value
        self.bar_spec = bar_size
        self.bar_color = util.parse_color(bar_color)
        self.bar_text_color = util.parse_color(bar_text_color)
        self.bar = self.lbut = self.rbut = None

        # for step repeat when clicking in the bar
        self.delay_timer = None

        super(HorizontalSlider, self).__init__(parent, x, y, z, width, height,
            bgcolor=bgcolor, **kw)
Example #21
0
 def __init__(self, parent, text, x=None, y=None, z=None, width=None,
         height=None, font_size=None, valign='top', halign='left',
         color='black', rotate=0, **kw):
     self.valign = valign
     self.halign = halign
     self.font_size = int(font_size or parent.getStyle().font_size)
     self.color = util.parse_color(color)
     self.rotate = util.parse_value(rotate, 0)
     assert self.rotate in (0, 90, 180, 270), \
         'rotate must be one of 0, 90, 180, 270, not %r'%(self.rotate, )
     # set parent now so style is available
     self.parent = parent
     super(LabelCommon, self).__init__(parent, x, y, z, width, height, **kw)
     self.text = text
Example #22
0
    def __init__(self, parent, value=0.0, show_value=True,
            bar_color='gray', bgcolor=(.3, .3, .3, 1), color='white',
            width=None, height=16, halign='center', valign='center', **kw):

        self._value = util.parse_value(value, 0)
        self.show_value = show_value
        self.bar_color = util.parse_color(bar_color)

        super(Progress, self).__init__(parent, ' ', width=width,
            height=height, bgcolor=bgcolor, color=color, halign=halign,
            valign=valign, **kw)

        if self.show_value:
            self.text = '%d%%'%(value * 100)
Example #23
0
    def __init__(self,
                 parent,
                 text,
                 bgcolor='white',
                 color='black',
                 border='black',
                 focus_border=(.3, .3, .7, 1),
                 pressed_bgcolor=(1, .9, .9, 1),
                 over_bgcolor=(.9, .9, 1, 1),
                 **kw):

        super().__init__(parent,
                         text,
                         bgcolor=bgcolor,
                         color=color,
                         border=border,
                         **kw)

        # colouring attributes
        self.base_bgcolor = self.bgcolor
        self.pressed_bgcolor = util.parse_color(pressed_bgcolor)
        self.over_bgcolor = util.parse_color(over_bgcolor)
        self.base_border = self.border
        self.focus_border = util.parse_color(focus_border)
Example #24
0
    def __init__(self, parent, image, is_blended=True, color=None, **kw):
        if image is None and file is None:
            raise ValueError, 'image or file required'

        if isinstance(image, str):
            image = data.load_image(image)
        elif hasattr(image, 'texture'):
            image = image.texture

        self.parent = parent

        self.color = util.parse_color(color)

        super(Image, self).__init__(parent, is_blended=is_blended, **kw)

        self.setImage(image)
Example #25
0
    def __init__(self, parent, image, is_blended=True, color=None, **kw):
        if image is None and file is None:
            raise ValueError, 'image or file required'

        if isinstance(image, str):
            image = data.load_image(image)
        elif hasattr(image, 'texture'):
            image = image.texture

        self.parent = parent

        self.color = util.parse_color(color)

        super(Image, self).__init__(parent, is_blended=is_blended, **kw)

        self.setImage(image)
Example #26
0
    def __init__(self,
                 parent,
                 text='',
                 font_size=None,
                 size=None,
                 x=0,
                 y=0,
                 z=0,
                 width=None,
                 height=None,
                 border='black',
                 padding=2,
                 bgcolor='white',
                 color='black',
                 focus_border=(.3, .3, .7, 1),
                 **kw):
        style = parent.getStyle()
        if font_size is None:
            font_size = style.font_size
        else:
            font_size = util.parse_value(font_size, None)
        self.font_size = font_size
        if size is not None:
            size = util.parse_value(size, None)
            width = size * style.getGlyphString('M', size=font_size).width
            width += padding * 2
        super().__init__(parent,
                         x,
                         y,
                         z,
                         width,
                         height,
                         padding=padding,
                         border=border,
                         bgcolor=bgcolor,
                         **kw)

        self.ti = TextInputLine(self,
                                text,
                                font_size=font_size,
                                bgcolor=bgcolor,
                                color=color)

        self.base_border = self.border
        self.focus_border = util.parse_color(focus_border)
Example #27
0
    def __init__(self,
                 parent,
                 image,
                 text=None,
                 pressed_image=None,
                 over_image=None,
                 is_blended=True,
                 font_size=None,
                 color=(0, 0, 0, 1),
                 x=0,
                 y=0,
                 z=0,
                 width=None,
                 height=None,
                 **kw):
        super().__init__(parent,
                         x,
                         y,
                         z,
                         width,
                         height,
                         is_blended=is_blended,
                         **kw)

        if image is None:
            raise ValueError('image argument is required')

        self.setImage(image)
        self.setPressedImage(pressed_image)
        self.setOverImage(over_image)
        self.color = util.parse_color(color)

        if text:
            self.font_size = int(font_size or self.getStyle().font_size)
            self.bg = self.base_image
            self.over_bg = self.over_image
            self.pressed_bg = self.pressed_image
            # clear so we don't delete these
            self.base_image = self.over_image = self.pressed_image = None
        self.text = text
Example #28
0
    def __init__(self, parent, border=None, color=None, bgcolor=None,
            active_bgcolor=None, is_active=False, width='100%', **kw):
        self.is_active = is_active

        # default styling and width to parent settings
        n = len(parent.children)
        table = parent.parent
        if color is None:
            color = table.color
        if bgcolor is None:
            bgcolor = (table.bgcolor, table.alt_bgcolor)[n%2]
        if active_bgcolor is None:
            self.active_bgcolor = table.active_bgcolor
        else:
            self.active_bgcolor = util.parse_color(active_bgcolor)

        font_size = parent.getStyle().font_size
        kw['y'] = n * font_size
        kw['height'] = font_size
        super(Row, self).__init__(parent, border=border, bgcolor=bgcolor,
            width=width, **kw)
        self.base_bgcolor = bgcolor
Example #29
0
    def __init__(self, parent, text='', font_size=None, size=None,
            x=0, y=0, z=0, width=None, height=None, border='black',
            padding=2, bgcolor='white', color='black',
            focus_border=(.3, .3, .7, 1), **kw):
        style = parent.getStyle()
        if font_size is None:
            font_size = style.font_size
        else:
            font_size = util.parse_value(font_size, None)
        self.font_size = font_size
        if size is not None:
            size = util.parse_value(size, None)
            width = size * style.getGlyphString('M', size=font_size).width
            width += padding*2
        super(TextInput, self).__init__(parent, x, y, z, width, height,
            padding=padding, border=border, bgcolor=bgcolor, **kw)

        self.ti = TextInputLine(self, text, font_size=font_size,
            bgcolor=bgcolor, color=color)

        self.base_border = self.border
        self.focus_border = util.parse_color(focus_border)