[pygtk] Mapping stock icon names to files

2011-10-25 Thread Jason Heeris
I'm building an app using PyGTK 2.22.4 and Python 2.6, and bundling it
up using py2exe. One of the big problems I'm facing is size, though.

I can strip out translations, etc and other extraneous files
(extraneous, that is, for my very well constrained deployment
environment!). What I'm looking at now are icons. I use a very small
subset of the GTK stock icons in my app, even considering those used
by the file save/load dialog and message boxes — but there are a tonne
of app-specific and unnecessary icons in the Tango theme (which I'm
using).

I'd like to whitelist the icons to keep in my distribution, but it's
hard to know what GTK stock identifiers map to what files. For
example, there's a "gtk-info" stock identifier listed in Glade. Does
this map to "status/info.[svg, png]"? What about "gtk-save"... there's
no "actions/save.*" but there is a "actions/gtk-save.*".

Also, what are the icons needed by the GTK file chooser? All the
mimetypes? Places?

Any pointers appreciated :)

Cheers,
Jason
___
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] Bundling GTK resources with py2exe

2011-10-25 Thread Jason Heeris
On 26 October 2011 09:07, Joel Rivera  wrote:
> of your software, if that is not what you want, just copy the dist directory
> and create manually the shortcuts if you will.

I read somewhere that it's possible to get Inno (or NSIS?) to extract
the files to a temp dir (instead of installing) and run the program
from there. I might look into that.

— Jason
___
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] Bundling GTK resources with py2exe

2011-10-25 Thread Jason Heeris
On 25 October 2011 23:52, Joel Rivera  wrote:
> but a last step is that you need to package all of
> those files to a single installer, I use `Inno setup` for that matter,
> this is my working setup file 'setup.iss', which I just need to build it
> from `Inno setup`.


Oh, I meant to ask: is this the Inno setup config for something that
runs straight away (ie. a one-shot executable), or does it actually
install the software?

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

[pygtk] Bundling GTK resources with py2exe

2011-10-24 Thread Jason Heeris
I'm using Python 2.6 and PyGTK 2.22.6 from the all-in-one installer on
Windows XP. I'm slowly making progress building a single-file
executable (via py2exe) for my app, and I've gotten to the point where
I need to know more about bundling up the GTK resources.

Specifically, when I run my app as normal (ie. not built into an .exe
file, just as a loose collection of .py files), it uses the
native-looking Windows theme, but when I run the built exe I see the
default GTK theme. I also haven't even considered how my app will fare
on a "clean" PC (ie. one with no existing Python or GTK installation).

I have read the FAQ entry for this[1] but it's quite localised and
probably a bit dated. I know *how* to bundle the resources (the
"data_files" option to "setup()"), so my starting questions are
basically:

1. Ideally, I'd like to be able to programmatically find the GTK
runtime rather than hard-coding paths like "C:\GTK\lib", etc (if that
even is the right path). How do I do this?

2. What are the resources I need to include?

Cheers,
Jason
___
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] Simplifying what's stored in a ListStore (was Re: Inconsistent format for "path" in TreeView callbacks)

2011-05-10 Thread Jason Heeris
On 9 May 2011 19:25, Alessandro Dentella  wrote:
>> Is there a way to tell the CellRenderer to redraw, or recheck?
>
> sure. Emitting a row-changed will trigger a redraw:
>
>   model.emit('row-changed', path, iter)

Presumably I trigger this by calling gtk.TreeModel.row_changed(path,
iter) — but why does it take *both* a path and iter?

— Jason
___
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] Simplifying what's stored in a ListStore (was Re: Inconsistent format for "path" in TreeView callbacks)

2011-05-08 Thread Jason Heeris
On 7 May 2011 15:55, Neil Muller  wrote:
> You can do via TreeViewColumn.set_cell_data_func and calling
> set_property on the cell renderers.

This approach has cleaned up my code somewhat, but there's one snag
I've hit. The object with the properties I'm showing in the table is a
subclass of GObject, and it has a "use" property that is displayed in
a CellRendererToggle in the table. It's easy enough to connect to the
"activate" signal and change the "use" property in the object, but
it's going to other way I'm having problems with, ie. updating what
the table displays when the "use" property changes in the object.

Is there a way to tell the CellRenderer to redraw, or recheck?

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


[pygtk] Simplifying what's stored in a ListStore (was Re: Inconsistent format for "path" in TreeView callbacks)

2011-05-06 Thread Jason Heeris
On 7 May 2011 03:24, Neil Muller  wrote:
> On 6 May 2011 21:07, Jason Heeris  wrote:
> Storing the object in a hidden column is fine, and what I assumed you
> were doing originally.

Hah! Okay then, now that it's morning, I can't believe that didn't
occur to me :P

While we're on the topic though, it strikes me as more sensible to
simply put the objects themselves in a ListStore without manually
extracting the information for the other columns (ie. so the ListStore
just contains one column, which is displayed in different ways). Is
there a way to tell each TreeViewColumn to, say, "look at column zero,
take the x.fit.param_A attribute, format it using "0x%03X and display
it in a CellRendererText" — and then so on for each attribute, each
describing to a different view of the same column?

Cheers,
Jason
___
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] Inconsistent format for "path" in TreeView callbacks

2011-05-06 Thread Jason Heeris
On 7 May 2011 02:50, Neil Muller  wrote:
> What are you storing in the list store if a row reference doesn't
> allow you to easily get back to the object you want?

I have an object that refers to a numpy array of several hundred data
points, and a few fit parameters and flags. I append the fit
parameters to the ListStore, and map the object to the path of the new
row so I can get back the data points, for use upon row activation (or
cell toggle).

While we've been discussing this, I've been poring over the pygtk docs
some more and think I see what I should be doing: I could store the
object itself in the ListStore as well, and simply not add a
TreeViewColumn for it in the TreeView. Then I can access it directly
upon row activation, etc. Does this sound reasonable, or is there a
better way?

— Jason
___
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] Inconsistent format for "path" in TreeView callbacks

2011-05-06 Thread Jason Heeris
On 7 May 2011 02:30, Neil Muller  wrote:
> Are you writing your own TreeModel (using GenericTreeModel) or using
> something like TreeStore?

Using a ListStore.

> I think you really should be using TreeIters rather than paths to
> manage this mapping, since they directly map to rows in the model,
> rather than positions in the treeview which may or may not match rows
> in the model.

I can't map against TreeIters though, since — for example — the
TreeIter returned by "ListStore.append()" is not the same as what
you'd get back by using the path passed in on one of the signals.
Sure, it points to the same row, but since it's not the same object
it's useless as a dict key.

— Jason
___
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] Inconsistent format for "path" in TreeView callbacks

2011-05-06 Thread Jason Heeris
On 6 May 2011 18:53, Neil Muller  wrote:
> a) why do you want to convert between the two? In my experience, when
> I start thinking about equating or manipulating paths, it usually
> means I'm actually trying to test something about the underlying model
> and should be converting to a TreeIter instead.

I have a TreeView with rows that show parameters related to a
particular object. When the user clicks the CellRendererToggle, it
sets a flag in that underlying object; when the row is double-clicked,
another dialog pops up with more detail about the object.

The only way I've thought to do this is to keep a dict mapping paths
in the TreeModel to the objects. If there's a better way, I wouldn't
shoot it down :)

(I'd post code, but I don't have it to hand right now. Hopefully that
description isn't too cryptic.)

Otherwise, the rest of your email covers it.

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


[pygtk] Inconsistent format for "path" in TreeView callbacks

2011-05-06 Thread Jason Heeris
Say I have a TreeView with a CellRendererToggle in one of the columns.
If I double-click on a row, it will emit a 'row-activated' signal,
passing the path as one of the parameters. If I select one of the
CellRendererToggle checkboxes, it will emit a 'toggled' signal, also
passing the path as one of the parameters. However, in the first case
it is passed as a tuple (eg. "(0,)"), but in the second case it is
given as a string (eg. "0").

Is there a canonical way to convert between these two formats? I don't
want to just use a simple line of code that turns out to be wrong at
some point in the future...

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

[pygtk] Putting a link inside a label

2011-04-13 Thread Jason Heeris
I have a label (actually a WrapLabel[1]) containing some warning text.
I'd like for a couple of the words of the text to take on the
appearance of a hyperlink which, when clicked, activate another widget
in the app (a notebook tab). I can't figure out how to do this — I've
looked at the LinkButton widget, but it's not something you can just
insert into the flow of text (is it?).

Is there some other way to do this?

Cheers,
Jason

[1] From http://git.gnome.org/cgit/meld/tree/meld/ui/wraplabel.py
___
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] Recent changes to the PyGTK Reference Manual

2011-04-11 Thread Jason Heeris
On 11 April 2011 23:44, F Wolff  wrote:
> I think you can maybe offer your help at this bug:
> https://bugzilla.gnome.org/show_bug.cgi?id=647047

Hmm, I think they've already said what I said. I'll keep my eye on it.

Having said that, if I wanted to contribute, what would I submit a
patch against?

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


[pygtk] Recent changes to the PyGTK Reference Manual

2011-04-10 Thread Jason Heeris
I'd like to offer some criticism of the new format of the "PyGTK 2.0
Reference Manual" at http://developer.gnome.org/pygtk/stable/

I use this reference all the time, but the recent changes make it
extremely difficult to use — primarily the fact that the table of
contents (which is to me the most important navigational tool for the
reference) is squashed up on the right hand side. The fact that it is
next to acres of empty space (below the list of examples) that it
could otherwise fill is also a little odd.

I notice that it's only on the front page that the TOC is even
visible, making it seem even more perverse that it's so hard to use :)

Would it be possible to move it back into the centre of the page, and
maybe add more differentiation between the node titles and their
description — possibly making it not a wall of traffic-cone orange
text? I'd suggest: keep the orange for the node titles, but render the
descriptions in the grey used for body text.

If someone tells me what to submit changes against, I'd be happy to
look into it myself.

Cheers,
Jason
___
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] SVG support in PyGTK on Windows

2011-03-09 Thread Jason Heeris
On 9 March 2011 16:17, Dieter Verfaillie  wrote:
> Other than updating GTK+ to 2.20.1 you could also try the PyGTK All-in-one
> installer: http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/.
> See https://github.com/dieterv/pygtk-installer#readme for more info.

This fixed everything! Kudos to whoever produced that, since it's now
made deployment about ten times easier. (Bringing it down to a total
of... three graphical installers and four console installations.)

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


[pygtk] SVG support in PyGTK on Windows

2011-03-08 Thread Jason Heeris
I've read through a previous thread on this list about SVG support
under Windows[1], but it hasn't shed any light on my problem.

Under Windows (XP), when I try to load SVG graphics in my PyGTK
(+Twisted) app, eg. using self.root.set_icon_from_file(logo_path), I
get:

Traceback (most recent call last):
Failure: glib.GError: Couldn't recognize the image file format
for file 'C:\path\to\logo.svg'

I have GTK+-2.20.0 installed in C:\GTK, and I have unzipped the
following packages[2] into C:\GTK:

  * svg-gdk-pixbuf-loader_2.32.1-1_win32.zip
  * svg-gtk-engine_2.32.1-1_win32.zip
  * librsvg_2.32.1-1_win32.zip
  * libcroco_0.6.2-1_win32.zip
  * libgsf_1.14.17-1_win32.zip

C:\GTK\etc\gtk-2.0\gdk-pixbuf.loaders only contains comments.

Running "gdk-pixbuf-query-loaders.exe svg_loader" gives:

C:\GTK\bin>gdk-pixbuf-query-loaders.exe svg_loader
# GdkPixbuf Image Loader Modules file
# Automatically generated file, do not edit
# Created by gdk-pixbuf-query-loaders.exe from gtk+-2.20.0
#
g_module_open() failed for C:\GTK\bin\svg_loader:
`C:\GTK\bin\svg_loader.dll': The specified module could not be found.


There is, in fact, no "C:\GTK\bin\svg_loader.dll". Should I have one?
If so, where do I get it? Otherwise, what can I do to fix this?

[1] http://www.daa.com.au/pipermail/pygtk/2010-April/018519.html
[2] ...from http://ftp.gnome.org/pub/GNOME/binaries/win32/

Cheers,
Jason
___
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] Cannot shrink width of scrolled textview

2011-03-02 Thread Jason Heeris
On 3 March 2011 14:46, burebista  wrote:

> Set "sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)" the
> automatic policy for both scrollbars.
>
>
But I don't want a horizontal scrollbar...

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

[pygtk] Cannot shrink width of scrolled textview

2011-03-02 Thread Jason Heeris
In the attached code, a word-wrapping TextView is placed inside a
ScrolledWindow which has a vertical scrollbar policy of "automatic".
The problem is that if the width of the window is increased to a point
where the scrollbar disappears, it cannot be shrunk again.

The problem goes away if the vertical scrollbar policy is set to
"always" ... but is this how it's meant to work? Or am I not
configuring it right?

This is under PyGTK 2.17, Debian Squeeze.

Cheers,
Jason
import gtk
import pygtk

# SAMPLE TEXT
TEXT = (
"A gtk.TextView widget provides the display for the contents of a "
"gtk.TextBuffer object. A textview provides a set of attributes for the default"
" display of text from a textbuffer. The attributes set by gtk.TextTag objects "
"override the attributes set on a gtk.TextView widget. Since a gtk.TextBuffer "
"can be associated with multiple gtk.TextView widgets each having a different "
"set of default attributes, the display of the same text in different textview "
"widgets can be quite different except for those attributes that are overridden"
" by texttags.")

def destroy(widget, data=None):
gtk.main_quit()

if __name__ == "__main__":
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)

tb = gtk.TextBuffer()
tb.set_text(TEXT)

tv = gtk.TextView(tb)
tv.set_property('wrap-mode', gtk.WRAP_WORD)

sw.add(tv)
window = gtk.Window()
window.add(sw)

window.connect('destroy', destroy)
window.show_all()
gtk.main()

___
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] Label & Word Wrapping

2011-02-22 Thread Jason Heeris
On 22 February 2011 20:30, Adam Tauno Williams  wrote:
> available space - just wrap incorrectly.  Any hints for displaying
> multi-lined / long-lined text in a label more elegantly?

I think I've had the same problem. You may be interested in this:

http://stackoverflow.com/questions/1893748/pygtk-dynamic-label-wrapping/1911179#1911179

...which I've used with good results.

— Jason
___
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] GIO async operations

2011-02-22 Thread Jason Heeris
On 22 February 2011 19:53, Christian Becke  wrote:
> Sorry, misread your message. The object is actually both: passed as an
> argument to the callback, and accessible through the gio.AsyncResult by
> calling its get_source_object method, see code below:

Right, I did wonder about the redundancy, but that's not unusual for C bindings.

If I have time I could fix up the docs — how do I submit changes?

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

[pygtk] GIO async operations

2011-02-21 Thread Jason Heeris
I'm confused about some of the GIO async functions. In my case, I want
to use gio.File.replace_contents_async(). But what's the signature of
the callback it takes? I would assume that the callback receives the
original File object, but looking at the docs for gio.AsyncResult, it
might also need to take other arguments:

"This callback will be triggered when the operation has completed, and
will be passed a GAsyncResult instance filled with the details of the
operation's success or failure, the object the asynchronous function
was started for and any error codes returned."

This sentence is a bit grammatically imprecise :P I'm not sure whether
the "object the asynchronous function was started for" is part of (a)
what is passed to the callback, or (b) the contents of the
GAsyncResult.

In either case, how do I use it? Presumably the return value from
replace_contents_finish() is the same as from replace_contents() (an
etag). But do I need to pass the GAsyncResult to
replace_contents_finish(), so that it's populated with any error
codes? Or are the error codes passed into the callback?

Any clarifying comments welcome :)

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

[pygtk] Tweaking GTK InfoBar properties

2011-02-08 Thread Jason Heeris
I have a GTK InfoBar that I'd like to show a fixed width message in,
but I can't figure out how to get at the contained text display widget
("get_content_area()" just gives me an HBox, and I'm not crazy about
hard-coding indices of undocumented components into my app).

Is there are robust way to do this?

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

[pygtk] Point of __gproperties__ "default" argument?

2010-09-22 Thread Jason Heeris
Consider the class given in the "Sub-classing GObject" tutorial[1].
What is the point of the default value for 'fuel' on line 12? Given
that any access needs to go through the `do_get_property()` method
anyway, which will need to work out what to return from the state of
the object, I don't see how it could ever get used.

[1] http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm#d0e127

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

[pygtk] List admin - info on mpsupport emails

2010-09-07 Thread Jason Heeris
Hi,

Sorry for the noise, but could a PyGTK list admin please get in touch
with me privately regarding the mpsupport.com bounces?

Cheers,
Jason
___
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] A recursive directory monitor

2010-09-01 Thread Jason Heeris
On 1 September 2010 18:39, Jason Heeris  wrote:

> The latter approach isn't actually a bad idea, although it involves the
> extra typical GObject boilerplate...
>

Actually, the other problem with that approach is that I don't get to use
the underlying properties and notifications for free. I'd need to reproduce
the properties in my own GObject subclass, connect to the notifications in
my wrapper class and emit any changes back out. Since I don't really need
any of that right now, it's not a big deal though.

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

[pygtk] A recursive directory monitor

2010-09-01 Thread Jason Heeris
I'm attempting to implement a recursive directory monitor. My approach is
basically to take the gio.FileMonitor returned by the method
gio.File.monitor_directory(), connect to the "changed" signal, and add or
remove monitors on create/delete events for subdirectories.

The problem I'm having is in creating it in the first place. Ideally I'd
like to just extend the gio.FileMonitor class, but since it's never
explicitly initialised in user code (but somewhere in
gio.File.monitor_directory() ) there's no point in just declaring a subclass
— where would I actually create an instance? The other option is to define a
new GObject with the same "changed" signal. This keeps the directory monitor
as a member variable, connects to its "changed" signal and does all the
recursive logic.

The latter approach isn't actually a bad idea, although it involves the
extra typical GObject boilerplate... But besides that, I was curious as to
whether there's a way to "slot in" my subclass so that it gets used instead
of the gio.FileMonitor.

Finally, does anyone know if the event gio.FILE_MONITOR_EVENT_MOVED is ever
actually used? All of the testing I've done shows a move or rename as a a
pair of gio.FILE_MONITOR_EVENT_DELETED/gio.FILE_MONITOR_EVENT_CREATED
events.

Cheers,
Jason
___
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] FileChooserButton forgets changed file

2010-07-12 Thread Jason Heeris
On 12 July 2010 16:39, Pietro Battiston  wrote:
> I can reproduce this (Debian, 2.17.0 too)...
>
> And I can't see any explanation but "it's a bug".

Great, just wanted to check I wasn't doing something wrong. Filed a bug:

https://bugzilla.gnome.org/show_bug.cgi?id=624136

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

[pygtk] FileChooserButton forgets changed file

2010-07-11 Thread Jason Heeris
> I couldn't reproduce what you're seeing unless I'm doing something wrong, 
> which is likely.

Basically, run the script, select a file, click "Check". Keep the app
open, but change the contents of the selected file and save it. Keep
clicking "check" and the file name has changed to another one in the
directory. (But if there's no other file in the directory with your
first file, it doesn't change!)

I see this on Debian (pygtk 2.17.0) and Windows (git, window branch).

> self.fcb.get_file().get_path() instead of self.fcb.get_filename()

No difference :/

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


[pygtk] FileChooserButton forgets changed file

2010-07-08 Thread Jason Heeris
Consider the attached program. Try this:

1. Select a file that is in a directory *with at least one other file*
2. Click "Check" to verify the path
3. Open the file in a text editor, modify it and save it
4. Click "Check" again

When I try this, the path has changed! Have I done something wrong, or
is this a bug?

— Jason


import pygtk
import gtk

class FCButtonTest(gtk.Window):

def __init__(self):
super(FCButtonTest, self).__init__()
self.fcb = gtk.FileChooserButton("Go nuts")
button1 = gtk.Button("Check")

button1.connect('clicked', self.do_check)

box1 = gtk.HBox()
box1.pack_start(self.fcb)
box1.pack_start(button1, expand=False)

self.add(box1)

def do_quit(source):
gtk.main_quit()

self.connect('destroy', do_quit)

def do_check(self, source):
print self.fcb.get_file().get_path()

if __name__ == "__main__":
FCButtonTest().show_all()
gtk.main()

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

[pygtk] What is "gobject.TYPE_BOXED"?

2010-07-07 Thread Jason Heeris
Looking through the PyGTK gobject type constants[1], I noticed the
gobject.TYPE_BOXED constant. What is it, exactly? Does it have a use
in Python not already filled by simply using PYOBJECT?

— Jason

[1] 
http://library.gnome.org/devel/pygobject/stable/gobject-constants.html#gobject-type-constants
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

[pygtk] idle_add vs. threads_enter/threads_leave

2010-07-06 Thread Jason Heeris
Tim Evans wrote:
> GTK+ 2.14.4
> PyGObject 2.14.2
> PyGTK 2.12.1

Mine is

GTK+ 2.20
PyGObject 2.21.2
PyGTK 2.17.1

A few things about your changes confused me -

1. You call glib.idle_add, but never called glib.threads_init - won't
this break on Linux?
2. You use BOTH gtk.gdk.lock and glib.idle_add - but surely one of
these is superfluous, since glib.idle_add executes the function in the
main loop, where the lock is already acquired?

Anyway, I came up with a different, simpler way, but I don't know
enough to say if it will never fail. I can't push to github from here,
but basically it's the same as my first example[1] but with this main
block for controller.py:


if __name__ == "__main__":

import glib
import gtk.gdk
gtk.gdk.threads_init()
glib.threads_init()

view = MyView()
model = MyModel()
controller = MyController(model, view)

with gtk.gdk.lock:
LaunchUI(view)


Works on both win32 and linux, using glib.idle_add throughout. I was a
bit worried that trying to acquire the gtk.gdk.lock from the main
thread would cause problems under linux as per [2], but it works fine.

Lessons learnt:

1. Call gtk.gdk.threads_init() BEFORE glib.threads_init() (otherwise
glib.idle_add won't work)
2. Call them both before you do anything else
3. Start the main loop in the gtk.gdk.lock context manager or
surrounded by gtk.gdk.threads_enter/leave()

Thanks for everyone's patience - I rarely have to develop under win32,
so I'm not really aware of these gotchas.

- Jason

[1] http://github.com/detly/gtk-async-test
[2] http://faq.pygtk.org/index.py?req=show&file=faq20.015.htp
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


[pygtk] idle_add vs. threads_enter/threads_leave

2010-07-06 Thread Jason Heeris
Antoine Martin wrote:

> It means that most of your code is not using threads at all, only the
> bits that are *slow*

Those are the only bits that use threads anyway.

> I've lost track of your particular issue though, so maybe this is not
> suitable for your use-case? How much slow work do you do compared to the
> rest? (how many code paths, rather than raw amount)

I have two kinds of long-blocking work: reading a large file and 
processing it to get a single result, and communication over a serial 
port (send command, await response, times about a hundred).

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

[pygtk] idle_add vs. threads_enter/threads_leave

2010-07-06 Thread Jason Heeris
Antoine Martin wrote:
> I don't know of any examples unfortunately and I must admit that I spent
> quite a bit of time getting to grips with it, but in the end it is
> remarkably simple (much more simple than I first thought too - so don't
> let that put you off):
> import gtk.gdk
> gtk.gdk.threads_init()

This is not a good idea under Windows, sometimes it'll freeze here,
other times... later.

> if you need to interact with the GUI from that thread, do it via 
> gobject.idle_add()

See, at this point I don't understand why Twisted gives me an
advantage. I'm still using threads, I'm still using the problematic
"idle_add"... what's different?

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


[pygtk] idle_add vs. threads_enter/threads_leave

2010-07-06 Thread Jason Heeris
Tim Evans wrote:
> Something worth noting is that if you're targeting Windows then 2.a. is
> your *only* option.

In fact, gtk.gdk.threads_init() will freeze straight off, you don't
need to wait for threads to start.

> I would also point out that "whenever it next feels like it" is almost
> always going to be the same as "right away" unless you're doing
> something yourself that still blocks the main thread.

Unfortunately, see my other email for my problems with
"glib.idle_add()" - basically, it doesn't work on Windows either.

There's a quick demo prog at:

http://github.com/detly/gtk-async-test

If you have access to a win32 box, run controller.py to see the
problem (or, in fact, fail to see it - you should click the start
button and see the progress bar go, if you don't, that's the problem).
It works fine under Debian.

So, in short, PyGTK + Windows + async = no :/

Cheers,
Jason
___
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] idle_add vs. threads_enter/threads_leave

2010-07-05 Thread Jason Heeris
On 5 July 2010 17:53, Pietro Battiston  wrote:
> Il giorno lun, 05/07/2010 alle 16.32 +0800, Jason Heeris ha scritto:
>>   3. I don't need to do the threads_enter/leave (or use the context
>> manager) if I only use glib.idle_add (or timeout_add, etc)
>
> No, you don't. If you don't really need threads, life is much simpler.

Aaaah, I've just discovered that using only glib.idle_add on Windows
does *not* mean that things get updated at the next available
oppurtunity. They only get updated when the widget gets redrawn (I
think... or maybe when the user interacts with the UI). Maybe this is
a known issue.

— Jason
___
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] idle_add vs. threads_enter/threads_leave

2010-07-05 Thread Jason Heeris
On 5 July 2010 21:48, A.T.Hofkamp  wrote:
> I was mostly triggered by the fact that you are doing asynchronous
> activities next to the GTK application, which are apparently complicated
> enough to use threads for.

It's not complicated, there's simply a time consuming operation involved.

> About not mentioning guis:
> If you write a spread sheet program, and explain its features, you don't
> explain that you can add two numbers, do you?

Yes, but if it can do arbitrary precision arithmetic, you might
mention that feature, even though it's *obviously* a *trivial*
extension of the ability to do batch computation :P

It's somewhat counter-intuitive to have a module named
"twisted.internet" that can be used for things that have nothing to do
with the internet. It makes a potential programmer think, "I don't
really want a full blown internet stack just for a quick and simple
desktop app." Just like I don't open up a spreadsheet just to add two
numbers, even though it's technically capable of that.

But fine, it's just a name, I can ignore it.

> I completely agree with you that this is a weak point.
> I found the best source of information to be their howtos and
> tutorials/examples, to get the global picture, and the API documentation
> (for the protocols, mostly).

I'll poke around, thanks.

> Basically, asynchronous communication means you are doing event-based
> programming everywhere.

I like that idea. I understand the principle. It's mainly how I use
GTK, where possible.

> From this point of view, it is totally irrelevant what event you get (a
> network comm event, a GUI event, or something from another source), only the
> actual handler of the event needs to know details of the event.

Yes, but the *details* are what I need to know. How do I write a "file
processor" model: something that takes a filename, returns a initial
status immediately, and then X minutes later returns the result of
processing the file? In fact, ignore that, how do I write a class that
does "time.sleep(100)" and then sends a signal saying that it's done?

> http://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html#auto11
>
> That page also refers to an example "doc/core/examples/pbgtk2.py"

...which still seems to involve some sort of network communication,
which is extra noise that just gets in the way of understanding the
GTK interaction.

> In the same way, Twisted does not care about the comm protocol use to
> deliver the event. Whether a user pressed a button at a web-form, or sent a
> IRC message does not matter for computing the response.

If Twisted doesn't care about the protocol, why can't I find a single
example that does not involve a network-based protocol?

> I am not sure why there is so little nice introductory information. I think
> it is because the gap between both worlds is so big. Either you don't get
> it, and then you cannot write about it due to lack of understanding, or you
> do get it, and then you cannot imagine how to explain it to somebody that
> doesn't.

It's not about "getting" event based programming. Take this very
email, for example. You go on at length about the architectural
principles of Twisted. But in a tenth of the space I could have
written an illustrative example of using GTK+ with Python threads to
do asynchronous activity (now). Why can't anyone just do that with
Twisted instead of writing essays?

What letters do I type to get anything done? Nothing I have read so
far has given me any hint about this.

> (Like programming, can you explain the essence of what programming is, to
> somebody that has no clue about computers?)

You could actually show them a computer, and show them the things it
can do, and then show them how to do the things they want to do with
it. That's how I would start.

Thanks for the pointers though. If I ever find the time, I'll try it out.

— Jason
___
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] idle_add vs. threads_enter/threads_leave

2010-07-05 Thread Jason Heeris
On 5 July 2010 18:05, Neil Benn  wrote:
> I persevered however and threads work fine in Python - OK the GIL can make
> things a little more complicated but threading in Python is not much harder
> to use then in Java or C# (in fact because of the GIL and single processor I
> don't have to worry about volatile variables).

Incidentally, typically I'll use Python's multiprocessing module, or
the Python-DBUS bindings (particulary the asynchronous features of
DBUS) if there's some really intensive work to be done. So it might be
worth a look for you too. Keep in mind, though, DBUS is emphatically
NOT optimised for throughput - it's not a good idea for pushing around
a lot of data (instead of, say, reading a lot of data and passing back
a summary). This is (presumably) where Twisted shines, because of its
origins as a networking framework.

- Jason
___
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] idle_add vs. threads_enter/threads_leave

2010-07-05 Thread Jason Heeris
On 5 July 2010 17:36, A.T.Hofkamp  wrote:
> Or you could drop threads entirely, and do your async activities using the
> Twisted framework, designed for making asynchronous programs (where GTK
> event handling is just one of the asynchronous sources).

Please don't take this as a flame, but I've had this advice before
(usually on #python), and I usually go through this process:

1. Look at Twisted website
2. Only read things about twisted being a networking framework
3. Someone corrects me, saying "Twisted is so much more!" (That may be
the case, but the fact that the website goes on and on without
mentioning this does not inspire confidence.)
4. I search the Twisted website for documentation on/examples of GTK
applications
5. I give up and search the Twisted website for documentation
on/examples of *any* non-network based applications
6. I give up and search the greater web for documentation on/examples
of Twisted GTK applications
7. I give up on Twisted and find another way.

Really, I would love to get a grip on Twisted. It seems really useful.
But I've still not found any kind of stepping stone into it. Please,
please, please if you know of one, post it so I can add another tool
to my belt. I will rescind everything I've said here and then some.

(Since the Twisted website is currently down, I can't tell if things
have changed and I should get over it and have another try.)

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


[pygtk] idle_add vs. threads_enter/threads_leave

2010-07-05 Thread Jason Heeris
Hi,

I've been reading some conflicting advice on PyGTK and threading
recently, probably because the API went through some fairly rapid
changes recently.

I'm a bit confused about the following points (consider them in
context of PyGTK/PyGObject unstable, ie. 2.17/2.21 respectively):

  1. If I want to do async activity in a new Python thread spawned
from the main loop, I need to have called glib.threads_init() *before*
starting the main loop, right? But what about gtk.gdk.threads_init()?
  2. Any GTK interaction, such as emitting a signal from this new
thread, must be either:
  a. done via glib.idle_add (if I'm happy to let GTK do it
whenever it next feels like it), -OR-
  b. wrapped in gtk.gdk.threads_enter()/...leave(), -OR-
  c. in a "with: gtk.gdk.lock:" block (equivalent to 2.b)
  3. I don't need to do the threads_enter/leave (or use the context
manager) if I only use glib.idle_add (or timeout_add, etc)

Cheers,
Jason
___
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] PyGTK 2.17 for Windows

2010-07-02 Thread Jason Heeris
On 2 July 2010 13:11, John Stowers  wrote:
> This looks like you are building from the master branch. Please build
> from the windows branch. I should update the instructions to make that
> clear.

Yes! It works! For the benefit of anyone else reading this (or maybe
for your updated instructions)...

Building the PyGTK Installer From Git
1. Follow the instructions to install msys, mingw and msysgit
2. Use msysgit to retrieve the current state of the windows branch
(to, for example, "C:\pygtk", which is "/c/pygtk" in msys and
msysgit):

$ git clone -b windows --depth 1 git://git.gnome.org/pygtk /c/pygtk

(The "--depth" flag just saves pulling the whole repo if you just want
a quick build.)

4. In msys, change to "/c/pygtk" and build as per current instructions
5. Installer can be found under "C:\pygtk\dist" (literally the
directory "dist", not the platform name)

Thanks everyone (for allowing me to dodge wxWidgets ;) ).

Cheers,
Jason
___
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] PyGTK 2.17 for Windows

2010-07-01 Thread Jason Heeris
On 2 July 2010 10:54, Jason Heeris  wrote:
> AFAIK, this is part of pygtk... so do I need PyGTK already installed
> to build a new PyGTK? Or have a missed something?

No, apparently a reboot was required after uninstalling PyGTK (certain
files were scheduled for removal that could not be immediately
removed). Now I can import all of the other modules fine...


$ python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gobject
>>> import glib
>>> import pango
>>> import cairo
>>> import atk
>>> ^Z


Now I get:

$ python setup.py build --compiler=mingw32 --enable-threading --yes-i-know-its-
not-supported bdist_wininst
c:\Python26\lib\site-packages\gtk-2.0\dsextras.py:354: DeprecationWarning: objec
t.__new__() takes no parameters
  return object.__new__(cls,*args, **kwds)
* numpy module could not be found, will build without numpy support.
* libglade-2.0.pc could not be found, bindings for gtk.glade will not be built.
running build
running build_py
running build_ext
using MinGW GCC version 3.4.5 with -mms-bitfields option
building 'atk' extension
writing build\temp.win32-2.6\Release\atk.def
C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.6\Release\atkmodu
le.o build\temp.win32-2.6\Release\atk.o build\temp.win32-2.6\Release\atk.def -Lc
:/GTK/lib -Lc:/GTK/lib -Lc:\Python26\libs -Lc:\Python26\PCbuild -latk-1.0 -lgobj
ect-2.0 -lgthread-2.0 -lglib-2.0 -lintl -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -
lintl -lgthread-2.0 -lglib-2.0 -lintl -lpython26 -lmsvcr90 -o build\lib.win32-2.
6\atk.pyd
build\temp.win32-2.6\Release\atk.o:atk.c:(.text+0xfa6f): undefined reference to
`atk_hyperlink_impl_get_type'
build\temp.win32-2.6\Release\atk.o:atk.c:(.text+0xfa89): undefined reference to
`atk_hyperlink_impl_get_hyperlink'
build\temp.win32-2.6\Release\atk.o:atk.c:(.text+0xfadd): undefined reference to
`atk_hyperlink_impl_get_type'
build\temp.win32-2.6\Release\atk.o:atk.c:(.text+0xfb2d): undefined reference to
`atk_hyperlink_impl_get_type'
build\temp.win32-2.6\Release\atk.o:atk.c:(.text+0x13643): undefined reference to
 `atk_streamable_content_get_uri'
