# -*- coding: utf-8 -*-
import sys
import time
import utool as ut
import matplotlib as mpl
from wbia.plottool import custom_figure
# from .custom_constants import golden_wh
SLEEP_TIME = 0.01
__QT4_WINDOW_LIST__ = []
ut.noinject(__name__, '[fig_presenter]')
VERBOSE = ut.get_argflag(('--verbose-fig', '--verbfig', '--verb-pt'))
# (print, print_, printDBG, rrr, profile) = ut.inject(__name__, '[fig_presenter]', DEBUG=True)
[docs]def unregister_qt4_win(win):
global __QT4_WINDOW_LIST__
if win == 'all':
__QT4_WINDOW_LIST__ = []
else:
try:
# index = __QT4_WINDOW_LIST__.index(win)
__QT4_WINDOW_LIST__.remove(win)
except ValueError:
pass
[docs]def register_qt4_win(win):
global __QT4_WINDOW_LIST__
__QT4_WINDOW_LIST__.append(win)
# ---- GENERAL FIGURE COMMANDS ----
[docs]def set_geometry(fnum, x, y, w, h):
fig = custom_figure.ensure_fig(fnum)
qtwin = get_figure_window(fig)
qtwin.setGeometry(x, y, w, h)
[docs]def get_geometry(fnum):
fig = custom_figure.ensure_fig(fnum)
qtwin = get_figure_window(fig)
(x1, y1, x2, y2) = qtwin.geometry().getCoords()
(x, y, w, h) = (x1, y1, x2 - x1, y2 - y1)
return (x, y, w, h)
# def get_screen_info():
# # TODO Move dependency to guitool
# desktop = QtWidgets.QDesktopWidget()
# mask = desktop.mask() # NOQA
# layout_direction = desktop.layoutDirection() # NOQA
# screen_number = desktop.screenNumber() # NOQA
# normal_geometry = desktop.normalGeometry() # NOQA
# num_screens = desktop.screenCount() # NOQA
# avail_rect = desktop.availableGeometry() # NOQA
# screen_rect = desktop.screenGeometry() # NOQA
# QtWidgets.QDesktopWidget().availableGeometry().center() # NOQA
# normal_geometry = desktop.normalGeometry() # NOQA
# @profile
[docs]def get_all_qt4_wins():
return __QT4_WINDOW_LIST__
# fig.show()
# fig.canvas.draw()
[docs]def get_main_win_base():
if hasattr(mpl.backends, 'backend_qt4'):
backend = mpl.backends.backend_qt4
else:
backend = mpl.backends.backend_qt5
try:
QMainWin = backend.MainWindow
except Exception as ex:
try:
ut.printex(ex, 'warning', '[fig_presenter]')
# from wbia.guitool.__PYQT__ import QtGui
QMainWin = backend.QtWidgets.QMainWindow
except Exception as ex1:
ut.printex(ex1, 'warning', '[fig_presenter]')
QMainWin = object
return QMainWin
[docs]def get_all_windows():
"""Returns all mpl figures and registered qt windows"""
try:
all_figures = get_all_figures()
all_qt4wins = get_all_qt4_wins()
all_wins = all_qt4wins + [get_figure_window(fig) for fig in all_figures]
return all_wins
except AttributeError as ex:
ut.printex(ex, 'probably using a windowless backend', iswarning=True)
return []
# @profile
[docs]def bring_to_front(fig):
if VERBOSE:
print('[pt] bring_to_front')
# what is difference between show and show normal?
qtwin = get_figure_window(fig)
qtwin.raise_()
# if not ut.WIN32:
# NOT sure on the correct order of these
# can cause the figure geometry to be unset
from wbia.guitool.__PYQT__.QtCore import Qt
qtwin.activateWindow()
qtwin.setWindowFlags(Qt.WindowStaysOnTopHint)
qtwin.setWindowFlags(Qt.WindowFlags(0))
qtwin.show()
[docs]def show():
if VERBOSE:
print('[pt] show')
all_figures_show()
all_figures_bring_to_front()
# plt.show()
[docs]def reset():
if VERBOSE:
print('[pt] reset')
close_all_figures()
[docs]def draw():
if VERBOSE:
print('[pt] draw')
all_figures_show()
[docs]def update():
if VERBOSE:
print('[pt] update')
draw()
all_figures_bring_to_front()
[docs]def iupdate():
if VERBOSE:
print('[pt] iupdate')
if ut.inIPython():
update()
iup = iupdate
[docs]def present(*args, **kwargs):
"""
basically calls show if not embeded.
Kwargs:
max_rows, row_first, no_tile, monitor_num, percent_w, percent_h,
hide_toolbar
CommandLine:
python -m wbia.plottool.fig_presenter present
Example:
>>> # DISABLE_DOCTEST
>>> from wbia.plottool.fig_presenter import * # NOQA
>>> result = present()
>>> print(result)
>>> import wbia.plottool as pt
>>> pt.show_if_requested()
"""
if VERBOSE:
print('[pt] present')
if not ut.get_argflag('--noshow'):
# print('[fig_presenter] Presenting figures...')
# with warnings.catch_warnings():
# warnings.simplefilter("ignore")
all_figures_tile(*args, **kwargs)
# Both of these lines cause the weird non-refresh black border behavior
all_figures_show()
all_figures_bring_to_front()