Esempio n. 1
0
 def __init__(self, template="ButtonDefault", **kwargs):
     LUIObject.__init__(self, x=0, y=0, solid=True)
     self._template = template
     self._button_sprite = LUISprite(self, template, "skin")
     self._button_sprite.width = width
     self._button_sprite.height = height
     LUIInitialState.init(self, kwargs)
Esempio n. 2
0
 def __init__(self,
              parent=None,
              group=None,
              value=None,
              active=False,
              label=u"Radiobox",
              **kwargs):
     """ Constructs a new radiobox. group should be a handle to a LUIRadioboxGroup.
     value will be the value returned by group.value, in case the box was
     selected. By default, the radiobox is not active. """
     assert group is not None, "LUIRadiobox needs a LUIRadioboxGroup!"
     LUIObject.__init__(self, x=0, y=0, solid=True)
     self._sprite = LUISprite(self, "Radiobox_Default", "skin")
     self._label = LUILabel(parent=self,
                            text=label,
                            margin=(0, 0, 0, 23),
                            center_vertical=True)
     self._value = value
     self._active = False
     self._hovered = False
     self._group = group
     self._group.register_box(self)
     if active:
         self.set_active()
     if parent:
         self.parent = parent
     LUIInitialState.init(self, kwargs)
Esempio n. 3
0
    def __init__(self, parent=None, width=200, value=50, show_label=True):
        """ Constructs a new progress bar. If show_label is True, a label indicating
        the current progress is shown """
        LUIObject.__init__(self)
        self.set_width(width)

        self._bg_layout = LUIHorizontalStretchedLayout(parent=self,
                                                       prefix="ProgressbarBg",
                                                       width="100%")

        self._fg_left = LUISprite(self, "ProgressbarFg_Left", "skin")
        self._fg_mid = LUISprite(self, "ProgressbarFg", "skin")
        self._fg_right = LUISprite(self, "ProgressbarFg_Right", "skin")
        self._fg_finish = LUISprite(self, "ProgressbarFg_Finish", "skin")

        self._show_label = show_label
        self._progress_pixel = 0
        self._fg_finish.right = 0

        if self._show_label:
            self._progress_label = LUILabel(parent=self, text=u"33 %")
            self._progress_label.centered = (True, True)

        self.set_value(value)
        self._update_progress()

        if parent is not None:
            self.parent = parent
Esempio n. 4
0
 def __init__(self, image_prefix="", **kwargs):
     """ Creates a new layout, using the image_prefix as prefix. """
     LUIObject.__init__(self)
     self.set_size("100%", "100%")
     self._prefix = image_prefix
     self._parts = {}
     for i in self._MODES:
         self._parts[i] = LUISprite(self, "blank", "skin")
     self._update_layout()
     LUIInitialState.init(self, kwargs)
Esempio n. 5
0
 def __init__(self, parent=None, prefix="ButtonDefault", **kwargs):
     LUIObject.__init__(self)
     self._layout = LUIHorizontalLayout(self, spacing=0)
     self._layout.width = "100%"
     self._sprite_left = LUISprite(self._layout.cell(), "blank", "skin")
     self._sprite_mid = LUISprite(self._layout.cell('*'), "blank", "skin")
     self._sprite_right = LUISprite(self._layout.cell(), "blank", "skin")
     if parent is not None:
         self.parent = parent
     self.prefix = prefix
     LUIInitialState.init(self, kwargs)
Esempio n. 6
0
    def __init__(self, checked=False, label=u"Checkbox", **kwargs):
        """ Constructs a new checkbox with the given label and state. """
        LUIObject.__init__(self, x=0, y=0, w=0, h=0, solid=True)
        LUIInitialState.init(self, kwargs)
        self.checkboxSprite = LUISprite(self, "Checkbox_Default", "skin")
        self.label = LUILabel(parent=self, text=label, shadow=True, left=self.checkboxSprite.width + 6)
        self.label.top = self.label.height - self.checkboxSprite.height
        self.label.bind("resized", self._on_label_resized)
        self.fit_to_children()

        self.checked = checked
        self._update_sprite()
Esempio n. 7
0
 def __init__(self, checked=False, label=u"Checkbox", **kwargs):
     """ Constructs a new checkbox with the given label and state. By default,
     the checkbox is not checked. """
     LUIObject.__init__(self, x=0, y=0, solid=True)
     self._checked = checked
     self._checkbox_sprite = LUISprite(self, "Checkbox_Default", "skin")
     self._label = LUILabel(parent=self,
                            text=label,
                            margin=(0, 0, 0, 25),
                            center_vertical=True,
                            alpha=0.4)
     self._hovered = False
     LUIInitialState.init(self, kwargs)
Esempio n. 8
0
    def __init__(self, text=u"Label", shadow=True, font_size=14, font="label", **kwargs):
        """ Creates a new label. """
        LUIObject.__init__(self)
        LUIInitialState.init(self, kwargs)
        self.text = LUIText(self, unicode(text), font, font_size, 0, 0)
        self.text.color = (1,1,1,0.9)
        self.text.z_offset = 1
        self.have_shadow = shadow

        if self.have_shadow:
            self.shadowText = LUIText(self, unicode(text), font, font_size, 0, 0)
            self.shadowText.top = 1
            self.shadowText.color = (0,0,0,0.7)

        self.fit_to_children()
Esempio n. 9
0
    def __init__(self, template="ButtonDefault", width = 50, height = 50, **kwargs):
        LUIObject.__init__(self, x=0, y=0, w=0, h=0, solid=True)
        LUIInitialState.init(self, kwargs)
        self.margin_left = -1
        self.template = template

        self.fit_to_children()

        self.button_sprite = LUISprite(self, template, "skin")
        self.fit_to_children()

        self.width = width
        self.height = height

        self.button_sprite.width = width
        self.button_sprite.height = height
Esempio n. 10
0
    def __init__(self, **kwargs):
        super(LUITabbedFrame, self).__init__(**kwargs)

        # The main window layout
        bar_spacing = kwargs.get('bar_spacing', 3)
        self.root_layout = LUIVerticalLayout(parent=self, spacing=bar_spacing)
        self.root_layout.height = "100%"
        self.root_layout.width = "100%"
        self.root_layout.margin = 0

        # The header bar
        header_spacing = kwargs.get('header_spacing', 3)
        self.header_bar = LUIHorizontalLayout(
            parent=self.root_layout.cell("?"), spacing=header_spacing)
        self.root_layout.add(self.header_bar, "?")
        self.header_to_frame = {}
        self.current_frame = None

        # The main window contents
        self.main_frame = LUIObject()
        self.main_frame.height = "100%"
        self.main_frame.width = "100%"
        self.main_frame.margin = 0
        # self.main_frame.padding = 0
        self.root_layout.add(self.main_frame, "*")
Esempio n. 11
0
    def __init__(self, group=None, value=None, active=False, label=u"Radiobox", **kwargs):
        LUIObject.__init__(self, x=0, y=0, w=0, h=0, solid=True)
        LUIInitialState.init(self, kwargs)

        self.sprite = LUISprite(self, "Radiobox_Default", "skin")
        self.label = LUILabel(parent=self, text=label, shadow=True, left=self.sprite.width+6)
        self.label.top = self.label.height - self.sprite.height
        self.label.bind("resized", self._on_label_resized)

        self.fit_to_children()
        self.group = group
        self.group.register_box(self)
        self.active = False
        self.value = value

        if active:
            self.set_active()
Esempio n. 12
0
    def __init__(self, parent, width=200):
        LUIObject.__init__(self, x=0, y=0, w=width, h=1, solid=True)

        self.layout = LUICornerLayout(parent=self, image_prefix="Selectdrop_", width=width + 10, height=100)
        self.layout.margin_left = -3

        self.opener = LUISprite(self, "SelectboxOpen_Right", "skin")
        self.opener.right = -4
        self.opener.top = -25
        self.opener.z_offset = 3

        self.container = LUIObject(self.layout, 0, 0, 0, 0)
        self.container.width = self.width
        self.container.clip_bounds = (0,0,0,0)
        self.container.left = 5

        self.selectbox = parent
        self.parent = self.selectbox
