Example #1
0
    def __init__(self):
        super(TestApp, self).__init__((800, 600), "NanoGUI Test", False)

        window = Window(self, "Canvas widget demo")
        window.set_position((15, 15))
        window.set_layout(GroupLayout())

        self.canvas = MyCanvas(window)
        self.canvas.set_background_color(Color(0.5, 0.5, 0.5, 1.0))
        self.canvas.set_size((400, 400))

        tools = Widget(window)
        tools.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 5))

        b0 = Button(tools, "Random Background")

        def cb0():
            self.canvas.set_background_color(
                Color(random.random(), random.random(), random.random(), 1.0))

        b0.set_callback(cb0)

        b1 = Button(tools, "Random Rotation")

        def cb1():
            self.canvas.rotation = random.random() * math.pi

        b1.set_callback(cb1)

        self.perform_layout()
Example #2
0
    def __init__(self, parent_window):
        position = (5, 35)
        super(FooWindow, self).__init__(parent_window, position)
        # Buttons
        Label(self.window, "Push buttons", "sans-bold")
        b = Button(self.window, "Plain button")

        def cb():
            print("pushed!")

        b.setCallback(cb)
        b = Button(self.window, "Styled", entypo.ICON_ROCKET)
        b.setBackgroundColor(Color(0, 0, 1.0, 0.1))
        b.setCallback(cb)
Example #3
0
    def __init__(self):
        super(TestApp, self).__init__((800, 600), "NanoGUI Test", False)

        window = Window(self, "GLCanvas Demo")
        window.setPosition((15, 15))
        window.setLayout(GroupLayout())

        self.canvas = MyGLCanvas(window)
        self.canvas.setBackgroundColor(Color(0.5, 0.5, 0.5, 1.0))
        self.canvas.setSize((400, 400))

        self.canvas.rotation = [0.25, 0.5, 0.33]

        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 5))

        b0 = Button(tools, "Random Color")
        def cb0():
            self.canvas.setBackgroundColor(Color(random.random(), random.random(), random.random(), 1.0))
        b0.setCallback(cb0)

        b1 = Button(tools, "Random Rotation")
        def cb1():
            self.canvas.rotation = [random.random(), random.random(), random.random()]
        b1.setCallback(cb1)

        self.performLayout()
Example #4
0
    def MainWindow(self, show=True):
        '''
		Main window.
		'''
        self.icons = nanogui.loadImageDirectory(self.screen.nvgContext(),
                                                "icons")

        self.main_wnd = Widget(self.screen)
        layout = GroupLayout()
        layout.setMargin(3)
        self.main_wnd.setLayout(layout)
        self.main_wnd.setFixedSize((self.main_width, self.main_height))

        b = Button(self.main_wnd, "Export")
        b.setFixedHeight(25)
        b.setCallback(ps_act.ExportFiles)

        # Slots.
        slots = Widget(self.main_wnd)
        slots.setPosition((20, 60))
        slots.setFixedHeight(345)

        self.DrawSlots(slots)

        # Tools.
        self.Tools(self.main_wnd)

        # Final draw.
        self.screen.setBackground(backgr_color)
        self.screen.drawAll()
        self.screen.drawContents()
        self.screen.performLayout()
Example #5
0
    def __init__(self, parent, name, sound, color):
        super(SoundLayer, self).__init__(parent)
        print('[+] SoundLayer::__init__')
        self.setLayout(GridLayout(resolution=4))
        self.sound = sound
        self.cp = Button(self, '')
        self.color = color
        self.cp.setBackgroundColor(color)
        label = Label(self, name + ':', 'sans-bold')
        label.setFixedSize((70, 20))
        self.cp.setFixedSize((20, 40))
        self.solomute = Widget(self)
        self.solomute.setLayout(GridLayout(resolution=3))
        self._parent = parent
        self._focused = False

        self.issolo = False
        self.ismute = False
        self.selected_color = Color(0x3e, 0x3e, 0x3f, 0xff)
        slider = Slider(self.solomute)
        slider.setFixedSize((180, 20))

        def mute_cb():
            print('mute')

        mute = Button(self.solomute, 'M')
        mute.setCallback(mute_cb)

        def solo_cb():
            print('solo')

        solo = Button(self.solomute, 'S')
        solo.setCallback(solo_cb)
        spacer = Widget(self)
        spacer.setWidth(20)

        self.setFixedSize((400, 40))
Example #6
0
    def __init__(self, parent, image):
        super(Slot, self).__init__(parent)

        b = Button(parent, "")
        b.setBackgroundColor(Color(0, 0.3, 0.2, 0.1))
        b.setFixedSize((300, 50))

        # slot = Widget(parent)

        pass
Example #7
0
    def __init__(self, parent_window, position):
        # The parent window is the main window for floating windows
        self.pw = parent_window

        # Default properties
        default_height = 250
        default_height_min = 30
        default_width = 200

        # Initialize the floating window
        self.window = Window(self.pw, "alpha")
        self.window.setFixedSize((default_width * self.pw.pixelRatio(),
                                  default_height * self.pw.pixelRatio()))
        self.window.setPosition(position)
        self.window.setLayout(GroupLayout())

        # Add window control buttons (min/max, close, etc)
        buttons = self.window.buttonPanel()

        # Minimize/Maximize
        b_minmax = Button(buttons, "", icon=entypo.ICON_CHEVRON_DOWN)

        def cb():
            if self.window.height() == default_height_min:
                self.window.setHeight(default_height)
            else:
                self.window.setHeight(default_height_min)
            b_minmax.setPushed(not b_minmax.pushed())

        b_minmax.setCallback(cb)

        # Close
        b_close = Button(buttons, "", icon=entypo.ICON_CIRCLE_WITH_CROSS)

        def cb():
            self.window.dispose()

        b_close.setCallback(cb)
Example #8
0
    def setItems(self, items, item_ids):
        if self.vscroll is not None:
            self.removeChild(self.vscroll)
        self.vscroll = VScrollPanel(self)
        self.vscroll.setFixedHeight(200)
        self.vscroll.setFixedWidth(self.item_width)
        self.itemwidget = Widget(self.vscroll)
        self.itemwidget.setLayout(
            BoxLayout(Orientation.Vertical, Alignment.Middle, 0, 0))

        def label_click_handler(button):
            self.selected = int(button.id())
            if self.cb is not None:
                self.cb(self.selected)

        self.list_items = []
        for i, item in enumerate(items):
            list_item = Button(self.itemwidget, item)
            list_item.setFixedWidth(self.item_width)
            list_item.setCallback(
                lambda button=list_item: label_click_handler(button))
            list_item.setId(str(item_ids[i]))
            list_item.setTooltip(item)
            list_item.setFontSize(14)
            list_item.setFlags(Button.Flags.RadioButton)
            self.list_items.append(list_item)
        self.selected = None
        self.setSelectedIndex(0)
