コード例 #1
0
  def widgets(self, helper):
    """ Create widgets """

    helper.scope(globals())

    # Common edges
    LEFT_OFFSET = edge(LEFT, 10, MM)

    # Define bounds
    BUTTON_PANEL_HEADER = bound(
      LEFT_OFFSET,
      edge(TOP, -20, MM),
      edge(LEFT_OFFSET, 50, PERCENT),
      edge(TOP, -10, MM)
    )
    CENTRAL_PANEL = bound(
      edge(CENTER.X, -20, MM),
      edge(CENTER.Y, -10, MM),
      edge(CENTER.X, 20, MM),
      edge(CENTER.Y, 10, MM)
    )
    BUTTON_SET = bound(
      LEFT_OFFSET,
      edge(BOTTOM, 20, MM),
      edge(CENTER.X, -40, MM),
      edge(TOP, -25, MM)
    )

    # Widgets
    self.MAIN_BUTTON = widget(theme.button(), BUTTON_PANEL_HEADER, text="Click me", color=(255, 0, 0, 255))
    self.OTHER_BUTTON = widget(theme.button(), CENTRAL_PANEL, text="Click Me", color=(255, 255, 0, 255), font_size=6)
    self.BUTTONS = widget(nwidget.VList(), BUTTON_SET)
    for i in range(5):
      b = theme.button()
      b.text = "Button : " + str(i)
      self.BUTTONS.add(b)

    # Set event codes for app to handle
    self.MAIN_BUTTON.on_click = "MAIN_BUTTON_CLICK"
    self.OTHER_BUTTON.on_click = "DEBUG_CLICK"
コード例 #2
0
    def widgets(self, helper):
        """ Create widgets """

        helper.scope(globals())

        # Header
        # Notice how this uses assets *inside* the ui folder for ui things.
        widget(
            nwidget.Image(),
            width=(50, MM),
            height=(20, MM),
            x=(CENTER.X, 0, MM),
            y=(CENTER.Y, 35, MM),
            texture=assets.resolve("assets", "title.png"),
            uv=(0, 0.6, 1, 0.6, 1, 1, 0, 1),
        )

        # Menu
        menu = widget(nwidget.VList(),
                      width=(40, MM),
                      height=(50, MM),
                      x=(CENTER.X, 0, MM),
                      y=(CENTER.Y, -5, MM),
                      padding=20)

        menu.add(
            widget(theme.button(),
                   keep=False,
                   text="Exit",
                   on_click="MENU_EXIT"))
        menu.add(
            widget(theme.button(),
                   keep=False,
                   text="Credits",
                   on_click="MENU_CREDITS"))
        menu.add(
            widget(theme.button(),
                   keep=False,
                   text="Play game",
                   on_click="MENU_PLAY_GAME"))
コード例 #3
0
 def setup(self):
     return nwidget.VList()