build\temp.win32-2.6\Release\atk.o:atk.c:(.text+0x21421): undefined reference to
 `atk_hyperlink_impl_get_type'
build\temp.win32-2.6\Release\atk.o:atk.c:(.text+0x21445): undefined reference to
 `atk_hyperlink_impl_get_type'
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

Presumably ATK is the wrong version. But since I can't get PyGObject
2.21 to build (neither flag that Tomeu Vizoso mentioned is actually
recognised by setup.py), can I just disable or ignore ATK?

- Jason
___
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] PyGTK 2.17 for Windows

2010-07-01 Thread Jason Heeris
So I decided to start this whole thing over, since I went down the
wrong path before. I uninstalled pygtk, but kept pycairo 1.8.6 and
pygobject 2.20.0. Then I brought up a mingw console and followed the
win32 build instructions[1].

I get this error:

$ python setup.py build --compiler=mingw32 --enable-threading
--yes-i-know-its-not-supported bdist_wininst
Traceback (most recent call last):
  File "setup.py", line 22, in 
from dsextras import get_m4_define, getoutput, have_pkgconfig, \
ImportError: No module named dsextras

AFAIK, this is part of pygtk... so do I need PyGTK already installed
to build a new PyGTK? Or have a missed something?

- Jason

[1] http://git.gnome.org/browse/pygtk/tree/README.win32
___
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] PyGTK 2.17 for Windows

