def regConfigFromPyPkg(pkgName: str): global cCache if not pkgName: return None eConf = cCache.get(pkgName, None) if eConf: return eConf fpath = Path(pkgResourcesRscFilename(pkgName, configYamlName)) if fpath.is_file(): regConfigFromFile(pkgName, fpath) if 0: listing = pkgResourcesListDir(pkgName, '') for entry in listing: if entry == configYamlName: continue mod = entry.replace(f'.{yamlExt}', '') modName = f'{pkgName}.{mod}' fpath = Path(pkgResourcesRscFilename(pkgName, entry)) if fpath.exists() and fpath.name.endswith(yamlExt): regConfigFromFile(modName, fpath)
def availableDapps(): try: listing = pkgResourcesListDir(dappsPkg, '') for fn in listing: path = pkgResourcesRscFilename(dappsPkg, fn) if not fn.startswith('_') and os.path.isdir(path): yield fn, path except Exception as err: log.debug(str(err))
async def init(self, ipfsop): # Import the assets assetsPath = pkgResourcesRscFilename('galacteek.templates', 'usersite/assets') self.assetsEntry = await ipfsop.addPath(assetsPath, recursive=True) if self.profile.ctx.hasRsc('ipfs-cube-64'): self.edag.root['media']['images']['ipfs-cube.png'] = \ self.edag.mkLink(self.profile.ctx.resources['ipfs-cube-64']) if self.profile.ctx.hasRsc('atom-feed'): self.edag.root['media']['images']['atom-feed.png'] = \ self.edag.mkLink(self.profile.ctx.resources['atom-feed']) self.edag.root['about.html'] = await self.renderLink( 'usersite/about.html')
async def load(self, source): try: count = 0 listing = pkgResourcesListDir(source.url, '') for fn in listing: if not fn.endswith('.yaml'): continue path = pkgResourcesRscFilename(source.url, fn) count += await self.importYamlHashmarks(path, source) return count except Exception as e: log.debug(str(e)) return 0
def discover(self): # TODO: move to config.yaml pkgList = ['galacteek-ld-web4'] for p in pkgList: pName = p.replace('-', '_') ctxModPath = f'{pName}.contexts' try: for ename in pkgResourcesListDir(ctxModPath, ''): if ename.startswith('_'): continue epath = pkgResourcesRscFilename(ctxModPath, ename) if not epath: continue self._fallbackNs[ename] = Path(epath) except Exception as err: log.debug(f'Could not discover for package: {p}: {err}') continue
def themesCompileAll(): commonPath = Path(pkgResourcesRscFilename('galacteek.ui.themes', '_common')) for name, path in themesList(): qrcPath = path.joinpath('theme.qrc') oPath = path.joinpath('theme_rc.py') initPath = path.joinpath('__init__.py') try: themeModule = modSpecImport(name, str(initPath)) theme = themeModule.theme theme.themePath = path except Exception: continue if theme.styleBaseTemplate: qssPath = path.joinpath('galacteek.qss') tPath = commonPath.joinpath(theme.styleBaseTemplate) try: with open(str(tPath), 'rt') as fd: tmpl = fd.read() except Exception: continue tmpl = tmplSub(tmpl, 'WIDGET_BGCOLOR', theme.colors.wBgColor) tmpl = tmplSub(tmpl, 'WIDGET_ITEM_HOVER_BGCOLOR', theme.colors.wItemBgColor) with open(str(qssPath), 'w+t') as fd: fd.write(tmpl) output = run(['pyrcc5', str(qrcPath), '-o', str(oPath)]) log.debug(output)
def themesList(): for name in pkgResourcesDirEntries(__name__): path = Path(pkgResourcesRscFilename('galacteek.ui.themes', name)) if path.is_dir(): yield name, path
def themeApply(self, themeName: str): exTheme = self.app.theme if exTheme: # There's already a theme installed if exTheme.styleModName and exTheme.styleModName in sys.modules: del sys.modules[exTheme.styleModName] libCommonPath = pkgResourcesRscFilename('galacteek.ui.themes', 'common.qss') themeDir = pkgResourcesRscFilename('galacteek.ui.themes', themeName) if not themeDir: return False initPath = Path(themeDir).joinpath('__init__.py') rcPath = Path(themeDir).joinpath('theme_rc.py') rcDotPath = f'galacteek.ui.themes.{themeName}.theme_rc' try: themeModule = modSpecImport(themeName, str(initPath)) modSpecImport('theme_rc', str(rcPath), sysModuleName=rcDotPath) except Exception as err: log.debug(f'Error importing theme {themeName}: {err}') style = GalacteekStyle() try: theme = themeModule.theme except Exception as err: log.debug(f'Invalid theme {themeName}: {err}') return False theme.themePath = Path(themeDir) theme.styleModName = rcDotPath sysName = self.app.system.lower() qssPath = f":/galacteek/ui/themes/{themeName}/galacteek.qss" qssPlatformPath = \ f":/galacteek/ui/themes/{themeName}/galacteek_{sysName}.qss" fontsQss = self.app.readQSSFile(libCommonPath) mainQss = self.app.readQSSFile(qssPath) pQss = self.app.readQSSFile(qssPlatformPath) qss = fontsQss + mainQss if pQss: self.app.setStyleSheet(qss + '\n' + pQss) else: self.app.setStyleSheet(qss) if style: self.app.setStyle(style) # self.fsWatcher.watch(themeDir) theme.apply(self.app) self.app.theme = theme return True
def ldRenderersRootPath(): return pkgResourcesRscFilename('galacteek.ld', 'renderers')
def ldContextsRootPath(): return pkgResourcesRscFilename('galacteek.ld', 'contexts')