def loadModule(self, module): if module.areaid not in self.areas_.keys(): self.loadArea(Struct(idarea=module.areaid, descripcion=module.areaid)) module_ = Struct() module_.areaid = module.areaid module_.description = module.description module_.name = module.name self.modules_[module_.name] = module_ self.moduleLoad(module)
def load(self): try: if self._loaded: return self.mainform_widget self.logger.debug("Loading action %s . . . ", self.name) w = self.prj.main_window if not self.mainform_widget: if self.prj._DGI.useDesktop(): self.mainform_widget = FLMainForm(w, self, load=False) else: from pineboolib.utils import Struct self.mainform_widget = Struct() self.mainform_widget.action = self self.mainform_widget.prj = self.prj try: self.load_script(getattr(self, "scriptform", None), self.mainform_widget) except Exception: self.logger.exception( "Error trying to load scriptform for %s", self.name) self._loaded = True self.logger.debug("End of action load %s (iface:%s ; widget:%s)", self.name, self.mainform_widget.iface, self.mainform_widget.widget) return self.mainform_widget except Exception as e: self.logger.exception("While loading action %s", self.name) return None
def loadModule(self, module): logger.debug("loadModule: Procesando %s ", module.name) # Creamos pestañas de areas y un vBLayout por cada módulo. Despues ahí metemos los actions de cada módulo if module.areaid not in self.areas: self.loadArea( Struct(idarea=module.areaid, descripcion=module.areaid)) moduleToolBox = self.toolBoxs[self.areas.index(module.areaid)] vBLayout = QtWidgets.QWidget() vBLayout.layout = QtWidgets.QVBoxLayout() # layout de cada módulo. vBLayout.layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize) vBLayout.layout.setSpacing(0) vBLayout.layout.setContentsMargins(0, 0, 0, 0) vBLayout.setLayout(vBLayout.layout) if module.icon[0] != "": pixmap = QtGui.QPixmap(module.icon) moduleToolBox.addItem(vBLayout, QtGui.QIcon(pixmap), module.description) else: moduleToolBox.addItem(vBLayout, module.description) try: self.moduleLoad(vBLayout.layout, module) except Exception: logger.exception("ERROR al procesar modulo %s", module.name)
def addModuleInTab(self, module): if MainForm.debugLevel > 50: print("- Procesando %s " % module.name) #Creamos pestañas de areas y un vBLayout por cada módulo. Despues ahí metemos los actions de cada módulo if module.areaid not in self.areas: self.addAreaTab( Struct(idarea=module.areaid, descripcion=module.areaid)) moduleToolBox = self.toolBoxs[self.areas.index(module.areaid)] vBLayout = QtGui.QWidget() vBLayout.layout = QtGui.QVBoxLayout() #layout de cada módulo. vBLayout.layout.setSizeConstraint(QtGui.QLayout.SetMinAndMaxSize) vBLayout.layout.setSpacing(0) vBLayout.layout.setContentsMargins(0, 0, 0, 0) vBLayout.setLayout(vBLayout.layout) moduleToolBox.addItem(vBLayout, module.description) try: self.moduleLoad(vBLayout.layout, module) except Exception: print("ERROR al procesar modulo %s:" % module.name) print(traceback.format_exc(), "---")
def loadModule(self, module): if module.areaid not in self.areas_.keys(): self.loadArea( Struct(idarea=module.areaid, descripcion=module.areaid)) module_ = Struct() module_.areaid = module.areaid module_.description = module.description module_.name = module.name self.modules_[module_.name] = module_ self.moduleLoad(module)
def run(self): # TODO: Refactorizar esta función en otras más sencillas # Preparar temporal if self.deleteCache and not not os.path.exists( self.dir("cache/%s" % self.dbname)): self.logger.debug("DEVELOP: DeleteCache Activado\nBorrando %s", self.dir("cache/%s" % self.dbname)) for root, dirs, files in os.walk(self.dir("cache/%s" % self.dbname), topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) # borrando de share # for root, dirs, files in os.walk(self.dir("../share/pineboo"), topdown=False): # for name in files: # if name.endswith("qs.py") or name.endswith("qs.py.debug") or name.endswith("qs.xml"): # os.remove(os.path.join(root, name)) if not os.path.exists(self.dir("cache")): os.makedirs(self.dir("cache")) # Conectar: if not self.conn: self.conn = PNConnection(self.dbname, self.dbserver.host, self.dbserver.port, self.dbauth.username, self.dbauth.password, self.dbserver.type) if self.conn.conn is False: return False # Se verifica que existen estas tablas for table in ("flareas", "flmodules", "flfiles", "flgroups", "fllarge", "flserial", "flusers", "flvar"): self.conn.manager().createSystemTable(table) util = FLUtil() util.writeSettingEntry(u"DBA/lastDB", self.dbname) self.cur = self.conn.cursor() self.areas = {} self.cur.execute( """ SELECT idarea, descripcion FROM flareas WHERE 1 = 1""") for idarea, descripcion in self.cur: self.areas[idarea] = Struct(idarea=idarea, descripcion=descripcion) self.areas["sys"] = Struct(idarea="sys", descripcion="Area de Sistema") # Obtener modulos activos self.cur.execute( """ SELECT idarea, idmodulo, descripcion, icono FROM flmodules WHERE bloqueo = %s """ % self.conn.driver().formatValue("bool", "True", False)) self.modules = {} for idarea, idmodulo, descripcion, icono in self.cur: icono = clearXPM(icono) self.modules[idmodulo] = Module(self, idarea, idmodulo, descripcion, icono) file_object = open(filedir("..", "share", "pineboo", "sys.xpm"), "r") icono = file_object.read() file_object.close() icono = clearXPM(icono) self.modules["sys"] = Module(self, "sys", "sys", "Administración", icono) # Descargar proyecto . . . self.cur.execute( """ SELECT idmodulo, nombre, sha FROM flfiles ORDER BY idmodulo, nombre """ ) size_ = len(self.cur.fetchall()) self.cur.execute( """ SELECT idmodulo, nombre, sha FROM flfiles ORDER BY idmodulo, nombre """ ) f1 = open(self.dir("project.txt"), "w") self.files = {} if self._DGI.useDesktop() and self._DGI.localDesktop(): tiempo_ini = time.time() if not os.path.exists(self.dir("cache")): raise AssertionError # if self.parseProject: if self._DGI.useDesktop() and self._DGI.localDesktop(): util.createProgressDialog("Pineboo", size_) p = 0 for idmodulo, nombre, sha in self.cur: p = p + 1 if self._DGI.useDesktop() and self._DGI.localDesktop(): util.setProgress(p) util.setLabelText("Convirtiendo %s." % nombre) if idmodulo not in self.modules: continue # I fileobj = File(self, idmodulo, nombre, sha) if nombre in self.files: self.logger.warn( "run: file %s already loaded, overwritting..." % nombre) self.files[nombre] = fileobj self.modules[idmodulo].add_project_file(fileobj) f1.write(fileobj.filekey + "\n") if os.path.exists(self.dir("cache", fileobj.filekey)): continue fileobjdir = os.path.dirname(self.dir("cache", fileobj.filekey)) if not os.path.exists(fileobjdir): os.makedirs(fileobjdir) cur2 = self.conn.cursor() sql = "SELECT contenido FROM flfiles WHERE idmodulo = %s AND nombre = %s AND sha = %s" % ( self.conn.driver().formatValue("string", idmodulo, False), self.conn.driver().formatValue("string", nombre, False), self.conn.driver().formatValue("string", sha, False)) cur2.execute(sql) for (contenido, ) in cur2: f2 = open(self.dir("cache", fileobj.filekey), "wb") # La cadena decode->encode corrige el bug de guardado de # AbanQ/Eneboo txt = "" try: # txt = contenido.decode("UTF-8").encode("ISO-8859-15") txt = contenido.encode("ISO-8859-15") except Exception: self.logger.exception("Error al decodificar %s %s", idmodulo, nombre) # txt = contenido.decode("UTF-8","replace").encode("ISO-8859-15","replace") txt = contenido.encode("ISO-8859-15", "replace") f2.write(txt) if self.parseProject and nombre.endswith(".qs"): self.parseScript(self.dir("cache", fileobj.filekey)) if self._DGI.useDesktop() and self._DGI.localDesktop(): tiempo_fin = time.time() self.logger.info( "Descarga del proyecto completo a disco duro: %.3fs", (tiempo_fin - tiempo_ini)) # Cargar el núcleo común del proyecto idmodulo = 'sys' for root, dirs, files in os.walk(filedir("..", "share", "pineboo")): for nombre in files: if root.find("modulos") == -1: fileobj = File(self, idmodulo, nombre, basedir=root) self.files[nombre] = fileobj self.modules[idmodulo].add_project_file(fileobj) if self.parseProject and nombre.endswith(".qs"): self.parseScript(self.dir(root, nombre)) if self._DGI.useDesktop() and self._DGI.localDesktop(): try: util.destroyProgressDialog() except Exception as e: self.logger.error(e) self.loadTranslations() self.readState() self.acl_ = FLAccessControlLists() self.acl_.init_()
def load(self): if self.ui: del self.ui self.ui = uic.loadUi(filedir('plugins/mainform/pineboo/mainform.ui'), self) frameGm = self.frameGeometry() screen = QtWidgets.QApplication.desktop().screenNumber( QtWidgets.QApplication.desktop().cursor().pos()) centerPoint = QtWidgets.QApplication.desktop().screenGeometry( screen).center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft()) self.areasTab = QtWidgets.QTabWidget() self.areasTab.setTabPosition(QtWidgets.QTabWidget.West) self.formTab = QtWidgets.QTabWidget() try: self.areasTab.removeItem = self.areasTab.removeTab self.areasTab.addItem = self.areasTab.addTab except Exception: pass self.dockAreasTab = QtWidgets.QDockWidget() self.dockAreasTab.setWindowTitle("Módulos") #self.dockAreas = QtWidgets.QDockWidget() self.dockFavoritos = QtWidgets.QDockWidget() self.dockFavoritos.setWindowTitle("Favoritos") self.dockForm = QtWidgets.QDockWidget() self.dockAreasTab.setWidget(self.areasTab) self.dockAreasTab.setMaximumWidth(400) self.dockFavoritos.setMaximumWidth(400) self.dockFavoritos.setMaximumHeight(500) # self.dockAreasTab.setMinimumWidth(400) # self.dockAreasTab.setMaximumHeight(500) self.dockForm.setWidget(self.formTab) self.addDockWidget(Qt.RightDockWidgetArea, self.dockForm) # self.dockForm.setMaximumWidth(950) self.addDockWidget(Qt.LeftDockWidgetArea, self.dockFavoritos) self.addDockWidget(Qt.LeftDockWidgetArea, self.dockAreasTab) # self.dockAreasTab.show() # self.dockForm.show() # self.areasTab.removeItem(0) #Borramos tab de ejemplo. self.formTab.setTabsClosable(True) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.formTab.tabCloseRequested[int].connect(self.closeFormTab) self.formTab.removeTab(0) #app_icon = QtGui.QIcon('share/icons/pineboo-logo-16.png') # app_icon.addFile(filedir('share/icons/pineboo-logo-16.png'), # QtCore.QSize(16, 16)) # app_icon.addFile(filedir('share/icons/pineboo-logo-24.png'), # QtCore.QSize(24, 24)) # app_icon.addFile(filedir('share/icons/pineboo-logo-32.png'), # QtCore.QSize(32, 32)) # app_icon.addFile(filedir('share/icons/pineboo-logo-48.png'), # QtCore.QSize(48, 48)) # app_icon.addFile(filedir('share/icons/pineboo-logo-64.png'), # QtCore.QSize(64, 64)) # app_icon.addFile(filedir('share/icons/pineboo-logo-128.png'), # QtCore.QSize(128, 128)) # app_icon.addFile(filedir('share/icons/pineboo-logo-256.png'), # QtCore.QSize(256, 256)) # self.setWindowIcon(app_icon) self.setWindowIcon(QtGui.QIcon('share/icons/pineboo-logo-16.png')) self.actionAcercaQt.triggered.connect(pineboolib.main.aboutQt) self.actionAcercaPineboo.triggered.connect( pineboolib.main.aboutPineboo) self.actionFavoritos.triggered.connect(self.changeStateDockFavoritos) self.dockFavoritos.visibilityChanged.connect( self.changeStateActionFavoritos) self.actionModulos.triggered.connect(self.changeStateDockAreas) self.dockAreasTab.visibilityChanged.connect( self.changeStateActionAreas) self.actionTipografia.triggered.connect(pineboolib.main.fontDialog) self.menuPineboo.addSeparator() # self.actionEstilo.triggered.connect(pineboolib.main.styleDialog) pineboolib.main.initStyle(self.configMenu) self.setWindowTitle("Pineboo") logger.info("Módulos y pestañas ...") for k, area in sorted(pineboolib.project.areas.items()): self.loadArea(area) for k, module in sorted(pineboolib.project.modules.items()): self.loadModule(module) # Cargando Area desarrollo si procede ... sett_ = FLSettings() if (sett_.readBoolEntry("application/isDebuggerMode", False)): areaDevelop = Struct(idarea="dvl", descripcion="Desarrollo") self.loadArea(areaDevelop) self.loadDevelop() self.restoreOpenedTabs() self.loadPreferences() # Cargamos nombre de vertical util = FLUtil() verticalName = util.sqlSelect("flsettings", "valor", "flkey='verticalName'") cbPosInfo = util.sqlSelect("flsettings", "valor", "flkey='PosInfo'") if verticalName != None: statusText = verticalName if cbPosInfo == 'True': sys_ = SysType() statusText += "\t\t\t" + sys_.nameUser() + "@" + sys_.nameDB() if verticalName != None: self.statusBar().showMessage(statusText)
def run(self): # TODO: Refactorizar esta función en otras más sencillas # Preparar temporal if not os.path.exists(self.dir("cache")): os.makedirs(self.dir("cache")) if not os.path.exists(self.dir("cache")): os.makedirs(self.dir("cache")) # Conectar: self.conn = PNConnection(self.dbname, self.dbserver.host, self.dbserver.port, self.dbauth.username, self.dbauth.password) self.cur = self.conn.cursor() self.areas = {} self.cur.execute( """ SELECT idarea, descripcion FROM flareas WHERE bloqueo = TRUE """ ) for idarea, descripcion in self.cur: self.areas[idarea] = Struct(idarea=idarea, descripcion=descripcion) # Obtener modulos activos self.cur.execute( """ SELECT idarea, idmodulo, descripcion, icono FROM flmodules WHERE bloqueo = TRUE """ ) self.modules = {} for idarea, idmodulo, descripcion, icono in self.cur: self.modules[idmodulo] = Module(self, idarea, idmodulo, descripcion, icono) self.modules["sys"] = Module( self, "sys", "sys", "Administración", None) #Añadimos módulo sistema(falta icono) # Descargar proyecto . . . self.cur.execute( """ SELECT idmodulo, nombre, sha::varchar(16) FROM flfiles ORDER BY idmodulo, nombre """ ) f1 = open(self.dir("project.txt"), "w") self.files = {} tiempo_ini = time.time() if not os.path.exists(self.dir("cache")): raise AssertionError for idmodulo, nombre, sha in self.cur: if idmodulo not in self.modules: continue # I fileobj = File(self, idmodulo, nombre, sha) if nombre in self.files: print("WARN: file %s already loaded, overwritting..." % nombre) self.files[nombre] = fileobj self.modules[idmodulo].add_project_file(fileobj) f1.write(fileobj.filekey + "\n") if os.path.exists(self.dir("cache", fileobj.filekey)): continue fileobjdir = os.path.dirname(self.dir("cache", fileobj.filekey)) if not os.path.exists(fileobjdir): os.makedirs(fileobjdir) cur2 = self.conn.cursor() cur2.execute( "SELECT contenido FROM flfiles " + "WHERE idmodulo = %s AND nombre = %s " + " AND sha::varchar(16) = %s", [idmodulo, nombre, sha]) for (contenido, ) in cur2: f2 = open(self.dir("cache", fileobj.filekey), "wb") # La cadena decode->encode corrige el bug de guardado de AbanQ/Eneboo txt = "" try: #txt = contenido.decode("UTF-8").encode("ISO-8859-15") txt = contenido.encode("ISO-8859-15") except Exception: print("Error al decodificar", idmodulo, nombre) #txt = contenido.decode("UTF-8","replace").encode("ISO-8859-15","replace") txt = contenido.encode("ISO-8859-15", "replace") f2.write(txt) tiempo_fin = time.time() if Project.debugLevel > 50: print("Descarga del proyecto completo a disco duro: %.3fs" % (tiempo_fin - tiempo_ini)) # Cargar el núcleo común del proyecto idmodulo = 'sys' for root, dirs, files in os.walk(filedir("..", "share", "pineboo")): for nombre in files: fileobj = File(self, idmodulo, nombre, basedir=root) self.files[nombre] = fileobj self.modules[idmodulo].add_project_file(fileobj)