Reorganizing some stuff

This commit is contained in:
Olivier Keshavjee 2016-04-04 20:00:19 +02:00
parent d20a9972c9
commit 0554ac519e
7 changed files with 100 additions and 42 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
from manuskript.exporter.manuskript import manuskriptExporter
from manuskript.exporter.manuskript import manuskriptExporter
from manuskript.exporter.mmd import mmdExporter
from manuskript.exporter.pandoc import pandocExporter

View file

@ -6,6 +6,8 @@ import subprocess
from PyQt5.QtWidgets import QWidget
from manuskript.models.outlineModel import outlineItem
class basicExporter:
@ -71,13 +73,59 @@ class basicFormat:
self.description = description
@classmethod
def settingsWidget(self):
def settingsWidget(cls):
return QWidget()
@classmethod
def previewWidgetBefore(self):
def previewWidgetBefore(cls):
return QWidget()
@classmethod
def previewWidgetAfter(self):
return QWidget()
def previewWidgetAfter(cls):
return QWidget()
@classmethod
def concatenate(cls, item:outlineItem,
processTitle=lambda x: x + "\n",
processText=lambda x: x + "\n",
processContent=lambda x: x + "\n",
textSep="", folderSep="", textFolderSep="", folderTextSep="") -> str:
r = ""
if not item.compile():
return ""
if item.level() >= 0: # item is not root
# Adds item title
r += processTitle(item.title())
# Adds item text
r += processText(item.text())
content = ""
# Add item children
last = None
for c in item.children():
# Separator
if last:
# Between folder
if last == c.type() == "folder":
content += folderSep
elif last == c.type() == "md":
content += textSep
elif last == "folder" and c.type() == "md":
content += folderTextSep
elif last == "md" and c.type() == "folder":
content += textFolderSep
content += cls.concatenate(c)
last = c.type()
r += processContent(content)
return r

View file

@ -1,35 +0,0 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
from PyQt5.QtWidgets import QTextEdit
from manuskript.exporter.basic import basicExporter, basicFormat
class markdownFormat(basicFormat):
name = "Markdown"
description = "A lightweigh markup language used by many tools."
implemented = False
requires = {
"Settings": True,
"PreviewBefore": True,
"PreviewAfter": False,
}
@classmethod
def settingsWidget(cls):
sW = QTextEdit()
return sW
class manuskriptExporter(basicExporter):
name = "Manuskript"
description = "Default exporter, provides basic formats used by other exporters."
exportTo = [
basicFormat("Plain text", "Simplest export to plain text. Allows you to use your own markup not understood "
"by manuskript, for example <a href='www.fountain.io'>Fountain</a>."),
markdownFormat,
basicFormat("OPML")
]
@classmethod
def isValid(cls):
return True

View file

@ -0,0 +1,21 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
from PyQt5.QtWidgets import QTextEdit
from manuskript.exporter.basic import basicExporter, basicFormat
from manuskript.exporter.manuskript.plainText import plainText
class manuskriptExporter(basicExporter):
name = "Manuskript"
description = "Default exporter, provides basic formats used by other exporters."
exportTo = [
plainText,
basicFormat("HTML"),
basicFormat("OPML")
]
@classmethod
def isValid(cls):
return True

View file

@ -0,0 +1,21 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
from PyQt5.QtWidgets import QTextEdit
from manuskript.exporter.basic import basicExporter, basicFormat
class plainText(basicFormat):
name = "Plain text"
description = "Simplest export to plain text. Allows you to use your own markup not understood " \
"by manuskript, for example <a href='www.fountain.io'>Fountain</a>."
implemented = False
requires = {
"Settings": True,
"PreviewBefore": True,
"PreviewAfter": False,
}
@classmethod
def settingsWidget(cls):
sW = QTextEdit()
return sW

View file

@ -1077,7 +1077,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
###############################################################################
def doCompile(self):
self.dialog = exporterDialog()
self.dialog = exporterDialog(mw=self)
self.dialog.show()
r = self.dialog.geometry()

View file

@ -14,11 +14,12 @@ from manuskript.ui.exporters.exportersManager import exportersManager
class exporterDialog(QWidget, Ui_exporter):
def __init__(self, parent=None):
def __init__(self, parent=None, mw=None):
QWidget.__init__(self, parent)
self.setupUi(self)
# Var
self.mw = mw
self.currentExporter = None
# Populates lite
@ -43,6 +44,8 @@ class exporterDialog(QWidget, Ui_exporter):
self.cmbExporters.currentIndexChanged.connect(self.updateUi)
self.cmbExporters.setCurrentIndex(1)
print(exporter.basic.basicFormat.concatenate(mw.mdlOutline.rootItem))
def updateUi(self, index):
name = self.cmbExporters.currentText()
exporterName = self.cmbExporters.currentData()