Esempio n. 13
0
    def __init__(self, width=200, options=None, selectedOption=None, **kwargs):
        LUIObject.__init__(self, x=0, y=0, w=width+4, h=0, solid=True)
        LUIInitialState.init(self, kwargs)
        LUICallback.__init__(self)

        # The selectbox has a small border, to correct this we move it
        self.margin_left = -2

        self.bgLeft = LUISprite(self, "Selectbox_Left", "skin")
        self.bgMid = LUISprite(self, "Selectbox", "skin")
        self.bgRight = LUISprite(self, "Selectbox_Right", "skin")

        self.bgMid.width = self.width - self.bgLeft.width - self.bgRight.width
        self.bgMid.left = self.bgLeft.width
        self.bgRight.left = self.bgMid.width + self.bgMid.left

        self.bgRight.z_offset = 1

        self.labelContainer = LUIObject(self, x=10, y=6, w=width - 20 - self.bgRight.width, h=self.bgMid.height - 6)
        self.labelContainer.clip_bounds = (0,0,0,0)

        self.label = LUILabel(parent=self.labelContainer, text=u"Select an option ..", shadow=True)

        self.bgRight.bind("mouseover", self._knob_mouseover)
        self.bgRight.bind("mouseout", self._knob_mouseout)
        self.bgRight.bind("click", self.on_click)
        self.bgRight.bind("click", self.on_click)

        self.fit_to_children()

        self.dropMenu = UISelectdrop(parent=self, width=width)
        self.dropMenu.top = self.bgMid.height - 7
        self.dropMenu.topmost = True

        self.dropOpen = False
        self.dropMenu.hide()

        self.options = []
        self.currentOptionId = None

        if options is not None:
            self.options = options

        self._select_option(selectedOption)
Esempio n. 14
0
    def __init__(self, inner_padding=5, scrollable=False, style=FS_raised, **kwargs):
        """ Creates a new frame with the given options and style. If scrollable
        is True, the contents of the frame will scroll if they don't fit into
        the frame height. inner_padding only has effect if scrollable is True.
        You can call fit_to_children() to make the frame fit automatically to
        it's contents."""
        LUIObject.__init__(self)

        # Each *style* has a different border size (size of the shadow). The
        # border size shouldn't get calculated to the actual framesize, so we
        # are determining it first and then substracting it.
        # TODO: We could do this automatically, determined by the sprite size
        # probably?
        self._border_size = 0
        self.padding = 10
        self.solid = True
        prefix = ""

        if style == LUIFrame.FS_raised:
            temp = LUISprite(self, "Frame_Left", "skin")
            self._border_size = temp.width
            self.remove_child(temp)
            prefix = "Frame_"
        elif style == LUIFrame.FS_sunken:
            self._border_size = 0
            prefix = "SunkenFrame_"
        else:
            raise Exception("Unkown LUIFrame style: " + style)

        self._scrollable = scrollable
        self._layout = LUICornerLayout(parent=self, image_prefix=prefix)
        self._layout.margin = -(self.padding.top + self._border_size)
        if self._scrollable:
            self._content = LUIObject(self)
            self._content.size = (self.width, self.height)
            self._content.pos = (self._border_size, self._border_size)
            self._scroll_content = LUIScrollableRegion(self._content,
                width=self.width-2*self.padding.left, height=self.height-2*self.padding.left,
                padding=inner_padding)
            self.content_node = self._scroll_content.content_node

        LUIInitialState.init(self, kwargs)
Esempio n. 15
0
    def __init__(self, text=u"Button", template="ButtonDefault", **kwargs):
        """ Constructs a new button. The template controls which sprites to use.
        If the template is "ButtonDefault" for example, the sprites
        "ButtonDefault_Left", "ButtonDefault" and "ButtonDefault_Right" will
        be used. The sprites used when the button is pressed should be named
        "ButtonDefaultFocus_Left" and so on then.

        If an explicit width is set on the button, the button will stick to that
        width, otherwise it will automatically resize to fit the label """
        LUIObject.__init__(self, x=0, y=0, solid=True)
        self._template = template
        self._layout = LUIHorizontalStretchedLayout(parent=self,
                                                    prefix=self._template,
                                                    width="100%")
        self._label = LUILabel(parent=self, text=text)
        self._label.z_offset = 1
        self._label.center_vertical = True
        self._label.margin = 0, 20, 0, 20
        self.margin.left = -1
        LUIInitialState.init(self, kwargs)
Esempio n. 16
0
 def __init__(self,
              text=u"Label",
              shadow=None,
              font_size=14,
              font="label",
              **kwargs):
     """ Creates a new label. If shadow is True, a small text shadow will be
     rendered below the actual text. """
     LUIObject.__init__(self)
     self._text = LUIText(self, unicode(text), font, font_size)
     self._text.z_offset = 1
     self.color = LUILabel.DEFAULT_COLOR
     if shadow is None:
         shadow = LUILabel.DEFAULT_USE_SHADOW
     self._have_shadow = shadow
     if self._have_shadow:
         self._shadow_text = LUIText(self, unicode(text), font, font_size)
         self._shadow_text.top = 1
         self._shadow_text.color = (0, 0, 0, 0.6)
     LUIInitialState.init(self, kwargs)
Esempio n. 17
0
    def __init__(self, innerPadding=5, scrollable=False, style=Raised, **kwargs):
        """ Creates a new frame with the given options and style. If scrollable 
        is True, the contents of the frame will scroll if they don't fit into 
        the frame height. innerPadding only has effect if scrollable is True. 
        You can call fit_to_children() to make the frame fit automatically to 
        it's contents."""
        LUIObject.__init__(self)

        # Each *style* has a different border size (size of the shadow). The
        # border size shouldn't get calculated to the actual framesize, so we
        # are determining it first and then substracting it.
        # TODO: We could do this automatically, determined by the sprite size
        # probably?
        self.borderSize = 0
        self.padding = 10
        self.solid = True
        prefix = ""

        if style == LUIFrame.Raised:
            self.borderSize = 33
            prefix = "Frame_"
        elif style == LUIFrame.Sunken:
            self.borderSize = 5
            prefix = "SunkenFrame_"
        else:
            print "Unkown UIFrame style:", style

        self.layout = LUICornerLayout(parent=self, image_prefix=prefix)
        LUIInitialState.init(self, kwargs)

        self.effectivePadding = self.padding_top + self.borderSize
        self.scrollable = scrollable
        self.layout.margin = -self.effectivePadding

        # TODO: Scrollable
        # if self.scrollable:
        self.content = LUIObject(self)
Esempio n. 18
0
    def __init__(self,
                 width=200,
                 options=None,
                 selected_option=None,
                 **kwargs):
        """ Constructs a new selectbox with a given width """
        LUIObject.__init__(self, x=0, y=0, w=width + 4, solid=True)
        LUIInitialState.init(self, kwargs)

        # The selectbox has a small border, to correct this we move it
        self.margin.left = -2

        self._bg_layout = LUIHorizontalStretchedLayout(parent=self,
                                                       prefix="Selectbox",
                                                       width="100%")

        self._label_container = LUIObject(self, x=10, y=0)
        self._label_container.set_size("100%", "100%")
        self._label_container.clip_bounds = (0, 0, 0, 0)
        self._label = LUILabel(parent=self._label_container,
                               text=u"Select an option ..")
        self._label.center_vertical = True

        self._drop_menu = LUISelectdrop(parent=self, width=width)
        self._drop_menu.top = self._bg_layout._sprite_right.height - 7
        self._drop_menu.topmost = True

        self._drop_open = False
        self._drop_menu.hide()

        self._options = []
        self._current_option_id = None

        if options is not None:
            self._options = options

        self._select_option(selected_option)
