Remove usage of hardcoded path separators

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
TheJackiMonster 2023-12-12 15:53:37 +01:00
parent 530352c78b
commit 98d6eb4975
No known key found for this signature in database
GPG key ID: D850A5F772E880F9
11 changed files with 29 additions and 24 deletions

View file

@ -8,6 +8,8 @@ from manuskript.exporter.manuskript.markdown import markdown
from manuskript.exporter.manuskript.plainText import plainText from manuskript.exporter.manuskript.plainText import plainText
from manuskript.functions import appPath, safeTranslate from manuskript.functions import appPath, safeTranslate
import os
class manuskriptExporter(basicExporter): class manuskriptExporter(basicExporter):
@ -19,7 +21,7 @@ class manuskriptExporter(basicExporter):
HTML(), HTML(),
basicFormat("OPML", icon="text-x-opml+xml") basicFormat("OPML", icon="text-x-opml+xml")
] ]
icon = appPath("icons/Manuskript/icon-256px.png") icon = appPath(os.path.join("icons", "Manuskript", "icon-256px.png"))
@classmethod @classmethod
def isValid(cls): def isValid(cls):

View file

@ -252,7 +252,7 @@ def colorifyPixmap(pixmap, color):
def appPath(suffix=None): def appPath(suffix=None):
p = os.path.realpath(os.path.join(os.path.split(__file__)[0], "../..")) p = os.path.realpath(os.path.join(os.path.split(__file__)[0], os.path.join("..", "..")))
if suffix: if suffix:
p = os.path.join(p, suffix) p = os.path.join(p, suffix)
return p return p
@ -305,7 +305,7 @@ def findBackground(filename):
""" """
Returns the full path to a background file of name filename within resources folders. Returns the full path to a background file of name filename within resources folders.
""" """
return findFirstFile(re.escape(filename), "resources/backgrounds") return findFirstFile(re.escape(filename), os.path.join("resources", "backgrounds"))
def findFirstFile(regex, path="resources"): def findFirstFile(regex, path="resources"):
@ -511,7 +511,7 @@ def getManuskriptPath(follow_symlinks=True):
path = os.path.abspath(sys.executable) path = os.path.abspath(sys.executable)
else: else:
import inspect import inspect
path = inspect.getabsfile(getManuskriptPath) + "/../.." path = os.path.join(inspect.getabsfile(getManuskriptPath), "..", "..")
if follow_symlinks: if follow_symlinks:
path = os.path.realpath(path) path = os.path.realpath(path)
return os.path.dirname(path) return os.path.dirname(path)

View file

@ -45,7 +45,7 @@ def prepare(arguments, tests=False):
icon = QIcon() icon = QIcon()
for i in [16, 32, 64, 128, 256, 512]: for i in [16, 32, 64, 128, 256, 512]:
icon.addFile(appPath("icons/Manuskript/icon-{}px.png".format(i))) icon.addFile(appPath(os.path.join("icons", "Manuskript", "icon-{}px.png".format(i))))
qApp.setWindowIcon(icon) qApp.setWindowIcon(icon)
app.setStyle("Fusion") app.setStyle("Fusion")

View file

