mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
Add skimage.viewer.qt wrapper.
This allows the viewer to use either PyQt4 or PySide as the toolkit.
This commit is contained in:
@@ -1,4 +1 @@
|
||||
try:
|
||||
from viewers import ImageViewer, CollectionViewer
|
||||
except ImportError:
|
||||
print("Could not import PyQt4 -- ImageViewer not available.")
|
||||
from viewers import ImageViewer, CollectionViewer
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
"""
|
||||
Base class for Plugins that interact with ImageViewer.
|
||||
"""
|
||||
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.")
|
||||
from ..qt import QtGui
|
||||
from ..qt.QtCore import Qt
|
||||
|
||||
from ..utils import RequiredAttr, init_qtapp
|
||||
|
||||
|
||||
class Plugin(QDialog):
|
||||
class Plugin(QtGui.QDialog):
|
||||
"""Base class for plugins that interact with an ImageViewer.
|
||||
|
||||
A plugin connects an image filter (or another function) to an image viewer.
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import numpy as np
|
||||
|
||||
try:
|
||||
from PyQt4 import QtGui
|
||||
except ImportError:
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
from ..qt import QtGui
|
||||
|
||||
from ..utils import new_plot
|
||||
from .base import Plugin
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
from . import qt_api
|
||||
|
||||
if qt_api == 'pyside':
|
||||
from PySide.QtCore import *
|
||||
elif qt_api == 'pyqt':
|
||||
from PyQt4.QtCore import *
|
||||
else:
|
||||
# Mock objects
|
||||
Qt = None
|
||||
@@ -0,0 +1,11 @@
|
||||
from . import qt_api
|
||||
|
||||
if qt_api == 'pyside':
|
||||
from PySide.QtGui import *
|
||||
elif qt_api == 'pyqt':
|
||||
from PyQt4.QtGui import *
|
||||
else:
|
||||
# Mock objects
|
||||
QMainWindow = object
|
||||
QDialog = object
|
||||
QWidget = object
|
||||
@@ -0,0 +1,5 @@
|
||||
This qt subpackage provides a wrapper to allow use of either PySide or PyQt4.
|
||||
In addition, if neither package is available, some mock objects are created to
|
||||
prevent errors in the TravisCI build. Only the objects used in the global
|
||||
namespace need to be mocked (e.g., a Qt object that gets subclassed is used
|
||||
in the global namespace).
|
||||
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
import warnings
|
||||
|
||||
qt_api = os.environ.get('QT_API')
|
||||
|
||||
if qt_api is None:
|
||||
try:
|
||||
import PySide
|
||||
qt_api = 'pyside'
|
||||
except ImportError:
|
||||
try:
|
||||
import PyQt4
|
||||
qt_api = 'pyqt'
|
||||
except ImportError:
|
||||
qt_api = 'none'
|
||||
# Note that we don't want to raise an error because that would
|
||||
# cause the TravisCI build to fail.
|
||||
warnings.warn("Could not import PyQt4: ImageViewer not available!")
|
||||
os.environ['QT_API'] = qt_api
|
||||
@@ -14,10 +14,7 @@ except ImportError:
|
||||
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.")
|
||||
from ..qt import QtGui
|
||||
|
||||
|
||||
__all__ = ['init_qtapp', 'start_qtapp', 'RequiredAttr', 'figimage',
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
"""
|
||||
ImageViewer class for viewing and interacting with images.
|
||||
"""
|
||||
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 ..qt import QtGui
|
||||
from ..qt import QtCore
|
||||
|
||||
from skimage import io, img_as_float
|
||||
from skimage.util.dtype import dtype_range
|
||||
@@ -32,7 +28,7 @@ def mpl_image_to_rgba(mpl_image):
|
||||
return img_as_float(image)
|
||||
|
||||
|
||||
class ImageViewer(QMainWindow):
|
||||
class ImageViewer(QtGui.QMainWindow):
|
||||
"""Viewer for displaying images.
|
||||
|
||||
This viewer is a simple container object that holds a Matplotlib axes
|
||||
|
||||
@@ -15,14 +15,9 @@ parameter type specified by its `ptype` attribute, which can be:
|
||||
property of the same name that updates the display.
|
||||
|
||||
"""
|
||||
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 ..qt import QtGui
|
||||
from ..qt import QtCore
|
||||
from ..qt.QtCore import Qt
|
||||
|
||||
from ..utils import RequiredAttr
|
||||
|
||||
@@ -30,7 +25,7 @@ from ..utils import RequiredAttr
|
||||
__all__ = ['BaseWidget', 'Slider', 'ComboBox', 'Text']
|
||||
|
||||
|
||||
class BaseWidget(QWidget):
|
||||
class BaseWidget(QtGui.QWidget):
|
||||
|
||||
plugin = RequiredAttr("Widget is not attached to a Plugin.")
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
from textwrap import dedent
|
||||
|
||||
try:
|
||||
from PyQt4 import QtGui, QtCore
|
||||
except ImportError:
|
||||
print("Could not import PyQt4 -- skimage.viewer not available.")
|
||||
from ..qt import QtGui
|
||||
from ..qt import QtCore
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
Reference in New Issue
Block a user