Esempio n. 19
0
    def __init__(self, parent, width=200):
        LUIObject.__init__(self, x=0, y=0, w=width, h=1, solid=True)

        self._layout = LUICornerLayout(parent=self,
                                       image_prefix="Selectdrop_",
                                       width=width + 10,
                                       height=100)
        self._layout.margin.left = -3

        self._opener = LUISprite(self, "SelectboxOpen_Right", "skin")
        self._opener.right = -4
        self._opener.top = -25
        self._opener.z_offset = 3

        self._container = LUIObject(self._layout, 0, 0, 0, 0)
        self._container.width = self.width
        self._container.clip_bounds = (0, 0, 0, 0)
        self._container.left = 5
        self._container.solid = True
        self._container.bind("mousedown", lambda *args: self.request_focus())

        self._selectbox = parent
        self._option_focus = False
        self.parent = self._selectbox
Esempio n. 20
0
    def _render_options(self, options):
        """ Internal method to update the options """
        num_visible_options = min(4, len(options))
        offset_top = 6
        self._layout.height = num_visible_options * 30 + offset_top + 11
        self._container.height = num_visible_options * 30 + offset_top + 1
        self._container.remove_all_children()

        current_y = offset_top
        for opt_id, opt_val in options:
            opt_container = LUIObject(self._container,
                                      x=0,
                                      y=current_y,
                                      w=self._container.width - 30,
                                      h=30)

            opt_bg = LUISprite(opt_container, "blank", "skin")
            opt_bg.width = self._container.width
            opt_bg.height = opt_container.height
            opt_bg.color = (0, 0, 0, 0)
            opt_bg.bind("mouseover", self._on_opt_over)
            opt_bg.bind("mouseout", self._on_opt_out)
            opt_bg.bind("mousedown", lambda *args: self.request_focus())
            opt_bg.bind("click", partial(self._on_opt_click, opt_id))
            opt_bg.solid = True

            opt_label = LUILabel(parent=opt_container, text=unicode(opt_val))
            opt_label.top = 8
            opt_label.left = 8

            if opt_id == self._selectbox.selected_option:
                opt_label.color = (0.6, 0.9, 0.4, 1.0)

            divider = LUISprite(opt_container, "SelectdropDivider", "skin")
            divider.top = 30 - divider.height / 2
            divider.width = self._container.width

            current_y += 30
Esempio n. 21
0
 def fit_height_to_children(self):
     """ Resizes the frame vertically to fit its contents """
     self.layout.size = 0, 0
     LUIObject.fit_height_to_children(self)
Esempio n. 22
0
 def fit_to_children(self):
     """ Resizes the frame so it exactly fits its contents """
     self.layout.size = 0, 0
     LUIObject.fit_to_children(self)
Esempio n. 23
0
class LUISelectbox(LUIObject):
    """ Selectbox widget, showing several options whereas the user can select
    only one. """
    def __init__(self,
                 width=200,
                 options=None,
                 selected_option=None,
                 **kwargs):
        """ Constructs a new selectbox with a given width """
        LUIObject.__init__(self, x=0, y=0, w=width + 4, solid=True)
        LUIInitialState.init(self, kwargs)

        # The selectbox has a small border, to correct this we move it
        self.margin.left = -2

        self._bg_layout = LUIHorizontalStretchedLayout(parent=self,
                                                       prefix="Selectbox",
                                                       width="100%")

        self._label_container = LUIObject(self, x=10, y=0)
        self._label_container.set_size("100%", "100%")
        self._label_container.clip_bounds = (0, 0, 0, 0)
        self._label = LUILabel(parent=self._label_container,
                               text=u"Select an option ..")
        self._label.center_vertical = True

        self._drop_menu = LUISelectdrop(parent=self, width=width)
        self._drop_menu.top = self._bg_layout._sprite_right.height - 7
        self._drop_menu.topmost = True

        self._drop_open = False
        self._drop_menu.hide()

        self._options = []
        self._current_option_id = None

        if options is not None:
            self._options = options

        self._select_option(selected_option)

    def get_selected_option(self):
        """ Returns the selected option """
        return self._current_option_id

    def set_selected_option(self, option_id):
        """ Sets the selected option """
        raise NotImplementedError()

    selected_option = property(get_selected_option, set_selected_option)

    def _render_options(self):
        """ Internal method to render all available options """
        self._drop_menu._render_options(self._options)

    def get_options(self):
        """ Returns the list of options """
        return self._options

    def set_options(self, options):
        """ Sets the list of options, options should be a list containing entries
        whereas each entry is a tuple in the format (option_id, option_label).
        The option ID can be an arbitrary object, and will not get modified. """
        self._options = options
        self._current_option_id = None
        self._render_options()

    options = property(get_options, set_options)

    def _select_option(self, opt_id):
        """ Internal method to select an option """
        self._label.alpha = 1.0
        for elem_opt_id, opt_val in self._options:
            if opt_id == elem_opt_id:
                self._label.text = opt_val
                self._current_option_id = opt_id
                return
        self._label.alpha = 0.3

    # def on_mouseover(self, event):
    #     """ Internal handle when the select-knob was hovered """
    #     self._bg_layout.color = (0.9,0.9,0.9,1.0)

    # def on_mouseout(self, event):
    #     """ Internal handle when the select-knob was no longer hovered """
    #     self._bg_layout.color = (1,1,1,1.0)

    def on_click(self, event):
        """ On-Click handler """
        self.request_focus()
        if self._drop_open:
            self._close_drop()
        else:
            self._open_drop()

    def on_mousedown(self, event):
        """ Mousedown handler """
        self._bg_layout.alpha = 0.9

    def on_mouseup(self, event):
        """ Mouseup handler """
        self._bg_layout.alpha = 1

    def on_blur(self, event):
        """ Internal handler when the selectbox lost focus """
        if not self._drop_menu.focused:
            self._close_drop()

    def _open_drop(self):
        """ Internal method to show the dropdown menu """
        if not self._drop_open:
            self._render_options()
            self._drop_menu.show()
            self.request_focus()
            self._drop_open = True

    def _close_drop(self):
        """ Internal method to close the dropdown menu """
        if self._drop_open:
            self._drop_menu.hide()
            self._drop_open = False

    def _on_option_selected(self, opt_id):
        """ Internal method when an option got selected """
        self._select_option(opt_id)
        self._close_drop()
Esempio n. 24
0
 def __init__(self, **kwargs):
     """ Creates a new formatted label. """
     LUIObject.__init__(self)
     LUIInitialState.init(self, kwargs)
     self.currentLeft = 0
     self.currentTop = 0