@ -513,7 +513,7 @@ class settingsWindow(QWidget, Ui_Settings):
# self.cmbDelegate = cmbPixmapDelegate() # self.cmbDelegate = cmbPixmapDelegate()
# self.cmbCorkImage.setItemDelegate(self.cmbDelegate) # self.cmbCorkImage.setItemDelegate(self.cmbDelegate)
paths = allPaths("resources/backgrounds") paths = allPaths(os.path.join("resources", "backgrounds"))
cmb.clear() cmb.clear()
cmb.addItem(QIcon.fromTheme("list-remove"), "", "") cmb.addItem(QIcon.fromTheme("list-remove"), "", "")
for p in paths: for p in paths:
@ -541,7 +541,7 @@ class settingsWindow(QWidget, Ui_Settings):
valid = px.load(filename) valid = px.load(filename)
del px del px
if valid: if valid:
shutil.copy(filename, writablePath("resources/backgrounds")) shutil.copy(filename, writablePath(os.path.join("resources", "backgrounds")))
return os.path.basename(filename) return os.path.basename(filename)
else: else:
QMessageBox.warning(self, self.tr("Error"), QMessageBox.warning(self, self.tr("Error"),
@ -727,7 +727,7 @@ class settingsWindow(QWidget, Ui_Settings):
self.btnThemeRemove.setEnabled(False) self.btnThemeRemove.setEnabled(False)
def newTheme(self): def newTheme(self):
path = writablePath("resources/themes") path = writablePath(os.path.join("resources", "themes"))
name = self.tr("newtheme") name = self.tr("newtheme")
if os.path.exists(os.path.join(path, "{}.theme".format(name))): if os.path.exists(os.path.join(path, "{}.theme".format(name))):
i = 1 i = 1
@ -756,7 +756,7 @@ class settingsWindow(QWidget, Ui_Settings):
self.populatesThemesList() self.populatesThemesList()
def populatesThemesList(self): def populatesThemesList(self):
paths = allPaths("resources/themes") paths = allPaths(os.path.join("resources", "themes"))
current = settings.fullScreenTheme current = settings.fullScreenTheme
self.lstThemes.clear() self.lstThemes.clear()

View file

@ -3,7 +3,7 @@
"""Tests for functions""" """Tests for functions"""
import re import re, os
from manuskript import functions as F from manuskript import functions as F
def test_wordCount(): def test_wordCount():
@ -81,7 +81,7 @@ def test_paths():
assert len(F.allPaths("suffix")) == 2 assert len(F.allPaths("suffix")) == 2
assert F.tempFile("yop") != None assert F.tempFile("yop") != None
f = F.findBackground("spacedreams.jpg") f = F.findBackground("spacedreams.jpg")
assert "resources/backgrounds/spacedreams.jpg" in f assert os.path.join("resources", "backgrounds", "spacedreams.jpg") in f
assert len(F.customIcons()) > 1 assert len(F.customIcons()) > 1
def test_mainWindow(): def test_mainWindow():

View file

@ -10,6 +10,9 @@ from manuskript.functions import appPath
from manuskript.ui.about_ui import Ui_about from manuskript.ui.about_ui import Ui_about
from manuskript.version import getVersion from manuskript.version import getVersion
import os
class aboutDialog(QWidget, Ui_about): class aboutDialog(QWidget, Ui_about):
def __init__(self, parent=None, mw=None): def __init__(self, parent=None, mw=None):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
@ -19,10 +22,10 @@ class aboutDialog(QWidget, Ui_about):
def populateFields(self): def populateFields(self):
# Fill in all the fields in the About dialog # Fill in all the fields in the About dialog
iconPic = appPath("icons/Manuskript/icon-64px.png") iconPic = appPath(os.path.join("icons", "Manuskript", "icon-64px.png"))
self.setWindowIcon(QIcon(iconPic)) self.setWindowIcon(QIcon(iconPic))
logoPic = QPixmap(appPath("icons/Manuskript/logo-400x104.png")) logoPic = QPixmap(appPath(os.path.join("icons", "Manuskript", "logo-400x104.png")))
self.labelLogo.setPixmap(logoPic) self.labelLogo.setPixmap(logoPic)
self.labelManuskriptVersion.setText( self.labelManuskriptVersion.setText(

View file

@ -116,7 +116,7 @@ class fullScreenEditor(QWidget):
self.bottomPanel.layout().addSpacing(24) self.bottomPanel.layout().addSpacing(24)
self.lstThemes = QComboBox(self) self.lstThemes = QComboBox(self)
self.lstThemes.setAttribute(Qt.WA_TranslucentBackground) self.lstThemes.setAttribute(Qt.WA_TranslucentBackground)
paths = allPaths("resources/themes") paths = allPaths(os.path.join("resources", "themes"))
for p in paths: for p in paths:
lst = [i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme"] lst = [i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme"]
for t in lst: for t in lst:

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# --!-- coding: utf8 --!-- # --!-- coding: utf8 --!--
import locale import locale, os
from PyQt5.QtCore import QModelIndex, QRect, QPoint from PyQt5.QtCore import QModelIndex, QRect, QPoint
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
@ -95,11 +95,11 @@ class mainEditor(QWidget, Ui_mainEditor):
# Cf. https://github.com/qtproject/qtbase/commit/a8621a3f85e64f1252a80ae81a6e22554f7b3f44 # Cf. https://github.com/qtproject/qtbase/commit/a8621a3f85e64f1252a80ae81a6e22554f7b3f44
# Since those are important, we provide fallback. # Since those are important, we provide fallback.
self.btnRedacFolderCork.setIcon(QIcon.fromTheme("view-cards", self.btnRedacFolderCork.setIcon(QIcon.fromTheme("view-cards",
QIcon(appPath("icons/NumixMsk/256x256/actions/view-cards.svg")))) QIcon(appPath(os.path.join("icons", "NumixMsk", "256x256", "actions", "view-cards.svg")))))
self.btnRedacFolderOutline.setIcon(QIcon.fromTheme("view-outline", self.btnRedacFolderOutline.setIcon(QIcon.fromTheme("view-outline",
QIcon(appPath("icons/NumixMsk/256x256/actions/view-outline.svg")))) QIcon(appPath(os.path.join("icons", "NumixMsk", "256x256", "actions", "view-outline.svg")))))
self.btnRedacFolderText.setIcon(QIcon.fromTheme("view-text", self.btnRedacFolderText.setIcon(QIcon.fromTheme("view-text",
QIcon(appPath("icons/NumixMsk/256x256/actions/view-text.svg")))) QIcon(appPath(os.path.join("icons", "NumixMsk", "256x256", "actions", "view-text.svg")))))
for btn in [self.btnRedacFolderCork, self.btnRedacFolderText, self.btnRedacFolderOutline]: for btn in [self.btnRedacFolderCork, self.btnRedacFolderText, self.btnRedacFolderOutline]:
btn.setToolTip(btn.text()) btn.setToolTip(btn.text())

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# --!-- coding: utf8 --!-- # --!-- coding: utf8 --!--
import locale import locale, os
from PyQt5.QtCore import QModelIndex, QRect, QPoint, Qt, QObject, QSize from PyQt5.QtCore import QModelIndex, QRect, QPoint, Qt, QObject, QSize
from PyQt5.QtGui import QIcon, QPalette from PyQt5.QtGui import QIcon, QPalette
@ -150,7 +150,7 @@ class tabSplitter(QWidget, Ui_tabSplitter):
self.updateTargetIcon(self.isTarget) self.updateTargetIcon(self.isTarget)
def updateTargetIcon(self, val): def updateTargetIcon(self, val):
icon = QIcon.fromTheme("set-target", QIcon(appPath("icons/NumixMsk/256x256/actions/set-target.svg"))) icon = QIcon.fromTheme("set-target", QIcon(appPath(os.path.join("icons", "NumixMsk", "256x256", "actions", "set-target.svg"))))
if not val: if not val:
icon = QIcon(icon.pixmap(128, 128, icon.Disabled)) icon = QIcon(icon.pixmap(128, 128, icon.Disabled))
self.btnTarget.setIcon(icon) self.btnTarget.setIcon(icon)

View file

@ -135,9 +135,9 @@ def createThemePreview(theme, screenRect, size=QSize(200, 120)):
def findThemePath(themeName): def findThemePath(themeName):
p = findFirstFile(re.escape("{}.theme".format(themeName)), "resources/themes") p = findFirstFile(re.escape("{}.theme".format(themeName)), os.path.join("resources", "themes"))
if not p: if not p:
return findFirstFile(r".*\.theme", "resources/themes") return findFirstFile(r".*\.theme", os.path.join("resources", "themes"))
else: else:
return p return p
@ -276,7 +276,7 @@ def addThemePreviewText(pixmap, themeDatas, screenRect):
previewText.setFrameStyle(QFrame.NoFrame) previewText.setFrameStyle(QFrame.NoFrame)
previewText.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) previewText.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
previewText.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) previewText.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
f = QFile(appPath("resources/themes/preview.txt")) f = QFile(appPath(os.path.join("resources", "themes", "preview.txt")))
f.open(QIODevice.ReadOnly) f.open(QIODevice.ReadOnly)
previewText.setPlainText(QTextStream(f).readAll()) previewText.setPlainText(QTextStream(f).readAll())

View file

@ -268,7 +268,7 @@ class welcome(QWidget, Ui_welcome):
# Change button text # Change button text
self.btnCreate.setText("Open {}".format(name)) self.btnCreate.setText("Open {}".format(name))
# Load project # Load project
self.mw.loadProject(appPath("sample-projects/{}".format(name))) self.mw.loadProject(appPath(os.path.join("sample-projects", name)))
def updateTemplate(self): def updateTemplate(self):
# Clear layout # Clear layout