#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
class InputDialog(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.vbox=QtGui.QVBoxLayout(self)
self.lst=QtGui.QListWidget(self)
self.lst.setSortingEnabled(True)
for x in ('digwtx', 'cctv', 'google', 'slackware', 'gentoo', u'中国'):
self.lst.addItem(x)
self.lst.setCurrentRow(2)
self.btn_1=QtGui.QPushButton('Show', self)
self.btn_2=QtGui.QPushButton('Remove', self)
self.btn_1.setFixedWidth(100)
self.btn_2.setFixedHeight(20)
self.vbox.addWidget(self.lst)
self.vbox.addWidget(self.btn_1)
self.vbox.addWidget(self.btn_2)
self.connect(self.lst, QtCore.SIGNAL('itemDoubleClicked (QListWidgetItem *)'), self.textDialog)
self.connect(self.btn_1, QtCore.SIGNAL('clicked()'), self.Show)
self.connect(self.btn_2, QtCore.SIGNAL('clicked()'), self.Remove)
def textDialog(self):
self.lst.takeItem(self.lst.currentRow())
def Show(self):
count=self.lst.count()
for i in range(count):
print unicode(self.lst.item(i).text())
def Remove(self):
self.lst.takeItem(self.lst.currentRow())
def main():
app = QtGui.QApplication(sys.argv)
icon = InputDialog()
icon.show()
app.exec_()
if __name__=='__main__':
main()
|