Hi all,
I've a probleme with pygtk used in a thread.
My application can be presented like that : I have a main thread that do some things and that can lunch plugins. Plugins are lunched in a new thread thanks to threading module.
one of these plugins is a pygtk plugin :
it starts gtk with gtk.gdk.threads_init(), gtk.main(), show windows, etc.
Now the probleme is when I want to close this plugin : I close the main window, then do a gtk.main_quit(), but the windows opened don't close. GTK is no more active : I cannot do anything in them, but they are always here ...
Is it my Job to close them all before the gtk.main_quit() ?
Asterix
I come back with the same pb not resolved, but this time I have a little program that shows the problem :
If you want to try it, lAunch ( ;) ) core.py : it prints "core" every 2 seconds and launch a thread that use GTK and open 2 windows. When we close the main one (named Gajim), the other doesn't close :(
Any help would be greatly appreciated.
Asterix
#!/usr/bin/env python
import threading, time
class GajimThread(threading.Thread):
def __init__(self, name = None):
threading.Thread.__init__(self, target = self.run, name = name)
# END __init__
def run(self):
mod = compile("import %s" % self.getName(), self.getName(), "exec")
res = eval(mod)
mod = compile("%s.plugin()" % self.getName(), self.getName(), "exec")
res = eval(mod)
# END run
thr = GajimThread('gt')
thr.start()
while 1:
time.sleep(2)
print "core"
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <glade-interface> <widget class="GtkWindow" id="Gajim"> <property name="visible">True</property> <property name="title" translatable="yes">Gajim</property> <property name="type">GTK_WINDOW_TOPLEVEL</property> <property name="window_position">GTK_WIN_POS_NONE</property> <property name="modal">False</property> <property name="default_width">150</property> <property name="default_height">400</property> <property name="resizable">True</property> <property name="destroy_with_parent">False</property> <property name="decorated">True</property> <property name="skip_taskbar_hint">False</property> <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Mon, 23 Aug 2004 08:35:29 GMT"/> <child> <widget class="GtkVBox" id="vbox1"> <property name="visible">True</property> <property name="homogeneous">False</property> <property name="spacing">0</property> <child> <widget class="GtkHandleBox" id="handlebox2"> <property name="visible">True</property> <property name="shadow_type">GTK_SHADOW_OUT</property> <property name="handle_position">GTK_POS_LEFT</property> <property name="snap_edge">GTK_POS_TOP</property> <child> <widget class="GtkMenuBar" id="menubar1"> <property name="visible">True</property> <child> <widget class="GtkImageMenuItem" id="gajim_menu"> <property name="visible">True</property> <property name="label" translatable="yes">_Menu</property> <property name="use_underline">True</property> <child internal-child="image"> <widget class="GtkImage" id="image161"> <property name="visible">True</property> <property name="stock">gtk-convert</property> <property name="icon_size">1</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> </child> <child> <widget class="GtkMenu" id="gajim_menu_menu"> <child> <widget class="GtkImageMenuItem" id="preferences"> <property name="visible">True</property> <property name="label" translatable="yes">_Preferences</property> <property name="use_underline">True</property> <signal name="activate" handler="on_preferences_activate" last_modification_time="Wed, 22 Oct 2003 21:18:29 GMT"/> <child internal-child="image"> <widget class="GtkImage" id="image162"> <property name="visible">True</property> <property name="stock">gtk-preferences</property> <property name="icon_size">1</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> </child> </widget> </child> <child> <widget class="GtkImageMenuItem" id="accounts"> <property name="visible">True</property> <property name="label" translatable="yes">A_ccounts</property> <property name="use_underline">True</property> <signal name="activate" handler="on_accounts_activate" last_modification_time="Wed, 22 Oct 2003 21:18:21 GMT"/> <child internal-child="image"> <widget class="GtkImage" id="image163"> <property name="visible">True</property> <property name="stock">gtk-select-color</property> <property name="icon_size">1</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> </child> </widget> </child> <child> <widget class="GtkImageMenuItem" id="browse_agents"> <property name="visible">True</property> <property name="label" translatable="yes">_Browse agents</property> <property name="use_underline">True</property> <signal name="activate" handler="on_browse_agents_activate" last_modification_time="Wed, 12 Nov 2003 10:50:33 GMT"/> <child internal-child="image"> <widget class="GtkImage" id="image164"> <property name="visible">True</property> <property name="stock">gtk-find</property> <property name="icon_size">1</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> </child> </widget> </child> <child> <widget class="GtkSeparatorMenuItem" id="separatormenuitem1"> <property name="visible">True</property> </widget> </child> <child> <widget class="GtkImageMenuItem" id="add"> <property name="visible">True</property> <property name="label" translatable="yes">Add</property> <property name="use_underline">True</property> <child internal-child="image"> <widget class="GtkImage" id="image165"> <property name="visible">True</property> <property name="stock">gtk-add</property> <property name="icon_size">1</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> </child> </widget> </child> <child> <widget class="GtkCheckMenuItem" id="show_offline"> <property name="visible">True</property> <property name="label" translatable="yes">Show Offline</property> <property name="use_underline">True</property> <property name="active">False</property> <signal name="activate" handler="on_show_offline_activate" last_modification_time="Wed, 31 Dec 2003 09:49:15 GMT"/> </widget> </child> <child> <widget class="GtkMenuItem" id="join_gc"> <property name="visible">True</property> <property name="label" translatable="yes">_Join Groupchat</property> <property name="use_underline">True</property> <signal name="activate" handler="on_join_gc_activate" last_modification_time="Tue, 03 Aug 2004 22:15:03 GMT"/> </widget> </child> <child> <widget class="GtkSeparatorMenuItem" id="separator1"> <property name="visible">True</property> </widget> </child> <child> <widget class="GtkImageMenuItem" id="about"> <property name="visible">True</property> <property name="label" translatable="yes">_About</property> <property name="use_underline">True</property> <signal name="activate" handler="on_about_activate" last_modification_time="Fri, 03 Oct 2003 12:49:50 GMT"/> <child internal-child="image"> <widget class="GtkImage" id="image166"> <property name="visible">True</property> <property name="stock">gtk-help</property> <property name="icon_size">1</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> </child> </widget> </child> <child> <widget class="GtkImageMenuItem" id="quit"> <property name="visible">True</property> <property name="label" translatable="yes">_Quit</property> <property name="use_underline">True</property> <signal name="activate" handler="on_quit_activate" last_modification_time="Fri, 03 Oct 2003 12:49:50 GMT"/> <accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/> <child internal-child="image"> <widget class="GtkImage" id="image167"> <property name="visible">True</property> <property name="stock">gtk-quit</property> <property name="icon_size">1</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> </child> </widget> </child> </widget> </child> </widget> </child> </widget> </child> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">True</property> </packing> </child> <child> <widget class="GtkScrolledWindow" id="scrolledwindow"> <property name="border_width">2</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> <property name="shadow_type">GTK_SHADOW_NONE</property> <property name="window_placement">GTK_CORNER_TOP_LEFT</property> <child> <widget class="GtkTreeView" id="treeview"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="headers_visible">False</property> <property name="rules_hint">False</property> <property name="reorderable">True</property> <property name="enable_search">True</property> <signal name="button_press_event" handler="on_treeview_event" last_modification_time="Tue, 30 Sep 2003 09:11:17 GMT"/> <signal name="row_activated" handler="on_row_activated" last_modification_time="Sun, 12 Oct 2003 18:11:52 GMT"/> <signal name="row_expanded" handler="on_row_expanded" last_modification_time="Wed, 10 Dec 2003 10:31:44 GMT"/> <signal name="row_collapsed" handler="on_row_collapsed" last_modification_time="Wed, 10 Dec 2003 10:54:27 GMT"/> <signal name="key_release_event" handler="on_treeview_event" last_modification_time="Tue, 18 May 2004 23:30:46 GMT"/> </widget> </child> </widget> <packing> <property name="padding">0</property> <property name="expand">True</property> <property name="fill">True</property> </packing> </child> <child> <widget class="GtkOptionMenu" id="optionmenu"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="history">0</property> <signal name="changed" handler="on_optionmenu_changed" last_modification_time="Thu, 11 Mar 2004 18:16:58 GMT"/> <child> <widget class="GtkMenu" id="menu_status"> <child> <widget class="GtkImageMenuItem" id="online"> <property name="visible">True</property> <property name="label" translatable="yes">Online</property> <property name="use_underline">True</property> </widget> </child> <child> <widget class="GtkImageMenuItem" id="away"> <property name="visible">True</property> <property name="label" translatable="yes">Away</property> <property name="use_underline">True</property> </widget> </child> <child> <widget class="GtkImageMenuItem" id="xa"> <property name="visible">True</property> <property name="label" translatable="yes">NA</property> <property name="use_underline">True</property> </widget> </child> <child> <widget class="GtkImageMenuItem" id="dnd"> <property name="visible">True</property> <property name="label" translatable="yes">DND</property> <property name="use_underline">True</property> </widget> </child> <child> <widget class="GtkImageMenuItem" id="invisible"> <property name="visible">True</property> <property name="label" translatable="yes">Invisible</property> <property name="use_underline">True</property> </widget> </child> <child> <widget class="GtkMenuItem" id="menuitem6"> <property name="visible">True</property> </widget> </child> <child> <widget class="GtkImageMenuItem" id="offline"> <property name="visible">True</property> <property name="label" translatable="yes">Offline</property> <property name="use_underline">True</property> </widget> </child> </widget> </child> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> </widget> </child> </widget> <widget class="GtkWindow" id="Chat"> <property name="visible">True</property> <property name="title" translatable="yes">Chat</property> <property name="type">GTK_WINDOW_TOPLEVEL</property> <property name="window_position">GTK_WIN_POS_NONE</property> <property name="modal">False</property> <property name="default_width">400</property> <property name="default_height">300</property> <property name="resizable">True</property> <property name="destroy_with_parent">False</property> <property name="decorated">True</property> <property name="skip_taskbar_hint">False</property> <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Sun, 12 Oct 2003 18:17:05 GMT"/> <child> <widget class="GtkVBox" id="vbox2"> <property name="border_width">5</property> <property name="visible">True</property> <property name="homogeneous">False</property> <property name="spacing">0</property> <child> <widget class="GtkHBox" id="hbox1"> <property name="border_width">5</property> <property name="visible">True</property> <property name="homogeneous">False</property> <property name="spacing">5</property> <child> <widget class="GtkButton" id="history_button"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="relief">GTK_RELIEF_NORMAL</property> <property name="focus_on_click">True</property> <signal name="clicked" handler="on_history_clicked" last_modification_time="Sun, 04 Apr 2004 05:30:58 GMT"/> <child> <widget class="GtkAlignment" id="alignment4"> <property name="visible">True</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xscale">0</property> <property name="yscale">0</property> <property name="top_padding">0</property> <property name="bottom_padding">0</property> <property name="left_padding">0</property> <property name="right_padding">0</property> <child> <widget class="GtkHBox" id="hbox8"> <property name="visible">True</property> <property name="homogeneous">False</property> <property name="spacing">2</property> <child> <widget class="GtkImage" id="image14"> <property name="visible">True</property> <property name="stock">gtk-justify-fill</property> <property name="icon_size">4</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> <child> <widget class="GtkLabel" id="label14"> <property name="visible">True</property> <property name="label" translatable="yes">History</property> <property name="use_underline">True</property> <property name="use_markup">False</property> <property name="justify">GTK_JUSTIFY_LEFT</property> <property name="wrap">False</property> <property name="selectable">False</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> </widget> </child> </widget> </child> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> <child> <widget class="GtkButton" id="clear_button"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="relief">GTK_RELIEF_NORMAL</property> <property name="focus_on_click">True</property> <signal name="clicked" handler="on_clear_clicked" last_modification_time="Thu, 18 Mar 2004 19:12:00 GMT"/> <child> <widget class="GtkAlignment" id="alignment5"> <property name="visible">True</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xscale">0</property> <property name="yscale">0</property> <property name="top_padding">0</property> <property name="bottom_padding">0</property> <property name="left_padding">0</property> <property name="right_padding">0</property> <child> <widget class="GtkHBox" id="hbox9"> <property name="visible">True</property> <property name="homogeneous">False</property> <property name="spacing">2</property> <child> <widget class="GtkImage" id="image15"> <property name="visible">True</property> <property name="stock">gtk-clear</property> <property name="icon_size">4</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> <child> <widget class="GtkLabel" id="label15"> <property name="visible">True</property> <property name="label" translatable="yes">Clear</property> <property name="use_underline">True</property> <property name="use_markup">False</property> <property name="justify">GTK_JUSTIFY_LEFT</property> <property name="wrap">False</property> <property name="selectable">False</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> </widget> </child> </widget> </child> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> <child> <widget class="GtkImage" id="image"> <property name="visible">True</property> <property name="stock">gtk-no</property> <property name="icon_size">4</property> <property name="xalign">0.5</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> <child> <widget class="GtkButton" id="button_contact"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="label" translatable="yes">Anonymous <[EMAIL PROTECTED]/res></property> <property name="use_underline">True</property> <property name="relief">GTK_RELIEF_NONE</property> <property name="focus_on_click">True</property> <signal name="clicked" handler="on_button_contact_clicked" last_modification_time="Sun, 15 Feb 2004 14:26:53 GMT"/> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">False</property> </packing> </child> </widget> <packing> <property name="padding">0</property> <property name="expand">False</property> <property name="fill">True</property> </packing> </child> <child> <widget class="GtkVPaned" id="vpaned1"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="position">170</property> <child> <widget class="GtkScrolledWindow" id="scrolledwindow3"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> <property name="shadow_type">GTK_SHADOW_IN</property> <property name="window_placement">GTK_CORNER_TOP_LEFT</property> <child> <widget class="GtkTextView" id="conversation"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="editable">False</property> <property name="overwrite">False</property> <property name="accepts_tab">True</property> <property name="justification">GTK_JUSTIFY_LEFT</property> <property name="wrap_mode">GTK_WRAP_WORD</property> <property name="cursor_visible">False</property> <property name="pixels_above_lines">0</property> <property name="pixels_below_lines">0</property> <property name="pixels_inside_wrap">0</property> <property name="left_margin">0</property> <property name="right_margin">0</property> <property name="indent">0</property> <property name="text" translatable="yes"></property> </widget> </child> </widget> <packing> <property name="shrink">True</property> <property name="resize">True</property> </packing> </child> <child> <widget class="GtkScrolledWindow" id="scrolledwindow4"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> <property name="shadow_type">GTK_SHADOW_IN</property> <property name="window_placement">GTK_CORNER_TOP_LEFT</property> <child> <widget class="GtkTextView" id="message"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="editable">True</property> <property name="overwrite">False</property> <property name="accepts_tab">True</property> <property name="justification">GTK_JUSTIFY_LEFT</property> <property name="wrap_mode">GTK_WRAP_WORD</property> <property name="cursor_visible">True</property> <property name="pixels_above_lines">0</property> <property name="pixels_below_lines">0</property> <property name="pixels_inside_wrap">0</property> <property name="left_margin">0</property> <property name="right_margin">0</property> <property name="indent">0</property> <property name="text" translatable="yes"></property> <signal name="key_press_event" handler="on_msg_key_press_event" last_modification_time="Mon, 13 Oct 2003 17:48:48 GMT"/> </widget> </child> </widget> <packing> <property name="shrink">True</property> <property name="resize">True</property> </packing> </child> </widget> <packing> <property name="padding">0</property> <property name="expand">True</property> <property name="fill">True</property> </packing> </child> </widget> </child> </widget> </glade-interface>
import pygtk
pygtk.require('2.0')
import gtk
from gtk import TRUE, FALSE
import gtk.glade
GTKGUI_GLADE='gtkgui.glade'
class message_Window:
def __init__(self):
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Chat')
class roster_Window:
def on_quit(self, widget):
print "plugin gt stopped"
gtk.main_quit()
def __init__(self):
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Gajim')
self.xml.signal_connect('gtk_widget_destroy', self.on_quit)
class plugin:
def __init__(self):
gtk.gdk.threads_init()
self.roster = roster_Window()
self.msg = message_Window()
gtk.main()
print "plugin gt loaded"
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
