mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-08 11:58:33 +08:00
BUG: Fix nosetest and autodoc errors when PyQt4 not available
nose and autodoc imports the viewer modules so all PyQt4 imports must be wrapped in a try-except block. In addition, any classes derived from PyQt4 must be proxied since the class definition are run on import. This is really hacky.
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
"""
|
||||
Base class for Plugins that interact with ImageViewer.
|
||||
"""
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4.QtCore import Qt
|
||||
import matplotlib as mpl
|
||||
try:
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4.QtCore import Qt
|
||||
from PyQt4.QtGui import QDialog
|
||||
except ImportError:
|
||||
QDialog = object # hack to prevent nosetest and autodoc errors
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
|
||||
try:
|
||||
import matplotlib as mpl
|
||||
except ImportError:
|
||||
print("Could not import matplotlib -- skimage.viewer not available.")
|
||||
|
||||
from ..utils import RequiredAttr
|
||||
|
||||
|
||||
class Plugin(QtGui.QDialog):
|
||||
class Plugin(QDialog):
|
||||
"""Base class for plugins that interact with an ImageViewer.
|
||||
|
||||
A plugin connects an image filter (or another function) to an image viewer.
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.colors import LinearSegmentedColormap
|
||||
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
|
||||
from PyQt4 import QtGui
|
||||
|
||||
try:
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.colors import LinearSegmentedColormap
|
||||
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
|
||||
except ImportError:
|
||||
FigureCanvasQTAgg = object # hack to prevent nosetest and autodoc errors
|
||||
LinearSegmentedColormap = object
|
||||
print("Could not import matplotlib -- skimage.viewer not available.")
|
||||
|
||||
try:
|
||||
from PyQt4 import QtGui
|
||||
except ImportError:
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
|
||||
|
||||
__all__ = ['figimage', 'LinearColormap', 'ClearColormap', 'MatplotlibCanvas',
|
||||
|
||||
@@ -3,7 +3,12 @@ ImageViewer class for viewing and interacting with images.
|
||||
"""
|
||||
import sys
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
try:
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from PyQt4.QtGui import QMainWindow
|
||||
except ImportError:
|
||||
QMainWindow = object # hack to prevent nosetest and autodoc errors
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
|
||||
from ..utils import figimage, MatplotlibCanvas
|
||||
|
||||
@@ -18,7 +23,7 @@ class ImageCanvas(MatplotlibCanvas):
|
||||
super(ImageCanvas, self).__init__(parent, self.fig, **kwargs)
|
||||
|
||||
|
||||
class ImageViewer(QtGui.QMainWindow):
|
||||
class ImageViewer(QMainWindow):
|
||||
"""Viewer for displaying images.
|
||||
|
||||
This viewer is a simple container object that holds a Matplotlib axes
|
||||
|
||||
@@ -15,9 +15,14 @@ parameter type specified by its `ptype` attribute, which can be:
|
||||
property of the same name that updates the display.
|
||||
|
||||
"""
|
||||
from PyQt4.QtCore import Qt
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4 import QtCore
|
||||
try:
|
||||
from PyQt4.QtCore import Qt
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4 import QtCore
|
||||
from PyQt4.QtGui import QWidget
|
||||
except ImportError:
|
||||
QWidget = object # hack to prevent nosetest and autodoc errors
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
|
||||
from ..utils import RequiredAttr
|
||||
|
||||
@@ -25,7 +30,7 @@ from ..utils import RequiredAttr
|
||||
__all__ = ['BaseWidget', 'Slider', 'ComboBox']
|
||||
|
||||
|
||||
class BaseWidget(QtGui.QWidget):
|
||||
class BaseWidget(QWidget):
|
||||
|
||||
plugin = RequiredAttr("Widget is not attached to a Plugin.")
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import os
|
||||
from textwrap import dedent
|
||||
|
||||
from PyQt4 import QtGui
|
||||
try:
|
||||
from PyQt4 import QtGui
|
||||
except ImportError:
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
|
||||
from skimage import io
|
||||
from .core import BaseWidget
|
||||
|
||||
Reference in New Issue
Block a user