Cleaning up a bit

This commit is contained in:
Olivier Keshavjee 2016-03-29 19:24:35 +02:00
parent 2c0e3074ce
commit b676d126ba
3 changed files with 15 additions and 7 deletions

View file

@ -12,7 +12,7 @@ from PyQt5.QtGui import QBrush, QIcon, QPainter
from PyQt5.QtGui import QColor
from PyQt5.QtGui import QImage
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import qApp
from PyQt5.QtWidgets import qApp, QTextEdit
from manuskript.enums import Outline
@ -235,4 +235,15 @@ def findFirstFile(regex, path="resources"):
lst = os.listdir(p)
for l in lst:
if re.match(regex, l):
return os.path.join(p, l)
return os.path.join(p, l)
def HTML2PlainText(html):
"""
Ressource-inefficient way to convert HTML to plain text.
@param html:
@return:
"""
e = QTextEdit()
e.setHtml(html)
return e.toPlainText()

View file

@ -15,7 +15,7 @@ from manuskript import settings
from lxml import etree as ET
from manuskript.enums import Outline
from manuskript.functions import mainWindow, toInt, wordCount
from manuskript.functions import mainWindow, toInt, wordCount, HTML2PlainText
locale.setlocale(locale.LC_ALL, '')
import time, os
@ -531,9 +531,7 @@ class outlineItem():
oldType = self._data[Outline.type]
if oldType == "html" and data in ["txt", "t2t", "md"]:
# Resource inneficient way to convert HTML to plain text
e = QTextEdit()
e.setHtml(self._data[Outline.text])
self._data[Outline.text] = e.toPlainText()
self._data[Outline.text] = HTML2PlainText(self._data[Outline.text])
elif oldType in ["txt", "t2t", "md"] and data == "html" and Outline.text in self._data:
self._data[Outline.text] = self._data[Outline.text].replace("\n", "<br>")

View file

@ -243,7 +243,6 @@ class settingsWindow(QWidget, Ui_Settings):
sttgs = QSettings()
sttgs.setValue("autoLoad", True if self.chkAutoLoad.checkState() else False)
print("Setting Value:", True if self.chkAutoLoad.checkState() else False)
sttgs.sync()
settings.autoSave = True if self.chkAutoSave.checkState() else False