2010-07-01 Thread Jason Heeris
On 1 July 2010 21:13, John Stowers  wrote:
> I have been generating the python installers for windows.

Good work :)

> This, and the fact that PyGtk has effectively been deprecated an
> replaced with PyGI makes me nervous.

...I was not aware of that. I'll have to look into PyGI.

> I will try to get to this over the next week but no promises.

There's no rush. I was simply looking for a way to get the program
deployed — just the ability to get it installed is all I need.

> Yip. I build the windows installers on windows. It looks like you are
> building on linux. If you want me to remove this restriction then
> convince me that it works - I am not interested in supporting
> configurations I cannot test.

No, don't do this on my account. It was just a long shot at getting it working.

Cheers,
Jason
___
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] PyGTK 2.17 for Windows

2010-07-01 Thread Jason Heeris
On 1 July 2010 17:45, Tomeu Vizoso  wrote:
> Two options, not sure which would be easiest:
>
> - build pygobject <2.21.4 with --disable-pygi
> - build pygobject 2.21.4 with --disable-introspection

> (I'm assuming that you have a reason for not using a stable release of
> PyGObject).

What's the minimum version of PyGObject I can use with PyGTK 2.17?

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

[pygtk] PyGTK 2.17 for Windows

2010-06-30 Thread Jason Heeris
I'm trying to get a PyGTK app going on a Windows XP installation. It
requires PyGTK 2.17. I have Python 2.6 and GTK 2.18 set up just fine,
but of course there's no binary installer for PyGTK 2.17. So I grabbed
the source from FTP[1], along with PyGObject, intending to build it
under MinGW.

