vendredi 26 août 2016

How can I print the checkbox that is clicked in pyqt.

I want to push a button and show the available interfaces, when one is clicked i want to print it

#!/usr/bin/python
from PyQt4 import QtCore, QtGui
from struct import *
import sys
import pcapy
from PyQt4.QtCore import * 
from PyQt4.QtGui 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)


class Ui_MainWindow(object):

     def setupUi(self, MainWindow):
         MainWindow.setObjectName(_fromUtf8("MainWindow"))
         MainWindow.resize(800, 616)
         self.centralwidget = QtGui.QWidget(MainWindow)
         self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
         self.listInterface = QtGui.QListView(self.centralwidget)
         self.listInterface.setGeometry(QtCore.QRect(230, 150, 256, 192))
         self.listInterface.setObjectName(_fromUtf8("listInterface"))
         self.model = QStandardItemModel(self.listInterface)
         self.btnCapturar = QtGui.QPushButton(self.centralwidget)
         self.btnCapturar.setGeometry(QtCore.QRect(310, 390, 98, 27))
         self.btnCapturar.setObjectName(_fromUtf8("btnCapturar"))
         self.btnCapturar.clicked.connect(self.llenarLista)
         MainWindow.setCentralWidget(self.centralwidget)
         self.menubar = QtGui.QMenuBar(MainWindow)
         self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 25))
         self.menubar.setObjectName(_fromUtf8("menubar"))
         MainWindow.setMenuBar(self.menubar)
         self.statusbar = QtGui.QStatusBar(MainWindow)
         self.statusbar.setObjectName(_fromUtf8("statusbar"))
         MainWindow.setStatusBar(self.statusbar)
         self.retranslateUi(MainWindow)

         QtCore.QMetaObject.connectSlotsByName(MainWindow)

     def retranslateUi(self, MainWindow):
         MainWindow.setWindowTitle(_translate("MainWindow", "Captura", None))
         self.btnCapturar.setText(_translate("MainWindow", "Show", None))

     def llenarLista(self,listWidget):

         devices = pcapy.findalldevs()
         for d in devices:
             item = QStandardItem(d)
         # add a checkbox to it
             item.setCheckable(True)
         # Add the item to the model
             self.model.appendRow(item)
         # Apply the model to the list view
         self.listInterface.setModel(self.model)



if __name__ == "__main__":
     app = QtGui.QApplication(sys.argv)
     MainWindow = QtGui.QMainWindow()
     ui = Ui_MainWindow()
     ui.setupUi(MainWindow)
     MainWindow.show()
     sys.exit(app.exec_())

I have take most of the code from http://ift.tt/2bn2NmM




Aucun commentaire:

Enregistrer un commentaire