Page MenuHomeLubuntu Development

breeze-config.py by @hmollercl
ActivePublic

Authored by wxl on Feb 3 2020, 8:26 PM.
#!/usr/bin/python3
# coding=utf-8
# Copyright (C) 2020 Hans P. Möller <hmollercl@lubuntu.me>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
from pathlib import Path
from shutil import copyfile
from PyQt5.QtWidgets import (QWidget, QApplication, QLabel, QVBoxLayout,
QComboBox, QDialogButtonBox)
from PyQt5.QtCore import (QDir, qDebug)
from PyQt5.QtGui import QIcon
# from PyQt5 import uic
# from PyQt5 import QtX11Extras
class MainWindow(QWidget):
def __init__(self):
QWidget.__init__(self)
# uic.loadUi("designer/main.ui", self)
self.confFile = Path(str(Path.home()) + "/.config/kdeglobals")
self.schemeDir = "/usr/share/color-schemes/"
self.initUI()
def initUI(self):
'''set UI not needed first part if uic is used'''
self.label = QLabel()
self.note = QLabel()
self.comboBox = QComboBox()
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Apply
| QDialogButtonBox.Close)
vbox = QVBoxLayout()
vbox.addWidget(self.label)
vbox.addWidget(self.comboBox)
vbox.addWidget(self.note)
vbox.addWidget(self.buttonBox)
self.label.setText("Select Color Scheme")
noteText = '''
<font size="-1">
Applications need to be restarted for changes to take effect.<br/>
In case of pcmanfm-qt, since it handles the desktop,<br/>
a restart of the desktop is needed.<br/>
Easier, restart session.<br/>
Best results if a matching GTK Theme is selected.
</font>
'''
self.note.setText(noteText)
self.setLayout(vbox)
self.setWindowTitle("Lubuntu Breeze Config")
'''populate combobox needed with uic'''
dir = QDir(self.schemeDir)
files = dir.entryList(dir, dir.Files)
self.comboBox.clear()
self.comboBox.addItem("None")
for f in files:
self.comboBox.addItem(f.split(".")[0])
self.comboBox.setCurrentText(self.checkCurrent())
self.buttonBox.clicked.connect(self.btnClk)
self.center()
def center(self):
'''centers UI'''
frameGm = self.frameGeometry()
screen = QApplication.desktop().screenNumber(
QApplication.desktop().cursor().pos())
centerPoint = QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
def checkCurrent(self):
'''check current used theme'''
if self.confFile.is_file():
qDebug("exist: " + str(self.confFile))
with open(str(self.confFile)) as f:
for line in f:
item = line.split("=")
if item[0] == "ColorScheme":
current = item[1].replace("\n", "") # remove \n
current = current.replace(" ", "") # remove spaces
qDebug("current scheme: " + current)
return(current)
qDebug("No Color Scheme found on file")
return("None")
else:
qDebug(str(self.confFile) + " wasn't found")
return("None")
def btnClk(self, btn):
'''copy selected color-scheme to kdeglobals or close'''
if btn == self.buttonBox.button(QDialogButtonBox.Apply):
qDebug("apply")
if self.comboBox.currentText() != "None":
copyfile(self.schemeDir + self.comboBox.currentText() +
".colors", self.confFile)
else:
os.remove(self.confFile)
os.execl(sys.executable, os.path.abspath(__file__), *sys.argv)
elif btn == self.buttonBox.button(QDialogButtonBox.Close):
exit(0)
class App(QApplication):
def __init__(self, *args):
QApplication.__init__(self, *args)
self.main = MainWindow()
self.main.show()
def main(args):
global app
app = App(args)
app.setWindowIcon(QIcon.fromTheme("preferences-desktop-color"))
app.exec_()
if __name__ == "__main__":
main(sys.argv)

Event Timeline

wxl created this paste.Feb 3 2020, 8:26 PM
wxl mentioned this in T137: improve theming.
hmollercl added a subscriber: hmollercl.EditedFeb 3 2020, 8:42 PM

commented lines 98 to 102 are my attempts to redraw (which haven't worked).
I wonder why submit button says "Nom Nom Nom Nom Nom".....

hmollercl edited the content of this paste. (Show Details)Feb 10 2020, 1:50 PM

So, I did some changes that make the app restart after "apply" and it restart with the new config chosen.

I couldn't found out how to "redraw" the whole system, although lxqt.conf is watched (if you change breez to fusion in the file the system apply iy inmediately) te changes on color-schemes (in kdeglobals) are not taken.

hmollercl edited the content of this paste. (Show Details)Feb 11 2020, 2:11 PM

I added a note regarding apps need to be restarted

hmollercl edited the content of this paste. (Show Details)Feb 12 2020, 9:46 PM