Exemplo n.º 1
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, "*")
Exemplo n.º 2
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)
Exemplo n.º 3
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
Exemplo n.º 4
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)
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._container.solid = True
        self._container.bind("mousedown", lambda *args: self.request_focus())

        self._selectbox = parent
        self._option_focus = False
        self.parent = self._selectbox
Exemplo n.º 6
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)
Exemplo n.º 7
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")
Exemplo n.º 8
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)