Esempio n. 25
0
class DemoFramework:
    """ This is a small helper class to setup common stuff for the demos """
    def __init__(self):
        """ Constructs the demo framework """

        if False:
            self._skin = LUIMetroSkin()
            base.win.set_clear_color(Vec4(1))
        else:
            self._skin = LUIDefaultSkin()
            base.win.set_clear_color(Vec4(0.1, 0.0, 0.0, 1))
        self._skin.load()

        # Construct the LUIRegion
        region = LUIRegion.make("LUI", base.win)
        handler = LUIInputHandler()
        base.mouseWatcher.attach_new_node(handler)
        region.set_input_handler(handler)

        self._root = region.root
        self._constructor_params = []

    def prepare_demo(self, demo_title=u"Some Demo"):

        # Background
        self._background = LUISprite(self._root, "res/DemoBackground.png")
        # Make the background solid and recieve events
        self._background.solid = True

        # Logo
        self._logo = LUISprite(self._root, "res/LUILogo.png")
        self._logo.top_left = 15, 20

        # Title
        self._title_label = LUILabel(parent=self._root,
                                     text=demo_title,
                                     font_size=40,
                                     font="header",
                                     pos=(120, 27))
        self._subtitle_label = LUILabel(parent=self._root,
                                        text="Widget Demo",
                                        font_size=14,
                                        font="default",
                                        pos=(121, 70),
                                        alpha=0.3)

        # Right bar

        self._right_bar = LUIVerticalLayout(parent=self._root)
        self._left_bar = LUIVerticalLayout(parent=self._root)
        self._right_bar.width = 350
        self._right_bar.pos = (410, 120)
        self._right_bar.spacing = 10
        self._left_bar.width = 350
        self._left_bar.pos = (20, 120)
        self._left_bar.spacing = 10

        # Public functions
        self._public_functions = LUIFrame(width=340, style=LUIFrame.FS_sunken)
        self._functions_label = LUILabel(text=U"Additional Public functions")
        self._functions_layout = LUIVerticalLayout(
            parent=self._public_functions)
        self._functions_layout.add(self._functions_label, 30)

        # Events
        self._events = LUIFrame(width=340, style=LUIFrame.FS_sunken)
        self._events_label = LUILabel(text=U"Additional Events")
        self._events_layout = LUIVerticalLayout(parent=self._events)
        self._events_layout.add(self._events_label, 30)

        # Actions
        self._actions = LUIFrame(width=340, style=LUIFrame.FS_sunken)
        self._actions_label = LUILabel(parent=self._actions,
                                       text=U"Demo-Actions")
        self._actions_select = LUISelectbox(parent=self._actions,
                                            width=225,
                                            top=30)
        self._actions_btn = LUIButton(parent=self._actions,
                                      right=0,
                                      top=30,
                                      text=u"Execute",
                                      template="ButtonGreen")
        self._actions_btn.bind("click", self._exec_action)

        # Properties
        self._properties = LUIFrame(width=340, style=LUIFrame.FS_sunken)
        self._properties_label = LUILabel(text=u"Additional Properties")
        self._properties_layout = LUIVerticalLayout(parent=self._properties)
        self._properties_layout.add(self._properties_label, 30)

        self._right_bar.add(self._actions)
        self._right_bar.add(self._public_functions)
        self._right_bar.add(self._properties)
        self._right_bar.add(self._events)

        # Widget
        self._widget_container = LUIFrame(width=360,
                                          height=250,
                                          style=LUIFrame.FS_sunken)
        self._widget_label = LUILabel(parent=self._widget_container,
                                      text=u"Widget Demo")
        self._left_bar.add(self._widget_container)

        # Source Code
        self._source_container = LUIFrame(width=360,
                                          height=190,
                                          style=LUIFrame.FS_sunken)
        self._source_label = LUILabel(parent=self._source_container,
                                      text=u"Default Constructor")
        self._copy_code_button = LUIButton(parent=self._source_container,
                                           text=u"Copy to Clipboard",
                                           template="ButtonGreen",
                                           bottom_right=(0, 0))
        self._source_content = LUIObject(self._source_container)
        self._source_content.top = 40
        self._left_bar.add(self._source_container)

        self._widget_node = LUIObject(self._widget_container, x=0, y=40)

    def _exec_action(self, event):
        selected = self._actions_select.get_selected_option()
        if selected is not None:
            selected()

    def set_actions(self, actions):
        opts = []

        for name, action in actions.items():
            opts.append((action, name))

        self._actions_select.set_options(opts)

    def add_public_function(self, name, parameters=None, return_type="void"):
        label = LUIFormattedLabel()
        label.add(text=return_type + " ",
                  color=(102 / 255.0, 217 / 255.0, 239 / 255.0))
        label.add(text=name + " ",
                  color=(166 / 255.0, 226 / 255.0, 46 / 255.0))

        label.add(text="( ", color=(0.9, 0.9, 0.9))

        if parameters is not None:
            for index, (pname, ptype) in enumerate(parameters):
                label.add(text=pname,
                          color=(255 / 255.0, 151 / 255.0, 31 / 255.0))
                label.add(text=" : ", color=(0.9, 0.9, 0.9))
                label.add(text=ptype,
                          color=(102 / 255.0, 217 / 255.0, 239 / 255.0))

                if index < len(parameters) - 1:
                    label.add(text=",", color=(0.9, 0.9, 0.9))
        label.add(text=" )", color=(0.9, 0.9, 0.9))
        self._functions_layout.add(label)
        self.update_layouts()

    def add_constructor_parameter(self, name, default):
        self._constructor_params.append((name, default))
        self.update_layouts()

    def add_event(self, event_name):
        label = LUILabel(text=event_name)
        label.color = (1, 1, 1, 0.5)
        self._events_layout.add(label)
        self.update_layouts()

    def add_property(self, property_name, property_type):
        label = LUIFormattedLabel()
        label.add(text=property_name,
                  color=(255 / 255.0, 151 / 255.0, 31 / 255.0))
        label.add(" : ", color=(0.9, 0.9, 0.9))
        label.add(text=property_type + " ",
                  color=(102 / 255.0, 217 / 255.0, 239 / 255.0))
        self._properties_layout.add(label)
        self.update_layouts()

    def update_layouts(self):
        pass

    def construct_sourcecode(self, classname):
        self._source_content.remove_all_children()
        label = LUIFormattedLabel(parent=self._source_content)
        label.add(text="element ", color=(0.9, 0.9, 0.9))
        label.add(text="= ", color=(249 / 255.0, 38 / 255.0, 114 / 255.0))
        label.add(text=classname, color=(166 / 255.0, 226 / 255.0, 46 / 255.0))
        label.add(text="(", color=(0.9, 0.9, 0.9))

        for index, (pname, pvalue) in enumerate(self._constructor_params):
            label.newline()
            label.add(text=" " * 15)
            label.add(text=pname, color=(255 / 255.0, 151 / 255.0, 31 / 255.0))
            label.add(text=" = ")
            label.add(text=pvalue,
                      color=(153 / 255.0, 129 / 255.0, 255 / 255.0))

            if index < len(self._constructor_params) - 1:
                label.add(text=",")

        label.add(text=")")

        copy_text = "element = " + classname + "("

        for index, (pname, pvalue) in enumerate(self._constructor_params):
            copy_text += pname + "=" + pvalue

            if index < len(self._constructor_params) - 1:
                copy_text += ", "
        copy_text += ")"

        def copy_code(event):
            # Copies the source code to clipboard
            from Tkinter import Tk
            r = Tk()
            r.withdraw()
            r.clipboard_clear()
            r.clipboard_append(copy_text)
            r.destroy()

        self._copy_code_button.bind("click", copy_code)

        # self._source_content.fit_height_to_children()
        # self._source_container.fit_height_to_children()
        self._source_container.height += 40

    def get_widget_node(self):
        return self._widget_node
