add transparency for menus

master
Hans P. Möller 4 years ago
parent cf0b5a0f66
commit 22ac5ad2a6

@ -0,0 +1,45 @@
#!/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.
# 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 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)

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>479</width>
<height>168</height>
<width>571</width>
<height>305</height>
</rect>
</property>
<property name="windowTitle">
@ -31,12 +31,67 @@
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
<item>
<widget class="QLabel" name="label2">
<property name="text">
<string>Menu Transparency:</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider">
<property name="value">
<number>99</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="invertedControls">
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label3a">
<property name="text">
<string>Transparent</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label3b">
<property name="text">
<string>Opaque</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="note">
<property name="text">
<string>&lt;font size=&quot;-1&quot;&gt;Applications need to be restarted for changes to take effect.&lt;br&gt;
In case of pcmanfm-qt, since it handles the desktop, a restart of the desktop is needed&lt;br/&gt;
Easier, restart session.&lt;br/&gt;Best results if a matching GTK Theme is selected.&lt;/font&gt;</string>
Easier, restart session.&lt;br/&gt;Best results if a matching GTK Theme is selected.&lt;br/&gt;
Compton (or other compositor) needs to be enabled for transparency.&lt;/font&gt;</string>
</property>
</widget>
</item>

@ -0,0 +1,152 @@
#!/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.
# 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 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 += "<br/>"
t += _("In case of pcmanfm-qt, since it handles the desktop, ")
t += _("a restart of the desktop is needed") + "<br/>"
t += _("Easier, restart session.")
t += "<br/>"
t += _("Best results if a matching GTK Theme is selected.")
t += "<br/>"
t += _("A compositor (Compton) needs to be enabled for transparency.")
self.note.setText('<font size="-1">' + t + '</font>')
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_()

@ -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",
)

Loading…
Cancel
Save