But it turns out I need PyGI to build PyGObject, and PyGI requires
"Python development tools" to build, and searching the web for that
problem yields nothing useful.

So before I embark on some odyssey of pain trying to get this all to
work, my question is: is there an easier way? A binary installer for
PyGI for Windows? A binary installer for PyGTK 2.17?

Please keep me CCd on replies.

Cheers,
Jason Heeris

PS. By the way, I usually work on a Debian Squeeze/Sid system, with
PyGTK 2.17.0 (installed from Debian repo). I thought maybe I could
take the 2.17 tarball and build it somewhere in my home dir, but:

~/Projects/python-virt2/pygobject-2.21.4$ ../bin/python setup.py build
--compiler=mingw32 --enable-threading --yes-i-know-its-not-supported
bdist_wininst
Error: distutils build only supported on windows

Nuts.

[1] http://ftp.gnome.org/pub/GNOME/sources/pygtk/2.17/
___
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] gtk InfoBar documentation?

2010-06-28 Thread Jason Heeris
On 28 June 2010 15:27, Vermeersch Simon  wrote:
> You can try to use the GTK documentation at
> http://library.gnome.org/devel/gtk/stable/GtkInfoBar.html

Yeah, that's what I'm going on at the moment. Mainly it's the signals
and properties that are important, so that's good enough.

