Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from PyQt4 import QtGui, QtCore
  4.  
  5. from PyQt4.QtGui import QApplication, QWidget, QVBoxLayout, QPushButton
  6.  
  7. from functools import partial
  8.  
  9. from collections import OrderedDict
  10.  
  11. import os
  12.  
  13. but_width = 190
  14. butnum = 1
  15.  
  16. global voffset
  17. voffset = 60
  18.  
  19. gui_width = 460
  20. gui_height = 200
  21.  
  22. class Window(QtGui.QMainWindow):
  23. def __init__(self):
  24. super(Window, self).__init__()
  25. self.setGeometry(50, 50, gui_width, gui_height)
  26. self.setWindowTitle("JWMSession")
  27.  
  28. def pos_button():
  29. if butnum % 2 > 0:
  30. lm1=20
  31. else:
  32. lm1=250
  33. return lm1;
  34.  
  35. #Format 'label':'progname'
  36. dic=OrderedDict()
  37. dic['Lock Screen'] = 'i3lock -c c59a7a'
  38. dic['Suspend'] = 'systemctl suspend'
  39. dic['Logout'] = 'jwm -exit'
  40. dic['Restart'] = 'systemctl reboot'
  41. dic['Shutdown'] = 'systemctl poweroff'
  42. dic['Cancel'] = 'kill -9 -$PPID'
  43.  
  44. vbox = QVBoxLayout(self)
  45.  
  46. global butnum
  47. butnum = 1
  48.  
  49. myFont = QtGui.QFont("", 11, QtGui.QFont.Bold)
  50. ltxt1="What do you want to do?"
  51. len1 = len(ltxt1)
  52. lbl1 = QtGui.QLabel(ltxt1, self)
  53. lbl1.setFont(myFont)
  54. lbl1.setFixedWidth(gui_width)
  55. lbl1.setAlignment(QtCore.Qt.AlignHCenter)
  56. lbl1.move(0,20)
  57. vbox.addWidget(lbl1)
  58.  
  59. for key,value in dic.items():
  60. global voffset
  61. btemp = butnum
  62. btn = QPushButton(" " + key, self)
  63. btn.setStyleSheet("Text-align:left")
  64. btn.setFixedWidth(but_width)
  65. btn.clicked.connect(partial(self.doit, value))
  66. lm1 = pos_button()
  67. if btemp % 2 == 0: btemp=btemp-1
  68. btn.move(lm1, (btemp*20)+voffset)
  69. butnum += 1
  70. if butnum == 15:
  71. voffset=120
  72. vbox.addWidget(btn)
  73.  
  74.  
  75. def doit(self, text):
  76. print("%s" % text)
  77. os.system(text)
  78.  
  79. if __name__ == "__main__":
  80. app = QApplication([])
  81. w = Window()
  82. w.show()
  83. app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement