Skip to content

Commit

Permalink
<Enhancement>[Theme Loader]: Use a modern method
Browse files Browse the repository at this point in the history
Make themes load in py2app packaged application

[#67]
  • Loading branch information
hasii2011 committed Nov 21, 2020
1 parent d39c477 commit 1229186
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
48 changes: 24 additions & 24 deletions albow/themes/ThemeLoader.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@

from logging import Logger
from logging import getLogger

import logging
from os import sep as osSep

import configparser
from configparser import ConfigParser
from configparser import SectionProxy

from ast import literal_eval as make_tuple

from pkg_resources import resource_filename

from albow.themes.Theme import Theme


class ThemeLoader:

DEFAULT_PKG = "albow.themes.resources"
DEFAULT_THEME_FILENAME = "default-theme.ini"
ROOT_THEME_NAME = "root"
DEFAULT_THEME_FILENAME: str = "default-theme.ini"

def __init__(self, themePkg: str = DEFAULT_PKG, themeFilename: str = DEFAULT_THEME_FILENAME):
"""
DEFAULT_PKG: str = "resources"
ROOT_THEME_NAME: str = "root"

def __init__(self, themePkg: str = DEFAULT_PKG, themeFilename: str = DEFAULT_THEME_FILENAME):
"""
"""
self.logger = logging.getLogger(__name__)
self.logger: Logger = getLogger(__name__)

self.themePkg: str = themePkg
self.themeFilename: str = themeFilename

self.themePkg = themePkg
self.themeFilename = themeFilename
self.themeFullFilename = self.findThemeFile()
self.topLevelClassThemes = []
self.themeRoot = None

def load(self):

config = configparser.ConfigParser()
config.read(self.themeFullFilename)
config = ConfigParser()

self.themeRoot = self.loadAClass(config[ThemeLoader.ROOT_THEME_NAME])
import pkgutil

bThemeData = pkgutil.get_data(__name__, f"{self.themePkg}{osSep}{self.themeFilename}")
themeData = bThemeData.decode('ascii')

self.logger.debug(f"Initial themeRoot: {self.themeRoot}")
self.logger.debug(f"{themeData=}")

config.read_string(themeData)

self.themeRoot = self.loadAClass(config[ThemeLoader.ROOT_THEME_NAME])

self.extractThemeInstances(config)
self.augmentInstancesWithBase()
Expand All @@ -56,13 +62,7 @@ def augmentInstancesWithBase(self):
setattr(embeddedTheme, "base", baseTheme)
self.logger.debug(f"Theme {embeddedTheme} has new base {baseTheme}")

def findThemeFile(self):

fileName = resource_filename(self.themePkg, self.themeFilename)

return fileName

def loadAClass(self, classDict: dict) -> Theme:
def loadAClass(self, classDict: SectionProxy) -> Theme:

themeName = classDict["name"]

Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
# The text of the README file
README = (HERE / "README.md").read_text()

DATA_FILES = [('albow/themes/resources', ['albow/themes/resources/default-theme.ini']),
('albow/themes/resources', ['albow/themes/resources/Vera.ttf']),
('albow/themes/resources', ['albow/themes/resources/VeraBd.ttf']),
]
setup(
name="python3-albow",
version="2.87",
version="2.89",
author='Humberto A. Sanchez II',
author_email='[email protected]',
description="A Little Bit of Widgetry for PyGame",
long_description=README,
long_description_content_type="text/markdown",
url="https://hasii2011.github.io",
url="https://github.com/hasii2011/albow-python-3",
packages=find_packages(),
include_package_data=True,
install_requires=['pygame', 'PyOpenGL', 'PyOpenGL-accelerate']
Expand Down

0 comments on commit 1229186

Please sign in to comment.