Exemple #1
0
def qt_template(world):
    """Runs a custom Qt frame around a visualization window"""
    if not glinit.available('PyQt5'):
        print(
            "PyQt5 is not available on your system, try sudo apt-get install python-qt5"
        )
        return

    #Qt objects must be explicitly deleted for some reason in PyQt5...
    g_mainwindow = None

    #All Qt functions must be called in the vis thread.
    #To hook into that thread, you will need to pass a window creation function into vis.customUI.
    def makefunc(gl_backend):
        global g_mainwindow
        g_mainwindow = MyQtMainWindow(gl_backend)
        return g_mainwindow

    vis.customUI(makefunc)
    vis.add("world", world)
    vis.setWindowTitle("Klamp't Qt test")
    vis.spin(float('inf'))
    vis.kill()
    #Safe cleanup of all Qt objects created in makefunc.
    #If you don't have this, PyQt5 complains about object destructors being called from the wrong thread
    del g_mainwindow
Exemple #2
0
def main():
    print("""
===============================================================================
A program to quickly browse Klamp't objects. 

USAGE: %s [item1 item2 ...]

where the given items are world, robot, terrain, object, or geometry files. Run
it without arguments

   %s

for an empty reference world. You may add items to the reference world using
the `Add to World` button.  If you know what items to use in the reference
world, run it with

   %s world.xml

or 

   %s item1 item2 ...

where the items are world, robot, terrain, object, or geometry files.
===============================================================================
""" % (sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0]))
    #must be explicitly deleted for some reason in PyQt5...
    g_browser = None

    def makefunc(gl_backend):
        global g_browser
        browser = ResourceBrowser(gl_backend)
        g_browser = browser
        dw = QtWidgets.QDesktopWidget()
        x = dw.width() * 0.8
        y = dw.height() * 0.8
        browser.setFixedSize(x, y)
        for fn in sys.argv[1:]:
            res = browser.world.readFile(fn)
            if not res:
                print("Unable to load model", fn)
                print("Quitting...")
                sys.exit(1)
            print("Added", fn, "to world")
        if len(sys.argv) > 1:
            browser.emptyVisPlugin.add("world", browser.world)
        return browser

    vis.customUI(makefunc)
    vis.setWindowTitle("Klamp't Resource Browser")
    vis.run()
    del g_browser
    return

    #this code below is incorrect...
    app = QtWidgets.QApplication(sys.argv)
    browser = ResourceBrowser()
    for fn in sys.argv[1:]:
        res = browser.world.readFile(fn)
        if not res:
            print("Unable to load model", fn)
            print("Quitting...")
            sys.exit(1)
        print("Added", fn, "to world")
    if len(sys.argv) > 1:
        browser.emptyVisPlugin.add("world", browser.world)
    dw = QtWidgets.QDesktopWidget()
    x = dw.width() * 0.8
    y = dw.height() * 0.8
    browser.setFixedSize(x, y)
    #browser.splitter.setWindowState(QtCore.Qt.WindowMaximized)
    browser.setWindowTitle("Klamp't Resource Browser")
    browser.show()
    # Start the main loop.
    res = app.exec_()
    return res