Re: Monitoring updating directory for image for GUI
WOW...I am thinking that all of this was actually unnecessary, I don't think I need a Queue, or List / Stack, or any traversal of the file system to accomplish this!! I only need one image displayed at a time and don't care about them after a newer image is generated. So my prototype of just replacing the image over and over again SHOULD suffice. All I need the for the monitor now is to grab the image file (that might have or might not have been updated by Lilypond) at set amount of times and refresh the GtkImage object. The only reason why I originally suggested using multiple files was because I wanted to make sure that I had to most recent image and I was not sure if the threads would guarantee that. So my only remaining question (for now) is... I'm I guaranteed that if I have threads 1...n, that were all started in **quick** succession to call an OS command on Lilypond, that if I replaced the image file being generated with the completion of each thread that I would end up with the final image being from thread n...and that if I were able to update the GUI in a fast enough fashion, that I would see the images being displayed on the screen from 1 to n without anything being out of place? All of my tests have shown that seems to be a reasonable assumption, but I need to know for sure. If that was the case were I am not guaranteed that, then when a user decides to stop the stream I could resend the note stream that I have saved on my end to Lilypond one last time to guarantee that all of the notes are displayed. So I would only create one image location at images\sheetMusic.png and that file would be continuously updated as new notes are streamed in. My monitor class (might be a legacy component now) would basically look for that one image - images\sheetMusic.png, grab it, and update the GUI at an interval that is easy on the eyes (maybe a half second for example). Could there be a problem where the image is being updated, so the OS deletes the image, and my program tries to update the image but cannot find it, and the OS reassigns that file location to that previous file location and name? Let me know what you thing or if anything is confusing you. Thanks for the comments so far! - Christopher - -- http://mail.python.org/mailman/listinfo/python-list
Re: Monitoring updating directory for image for GUI
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. h, 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 -- http://mail.python.org/mailman/listinfo/python-list
Glade + GTK.Builder() | Missing Handlers | Handler for multiple objects
Here is my code in PasteBin... http://pastebin.com/ZubyV8RT If you go to the very bottom of the paste, you will see the error messages that I get, but here it is again. --- Warning (from warnings module): File C:\Users\rucinskic\Dropbox\SeniorDesign\cflat\frontend\CFlatGUI.py, line 287 self.builder.connect_signals( event_dictionary ) RuntimeWarning: missing handler 'on_mnuHelp_activate' Warning (from warnings module): File C:\Users\rucinskic\Dropbox\SeniorDesign\cflat\frontend\CFlatGUI.py, line 287 self.builder.connect_signals( event_dictionary ) RuntimeWarning: missing handler 'on_mnuRecord_activate' Warning (from warnings module): File C:\Users\rucinskic\Dropbox\SeniorDesign\cflat\frontend\CFlatGUI.py, line 287 self.builder.connect_signals( event_dictionary ) RuntimeWarning: missing handler 'on_mnuEdit_activate' Warning (from warnings module): File C:\Users\rucinskic\Dropbox\SeniorDesign\cflat\frontend\CFlatGUI.py, line 287 self.builder.connect_signals( event_dictionary ) RuntimeWarning: missing handler 'on_mnuFile_activate' --- If you look near the bottom of the paste, you will also see code like... self.dlgAbout.show() ...one commented out, and one not. If I uncomment that one, then dlgAbout is shown, but the one that I don't have commented out will NEVER work...that goes for all of the handler functions? Why is that? Also, why am I getting those warning messages? I am trying to connect multiple menu items to one handler (like all File menu items will go to the on_mnuFile_activate handler). In Glade, I am setting the GtkMenuItem's activate signal to go to the on_xxx_active handler (on_mnuFile_active) Does anyone understand what is going wrong? Thanks, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Monitoring updating directory for image for GUI
Real-time...as close to real-time as possible. That is why I did not really want to use a queue. That is because if a bunch of the thread that create the images finish really close to one another (when they should be spread out based on how the music is played), then there would be a larger lag in the display. So displaying only the most recent image is preferred. That is why I though Stack...but then that might mean that older images will replace newer ones. The Workflow is as such: 1) Music is analyzed and streamed to the program. Note-by-Note. 2) The note is grabbed (same way as a Java Scanner class) 3) A new thread is created to call an OS command (Lilypond command) a) Thread waits until command is finished, and Lilypond creates an image that I can define the filename for in a directory. From here I want only the latest one (as close to the latest one at least) to be displayed to the gtkImage object in the GUI I set up a class that would act as a directory monitor (just stubbed)...that would do all the work I am asking for here Also, don't think this matters much, but I am using Windows (I seen someone mention Linux) -- http://mail.python.org/mailman/listinfo/python-list
Monitoring updating directory for image for GUI
Hello, I have been using Python for a few months now, so I am still learning a few things here and there. Basically I am creating a program that will stream musical notes into a program called Lilypond one-by-one and it will create the sheet music for that stream of music via OS command. Your understanding of Lilypond is not needed, but you need to know that for each new note that is streamed in real-time, a PNG image file will be created for that stream of music up to that point...via Lilypond. What I am looking at doing is to monitor the directory where the image files are being created in real-time, and update the GUI (build with gtk.Builder and Glade) with the most recent image file. I have the program multithreaded and it appears that all of the images are being created sequentially; however, I need to make sure that an older image (an image with less notes displayed) is NOT going to be displayed over a newer image. The question I have is what do you see as the best way of going about this? I have looked at creating a Stack from the python List, along with os.walk(). However, I am not sure if those are adequate with a directory that is actively adding new files. Also, how I imagined using the Stack with taking the next item off of the stack meant that older ones would be replacing new ones...and with a queue, it might be updating too slow; especially if the notes being streamed in are played fast. So I would like for the most recent image to be used and all others discarded. Thanks, Christopher -- http://mail.python.org/mailman/listinfo/python-list