Monitoring updating directory for image for GUI

ciscorucinski at gmail.com ciscorucinski at gmail.com
Fri Feb 8 18:09:31 CET 2013



> Who/what are you responding to here? You haven't included any context
> from what you're replying to.

Sorry, never really used Google Groups, or anything like this before. That I was responding to only Chris Angelico with his question of how real-time it needed to be...since it takes some time for Lilypond to create the images.


> So you have a thread that updates the image and then checks the stack
> to see if a new image is available? Can you not just have it only try
> to load the newest image?

That is what I am trying to figure out how to do. I have a counter that updates with every note that is grabbed from the stream. That counter is passed into a threaded class that might or might not create the image right away...but seems to create them sequentially from what I have seen so far (I don't know if that is absolute thought). 

Please let me know you thought on the above part! Each new thread should only take only a very small amount longer to do than the previous thread that was started...because it has one more note to deal with this time.

Anyways...I do have the count of the latest image that WILL BE created...but by the time that one is created in the directory, a new note is most likely streamed in and replaces that count. Therefore, I cannot really do that...I think.

hmmmm, I wonder. I create the images via OS command that will .wait() on a subprocess.Popen(). I could increment the counter there? Or do something there that will let me know of the most recent image file via a counter or something? But it needs to be thread-safe

> You say that you control the filenames of the images. I assume that
> you are notified when a file is created and given the filename of the
> new file. So you can maintain a mapping of filename->ordering. In this
> case you can determine when a file notification arrives whether the
> filename corresponds to a more recent note than the filename that is
> currently waiting to be displayed (or is currently displayed). If it
> is an older note then discard it (and delete the file?) when the
> notification arrives. If it is newer then discard the one that is
> currently waiting to be displayed. This way there are always either
> zero or one filenames waiting and if there is one then it is the most
> recent one seen so far.

I am not notified when the file is created...but like I said before, I wait on the subprocess and could do something there.

> Is that using something like watchdog?
> http://pypi.python.org/pypi/watchdog

I don't know about Watchdog...but from an earlier version of a tutorial online...

http://pypi.python.org/pypi/watchdog/0.3.6  (Yes, it is currently on v0.6.0 and this is older - v0.3.6)

... it looks like I COULD do something like...

class MyEventHandler(FileSystemEventHandler):
    ...
    ...
    def on_created(self, event):
        # update gtkImage object here!!

...right? Or no? I will say that I kind of like that. The only thing is, do you think that would "flicker" in the GUI if a bunch of new images are created in quick succession? Anyways, I think that would be the most desired outcome...with every image being used and replaced with something newer without a large lag...as it will happen during each creation of a new image. 


> It matters for how you monitor the directory at least.

My other question, if I do monitor the directory vs. use a queue, or stack / list, is how to monitor a directory that is actively being updated while I search for the file. This might not matter and something like os.walk() might work...I don't know, I don't know python that well yet.

Do you get what I mean with this?


Sorry if something seems out of place...I was going back and forth and adding / removing things to my reply.

Thanks,
Christopher



More information about the Python-list mailing list