コード例 #4
0
        def runner():

            # Global setup
            self.__widgets = []
            self.enable_blending()
            a = nwidget.Assets()

            # Text button select with both buttons
            b_next = nwidget.Button(text="next", on_click="S_NEXT_1")
            b_prev = nwidget.Button(text="prev", on_click="S_NEXT_2")
            items = nwidget.HList()
            marker = nwidget.Block(solid=False, color=(255, 0, 0, 255))

            b_prev.bounds(10, 10, 50, 50)
            items.bounds(50, 10, 200, 50)
            b_next.bounds(200, 10, 240, 50)

            selector = nwidget.Select(next=b_next,
                                      prev=b_prev,
                                      marker=marker,
                                      list=items)
            selector.on_change = "SELECTED"

            for i in range(10):
                b = nwidget.Block(solid=True, color=(0, 0, 25 * i, 255))
                selector.add(b, "ITEM_" + str(i), -1, 10 * i)
            selector.index = 3

            selector.register(self._window)
            b_prev.register(self._window)
            b_next.register(self._window)
            self.__widgets.append(selector)

            def scb1(_, widget):
                print("Currently selected item is: %s" % widget.selected)

            nwidget.listen("SELECTED", scb1)

            # Vertical list with image buttons, marker, and restricted display count
            b_next = nwidget.ImageButton(on_click="SELECT_2")
            b_next.from_row(a.resolve("data", "arrows.png"), (0, 0, 1, 0.25))
            marker = nwidget.Block(solid=False, color=(255, 255, 255, 255))
            items = nwidget.VList(padding=5)

            items.bounds(10, 100, 60, 340)
            b_next.bounds(10, 340, 60, 390)

            selector = nwidget.Select(next=b_next, list=items, marker=marker)

            for i in range(10):
                img = nwidget.Image(texture=a.resolve("data", "select1.png"))
                low = 0.1 * i
                high = 0.1 * (i + 1)
                img.uv = (low, low, low, high, high, high, high, low)
                selector.add(img, "ITEM_" + str(i))

            selector.index = 0
            selector.display_count = 5

            b_next.register(self._window)
            selector.register(self._window)
            self.__widgets.append(selector)

            # Image buttons, active item enabled only
            # The marker here is a semi-transparent image overlay
            b_next = nwidget.ImageButton(on_click="SELECT_3_NEXT")
            b_next.from_row(a.resolve("data", "arrows.png"), (0, 0.75, 1, 1))
            b_prev = nwidget.ImageButton(
                on_click="SELECT_3_PREV")  # <-- different event code
            b_prev.from_row(a.resolve("data", "arrows.png"), (0, 0.25, 1, 0.5))
            marker = nwidget.Image(texture=a.resolve("data", "marker1.png"))
            items = nwidget.HList(padding=5)

            items.bounds(150, 200, 350, 250)
            b_prev.bounds(100, 200, 150, 250)
            b_next.bounds(350, 200, 400, 250)

            selector = nwidget.Select(next=b_next,
                                      list=items,
                                      marker=marker,
                                      prev=b_prev)
            selector.display_count = 5
            selector.index = 2
            selector.display_start = 0
            selector.on_change = "SELECT_3_UPDATE"

            for i in range(10):
                b = nwidget.ImageButton()
                b.texture = a.resolve("data", "select2.png")
                b.texture_over = a.resolve("data", "select2.png")
                b.texture_down = a.resolve("data", "select2.png")
                b.texture_disabled = a.resolve("data", "select2.png")
                xo = i * 0.1
                xe = xo + 0.1
                b.uv = (xo, 0.3, xe, 0.3, xe, 0.4, xo, 0.4)
                b.uv_over = (xo, 0.2, xe, 0.2, xe, 0.3, xo, 0.3)
                b.uv_down = (xo, 0.1, xe, 0.1, xe, 0.2, xo, 0.2)
                b.uv_disabled = (xo, 0, xe, 0, xe, 0.1, xo, 0.1)
                b.register(self._window)
                if i != selector.index:
                    b.disabled = True
                selector.add(b, "BUTTON_" + str(i))

            def scb3(_, w):
                for i in range(10):
                    wx = w.item(i)
                    wx.disabled = not (i == w.index)
                    pass

            nwidget.listen("SELECT_3_UPDATE", scb3)

            b_next.register(self._window)
            b_prev.register(self._window)
            selector.register(self._window)
            self.__widgets.append(selector)
コード例 #5
0
        def runner():
            a, i = self.setup()
            a.notNull(i, "Failed to create test instance")

            self.__widgets = []

            panel = i.panel()
            panel.bounds(10, 10, 150, 390)
            self.__widgets.append(panel)

            panel = i.panel()
            panel.bounds(160, 10, 390, 390)
            self.__widgets.append(panel)

            panel = i.panel()
            panel.bounds(410, 10, 790, 390)
            self.__widgets.append(panel)

            button = i.button()
            button.bounds(20, 315, 140, 345)
            button.text = "Button Two"
            button.disabled = True
            ref = button
            self.__widgets.append(
                button
            )  # <--- Notice the theme transparently invokes register() internally

            button = i.button()
            button.bounds(20, 350, 140, 380)
            button.text = "Enable"
            button.on_click = "BUTTON_SWAP_STATE"
            self.__widgets.append(button)

            boxes = nwidget.VList(padding=10)
            boxes.bounds(40, 190, 160, 300)
            boxes.add(i.checkbox(), 10, 10)
            boxes.add(i.checkbox(), 20, 20)
            boxes.add(i.checkbox(), 20, 20)
            boxes.add(i.checkbox(), 30, 30)
            boxes.item(2).disabled = True
            self.__widgets.append(boxes)

            def callback(code, button):
                if button.text == "Enable":
                    ref.disabled = False
                    boxes.item(2).disabled = False
                    button.text = "Disable"
                else:
                    ref.disabled = True
                    boxes.item(2).disabled = True
                    button.text = "Enable"

            nwidget.listen("BUTTON_SWAP_STATE", callback)

            bars = nwidget.VList(padding=5)
            bars.bounds(20, 80, 140, 180)
            bars.add(i.progress())
            bars.add(i.progress())
            bars.add(i.progress())
            bars.add(i.progress())
            bars.add(i.progress())
            bars.item(0).value = 0
            bars.item(1).value = 0.25
            bars.item(2).value = 0.5
            bars.item(3).value = 0.75
            bars.item(4).value = 1
            self.__widgets.append(bars)

            display_box = i.subpanel()
            display_box.bounds(180, 100, 370, 250)
            self.__widgets.append(display_box)

            display = i.text()
            display.bounds(192, 100, 370, 239)
            display.text = ": Text goes here!\n: Press enter to see more!"
            display.keep = 8
            self.__widgets.append(display)

            arrows = nwidget.HList(padding=4)
            arrows.bounds(25, 40, 140, 65)
            self.__widgets.append(arrows)

            a1 = i.arrow_left()
            a1.on_click = "ARROW_CLICK"
            arrows.add(a1, width=25)

            a2 = i.arrow_right()
            a2.on_click = "ARROW_CLICK"
            arrows.add(a2, width=25)

            a3 = i.arrow_up()
            a3.on_click = "ARROW_CLICK"
            arrows.add(a3, width=25)

            a4 = i.arrow_down()
            a4.on_click = "ARROW_CLICK"
            arrows.add(a4, width=25)

            def disable_it(code, widget):
                widget.disabled = True

            nwidget.listen("ARROW_CLICK", disable_it)

            hint = i.hint()
            hint.bounds(180, 75, 370, 90)
            hint.text = "Type below and press enter to update text list"
            self.__widgets.append(hint)

            textbox = i.textbox()
            textbox.bounds(180, 30, 370, 70)
            textbox.text = "Type stuff here..."
            textbox.on_focus = "TB1_FOCUS"
            textbox.on_enter = "TB1_SUBMIT"
            textbox.limit = 20
            textbox.multiline = False
            self.__widgets.append(textbox)

            def clear_tb(_, widget):
                widget.text = ""

            def submit_tb(_, widget):
                display.append(": " + widget.text)
                widget.text = ""

            nwidget.listen("TB1_FOCUS", clear_tb)
            nwidget.listen("TB1_SUBMIT", submit_tb)

            header = i.header()
            header.text = "Light Theme Test"
            header.bounds(180, 330, 370, 390)
            self.__widgets.append(header)

            subheader = i.subheader()
            subheader.text = "subheading here"
            subheader.bounds(180, 300, 370, 370)
            self.__widgets.append(subheader)

            info = i.text()
            info.bounds(180, 250, 370, 320)
            info.text = "Bacon ipsum dolor sit amet turkey shoulder biltong leberkas corned beef turducken hamburger sirloin. Short loin"
            self.__widgets.append(info)

            header = i.header()
            header.text = "Options test"
            header.bounds(430, 330, 790, 390)
            self.__widgets.append(header)

            block = nwidget.VList(padding=10)
            block.bounds(430, 130, 760, 435)
            self.__widgets.append(block)

            label = i.label()
            label.text = "Value 43:"

            bar = i.progress()
            bar.value = 0.34

            item = nwidget.HList(padding=25)
            item.add(label, 150)
            item.add(bar, height=15)

            block.add(item, height=25)

            label = i.label()
            label.text = "Awesomenesss:"

            bar = i.progress()
            bar.value = 1.0

            item = nwidget.HList(padding=25)
            item.add(label, 150)
            item.add(bar, height=20)

            block.add(item, -1, 25)

            label = i.label()
            label.text = "Anonymous statistics:"

            box = i.checkbox()
            box.change()

            item = nwidget.HList(padding=25)
            item.add(label, 150)
            item.add(box, 20, 20)

            block.add(item, -1, 25)

            label = i.label()
            label.text = "Debug mode:"

            box = i.checkbox()

            item = nwidget.HList(padding=25)
            item.add(label, 150)
            item.add(box, 20, 20)

            block.add(item, -1, 25)

            label = i.label()
            label.text = "More ninjas:"

            box = i.checkbox()

            item = nwidget.HList(padding=25)
            item.add(label, 150)
            item.add(box, 20, 20)

            block.add(item, -1, 25)

            label = i.label()
            label.text = "Select resolution:"

            options = i.options({
                "LOW": "640 x 480",
                "MEDIUM": "800 x 600",
                "HIGH": "1024 x 768",
                "NORMAL": "1200 x 1600"
            })

            item = nwidget.HList(padding=25)
            item.add(label, 150)
            item.add(options, height=32)

            block.add(item, -1, 25)

            ok = i.accept()
            ok.on_click = "ARROW_CLICK"
            ok.bounds(720, 90, 752, 122)
            self.__widgets.append(ok)

            reject = i.reject()
            reject.on_click = "ARROW_CLICK"
            reject.bounds(755, 360, 771, 376)
            self.__widgets.append(reject)