diff --git a/makefile b/makefile index e423f96..bb57cb0 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -UI := $(wildcard src/ui/*.ui) $(wildcard src/ui/*/*.ui) $(wildcard src/ui/*.qrc) +UI := $(wildcard manuskript/ui/*.ui) $(wildcard manuskript/ui/*/*.ui) $(wildcard manuskript/ui/*.qrc) UIs= $(UI:.ui=.py) $(UI:.qrc=_rc.py) TS := $(wildcard i18n/*.ts) QMs= $(TS:.ts=.qm) @@ -6,22 +6,23 @@ QMs= $(TS:.ts=.qm) ui: $(UIs) run: $(UIs) - python3 src/main.py +# python3 manuskript/main.py + bin/manuskript debug: $(UIs) - gdb --args python3 src/main.py + gdb --args python3 manuskript/main.py lineprof: - kernprof -l -v src/main.py + kernprof -l -v manuskript/main.py profile: - python3 -m cProfile -s 'cumtime' src/main.py | more + python3 -m cProfile -s 'cumtime' manuskript/main.py | more compile: - cd src && python3 setup.py build_ext --inplace + cd manuskript && python3 setup.py build_ext --inplace callgraph: - cd src; pycallgraph myoutput -- main.py + cd manuskript; pycallgraph myoutput -- main.py translation: pylupdate5 -noobsolete i18n/manuskript.pro diff --git a/manuskript/exporter/__init__.py b/manuskript/exporter/__init__.py index cf9be85..a1c718d 100644 --- a/manuskript/exporter/__init__.py +++ b/manuskript/exporter/__init__.py @@ -1,31 +1,32 @@ #!/usr/bin/env python -#--!-- coding: utf8 --!-- - +# --!-- coding: utf8 --!-- import collections -from qt import * -from .html import htmlExporter -from .arbo import arboExporter -from .odt import odtExporter + +from PyQt5.QtWidgets import qApp + +from manuskript.exporter.arbo import arboExporter +from manuskript.exporter.html import htmlExporter +from manuskript.exporter.odt import odtExporter formats = collections.OrderedDict([ - #Format - # Readable name - # Class - # QFileDialog filter + # Format + # Readable name + # Class + # QFileDialog filter ('html', ( - qApp.translate("exporter", "HTML"), + qApp.translate("exporter", "HTML"), htmlExporter, qApp.translate("exporter", "HTML Document (*.html)"))), ('arbo', ( - qApp.translate("exporter", "Arborescence"), + qApp.translate("exporter", "Arborescence"), arboExporter, None)), - ('odt', ( - qApp.translate("exporter", "OpenDocument (LibreOffice)"), + ('odt', ( + qApp.translate("exporter", "OpenDocument (LibreOffice)"), odtExporter, qApp.translate("exporter", "OpenDocument (*.odt)"))), ('epub', ( - "ePub (not yet)", + "ePub (not yet)", None, None)), -]) \ No newline at end of file +]) diff --git a/manuskript/exporter/arbo.py b/manuskript/exporter/arbo.py index 2664eeb..cece381 100644 --- a/manuskript/exporter/arbo.py +++ b/manuskript/exporter/arbo.py @@ -1,53 +1,48 @@ #!/usr/bin/env python -#--!-- coding: utf8 --!-- - -from qt import * -from enums import * -from functions import * +# --!-- coding: utf8 --!-- +import os + +from manuskript.functions import mainWindow + class arboExporter(): - requires = ["path"] - + def __init__(self): pass - + def doCompile(self, path): - #FIXME: overwrites when items have identical names + # FIXME: overwrites when items have identical names mw = mainWindow() root = mw.mdlOutline.rootItem - + def writeItem(item, path): if item.isFolder(): path2 = os.path.join(path, item.title()) - + try: os.mkdir(path2) except FileExistsError: pass - + for c in item.children(): writeItem(c, path2) - + else: ext = ".t2t" if item.isT2T() else \ - ".html" if item.isHTML() else \ - ".txt" + ".html" if item.isHTML() else \ + ".txt" path2 = os.path.join(path, item.title() + ext) f = open(path2, "w") text = self.formatText(item.text(), item.type()) f.write(text) - + for c in root.children(): writeItem(c, path) - - + def formatText(self, text, _type): if _type == "t2t": # Empty lines for headers text = "\n\n\n" + text - + return text - - - diff --git a/manuskript/exporter/basic.py b/manuskript/exporter/basic.py index 46136d8..a53c434 100644 --- a/manuskript/exporter/basic.py +++ b/manuskript/exporter/basic.py @@ -1,31 +1,28 @@ #!/usr/bin/env python -#--!-- coding: utf8 --!-- - -from qt import * -from enums import * -from functions import * -import subprocess +# --!-- coding: utf8 --!-- + import re +import subprocess + class basicExporter(): - def __init__(self): pass - + def runT2T(self, text, target="html"): - + cmdl = ['txt2tags', '-t', target, '--enc=utf-8', '--no-headers', '-o', '-', '-'] - + cmd = subprocess.Popen(('echo', text), stdout=subprocess.PIPE) try: - output = subprocess.check_output(cmdl, stdin=cmd.stdout, stderr=subprocess.STDOUT) # , cwd="/tmp" + output = subprocess.check_output(cmdl, stdin=cmd.stdout, stderr=subprocess.STDOUT) # , cwd="/tmp" except subprocess.CalledProcessError as e: print("Error!") return text cmd.wait() - + return output.decode("utf-8") - + def htmlBody(self, text): text = text.replace("\n", "") text = re.sub(r".*
]*?>(.*).*", "\\1", text) diff --git a/manuskript/exporter/html.py b/manuskript/exporter/html.py index 82e83e8..69b704f 100644 --- a/manuskript/exporter/html.py +++ b/manuskript/exporter/html.py @@ -1,45 +1,41 @@ #!/usr/bin/env python -#--!-- coding: utf8 --!-- - -from qt import * -from enums import * -from functions import * -from exporter.basic import basicExporter +# --!-- coding: utf8 --!-- +from manuskript.exporter.basic import basicExporter +from manuskript.functions import mainWindow + class htmlExporter(basicExporter): - requires = ["filename"] - + def __init__(self): pass - + def doCompile(self, filename): mw = mainWindow() root = mw.mdlOutline.rootItem - + html = "" - + def appendItem(item): if item.isFolder(): html = "" title = "