Example #9
0
    def __init__(self):
        super(TestApp, self).__init__((1024, 768), "NanoGUI Test")

        window = Window(self, "Button demo")
        window.setPosition((15, 15))
        window.setLayout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")

        b.setCallback(cb)

        b = Button(window, "Styled", entypo.ICON_ROCKET)
        b.setBackgroundColor(Color(0, 0, 1.0, 0.1))
        b.setCallback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.setFlags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))

        b.setChangeCallback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.setFlags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.setFlags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        ToolButton(tools, entypo.ICON_CLOUD)
        ToolButton(tools, entypo.ICON_CONTROLLER_FAST_FORWARD)
        ToolButton(tools, entypo.ICON_COMPASS)
        ToolButton(tools, entypo.ICON_INSTALL)

        Label(window, "Popup buttons", "sans-bold")
        popupBtn = PopupButton(window, "Popup", entypo.ICON_EXPORT)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        # popup right
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popupRight = popupBtn.popup()
        popupRight.setLayout(GroupLayout())
        CheckBox(popupRight, "Another check box")
        # popup left
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popupBtn.setSide(Popup.Side.Left)
        popupLeft = popupBtn.popup()
        popupLeft.setLayout(GroupLayout())
        CheckBox(popupLeft, "Another check box")

        window = Window(self, "Basic widgets")
        window.setPosition((200, 15))
        window.setLayout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.setCallback(cb2)

        b.setCallback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.setCallback(cb2)

        b.setCallback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.setCallback(cb2)

        b.setCallback(cb)

        import os
        import sys
        os.chdir(sys.path[0])
        try:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "icons")
        except:
            try:
                icons = nanogui.loadImageDirectory(self.nvgContext(),
                                                   "../icons")
            except:
                icons = nanogui.loadImageDirectory(self.nvgContext(),
                                                   "../resources/icons")

        Label(window, "Image panel & scroll panel", "sans-bold")
        imagePanelBtn = PopupButton(window, "Image Panel")
        imagePanelBtn.setIcon(entypo.ICON_FOLDER)
        popup = imagePanelBtn.popup()
        vscroll = VScrollPanel(popup)
        imgPanel = ImagePanel(vscroll)
        imgPanel.setImages(icons)
        popup.setFixedSize((245, 150))

        img_window = Window(self, "Selected image")
        img_window.setPosition((710, 15))
        img_window.setLayout(GroupLayout())

        imgView = ImageView(img_window, icons[0][0])

        def cb(i):
            print("Selected item %i" % i)
            imgView.bindImage(icons[i][0])

        imgPanel.setCallback(cb)

        imgView.setGridThreshold(3)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.setCallback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.setCallback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window,
                 ["Combo box item 1", "Combo box item 2", "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)

        chb = CheckBox(window, "Flag 1", cb)
        chb.setChecked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)

        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.setValue(0.5)
        slider.setFixedWidth(80)

        textBox = TextBox(panel)
        textBox.setFixedSize((60, 25))
        textBox.setValue("50")
        textBox.setUnits("%")
        textBox.setFontSize(20)
        textBox.setAlignment(TextBox.Alignment.Right)

        def cb(value):
            textBox.setValue("%i" % int(value * 100))

        slider.setCallback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))

        slider.setFinalCallback(cb)

        window = Window(self, "Misc. widgets")
        window.setPosition((425, 15))
        window.setLayout(GroupLayout())

        tabWidget = TabWidget(window)
        layer = tabWidget.createTab("Color Wheel")
        layer.setLayout(GroupLayout())

        Label(layer, "Color wheel widget", "sans-bold")
        ColorWheel(layer)

        layer = tabWidget.createTab("Function Graph")
        layer.setLayout(GroupLayout())
        Label(layer, "Function graph widget", "sans-bold")

        graph = Graph(layer, "Some function")
        graph.setHeader("E = 2.35e-3")
        graph.setFooter("Iteration 89")
        values = [
            0.5 * (0.5 * math.sin(i / 10.0) + 0.5 * math.cos(i / 23.0) + 1)
            for i in range(100)
        ]
        graph.setValues(values)
        tabWidget.setActiveTab(0)

        # Dummy tab used to represent the last tab button.
        tabWidget.createTab("+")

        def tab_cb(index):
            if index == (tabWidget.tabCount() - 1):
                global counter
                # When the "+" tab has been clicked, simply add a new tab.
                tabName = "Dynamic {0}".format(counter)
                layerDyn = tabWidget.createTab(index, tabName)
                layerDyn.setLayout(GroupLayout())
                Label(layerDyn, "Function graph widget", "sans-bold")
                graphDyn = Graph(layerDyn, "Dynamic function")

                graphDyn.setHeader("E = 2.35e-3")
                graphDyn.setFooter("Iteration {0}".format(index * counter))
                valuesDyn = [
                    0.5 * abs((0.5 * math.sin(i / 10.0 + counter)) +
                              (0.5 * math.cos(i / 23.0 + 1 + counter)))
                    for i in range(100)
                ]
                graphDyn.setValues(valuesDyn)
                counter += 1
                # We must invoke perform layout from the screen instance to keep everything in order.
                # This is essential when creating tabs dynamically.
                self.performLayout()
                # Ensure that the newly added header is visible on screen
                tabWidget.ensureTabVisible(index)

        tabWidget.setCallback(tab_cb)
        tabWidget.setActiveTab(0)

        window = Window(self, "Grid of small widgets")
        window.setPosition((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2, Alignment.Middle, 15, 5)
        layout.setColAlignment([Alignment.Maximum, Alignment.Fill])
        layout.setSpacing(0, 10)
        window.setLayout(layout)

        Label(window, "Floating point :", "sans-bold")
        floatBox = TextBox(window)
        floatBox.setEditable(True)
        floatBox.setFixedSize((100, 20))
        floatBox.setValue("50")
        floatBox.setUnits("GiB")
        floatBox.setDefaultValue("0.0")
        floatBox.setFontSize(16)
        floatBox.setFormat("[-]?[0-9]*\\.?[0-9]+")

        Label(window, "Positive integer :", "sans-bold")
        intBox = IntBox(window)
        intBox.setEditable(True)
        intBox.setFixedSize((100, 20))
        intBox.setValue(50)
        intBox.setUnits("Mhz")
        intBox.setDefaultValue("0")
        intBox.setFontSize(16)
        intBox.setFormat("[1-9][0-9]*")
        intBox.setSpinnable(True)
        intBox.setMinValue(1)
        intBox.setValueIncrement(2)

        Label(window, "Checkbox :", "sans-bold")

        cb = CheckBox(window, "Check me")
        cb.setFontSize(16)
        cb.setChecked(True)

        Label(window, "Combo box :", "sans-bold")
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.setFontSize(16)
        cobo.setFixedSize((100, 20))

        Label(window, "Color picker :", "sans-bold")
        cp = ColorPicker(window, Color(255, 120, 0, 255))
        cp.setFixedSize((100, 20))

        def cp_final_cb(color):
            print("ColorPicker Final Callback: [{0}, {1}, {2}, {3}]".format(
                color.r, color.g, color.b, color.w))

        cp.setFinalCallback(cp_final_cb)

        # setup a fast callback for the color picker widget on a new window
        # for demonstrative purposes
        window = Window(self, "Color Picker Fast Callback")
        window.setPosition((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2, Alignment.Middle, 15, 5)
        layout.setColAlignment([Alignment.Maximum, Alignment.Fill])
        layout.setSpacing(0, 10)
        window.setLayout(layout)
        window.setPosition((425, 500))
        Label(window, "Combined: ")
        b = Button(window, "ColorWheel", entypo.ICON_500PX)
        Label(window, "Red: ")
        redIntBox = IntBox(window)
        redIntBox.setEditable(False)
        Label(window, "Green: ")
        greenIntBox = IntBox(window)
        greenIntBox.setEditable(False)
        Label(window, "Blue: ")
        blueIntBox = IntBox(window)
        blueIntBox.setEditable(False)
        Label(window, "Alpha: ")
        alphaIntBox = IntBox(window)

        def cp_fast_cb(color):
            b.setBackgroundColor(color)
            b.setTextColor(color.contrastingColor())
            red = int(color.r * 255.0)
            redIntBox.setValue(red)
            green = int(color.g * 255.0)
            greenIntBox.setValue(green)
            blue = int(color.b * 255.0)
            blueIntBox.setValue(blue)
            alpha = int(color.w * 255.0)
            alphaIntBox.setValue(alpha)

        cp.setCallback(cp_fast_cb)

        self.performLayout()

        try:
            import numpy as np

            self.shader = GLShader()
            self.shader.init(
                # An identifying name
                "a_simple_shader",

                # Vertex shader
                """#version 330
                uniform mat4 modelViewProj;
                in vec3 position;
                void main() {
                    gl_Position = modelViewProj * vec4(position, 1.0);
                }""",
                """#version 330
                out vec4 color;
                uniform float intensity;
                void main() {
                    color = vec4(vec3(intensity), 1.0);
                }""")

            # Draw 2 triangles
            indices = np.array([[0, 2], [1, 3], [2, 0]], dtype=np.int32)

            positions = np.array(
                [[-1, 1, 1, -1], [-1, -1, 1, 1], [0, 0, 0, 0]],
                dtype=np.float32)

            self.shader.bind()
            self.shader.uploadIndices(indices)
            self.shader.uploadAttrib("position", positions)
            self.shader.setUniform("intensity", 0.5)
        except ImportError:
            self.shader = None
            pass
Example #10
0
    def __init__(self):
        super(TestApp, self).__init__(Vector2i(1024, 768), "NanoGUI Test")

        window = Window(self, "Button demo")
        window.setPosition(Vector2i(15, 15))
        window.setLayout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")
        b.setCallback(cb)

        b = Button(window, "Styled", entypo.ICON_ROCKET)
        b.setBackgroundColor(Color(0, 0, 1.0, 0.1))
        b.setCallback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.setFlags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))
        b.setChangeCallback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.setFlags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.setFlags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))

        ToolButton(tools, entypo.ICON_CLOUD)
        ToolButton(tools, entypo.ICON_FF)
        ToolButton(tools, entypo.ICON_COMPASS)
        ToolButton(tools, entypo.ICON_INSTALL)

        Label(window, "Popup buttons", "sans-bold")
        popupBtn = PopupButton(window, "Popup", entypo.ICON_EXPORT)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        CheckBox(popup, "Another check box")

        window = Window(self, "Basic widgets")
        window.setPosition(Vector2i(200, 15))
        window.setLayout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.setCallback(cb2)
        b.setCallback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.setCallback(cb2)
        b.setCallback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.setCallback(cb2)
        b.setCallback(cb)

        import os
        import sys
        os.chdir(sys.path[0])
        try:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "icons")
        except:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "../icons")

        Label(window, "Image panel & scroll panel", "sans-bold")
        imagePanelBtn = PopupButton(window, "Image Panel")
        imagePanelBtn.setIcon(entypo.ICON_FOLDER)
        popup = imagePanelBtn.popup()
        vscroll = VScrollPanel(popup)
        imgPanel = ImagePanel(vscroll)
        imgPanel.setImages(icons)
        popup.setFixedSize(Vector2i(245, 150))

        img_window = Window(self, "Selected image")
        img_window.setPosition(Vector2i(675, 15))
        img_window.setLayout(GroupLayout());

        img = ImageView(img_window)
        img.setPolicy(ImageView.SizePolicy.Expand)
        img.setFixedSize(Vector2i(300, 300))
        img.setImage(icons[0][0])

        def cb(i):
            print("Selected item %i" % i)
            img.setImage(icons[i][0])
        imgPanel.setCallback(cb)

        def cb(s):
            if s:
                img.setPolicy(ImageView.SizePolicy.Expand)
            else:
                img.setPolicy(ImageView.SizePolicy.Fixed)
        img_cb = CheckBox(img_window, "Expand", cb)
        img_cb.setChecked(True)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.setCallback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.setCallback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window, ["Combo box item 1", "Combo box item 2",
                          "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)
        chb = CheckBox(window, "Flag 1", cb)
        chb.setChecked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)
        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.setValue(0.5)
        slider.setFixedWidth(80)

        textBox = TextBox(panel)
        textBox.setFixedSize(Vector2i(60, 25))
        textBox.setValue("50")
        textBox.setUnits("%")
        textBox.setFontSize(20)
        textBox.setAlignment(TextBox.Alignment.Right)

        def cb(value):
            textBox.setValue("%i" % int(value * 100))
        slider.setCallback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))
        slider.setFinalCallback(cb)

        window = Window(self, "Misc. widgets")
        window.setPosition(Vector2i(425, 15))
        window.setLayout(GroupLayout())
        Label(window, "Color wheel", "sans-bold")
        ColorWheel(window)
        Label(window, "Function graph", "sans-bold")
        graph = Graph(window, "Some function")
        graph.setHeader("E = 2.35e-3")
        graph.setFooter("Iteration 89")
        values = VectorXf(100)
        for i in range(100):
            values[i] = 0.5 * (0.5 * math.sin(i / 10.0) +
                               0.5 * math.cos(i / 23.0) + 1)
        graph.setValues(values)

        window = Window(self, "Grid of small widgets")
        window.setPosition(Vector2i(425, 288))
        layout = GridLayout(Orientation.Horizontal, 2,
                            Alignment.Middle, 15, 5)
        layout.setColAlignment(
            [Alignment.Maximum, Alignment.Fill])
        layout.setSpacing(0, 10)
        window.setLayout(layout)

        Label(window, "Floating point :", "sans-bold")
        floatBox = TextBox(window)
        floatBox.setEditable(True)
        floatBox.setFixedSize(Vector2i(100, 20))
        floatBox.setValue("50")
        floatBox.setUnits("GiB")
        floatBox.setDefaultValue("0.0")
        floatBox.setFontSize(16)
        floatBox.setFormat("[-]?[0-9]*\\.?[0-9]+")

        Label(window, "Positive integer :", "sans-bold")
        intBox = TextBox(window)
        intBox.setEditable(True)
        intBox.setFixedSize(Vector2i(100, 20))
        intBox.setValue("50")
        intBox.setUnits("Mhz")
        intBox.setDefaultValue("0.0")
        intBox.setFontSize(16)
        intBox.setFormat("[1-9][0-9]*")

        Label(window, "Checkbox :", "sans-bold")

        cb = CheckBox(window, "Check me")
        cb.setFontSize(16)
        cb.setChecked(True)

        Label(window, "Combo box :", "sans-bold")
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.setFontSize(16)
        cobo.setFixedSize(Vector2i(100, 20))

        Label(window, "Color button :", "sans-bold")
        popupBtn = PopupButton(window, "", 0)
        popupBtn.setBackgroundColor(Color(1, 0.47, 0, 1))
        popupBtn.setFontSize(16)
        popupBtn.setFixedSize(Vector2i(100, 20))
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())

        colorwheel = ColorWheel(popup)
        colorwheel.setColor(popupBtn.backgroundColor())

        colorBtn = Button(popup, "Pick")
        colorBtn.setFixedSize(Vector2i(100, 25))
        c = colorwheel.color()
        colorBtn.setBackgroundColor(c)

        def cb(value):
            colorBtn.setBackgroundColor(value)

        colorwheel.setCallback(cb)

        def cb(pushed):
            if (pushed):
                popupBtn.setBackgroundColor(colorBtn.backgroundColor())
                popupBtn.setPushed(False)
        colorBtn.setChangeCallback(cb)

        self.performLayout()
