From 22ac5ad2a60173703acde9a1e019e8b35a4e581c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20P=2E=20M=C3=B6ller?= Date: Mon, 24 Aug 2020 16:09:11 -0400 Subject: [PATCH] add transparency for menus --- breeze-config | 45 ++++++ ...ze-color.desktop => breeze-config.desktop} | 0 data/designer/main.ui | 61 ++++++- .../{breeze-color.1 => breeze-config.1} | 0 lubuntubreeze/__init__.py | 0 lubuntubreeze/breezeconfig.py | 152 ++++++++++++++++++ setup.py | 17 +- 7 files changed, 263 insertions(+), 12 deletions(-) create mode 100755 breeze-config rename data/{breeze-color.desktop => breeze-config.desktop} (100%) rename debian/manpages/{breeze-color.1 => breeze-config.1} (100%) create mode 100644 lubuntubreeze/__init__.py create mode 100755 lubuntubreeze/breezeconfig.py diff --git a/breeze-config b/breeze-config new file mode 100755 index 0000000..e4db3ca --- /dev/null +++ b/breeze-config @@ -0,0 +1,45 @@ +#!/usr/bin/python3 +# coding=utf-8 + +# Copyright (C) 2020 Hans P. Möller +# +# 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. +# 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 . + +import sys +from argparse import ArgumentParser + +from lubuntubreeze import breezeconfig + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument('--version', + action='version', + version='%(prog)s 0.1') + parser.add_argument("--data-dir", + dest="datadir", + default="/usr/share/lubuntu-breeze-config/designer", # modificar al final + help="data directory for UI files") + parser.add_argument("--bin-dir", + dest="bindir", + default="/bin", # modificar al final + help="directory where this script is, default /bin") + options = parser.parse_args() + + # TODO translations replace gettext with _ ??? + # localesApp="lubuntu-breeze" + # localesDir="/usr/share/locale" + # gettext.bindtextdomain(localesApp, localesDir) + # gettext.textdomain(localesApp) + # to test run as "./breeze-config --data-dir data --bin-dir ." + breezeconfig.main(sys.argv, options) diff --git a/data/breeze-color.desktop b/data/breeze-config.desktop similarity index 100% rename from data/breeze-color.desktop rename to data/breeze-config.desktop diff --git a/data/designer/main.ui b/data/designer/main.ui index e32b8a8..f99cd81 100644 --- a/data/designer/main.ui +++ b/data/designer/main.ui @@ -6,8 +6,8 @@ 0 0 - 479 - 168 + 571 + 305 @@ -31,12 +31,67 @@ + + + + Menu Transparency: + + + + + + + 99 + + + Qt::Horizontal + + + false + + + false + + + QSlider::TicksBelow + + + + + + + + + Transparent + + + + + + + Opaque + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Horizontal + + + <font size="-1">Applications need to be restarted for changes to take effect.<br> In case of pcmanfm-qt, since it handles the desktop, a restart of the desktop is needed<br/> -Easier, restart session.<br/>Best results if a matching GTK Theme is selected.</font> +Easier, restart session.<br/>Best results if a matching GTK Theme is selected.<br/> +Compton (or other compositor) needs to be enabled for transparency.</font> diff --git a/debian/manpages/breeze-color.1 b/debian/manpages/breeze-config.1 similarity index 100% rename from debian/manpages/breeze-color.1 rename to debian/manpages/breeze-config.1 diff --git a/lubuntubreeze/__init__.py b/lubuntubreeze/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lubuntubreeze/breezeconfig.py b/lubuntubreeze/breezeconfig.py new file mode 100755 index 0000000..ef2659c --- /dev/null +++ b/lubuntubreeze/breezeconfig.py @@ -0,0 +1,152 @@ +#!/usr/bin/python3 +# coding=utf-8 + +# Copyright (C) 2020 Hans P. Möller +# +# 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. +# 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 . + +import os +import subprocess +import sys +from pathlib import Path +from shutil import copyfile +from PyQt5.QtWidgets import (QWidget, QApplication, QDialogButtonBox) +from PyQt5.QtCore import (QDir, qDebug, QSettings) +from PyQt5 import uic +from gettext import gettext as _ +# better than in main "_ = gettext.gettext" for testing + + +class MainWindow(QWidget): + def __init__(self, options=None): + QWidget.__init__(self) + if options is not None: + self.datadir = options.datadir + self.bindir = options.bindir + else: + self.datadir = '/usr/share/lubuntu-breeze-config/designer' + uic.loadUi("%s/designer/main.ui" % self.datadir, self) + self.confFile = Path(Path.home() / ".config/kdeglobals") + self.schemeDir = "/usr/share/color-schemes/" + self.rcFile = Path(Path.home() / ".config/breezerc") + self.menuOpacity = 99 + self.initUI() + + def initUI(self): + '''populate text and combobox needed with uic''' + self.label.setText(_("Select Color Scheme for Breeze Qt Style:")) + t = _("Applications need to be restarted for changes to take effect.") + t += "
" + t += _("In case of pcmanfm-qt, since it handles the desktop, ") + t += _("a restart of the desktop is needed") + "
" + t += _("Easier, restart session.") + t += "
" + t += _("Best results if a matching GTK Theme is selected.") + t += "
" + t += _("A compositor (Compton) needs to be enabled for transparency.") + + self.note.setText('' + t + '') + sDir = QDir(self.schemeDir) + self.files = sDir.entryList(sDir, sDir.Files) + self.comboBox.clear() + self.comboBox.addItem(_("None")) + for f in self.files: + settings = QSettings(self.schemeDir + f, QSettings.NativeFormat) + self.comboBox.addItem(settings.value("ColorScheme")) + self.comboBox.setCurrentText(self.checkCurrent()) + self.horizontalSlider.setValue(self.checkTransparency()) + 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)) + settings = QSettings(str(self.confFile), QSettings.NativeFormat) + set = settings.value("ColorScheme") + qDebug(set) + if set != "": + return(set) + else: + return("None") + else: + qDebug(str(self.confFile) + " wasn't found") + return("None") + + def checkTransparency(self): + '''check current transparency''' + if self.rcFile.is_file(): + qDebug("exist: " + str(self.rcFile)) + settings = QSettings(str(self.rcFile), QSettings.NativeFormat) + settings.beginGroup("Style") + actual = settings.value("MenuOpacity") + qDebug(actual) + try: + actual = int(actual) + except ValueError: + actual = 99 + qDebug(str(actual)) + return actual + else: + qDebug(str(self.rcFile) + " wasn't found") + return 99 + + 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": + for f in self.files: + s = QSettings(self.schemeDir + f, QSettings.NativeFormat) + if(s.value("ColorScheme") == self.comboBox.currentText()): + copyfile(self.schemeDir + f, self.confFile) + else: + os.remove(self.confFile) + if self.horizontalSlider.value != self.checkTransparency(): + settings = QSettings(str(self.rcFile), QSettings.NativeFormat) + settings.beginGroup("Style") + settings.setValue("MenuOpacity", self.horizontalSlider.value()) + + filename = self.bindir + '/breeze-config' + print(filename) + # subprocess.Popen(filename) + subprocess.Popen([filename, '--data-dir', self.datadir, + '--bin-dir', self.bindir]) + sys.exit(0) + + elif btn == self.buttonBox.button(QDialogButtonBox.Close): + exit(0) + + +class App(QApplication): + def __init__(self, options, *args): + QApplication.__init__(self, *args) + self.main = MainWindow(options) + self.main.show() + + +def main(args, options): + global app + app = App(options, args) + # app.setWindowIcon(QIcon.fromTheme("preferences-desktop-color")) + app.exec_() diff --git a/setup.py b/setup.py index 3ff4bff..794520f 100644 --- a/setup.py +++ b/setup.py @@ -19,14 +19,13 @@ from setuptools import setup setup( - name="lubuntu-breeze-color", - version="0.1", - packages=['lubuntu-breeze-color'], - scripts=['breeze-color'], - data_files=[ - ('lib/lubuntu-breeze-color/', - ['lubuntuBreeze.py', ] - ), - ], + name="lubuntu-breeze-config", + version="0.1dev", + packages=['lubuntu-breeze-config'], + scripts=['breeze-config'], + data_files=[('libexec/lubuntu-breeze-config/', ['lubuntuBreeze.py']), + ('share/applications/', ['data/breeze-config.desktop']), + ('share/lubuntu-breeze-config/designer/', + ['data/designer/main.ui'])], test_suite="tests", )