mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-07 05:35:50 +08:00
ENH: Add SaveButtons widget.
This commit is contained in:
@@ -137,6 +137,7 @@ class Plugin(QtGui.QDialog):
|
||||
widget.callback = self.filter_image
|
||||
elif widget.ptype == 'plugin':
|
||||
widget.callback = self.update_plugin
|
||||
widget.plugin = self
|
||||
self.layout.addWidget(widget, self.row, 0)
|
||||
self.row += 1
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from core import *
|
||||
from history import *
|
||||
|
||||
@@ -19,17 +19,22 @@ from PyQt4.QtCore import Qt
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4 import QtCore
|
||||
|
||||
from ..utils import RequiredAttr
|
||||
|
||||
|
||||
__all__ = ['BaseWidget', 'Slider', 'ComboBox']
|
||||
|
||||
|
||||
class BaseWidget(QtGui.QWidget):
|
||||
|
||||
plugin = RequiredAttr("Widget is not attached to a Plugin.")
|
||||
|
||||
def __init__(self, name, ptype, callback):
|
||||
super(BaseWidget, self).__init__()
|
||||
self.name = name
|
||||
self.ptype = ptype
|
||||
self.callback = callback
|
||||
self.plugin = None
|
||||
|
||||
@property
|
||||
def val(self):
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import os
|
||||
from textwrap import dedent
|
||||
|
||||
from PyQt4 import QtGui
|
||||
|
||||
from skimage import io
|
||||
from .core import BaseWidget
|
||||
|
||||
|
||||
__all__ = ['SaveButtons']
|
||||
|
||||
|
||||
class SaveButtons(BaseWidget):
|
||||
|
||||
def __init__(self, default_format='png'):
|
||||
name = 'Save to:'
|
||||
ptype = None
|
||||
callback = None
|
||||
super(SaveButtons, self).__init__(name, ptype, callback)
|
||||
|
||||
self.default_format = default_format
|
||||
|
||||
self.name_label = QtGui.QLabel()
|
||||
self.name_label.setText(name)
|
||||
|
||||
self.save_file = QtGui.QPushButton('File')
|
||||
self.save_file.clicked.connect(self.save_to_file)
|
||||
self.save_stack = QtGui.QPushButton('Stack')
|
||||
self.save_stack.clicked.connect(self.save_to_stack)
|
||||
|
||||
self.layout = QtGui.QHBoxLayout(self)
|
||||
self.layout.addWidget(self.name_label)
|
||||
self.layout.addWidget(self.save_stack)
|
||||
self.layout.addWidget(self.save_file)
|
||||
|
||||
def save_to_stack(self):
|
||||
image = self.plugin.image_viewer.image.copy()
|
||||
io.push(image)
|
||||
|
||||
msg = dedent('''\
|
||||
The image has been pushed to the io stack.
|
||||
Use io.pop() to retrieve the most recently pushed image.
|
||||
NOTE: The io stack only works in interactive sessions.''')
|
||||
notify(msg)
|
||||
|
||||
def save_to_file(self):
|
||||
filename = str(QtGui.QFileDialog.getSaveFileName())
|
||||
if len(filename) == 0:
|
||||
return
|
||||
#TODO: io plugins should assign default image formats
|
||||
basename, ext = os.path.splitext(filename)
|
||||
if not ext:
|
||||
filename = '%s.%s' % (filename, self.default_format)
|
||||
io.imsave(filename, self.plugin.image_viewer.image)
|
||||
|
||||
|
||||
def notify(msg):
|
||||
msglabel = QtGui.QLabel(msg)
|
||||
dialog = QtGui.QDialog()
|
||||
ok = QtGui.QPushButton('OK', dialog)
|
||||
ok.clicked.connect(dialog.accept)
|
||||
ok.setDefault(True)
|
||||
dialog.layout = QtGui.QGridLayout(dialog)
|
||||
dialog.layout.addWidget(msglabel, 0, 0, 1, 3)
|
||||
dialog.layout.addWidget(ok, 1, 1)
|
||||
dialog.exec_()
|
||||
@@ -0,0 +1,18 @@
|
||||
from skimage import data
|
||||
from skimage.filter import median_filter
|
||||
|
||||
from skimage.viewer import ImageViewer
|
||||
from skimage.viewer.widgets import Slider
|
||||
from skimage.viewer.widgets.history import SaveButtons
|
||||
from skimage.viewer.plugins.overlayplugin import Plugin
|
||||
|
||||
|
||||
image = data.coins()
|
||||
viewer = ImageViewer(image)
|
||||
|
||||
plugin = Plugin(image_filter=median_filter)
|
||||
plugin += Slider('radius', 2, 10, value_type='int', update_on='release')
|
||||
plugin += SaveButtons()
|
||||
|
||||
viewer += plugin
|
||||
viewer.show()
|
||||
Reference in New Issue
Block a user