Example #11
0
    window.setFixedSize((width, height))

    # attach a vertical scroll panel
    vscroll = VScrollPanel(window)
    vscroll.setFixedSize((width, height))

    # vscroll should only have *ONE* child. this is what `wrapper` is for
    wrapper = Widget(vscroll)
    wrapper.setFixedSize((width, height))
    wrapper.setLayout(GridLayout())  # defaults: 2 columns

    # NOTE: don't __dict__ crawl in real code!
    # this is just because it's more convenient to do this for enumerating all
    # of the icons -- see cpp example for alternative...
    for key in entypo.__dict__.keys():
        if key.startswith("ICON_"):
            b = Button(wrapper, "entypo.{0}".format(key), entypo.__dict__[key])
            b.setIconPosition(Button.IconPosition.Left)
            b.setFixedWidth(half_width)

    screen.performLayout()
    screen.drawAll()
    screen.setVisible(True)

    nanogui.mainloop()

    del screen
    gc.collect()

    nanogui.shutdown()
Example #12
0
    def __init__(self):
        super(TestApp, self).__init__(Vector2i(1024, 768), "NanoGUI Test")

        window = Window(self, "Button demo")
        window.setPosition(Vector2i(15, 15))
        window.setLayout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")
        b.setCallback(cb)

        b = Button(window, "Styled", entypo.ICON_ROCKET)
        b.setBackgroundColor(Color(0, 0, 1.0, 0.1))
        b.setCallback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.setFlags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))
        b.setChangeCallback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.setFlags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.setFlags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))

        ToolButton(tools, entypo.ICON_CLOUD)
        ToolButton(tools, entypo.ICON_FF)
        ToolButton(tools, entypo.ICON_COMPASS)
        ToolButton(tools, entypo.ICON_INSTALL)

        Label(window, "Popup buttons", "sans-bold")
        popupBtn = PopupButton(window, "Popup", entypo.ICON_EXPORT)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        CheckBox(popup, "Another check box")

        window = Window(self, "Basic widgets")
        window.setPosition(Vector2i(200, 15))
        window.setLayout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.setCallback(cb2)
        b.setCallback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.setCallback(cb2)
        b.setCallback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.setCallback(cb2)
        b.setCallback(cb)

        import os
        import sys
        os.chdir(sys.path[0])
        try:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "icons")
        except:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "../icons")

        Label(window, "Image panel & scroll panel", "sans-bold")
        imagePanelBtn = PopupButton(window, "Image Panel")
        imagePanelBtn.setIcon(entypo.ICON_FOLDER)
        popup = imagePanelBtn.popup()
        vscroll = VScrollPanel(popup)
        imgPanel = ImagePanel(vscroll)
        imgPanel.setImages(icons)
        popup.setFixedSize(Vector2i(245, 150))

        img_window = Window(self, "Selected image")
        img_window.setPosition(Vector2i(710, 15))
        img_window.setLayout(GroupLayout())

        
        imgView = ImageView(img_window, icons[0][0]))

        def cb(i):
            print("Selected item %i" % i)
            imgView.bindImage(icons[i][0])
        imgPanel.setCallback(cb)

        imgView.setGridThreshold(3)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.setCallback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.setCallback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window, ["Combo box item 1", "Combo box item 2",
                          "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)
        chb = CheckBox(window, "Flag 1", cb)
        chb.setChecked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)
        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.setValue(0.5)
        slider.setFixedWidth(80)

        textBox = TextBox(panel)
        textBox.setFixedSize(Vector2i(60, 25))
        textBox.setValue("50")
        textBox.setUnits("%")
        textBox.setFontSize(20)
        textBox.setAlignment(TextBox.Alignment.Right)

        def cb(value):
            textBox.setValue("%i" % int(value * 100))
        slider.setCallback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))
        slider.setFinalCallback(cb)

        window = Window(self, "Misc. widgets")
        window.setPosition(Vector2i(425, 15))
        window.setLayout(GroupLayout())

        tabWidget = TabWidget(window)
        layer = tabWidget.createTab("Color Wheel")
        layer.setLayout(GroupLayout())

        Label(layer, "Color wheel widget", "sans-bold")
        ColorWheel(layer)

        layer = tabWidget.createTab("Function Graph")
        layer.setLayout(GroupLayout())
        Label(layer, "Function graph widget", "sans-bold")

        graph = Graph(layer, "Some function")
        graph.setHeader("E = 2.35e-3")
        graph.setFooter("Iteration 89")
        values = VectorXf(100)
        for i in range(100):
            values[i] = 0.5 * (0.5 * math.sin(i / 10.0) +
                               0.5 * math.cos(i / 23.0) + 1)
