www*_*iam 5 python user-interface multithreading pygtk
我正在编写一个带有 GUI 的多线程 Python 程序,其中有几个模块可以通过更改文本和背景颜色来“触摸”GUI。我目前正在使用 PyGTK,发现 GUI 有时会“无提示”崩溃(没有错误消息;程序只是终止),有时会遇到分段错误。
该站点指出 GTK 并非完全线程安全,并且 PyGTK 多线程编程很棘手。是否有更好的 Python GUI 框架用于多线程程序且不太可能产生问题?
哦,我绝对推荐PyQt4。起初,我并没有理解所有这些SIGNAL和EMIT废话,但现在我已经用它编写了一个程序,该QThread模块非常有用。
至于稳定性,我从来没有遇到过崩溃。即使当我调试半功能代码时,QT 也没有任何问题。每当我单击带有无效信号槽的按钮时,它都会向控制台窗口抛出错误。
另一方面,GTK 只是“偶尔爆发一次,没有任何错误”。只是你的描述性极强且友好Segmentation Fault。这是我觉得使用 PyQt 很愉快的原因之一。当你遇到错误时,你实际上知道出了什么问题。
我很确定这只是个人喜好,但还有一个优点是 Mac、Linux 和 Windows 上具有原生外观的 GUI。Windows 上的 GTK+(不要误会我的意思。我使用 Ubuntu)只是有一种 X-org 的感觉,这让我感到不安。
祝你好运!
为了让 PyQt 更有吸引力,这里是我的书籍装订应用程序的摘录(有点乱):
class Binder(QtCore.QThread):
'''
Class for binding the actual book
'''
def __init__(self, parent = None):
super(Binder, self).__init__(parent)
def initialize(self, pages, options, outfile):
self.pages = pages
self.options = options
self.outFile = outfile
self.book = organizer.Book()
self.enc = Encoder(self.options)
self.ocr = ocr.OCR(self.options)
self.connect(self.enc, QtCore.SIGNAL('updateProgress(int, int)'), self.updateProgress)
def updateProgress(self, percent, item):
self.emit(QtCore.SIGNAL('updateProgress(int, QString)'), int(percent), 'Binding the book...')
self.emit(QtCore.SIGNAL('updateBackground(int, QColor)'), int(item), QtGui.QColor(170, 255, 170, 120))
if int(percent) == 100:
time.sleep(0.5)
self.emit(QtCore.SIGNAL('finishedBinding'))
def run(self):
self.die = False
for page in self.pages:
self.add_file(page, 'page')
if not self.die:
self.analyze()
if not self.die:
self.book.get_dpi()
if self.options['ocr'] and not self.die:
self.get_ocr()
if not self.die:
self.enc.initialize(self.book, self.outFile)
self.enc.start()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4621 次 |
| 最近记录: |