zoukankan      html  css  js  c++  java
  • TopicSpace: PyQt4, QThread example

    TopicSpace: PyQt4, QThread example

    Title: PyQt4, QThread example

    Last Modified: 10.16.2008

    This is about the most simple example I could think of how to make a thread

    #!/usr/bin/env python
    """This is a short program to have an external program grab data for me and get displayed without blocking the whole program"""
    from PyQt4 import QtGui,QtCore
    import sys
    class TerminalViewer(QtGui.QWidget):
    	def __init__(self,parent=None):
    		QtGui.QWidget.__init__(self,parent)
    		self.Label = QtGui.QLabel("Waiting for Something",self)
    		self.DataCollector = TerminalX(self)
    		self.connect(self.DataCollector,QtCore.SIGNAL("Activated ( QString ) "), self.Activated)
    		self.DataCollector.start()
    	def Activated(self,newtext):
    		self.Label.setText(newtext)
    	def closeEvent(self,e):
    		e.accept()
    		app.exit()
    
    class TerminalX(QtCore.QThread):
    	def __init__(self,parent=None):
    		QtCore.QThread.__init__(self,parent)
    		self.test = ''
    	def run(self):
    		while self.test != 'q':
    			self.test = raw_input('enter data: ')
    			self.emit(QtCore.SIGNAL("Activated( QString )"),self.test)
    
    app = QtGui.QApplication(sys.argv)
    qb = TerminalViewer()
    qb.show()
    sys.exit(app.exec_())
    

    This starts a QLabel with some text, if you type in the terminal where you started the program then you can change the text on the widget. The "start()" method executes the "run()" method in addition to starting the thread in a separate process.

  • 相关阅读:
    程序员学习方法差在哪里
    解析域名
    tomcat下的公共jar包配置
    Ubuntu 16.04 修改状态栏位置
    sqlite3 C语言 API 函数
    vim配置文件
    关于 ioctl 函数
    字符设备基础了解
    Ubuntu14.04搭建Boa服务
    gcc 交叉工具链中工具使用(arm-linux-xxx)
  • 原文地址:https://www.cnblogs.com/lexus/p/2820151.html
Copyright © 2011-2022 走看看