def __init__(self, title, message): self._window = None # A Dialog is just a widget, so you make its child a layout just like # a Window. dlg = gui.Dialog(title) # Add the message text em = self.window.theme.font_size dlg_layout = gui.Vert(em, gui.Margins(em, em, em, em)) dlg_layout.add_child(gui.Label(message)) # Add the Ok button. We need to define a callback function to handle # the click. ok_button = gui.Button("Ok") ok_button.set_on_clicked(self._on_ok) # We want the Ok button to be an the right side, so we need to add # a stretch item to the layout, otherwise the button will be the size # of the entire row. A stretch item takes up as much space as it can, # which forces the button to be its minimum size. button_layout = gui.Horiz() button_layout.add_stretch() button_layout.add_child(ok_button) # Add the button layout, dlg_layout.add_child(button_layout) # ... then add the layout as the child of the Dialog dlg.add_child(dlg_layout)
def _on_menu_about(self): # Show a simple dialog. Although the Dialog is actually a widget, you can # treat it similar to a Window for layout and put all the widgets in a # layout which you make the only child of the Dialog. em = self.window.theme.font_size dlg = gui.Dialog("About") # Add the text dlg_layout = gui.Vert(em, gui.Margins(em, em, em, em)) dlg_layout.add_child(gui.Label("Open3D GUI Example")) # Add the Ok button. We need to define a callback function to handle # the click. ok = gui.Button("OK") ok.set_on_clicked(self._on_about_ok) # We want the Ok button to be an the right side, so we need to add # a stretch item to the layout, otherwise the button will be the size # of the entire row. A stretch item takes up as much space as it can, # which forces the button to be its minimum size. h = gui.Horiz() h.add_stretch() h.add_child(ok) h.add_stretch() dlg_layout.add_child(h) dlg.add_child(dlg_layout) self.window.show_dialog(dlg)