Example #13
0
    def __init__(self):
        super(TestApp, self).__init__((1024, 768), "NanoGUI Test")

        window = Window(self, "Button demo")
        window.setPosition((15, 15))
        window.setLayout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")

        b.setCallback(cb)

        b = Button(window, "Styled", entypo.ICON_ROCKET)
        b.setBackgroundColor(Color(0, 0, 1.0, 0.1))
        b.setCallback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.setFlags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))

        b.setChangeCallback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.setFlags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.setFlags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        ToolButton(tools, entypo.ICON_CLOUD)
        ToolButton(tools, entypo.ICON_FF)
        ToolButton(tools, entypo.ICON_COMPASS)
        ToolButton(tools, entypo.ICON_INSTALL)

        Label(window, "Popup buttons", "sans-bold")
        popupBtn = PopupButton(window, "Popup", entypo.ICON_EXPORT)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        CheckBox(popup, "Another check box")

        window = Window(self, "Basic widgets")
        window.setPosition((200, 15))
        window.setLayout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.setCallback(cb2)

        b.setCallback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.setCallback(cb2)

        b.setCallback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.setCallback(cb2)

        b.setCallback(cb)

        import os
        import sys
        os.chdir(sys.path[0])
        try:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "icons")
        except:
            try:
                icons = nanogui.loadImageDirectory(self.nvgContext(),
                                                   "../icons")
            except:
                icons = nanogui.loadImageDirectory(self.nvgContext(),
                                                   "../resources/icons")

        Label(window, "Image panel & scroll panel", "sans-bold")
        imagePanelBtn = PopupButton(window, "Image Panel")
        imagePanelBtn.setIcon(entypo.ICON_FOLDER)
        popup = imagePanelBtn.popup()
        vscroll = VScrollPanel(popup)
        imgPanel = ImagePanel(vscroll)
        imgPanel.setImages(icons)
        popup.setFixedSize((245, 150))

        img_window = Window(self, "Selected image")
        img_window.setPosition((710, 15))
        img_window.setLayout(GroupLayout())

        imgView = ImageView(img_window, icons[0][0])

        def cb(i):
            print("Selected item %i" % i)
            imgView.bindImage(icons[i][0])

        imgPanel.setCallback(cb)

        imgView.setGridThreshold(3)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.setCallback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.setCallback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window,
                 ["Combo box item 1", "Combo box item 2", "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)

        chb = CheckBox(window, "Flag 1", cb)
        chb.setChecked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)

        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.setValue(0.5)
        slider.setFixedWidth(80)

        textBox = TextBox(panel)
        textBox.setFixedSize((60, 25))
        textBox.setValue("50")
        textBox.setUnits("%")
        textBox.setFontSize(20)
        textBox.setAlignment(TextBox.Alignment.Right)

        def cb(value):
            textBox.setValue("%i" % int(value * 100))

        slider.setCallback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))

        slider.setFinalCallback(cb)

        window = Window(self, "Misc. widgets")
        window.setPosition((425, 15))
        window.setLayout(GroupLayout())

        tabWidget = TabWidget(window)
        layer = tabWidget.createTab("Color Wheel")
        layer.setLayout(GroupLayout())

        Label(layer, "Color wheel widget", "sans-bold")
        ColorWheel(layer)

        layer = tabWidget.createTab("Function Graph")
        layer.setLayout(GroupLayout())
        Label(layer, "Function graph widget", "sans-bold")

        graph = Graph(layer, "Some function")
        graph.setHeader("E = 2.35e-3")
        graph.setFooter("Iteration 89")
        values = [
            0.5 * (0.5 * math.sin(i / 10.0) + 0.5 * math.cos(i / 23.0) + 1)
            for i in range(100)
        ]
        graph.setValues(values)
        tabWidget.setActiveTab(0)

        window = Window(self, "Grid of small widgets")
        window.setPosition((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2, Alignment.Middle, 15, 5)
        layout.setColAlignment([Alignment.Maximum, Alignment.Fill])
        layout.setSpacing(0, 10)
        window.setLayout(layout)

        Label(window, "Floating point :", "sans-bold")
        floatBox = TextBox(window)
        floatBox.setEditable(True)
        floatBox.setFixedSize((100, 20))
        floatBox.setValue("50")
        floatBox.setUnits("GiB")
        floatBox.setDefaultValue("0.0")
        floatBox.setFontSize(16)
        floatBox.setFormat("[-]?[0-9]*\\.?[0-9]+")

        Label(window, "Positive integer :", "sans-bold")
        intBox = IntBox(window)
        intBox.setEditable(True)
        intBox.setFixedSize((100, 20))
        intBox.setValue(50)
        intBox.setUnits("Mhz")
        intBox.setDefaultValue("0")
        intBox.setFontSize(16)
        intBox.setFormat("[1-9][0-9]*")
        intBox.setSpinnable(True)
        intBox.setMinValue(1)
        intBox.setValueIncrement(2)

        Label(window, "Checkbox :", "sans-bold")

        cb = CheckBox(window, "Check me")
        cb.setFontSize(16)
        cb.setChecked(True)

        Label(window, "Combo box :", "sans-bold")
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.setFontSize(16)
        cobo.setFixedSize((100, 20))

        Label(window, "Color button :", "sans-bold")
        popupBtn = PopupButton(window, "", 0)
        popupBtn.setBackgroundColor(Color(1, 0.47, 0, 1))
        popupBtn.setFontSize(16)
        popupBtn.setFixedSize((100, 20))
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())

        colorwheel = ColorWheel(popup)
        colorwheel.setColor(popupBtn.backgroundColor())

        colorBtn = Button(popup, "Pick")
        colorBtn.setFixedSize((100, 25))
        c = colorwheel.color()
        colorBtn.setBackgroundColor(c)

        def cb(value):
            colorBtn.setBackgroundColor(value)

        colorwheel.setCallback(cb)

        def cb(pushed):
            if (pushed):
                popupBtn.setBackgroundColor(colorBtn.backgroundColor())
                popupBtn.setPushed(False)

        colorBtn.setChangeCallback(cb)

        self.performLayout()

        try:
            import numpy as np

            self.shader = GLShader()
            self.shader.init(
                # An identifying name
                "a_simple_shader",

                # Vertex shader
                """#version 330
                uniform mat4 modelViewProj;
                in vec3 position;
                void main() {
                    gl_Position = modelViewProj * vec4(position, 1.0);
                }""",
                """#version 330
                out vec4 color;
                uniform float intensity;
                void main() {
                    color = vec4(vec3(intensity), 1.0);
                }""")

            # Draw 2 triangles
            indices = np.array([[0, 2], [1, 3], [2, 0]], dtype=np.int32)

            positions = np.array(
                [[-1, 1, 1, -1], [-1, -1, 1, 1], [0, 0, 0, 0]],
                dtype=np.float32)

            self.shader.bind()
            self.shader.uploadIndices(indices)
            self.shader.uploadAttrib("position", positions)
            self.shader.setUniform("intensity", 0.5)
        except ImportError:
            self.shader = None
            pass
Example #14
0
class SoundLayer(Widget):
    def __init__(self, parent, name, sound, color):
        super(SoundLayer, self).__init__(parent)
        print('[+] SoundLayer::__init__')
        self.setLayout(GridLayout(resolution=4))
        self.sound = sound
        self.cp = Button(self, '')
        self.color = color
        self.cp.setBackgroundColor(color)
        label = Label(self, name + ':', 'sans-bold')
        label.setFixedSize((70, 20))
        self.cp.setFixedSize((20, 40))
        self.solomute = Widget(self)
        self.solomute.setLayout(GridLayout(resolution=3))
        self._parent = parent
        self._focused = False

        self.issolo = False
        self.ismute = False
        self.selected_color = Color(0x3e, 0x3e, 0x3f, 0xff)
        slider = Slider(self.solomute)
        slider.setFixedSize((180, 20))

        def mute_cb():
            print('mute')

        mute = Button(self.solomute, 'M')
        mute.setCallback(mute_cb)

        def solo_cb():
            print('solo')

        solo = Button(self.solomute, 'S')
        solo.setCallback(solo_cb)
        spacer = Widget(self)
        spacer.setWidth(20)

        self.setFixedSize((400, 40))

    def get_spect_image(self,
                        fft_size=FFT_SIZE,
                        zoom=1,
                        offset=0,
                        dtype=np.uint8):
        print('[+] sound.sample_width', self.sound.sample_width)
        print('[+] sound.channels', self.sound.channels)
        print('[+] sound.frame_rate', self.sound.frame_rate)
        print('[+] sound.frame_count', int(self.sound.frame_count()))

        fbins, rbins = self.get_bins(fft_size)

        ret = fbins[:, :fft_size]
        frames_num = ret.shape[0]
        # import pdb; pdb.set_trace()
        ret = np.abs(ret)
        ret = 20 * np.log10(ret)  # scale to db
        ret = np.clip(ret, -40, 200)  # clip values
        ret = ret + 40  # to pix
        ret = (ret / 240.0) * np.iinfo(dtype).max
        ret = np.concatenate(ret.T)  # join frames and tilt
        ret = dtype(ret).reshape(fft_size, frames_num)  # reshape as bins/time
        ret = ret[::-1, :]  # flip vertically for PIL
        return ret

    def get_channels(self):
        if self.sound.channels == 1:
            for chunks in make_chunks(self.sound,
                                      int(self.sound.frame_count())):
                left = np.array(chunks.get_array_of_samples())
                return left, left

        for chunks in make_chunks(self.sound, int(self.sound.frame_count())):
            samps = chunks.get_array_of_samples()
            left = np.array(samps[::2])  # left ch
            right = np.array(samps[1::2])
        return left, right

    def get_bins(self, fft_size=FFT_SIZE):
        left, right = self.get_channels()
        self.l_bins = fftutils.windowed_fft(left,
                                            fft_size=fft_size,
                                            overlap_fac=OVERLAP)
        self.r_bins = fftutils.windowed_fft(right,
                                            fft_size=fft_size,
                                            overlap_fac=OVERLAP)
        return self.l_bins, self.r_bins

    def draw(self, ctx):
        if self.is_focused():
            ctx.BeginPath()
            ctx.Rect(self.position()[0],
                     self.position()[1],
                     self.size()[0] - 30,
                     self.size()[1])
            ctx.FillColor(self.selected_color)
            ctx.Fill()
            bg = ctx.LinearGradient(self.position()[0],
                                    self.position()[1],
                                    self.size()[0] - 30,
                                    self.size()[1], self.selected_color,
                                    self.selected_color)
            ctx.FillPaint(bg)
            ctx.Fill()
        return super(SoundLayer, self).draw(ctx)

    def is_focused(self):
        return self._focused

    def set_focus(self, val):
        if val:
            self._parent.blur_all()
        self._focused = val

    def mouseButtonEvent(self, p, button, down, modifiers):
        ret = super(SoundLayer, self).mouseButtonEvent(p, button, down,
                                                       modifiers)
        if ret:
            return ret
        if (button == 0):
            if down:
                self.set_focus(True)
            return True
        return False
