all repos — nitroplasm @ a859dcd3e81a524a5ea5465f79914b7c7cf26183

lightweight wallpaper setter for KDE5/Plasma

first commit
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmBVhPsACgkQO3+8IhRO
Y5jKEQ//QQwwI/xPrYyHIZG/K+m7ZMB2k6l+HfEShTZzdYsoOHDmT+ER4anx8Qgr
QTKax2VIDruDIOwdBr39nJ0SsrZImCUThbSlBm+X6Gla3sZWFfHUZgwj/nYWYkms
o+VuWMR1n6qy6lhRz4XPTSzixSygh8dsREnovNaAKBiEniFJXM6gvuTdGBg5EXTX
BkvOUaVSkjVKdvxBKa9ECDcFkIRPgagdgdsBA6RPd6bXRT1Qela/wKcrc3lmBuOt
fxCUDlWTumhY5pxDbc2u9XJpWTX+7gikLsnphiArbUHYe561wgRRFN3le/DyZj7B
On4k2wkAs8Sf0JLelfx1nbpnxDYd3L2i4jeGOQLFrdU3fGBh8RI7xtWIP0V9CBwx
XPhlITh3y13qFJ37iVtphRyx20m4Spwi2xo5kzUGmaLZb02ZreCVWqj77AcOw3ds
ofpPxi+Q8Wq2TQG9x3LK/ae3hKIgxBA4SAFkP2eM0Z/oafYGdLueTgeQyvFXk8Ha
cGnf0W439OOmp4n5+JlEHsozbV/5gUDadoNtk5rxRSK/UPYvgmCn/0pWFnY0+ZkQ
JYVC+F24+M5zNml66zsW+C7mIz5RCnSYA8PIwNpf4DmMndN9fQBF7I3is1r+qhpO
v8oLp9HuvOtEV0BFzQcUq0Kp/hJ0ngqPa2aaZUU9UIMKN7GFLn8=
=oCuB
-----END PGP SIGNATURE-----
commit

a859dcd3e81a524a5ea5465f79914b7c7cf26183

1 files changed, 181 insertions(+), 0 deletions(-)

jump to
A nitroplasm.py

@@ -0,0 +1,181 @@

