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:
Tony S Yu
2012-08-25 12:06:03 -04:00
parent 3f8d000db3
commit b14514e018
5 changed files with 47 additions and 15 deletions
+13 -4
View File
@@ -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.
+14 -4
View File
@@ -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',
+7 -2
View File
@@ -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
+9 -4
View File
@@ -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.")
+4 -1
View File
@@ -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