Bug corrections and small features

This commit is contained in:
Olivier Keshavjee 2015-06-20 16:45:54 +02:00
parent 58f4e45e47
commit 86133d3912
3 changed files with 43 additions and 8 deletions

View file

@ -142,9 +142,15 @@ def appPath(suffix=None):
return p
def writablePath(suffix=None):
p = QStandardPaths.writableLocation(QStandardPaths.AppLocalDataLocation)
if hasattr(QStandardPaths, "AppLocalDataLocation"):
p = QStandardPaths.writableLocation(QStandardPaths.AppLocalDataLocation)
else:
# Qt < 5.4
p = QStandardPaths.writableLocation(QStandardPaths.DataLocation)
if suffix:
p = os.path.join(p, suffix)
if not os.path.exists(p):
os.makedirs(p)
return p
def allPaths(suffix=None):

View file

@ -20,13 +20,14 @@ class fullScreenEditor(QWidget):
# Text editor
self.editor = textEditView(self, dict=settings.dict)
self.editor.setFrameStyle(QFrame.NoFrame)
self.editor.document().setPlainText(open(appPath("resources/themes/preview.txt")).read() * 5)
f = QFile(appPath("resources/themes/preview.txt"))
f.open(QIODevice.ReadOnly)
self.editor.setPlainText(QTextStream(f).readAll()*5)
self.editor.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.editor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.editor.installEventFilter(self)
self.editor.setMouseTracking(True)
# Scroll bar
if self._themeDatas["Foreground/Color"] == self._themeDatas["Background/Color"] or \
self._themeDatas["Foreground/Opacity"] < 5:
@ -65,6 +66,10 @@ class fullScreenEditor(QWidget):
r.moveRight(rect.right())
self.scrollBar.setGeometry(r)
self.scrollBar.setVisible(False)
p = self.scrollBar.palette()
b = QBrush(self._background.copy(self.scrollBar.geometry()))
p.setBrush(QPalette.Base, b)
self.scrollBar.setPalette(p)
# Set Panel
r = QRect(0, 0, 400, 120)
@ -76,6 +81,7 @@ class fullScreenEditor(QWidget):
def paintEvent(self, event):
if self._background:
painter = QPainter(self)
painter.setClipRegion(event.region())
painter.drawPixmap(event.rect(), self._background, event.rect())
painter.end()
@ -104,12 +110,28 @@ class myScrollBar(QScrollBar):
def __init__(self, color=Qt.white, parent=None):
QScrollBar.__init__(self, parent)
self._color = color
#self.setAttribute(Qt.WA_TranslucentBackground)
self.timer = QTimer()
self.timer.setInterval(250)
self.timer.setSingleShot(True)
self.timer.timeout.connect(self.hide)
self.valueChanged.connect(lambda v: self.timer.start())
self.valueChanged.connect(self.show)
def paintEvent(self, event):
opt = QStyleOptionSlider()
self.initStyleOption(opt)
style = qApp.style()
painter = QPainter(self)
# Background (Necessary with Qt 5.2 it seems, not with 5.4)
painter.save()
painter.setPen(Qt.NoPen)
painter.setBrush(self.palette().brush(QPalette.Base))
painter.drawRect(event.rect())
painter.restore()
#slider
r = style.subControlRect(style.CC_ScrollBar, opt, style.SC_ScrollBarSlider)
painter.fillRect(r, self._color)

View file

@ -8,6 +8,7 @@ from enums import *
from functions import *
from ui.views.textEditView import *
import settings
import re
def loadThemeDatas(themeFile):
settings = QSettings(themeFile, QSettings.IniFormat)
@ -104,17 +105,21 @@ def createThemePreview(theme, screenRect, size=QSize(200, 120)):
return px
def findThemePath(themeName):
return findFirstFile(themeName, "resources/themes", "{}.theme")
p = findFirstFile(re.escape("{}.theme".format(themeName)), "resources/themes")
if not p:
return findFirstFile(".*\.theme", "resources/themes")
else:
return p
def findBackground(filename):
return findFirstFile(filename, "resources/backgrounds")
return findFirstFile(re.escape(filename), "resources/backgrounds")
def findFirstFile(filename, path="resources", mask="{}"):
def findFirstFile(regex, path="resources"):
paths = allPaths(path)
for p in paths:
lst = os.listdir(p)
for l in lst:
if l == mask.format(filename):
if re.match(regex, l):
return os.path.join(p, l)
def generateTheme(themeDatas, screenRect):
@ -221,7 +226,9 @@ def addThemePreviewText(pixmap, themeDatas, screenRect):
previewText.setFrameStyle(QFrame.NoFrame)
previewText.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
previewText.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
previewText.setPlainText(open(appPath("resources/themes/preview.txt")).read())
f = QFile(appPath("resources/themes/preview.txt"))
f.open(QIODevice.ReadOnly)
previewText.setPlainText(QTextStream(f).readAll())
setThemeEditorDatas(previewText, themeDatas, pixmap, screenRect)