Created
December 10, 2016 15:10
-
-
Save holmeslinux/3d01840aecb43ef9a1eab0ca9ec11b0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from PyQt4 import QtGui, QtCore | |
from PyQt4.QtGui import QApplication, QWidget, QVBoxLayout, QPushButton | |
from functools import partial | |
from collections import OrderedDict | |
import os | |
but_width = 130 | |
butnum = 1 | |
global voffset | |
voffset = 40 | |
gui_width = 360 | |
gui_height = 180 | |
class Window(QtGui.QMainWindow): | |
def __init__(self): | |
super(Window, self).__init__() | |
self.setGeometry(50, 50, gui_width, gui_height) | |
self.setWindowTitle("JWMSession") | |
def pos_button(): | |
if butnum % 2 > 0: | |
lm1=20 | |
else: | |
lm1=210 | |
return lm1; | |
#Format 'label':'progname' | |
dic=OrderedDict() | |
dic['Lock Screen'] = 'i3lock -c c59a7a' | |
dic['Suspend'] = 'systemctl suspend' | |
dic['Logout'] = 'jwm -exit' | |
dic['Restart'] = 'systemctl reboot' | |
dic['Shutdown'] = 'systemctl poweroff' | |
dic['Cancel'] = 'kill -9 -$PPID' | |
vbox = QVBoxLayout(self) | |
global butnum | |
butnum = 1 | |
myFont = QtGui.QFont("", 11, QtGui.QFont.Bold) | |
ltxt1="What do you want to do?" | |
len1 = len(ltxt1) | |
lbl1 = QtGui.QLabel(ltxt1, self) | |
lbl1.setFont(myFont) | |
lbl1.setFixedWidth(gui_width) | |
lbl1.setAlignment(QtCore.Qt.AlignHCenter) | |
lbl1.move(0,20) | |
vbox.addWidget(lbl1) | |
for key,value in dic.items(): | |
global voffset | |
btemp = butnum | |
btn = QPushButton(" " + key, self) | |
btn.setStyleSheet("Text-align:left") | |
btn.setFixedWidth(but_width) | |
btn.clicked.connect(partial(self.doit, value)) | |
lm1 = pos_button() | |
if btemp % 2 == 0: btemp=btemp-1 | |
btn.move(lm1, (btemp*20)+voffset) | |
butnum += 1 | |
if butnum == 15: | |
voffset=120 | |
vbox.addWidget(btn) | |
def doit(self, text): | |
print("%s" % text) | |
os.system(text) | |
exit() | |
if __name__ == "__main__": | |
app = QApplication([]) | |
w = Window() | |
w.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment