Jan-24-2018, 05:18 AM
Thanks again Larz, Sebastian, and Gribouillis for your help. All of the links were useful and educational.
I have a solution to the problem of finding which of the matplotlib windows is frontmost which avoids the issue that they have no common root. I'm posting it because somebody may stumble over this thread and just possibly it will be useful. However, it's not really ideal for a number of reasons, such as dependency on backend. I think that somewhere there's some simple call that would let me skip all of this.
Anyhow, here's my modified version: the idea is to put a callback on the FocusIn event so that the program keeps itself keeps track of where the focus last was.
This part would be stored in a file vers2_mw.py ('vers2', because it's version 2):
Thanks again everybody! :)
I have a solution to the problem of finding which of the matplotlib windows is frontmost which avoids the issue that they have no common root. I'm posting it because somebody may stumble over this thread and just possibly it will be useful. However, it's not really ideal for a number of reasons, such as dependency on backend. I think that somewhere there's some simple call that would let me skip all of this.
Anyhow, here's my modified version: the idea is to put a callback on the FocusIn event so that the program keeps itself keeps track of where the focus last was.
This part would be stored in a file vers2_mw.py ('vers2', because it's version 2):
front_win = None def make_wins( cnt = 3 ): def make_func( w ): def replace_front( event ): global front_win front_win = w return replace_front figs=[None]*cnt axs =[None]*cnt for i in range(cnt): figs[i],axs[i] = plt.subplots() plt.show(block=False) wins=[None]*cnt for i in range(cnt): wins[i] = figs[i].canvas.manager.window wins[i].bind( '<FocusIn>', make_func( wins[i] ) ) global front_win front_win = wins[cnt-1] return winsThen you can demonstrate it like this:
import vers2_mw from vers2_mw import * w = make_wins() vers2_mw.front_win == w[2] # This last line should print True # Now click around and select window 0: vers2_mw.front_win == w[0] # The previous line should also print True vers2_mw.front_win == w[1] # The previous line here will print False unless window 1 was chosen.So this works, and is good enough for the program that i'm developing, but a more universal solution would be useful (and thanks for any suggestions, btw).
Thanks again everybody! :)