From 22f4c03aee60ba4b90d1a676e4e5f8d000675fef Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 26 Mar 2014 21:51:33 +0000 Subject: [PATCH] Better startup code --- source/carla | 62 ++++++++++++++++++++-------------------- source/carla-patchbay | 64 +++++++++++++++++++++--------------------- source/carla-plugin | 17 +++++++---- source/carla-rack | 64 +++++++++++++++++++++--------------------- source/carla_shared.py | 2 +- source/carla_style.py | 19 ++++--------- 6 files changed, 111 insertions(+), 117 deletions(-) diff --git a/source/carla b/source/carla index 71b31c044..4d010e7b2 100755 --- a/source/carla +++ b/source/carla @@ -293,6 +293,13 @@ class CarlaHostW(HostWindow): # ----------------------------------------------------------------- + def showEvent(self, event): + HostWindow.showEvent(self, event) + + # set our gui as parent for all plugins UIs + if gCarla.host is not None: + gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(self.winId())) + def resizeEvent(self, event): HostWindow.resizeEvent(self, event) self.updateInfoLabelXandSize() @@ -307,41 +314,28 @@ class CarlaHostW(HostWindow): # Main if __name__ == '__main__': - # ------------------------------------------------------------- - # App initialization - - app = CarlaApplication() - - # ------------------------------------------------------------- - # Set-up custom signal handling - - setUpSignals() - # ------------------------------------------------------------- # Read CLI args - appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0] + initName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0] libPrefix = None - projectFilename = None - argv = app.arguments() - argc = len(argv) + for arg in sys.argv: + if arg.startswith("--with-appname="): + initName = os.path.basename(arg.replace("--with-initname=", "")) - for i in range(argc): - if i == 0: continue - argument = argv[i] + elif arg.startswith("--with-libprefix="): + libPrefix = arg.replace("--with-libprefix=", "") - if argument.startswith("--with-appname="): - appName = os.path.basename(argument.replace("--with-appname=", "")) + # ------------------------------------------------------------- + # App initialization - elif argument.startswith("--with-libprefix="): - libPrefix = argument.replace("--with-libprefix=", "") + app = CarlaApplication("Carla2", libPrefix) - elif os.path.exists(argument): - projectFilename = argument + # ------------------------------------------------------------- + # Set-up custom signal handling - if libPrefix is not None: - app.addLibraryPath(os.path.join(libPrefix, "lib", "carla")) + setUpSignals() # ------------------------------------------------------------- # Init host backend @@ -350,21 +344,25 @@ if __name__ == '__main__': gCarla.isLocal = True gCarla.isPlugin = False - initHost(appName, libPrefix) + initHost(initName, libPrefix) # ------------------------------------------------------------- # Create GUI gCarla.gui = CarlaHostW() - # set our gui as parent for all plugins UIs - gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(gCarla.gui.winId())) - # ------------------------------------------------------------- # Load project file if set - if projectFilename is not None: - gCarla.gui.loadProjectLater(projectFilename) + args = app.arguments() + + if len(args) > 1: + arg = args[-1] + + if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix="): + pass + elif os.path.exists(arg): + gCarla.gui.loadProjectLater(arg) # ------------------------------------------------------------- # Show GUI @@ -374,4 +372,4 @@ if __name__ == '__main__': # ------------------------------------------------------------- # App-Loop - sys.exit(app.exec_()) + app.exit_exec() diff --git a/source/carla-patchbay b/source/carla-patchbay index bea037871..573947ebe 100755 --- a/source/carla-patchbay +++ b/source/carla-patchbay @@ -32,45 +32,41 @@ class CarlaHostW(HostWindow): self.fContainer = CarlaPatchbayW(self) self.setupContainer(True, self.fContainer.themeData) -# ------------------------------------------------------------------------------------------------------------ -# Main - -if __name__ == '__main__': - # ------------------------------------------------------------- - # App initialization + # ----------------------------------------------------------------- - app = CarlaApplication("Carla2-Patchbay") + def showEvent(self, event): + HostWindow.showEvent(self, event) - # ------------------------------------------------------------- - # Set-up custom signal handling + # set our gui as parent for all plugins UIs + if gCarla.host is not None: + gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(self.winId())) - setUpSignals() +# ------------------------------------------------------------------------------------------------------------ +# Main +if __name__ == '__main__': # ------------------------------------------------------------- # Read CLI args - appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0] + initName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0] libPrefix = None - projectFilename = None - argv = app.arguments() - argc = len(argv) + for arg in sys.argv: + if arg.startswith("--with-appname="): + initName = os.path.basename(arg.replace("--with-initname=", "")) - for i in range(argc): - if i == 0: continue - argument = argv[i] + elif arg.startswith("--with-libprefix="): + libPrefix = arg.replace("--with-libprefix=", "") - if argument.startswith("--with-appname="): - appName = os.path.basename(argument.replace("--with-appname=", "")) + # ------------------------------------------------------------- + # App initialization - elif argument.startswith("--with-libprefix="): - libPrefix = argument.replace("--with-libprefix=", "") + app = CarlaApplication("Carla2-Patchbay", libPrefix) - elif os.path.exists(argument): - projectFilename = argument + # ------------------------------------------------------------- + # Set-up custom signal handling - if libPrefix is not None: - app.addLibraryPath(os.path.join(libPrefix, "lib", "carla")) + setUpSignals() # ------------------------------------------------------------- # Init host backend @@ -80,21 +76,25 @@ if __name__ == '__main__': gCarla.isPlugin = False gCarla.processMode = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS - initHost(appName, libPrefix) + initHost(initName, libPrefix) # ------------------------------------------------------------- # Create GUI gCarla.gui = CarlaHostW() - # set our gui as parent for all plugins UIs - gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(gCarla.gui.winId())) - # ------------------------------------------------------------- # Load project file if set - if projectFilename is not None: - gCarla.gui.loadProjectLater(projectFilename) + args = app.arguments() + + if len(args) > 1: + arg = args[-1] + + if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix="): + pass + elif os.path.exists(arg): + gCarla.gui.loadProjectLater(arg) # ------------------------------------------------------------- # Show GUI @@ -104,4 +104,4 @@ if __name__ == '__main__': # ------------------------------------------------------------- # App-Loop - sys.exit(app.exec_()) + app.exit_exec() diff --git a/source/carla-plugin b/source/carla-plugin index 645de8a52..0b3a09a73 100755 --- a/source/carla-plugin +++ b/source/carla-plugin @@ -531,6 +531,13 @@ class CarlaMiniW(HostWindow, ExternalUI): # ------------------------------------------------------------------- # Qt events + def showEvent(self, event): + HostWindow.showEvent(self, event) + + # set our gui as parent for all plugins UIs + if gCarla.host is not None: + gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(self.winId())) + def closeEvent(self, event): self.closeExternalUI() HostWindow.closeEvent(self, event) @@ -728,9 +735,10 @@ if __name__ == '__main__': # ------------------------------------------------------------- # Init plugin host data - gCarla.isControl = False - gCarla.isLocal = True - gCarla.isPlugin = True + gCarla.isControl = False + gCarla.isLocal = True + gCarla.isPlugin = True + gCarla.processMode = ENGINE_PROCESS_MODE_CONTINUOUS_RACK # ------------------------------------------------------------- # Create GUI first @@ -744,9 +752,6 @@ if __name__ == '__main__': initHost("Carla-Plugin") - # set our gui as parent for all plugins UIs - gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(gCarla.gui.winId())) - # simulate an engire started callback engineCallback(None, ENGINE_CALLBACK_ENGINE_STARTED, 0, ENGINE_PROCESS_MODE_CONTINUOUS_RACK, ENGINE_TRANSPORT_MODE_PLUGIN, 0.0, "Plugin") diff --git a/source/carla-rack b/source/carla-rack index 2fdface0e..4415468d8 100755 --- a/source/carla-rack +++ b/source/carla-rack @@ -32,45 +32,41 @@ class CarlaHostW(HostWindow): self.fContainer = CarlaRackW(self) self.setupContainer(False) -# ------------------------------------------------------------------------------------------------------------ -# Main - -if __name__ == '__main__': - # ------------------------------------------------------------- - # App initialization + # ----------------------------------------------------------------- - app = CarlaApplication("Carla2-Rack") + def showEvent(self, event): + HostWindow.showEvent(self, event) - # ------------------------------------------------------------- - # Set-up custom signal handling + # set our gui as parent for all plugins UIs + if gCarla.host is not None: + gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(self.winId())) - setUpSignals() +# ------------------------------------------------------------------------------------------------------------ +# Main +if __name__ == '__main__': # ------------------------------------------------------------- # Read CLI args - appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0] + initName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0] libPrefix = None - projectFilename = None - argv = app.arguments() - argc = len(argv) + for arg in sys.argv: + if arg.startswith("--with-appname="): + initName = os.path.basename(arg.replace("--with-initname=", "")) - for i in range(argc): - if i == 0: continue - argument = argv[i] + elif arg.startswith("--with-libprefix="): + libPrefix = arg.replace("--with-libprefix=", "") - if argument.startswith("--with-appname="): - appName = os.path.basename(argument.replace("--with-appname=", "")) + # ------------------------------------------------------------- + # App initialization - elif argument.startswith("--with-libprefix="): - libPrefix = argument.replace("--with-libprefix=", "") + app = CarlaApplication("Carla2-Rack", libPrefix) - elif os.path.exists(argument): - projectFilename = argument + # ------------------------------------------------------------- + # Set-up custom signal handling - if libPrefix is not None: - app.addLibraryPath(os.path.join(libPrefix, "lib", "carla")) + setUpSignals() # ------------------------------------------------------------- # Init host backend @@ -80,21 +76,25 @@ if __name__ == '__main__': gCarla.isPlugin = False gCarla.processMode = ENGINE_PROCESS_MODE_CONTINUOUS_RACK - initHost(appName, libPrefix) + initHost(initName, libPrefix) # ------------------------------------------------------------- # Create GUI gCarla.gui = CarlaHostW() - # set our gui as parent for all plugins UIs - gCarla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(gCarla.gui.winId())) - # ------------------------------------------------------------- # Load project file if set - if projectFilename is not None: - gCarla.gui.loadProjectLater(projectFilename) + args = app.arguments() + + if len(args) > 1: + arg = args[-1] + + if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix="): + pass + elif os.path.exists(arg): + gCarla.gui.loadProjectLater(arg) # ------------------------------------------------------------- # Show GUI @@ -104,4 +104,4 @@ if __name__ == '__main__': # ------------------------------------------------------------- # App-Loop - sys.exit(app.exec_()) + app.exit_exec() diff --git a/source/carla_shared.py b/source/carla_shared.py index 165180c8f..cd0b1a5f9 100644 --- a/source/carla_shared.py +++ b/source/carla_shared.py @@ -485,7 +485,7 @@ def findTool(toolDir, toolName): # ------------------------------------------------------------------------------------------------------------ # Init host -def initHost(appName, libPrefix = None, failError = True): +def initHost(initName, libPrefix = None, failError = True): # ------------------------------------------------------------- # Set Carla library name diff --git a/source/carla_style.py b/source/carla_style.py index ab1bb9add..aa200a0d6 100644 --- a/source/carla_style.py +++ b/source/carla_style.py @@ -43,25 +43,23 @@ from carla_shared import * # ------------------------------------------------------------------------------------------------------------ class CarlaApplication(object): - def __init__(self, appName = "Carla2"): + def __init__(self, appName = "Carla2", libPrefix = None): object.__init__(self) # try to find style dir - foundDir = False + if libPrefix is not None: + QApplication.addLibraryPath(os.path.join(libPrefix, "lib", "carla")) - if os.path.exists(os.path.join(CWD, "modules", "theme", "styles")): + elif os.path.exists(os.path.join(CWD, "modules", "theme", "styles")): QApplication.addLibraryPath(os.path.join(CWD, "modules", "theme")) - foundDir = True elif os.path.exists(os.path.join(CWD, "styles")): QApplication.addLibraryPath(CWD) - foundDir = True elif os.path.exists(os.path.join(CWD, "..", "styles")): QApplication.addLibraryPath(os.path.join(CWD, "..")) - foundDir = True - if not foundDir: + else: self._createApp(appName) return @@ -235,13 +233,6 @@ class CarlaApplication(object): else: self.fApp.setWindowIcon(QIcon(":/scalable/carla.svg")) - def addLibraryPath(self, libdir): - if not os.path.exists(libdir): - return - - #QApplication.addLibraryPath(libdir) - #self.loadSettings() - def arguments(self): return self.fApp.arguments()