I have written code to implement a simple Ghostscript viewer in a wxScrolledWindow. You can look at the code at http://www.cs.unc.edu/~gb/gv.py. Pretty simple and pretty rough. I have only tested it on WindowsXP with Ghostscript 8.0 but I think it should work on Linux and with other versions of Ghostscript.
Working on it brought up some questions.
1) Can I get a close event (or some signal that things are closing down) without requiring the user of the window to explicitly call Close? I need to cleanup some files that were stored in temp when the window is shutdown. I tried attaching an EVT_CLOSE to the window but this only seems to work on frames. I tried a __del__ method but that didn't do the job either. I'd like the window to hide the complexity of cleaning up after Ghostscript so that it works like any other window.
2) I don't know how many pages there are when I start. I don't want to wait for Ghostscript to generate all the image files before displaying. So I have a second thread watching Ghostscript and reporting the availability of new pages. When I get a new page, I'd like to let the parent know that the count has changed (for example to update the status bar as in the example usage at the bottom of gv.py). I did this by synthesizing a wxSCROLLWIN_EVENT that does nothing so that the parent can watch for these. In the example, on scroll I update the status bar to indicate the current page and the total number of pages. Is there a better (or proper) way to accomplish this result?
Thanks and I welcome any suggestions on how to make this code better.
gb
I have written code to implement a simple Ghostscript viewer in a wxScrolledWindow. You can look at the code at http://www.cs.unc.edu/~gb/gv.py. Pretty simple and pretty rough. I have only tested it on WindowsXP with Ghostscript 8.0 but I think it should work on Linux and with other versions of Ghostscript.
Working on it brought up some questions.
1) Can I get a close event (or some signal that things are closing down) without requiring the user of the window to explicitly call Close? I need to cleanup some files that were stored in temp when the window is shutdown. I tried attaching an EVT_CLOSE to the window but this only seems to work on frames. I tried a __del__ method but that didn't do the job either. I'd like the window to hide the complexity of cleaning up after Ghostscript so that it works like any other window.
__del__ will start working in the next release. You can see the details of why it doesn't work now in the mail archives, but basically it is because when the C++ class is destroyed the Python __class__ is changed to _wxPyDeadObject.
You can use EVT_WINDOW_DESTOY to catch when the windows is being destroyed, but be sure to *not* call any methods of the wxWindow because the C++ window is already in the process of being detroyed.
2) I don't know how many pages there are when I start. I don't want to wait for Ghostscript to generate all the image files before displaying. So I have a second thread watching Ghostscript and reporting the availability of new pages. When I get a new page, I'd like to let the parent know that the count has changed (for example to update the status bar as in the example usage at the bottom of gv.py). I did this by synthesizing a wxSCROLLWIN_EVENT that does nothing so that the parent can watch for these. In the example, on scroll I update the status bar to indicate the current page and the total number of pages. Is there a better (or proper) way to accomplish this result?
Give your class a method such as UpdatePageCount and then call it from the monitor thread like this: