mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-03 19:14:46 +08:00
STY: Refactor initialization of QApplication.
This commit is contained in:
@@ -17,8 +17,25 @@ except ImportError:
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
|
||||
|
||||
__all__ = ['figimage', 'LinearColormap', 'ClearColormap', 'MatplotlibCanvas',
|
||||
'RequiredAttr']
|
||||
__all__ = ['init_qtapp', 'start_qtapp', 'RequiredAttr', 'figimage',
|
||||
'LinearColormap', 'ClearColormap', 'MatplotlibCanvas']
|
||||
|
||||
|
||||
QApp = None
|
||||
|
||||
|
||||
def init_qtapp():
|
||||
"""Initialize QAppliction.
|
||||
|
||||
The QApplication needs to be initialized before creating any QWidgets
|
||||
"""
|
||||
global QApp
|
||||
if QApp is None:
|
||||
QApp = QtGui.QApplication([])
|
||||
|
||||
def start_qtapp():
|
||||
"""Start Qt mainloop"""
|
||||
QApp.exec_()
|
||||
|
||||
|
||||
class RequiredAttr(object):
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
"""
|
||||
ImageViewer class for viewing and interacting with images.
|
||||
"""
|
||||
import sys
|
||||
|
||||
try:
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from PyQt4.QtGui import QMainWindow
|
||||
@@ -11,20 +9,18 @@ except ImportError:
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
|
||||
from skimage.util.dtype import dtype_range
|
||||
from ..utils import figimage, MatplotlibCanvas
|
||||
from .. import utils
|
||||
from ..widgets import Slider
|
||||
|
||||
|
||||
__all__ = ['ImageViewer', 'CollectionViewer']
|
||||
|
||||
|
||||
qApp = None
|
||||
|
||||
|
||||
class ImageCanvas(MatplotlibCanvas):
|
||||
class ImageCanvas(utils.MatplotlibCanvas):
|
||||
"""Canvas for displaying images."""
|
||||
def __init__(self, parent, image, **kwargs):
|
||||
self.fig, self.ax = figimage(image, **kwargs)
|
||||
self.fig, self.ax = utils.figimage(image, **kwargs)
|
||||
super(ImageCanvas, self).__init__(parent, self.fig, **kwargs)
|
||||
|
||||
|
||||
@@ -60,9 +56,7 @@ class ImageViewer(QMainWindow):
|
||||
"""
|
||||
def __init__(self, image):
|
||||
# Start main loop
|
||||
global qApp
|
||||
if qApp is None:
|
||||
qApp = QtGui.QApplication(sys.argv)
|
||||
utils.init_qtapp()
|
||||
super(ImageViewer, self).__init__()
|
||||
|
||||
#TODO: Add ImageViewer to skimage.io window manager
|
||||
@@ -136,7 +130,7 @@ class ImageViewer(QMainWindow):
|
||||
for p in self.plugins:
|
||||
p.show()
|
||||
super(ImageViewer, self).show()
|
||||
qApp.exec_()
|
||||
utils.start_qtapp()
|
||||
|
||||
def redraw(self):
|
||||
self.canvas.draw_idle()
|
||||
|
||||
Reference in New Issue
Block a user