Esempio n. 26
0
class LUIScrollableRegion(LUIObject):
    """ Scrollable region, reparent elements to the .content_node to make them
    scroll. """
    def __init__(self,
                 parent=None,
                 width=100,
                 height=100,
                 padding=10,
                 **kwargs):
        LUIObject.__init__(self)
        self.set_size(width, height)
        self._content_parent = LUIObject(self)
        self._content_parent.set_size("100%", "100%")
        self._content_parent.clip_bounds = (0, 0, 0, 0)

        self._content_clip = LUIObject(self._content_parent,
                                       x=padding,
                                       y=padding)
        self._content_clip.set_size("100%", "100%")

        self._content_scroller = LUIObject(self._content_clip)
        self._content_scroller.width = "100%"

        self._scrollbar = LUIObject(self, x=0, y=0, w=20)
        self._scrollbar.height = "100%"
        self._scrollbar.right = -10

        self._scrollbar_bg = LUISprite(self._scrollbar, "blank", "skin")
        self._scrollbar_bg.color = (1, 1, 1, 0.05)
        self._scrollbar_bg.set_size(3, "100%")
        self._scrollbar_bg.center_horizontal = True

        # Handle
        self._scrollbar_handle = LUIObject(self._scrollbar, x=5, y=0, w=10)
        self._scroll_handle_top = LUISprite(self._scrollbar_handle,
                                            "ScrollbarHandle_Top", "skin")
        self._scroll_handle_mid = LUISprite(self._scrollbar_handle,
                                            "ScrollbarHandle", "skin")
        self._scroll_handle_bottom = LUISprite(self._scrollbar_handle,
                                               "ScrollbarHandle_Bottom",
                                               "skin")

        self._scrollbar_handle.solid = True
        self._scrollbar.solid = True

        self._scrollbar_handle.bind("mousedown", self._start_scrolling)
        self._scrollbar_handle.bind("mouseup", self._stop_scrolling)
        self._scrollbar.bind("mousedown", self._on_bar_click)
        self._scrollbar.bind("mouseup", self._stop_scrolling)

        self._handle_dragging = False
        self._drag_start_y = 0

        self._scroll_top_position = 0
        self._content_height = 400

        scroll_shadow_width = self.width - 10

        # Scroll shadow
        self._scroll_shadow_top = LUIHorizontalStretchedLayout(
            parent=self, prefix="ScrollShadowTop", width="100%")
        self._scroll_shadow_bottom = LUIHorizontalStretchedLayout(
            parent=self, prefix="ScrollShadowBottom", width="100%")
        self._scroll_shadow_bottom.bottom = 0

        self._handle_height = 100

        if parent is not None:
            self.parent = parent

        LUIInitialState.init(self, kwargs)
        self.content_node = self._content_scroller
        taskMgr.doMethodLater(0.05, lambda task: self._update(),
                              "update_scrollbar")

    def _on_bar_click(self, event):
        """ Internal handler when the user clicks on the scroll bar """
        self._scroll_to_bar_pixels(event.coordinates.y -
                                   self._scrollbar.abs_pos.y -
                                   self._handle_height / 2.0)
        self._update()
        self._start_scrolling(event)

    def _start_scrolling(self, event):
        """ Internal method when we start scrolling """
        self.request_focus()
        if not self._handle_dragging:
            self._drag_start_y = event.coordinates.y
            self._handle_dragging = True

    def _stop_scrolling(self, event):
        """ Internal handler when we should stop scrolling """
        if self._handle_dragging:
            self._handle_dragging = False
            self.blur()

    def _scroll_to_bar_pixels(self, pixels):
        """ Internal method to convert from pixels to a relative position """
        offset = pixels * self._content_height / self.height
        self._scroll_top_position = offset
        self._scroll_top_position = max(
            0,
            min(self._content_height - self._content_clip.height,
                self._scroll_top_position))

    def on_tick(self, event):
        """ Internal on tick handler """
        if self._handle_dragging:
            scroll_abs_pos = self._scrollbar.abs_pos
            clamped_coord_y = max(
                scroll_abs_pos.y,
                min(scroll_abs_pos.y + self.height, event.coordinates.y))
            offset = clamped_coord_y - self._drag_start_y
            self._drag_start_y = clamped_coord_y
            self._scroll_to_bar_pixels(self._scroll_top_position /
                                       self._content_height * self.height +
                                       offset)
        self._update()

    def _set_handle_height(self, height):
        """ Internal method to set the scrollbar height """
        self._scroll_handle_mid.top = float(self._scroll_handle_top.height)

        self._scroll_handle_mid.height = max(
            0.0, height - self._scroll_handle_top.height -
            self._scroll_handle_bottom.height)
        self._scroll_handle_bottom.top = self._scroll_handle_mid.height + self._scroll_handle_mid.top
        self._handle_height = height

    def _update(self):
        """ Internal method to update the scroll bar """
        self._content_height = max(1, self._content_scroller.get_height() + 20)
        self._content_scroller.top = -self._scroll_top_position
        scrollbar_height = max(
            0.1, min(1.0, self._content_clip.height / self._content_height))
        scrollbar_height_px = scrollbar_height * self.height

        self._set_handle_height(scrollbar_height_px)
        self._scrollbar_handle.top = self._scroll_top_position / self._content_height * self.height

        top_alpha = max(0.0, min(1.0, self._scroll_top_position / 50.0))
        bottom_alpha = max(
            0.0,
            min(1.0, (self._content_height - self._scroll_top_position -
                      self._content_clip.height) / 50.0))
        self._scroll_shadow_top.color = (1, 1, 1, top_alpha)
        self._scroll_shadow_bottom.color = (1, 1, 1, bottom_alpha)

        if self._content_height <= self.height:
            self._scrollbar_handle.hide()
        else:
            self._scrollbar_handle.show()

    def on_element_added(self):
        taskMgr.doMethodLater(0.05, lambda task: self._update(),
                              "update_layout")

    def get_scroll_percentage(self):
        """ Returns the current scroll height in percentage from 0 to 1 """
        return self._scroll_top_position / max(
            1, self._content_height - self._content_clip.height)

    def set_scroll_percentage(self, percentage):
        """ Sets the scroll position in percentage, 0 means top and 1 means bottom """
        percentage = max(0.0, min(1.0, percentage))
        pixels = max(
            0.0, self._content_height - self._content_clip.height) * percentage
        self._scroll_top_position = pixels
        self._update()

    scroll_percentage = property(get_scroll_percentage, set_scroll_percentage)

    def scroll_to_bottom(self):
        """ Scrolls to the bottom of the frame """
        taskMgr.doMethodLater(0.07,
                              lambda task: self.set_scroll_percentage(1.0),
                              "scroll_to_bottom")

    def scroll_to_top(self):
        """ Scrolls to the top of the frame """
        taskMgr.doMethodLater(0.07,
                              lambda task: self.set_scroll_percentage(0.0),
                              "scroll_to_top")
Esempio n. 27
0
class LUISelectdrop(LUIObject):
    """ Internal class used by the selectbox, representing the dropdown menu """
    def __init__(self, parent, width=200):
        LUIObject.__init__(self, x=0, y=0, w=width, h=1, solid=True)

        self._layout = LUICornerLayout(parent=self,
                                       image_prefix="Selectdrop_",
                                       width=width + 10,
                                       height=100)
        self._layout.margin.left = -3

        self._opener = LUISprite(self, "SelectboxOpen_Right", "skin")
        self._opener.right = -4
        self._opener.top = -25
        self._opener.z_offset = 3

        self._container = LUIObject(self._layout, 0, 0, 0, 0)
        self._container.width = self.width
        self._container.clip_bounds = (0, 0, 0, 0)
        self._container.left = 5
        self._container.solid = True
        self._container.bind("mousedown", lambda *args: self.request_focus())

        self._selectbox = parent
        self._option_focus = False
        self.parent = self._selectbox

    def _on_opt_over(self, event):
        """ Inernal handler when an option got hovered """
        event.sender.color = (0, 0, 0, 0.1)

    def _on_opt_out(self, event):
        """ Inernal handler when an option got no longer hovered """
        event.sender.color = (0, 0, 0, 0)

    def _on_opt_click(self, opt_id, event):
        """ Internal handler when an option got clicked """
        self._selectbox._on_option_selected(opt_id)

    def _render_options(self, options):
        """ Internal method to update the options """
        num_visible_options = min(4, len(options))
        offset_top = 6
        self._layout.height = num_visible_options * 30 + offset_top + 11
        self._container.height = num_visible_options * 30 + offset_top + 1
        self._container.remove_all_children()

        current_y = offset_top
        for opt_id, opt_val in options:
            opt_container = LUIObject(self._container,
                                      x=0,
                                      y=current_y,
                                      w=self._container.width - 30,
                                      h=30)

            opt_bg = LUISprite(opt_container, "blank", "skin")
            opt_bg.width = self._container.width
            opt_bg.height = opt_container.height
            opt_bg.color = (0, 0, 0, 0)
            opt_bg.bind("mouseover", self._on_opt_over)
            opt_bg.bind("mouseout", self._on_opt_out)
            opt_bg.bind("mousedown", lambda *args: self.request_focus())
            opt_bg.bind("click", partial(self._on_opt_click, opt_id))
            opt_bg.solid = True

            opt_label = LUILabel(parent=opt_container, text=unicode(opt_val))
            opt_label.top = 8
            opt_label.left = 8

            if opt_id == self._selectbox.selected_option:
                opt_label.color = (0.6, 0.9, 0.4, 1.0)

            divider = LUISprite(opt_container, "SelectdropDivider", "skin")
            divider.top = 30 - divider.height / 2
            divider.width = self._container.width

            current_y += 30