Example #15
0
    def __init__(self):
        super(TestApp, self).__init__(Vector2i(1024, 768), "NanoGUI Test")

        window = Window(self, "Button demo")
        window.setPosition(Vector2i(15, 15))
        window.setLayout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")

        b.setCallback(cb)

        b = Button(window, "Styled", entypo.ICON_ROCKET)
        b.setBackgroundColor(Color(0, 0, 1.0, 0.1))
        b.setCallback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.setFlags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))

        b.setChangeCallback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.setFlags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.setFlags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        ToolButton(tools, entypo.ICON_CLOUD)
        ToolButton(tools, entypo.ICON_FF)
        ToolButton(tools, entypo.ICON_COMPASS)
        ToolButton(tools, entypo.ICON_INSTALL)

        Label(window, "Popup buttons", "sans-bold")
        popupBtn = PopupButton(window, "Popup", entypo.ICON_EXPORT)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        CheckBox(popup, "Another check box")

        window = Window(self, "Basic widgets")
        window.setPosition(Vector2i(200, 15))
        window.setLayout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.setCallback(cb2)

        b.setCallback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.setCallback(cb2)

        b.setCallback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.setCallback(cb2)

        b.setCallback(cb)

        import os
        import sys
        os.chdir(sys.path[0])
        try:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "icons")
        except:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "../icons")

        Label(window, "Image panel & scroll panel", "sans-bold")
        imagePanelBtn = PopupButton(window, "Image Panel")
        imagePanelBtn.setIcon(entypo.ICON_FOLDER)
        popup = imagePanelBtn.popup()
        vscroll = VScrollPanel(popup)
        imgPanel = ImagePanel(vscroll)
        imgPanel.setImages(icons)
        popup.setFixedSize(Vector2i(245, 150))

        img_window = Window(self, "Selected image")
        img_window.setPosition(Vector2i(675, 15))
        img_window.setLayout(GroupLayout())

        img = ImageView(img_window)
        img.setPolicy(ImageView.SizePolicy.Expand)
        img.setFixedSize(Vector2i(300, 300))
        img.setImage(icons[0][0])

        def cb(i):
            print("Selected item %i" % i)
            img.setImage(icons[i][0])

        imgPanel.setCallback(cb)

        def cb(s):
            if s:
                img.setPolicy(ImageView.SizePolicy.Expand)
            else:
                img.setPolicy(ImageView.SizePolicy.Fixed)

        img_cb = CheckBox(img_window, "Expand", cb)
        img_cb.setChecked(True)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.setCallback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.setCallback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window,
                 ["Combo box item 1", "Combo box item 2", "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)

        chb = CheckBox(window, "Flag 1", cb)
        chb.setChecked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)

        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.setLayout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.setValue(0.5)
        slider.setFixedWidth(80)

        textBox = TextBox(panel)
        textBox.setFixedSize(Vector2i(60, 25))
        textBox.setValue("50")
        textBox.setUnits("%")
        textBox.setFontSize(20)
        textBox.setAlignment(TextBox.Alignment.Right)

        def cb(value):
            textBox.setValue("%i" % int(value * 100))

        slider.setCallback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))

        slider.setFinalCallback(cb)

        window = Window(self, "Misc. widgets")
        window.setPosition(Vector2i(425, 15))
        window.setLayout(GroupLayout())
        Label(window, "Color wheel", "sans-bold")
        ColorWheel(window)
        Label(window, "Function graph", "sans-bold")
        graph = Graph(window, "Some function")
        graph.setHeader("E = 2.35e-3")
        graph.setFooter("Iteration 89")
        values = VectorXf(100)
        for i in range(100):
            values[i] = 0.5 * (0.5 * math.sin(i / 10.0) +
                               0.5 * math.cos(i / 23.0) + 1)
        graph.setValues(values)

        window = Window(self, "Grid of small widgets")
        window.setPosition(Vector2i(425, 288))
        layout = GridLayout(Orientation.Horizontal, 2, Alignment.Middle, 15, 5)
        layout.setColAlignment([Alignment.Maximum, Alignment.Fill])
        layout.setSpacing(0, 10)
        window.setLayout(layout)

        Label(window, "Floating point :", "sans-bold")
        floatBox = TextBox(window)
        floatBox.setEditable(True)
        floatBox.setFixedSize(Vector2i(100, 20))
        floatBox.setValue("50")
        floatBox.setUnits("GiB")
        floatBox.setDefaultValue("0.0")
        floatBox.setFontSize(16)
        floatBox.setFormat("[-]?[0-9]*\\.?[0-9]+")

        Label(window, "Positive integer :", "sans-bold")
        intBox = TextBox(window)
        intBox.setEditable(True)
        intBox.setFixedSize(Vector2i(100, 20))
        intBox.setValue("50")
        intBox.setUnits("Mhz")
        intBox.setDefaultValue("0.0")
        intBox.setFontSize(16)
        intBox.setFormat("[1-9][0-9]*")

        Label(window, "Checkbox :", "sans-bold")

        cb = CheckBox(window, "Check me")
        cb.setFontSize(16)
        cb.setChecked(True)

        Label(window, "Combo box :", "sans-bold")
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.setFontSize(16)
        cobo.setFixedSize(Vector2i(100, 20))

        Label(window, "Color button :", "sans-bold")
        popupBtn = PopupButton(window, "", 0)
        popupBtn.setBackgroundColor(Color(1, 0.47, 0, 1))
        popupBtn.setFontSize(16)
        popupBtn.setFixedSize(Vector2i(100, 20))
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())

        colorwheel = ColorWheel(popup)
        colorwheel.setColor(popupBtn.backgroundColor())

        colorBtn = Button(popup, "Pick")
        colorBtn.setFixedSize(Vector2i(100, 25))
        c = colorwheel.color()
        colorBtn.setBackgroundColor(c)

        def cb(value):
            colorBtn.setBackgroundColor(value)

        colorwheel.setCallback(cb)

        def cb(pushed):
            if (pushed):
                popupBtn.setBackgroundColor(colorBtn.backgroundColor())
                popupBtn.setPushed(False)

        colorBtn.setChangeCallback(cb)

        self.performLayout()
Example #16
0
    def Tools(self, parent):
        '''
		Draw tools widget.
		'''
        tools = Widget(parent)
        tools.setPosition((20, 420))
        layout = BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 2)
        tools.setLayout(layout)

        tools2 = Widget(tools)
        tools2.setFixedWidth(150)

        b_size = (28, 28)
        b = Button(tools, "", entypo.ICON_ADD_TO_LIST)
        b.setFixedSize(b_size)

        def add():
            print("Add")

        b.setCallback(add)

        # Settings.
        b = Button(tools, "", entypo.ICON_ADJUST)
        b.setFixedSize(b_size)

        def settings():
            print("Add")
            self.main_wnd.setVisible(False)

        b.setCallback(settings)

        #
        b = Button(tools, "", entypo.ICON_ALIGN_BOTTOM)
        b.setFixedSize(b_size)

        # Save.
        b = Button(tools, "", entypo.ICON_INSTALL)
        b.setFixedSize(b_size)
