Re: [pygtk] use gtk.FileChooser to check mime type

2013-09-27 Thread Niklas Koep
Hey, there are two ways to do this that I can think of off the top of my
head. One is using
gio.content_type_guesshttps://developer.gnome.org/pygobject/2.28/gio-functions.html#function-gio--content-type-guess,
the other (and likely slower albeit more accurate) way would be to use a
gio.File instance like so:

file_ = gio.File(filename)
info = file_.query_info(standard::content-type) or equivalently info
= file_.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)
mimetype = info.get_content_type()

Regards.


On Wed, Sep 25, 2013 at 12:04 AM, Giuseppe Penone gius...@gmail.com wrote:

 Hi,
 I'm using gtk.FileChooserDialog with a filter to display only text/plain
 files and this works fine:

 filter = gtk.FileFilter()
 filter.add_mime_type(text/plain)
 chooser.add_filter(filter)

 But if I need to check if a file is of this mime type, using python module
 mimetypes is not so good in detecting the proper mime type.

 Is it possible somehow to use gtk.FileChooser engine to retrieve files
 with a mime type in a directory without going through the dialog?

 I tried to do it without running the dialog and just doing:

 ...
 chooser.add_filter(filter)
 chooser.set_current_folder(foldername)
 chooser.select_all()
 print chooser.get_filenames()

 but I always get an empty list, it seems that without chooser.run() it
 doesn't work, unfortunately I cannot instantiate just a gtk.FileChooser()

 Cheers,
 Giuseppe.


 ___
 pygtk mailing list   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/

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

2013-07-25 Thread Niklas Koep
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 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
 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/

Re: [pygtk] gstreamer 0.10 to 1.0 and gtk2 to gtk3 errors

2013-02-02 Thread Niklas Koep
It appears I completely misunderstood the --add-init-section option of
g-ir-scanner. It's only relevant for the creation of the introspection
data. It's not a code section which gets called whenever the respective
gobject language bindings (in your case pygobject) load a typelib. So in
any case you have to call Gst.init() which you may or may not be doing
anyway.


