Exemplo n.º 1
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()
Exemplo n.º 2
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()
Exemplo n.º 3
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
Exemplo n.º 4
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()
Exemplo n.º 5
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
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
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)
Exemplo n.º 12
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
Exemplo n.º 13
0
 def __init__(self, *args, **kwargs):
     _LUIObject.__init__(self, *args)
     LUIInitialState.init(self, kwargs)
Exemplo n.º 14
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
Exemplo n.º 15
0
 def __init__(self, **kwargs):
     """ Creates a new formatted label. """
     LUIObject.__init__(self)
     LUIInitialState.init(self, kwargs)
     self.currentLeft = 0
     self.currentTop = 0