Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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):
if i < len(icons):
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)
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)
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)
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()
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))
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)
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))