1

I have written some code on a GUI which when a button is pressed runs a really long process that sorts out images and processes them. However, I have a textCtrl(text box) which the stdout is redirected to the text box. My issue is that the textbox does not update during the event and only after the event is finished then updates all in one go.

I have tried a few solutions such as threading, multiprocessing(best hope yet), wx.callafter, but still I don't quite understand how is best to proceed. please do let me know if u have any idea what would be the best way. I would post the code but it is currently 800 lines long so not sure how useful it would be. Any help would be appreciated.

Plebala
  • 60
  • 1
  • 10
  • 1
    Even though your overall code may be 800 lines, can you maybe try changing the complex sorting event to something simpler e.g. a loop where you sleep for 5 seconds, try to add to the textbox, and repeat? If that showed the problem and cut the number of code lines down a lot, that could help. – aschultz Aug 15 '19 at 14:11
  • the event basically runs several steps which import images, metadata, sorting, creating directories, image processing hence why it is quite a few lines of code. running the full process takes about 10-15 minutes due to the fact that it is sifting through 5-10gb of data at a time. would there be a way perhaps to pause the event handler to updata the gui say every second or so ? also i've noticed running the code that the stdout does print to the textbox for a few seconds then the GUI just stops and not responds. – matthew lim Aug 15 '19 at 14:25
  • That seems possible. I think it's worthwhile to try something much simpler to see if it is the textbox code that is at fault or your complex image code. If the textbox updates regularly when you print to stdout for something much less stressful, I'd guess the slowdown is in the intense image sorting/processing. I wouldn't know enough about that area of python to help. But I hope this gives you experiments to get started. – aschultz Aug 15 '19 at 14:30
  • Look at the answers to this question https://stackoverflow.com/questions/56945900/how-to-update-progress-bar-as-well-as-download-file-using-multi-threading/56976834#56976834 One answer uses wx.python `events` to notify the mainthread that something has occurred and the other answer uses `pubsub`. Both would be valid for your project. – Rolf of Saxony Aug 15 '19 at 16:33

0 Answers0