Bläddra i källkod

use configuration via python files containing constants

Noah Vogt 2 år sedan
förälder
incheckning
34e468cb33

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 .vim
 __pycache__
+config/config.py

+ 8 - 2
README.md

@@ -85,7 +85,12 @@ Here is a example of a text body using the first three verses of *'Amazing Grace
 
 ### Configuration
 
-As of now, all Configuration is handled via constants in `slidegen.py`, which will change in the future. See the roadmap below.
+The configuration of *slidegen* is handled via constants in `*.py` files. The default configuration is stored in `config/default_config.py`, and in the same form a custom user-defined configuration can optionally be placed in `config/config.py`. You don't have to specify all the constants present in the default config, only the one's you want to change.
+
+For example, if you want to change the text color to green and the file extension the jpeg, your `config/config.py` could look like this:
+
+    TEXT_COLOR = "green"
+    FILE_EXTENSION = "jpeg"
 
 ## Roadmap
 
@@ -101,7 +106,8 @@ These are some issues and possible changes that will be addressed or at least co
 - better packaging and modularisation
 - add more optional metadata strings
 - use a more typical commandline argument system
-- add more documentation, especially explaining the slide generation and its Configuration
+- add more documentation, especially explaining the slide generation and its configuration
+- better handling of font path Configuration
 
 ## Licensing
 

+ 5 - 0
config/__init__.py

@@ -1 +1,6 @@
+from .default_config import *
 
+try:
+    from .config import *  # pyright: ignore [reportMissingImports]
+except ModuleNotFoundError:
+    pass

+ 3 - 13
config/default_config.py

@@ -15,11 +15,9 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-from os import name
-
 IMAGE_FORMAT = "jpeg"
 FILE_EXTENSION = "jpg"
-FILE_NAMEING = "folie"
+FILE_NAMEING = "slide"
 
 WIDTH = 1920
 HEIGHT = 1080
@@ -39,16 +37,8 @@ INFODISPLAY_ITEM_WIDTH = 20
 PLAYER_WIDTH = 560
 PLAYER_HEIGHT = 315
 
-BOLD_FONT_PATH = (
-    "/usr/share/fonts/TTF/century-gothic/CenturyGothicBold.ttf"
-    if name == "posix"
-    else "winPATH"
-)
-FONT_PATH = (
-    "/usr/share/fonts/TTF/century-gothic/CenturyGothic.ttf"
-    if name == "posix"
-    else "winPATH"
-)
+BOLD_FONT_PATH = "/usr/share/fonts/TTF/century-gothic/CenturyGothicBold.ttf"
+FONT_PATH = "/usr/share/fonts/TTF/century-gothic/CenturyGothic.ttf"
 FONT = "Century-Gothic"
 BOLD_FONT = "Century-Gothic-Bold"
 

+ 1 - 5
slidegen.py

@@ -35,11 +35,7 @@ from utils import (
 
 from slides import ClassicSongTemplate, ClassicStartSlide, ClassicSongSlide
 
-try:
-    import config.config as const  # pyright: ignore [reportMissingImports]
-except ModuleNotFoundError:
-    log("no costom config found, using defaults")
-    import config.default_config as const
+import config as const
 
 
 class Slidegen:

+ 2 - 6
slides/classic_song_slide.py

@@ -20,13 +20,9 @@ from wand.drawing import Drawing
 from wand.font import Font
 from wand.color import Color
 
-from .song_slide import SongSlide
-
+import config as const
 
-try:
-    import config.config as const  # pyright: ignore [reportMissingImports]
-except ModuleNotFoundError:
-    import config.default_config as const
+from .song_slide import SongSlide
 
 
 class ClassicSongSlide(SongSlide):

+ 3 - 6
slides/classic_song_template.py

@@ -20,14 +20,11 @@ from wand.drawing import Drawing
 from wand.color import Color
 from wand.font import Font
 
-from .song_template import SongTemplate
-
 from utils import get_empty_image
 
-try:
-    import config.config as const  # pyright: ignore [reportMissingImports]
-except ModuleNotFoundError:
-    import config.default_config as const
+import config as const
+
+from .song_template import SongTemplate
 
 
 class ClassicSongTemplate(SongTemplate):

+ 2 - 5
slides/classic_start_slide.py

@@ -19,12 +19,9 @@ from wand.image import Image
 from wand.color import Color
 from wand.font import Font
 
-from .start_slide import StartSlide
+import config as const
 
-try:
-    import config.config as const  # pyright: ignore [reportMissingImports]
-except ModuleNotFoundError:
-    import config.default_config as const
+from .start_slide import StartSlide
 
 
 class ClassicStartSlide(StartSlide):

+ 3 - 1
utils/img.py

@@ -18,7 +18,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 from wand.image import Image
 from wand.color import Color
 
+import config as const
+
 
 def get_empty_image() -> Image:
-    img = Image(width=1, height=1, background=Color("white"))
+    img = Image(width=1, height=1, background=Color(const.BG_COLOR))
     return img.clone()

+ 0 - 1
utils/log.py

@@ -13,7 +13,6 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
 """
 
 import sys

+ 1 - 4
utils/strings.py

@@ -15,10 +15,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-try:
-    import config.config as const  # pyright: ignore [reportMissingImports]
-except ModuleNotFoundError:
-    import config.default_config as const
+import config as const
 
 from .log import error_msg