mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-08 14:04:33 +12:00
Tries to fix 'Indent not saved in custom full screen theme #133', and adds cache to theme thumbnails
This commit is contained in:
parent
2c36902d46
commit
3eda56ed5a
|
@ -560,6 +560,9 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
item = QListWidgetItem(n)
|
||||
item.setData(Qt.UserRole, theme)
|
||||
item.setData(Qt.UserRole + 1, editable)
|
||||
item.setToolTip("{}{}".format(
|
||||
n,
|
||||
self.tr(" (read-only)") if not editable else ""))
|
||||
|
||||
thumb = os.path.join(p, t.replace(".theme", ".jpg"))
|
||||
px = QPixmap(200, 120)
|
||||
|
|
|
@ -12,6 +12,7 @@ from PyQt5.QtWidgets import qApp, QFrame
|
|||
from manuskript.functions import allPaths, appPath, findBackground, findFirstFile
|
||||
from manuskript.ui.views.textEditView import textEditView
|
||||
|
||||
_thumbCache = {}
|
||||
|
||||
def loadThemeDatas(themeFile):
|
||||
settings = QSettings(themeFile, QSettings.IniFormat)
|
||||
|
@ -51,18 +52,11 @@ def loadThemeDatas(themeFile):
|
|||
|
||||
|
||||
def loadThemeSetting(datas, settings, key, default):
|
||||
if settings.contains(key):
|
||||
|
||||
if type(default) != type(True):
|
||||
datas[key] = type(default)(settings.value(key))
|
||||
else:
|
||||
# Bools are stored as "true"/"false", but both are read as True
|
||||
# since they are non-empty string.
|
||||
datas[key] = True if settings.value(key) == "true" else False
|
||||
|
||||
else:
|
||||
datas[key] = default
|
||||
|
||||
"""
|
||||
Loads data from ini file, using default value if the key is absent,
|
||||
and casting to the proper type based on default.
|
||||
"""
|
||||
datas[key] = settings.value(key, default, type(default))
|
||||
|
||||
def getThemeName(theme):
|
||||
settings = QSettings(theme, QSettings.IniFormat)
|
||||
|
@ -93,11 +87,28 @@ def themeTextRect(themeDatas, screenRect):
|
|||
|
||||
|
||||
def createThemePreview(theme, screenRect, size=QSize(200, 120)):
|
||||
"""
|
||||
Generates a QPixmap preview for given theme.
|
||||
|
||||
Theme can be either a string containing the filename of the ini
|
||||
file with the theme settings, or it can be a dict with the settings.
|
||||
|
||||
If theme is a filename, the result is cached.
|
||||
"""
|
||||
|
||||
# Checking whether theme is a string or dict
|
||||
if type(theme) == str and os.path.exists(theme):
|
||||
# Theme is the path to an ini file
|
||||
themeDatas = loadThemeDatas(theme)
|
||||
fromFile = True
|
||||
else:
|
||||
themeDatas = theme
|
||||
fromFile = False
|
||||
|
||||
# Check if item is in cache
|
||||
if fromFile and theme in _thumbCache:
|
||||
if _thumbCache[theme][0] == themeDatas:
|
||||
return _thumbCache[theme][1]
|
||||
|
||||
pixmap = generateTheme(themeDatas, screenRect)
|
||||
|
||||
|
@ -116,6 +127,10 @@ def createThemePreview(theme, screenRect, size=QSize(200, 120)):
|
|||
painter.drawRect(QRect(w, h, w * 4, h * 5))
|
||||
painter.end()
|
||||
|
||||
# If theme is a themefile, we keep it in cache
|
||||
if fromFile:
|
||||
_thumbCache[theme] = [themeDatas, px]
|
||||
|
||||
return px
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue