I'm using PyQT4 as the backend inside matplotlib, here is the demo code:
nnoremap \t :<C-u>py3 test_graphical_interface()<CR>
python3 << EOF
import matplotlib
matplotlib.use("Qt4Agg", warn=True)
import matplotlib.pyplot as pyplot
from PyQt4 import QtGui, QtCore
def test_graphical_interface():
fig= pyplot.figure( \
figsize= (3.0, 3.0), \
dpi= 300, \
facecolor= '#ffc0cb', \
edgecolor= '#ffc0cb', \
linewidth= 1.0
)
ax= fig.add_axes((0.1, 0.1, 0.8, 0.8), axis_bgcolor='black')
manager= pyplot.get_current_fig_manager()
manager.window.setWindowTitle('GIF testing')
manager.window.showMaximized() # XXX: show up the graphical window
EOF
The following code I found online was also tried, yet it has no effect.
manager.window.setWindowState(
manager.window.windowState() & \
~QtCore.Qt.WindowMinimized | \
QtCore.Qt.WindowActive
)
manager.window.setWindowFlags(
manager.window.windowFlags() & \
QtCore.Qt.WindowStaysOnTopHint
)
manager.window.setWindowFlags(
manager.window.windowFlags() & \
~QtCore.Qt.WindowStaysOnTopHint
)
manager.window.raise_()
manager.window.activateWindow()
I realized this issue was in line with Unity's behaviour, like when you open up multiple image files with eog the viewer, only the first time opening will bring up the eog window, later opening up will only gives you notice in the launching area and Unity will not bring up new windows (having the new windows minimized and hidden below).
After some try I realized two consecutive calls of window.show() will always bring up the window to the front as desired:
manager.window.showNormal()
manager.window.showMaximized()
but a new problem occurred, when the matplotlib window is closed, gvim window will be closed as well, it looks like each call of the show() function will be registered, such that corresponding numbers of TERM signal will be generated later, first signal kills the graphical window, the second kills gvim.
There are 3 options I can think of trying to solve the issue:
1. try to make gvim ignore the TERM signal, such that it can only be quitted by commands like :qall
2. try to alter the behaviour of Unity into always bringing up the new app windows to the top
3. keep trying within the Qt frame, like more methods of the manager.window object to see if a solution can be found
Can someone enlighten me as to which option I should try with the most likelihood of success? Thanks.
OK, I found a not so elegant solution:
evalstr= "feedkeys(':py3 subprocess.Popen([''wmctrl'', ''-a'', ''" +"GIF testing"+ "''], shell=False)' . " + '"\<CR>")'
vim.eval(evalstr)
When in doubt, feedkeys.
> > On Monday, June 27, 2016 at 6:40:07 PM UTC+8, Jacky Liu wrote:
You're right, I also realized that when I screwed up my Python program such that gvim stopped responding, I also have to rely on manually closing the window to quit gvim, so ignoring the TERM signal may not be an option. Fortunately the feedkeys() approach worked for me.