/usr/lib/python2.7/dist-packages/pyFAI/gui_utils.py is in pyfai 0.10.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Project: Azimuthal integration
# https://github.com/kif
#
# Copyright (C) European Synchrotron Radiation Facility, Grenoble, France
#
# Principal author: Jérôme Kieffer (Jerome.Kieffer@ESRF.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
gui_utils
Module to handle matplotlib and the Qt backend
"""
__author__ = "Jerome Kieffer"
__contact__ = "Jerome.Kieffer@ESRF.eu"
__license__ = "GPLv3+"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "20/10/2014"
__status__ = "production"
import sys
import matplotlib
has_Qt = True
if ('PySide' in sys.modules):
from PySide import QtGui, QtCore, QtUiTools, QtWebKit
from PySide.QtCore import SIGNAL, Signal
#we need to handle uic !!!
"""
loadUi(uifile, baseinstance=None, package='') -> widget
Load a Qt Designer .ui file and return an instance of the user interface.
uifile is a file name or file-like object containing the .ui file.
baseinstance is an optional instance of the Qt base class. If specified
then the user interface is created in it. Otherwise a new instance of the
base class is automatically created.
package is the optional package which is used as the base for any relative
imports of custom widgets.
"""
class uic(object):
@staticmethod
def loadUi(uifile, baseinstance=None, package=''):
"""Load a Qt Designer .ui file and return an instance of the user interface.
uifile is a file name or file-like object containing the .ui file.
baseinstance is an optional instance of the Qt base class. If specified
then the user interface is created in it. Otherwise a new instance of the
base class is automatically created.
package is the optional package which is used as the base for any relative
imports of custom widgets.
Totally untested !
"""
loader = QtUiTools.QUiLoader()
file = QtCore.QFile(uifile)
file.open(QtCore.QFile.ReadOnly)
myWidget = loader.load(file, self)
file.close()
if baseinstance is not None:
baseinstance = myWidget
else:
return myWidget
sys.modules["PySide.uic"] = uic
matplotlib.rcParams['backend.qt4'] = 'PySide'
else:
try:
from PyQt4 import QtGui, QtCore, uic, QtWebKit
from PyQt4.QtCore import SIGNAL, pyqtSignal as Signal
except ImportError:
has_Qt = False
if has_Qt:
matplotlib.use('Qt4Agg')
from matplotlib.backends import backend_qt4 as backend
from matplotlib import pyplot
from matplotlib import pylab
else:
from matplotlib import pyplot
from matplotlib import pylab
from matplotlib.backends import backend
QtGui = QtCore = QtUiTools = QtWebKit = loadUi = None
SIGNAL = Signal = None
main_loop = False
def update_fig(fig=None):
"""
Update a matplotlib figure with a Qt4 backend
@param fig: pylab figure
"""
if fig and "canvas" in dir(fig) and fig.canvas:
fig.canvas.draw()
if "Qt4" in pylab.get_backend():
QtGui.qApp.postEvent(fig.canvas,
QtGui.QResizeEvent(fig.canvas.size(),
fig.canvas.size()))
if not main_loop:
QtCore.QCoreApplication.processEvents()
class Event(object):
"Dummy class for dummy things"
def __init__(self, width, height):
self.width = width
self.height = height
def maximize_fig(fig=None):
"""
Try to set the figure fullscreen
"""
if fig and "canvas" in dir(fig) and fig.canvas:
if "Qt4" in pylab.get_backend():
fig.canvas.setWindowState(QtCore.Qt.WindowMaximized)
else:
mng = pylab.get_current_fig_manager()
# attempt to maximize the figure ... lost hopes.
win_shape = (1920, 1080)
event = Event(*win_shape)
try:
mng.resize(event)
except TypeError:
mng.resize(*win_shape)
update_fig(fig)
|