Thread 中的 Python GTK 窗口

发布于 2024-11-11 04:40:09 字数 986 浏览 3 评论 0原文

我有一个 CLI 应用程序,它正在挖掘一些数据,在需要时启动一个线程,创建包含一些信息的 GTK 窗口。然而,CLI(主线程)仍然在后台分析数据,因此可能会创建大量窗口。如果我关闭窗口,销毁事件实际上会被触发,我在 CLI 中得到了一条调试行,但窗口被锁定。

我必须使用一些神奇的命令?

我在主线程中创建这样的窗口:

    gtk.gdk.threads_init()
    notifyWindow = NotifyWindow()
    notifyWindow.start()

这是 NotifyWindow(Thread).destroy

def destroy(self, widget, data=None):
    print "destroy signal occurred"
    gtk.main_quit()

这是 NotifyWindow(Thread).run

def run(self):

    self.window = gtk.glade.XML( "hadinfo.glade" )

    self.window_main = self.window.get_widget("window_main")

    if (self.window_main):
        self.window_main.connect("destroy", self.destroy)
        self.window_main.connect("delete_event", self.delete_event)

    self.button_cancel = self.window.get_widget("button_cancel")
    self.button_cancel.connect("clicked", self.destroy)

    self.window.get_widget("window_main").show()

    gtk.main()

I have a CLI application, which is digging some data, in case of need, fires up a thread which creates GTK window with some information. However the CLI (main thread) still analyzes the data in the background, so there could be numerous windows created. In case I close the window, the destroy event is actually fired up, I got a debug line in CLI, but the window locks up.

Some magical command that I have to use ?

I create window like this in the main thread:

    gtk.gdk.threads_init()
    notifyWindow = NotifyWindow()
    notifyWindow.start()

This is NotifyWindow(Thread).destroy

def destroy(self, widget, data=None):
    print "destroy signal occurred"
    gtk.main_quit()

This is NotifyWindow(Thread).run

def run(self):

    self.window = gtk.glade.XML( "hadinfo.glade" )

    self.window_main = self.window.get_widget("window_main")

    if (self.window_main):
        self.window_main.connect("destroy", self.destroy)
        self.window_main.connect("delete_event", self.delete_event)

    self.button_cancel = self.window.get_widget("button_cancel")
    self.button_cancel.connect("clicked", self.destroy)

    self.window.get_widget("window_main").show()

    gtk.main()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么敢 2024-11-18 04:40:09

使用 gtk.threads_enter() 并保留主要调用应该会有所帮助。

查看 PyGtk 常见问题解答:PyGtk 常见问题解答

using a gtk.threads_enter() and leave around your main call should help.

Take a look at the PyGtk Faq : PyGtk FAQ

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文