Re: [pygtk] UI will be blocked if creating a message dialog by emitting a signal

2013-07-25 Thread Todong Ma
Thanks a lot, it works now! So far I'm using a really stupid method: 
using gobject.timeout_add() to check a global flag variable every 0.1 
seconds, if the flag is set, the message dialog will be shown.. But now 
they can be fixed:)


On 2013/7/25 23:15, Niklas Koep wrote:
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 <mailto:gbstac...@gmail.com>> 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,

___
pygtk mailing list pygtk@daa.com.au <mailto:pygtk@daa.com.au>
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/




___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

[pygtk] UI will be blocked if creating a message dialog by emitting a signal

2013-07-25 Thread Todong Ma

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,
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

[pygtk] How to get hwnd of StatusIcon

2013-07-16 Thread Todong Ma

Hi everyone,
I want to display a balloon notification near system tray icon, I found 
calling Shell_NotifyIcon with .szInfo and .szInfoTitle will show a 
balloon message.


Widget.get_window() can be used to get a Widget's hwnd, but how could I 
get hwnd of StatusIcon since it's direct child class of GObject?


Thanks,
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] gobject.timeout_add() won't work after calling gtk.threads_init() on windows xp

2013-06-26 Thread Todong Ma

On 2013/6/26 18:56, Todong Ma wrote:

Hi, everyone

Following simple code will hang forever on windows XP, and the "check 
dialog" text is never outputted to console. The window created in the 
code showed but is blocked (when I move mouse into the window area, 
the mouse pointer is always a "loading" icon)


*/|import  gtk
import  gobject

def  checkDialog():
   print  'check dialog'
   return  True

gobject.timeout_add(500,  checkDialog)
gtk.threads_init()
w=  gtk.Window()
w.show()
gtk.main()|/*

While same code works well on Windows 7

Runtime details: Windows XP SP3, python 2.7.5, pytgtk-2.24-allinone


Just now Juhaz on the IRC channel told me I should try 
gtk.gdk.threads_init() or gobject.threads_init() instead of 
gtk.threads_init().

Then I tried them and found it works by using gobject.threads_init()!

Thank you all!
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

[pygtk] gobject.timeout_add() won't work after calling gtk.threads_init() on windows xp

2013-06-26 Thread Todong Ma

Hi, everyone

Following simple code will hang forever on windows XP, and the "check 
dialog" text is never outputted to console. The window created in the 
code showed but is blocked (when I move mouse into the window area, the 
mouse pointer is always a "loading" icon)


*/|import  gtk
import  gobject

def  checkDialog():
  print  'check dialog'
  return  True

gobject.timeout_add(500,  checkDialog)
gtk.threads_init()
w=  gtk.Window()
w.show()
gtk.main()|/*

While same code works well on Windows 7

Runtime details: Windows XP SP3, python 2.7.5, pytgtk-2.24-allinone


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/