> It should look fairly similar to the python one, and you can always
> use the built-in dir-function to see all methods.

"dir" works, but I can't use the inspect module on it to see function
args (and default values), since it's native code. But it's not that
hard :)

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

[pygtk] gtk InfoBar documentation?

2010-06-27 Thread Jason Heeris
Is there any PyGTK documentation for the gtk.InfoBar widget? By the
looks of it, it's a GTK 2.18 thing, and the PyGTK docs only go up to
2.17, so presumably that's why it's not there. At the moment I'm
poring over the defs file, but is it available somewhere other than
the usual place?

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

[pygtk] GIO: Monitor directory for changes recursively

2010-06-15 Thread Jason Heeris
Take the following demo code[1], which uses a GIO FileMonitor to
monitor a directory for changes:

   import gio

   def directory_changed(monitor, file1, file2, evt_type):
   print "Changed:", file1, file2, evt_type

   gfile = gio.File(".")
   monitor = gfile.monitor_directory(gio.FILE_MONITOR_NONE, None)
   monitor.connect("changed", directory_changed)

   import glib
   ml = glib.MainLoop()
   ml.run()

After running this code, I can then create and modify child nodes and
be notified of the changes. However, this only works for immediate
children (I am aware that the docs don't say otherwise). The last of
the following shell commands will not result in a notification:

   touch one
   mkdir two
   touch two/three

Is there an easy way to make it recursive? I'd rather not manually
code something that looks for directory creation and adds a monitor,
removing them on deletion, etc (of course, if that's the only way,
then I've answered my own Q).

The intended use is for a VCS file browser extension, to be able to
cache the statuses of files in a working copy and update them
individually on changes. So there might by anywhere from tens to
thousands (or more) directories to monitor. I'd like to just find the
root of the working copy and add the file monitor there.

(By the way: the reason I'm avoiding pyinotify[1] is so that this
works under non-Linux kernels such as FreeBSD or... others. As far as
I'm aware, the GIO FileMonitor uses inotify underneath where
available, and I can understand not emphasising the implementation to
maintain some degree of abstraction, but it suggested to me that it
should be possible.)

— Jason

[1]  from StackOverflow, the GIO answer to "detect new or modified
files with python"
(http://stackoverflow.com/questions/1618853/detect-new-or-modified-files-with-python)
[2] http://trac.dbzteam.org/pyinotify

(If this hits the list twice, it's because it wasn't possible to
cancel my last attempt.)
___
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] Threading in nautilus-python extensions

2009-07-16 Thread Jason Heeris
Just to follow up on this a bit, it really seems to be something to do
with the nautilus-python extension specifically. One of the other
NautilusSVN developers found that an extension written in C does not
have the same problem at all:


I've created a simple nautilus extension written in C that creates a
thread and sleeps in it, and it doesn't block nautilus at all.  I've
got the code up at github at
git://github.com/adamplumb/nautilus-test-extension.git.  Just do a git
clone to get it.  Then compile/install with sh autogen.sh ; make ;
make install.  (FYI It will install files to
/usr/lib/nautilus/extensions-2.0).


But is there a way to work around this without using C? I'm poring
over the nautilus-python and pygtk source, but I'm not really seeing
anything enlightening.

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


[pygtk] Threading in nautilus-python extensions

2009-07-04 Thread Jason Heeris
Hi,

I'm working on NautilusSVN, a Python-based extension to integrate
Subversion into Nautilus. I've run into some confusing issues regarding
threading and I was hoping for some advice.

Basically, what I've found is that threads spawned by the Python
extension do not run unless the user specifically interacts with
Nautilus (eg. refreshes, selects files, opens context menu).

I've attached some code - it's the smallest possible example (I think)
that illustrates the problem. Drop it in ~/.nautilus/python-extensions
and use "nautilus -q && nautilus --no-desktop" to kill and restart
nautilus and log to the console.

What I would expect is that the test extension logs once every 1/100th
of a second. What actually happens is that it only logs when I interact
with Nautilus.

So what exactly is happening here? Is it expected?

I would appreciate any advice on this.

Just some background: one of the previous maintainers for this project
had the same problems[1], but I couldn't find any resolution. I asked a
few days ago on the Nautilus Dev list[2], and I was directed here.

Cheers,
Jason Heeris

[1] http://mail.gnome.org/archives/nautilus-list/2006-December/msg00053.html

[2] http://mail.gnome.org/archives/nautilus-list/2009-July/msg0.html

PS. I think a 48 hour moderation queue might just be a little on the
extreme side... :)

'''
AsyncTest.py

Created on 27/06/2009

This is an attempt to create the simplest possible test for threading in a
Python extension for Nautilus.

@author: Jason Heeris
'''

import nautilus
import gobject

import threading
import time

import logging

class AsyncTest(nautilus.MenuProvider):
''' Simple test class for multithreaded Python Nautilus extension.
'''

def __init__(self):
logging.getLogger().setLevel(logging.DEBUG)

def get_background_items(self, window, files):
'''
Gets the context menu entry.
'''
menu_item = nautilus.MenuItem(
'AsyncTest',
'Test Async. Behaviour',
'Tests multithreading in python-nautilus extensions'
)

menu_item.connect('activate', self.test_asynchronicity)

return [menu_item]

def test_asynchronicity(self, *args, **kwargs):
'''
This is a function to test doing things asynchronously.
'''
  
def asynchronous_function():

logging.getLogger().setLevel(logging.DEBUG)

logging.debug('\n%s Inside asynchronous_function()' % time.time()) 

for i in range(1, 21):
time.sleep(0.01)
logging.debug('%s %0i Asynchronous thread still running...' % (time.time(), i))
logging.debug('Current thread: %s' % threading.currentThread())
logging.debug('Is demon: %s' % threading.currentThread().isDaemon())

logging.debug("%s asynchronous_function() finished\n" % time.time())

# Calling threads_init does not seem to do anything.
logging.debug('Current thread: %s' % threading.currentThread())
gobject.threads_init()
threading.Thread(target=asynchronous_function, name='Async Test').start()



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