diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..46c323d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "env": { + "PYTHONPATH": "${workspaceFolder}" + } + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a787151 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +## Textporter - + +Basic developer instructions here. diff --git a/dialog extractor.py b/dialog extractor.py index c66ef44..ad808a5 100644 --- a/dialog extractor.py +++ b/dialog extractor.py @@ -3,31 +3,23 @@ import fitz # PyMuPDF for PDF handling import re from krita import Krita +from collections import ChainMap # Load default character styles from an .ini file def load_default_styles_from_ini(file_path): config = configparser.ConfigParser() config.read(file_path) - character_styles = {} + + ini_dict = {section: dict(config.items(section)) for section in config.sections()} + default_values = {'DefaultStyle': + { + 'color':'0,0,0', + 'font':'Arial', + 'size':'12' + }} - for section in config.sections(): - color_str = config.get(section, "color", fallback="0,0,0") - color = [int(c) for c in color_str.split(",")] # Store color as [R, G, B] list - character_styles[section] = { - "font": config.get(section, "font", fallback="Arial"), - "size": config.getint(section, "size", fallback=14), - "color": color - } - - # Check if "default" is present, else add a default entry - if "default" not in character_styles: - character_styles["default"] = { - "font": "Arial", - "size": 14, - "color": [0, 0, 0] - } - - return character_styles + merged_dict = {section: dict(ChainMap(ini_dict.get(section, {}), default_values[section])) for section in default_values} + return merged_dict # Save character styles dictionary to JSON file @@ -160,11 +152,12 @@ def add_dialogue_to_krita(pdf_file, page_ranges): # Main usage example if __name__ == "__main__": # Load default styles from .ini file + print(" ✨ Loading default styles from settings.ini") default_styles = load_default_styles_from_ini("settings.ini") print(default_styles) print("------------------------") # Path to the PDF file - pdf_file = "/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/Mimosa_FernNorfolk.docx.pdf" + #pdf_file = "/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/Mimosa_FernNorfolk.docx.pdf" # read in the text file an populate the characters #default_styles = parse_character_styles_from_pdf(pdf_file, default_styles) @@ -178,5 +171,5 @@ def add_dialogue_to_krita(pdf_file, page_ranges): # Save parsed character styles to JSON for future use #save_character_styles_to_json(default_styles, "/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/character_styles.json") #load parsed character styles from JSON - default_styles = load_character_styles_from_json("/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/character_styles.json") - print(default_styles.keys()) \ No newline at end of file + #default_styles = load_character_styles_from_json("/home/dave/Documents/Comic Jams/366_DungeonsAndBreakfast/character_styles.json") + #print(default_styles.keys()) \ No newline at end of file diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..75910d4 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,53 @@ +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. + +[[package]] +name = "configparser" +version = "7.1.0" +description = "Updated configparser from stdlib for earlier Pythons." +optional = false +python-versions = ">=3.8" +files = [ + {file = "configparser-7.1.0-py3-none-any.whl", hash = "sha256:98e374573c4e10e92399651e3ba1c47a438526d633c44ee96143dec26dad4299"}, + {file = "configparser-7.1.0.tar.gz", hash = "sha256:eb82646c892dbdf773dae19c633044d163c3129971ae09b49410a303b8e0a5f7"}, +] + +[package.extras] +doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +test = ["pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-ruff (>=0.2.1)", "types-backports"] + +[[package]] +name = "krita" +version = "0.1" +description = "" +optional = false +python-versions = "*" +files = [] +develop = false + +[package.source] +type = "git" +url = "https://github.com/rbreu/krita-python-mock.git" +reference = "HEAD" +resolved_reference = "4848ef748ba1ce36faf0a6510c53c86178ab8c65" + +[[package]] +name = "pymupdf" +version = "1.24.13" +description = "A high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents." +optional = false +python-versions = ">=3.9" +files = [ + {file = "PyMuPDF-1.24.13-cp39-abi3-macosx_10_9_x86_64.whl", hash = "sha256:c11bb9198af69d490b4b346421db827d875a28fbc760d239e691d4b3ed12b5ad"}, + {file = "PyMuPDF-1.24.13-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:240d5c43daa9278db50d609162b48f673ab256d7e5c73eea67af517c1fc2d47c"}, + {file = "PyMuPDF-1.24.13-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:e4c8808e62afbbde0f7b9c4151c4b1a5735911c2d39c34332860df600dba76f8"}, + {file = "PyMuPDF-1.24.13-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c830610e4fde237fcf0532f1f8c1381453f48c164a5eadd0c6e5fd0bea1ca8e3"}, + {file = "PyMuPDF-1.24.13-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:4520558580ac6b5a7164fda29fbc14e39d3114fd803420721500edbf47d04872"}, + {file = "PyMuPDF-1.24.13-cp39-abi3-win32.whl", hash = "sha256:ab22828d4fc205791ef1332a64893cbfc38cd9c331c5f46ae4537372ffee6fc1"}, + {file = "PyMuPDF-1.24.13-cp39-abi3-win_amd64.whl", hash = "sha256:ec17914e4a560f4070212a2e84db5cc8b561d85d1ead193605a22f9561b03148"}, + {file = "PyMuPDF-1.24.13.tar.gz", hash = "sha256:6ec3ab3c6d5cba60bfcf58daaa2d1a5b700b0366ce52be666445007351461fa4"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "^3.12" +content-hash = "56fd47df7cabba813a90f663d6e06bdce1680e32b77380324f20801af1efb189" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9966b36 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "textporter" +version = "0.1.0" +description = "Description Here" +authors = ["Dave Hingley "] +license = "TBC" +readme = "README.md" +package-mode = false + +[tool.poetry.dependencies] +python = "^3.12" +configparser = "^7.1.0" +pymupdf = "^1.24.13" +krita = {git = "https://github.com/rbreu/krita-python-mock.git"} + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/settings.ini b/settings.ini index 14e63cd..408d05e 100644 --- a/settings.ini +++ b/settings.ini @@ -1,4 +1,4 @@ [DefaultStyle] font = Arial size = 30 -color = black +color = 0,0,0