+#!/usr/bin/python3 + +# nitroplasm: a lightweight desktop setter for KDE Plasma +# by Derek Stevens <drkste@zoho.com> +# written for use with the custom root menu by MatMoul: +# https://github.com/MatMoul/plasma-containmentactions-customdesktopmenu +# original script by pashazz: +# https://github.com/pashazz/ksetwallpaper +# license: GPLv3 + +from PyQt5 import QtGui, QtCore +from PyQt5.QtWidgets import \ + QApplication, \ + QWidget, \ + QComboBox, \ + QVBoxLayout, \ + QHBoxLayout, \ + QPushButton, \ + QFileDialog , \ + QLabel, \ + QSizePolicy +import sys +from PyQt5.QtGui import QPixmap +from Xlib import display +import subprocess +import dbus +import argparse + +class Window(QWidget): + def __init__(self): + super().__init__() + + self.title = "Nitroplasm" + self.top = 100 + self.left = 200 + self.width = 500 + self.height = 400 + + self.InitWindow() + + def InitWindow(self): + self.setWindowIcon(QtGui.QIcon(None)) + self.setWindowTitle(self.title) + self.setGeometry(self.left, self.top, self.width, self.height) + self.setFixedSize(self.width, self.height) + self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + self.setWindowFlags(QtCore.Qt.Dialog) + + vbox = QVBoxLayout() + hbox = QHBoxLayout() + + self.image = None + self.label = QLabel(self.image) + self.label.setScaledContents(False) + self.label.setAlignment(QtCore.Qt.AlignCenter) + self.label.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) + self.layout = 2 + self.monitor = -1 + + self.select_button = QPushButton("Select Image") + self.select_button.clicked.connect(self.get_image) + + layouts = { + "Stretch": 0, + "Scale": 1, + "Zoom": 2, + "Tile": 3, + "Vertical Tile": 4, + "Horizontal Tile": 5, + "Center": 6 + } + + self.layout_selector = QComboBox() + for l in layouts: + self.layout_selector.addItem(l, layouts[l]) + self.layout_selector.currentIndexChanged.connect(self.set_layout) + self.layout_selector.setCurrentIndex(2) + + self.monitor_selector = QComboBox() + self.monitor_selector.addItem("All Monitors", -1) + nDisplays = self.get_displays() + print(nDisplays) + if nDisplays > 1: + for i in range(0, nDisplays): + self.monitor_selector.addItem("Monitor" + str(i+1), i) + self.monitor_selector.currentIndexChanged.connect(self.set_monitor) + self.monitor_selector.setCurrentIndex(0) + + self.apply_button = QPushButton("Apply Image") + self.apply_button.setEnabled(False) + self.apply_button.clicked.connect(self.apply_image) + + vbox.addWidget(self.label) + + hbox.addWidget(self.select_button) + hbox.addWidget(self.layout_selector) + hbox.addWidget(self.monitor_selector) + hbox.addWidget(self.apply_button) + + vbox.addLayout(hbox) + self.setLayout(vbox) + self.show() + + def set_layout(self, index): + self.layout = self.layout_selector.itemData(index) + + def get_displays(self): + if 'RANDR' in display.Display().list_extensions(): + try: + output = [l for l in subprocess.check_output(["xrandr"]).decode("utf-8").splitlines()] + return len([l.split()[0] for l in output if " connected " in l]) + except: + return 1 + else: + return 1 + + def set_monitor(self, index): + self.monitor = self.monitor_selector.itemData(index) + + def get_image(self): + fname = QFileDialog.getOpenFileName( + self, + 'Select Image File', + './', + 'Image files (*.png *.jpg *.gif *.jpeg)') + + if fname[0]: + self.image = fname[0] + self.apply_button.setEnabled(True) + + pixmap = QPixmap(self.image).scaled( + self.label.width(), + self.label.height(), + QtCore.Qt.KeepAspectRatio, + QtCore.Qt.SmoothTransformation) + + #self.label.setMaximumSize(self.label.width(), self.label.height()) + self.label.setPixmap(pixmap) + + def set_wallpaper(self, filepath, plugin = 'org.kde.image', layout = 2, desk = -1): + if desk < 0: + jscript = """ + var allDesktops = desktops(); + for (i=0;i<allDesktops.length;i++) { + d = allDesktops[i]; + d.wallpaperPlugin = "%s"; + d.currentConfigGroup = Array("Wallpaper", "%s", "General"); + d.writeConfig("Image", "file://%s") + d.writeConfig("FillMode", "%s") + } + """ + else: + jscript = """ + var d = desktops()[%s]; + d.wallpaperPlugin = "%s"; + d.currentConfigGroup = Array("Wallpaper", "%s", "General"); + d.writeConfig("Image", "file://%s") + d.writeConfig("FillMode", "%s") + """ + + bus = dbus.SessionBus() + plasma = dbus.Interface( + bus.get_object( + 'org.kde.plasmashell', + '/PlasmaShell'), + dbus_interface='org.kde.PlasmaShell') + if desk < 0: + plasma.evaluateScript(jscript % (plugin, plugin, filepath, layout)) + else: + plasma.evaluateScript(jscript % (desk, plugin, plugin, filepath, layout)) + + def apply_image(self): + self.set_wallpaper(self.image, 'org.kde.image', self.layout, self.monitor) + +if __name__ == '__main__': + if len(sys.argv) == 1: + App = QApplication(sys.argv) + window = Window() + sys.exit(App.exec()) + else: + parser = argparse.ArgumentParser(description='KDE Wallpaper setter')