title: python pyqt4 contextMenu on multiple pushButtons
body: <p>I'm trying to build off this example that I've came across from here:
  <a href="https://stackoverflow.com/questions/4815925/python-pyqt4-contextmenu-on-pushbutton?answertab=oldest#tab-top">Right click contextMenu on QPushButton</a></p>
  
  <p>How would I get this to work when I'm creating the button dynamically? I can't figure out a way to dynamically create the method <code>on_context_menu</code>.</p>
  
  <p>Here is the code that I have so far.</p>
  
  <pre><code>import sys
  from PyQt4 import QtGui,QtCore
  import sip
  
  class LayoutTest(QtGui.QWidget):
      def __init__(self):
          super(LayoutTest, self).__init__()
          self.setGeometry(300, 300, 400, 200)
          VmasterLayout = QtGui.QVBoxLayout(self)
          self.Hbox = QtGui.QHBoxLayout()
  
          for i in range(1,4):
              self.butVal = 'buttonMenu_%s' % i
              self.button = QtGui.QPushButton(self.butVal)
              self.button.clicked.connect(self.allCheckButton)
              self.button.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
              self.connect(self.button, QtCore.SIGNAL('customContextMenuRequested(const QPoint&amp;)'), self.on_context_menu)
  
              # create context menu
              self.popMenu = QtGui.QMenu(self)
              action = QtGui.QActionGroup(self, exclusive=True)
              listVer = ['image_v001','image_v003','image_v012','image_v120','image_v140', 'image_v013']
              for i, vDir in enumerate(sorted(listVer)):
                  x = action.addAction(QtGui.QAction( vDir, self, checkable = True))
                  x.triggered.connect(self.foo(x.text())) 
                  self.popMenu.addAction(x)
                  self.popMenu.addSeparator()
  
              self.Hbox.addWidget(self.button)
  
          VmasterLayout.addLayout(self.Hbox)
  
      def on_context_menu(self, point):
          # show context menu
          self.popMenu.exec_(self.button.mapToGlobal(point)) 
  
      def foo(self, name):
          def poo():
              print 'Image version is: %s' % name
          return poo
  
      def allCheckButton(self):
          point = QtGui.QCursor.pos()
          print point
  
  def run():
      app = QtGui.QApplication(sys.argv)
      ex = LayoutTest()
      ex.show()
      sys.exit(app.exec_())
  
  if __name__ == "__main__":
      run()
  </code></pre>