gtk ui block
来源:互联网 发布:网络新词及意思 编辑:程序博客网 时间:2024/06/06 20:56
Emitting signals from a thread will run the handler in the same thread. You shouldn't call gtk functions from a thread other than the main one. If you insist on doing so you have to make sure to acquire the GDK lock first by wrapping your code in gtk.gdk.threads_enter() ... gtk.gdk.threads_leave() calls. In this case you also have to call gtk.gdk.thread_init() as otherwise the main loop will never release the GDK lock. The easier solution is to push the signal emission to the main thread by replacing self.emit('ASignal') with gobject.idle_add(self.emit, 'ASignal') which guarantees the handler will also run in the main thread (which already has the GDK lock).
Regards.
On Thu, Jul 25, 2013 at 4:56 PM, Todong Ma <[hidden email]> wrote:
Hi, everyone
I met a problem that UI will be blocked forever if I emit a signal from a thread to create a message dialog.
Following code will reproduce the issue, please let me give a short explanation: AThread thread defines a custom signal named "ASignal", and the signal handler is aSignal() function of MainWindow class. The aSignal() function is used to display a message dialog. Emitting "ASignal" signal will display the message dialog successfully but the UI is blocked forever.import gtk
import gobject
import threading
class AThread(threading.Thread, gobject.GObject):
__gsignals__ = {
'ASignal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
}
def __init__(self):
threading.Thread.__init__(self)
gobject.GObject.__init__(self)
def run(self):
self.emit('ASignal')
class MainWindow(gtk.Window):
def aSignal(self, obj):
dialog = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, 'asdfasf')
dialog.run()
dialog.destroy()
gobject.threads_init()
w = MainWindow()
t = AThread()
t.connect('ASignal', w.aSignal)
t.start()
gtk.main()
Any suggestion is appreciated.
Thanks,
0 0
- gtk ui block
- block-ui
- UI - Block
- ADF Block UI Input
- Composite UI Application Block
- JQuery Block UI V2
- JQuery Block UI V2
- jquery block ui
- jquery block ui 下载
- UI Block高级
- UI Block传值
- UI中的Block传值
- UI 10 block 练习
- IOS UI-Block
- [代码实例][gtk+]使用builder创建UI
- 初试Composite UI Application Block
- IOS笔记UI--Block传值
- iOS UI 12 block传值
- c++多线程学习
- Fortran把未分配的数组传入子过程,在子过程中分配空间
- 动态规划算法剖析
- UFT\QTP 12 即将发布!
- Core Animation 学习笔记
- gtk ui block
- Kerberos认证流程详解
- POJ 1815 最小点割集
- CUGB专题训练之数据结构:E - Keywords Search(HDU 2222 AC自动机经典入门模板题)
- editplus的注册码
- C语言函数参数传递之痛
- Xpose
- android实现translate位移动画效果
- 我的博客