Esempio n. 28
0
 def __init__(self, **kwargs):
     """ Creates a new formatted label. """
     LUIObject.__init__(self)
     LUIInitialState.init(self, kwargs)
     self._cursor = LVecBase2i(0)
     self._last_size = 14
Esempio n. 29
0
 def __init__(self, *args, **kwargs):
     _LUIObject.__init__(self, *args)
     LUIInitialState.init(self, kwargs)
Esempio n. 30
0
class UISelectdrop(LUIObject):

    def __init__(self, parent, width=200):
        LUIObject.__init__(self, x=0, y=0, w=width, h=1, solid=True)

        self.layout = LUICornerLayout(parent=self, image_prefix="Selectdrop_", width=width + 10, height=100)
        self.layout.margin_left = -3

        self.opener = LUISprite(self, "SelectboxOpen_Right", "skin")
        self.opener.right = -4
        self.opener.top = -25
        self.opener.z_offset = 3

        self.container = LUIObject(self.layout, 0, 0, 0, 0)
        self.container.width = self.width
        self.container.clip_bounds = (0,0,0,0)
        self.container.left = 5

        self.selectbox = parent
        self.parent = self.selectbox

    def _on_opt_over(self, event):
        event.sender.color = (0,0,0,0.1)

    def _on_opt_out(self, event):
        event.sender.color = (0,0,0,0)

    def _on_opt_click(self, optid, event):
        self.selectbox._on_option_selected(optid)

    def _render_options(self, options):
        visible = min(4, len(options))
        offsetTop = 6
        self.layout.height = visible * 30 + offsetTop + 11
        self.container.height = visible * 30 + offsetTop + 1
        self.layout.update_layout()
        self.container.remove_all_children()
        
        currentY = offsetTop
        for optId, optVal in options:
            optContainer = LUIObject(self.container, x=0, y=currentY, w=self.container.width - 30, h=30)

            optBg = LUISprite(optContainer, "blank", "skin")
            optBg.width = self.container.width
            optBg.height = optContainer.height
            optBg.color = (0,0,0,0)
            optBg.bind("mouseover", self._on_opt_over)
            optBg.bind("mouseout", self._on_opt_out)
            optBg.bind("click", partial(self._on_opt_click, optId))
            optBg.solid = True

            optLabel = LUILabel(parent=optContainer, text=unicode(optVal), shadow=True)
            optLabel.top = 5
            optLabel.left = 8

            if optId == self.selectbox.get_selected_option():
                optLabel.color = (0.6, 0.9, 0.4, 1.0)

            divider = LUISprite(optContainer, "SelectdropDivider", "skin")
            divider.top = 30 - divider.height / 2
            divider.width = self.container.width

            currentY += 30
Esempio n. 31
0
 def fit_width_to_children(self):
     """ Resizes the frame horizontally to fit its contents """
     self.layout.size = 0, 0
     LUIObject.fit_width_to_children(self)
Esempio n. 32
0
    def __init__(self,
                 parent=None,
                 filled=True,
                 min_value=0.0,
                 max_value=1.0,
                 width=100.0,
                 value=None,
                 **kwargs):
        """ Constructs a new slider. If filled is True, the part behind the knob
        will be solid """
        LUIObject.__init__(self, x=0, y=0, solid=True)
        self.set_width(width)
        self._knob = LUISprite(self, "SliderKnob", "skin")
        self._knob.z_offset = 2
        self._knob.solid = True

        # Construct the background
        self._slider_bg = LUIHorizontalStretchedLayout(parent=self,
                                                       prefix="SliderBg",
                                                       center_vertical=True,
                                                       width="100%",
                                                       margin=(-1, 0, 0, 0))

        self._filled = filled
        self._min_value = min_value
        self._max_value = max_value

        self._side_margin = self._knob.width / 4
        self._effective_width = self.width - 2 * self._side_margin

        if self._filled:
            self._slider_fill = LUIObject(self)
            self._fill_left = LUISprite(self._slider_fill, "SliderBgFill_Left",
                                        "skin")
            self._fill_mid = LUISprite(self._slider_fill, "SliderBgFill",
                                       "skin")
            self._fill_mid.left = self._fill_left.width
            self._slider_fill.z_offset = 1
            self._slider_fill.center_vertical = True

        if parent is not None:
            self.parent = parent

        # Handle various events
        self._knob.bind("mousedown", self._start_drag)
        self._knob.bind("mousemove", self._update_drag)
        self._knob.bind("mouseup", self._stop_drag)
        self._knob.bind("keydown", self._on_keydown)
        self._knob.bind("blur", self._stop_drag)
        self._knob.bind("keyrepeat", self._on_keydown)

        self._drag_start_pos = None
        self._dragging = False
        self._drag_start_val = 0
        self.current_val = 10

        # Set initial value
        if value is None:
            self.set_value((self._min_value + self._max_value) / 2.0)
        else:
            self.set_value(value)

        self._update_knob()

        LUIInitialState.init(self, kwargs)
