ENH: Simplify creation of Slider widget.

This commit is contained in:
Tony S Yu
2012-07-22 02:02:29 -04:00
parent bc6c81606f
commit 887a9119b2
4 changed files with 40 additions and 14 deletions
+15 -8
View File
@@ -1,7 +1,7 @@
from PyQt4 import QtGui
import matplotlib as mpl
from skimage.io._plugins.q_color_mixer import IntelligentSlider
from ..widgets import Slider
class Plugin(QtGui.QDialog):
@@ -78,17 +78,17 @@ class Plugin(QtGui.QDialog):
else:
return param
def add_argument(self, name, low, high, callback, **kwargs):
name, slider = self.add_slider(name, low, high, callback, **kwargs)
def add_argument(self, name, low, high, **kwargs):
name, slider = self.add_slider(name, low, high, **kwargs)
self.arguments.append(slider)
def add_keyword_argument(self, name, low, high, callback, **kwargs):
name, slider = self.add_slider(name, low, high, callback, **kwargs)
def add_keyword_argument(self, name, low, high, **kwargs):
name, slider = self.add_slider(name, low, high, **kwargs)
self.keyword_arguments[name] = slider
def add_slider(self, name, low, high, callback, **kwargs):
slider = IntelligentSlider(name, low, high, callback,
orientation='horizontal', **kwargs)
def add_slider(self, name, low, high, **kwargs):
slider = Slider(name, low, high, **kwargs)
slider.callback = self.caller
self.layout.addWidget(slider, self.row, 0)
self.row += 1
return name.replace(' ', '_'), slider
@@ -110,6 +110,13 @@ class Plugin(QtGui.QDialog):
This should be used in lieu of `figure.canvas.mpl_connect` since this
function stores call back ids for later clean up.
Parameters
----------
event : str
Matplotlib event.
callback : function
Callback function with a matplotlib Event object as its argument.
"""
cid = self.image_viewer.connect_event(event, callback)
self.cids.append(cid)
+3 -6
View File
@@ -12,12 +12,9 @@ class CannyPlugin(OverlayPlugin):
width = kwargs.get('width', 400)
super(CannyPlugin, self).__init__(image_viewer,
width=width, height=height)
self.add_keyword_argument('sigma', 0.005, 0, self.caller,
update_on='release')
self.add_keyword_argument('low_threshold', 0.255, 0, self.caller,
update_on='release')
self.add_keyword_argument('high_threshold', 0.255, 0, self.caller,
update_on='release')
self.add_keyword_argument('sigma', 0, 5, update_on='release')
self.add_keyword_argument('low_threshold', 0, 255, update_on='release')
self.add_keyword_argument('high_threshold', 0, 255, update_on='release')
# Call callback so that image is updated to slider values.
self.caller()
+1
View File
@@ -0,0 +1 @@
from core import *
+21
View File
@@ -0,0 +1,21 @@
from skimage.io._plugins.q_color_mixer import IntelligentSlider
class Slider(IntelligentSlider):
"""Slider widget.
Parameters
----------
name : str
Name of slider parameter. If this parameter is passed as a keyword
argument, it must match the name of that keyword argument. In addition,
this name is displayed as the name of the slider.
low, high : float
Range of slider values.
ptype : {'arg' | 'kwarg' | ...}
Parameter
"""
def __init__(self, name, low, high, ptype='kwarg', callback=None, **kwargs):
self.ptype = ptype
kwargs.setdefault('orientation', 'horizontal')
scale = (high - low) / 1000.0
super(Slider, self).__init__(name, scale, low, callback, **kwargs)