Reputation: 6676
I am pretty new to programming and one of first things I tried is writing my own file manager (for learning purposes). I use python2.7 and GTK+ 3 library.
While writing my file manager I faced problem: how to react to changes in current folder's files? For example I have home folder opened in my file manager. Then another program creates new file there. File manager should refresh list of files and show actual result. How can I implement it?
Code of my file manager is available on github.
Upvotes: 0
Views: 857
Reputation: 11454
GIO is what you should use here. It's provided by the GLib, on which GTK is based. DON'T use polling to do this. Polling is often slow, resources-consuming (CPU, power - as it prevents the CPU from going in deep sleep modes) and has no benefit against an asynchronous API that will just notify you when the content has changed. See also PyGTK/GIO: monitor directory for changes recursively.
You import it that way:
from gi.repository import Gio
By the way, I'm removing the PyGTK tag of the question, as PyGTK (which should be used for GTK 2) has been obsoleted in favor of PyGObject (which should be used for GTK3).
EDIT:
Here's a link to the python + GTK3 tutorial.
Upvotes: 3
Reputation: 16212
Just check the contents of the directory every few seconds. I'm assuming that you are using os.listdir to get the contents in the first place? Just do that some more.
Alternatively, if efficiency is an issue read on:
look at this for an example, or this for a whole lot more.
Seen this?
These links were gleaned from simple Google and Stackoverflow searches. If they are not informative enough for you please update your question with your requirements
Upvotes: -1