mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-16 01:44:34 +12:00
Stuff with paths
This commit is contained in:
parent
ca270b0b09
commit
eff0408260
|
@ -4,6 +4,7 @@
|
||||||
from qt import *
|
from qt import *
|
||||||
from random import *
|
from random import *
|
||||||
from enums import *
|
from enums import *
|
||||||
|
import os
|
||||||
|
|
||||||
def wordCount(text):
|
def wordCount(text):
|
||||||
return len(text.strip().replace(" ", "\n").split("\n")) if text else 0
|
return len(text.strip().replace(" ", "\n").split("\n")) if text else 0
|
||||||
|
@ -133,3 +134,27 @@ def colorifyPixmap(pixmap, color):
|
||||||
p.setCompositionMode(p.CompositionMode_Overlay)
|
p.setCompositionMode(p.CompositionMode_Overlay)
|
||||||
p.fillRect(pixmap.rect(), color)
|
p.fillRect(pixmap.rect(), color)
|
||||||
return pixmap
|
return pixmap
|
||||||
|
|
||||||
|
def appPath():
|
||||||
|
return os.path.realpath(os.path.join(os.path.split(__file__)[0], ".."))
|
||||||
|
|
||||||
|
def writablePath():
|
||||||
|
return QStandardPaths.writableLocation(QStandardPaths.AppLocalDataLocation)
|
||||||
|
|
||||||
|
def allPaths(suffix=None):
|
||||||
|
paths = []
|
||||||
|
# src directory
|
||||||
|
paths.append(appPath())
|
||||||
|
# user writable directory
|
||||||
|
paths.append(writablePath())
|
||||||
|
|
||||||
|
if suffix:
|
||||||
|
paths2 = []
|
||||||
|
for p in paths:
|
||||||
|
p2 = os.path.join(p, suffix)
|
||||||
|
paths2.append(p2)
|
||||||
|
if not os.path.exists(p2):
|
||||||
|
os.makedirs(p2)
|
||||||
|
paths = paths2
|
||||||
|
|
||||||
|
return paths
|
|
@ -226,7 +226,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
self.lstDebugLabels.setModel(self.mdlLabels)
|
self.lstDebugLabels.setModel(self.mdlLabels)
|
||||||
self.lstDebugStatus.setModel(self.mdlStatus)
|
self.lstDebugStatus.setModel(self.mdlStatus)
|
||||||
|
|
||||||
self.loadProject("test_project.zip")
|
self.loadProject(os.path.join(appPath(), "test_project.zip"))
|
||||||
|
|
||||||
self.settingsWindow(tab="Fullscreen")
|
self.settingsWindow(tab="Fullscreen")
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
|
@ -191,7 +191,7 @@ class settingsWindow(QWidget, Ui_Settings):
|
||||||
def setCorkBackground(self, i):
|
def setCorkBackground(self, i):
|
||||||
img = self.cmbCorkImage.itemData(i)
|
img = self.cmbCorkImage.itemData(i)
|
||||||
if img:
|
if img:
|
||||||
settings.corkBackground["image"] = os.path.join("resources/backgrounds", img)
|
settings.corkBackground["image"] = img
|
||||||
else:
|
else:
|
||||||
settings.corkBackground["image"] = ""
|
settings.corkBackground["image"] = ""
|
||||||
# Update Cork view
|
# Update Cork view
|
||||||
|
@ -201,14 +201,16 @@ class settingsWindow(QWidget, Ui_Settings):
|
||||||
#self.cmbDelegate = cmbPixmapDelegate()
|
#self.cmbDelegate = cmbPixmapDelegate()
|
||||||
#self.cmbCorkImage.setItemDelegate(self.cmbDelegate)
|
#self.cmbCorkImage.setItemDelegate(self.cmbDelegate)
|
||||||
|
|
||||||
path = "resources/backgrounds"
|
paths = allPaths("resources/backgrounds")
|
||||||
lst = os.listdir(path)
|
|
||||||
self.cmbCorkImage.addItem(QIcon.fromTheme("list-remove"), "", "")
|
self.cmbCorkImage.addItem(QIcon.fromTheme("list-remove"), "", "")
|
||||||
|
for p in paths:
|
||||||
|
lst = os.listdir(p)
|
||||||
for l in lst:
|
for l in lst:
|
||||||
if l.lower()[-4:] in [".jpg", ".png"] or \
|
if l.lower()[-4:] in [".jpg", ".png"] or \
|
||||||
l.lower()[-5:] in [".jpeg"]:
|
l.lower()[-5:] in [".jpeg"]:
|
||||||
px = QPixmap(os.path.join(path, l)).scaled(128, 64, Qt.KeepAspectRatio)
|
px = QPixmap(os.path.join(p, l)).scaled(128, 64, Qt.KeepAspectRatio)
|
||||||
self.cmbCorkImage.addItem(QIcon(px), "", l)
|
self.cmbCorkImage.addItem(QIcon(px), "", os.path.join(p, l))
|
||||||
|
|
||||||
self.cmbCorkImage.setIconSize(QSize(128, 64))
|
self.cmbCorkImage.setIconSize(QSize(128, 64))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue