title: Python & PyQt. Clipboard contents to listwidget
body: <p>I am writing my first python app with PyQt4. I'm a beginner in python and generally new to programming. Basically what this app does is monitor clipboard data changes and put/display this as an item in QlistWidget. You can also add items manually by copy pasting the data and clicking the add button. As for monitoring data and automatically adding it in the list widget, I've added a condition where a radio button needs to be toggled for the "monitoring feature" to do its thing. The manual way of adding items works but the monitoring feature doesn't seem to be working. It doesn't add the data (saved in the clipboard) to the list widget. I think I seem to be missing something. 
  I'm using Python 2.7 and PyQt 4.11</p>
  
  <p>Here is my code. I removed the extra lines of code (stylesheets &amp; etc~).</p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  from PyQt4.QtGui import *
  from PyQt4.QtCore import *
  
  try:
      _fromUtf8 = QtCore.QString.fromUtf8
  except AttributeError:
      def _fromUtf8(s):
          return s
  
  try:
      _encoding = QtGui.QApplication.UnicodeUTF8
      def _translate(context, text, disambig):
          return QtGui.QApplication.translate(context, text, disambig, _encoding)
  except AttributeError:
      def _translate(context, text, disambig):
          return QtGui.QApplication.translate(context, text, disambig)
  
  rbs = False
  class Ui_Form(QtGui.QWidget):
      def __init__(self):
          QtGui.QWidget.__init__(self)
          self.setupUi(self)
      def setupUi(self, Form):
          Form.setObjectName(_fromUtf8("Form"))
          Form.resize(385, 277)
          self.gridLayout = QtGui.QGridLayout(Form)
          self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
          self.radioButton = QtGui.QRadioButton(Form)
          self.radioButton.setObjectName(_fromUtf8("radioButton"))
          self.gridLayout.addWidget(self.radioButton, 0, 1, 1, 1)
  
          self.radioButton.toggled.connect(self.toggledRB)
  
          self.lineEdit = QtGui.QLineEdit(Form)
          self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
          self.gridLayout.addWidget(self.lineEdit, 1, 0, 1, 1)
  
          self.pushButton = QtGui.QPushButton(Form)
          self.pushButton.setObjectName(_fromUtf8("pushButton"))
          self.gridLayout.addWidget(self.pushButton, 1, 1, 1, 1)
  
          self.pushButton.clicked.connect(self.addItem)
  
          self.listWidget = QtGui.QListWidget(Form)
          self.listWidget.setEditTriggers(QtGui.QAbstractItemView.DoubleClicked|QtGui.QAbstractItemView.EditKeyPressed|QtGui.QAbstractItemView.SelectedClicked)
          self.listWidget.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems)
          self.listWidget.setMovement(QtGui.QListView.Snap)
          self.listWidget.setUniformItemSizes(False)
          self.listWidget.setObjectName(_fromUtf8("listView"))
          self.gridLayout.addWidget(self.listWidget, 2, 0, 1, 2)
  
  
          self.retranslateUi(Form)
          QtCore.QMetaObject.connectSlotsByName(Form)
  
      def retranslateUi(self, Form):
          Form.setWindowTitle(_translate("Form", "Form", None))
  
          self.radioButton.setText(_translate("Form", "monitor clipboard", None))
          self.pushButton.setText(_translate("Form", "Add", None))
  
      def toggledRB(self, bool):
          global rbs
          if self.radioButton.isChecked():
              rbs = True
          else:
              rbs = False
          print rbs
  
      def addItem(self):
          yyy = self.lineEdit.text()
          self.listWidget.addItem(yyy)
  
      def dataReceiver(self, intel):
          print 'data is here!'
          self.listWidget.addItem(intel)
  
  class clipboardListener(QObject):  
  
      @pyqtSlot()  
      def changedSlot(self):
          global rbs
          print 'clipboard data detected!'
          if rbs == True:
              intel = QApplication.clipboard().text()
              print intel
              xxx = Ui_Form()
              xxx.dataReceiver(intel)
          else:
              print 'False Alarm. There was no data. I was just kidding.'
  
  if __name__ == "__main__":
      import sys
      app = QtGui.QApplication(sys.argv)
      Form = QtGui.QWidget()
      ui = Ui_Form()
      ui.setupUi(Form)
      Form.show()
  
      listener = clipboardListener()
      QObject.connect(QApplication.clipboard(),SIGNAL("dataChanged()"),listener,SLOT("changedSlot()"))
  
      sys.exit(app.exec_()) 
  </code></pre>