Example #17
0
    def __init__(self):
        super(TestApp, self).__init__((1024, 768), "NanoGUI Test")

        window = Window(self, "Button demo")
        window.setPosition((15, 15))
        window.setLayout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")
        b.setCallback(cb)

        b = Button(window, "Styled", entypo.ICON_ROCKET)
        b.setBackgroundColor(Color(0, 0, 1.0, 0.1))
        b.setCallback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.setFlags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))
        b.setChangeCallback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.setFlags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.setFlags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))

        ToolButton(tools, entypo.ICON_CLOUD)
        ToolButton(tools, entypo.ICON_CONTROLLER_FAST_FORWARD)
        ToolButton(tools, entypo.ICON_COMPASS)
        ToolButton(tools, entypo.ICON_INSTALL)

        Label(window, "Popup buttons", "sans-bold")
        popupBtn = PopupButton(window, "Popup", entypo.ICON_EXPORT)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        # popup right
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popupRight = popupBtn.popup()
        popupRight.setLayout(GroupLayout())
        CheckBox(popupRight, "Another check box")
        # popup left
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popupBtn.setSide(Popup.Side.Left)
        popupLeft = popupBtn.popup()
        popupLeft.setLayout(GroupLayout())
        CheckBox(popupLeft, "Another check box");

        window = Window(self, "Basic widgets")
        window.setPosition((200, 15))
        window.setLayout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.setCallback(cb2)
        b.setCallback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.setCallback(cb2)
        b.setCallback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.setCallback(cb2)
        b.setCallback(cb)

        import os
        import sys
        os.chdir(sys.path[0])
        try:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "icons")
        except:
            try:
                icons = nanogui.loadImageDirectory(self.nvgContext(), "../icons")
            except:
                icons = nanogui.loadImageDirectory(self.nvgContext(), "../resources/icons")


        Label(window, "Image panel & scroll panel", "sans-bold")
        imagePanelBtn = PopupButton(window, "Image Panel")
        imagePanelBtn.setIcon(entypo.ICON_FOLDER)
        popup = imagePanelBtn.popup()
        vscroll = VScrollPanel(popup)
        imgPanel = ImagePanel(vscroll)
        imgPanel.setImages(icons)
        popup.setFixedSize((245, 150))

        img_window = Window(self, "Selected image")
        img_window.setPosition((710, 15))
        img_window.setLayout(GroupLayout())

        imgView = ImageView(img_window, icons[0][0])

        def cb(i):
            print("Selected item %i" % i)
            imgView.bindImage(icons[i][0])
        imgPanel.setCallback(cb)

        imgView.setGridThreshold(3)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.setCallback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.setCallback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window, ["Combo box item 1", "Combo box item 2",
                          "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)
        chb = CheckBox(window, "Flag 1", cb)
        chb.setChecked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)
        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.setValue(0.5)
        slider.setFixedWidth(80)

        textBox = TextBox(panel)
        textBox.setFixedSize((60, 25))
        textBox.setValue("50")
        textBox.setUnits("%")
        textBox.setFontSize(20)
        textBox.setAlignment(TextBox.Alignment.Right)

        def cb(value):
            textBox.setValue("%i" % int(value * 100))
        slider.setCallback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))
        slider.setFinalCallback(cb)

        window = Window(self, "Misc. widgets")
        window.setPosition((425, 15))
        window.setLayout(GroupLayout())

        tabWidget = TabWidget(window)
        layer = tabWidget.createTab("Color Wheel")
        layer.setLayout(GroupLayout())

        Label(layer, "Color wheel widget", "sans-bold")
        ColorWheel(layer)

        layer = tabWidget.createTab("Function Graph")
        layer.setLayout(GroupLayout())
        Label(layer, "Function graph widget", "sans-bold")

        graph = Graph(layer, "Some function")
        graph.setHeader("E = 2.35e-3")
        graph.setFooter("Iteration 89")
        values = [0.5 * (0.5 * math.sin(i / 10.0) +
                         0.5 * math.cos(i / 23.0) + 1)
                  for i in range(100)]
        graph.setValues(values)
        tabWidget.setActiveTab(0)

        # Dummy tab used to represent the last tab button.
        tabWidget.createTab("+")

        def tab_cb(index):
            if index == (tabWidget.tabCount()-1):
                global counter
                # When the "+" tab has been clicked, simply add a new tab.
                tabName  = "Dynamic {0}".format(counter)
                layerDyn = tabWidget.createTab(index, tabName)
                layerDyn.setLayout(GroupLayout())
                Label(layerDyn, "Function graph widget", "sans-bold")
                graphDyn = Graph(layerDyn, "Dynamic function")

                graphDyn.setHeader("E = 2.35e-3")
                graphDyn.setFooter("Iteration {0}".format(index*counter))
                valuesDyn = [0.5 * abs((0.5 * math.sin(i / 10.0 + counter)) +
                                       (0.5 * math.cos(i / 23.0 + 1 + counter)))
                             for i in range(100)]
                graphDyn.setValues(valuesDyn)
                counter += 1
                # We must invoke perform layout from the screen instance to keep everything in order.
                # This is essential when creating tabs dynamically.
                self.performLayout()
                # Ensure that the newly added header is visible on screen
                tabWidget.ensureTabVisible(index)

        tabWidget.setCallback(tab_cb)
        tabWidget.setActiveTab(0);

        window = Window(self, "Grid of small widgets")
        window.setPosition((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2,
                            Alignment.Middle, 15, 5)
        layout.setColAlignment(
            [Alignment.Maximum, Alignment.Fill])
        layout.setSpacing(0, 10)
        window.setLayout(layout)

        Label(window, "Floating point :", "sans-bold")
        floatBox = TextBox(window)
        floatBox.setEditable(True)
        floatBox.setFixedSize((100, 20))
        floatBox.setValue("50")
        floatBox.setUnits("GiB")
        floatBox.setDefaultValue("0.0")
        floatBox.setFontSize(16)
        floatBox.setFormat("[-]?[0-9]*\\.?[0-9]+")

        Label(window, "Positive integer :", "sans-bold")
        intBox = IntBox(window)
        intBox.setEditable(True)
        intBox.setFixedSize((100, 20))
        intBox.setValue(50)
        intBox.setUnits("Mhz")
        intBox.setDefaultValue("0")
        intBox.setFontSize(16)
        intBox.setFormat("[1-9][0-9]*")
        intBox.setSpinnable(True)
        intBox.setMinValue(1)
        intBox.setValueIncrement(2)

        Label(window, "Checkbox :", "sans-bold")

        cb = CheckBox(window, "Check me")
        cb.setFontSize(16)
        cb.setChecked(True)

        Label(window, "Combo box :", "sans-bold")
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.setFontSize(16)
        cobo.setFixedSize((100, 20))

        Label(window, "Color picker :", "sans-bold");
        cp = ColorPicker(window, Color(255, 120, 0, 255));
        cp.setFixedSize((100, 20));

        def cp_final_cb(color):
            print(
                "ColorPicker Final Callback: [{0}, {1}, {2}, {3}]".format(color.r,
                                                                          color.g,
                                                                          color.b,
                                                                          color.w)
            )

        cp.setFinalCallback(cp_final_cb)

        # setup a fast callback for the color picker widget on a new window
        # for demonstrative purposes
        window = Window(self, "Color Picker Fast Callback")
        window.setPosition((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2,
                            Alignment.Middle, 15, 5)
        layout.setColAlignment(
            [Alignment.Maximum, Alignment.Fill])
        layout.setSpacing(0, 10)
        window.setLayout(layout)
        window.setPosition((425, 500))
        Label(window, "Combined: ");
        b = Button(window, "ColorWheel", entypo.ICON_500PX)
        Label(window, "Red: ")
        redIntBox = IntBox(window)
        redIntBox.setEditable(False)
        Label(window, "Green: ")
        greenIntBox = IntBox(window)
        greenIntBox.setEditable(False)
        Label(window, "Blue: ")
        blueIntBox = IntBox(window)
        blueIntBox.setEditable(False)
        Label(window, "Alpha: ")
        alphaIntBox = IntBox(window)

        def cp_fast_cb(color):
            b.setBackgroundColor(color)
            b.setTextColor(color.contrastingColor())
            red = int(color.r * 255.0)
            redIntBox.setValue(red)
            green = int(color.g * 255.0)
            greenIntBox.setValue(green)
            blue = int(color.b * 255.0)
            blueIntBox.setValue(blue)
            alpha = int(color.w * 255.0)
            alphaIntBox.setValue(alpha)

        cp.setCallback(cp_fast_cb)

        self.performLayout()

        try:
            import numpy as np

            self.shader = GLShader()
            self.shader.init(
                # An identifying name
                "a_simple_shader",

                # Vertex shader
                """#version 330
                uniform mat4 modelViewProj;
                in vec3 position;
                void main() {
                    gl_Position = modelViewProj * vec4(position, 1.0);
                }""",

                """#version 330
                out vec4 color;
                uniform float intensity;
                void main() {
                    color = vec4(vec3(intensity), 1.0);
                }"""
            )

            # Draw 2 triangles
            indices = np.array(
                [[0, 2], [1, 3], [2, 0]],
                dtype=np.int32)

            positions = np.array(
                [[-1, 1, 1, -1],
                 [-1, -1, 1, 1],
                 [0, 0, 0, 0]],
                dtype=np.float32)

            self.shader.bind()
            self.shader.uploadIndices(indices)
            self.shader.uploadAttrib("position", positions)
            self.shader.setUniform("intensity", 0.5)
        except ImportError:
            self.shader = None
            pass
Example #18
0
    def __init__(self):
        super(TestApp, self).__init__((1024, 768), "NanoGUI Test")

        window = Window(self, "Button demo")
        window.setPosition((15, 15))
        window.setLayout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")
        b.setCallback(cb)

        b = Button(window, "Styled", entypo.ICON_ROCKET)
        b.setBackgroundColor(Color(0, 0, 1.0, 0.1))
        b.setCallback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.setFlags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))
        b.setChangeCallback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.setFlags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.setFlags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))

        ToolButton(tools, entypo.ICON_CLOUD)
        ToolButton(tools, entypo.ICON_FF)
        ToolButton(tools, entypo.ICON_COMPASS)
        ToolButton(tools, entypo.ICON_INSTALL)

        Label(window, "Popup buttons", "sans-bold")
        popupBtn = PopupButton(window, "Popup", entypo.ICON_EXPORT)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        popupBtn = PopupButton(popup, "Recursive popup", entypo.ICON_FLASH)
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())
        CheckBox(popup, "Another check box")

        window = Window(self, "Basic widgets")
        window.setPosition((200, 15))
        window.setLayout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.setCallback(cb2)
        b.setCallback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.setCallback(cb2)
        b.setCallback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.setCallback(cb2)
        b.setCallback(cb)

        import os
        import sys
        os.chdir(sys.path[0])
        try:
            icons = nanogui.loadImageDirectory(self.nvgContext(), "icons")
        except:
            try:
                icons = nanogui.loadImageDirectory(self.nvgContext(), "../icons")
            except:
                icons = nanogui.loadImageDirectory(self.nvgContext(), "../resources/icons")


        Label(window, "Image panel & scroll panel", "sans-bold")
        imagePanelBtn = PopupButton(window, "Image Panel")
        imagePanelBtn.setIcon(entypo.ICON_FOLDER)
        popup = imagePanelBtn.popup()
        vscroll = VScrollPanel(popup)
        imgPanel = ImagePanel(vscroll)
        imgPanel.setImages(icons)
        popup.setFixedSize((245, 150))

        img_window = Window(self, "Selected image")
        img_window.setPosition((710, 15))
        img_window.setLayout(GroupLayout())

        imgView = ImageView(img_window, icons[0][0])

        def cb(i):
            print("Selected item %i" % i)
            imgView.bindImage(icons[i][0])
        imgPanel.setCallback(cb)

        imgView.setGridThreshold(3)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.setCallback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.setCallback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window, ["Combo box item 1", "Combo box item 2",
                          "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)
        chb = CheckBox(window, "Flag 1", cb)
        chb.setChecked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)
        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.setLayout(BoxLayout(Orientation.Horizontal,
                                  Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.setValue(0.5)
        slider.setFixedWidth(80)

        textBox = TextBox(panel)
        textBox.setFixedSize((60, 25))
        textBox.setValue("50")
        textBox.setUnits("%")
        textBox.setFontSize(20)
        textBox.setAlignment(TextBox.Alignment.Right)

        def cb(value):
            textBox.setValue("%i" % int(value * 100))
        slider.setCallback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))
        slider.setFinalCallback(cb)

        window = Window(self, "Misc. widgets")
        window.setPosition((425, 15))
        window.setLayout(GroupLayout())

        tabWidget = TabWidget(window)
        layer = tabWidget.createTab("Color Wheel")
        layer.setLayout(GroupLayout())

        Label(layer, "Color wheel widget", "sans-bold")
        ColorWheel(layer)

        layer = tabWidget.createTab("Function Graph")
        layer.setLayout(GroupLayout())
        Label(layer, "Function graph widget", "sans-bold")

        graph = Graph(layer, "Some function")
        graph.setHeader("E = 2.35e-3")
        graph.setFooter("Iteration 89")
        values = [0.5 * (0.5 * math.sin(i / 10.0) +
                         0.5 * math.cos(i / 23.0) + 1)
                  for i in range(100)]
        graph.setValues(values)
        tabWidget.setActiveTab(0)

        window = Window(self, "Grid of small widgets")
        window.setPosition((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2,
                            Alignment.Middle, 15, 5)
        layout.setColAlignment(
            [Alignment.Maximum, Alignment.Fill])
        layout.setSpacing(0, 10)
        window.setLayout(layout)

        Label(window, "Floating point :", "sans-bold")
        floatBox = TextBox(window)
        floatBox.setEditable(True)
        floatBox.setFixedSize((100, 20))
        floatBox.setValue("50")
        floatBox.setUnits("GiB")
        floatBox.setDefaultValue("0.0")
        floatBox.setFontSize(16)
        floatBox.setFormat("[-]?[0-9]*\\.?[0-9]+")

        Label(window, "Positive integer :", "sans-bold")
        intBox = IntBox(window)
        intBox.setEditable(True)
        intBox.setFixedSize((100, 20))
        intBox.setValue(50)
        intBox.setUnits("Mhz")
        intBox.setDefaultValue("0")
        intBox.setFontSize(16)
        intBox.setFormat("[1-9][0-9]*")
        intBox.setSpinnable(True)
        intBox.setMinValue(1)
        intBox.setValueIncrement(2)

        Label(window, "Checkbox :", "sans-bold")

        cb = CheckBox(window, "Check me")
        cb.setFontSize(16)
        cb.setChecked(True)

        Label(window, "Combo box :", "sans-bold")
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.setFontSize(16)
        cobo.setFixedSize((100, 20))

        Label(window, "Color button :", "sans-bold")
        popupBtn = PopupButton(window, "", 0)
        popupBtn.setBackgroundColor(Color(1, 0.47, 0, 1))
        popupBtn.setFontSize(16)
        popupBtn.setFixedSize((100, 20))
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())

        colorwheel = ColorWheel(popup)
        colorwheel.setColor(popupBtn.backgroundColor())

        colorBtn = Button(popup, "Pick")
        colorBtn.setFixedSize((100, 25))
        c = colorwheel.color()
        colorBtn.setBackgroundColor(c)

        def cb(value):
            colorBtn.setBackgroundColor(value)

        colorwheel.setCallback(cb)

        def cb(pushed):
            if (pushed):
                popupBtn.setBackgroundColor(colorBtn.backgroundColor())
                popupBtn.setPushed(False)
        colorBtn.setChangeCallback(cb)

        self.performLayout()

        try:
            import numpy as np

            self.shader = GLShader()
            self.shader.init(
                # An identifying name
                "a_simple_shader",

                # Vertex shader
                """#version 330
                uniform mat4 modelViewProj;
                in vec3 position;
                void main() {
                    gl_Position = modelViewProj * vec4(position, 1.0);
                }""",

                """#version 330
                out vec4 color;
                uniform float intensity;
                void main() {
                    color = vec4(vec3(intensity), 1.0);
                }"""
            )

            # Draw 2 triangles
            indices = np.array(
                [[0, 2], [1, 3], [2, 0]],
                dtype=np.int32)

            positions = np.array(
                [[-1, 1, 1, -1],
                 [-1, -1, 1, 1],
                 [0, 0, 0, 0]],
                dtype=np.float32)

            self.shader.bind()
            self.shader.uploadIndices(indices)
            self.shader.uploadAttrib("position", positions)
            self.shader.setUniform("intensity", 0.5)
        except ImportError:
            self.shader = None
            pass