Esempio n. 33
0
class DemoFramework:

    """ This is a small helper class to setup common stuff for the demos """

    def __init__(self):
        base.win.set_clear_color(Vec4(0, 0, 0, 1))
        self.skin = LUIDefaultSkin()
        self.skin.load()

        # Construct the LUIRegion
        region = LUIRegion.make("LUI", base.win)
        handler = LUIInputHandler()
        base.mouseWatcher.attach_new_node(handler)
        region.set_input_handler(handler)

        self.root = region.root()
        self.constructorParams = []

    def prepare_demo(self, demo_title=u"Some Demo"):

        # Background
        self.background = LUISprite(self.root, "res/DemoBackground.png")

        
        # Make the background solid and recieve events
        self.background.bind("click", lambda event: self.background.request_focus())
        self.background.solid = True

        # Logo
        self.logo = LUISprite(self.root, "res/LUILogo.png")
        self.logo.top = 15
        self.logo.left = 20

        # Title
        self.titleLabel = LUILabel(parent=self.root, text=demo_title, font_size=40, font="header")
        self.titleLabel.pos = (120, 20)
        self.subtitleLabel = LUILabel(parent=self.root, text="Widget Demo", font_size=14, font="default")
        self.subtitleLabel.pos = (121, 65)
        self.subtitleLabel.color = (1,1,1,0.5)

        # Right bar
        self.rightBar = LUIVerticalLayout(parent=self.root, width=350, spacing=20)
        self.rightBar.pos = (410, 120)

        # Constructor parameters
        # self.constructorParameters = LUIFrame(width=340, style=LUIFrame.Sunken)
        # self.constructorLabel = LUILabel(parent=self.constructorParameters, text=u"Additional Constructor Parameters")
        # self.constructorLayout = UIVerticalLayout(parent=self.constructorParameters, spacing=10, use_dividers=True)
        # self.constructorLayout.top = 30

        # Public functions
        self.publicFunctions = LUIFrame(width=340, style=LUIFrame.Sunken)
        self.functionsLabel = LUILabel(parent=self.publicFunctions, text=U"Additional Public functions")
        self.functionsLayout = LUIVerticalLayout(parent=self.publicFunctions,spacing=10, use_dividers=True)
        self.functionsLayout.top = 30

        # Events
        self.events = LUIFrame(width=340,style=LUIFrame.Sunken)
        self.eventsLabel = LUILabel(parent=self.events, text=U"Additional Events")
        self.eventsLayout = LUIVerticalLayout(parent=self.events, spacing=10, use_dividers=True)
        self.eventsLayout.top = 30

        # Actions
        self.actions = LUIFrame(width=340,style=LUIFrame.Sunken, height=80)
        self.actionsLabel = LUILabel(parent=self.actions, text=U"Demo-Actions")
        self.actionsSelect = LUISelectbox(parent=self.actions, width=245, top=30)
        self.actionsBtn = LUIButton(parent=self.actions, right=0, top=30, text=u"Execute", template="ButtonMagic")
        self.actionsBtn.bind("click", self._exec_action)

        self.rightBar.add_row(self.actions)
        # self.rightBar.add_row(self.constructorParameters)
        self.rightBar.add_row(self.publicFunctions)
        self.rightBar.add_row(self.events)

        # Widget
        self.widgetContainer = LUIFrame(parent=self.root, width=360, height=250, style=LUIFrame.Sunken)
        self.widgetLabel = LUILabel(parent=self.widgetContainer, text=u"Widget Demo")
        self.widgetContainer.left = 26
        self.widgetContainer.top = 120

        # Source Code
        self.sourceContainer = LUIFrame(parent=self.root, width=360, height=200, style=LUIFrame.Sunken)
        self.sourceLabel = LUILabel(parent=self.sourceContainer, text=u"Default Constructor")
        self.copyCodeButton = LUIButton(parent=self.sourceContainer, 
                text=u"Copy to Clipboard", template="ButtonMagic", 
                right=-5, bottom=-5)
        self.sourceContainer.left = 26
        self.sourceContainer.top = 390
        self.sourceContent = LUIObject(self.sourceContainer)
        self.sourceContent.top = 40


        self.widgetNode = LUIObject(self.widgetContainer, x=0, y=40)


    def _exec_action(self, event):
        selected = self.actionsSelect.get_selected_option()
        if selected is not None:
            selected()

    def set_actions(self, actions):
        opts = []

        for name, action in actions.items():
            opts.append((action, name))

        self.actionsSelect.set_options(opts)

    def add_public_function(self, name, parameters=None, return_type="void"):
        label = LUIFormattedLabel()
        label.add_text(text=return_type + " ", color = (102/255.0, 217/255.0, 239/255.0))
        label.add_text(text=name + " ", color = (166/255.0, 226/255.0, 46/255.0))

        label.add_text(text="( ", color=(0.9,0.9,0.9))

        if parameters is not None:
            for index, (pname, ptype) in enumerate(parameters):
                label.add_text(text=pname, color=(255/255.0, 151/255.0, 31/255.0))
                label.add_text(text=" : ", color=(0.9,0.9,0.9))
                label.add_text(text=ptype, color=(102/255.0, 217/255.0, 239/255.0))

                if index < len(parameters) - 1:
                    label.add_text(text=",", color=(0.9,0.9,0.9))
        label.add_text(text=" )", color=(0.9,0.9,0.9))
        self.functionsLayout.add_row(label)
        self.update_layouts()

    def add_constructor_parameter(self, name, default):
        # label = UIFormattedLabel()
        # label.add_text(text=name, color=(255/255.0, 151/255.0, 31/255.0))
        # label.add_text(text=" = ", color=(249/255.0, 38/255.0, 114/255.0))
        # label.add_text(text=default, color=(153/255.0, 129/255.0, 255/255.0))
        # self.constructorLayout.add_row(label)
        self.constructorParams.append((name, default))
        self.update_layouts()

    def add_event(self, event_name):
        label = LUILabel(text=event_name)
        label.color = (1,1,1,0.5)
        self.eventsLayout.add_row(label)
        self.update_layouts()

    def update_layouts(self):
        self.publicFunctions.fit_height_to_children()
        # self.constructorParameters.fit_height_to_children()
        self.events.fit_height_to_children()
        self.rightBar.update()

    def construct_sourcecode(self, classname):
        self.sourceContent.remove_all_children()
        label = LUIFormattedLabel(parent=self.sourceContent)
        label.add_text(text="element ", color=(0.9,0.9,0.9))
        label.add_text(text="= ", color=(249/255.0, 38/255.0, 114/255.0))
        label.add_text(text=classname, color=(166/255.0, 226/255.0, 46/255.0))
        label.add_text(text="(", color=(0.9,0.9,0.9))

        for index, (pname, pvalue) in enumerate(self.constructorParams):
            label.br()
            label.add_text(text=" " * 15)
            label.add_text(text=pname, color=(255/255.0, 151/255.0, 31/255.0))
            label.add_text(text=" = ")
            label.add_text(text=pvalue, color=(153/255.0, 129/255.0, 255/255.0))

            if index < len(self.constructorParams) - 1:
                label.add_text(text=",")

        label.add_text(text=")")

        self.sourceContent.fit_height_to_children()
        self.sourceContainer.fit_height_to_children()
        self.sourceContainer.height += 40


    def get_widget_node(self):
        return self.widgetNode
Esempio n. 34
0
    def __init__(self,
                 parent=None,
                 width=100,
                 height=100,
                 padding=10,
                 **kwargs):
        LUIObject.__init__(self)
        self.set_size(width, height)
        self._content_parent = LUIObject(self)
        self._content_parent.set_size("100%", "100%")
        self._content_parent.clip_bounds = (0, 0, 0, 0)

        self._content_clip = LUIObject(self._content_parent,
                                       x=padding,
                                       y=padding)
        self._content_clip.set_size("100%", "100%")

        self._content_scroller = LUIObject(self._content_clip)
        self._content_scroller.width = "100%"

        self._scrollbar = LUIObject(self, x=0, y=0, w=20)
        self._scrollbar.height = "100%"
        self._scrollbar.right = -10

        self._scrollbar_bg = LUISprite(self._scrollbar, "blank", "skin")
        self._scrollbar_bg.color = (1, 1, 1, 0.05)
        self._scrollbar_bg.set_size(3, "100%")
        self._scrollbar_bg.center_horizontal = True

        # Handle
        self._scrollbar_handle = LUIObject(self._scrollbar, x=5, y=0, w=10)
        self._scroll_handle_top = LUISprite(self._scrollbar_handle,
                                            "ScrollbarHandle_Top", "skin")
        self._scroll_handle_mid = LUISprite(self._scrollbar_handle,
                                            "ScrollbarHandle", "skin")
        self._scroll_handle_bottom = LUISprite(self._scrollbar_handle,
                                               "ScrollbarHandle_Bottom",
                                               "skin")

        self._scrollbar_handle.solid = True
        self._scrollbar.solid = True

        self._scrollbar_handle.bind("mousedown", self._start_scrolling)
        self._scrollbar_handle.bind("mouseup", self._stop_scrolling)
        self._scrollbar.bind("mousedown", self._on_bar_click)
        self._scrollbar.bind("mouseup", self._stop_scrolling)

        self._handle_dragging = False
        self._drag_start_y = 0

        self._scroll_top_position = 0
        self._content_height = 400

        scroll_shadow_width = self.width - 10

        # Scroll shadow
        self._scroll_shadow_top = LUIHorizontalStretchedLayout(
            parent=self, prefix="ScrollShadowTop", width="100%")
        self._scroll_shadow_bottom = LUIHorizontalStretchedLayout(
            parent=self, prefix="ScrollShadowBottom", width="100%")
        self._scroll_shadow_bottom.bottom = 0

        self._handle_height = 100

        if parent is not None:
            self.parent = parent

        LUIInitialState.init(self, kwargs)
        self.content_node = self._content_scroller
        taskMgr.doMethodLater(0.05, lambda task: self._update(),
                              "update_scrollbar")
