print("Módulos y pestañas ...") for k,area in sorted(project.areas.items()): main_window.addAreaTab(area) for k,module in sorted(project.modules.items()): main_window.addModuleInTab(module) if options.preload: print("Precarga ...") for action in project.actions: print("* * * Cargando acción %s . . . " % action) try: project.actions[action].load() except Exception: print(traceback.format_exc()) project.conn.conn.rollback() else: print("Abriendo interfaz ...") main_window.show() ret = app.exec_() mainForm.mainWindow = None del main_window del project return ret if __name__ == "__main__": ret = main() gc.collect() print("Closing Pineboo...") if ret: sys.exit(ret) else: sys.exit(0)
print("Abriendo interfaz ...") main_window.show() objaction.openDefaultForm() ret = app.exec_() mainForm.mainWindow = None return ret else: main_window = mainForm.mainWindow main_window.load() print("Módulos y pestañas ...") for k, area in sorted(project.areas.items()): main_window.addAreaTab(area) for k, module in sorted(project.modules.items()): main_window.addModuleInTab(module) print("Abriendo interfaz ...") main_window.show() ret = app.exec_() mainForm.mainWindow = None del main_window del project return ret if __name__ == "__main__": ret = main() gc.collect() print("Closing Pineboo...") if ret: sys.exit(ret) else: sys.exit(0)
def main(): """ Programa principal. Gestión de las opciones y la ayuda, así como inicializar todos los objetos. """ # TODO: Refactorizar función en otras más pequeñas parser = OptionParser() parser.add_option("-l", "--load", dest="project", help="load projects/PROJECT.xml and run it", metavar="PROJECT") parser.add_option("-c", "--connect", dest="connection", help="connect to database with user and password.", metavar="user:passwd:driver_alias@host:port/database") parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True, help="don't print status messages to stdout") parser.add_option("-a", "--action", dest="action", help="load action", metavar="ACTION") parser.add_option("--no-python-cache", action="store_true", dest="no_python_cache", default=False, help="Always translate QS to Python") parser.add_option( "--preload", action="store_true", dest="preload", default=False, help="Load everything. Then exit. (Populates Pineboo cache)") app = QtWidgets.QApplication(sys.argv) (options, args) = parser.parse_args() noto_fonts = [ "NotoSans-BoldItalic.ttf", "NotoSans-Bold.ttf", "NotoSans-Italic.ttf", "NotoSans-Regular.ttf", ] for fontfile in noto_fonts: QtGui.QFontDatabase.addApplicationFont( filedir("fonts/Noto_Sans", fontfile)) QtWidgets.QApplication.setStyle("QtCurve") font = QtGui.QFont('Noto Sans', 9) font.setBold(False) font.setItalic(False) QtWidgets.QApplication.setFont(font) pineboolib.no_python_cache = options.no_python_cache # Es necesario importarlo a esta altura, QApplication tiene que ser construido antes que cualquier widget mainForm = importlib.import_module("pineboolib.plugins.mainForm.%s.%s" % (pineboolib.main.Project.mainFormName, pineboolib.main.Project.mainFormName)) #mainForm = getattr(module_, "MainForm")() #from pineboolib import mainForm project = pineboolib.main.Project() if options.verbose: project.setDebugLevel(100) mainForm.MainForm.setDebugLevel(100) else: project.setDebugLevel(0) mainForm.MainForm.setDebugLevel(0) if options.project: if not options.project.endswith(".xml"): options.project += ".xml" prjpath = filedir("../projects", options.project) if not os.path.isfile(prjpath): raise ValueError("el proyecto %s no existe." % options.project) project.load(prjpath) elif options.connection: user, passwd, driver_alias, host, port, dbname = translate_connstring( options.connection) project.load_db(dbname, host, port, user, passwd, driver_alias) else: connection_window = pineboolib.DlgConnect.DlgConnect() connection_window.load() connection_window.show() ret = app.exec_() if connection_window.close(): #if connection_window.ruta: # prjpath = connection_window.ruta # print("Cargando desde ruta %r " % prjpath) # project.load(prjpath) #elif connection_window.database: if connection_window.database: print("Cargando credenciales") project.load_db(connection_window.database, connection_window.hostname, connection_window.portnumber, connection_window.username, connection_window.password, connection_window.driveralias) if not connection_window.ruta and not connection_window.database: sys.exit(ret) #Cargando spashscreen # Create and display the splash screen splash_pix = QtGui.QPixmap( filedir("../share/splashscreen/splash_%s.png" % project.dbname)) splash = QtWidgets.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint) splash.setMask(splash_pix.mask()) splash.show() frameGm = splash.frameGeometry() screen = QtWidgets.QApplication.desktop().screenNumber( QtWidgets.QApplication.desktop().cursor().pos()) centerPoint = QtWidgets.QApplication.desktop().screenGeometry( screen).center() frameGm.moveCenter(centerPoint) splash.move(frameGm.topLeft()) project.run() if project.conn.conn == False: return main() splash.showMessage("Iniciando proyecto ...") if options.verbose: print("Iniciando proyecto ...") splash.showMessage("Creando interfaz ...") if options.verbose: print("Creando interfaz ...") if options.action: objaction = None for k, module in list(project.modules.items()): try: if not module.load(): continue except Exception as err: print("ERROR:", err.__class__.__name__, str(err)) continue if options.action in module.actions: objaction = module.actions[options.action] if objaction is None: raise ValueError("Action name %s not found" % options.action) main_window = mainForm.mainWindow main_window.load() splash.showMessage("Módulos y pestañas ...") if options.verbose: print("Módulos y pestañas ...") for k, area in sorted(project.areas.items()): main_window.loadArea(area) for k, module in sorted(project.modules.items()): main_window.loadModule(module) splash.showMessage("Abriendo interfaz ...") if options.verbose: print("Abriendo interfaz ...") main_window.show() project.call("sys.widget.init()", [], None, True) objaction.openDefaultForm() splash.hide() ret = app.exec_() mainForm.mainWindow = None return ret else: main_window = mainForm.mainWindow main_window.load() ret = 0 splash.showMessage("Módulos y pestañas ...") if options.verbose: print("Módulos y pestañas ...") for k, area in sorted(project.areas.items()): main_window.loadArea(area) for k, module in sorted(project.modules.items()): main_window.loadModule(module) if options.preload: if options.verbose: print("Precarga ...") for action in project.actions: if options.verbose: print("* * * Cargando acción %s . . . " % action) try: project.actions[action].load() except Exception: print(traceback.format_exc()) project.conn.conn.rollback() else: splash.showMessage("Abriendo interfaz ...") if options.verbose: print("Abriendo interfaz ...") main_window.show() project.call("sys.widget.init()", [], None, True) splash.showMessage("Listo ...") QtCore.QTimer.singleShot(2000, splash.hide) ret = app.exec_() mainForm.mainWindow = None del main_window del project return ret