mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-04-29 18:42:34 +12:00
Remove usage of hardcoded path separators
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
530352c78b
commit
98d6eb4975
|
@ -8,6 +8,8 @@ from manuskript.exporter.manuskript.markdown import markdown
|
|||
from manuskript.exporter.manuskript.plainText import plainText
|
||||
from manuskript.functions import appPath, safeTranslate
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class manuskriptExporter(basicExporter):
|
||||
|
||||
|
@ -19,7 +21,7 @@ class manuskriptExporter(basicExporter):
|
|||
HTML(),
|
||||
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
|
||||
def isValid(cls):
|
||||
|
|
|
@ -252,7 +252,7 @@ def colorifyPixmap(pixmap, color):
|
|||
|
||||
|
||||
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:
|
||||
p = os.path.join(p, suffix)
|
||||
return p
|
||||
|
@ -305,7 +305,7 @@ def findBackground(filename):
|
|||
"""
|
||||
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"):
|
||||
|
@ -511,7 +511,7 @@ def getManuskriptPath(follow_symlinks=True):
|
|||
path = os.path.abspath(sys.executable)
|
||||
else:
|
||||
import inspect
|
||||
path = inspect.getabsfile(getManuskriptPath) + "/../.."
|
||||
path = os.path.join(inspect.getabsfile(getManuskriptPath), "..", "..")
|
||||
if follow_symlinks:
|
||||
path = os.path.realpath(path)
|
||||
return os.path.dirname(path)
|
||||
|
|
|
@ -45,7 +45,7 @@ def prepare(arguments, tests=False):
|
|||
|
||||
icon = QIcon()
|
||||
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)
|
||||
|
||||
app.setStyle("Fusion")
|
||||
|
|
|
@ -513,7 +513,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
# self.cmbDelegate = cmbPixmapDelegate()
|
||||
# self.cmbCorkImage.setItemDelegate(self.cmbDelegate)
|
||||
|
||||
paths = allPaths("resources/backgrounds")
|
||||
paths = allPaths(os.path.join("resources", "backgrounds"))
|
||||
cmb.clear()
|
||||
cmb.addItem(QIcon.fromTheme("list-remove"), "", "")
|
||||
for p in paths:
|
||||
|
@ -541,7 +541,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
valid = px.load(filename)
|
||||
del px
|
||||
if valid:
|
||||
shutil.copy(filename, writablePath("resources/backgrounds"))
|
||||
shutil.copy(filename, writablePath(os.path.join("resources", "backgrounds")))
|
||||
return os.path.basename(filename)
|
||||
else:
|
||||
QMessageBox.warning(self, self.tr("Error"),
|
||||
|
@ -727,7 +727,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
self.btnThemeRemove.setEnabled(False)
|
||||
|
||||
def newTheme(self):
|
||||
path = writablePath("resources/themes")
|
||||
path = writablePath(os.path.join("resources", "themes"))
|
||||
name = self.tr("newtheme")
|
||||
if os.path.exists(os.path.join(path, "{}.theme".format(name))):
|
||||
i = 1
|
||||
|
@ -756,7 +756,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
self.populatesThemesList()
|
||||
|
||||
def populatesThemesList(self):
|
||||
paths = allPaths("resources/themes")
|
||||
paths = allPaths(os.path.join("resources", "themes"))
|
||||
current = settings.fullScreenTheme
|
||||
self.lstThemes.clear()
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
"""Tests for functions"""
|
||||
|
||||
import re
|
||||
import re, os
|
||||
from manuskript import functions as F
|
||||
|
||||
def test_wordCount():
|
||||
|
@ -81,7 +81,7 @@ def test_paths():
|
|||
assert len(F.allPaths("suffix")) == 2
|
||||
assert F.tempFile("yop") != None
|
||||
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
|
||||
|
||||
def test_mainWindow():
|
||||
|
|
|
@ -10,6 +10,9 @@ from manuskript.functions import appPath
|
|||
from manuskript.ui.about_ui import Ui_about
|
||||
from manuskript.version import getVersion
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class aboutDialog(QWidget, Ui_about):
|
||||
def __init__(self, parent=None, mw=None):
|
||||
QWidget.__init__(self, parent)
|
||||
|
@ -19,10 +22,10 @@ class aboutDialog(QWidget, Ui_about):
|
|||
|
||||
def populateFields(self):
|
||||
# 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))
|
||||
|
||||
logoPic = QPixmap(appPath("icons/Manuskript/logo-400x104.png"))
|
||||
logoPic = QPixmap(appPath(os.path.join("icons", "Manuskript", "logo-400x104.png")))
|
||||
self.labelLogo.setPixmap(logoPic)
|
||||
|
||||
self.labelManuskriptVersion.setText(
|
||||
|
|
|
@ -116,7 +116,7 @@ class fullScreenEditor(QWidget):
|
|||
self.bottomPanel.layout().addSpacing(24)
|
||||
self.lstThemes = QComboBox(self)
|
||||
self.lstThemes.setAttribute(Qt.WA_TranslucentBackground)
|
||||
paths = allPaths("resources/themes")
|
||||
paths = allPaths(os.path.join("resources", "themes"))
|
||||
for p in paths:
|
||||
lst = [i for i in os.listdir(p) if os.path.splitext(i)[1] == ".theme"]
|
||||
for t in lst:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
import locale
|
||||
import locale, os
|
||||
|
||||
from PyQt5.QtCore import QModelIndex, QRect, QPoint
|
||||
from PyQt5.QtCore import Qt
|
||||
|
@ -95,11 +95,11 @@ class mainEditor(QWidget, Ui_mainEditor):
|
|||
# Cf. https://github.com/qtproject/qtbase/commit/a8621a3f85e64f1252a80ae81a6e22554f7b3f44
|
||||
# Since those are important, we provide fallback.
|
||||
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",
|
||||
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",
|
||||
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]:
|
||||
btn.setToolTip(btn.text())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
import locale
|
||||
import locale, os
|
||||
|
||||
from PyQt5.QtCore import QModelIndex, QRect, QPoint, Qt, QObject, QSize
|
||||
from PyQt5.QtGui import QIcon, QPalette
|
||||
|
@ -150,7 +150,7 @@ class tabSplitter(QWidget, Ui_tabSplitter):
|
|||
self.updateTargetIcon(self.isTarget)
|
||||
|
||||
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:
|
||||
icon = QIcon(icon.pixmap(128, 128, icon.Disabled))
|
||||
self.btnTarget.setIcon(icon)
|
||||
|
|
|
@ -135,9 +135,9 @@ def createThemePreview(theme, screenRect, size=QSize(200, 120)):
|
|||
|
||||
|
||||
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:
|
||||
return findFirstFile(r".*\.theme", "resources/themes")
|
||||
return findFirstFile(r".*\.theme", os.path.join("resources", "themes"))
|
||||
else:
|
||||
return p
|
||||
|
||||
|
@ -276,7 +276,7 @@ def addThemePreviewText(pixmap, themeDatas, screenRect):
|
|||
previewText.setFrameStyle(QFrame.NoFrame)
|
||||
previewText.setHorizontalScrollBarPolicy(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)
|
||||
previewText.setPlainText(QTextStream(f).readAll())
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ class welcome(QWidget, Ui_welcome):
|
|||
# Change button text
|
||||
self.btnCreate.setText("Open {}".format(name))
|
||||
# Load project
|
||||
self.mw.loadProject(appPath("sample-projects/{}".format(name)))
|
||||
self.mw.loadProject(appPath(os.path.join("sample-projects", name)))
|
||||
|
||||
def updateTemplate(self):
|
||||
# Clear layout
|
||||
|
|
Loading…
Reference in a new issue