def initialize_inviwo_app(self): # Inviwo requires that a logcentral is created. self.lc = ivw.LogCentral() # Create and register a console logger self.cl = ivw.ConsoleLogger() self.lc.registerLogger(self.cl) # Create the inviwo application self.app = ivwapp.InviwoApplicationQt() self.app.registerModules() # load a workspace # self.app.network.load(self.app.getPath(ivw.PathType.Workspaces) + "/boron.inv") # Make sure the app is ready self.app.update() self.app.waitForPool() self.app.update() self.app.network.clear()
def main(workspace=None, properties=None, screenshot=None, run=False, ipython=False, list_processors=False, list_properties=None): """ Constructs a Inviwo application and loads a workspace. :param workspace: Path to workspace to load, defaults load boron.inv :param properties: List of processor identifiers and property paths to show in the property list widget :param screenshot: Path to a output file for a screenshot of the 'Canvas' processor :paran run: Start the qt event loop, default False :param ipython: Register the ipython event loop hook. Use the ipython magic command '#gui inviwo' to start. :param list_processors: Output a list of all processors, default False. :param list_properties: Output a list of all properties of the Processors identifiers given If python can't find the i`inviwopy` module use the '--libdir' CLI argument to pass in the path to inviwo bin directory. If the program complains about missing QT plugins try passing the '--libdir' CLI argument. It will set the 'QT_PLUGIN_PATH' in python. Or you can try and set it manually. """ try: import inviwopy as ivw import inviwopyapp as qt except ModuleNotFoundError as e: print("Did you remember to add the path to 'inviwppy.*.pyd' to the PYTHONPATH?") print("Powershell: $Env:PYTHONPATH=\"<path to inviwo bin folder>\"") print("CMD: set PYTHONPATH=\"<path to inviwo bin folder>\"") print("BASH: export PYTHONPATH=\"<path to inviwo bin folder>\"") print("You can also use the libdir cli parameter to pass the path.") raise e def addIpythonGuiHook(inviwoApp: qt.InviwoApplicationQt, name: str = "inviwo") -> bool: """ Add a event loop hook in IPyhton to enable simultanious use of the IPython terminal and the inviwo qt gui use the IPython magic function '#gui inviwo' to start the event loop after calling this function. See https://ipython.readthedocs.io/en/stable/config/eventloops.html """ try: import IPython except ImportError: return False def inputhook(context): while not context.input_is_ready(): inviwoApp.update() IPython.terminal.pt_inputhooks.register(name, inputhook) return True res = [] # Inviwo requires that a logcentral is created. lc = ivw.LogCentral() res.append(lc) # Create and register a console logger cl = ivw.ConsoleLogger() lc.registerLogger(cl) # Create the inviwo application try: app = qt.InviwoApplicationQt() except ... as e: print("failed to create app") print(e) raise e res.append(app) app.registerModules() # load a workspace workspace = (workspace if workspace else (app.getPath(ivw.PathType.Workspaces) + "/boron.inv")) app.network.load(workspace) if properties: plw = ivw.qt.PropertyListWidget(app) res.append(plw) for path in properties: if len(path.split('.')) == 1: if proc := app.network.getProcessorByIdentifier(path): plw.addProcessorProperties(proc) else: if prop := app.network.getProperty(path): plw.addPropertyWidgets(prop)
import inviwopy as ivw import inviwopyapp as qt if __name__ == '__main__': # Inviwo requires that a logcentral is created. lc = ivw.LogCentral() # Create and register a console logger cl = ivw.ConsoleLogger() lc.registerLogger(cl) # Create the inviwo application app = qt.InviwoApplicationQt() app.registerModules() # load a workspace app.network.load(app.getPath(ivw.PathType.Workspaces) + "/boron.inv") print("Load processors:") for p in app.network.processors: print(p.identifier) plw = ivw.qt.PropertyListWidget(app) plw.addProcessorProperties(app.network.VolumeRaycaster) plw.addProcessorProperties(app.network.VolumeSource) plw.move(100,100) plw.show() # Make sure the app is ready app.update() app.waitForPool()