2013/2/1 Niklas Koep niklas.k...@gmail.com

 I think a minimal program which reproduces the error would be helpful
 here. What exact versions of gstreamer, pygobject (python2-gobject), etc.
 are you using? In any case, calling Gst.ElementFactory.make with one
 argument from an interactive session already raises a TypeError exception
 for me as the method requires you to specify a unique name, as well as the
 element type. I guess default arguments aren't supported by pygobject yet
 which means you have to pass both 'xvimagesink' and None to the method for
 gstreamer to create a name for the element by itself.

 Also, do you call Gst.init() before making any other gstreamer calls? I
 was under the impression this was called upon importing the module, but for
 some reason the interpreter complains about it if you don't explicitly call
 it. Weirdly enough according to the gstreamer-1.0 source g-ir-scanner is
 called with --add-init-section=gst_init(NULL, NULL);.

 Regards, Niklas



 2013/1/31 laguillaumie sylvain s.la...@free.fr

 hi list(s)

 i try to port my app to gtk3/gst1.0 but have some errors i dont
 understand i can post my code if needed but does someone have an idear on
 the followings errors...

 i post in pygtk and gst list but i have this crash since i used :

 self.player.videosink = Gst.ElementFactory.make('**xvimagesink')


 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning: cannot
 register existing type `GstObject'
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning:
 g_once_init_leave: assertion `result != 0' failed
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning:
 g_type_register_static: assertion `parent_type  0' failed
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning: interface
 type `GstImplementsInterface' or prerequisite type `invalid' invalid
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning: cannot add
 interface type `GstColorBalance' to type `GstPlayBin' which does not
 conform to prerequisite `GstImplementsInterface'
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning: cannot add
 interface type `GstColorBalance' to type `GstPlaySink' which does not
 conform to prerequisite `GstImplementsInterface'
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning:
 /build/buildd/glib2.0-2.34.1/.**/gobject/gsignal.c:2459: signal
 `value-changed' is invalid for instance `0x9f680a8'
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/module.py:152: Warning: cannot
 register existing type `GstNavigation'
   g_type = info.get_g_type()
 /usr/lib/python2.7/dist-**packages/gi/module.py:156: Warning:
 g_type_get_qdata: assertion `node != NULL' failed
   type_ = g_type.pytype
 /usr/lib/python2.7/dist-**packages/gi/types.py:240: Warning: cannot
 register existing type `GstNavigation'
   register_interface_info(cls.__**info__.get_g_type())
 Traceback (most recent call last):
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 243, in mro
 return mro(cls)
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 262, in mro
 not_head = [s for s in bases_of_subclasses if candidate in s[1:]]
   File /usr/lib/python2.7/dist-**packages/gi/module.py, line 269, in
 __getattr__
 return getattr(self._introspection_**module, name)
   File /usr/lib/python2.7/dist-**packages/gi/module.py, line 193, in
 __getattr__
 wrapper = metaclass(name, bases, dict_)
   File /usr/lib/python2.7/dist-**packages/gi/types.py

Re: [pygtk] gstreamer 0.10 to 1.0 and gtk2 to gtk3 errors

2013-02-01 Thread Niklas Koep
I think a minimal program which reproduces the error would be helpful here.
What exact versions of gstreamer, pygobject (python2-gobject), etc. are you
using? In any case, calling Gst.ElementFactory.make with one argument from
an interactive session already raises a TypeError exception for me as the
method requires you to specify a unique name, as well as the element type.
I guess default arguments aren't supported by pygobject yet which means you
have to pass both 'xvimagesink' and None to the method for gstreamer to
create a name for the element by itself.

Also, do you call Gst.init() before making any other gstreamer calls? I was
under the impression this was called upon importing the module, but for
some reason the interpreter complains about it if you don't explicitly call
it. Weirdly enough according to the gstreamer-1.0 source g-ir-scanner is
called with --add-init-section=gst_init(NULL, NULL);.

Regards, Niklas



2013/1/31 laguillaumie sylvain s.la...@free.fr

 hi list(s)

 i try to port my app to gtk3/gst1.0 but have some errors i dont understand
 i can post my code if needed but does someone have an idear on the
 followings errors...

 i post in pygtk and gst list but i have this crash since i used :

 self.player.videosink = Gst.ElementFactory.make('**xvimagesink')


 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning: cannot
 register existing type `GstObject'
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning:
 g_once_init_leave: assertion `result != 0' failed
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning:
 g_type_register_static: assertion `parent_type  0' failed
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning: interface
 type `GstImplementsInterface' or prerequisite type `invalid' invalid
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning: cannot add
 interface type `GstColorBalance' to type `GstPlayBin' which does not
 conform to prerequisite `GstImplementsInterface'
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning: cannot add
 interface type `GstColorBalance' to type `GstPlaySink' which does not
 conform to prerequisite `GstImplementsInterface'
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/types.py:47: Warning:
 /build/buildd/glib2.0-2.34.1/.**/gobject/gsignal.c:2459: signal
 `value-changed' is invalid for instance `0x9f680a8'
   return info.invoke(*args, **kwargs)
 /usr/lib/python2.7/dist-**packages/gi/module.py:152: Warning: cannot
 register existing type `GstNavigation'
   g_type = info.get_g_type()
 /usr/lib/python2.7/dist-**packages/gi/module.py:156: Warning:
 g_type_get_qdata: assertion `node != NULL' failed
   type_ = g_type.pytype
 /usr/lib/python2.7/dist-**packages/gi/types.py:240: Warning: cannot
 register existing type `GstNavigation'
   register_interface_info(cls.__**info__.get_g_type())
 Traceback (most recent call last):
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 243, in mro
 return mro(cls)
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 257, in mro
 bases_of_subclasses += list(map(mro, C.__bases__)) +
 [list(C.__bases__)]
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 262, in mro
 not_head = [s for s in bases_of_subclasses if candidate in s[1:]]
   File /usr/lib/python2.7/dist-**packages/gi/module.py, line 269, in
 __getattr__
 return getattr(self._introspection_**module, name)
   File /usr/lib/python2.7/dist-**packages/gi/module.py, line 193, in
 __getattr__
 wrapper = metaclass(name, bases, dict_)
   File /usr/lib/python2.7/dist-**packages/gi/types.py, line 240, in
 __init__
 register_interface_info(cls.__**info__.get_g_type())
 TypeError: must be an interface
 **
 ERROR:/build/buildd/pygobject-**3.4.0/gi/_gobject/pygobject.c:**946:pygobject_new_full:
 assertion failed: (tp != NULL)
 Abandon (core dumped)

 thanks

 __**_
 pygtk mailing list   pygtk@daa.com.au
 

Re: [pygtk] [GTK3] get background color

2013-01-29 Thread Niklas Koep
Sounds like you're trying to retrieve the default colors before the widget
has been realized. Consider this (mind you this uses pygtk):

#!/usr/bin/env python

import gtk


def main():
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect(delete-event, lambda *x: gtk.main_quit())

tv = gtk.TreeView()
tv.set_size_request(400, 250)

def realize(tv): print tv.get_style().bg[gtk.STATE_ACTIVE]
tv.connect(realize, realize)
realize(tv)

window.add(tv)
window.show_all()

gtk.main()

if __name__ == __main__:
main()


The output of this example on my machine is

#dcdad5
#f0f0f0

which just goes to show that the colors before and after realization
(might) differ.

Regards, Niklas



2013/1/29 Yann Leboulanger aste...@lagaule.org

 Hi,

 I'm trying to get the default / current background color of a textview.
 The code I do it:

 context = tv.get_style_context()
 color = context.get_background_color(**Gtk.StateFlags.NORMAL)

 But that returns a fully transparent color (0,0,0,0)

 If I first set a custom color with tv.override_background_color()**, then
 get_background_color() correctly works and returns the color I set.

 So how can I get the current default color?

 Thanks in advanced
 --
 Yann
 __**_
 pygtk mailing list   pygtk@daa.com.au
 http://www.daa.com.au/mailman/**listinfo/pygtkhttp://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/

Re: [pygtk] Key event handling and Pythons lake of switch statement

2013-01-28 Thread Niklas Koep
Just to quote the Python
docshttp://docs.python.org/2/tutorial/controlflow.html#if-statements
on
the subject: An if ... elif ... elif ... sequence is a substitute for the
switch or case statements found in other languages.

Regards


2013/1/27 David Ripton drip...@ripton.net

 On 01/27/2013 03:24 PM, Christian Mallwitz wrote:

  Where in C you would have something along the lines of:

   switch (event-keyval) {
 case GDK_Left: ...
 case GDK_BackSpace: ...
 ...
 }

 What is your preferred code style to handle that in Python? How about
 more than one keyval triggering the same action?


 If it's a small number of cases, just use if/elif.  (With or for the
 multiple value case.)

 If it's a large number of cases, you can use a dict, with functions or
 methods as the values.

 --
 David Riptondrip...@ripton.net

 __**_
 pygtk mailing list   pygtk@daa.com.au
 http://www.daa.com.au/mailman/**listinfo/pygtkhttp://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/

Re: [pygtk] Reload gtk.Image contents

2013-01-28 Thread Niklas Koep
If you're updating your gtk.Image contents via its set_from_file() method
you don't need to request an update at all -- it happens automatically.
Generally speaking, however, gtk.Widget implements a queue_draw() method
which can be used to invalidate the entire visible area of a widget which
in turn causes it to be redrawn. For your use this doesn't seem to be
required though. Hope this helps.



2013/1/27 Daniil Baturin dan...@baturin.org

 Hi,
 What is the proper way to reload gtk.Image contents?

 I want to make a simple educational gnuplot frontend that would allow
 playing with parametric curve coefficients by using spin buttons,
 expressions with substituted constants will be passed to gnuplot and
 generated png displayed in a gtk.Image. But I'm not sure how to request
 update of displayed image if the image has changed.


 --
 #!/usr/bin/env perl
 @a=split(//, daniil @ baturin  .  org );# Daniil Baturin
 @b=split(//,q/Px%!+o0Q6lh*7dp$**.@8#%|y{/);while($i24){$_.=
 chr((ord(@b[$i])-ord(@a[$i])+**62)%94+32);$i++};print$_\n#

 __**_
 pygtk mailing list   pygtk@daa.com.au
 http://www.daa.com.au/mailman/**listinfo/pygtkhttp://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/

Re: [pygtk] Reload gtk.Image contents

2013-01-28 Thread Niklas Koep
I've tested the what I described earlier today and it works. If there are
two distinct images on disk, then calling gtk.Image.set_from_file() will
automatically update the image gtk displays. This leads me to believe that
it's a timing issue you're facing. The plotter.plot() method wouldn't
happen to be asynchronous, would it? Because if it is it might just be the
case that you update the gtk.Image before the entire image generated by
gnuplot has been written to disk. Obviously, that's just a guess since I
don't know how your plot() method works internally. But it would explain
why the first update of your image (sometimes) doesn't take and the image
on disk actually appears correct if you look at it after a certain time.


2013/1/28 Daniil Baturin dan...@baturin.org

  I'm using set_from_file(), and it kind of works. The problem is that the
 image is updated only second time event handler that replots and invokes
 set_from_file() is triggered. I double checked replot occurs every time
 event is caught, when I open the image file manually it contains the
 updated plot.

 I added queue_redraw() after set_from_file(), but it didn't help.

 This is what I have there now:
   def apply_equations(self, widget, data):
 x_equation = data[0].get_text()
 y_equation = data[1].get_text()
 image = data[2]
 print Equations: x=%s, y=%s % (x_equation, y_equation)
 expression = x_equation + , + y_equation
 plotter.set_expression(expression)
 plotter.plot()
 image.set_from_file(test.png)
 image.queue_draw()

 self.equations_apply.connect(clicked, self.apply_equations,
 (self.x_expression, self.y_expression, self.image) )




 On 01/28/2013 10:02 PM, Niklas Koep wrote:

 If you're updating your gtk.Image contents via its set_from_file() method
 you don't need to request an update at all -- it happens automatically.
 Generally speaking, however, gtk.Widget implements a queue_draw() method
 which can be used to invalidate the entire visible area of a widget which
 in turn causes it to be redrawn. For your use this doesn't seem to be
 required though. Hope this helps.



 2013/1/27 Daniil Baturin dan...@baturin.org

 Hi,
 What is the proper way to reload gtk.Image contents?

 I want to make a simple educational gnuplot frontend that would allow
 playing with parametric curve coefficients by using spin buttons,
 expressions with substituted constants will be passed to gnuplot and
 generated png displayed in a gtk.Image. But I'm not sure how to request
 update of displayed image if the image has changed.


 --
 #!/usr/bin/env perl
 @a=split(//, daniil @ baturin  .  org );# Daniil Baturin
 @b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i24){$_.=
 chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print$_\n#

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




 --
 #!/usr/bin/env perl
 @a=split(//, daniil @ baturin  .  org );# Daniil Baturin
 @b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i24){$_.=
 chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print$_\n#


 ___
 pygtk mailing list   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/

Re: [pygtk] Reload gtk.Image contents

2013-01-28 Thread Niklas Koep
Glad to hear it, although I must say manually adding a delay sounds like an
unreliable workaround. Putting a file monitor in place might look like an
overkill solution, but it should work more reliably. Take a look at
gio.FileMonitor. If you add a montior for a directory (or a specific file)
and listen for events indicating metadata changes you should be able to
determine when it's safe to read the image. Just a suggestion. Another
solution I could think of would be to call gnuplot manually, setting its
output to stdout and connecting to the process via pipe. That way you could
get the raw image data and then manually construct a gtk.gdk.Pixbuf from
that which you can in turn feed to a gtk.Image. Again, that's all just
speculation though as I've never tried any of this myself. Best of luck.

Cheers.


2013/1/28 Daniil Baturin dan...@baturin.org

  Niklas, you were right. Thanks a lot!
 I was using a gnuplot module and a quick look at it gave me impression it
 did take care of time issues and its method don't return until gnuplot task
 if finished. In fact it didn't, but sleep() inserted before set_from_file()
 fixed the issue.

 That module is not so perfect in other aspects too, so I guess I should
 either improve it and send patches back to the author or make a less
 general purpose synchronous interface myself. :)


 On 01/29/2013 03:28 AM, Niklas Koep wrote:

 I've tested the what I described earlier today and it works. If there are
 two distinct images on disk, then calling gtk.Image.set_from_file() will
 automatically update the image gtk displays. This leads me to believe that
 it's a timing issue you're facing. The plotter.plot() method wouldn't
 happen to be asynchronous, would it? Because if it is it might just be the
 case that you update the gtk.Image before the entire image generated by
 gnuplot has been written to disk. Obviously, that's just a guess since I
 don't know how your plot() method works internally. But it would explain
 why the first update of your image (sometimes) doesn't take and the image
 on disk actually appears correct if you look at it after a certain time.


 2013/1/28 Daniil Baturin dan...@baturin.org

  I'm using set_from_file(), and it kind of works. The problem is that the
 image is updated only second time event handler that replots and invokes
 set_from_file() is triggered. I double checked replot occurs every time
 event is caught, when I open the image file manually it contains the
 updated plot.

 I added queue_redraw() after set_from_file(), but it didn't help.

 This is what I have there now:
   def apply_equations(self, widget, data):
 x_equation = data[0].get_text()
 y_equation = data[1].get_text()
 image = data[2]
 print Equations: x=%s, y=%s % (x_equation, y_equation)
 expression = x_equation + , + y_equation
 plotter.set_expression(expression)
 plotter.plot()
 image.set_from_file(test.png)
 image.queue_draw()

 self.equations_apply.connect(clicked, self.apply_equations,
 (self.x_expression, self.y_expression, self.image) )




 On 01/28/2013 10:02 PM, Niklas Koep wrote:

 If you're updating your gtk.Image contents via its set_from_file() method
 you don't need to request an update at all -- it happens automatically.
 Generally speaking, however, gtk.Widget implements a queue_draw() method
 which can be used to invalidate the entire visible area of a widget which
 in turn causes it to be redrawn. For your use this doesn't seem to be
 required though. Hope this helps.



 2013/1/27 Daniil Baturin dan...@baturin.org

 Hi,
 What is the proper way to reload gtk.Image contents?

 I want to make a simple educational gnuplot frontend that would allow
 playing with parametric curve coefficients by using spin buttons,
 expressions with substituted constants will be passed to gnuplot and
 generated png displayed in a gtk.Image. But I'm not sure how to request
 update of displayed image if the image has changed.


 --
 #!/usr/bin/env perl
 @a=split(//, daniil @ baturin  .  org );# Daniil Baturin
 @b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i24){$_.=
 chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print$_\n#

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




 --
 #!/usr/bin/env perl
 @a=split(//, daniil @ baturin  .  org );# Daniil Baturin
 @b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i24){$_.=
 chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print$_\n#


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




 --
 #!/usr/bin/env perl
 @a=split(//, daniil @ baturin  .  org );# Daniil Baturin
 @b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i24){$_.=
 chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print$_\n

[pygtk] PyGTK deadlocks... I know, right?

2013-01-12 Thread Niklas Koep
Here's one. I'm using PyGTK 2.24 with gstreamer 0.10.36. Whenever gstreamer
reports an error on my playbin2's message bus I display the error in a
gtk.MessageDialog. This causes the app to deadlock unless I use a context
manager with gtk.gdk.lock. At first I suspected a threading issue, but
according to the gstreamer docs messages on the bus are emitted from the
main thread so I don't see how threading could be an issue. Nevertheless, I
verified this by retrieving the thread ids with libc via ctypes and they're
identical. Here's a minimal example of an app that demonstrates the issue:
http://pastebin.com/b4VTGy9q.

Any ideas of an obvious issue I'm overlooking? I'd greatly appreciate any
input. Cheers!
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/