Example #19
0
    def __init__(self):
        super(TestApp, self).__init__((1024, 768), "NanoGUI Test")
        self.shader = None

        window = Window(self, "Button demo")
        window.set_position((15, 15))
        window.set_layout(GroupLayout())

        Label(window, "Push buttons", "sans-bold")
        b = Button(window, "Plain button")

        def cb():
            print("pushed!")

        b.set_callback(cb)

        b = Button(window, "Styled", icons.FA_ROCKET)
        b.set_background_color(Color(0, 0, 1.0, 0.1))
        b.set_callback(cb)

        Label(window, "Toggle buttons", "sans-bold")
        b = Button(window, "Toggle me")
        b.set_flags(Button.Flags.ToggleButton)

        def change_cb(state):
            print("Toggle button state: %s" % str(state))

        b.set_change_callback(change_cb)

        Label(window, "Radio buttons", "sans-bold")
        b = Button(window, "Radio button 1")
        b.set_flags(Button.Flags.RadioButton)
        b = Button(window, "Radio button 2")
        b.set_flags(Button.Flags.RadioButton)

        Label(window, "A tool palette", "sans-bold")
        tools = Widget(window)
        tools.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        ToolButton(tools, icons.FA_CLOUD)
        ToolButton(tools, icons.FA_FAST_FORWARD)
        ToolButton(tools, icons.FA_COMPASS)
        ToolButton(tools, icons.FA_UTENSILS)

        Label(window, "Popup buttons", "sans-bold")
        popup_btn = PopupButton(window, "Popup", icons.FA_FLASK)
        popup = popup_btn.popup()
        popup.set_layout(GroupLayout())
        Label(popup, "Arbitrary widgets can be placed here")
        CheckBox(popup, "A check box")
        # popup right
        popup_btn = PopupButton(popup, "Recursive popup", icons.FA_CHART_PIE)
        popup_right = popup_btn.popup()
        popup_right.set_layout(GroupLayout())
        CheckBox(popup_right, "Another check box")
        # popup left
        popup_btn = PopupButton(popup, "Recursive popup", icons.FA_DNA)
        popup_btn.set_side(Popup.Side.Left)
        popup_left = popup_btn.popup()
        popup_left.set_layout(GroupLayout())
        CheckBox(popup_left, "Another check box")

        window = Window(self, "Basic widgets")
        window.set_position((200, 15))
        window.set_layout(GroupLayout())

        Label(window, "Message dialog", "sans-bold")
        tools = Widget(window)
        tools.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))

        def cb2(result):
            print("Dialog result: %i" % result)

        b = Button(tools, "Info")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Information, "Title",
                                "This is an information message")
            dlg.set_callback(cb2)

        b.set_callback(cb)

        b = Button(tools, "Warn")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a warning message")
            dlg.set_callback(cb2)

        b.set_callback(cb)

        b = Button(tools, "Ask")

        def cb():
            dlg = MessageDialog(self, MessageDialog.Type.Warning, "Title",
                                "This is a question message", "Yes", "No",
                                True)
            dlg.set_callback(cb2)

        b.set_callback(cb)

        import os
        import sys
        os.chdir(sys.path[0])
        try:
            icons_data = nanogui.load_image_directory(self.nvg_context(),
                                                      "icons")
        except:
            try:
                icons_data = nanogui.load_image_directory(
                    self.nvg_context(), "../icons")
            except:
                icons_data = nanogui.load_image_directory(
                    self.nvg_context(), "../resources/icons")

        Label(window, "Image panel & scroll panel", "sans-bold")
        image_panel_btn = PopupButton(window, "Image Panel")
        image_panel_btn.set_icon(icons.FA_IMAGES)
        popup = image_panel_btn.popup()
        vscroll = VScrollPanel(popup)
        img_panel = ImagePanel(vscroll)
        img_panel.set_images(icons_data)
        popup.set_fixed_size((245, 150))

        img_window = Window(self, "Selected image")
        img_window.set_position((710, 15))
        img_window.set_layout(GroupLayout())

        img_view = ImageView(img_window)
        img_view.set_image(
            Texture(icons_data[0][1] + ".png",
                    Texture.InterpolationMode.Trilinear,
                    Texture.InterpolationMode.Nearest))
        img_view.center()

        def cb(i):
            print("Selected item %i" % i)
            img_view.set_image(
                Texture(icons_data[i][1] + ".png",
                        Texture.InterpolationMode.Trilinear,
                        Texture.InterpolationMode.Nearest))

        img_panel.set_callback(cb)

        Label(window, "File dialog", "sans-bold")
        tools = Widget(window)
        tools.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 6))
        b = Button(tools, "Open")
        valid = [("png", "Portable Network Graphics"), ("txt", "Text file")]

        def cb():
            result = nanogui.file_dialog(valid, False)
            print("File dialog result = %s" % result)

        b.set_callback(cb)
        b = Button(tools, "Save")

        def cb():
            result = nanogui.file_dialog(valid, True)
            print("File dialog result = %s" % result)

        b.set_callback(cb)

        Label(window, "Combo box", "sans-bold")
        ComboBox(window,
                 ["Combo box item 1", "Combo box item 2", "Combo box item 3"])
        Label(window, "Check box", "sans-bold")

        def cb(state):
            print("Check box 1 state: %s" % state)

        chb = CheckBox(window, "Flag 1", cb)
        chb.set_checked(True)

        def cb(state):
            print("Check box 2 state: %s" % state)

        CheckBox(window, "Flag 2", cb)

        Label(window, "Progress bar", "sans-bold")
        self.progress = ProgressBar(window)

        Label(window, "Slider and text box", "sans-bold")

        panel = Widget(window)
        panel.set_layout(
            BoxLayout(Orientation.Horizontal, Alignment.Middle, 0, 20))

        slider = Slider(panel)
        slider.set_value(0.5)
        slider.set_fixed_width(80)

        text_box = TextBox(panel)
        text_box.set_fixed_size((60, 25))
        text_box.set_value("50")
        text_box.set_units("%")
        text_box.set_font_size(20)
        text_box.set_alignment(TextBox.Alignment.Right)

        def cb(value):
            text_box.set_value("%i" % int(value * 100))

        slider.set_callback(cb)

        def cb(value):
            print("Final slider value: %i" % int(value * 100))

        slider.set_final_callback(cb)

        window = Window(self, "Misc. widgets")
        window.set_position((425, 15))
        window.set_layout(GroupLayout())

        tab_widget = TabWidget(window)
        layer = Widget(tab_widget)
        layer.set_layout(GroupLayout())
        tab_widget.append_tab("Color Wheel", layer)

        Label(layer, "Color wheel widget", "sans-bold")
        ColorWheel(layer)

        layer = Widget(tab_widget)
        layer.set_layout(GroupLayout())
        tab_widget.append_tab("Function Graph", layer)
        Label(layer, "Function graph widget", "sans-bold")

        graph = Graph(layer, "Some function")
        graph.set_header("E = 2.35e-3")
        graph.set_footer("Iteration 89")
        values = [
            0.5 * (0.5 * math.sin(i / 10.0) + 0.5 * math.cos(i / 23.0) + 1)
            for i in range(100)
        ]
        graph.set_values(values)

        # Dummy tab used to represent the last tab button.
        plus_id = tab_widget.append_tab("+", Widget(tab_widget))

        def tab_cb(index):
            if index == plus_id:
                global counter
                # When the "+" tab has been clicked, simply add a new tab.
                tab_name = "Dynamic {0}".format(counter)
                layer_dyn = Widget(tab_widget)
                layer_dyn.set_layout(GroupLayout())
                new_id = tab_widget.insert_tab(tab_widget.tab_count() - 1,
                                               tab_name, layer_dyn)
                Label(layer_dyn, "Function graph widget", "sans-bold")
                graph_dyn = Graph(layer_dyn, "Dynamic function")

                graph_dyn.set_header("E = 2.35e-3")
                graph_dyn.set_footer("Iteration {0}".format(index * counter))
                values_dyn = [
                    0.5 * abs((0.5 * math.sin(i / 10.0 + counter)) +
                              (0.5 * math.cos(i / 23.0 + 1 + counter)))
                    for i in range(100)
                ]
                graph_dyn.set_values(values_dyn)
                counter += 1
                # We must invoke the layout manager after adding tabs dynamically
                self.perform_layout()
                tab_widget.set_selected_id(new_id)

        tab_widget.set_callback(tab_cb)

        window = Window(self, "Grid of small widgets")
        window.set_position((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2, Alignment.Middle, 15, 5)
        layout.set_col_alignment([Alignment.Maximum, Alignment.Fill])
        layout.set_spacing(0, 10)
        window.set_layout(layout)

        Label(window, "Floating point :", "sans-bold")
        float_box = TextBox(window)
        float_box.set_editable(True)
        float_box.set_fixed_size((100, 20))
        float_box.set_value("50")
        float_box.set_units("GiB")
        float_box.set_default_value("0.0")
        float_box.set_font_size(16)
        float_box.set_format("[-]?[0-9]*\\.?[0-9]+")

        Label(window, "Positive integer :", "sans-bold")
        int_box = IntBox(window)
        int_box.set_editable(True)
        int_box.set_fixed_size((100, 20))
        int_box.set_value(50)
        int_box.set_units("Mhz")
        int_box.set_default_value("0")
        int_box.set_font_size(16)
        int_box.set_format("[1-9][0-9]*")
        int_box.set_spinnable(True)
        int_box.set_min_value(1)
        int_box.set_value_increment(2)

        Label(window, "Checkbox :", "sans-bold")

        cb = CheckBox(window, "Check me")
        cb.set_font_size(16)
        cb.set_checked(True)

        Label(window, "Combo box :", "sans-bold")
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.set_font_size(16)
        cobo.set_fixed_size((100, 20))

        Label(window, "Color picker :", "sans-bold")
        cp = ColorPicker(window, Color(255, 120, 0, 255))
        cp.set_fixed_size((100, 20))

        def cp_final_cb(color):
            print("ColorPicker Final Callback: [{0}, {1}, {2}, {3}]".format(
                color.r, color.g, color.b, color.w))

        cp.set_final_callback(cp_final_cb)

        # setup a fast callback for the color picker widget on a new window
        # for demonstrative purposes
        window = Window(self, "Color Picker Fast Callback")
        window.set_position((425, 300))
        layout = GridLayout(Orientation.Horizontal, 2, Alignment.Middle, 15, 5)
        layout.set_col_alignment([Alignment.Maximum, Alignment.Fill])
        layout.set_spacing(0, 10)
        window.set_layout(layout)
        window.set_position((425, 500))
        Label(window, "Combined: ")
        b = Button(window, "ColorWheel", icons.FA_INFINITY)
        Label(window, "Red: ")
        red_int_box = IntBox(window)
        red_int_box.set_editable(False)
        Label(window, "Green: ")
        green_int_box = IntBox(window)
        green_int_box.set_editable(False)
        Label(window, "Blue: ")
        blue_int_box = IntBox(window)
        blue_int_box.set_editable(False)
        Label(window, "Alpha: ")
        alpha_int_box = IntBox(window)

        def cp_fast_cb(color):
            b.set_background_color(color)
            b.set_text_color(color.contrasting_color())
            red = int(color.r * 255.0)
            red_int_box.set_value(red)
            green = int(color.g * 255.0)
            green_int_box.set_value(green)
            blue = int(color.b * 255.0)
            blue_int_box.set_value(blue)
            alpha = int(color.w * 255.0)
            alpha_int_box.set_value(alpha)

        cp.set_callback(cp_fast_cb)

        self.perform_layout()

        self.render_pass = RenderPass([self])
        self.render_pass.set_clear_color(0, Color(0.3, 0.3, 0.32, 1.0))

        if nanogui.api == 'opengl':
            vertex_shader = """
            #version 330
            uniform mat4 mvp;
            in vec3 position;
            void main() {
                gl_Position = mvp * vec4(position, 1.0);
            }"""

            fragment_shader = """
            #version 330
            out vec4 color;
            uniform float intensity;
            void main() {
                color = vec4(vec3(intensity), 1.0);
            }"""
        elif nanogui.api == 'gles2' or nanogui.api == 'gles3':
            vertex_shader = """
            precision highp float;
            uniform mat4 mvp;
            attribute vec3 position;
            void main() {
                gl_Position = mvp * vec4(position, 1.0);
            }"""

            fragment_shader = """
            precision highp float;
            uniform float intensity;
            void main() {
                gl_FragColor = vec4(vec3(intensity), 1.0);
            }"""
        elif nanogui.api == 'metal':
            vertex_shader = """
            using namespace metal;
            struct VertexOut {
                float4 position [[position]];
            };

            vertex VertexOut vertex_main(const device packed_float3 *position,
                                         constant float4x4 &mvp,
                                         uint id [[vertex_id]]) {
                VertexOut vert;
                vert.position = mvp * float4(position[id], 1.f);
                return vert;
            }"""

            fragment_shader = """
            using namespace metal;
            fragment float4 fragment_main(const constant float &intensity) {
                return float4(intensity);
            }"""

        self.shader = Shader(
            self.render_pass,
            # An identifying name
            "A simple shader",
            vertex_shader,
            fragment_shader)

        self.shader.set_buffer("indices",
                               np.array([0, 1, 2, 2, 3, 0], dtype=np.uint32))
        self.shader.set_buffer(
            "position",
            np.array([[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 0]],
                     dtype=np.float32))

        self.shader.set_buffer("intensity", np.array(0.5, dtype=np.float32))
Example #20
0
        cobo = ComboBox(window, ["Item 1", "Item 2", "Item 3"])
        cobo.setFontSize(16)
        cobo.setFixedSize(Vector2i(100, 20))

        Label(window, "Color button :", "sans-bold")
        popupBtn = PopupButton(window, "", 0)
        popupBtn.setBackgroundColor(Color(1, 0.47, 0, 1))
        popupBtn.setFontSize(16)
        popupBtn.setFixedSize(Vector2i(100, 20))
        popup = popupBtn.popup()
        popup.setLayout(GroupLayout())

        colorwheel = ColorWheel(popup)
        colorwheel.setColor(popupBtn.backgroundColor())

        colorBtn = Button(popup, "Pick")
        colorBtn.setFixedSize(Vector2i(100, 25))
        c = colorwheel.color()
        colorBtn.setBackgroundColor(c)

        def cb(value):
            colorBtn.setBackgroundColor(value)

        colorwheel.setCallback(cb)

        def cb(pushed):
            if (pushed):
                popupBtn.setBackgroundColor(colorBtn.backgroundColor())
                popupBtn.setPushed(False)
        colorBtn.setChangeCallback(cb)