Esempio n. 35
0
    def prepare_demo(self, demo_title=u"Some Demo"):

        # Background
        self.background = LUISprite(self.root, "res/DemoBackground.png")

        
        # Make the background solid and recieve events
        self.background.bind("click", lambda event: self.background.request_focus())
        self.background.solid = True

        # Logo
        self.logo = LUISprite(self.root, "res/LUILogo.png")
        self.logo.top = 15
        self.logo.left = 20

        # Title
        self.titleLabel = LUILabel(parent=self.root, text=demo_title, font_size=40, font="header")
        self.titleLabel.pos = (120, 20)
        self.subtitleLabel = LUILabel(parent=self.root, text="Widget Demo", font_size=14, font="default")
        self.subtitleLabel.pos = (121, 65)
        self.subtitleLabel.color = (1,1,1,0.5)

        # Right bar
        self.rightBar = LUIVerticalLayout(parent=self.root, width=350, spacing=20)
        self.rightBar.pos = (410, 120)

        # Constructor parameters
        # self.constructorParameters = LUIFrame(width=340, style=LUIFrame.Sunken)
        # self.constructorLabel = LUILabel(parent=self.constructorParameters, text=u"Additional Constructor Parameters")
        # self.constructorLayout = UIVerticalLayout(parent=self.constructorParameters, spacing=10, use_dividers=True)
        # self.constructorLayout.top = 30

        # Public functions
        self.publicFunctions = LUIFrame(width=340, style=LUIFrame.Sunken)
        self.functionsLabel = LUILabel(parent=self.publicFunctions, text=U"Additional Public functions")
        self.functionsLayout = LUIVerticalLayout(parent=self.publicFunctions,spacing=10, use_dividers=True)
        self.functionsLayout.top = 30

        # Events
        self.events = LUIFrame(width=340,style=LUIFrame.Sunken)
        self.eventsLabel = LUILabel(parent=self.events, text=U"Additional Events")
        self.eventsLayout = LUIVerticalLayout(parent=self.events, spacing=10, use_dividers=True)
        self.eventsLayout.top = 30

        # Actions
        self.actions = LUIFrame(width=340,style=LUIFrame.Sunken, height=80)
        self.actionsLabel = LUILabel(parent=self.actions, text=U"Demo-Actions")
        self.actionsSelect = LUISelectbox(parent=self.actions, width=245, top=30)
        self.actionsBtn = LUIButton(parent=self.actions, right=0, top=30, text=u"Execute", template="ButtonMagic")
        self.actionsBtn.bind("click", self._exec_action)

        self.rightBar.add_row(self.actions)
        # self.rightBar.add_row(self.constructorParameters)
        self.rightBar.add_row(self.publicFunctions)
        self.rightBar.add_row(self.events)

        # Widget
        self.widgetContainer = LUIFrame(parent=self.root, width=360, height=250, style=LUIFrame.Sunken)
        self.widgetLabel = LUILabel(parent=self.widgetContainer, text=u"Widget Demo")
        self.widgetContainer.left = 26
        self.widgetContainer.top = 120

        # Source Code
        self.sourceContainer = LUIFrame(parent=self.root, width=360, height=200, style=LUIFrame.Sunken)
        self.sourceLabel = LUILabel(parent=self.sourceContainer, text=u"Default Constructor")
        self.copyCodeButton = LUIButton(parent=self.sourceContainer, 
                text=u"Copy to Clipboard", template="ButtonMagic", 
                right=-5, bottom=-5)
        self.sourceContainer.left = 26
        self.sourceContainer.top = 390
        self.sourceContent = LUIObject(self.sourceContainer)
        self.sourceContent.top = 40


        self.widgetNode = LUIObject(self.widgetContainer, x=0, y=40)
Esempio n. 36
0
    def prepare_demo(self, demo_title=u"Some Demo"):

        # Background
        self._background = LUISprite(self._root, "res/DemoBackground.png")
        # Make the background solid and recieve events
        self._background.solid = True

        # Logo
        self._logo = LUISprite(self._root, "res/LUILogo.png")
        self._logo.top_left = 15, 20

        # Title
        self._title_label = LUILabel(parent=self._root,
                                     text=demo_title,
                                     font_size=40,
                                     font="header",
                                     pos=(120, 27))
        self._subtitle_label = LUILabel(parent=self._root,
                                        text="Widget Demo",
                                        font_size=14,
                                        font="default",
                                        pos=(121, 70),
                                        alpha=0.3)

        # Right bar

        self._right_bar = LUIVerticalLayout(parent=self._root)
        self._left_bar = LUIVerticalLayout(parent=self._root)
        self._right_bar.width = 350
        self._right_bar.pos = (410, 120)
        self._right_bar.spacing = 10
        self._left_bar.width = 350
        self._left_bar.pos = (20, 120)
        self._left_bar.spacing = 10

        # Public functions
        self._public_functions = LUIFrame(width=340, style=LUIFrame.FS_sunken)
        self._functions_label = LUILabel(text=U"Additional Public functions")
        self._functions_layout = LUIVerticalLayout(
            parent=self._public_functions)
        self._functions_layout.add(self._functions_label, 30)

        # Events
        self._events = LUIFrame(width=340, style=LUIFrame.FS_sunken)
        self._events_label = LUILabel(text=U"Additional Events")
        self._events_layout = LUIVerticalLayout(parent=self._events)
        self._events_layout.add(self._events_label, 30)

        # Actions
        self._actions = LUIFrame(width=340, style=LUIFrame.FS_sunken)
        self._actions_label = LUILabel(parent=self._actions,
                                       text=U"Demo-Actions")
        self._actions_select = LUISelectbox(parent=self._actions,
                                            width=225,
                                            top=30)
        self._actions_btn = LUIButton(parent=self._actions,
                                      right=0,
                                      top=30,
                                      text=u"Execute",
                                      template="ButtonGreen")
        self._actions_btn.bind("click", self._exec_action)

        # Properties
        self._properties = LUIFrame(width=340, style=LUIFrame.FS_sunken)
        self._properties_label = LUILabel(text=u"Additional Properties")
        self._properties_layout = LUIVerticalLayout(parent=self._properties)
        self._properties_layout.add(self._properties_label, 30)

        self._right_bar.add(self._actions)
        self._right_bar.add(self._public_functions)
        self._right_bar.add(self._properties)
        self._right_bar.add(self._events)

        # Widget
        self._widget_container = LUIFrame(width=360,
                                          height=250,
                                          style=LUIFrame.FS_sunken)
        self._widget_label = LUILabel(parent=self._widget_container,
                                      text=u"Widget Demo")
        self._left_bar.add(self._widget_container)

        # Source Code
        self._source_container = LUIFrame(width=360,
                                          height=190,
                                          style=LUIFrame.FS_sunken)
        self._source_label = LUILabel(parent=self._source_container,
                                      text=u"Default Constructor")
        self._copy_code_button = LUIButton(parent=self._source_container,
                                           text=u"Copy to Clipboard",
                                           template="ButtonGreen",
                                           bottom_right=(0, 0))
        self._source_content = LUIObject(self._source_container)
        self._source_content.top = 40
        self._left_bar.add(self._source_container)

        self._widget_node = LUIObject(self._widget_container, x=0, y=40)
Esempio n. 37
0
 def __init__(self, *args, **kwargs):
     _LUIObject.__init__(self, *args)
     LUIInitialState.init(self, kwargs)