Guest User

Untitled

a guest
May 13th, 2014
178
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PyQt4 import QtGui, QtCore
  2. import sys
  3.  
  4. class GUI:
  5.     CHANNELS = [
  6.         { "c":  "channel 1",    "g":    "command" },
  7.         { "c":  "channel 2",    "g":    "command" },
  8.         { "c":  "channel N",    "g":    "general" }
  9.     ]
  10.  
  11.     CHANNEL_NAME = "c"
  12.     CHANNEL_GROUP = "g"
  13.  
  14. class Handler(QtGui.QMainWindow):
  15.     #button_map = QtCore.pyqtSignal()
  16.     signalMapper = QtCore.QSignalMapper()
  17.    
  18.     def __init__(self):
  19.         super(Handler,self).__init__()
  20.         self.setupGui()
  21.         self.generate_channels()
  22.  
  23.     def setupGui(self):
  24.         w = QtGui.QWidget(self)
  25.         layout = QtGui.QHBoxLayout(w)
  26.         self.commandLayout = QtGui.QVBoxLayout()
  27.         self.generalLayout = QtGui.QVBoxLayout()
  28.         layout.addLayout(self.commandLayout)
  29.         layout.addLayout(self.generalLayout)
  30.         self.setCentralWidget(w)
  31.        
  32.  
  33.     def generate_channels(self):
  34.         for i in range(0,len(GUI.CHANNELS)):
  35.             self.button = QtGui.QPushButton(GUI.CHANNELS[i][GUI.CHANNEL_NAME])
  36.             self.signalMapper.setMapping(self.button, GUI.CHANNELS[i][GUI.CHANNEL_NAME])  
  37.             self.button.clicked.connect(self.signalMapper.map)
  38.             if GUI.CHANNELS[i][GUI.CHANNEL_GROUP] == "command":
  39.                 self.commandLayout.addWidget(self.button)
  40.             elif GUI.CHANNELS[i][GUI.CHANNEL_GROUP] == "general":
  41.                 self.generalLayout.addWidget(self.button)
  42.  
  43.         #self.signalMapper.mapped.connect(self.button_map)  
  44.         #self.button_map.connect(self.channel_clicked)
  45.         self.signalMapper.mapped[str].connect(self.channel_clicked)
  46.         #                        /\ -- connecting overloaded signals
  47.  
  48.  
  49.     def channel_clicked(self, channel):
  50.         print("I got here!")
  51.         print(channel)
  52.  
  53.  
  54. app = QtGui.QApplication(sys.argv)
  55. h = Handler()
  56. h.show()
  57. app.exec_()
RAW Paste Data