Handle text with WidgetParameterItem and SimpleParameter
This commit is contained in:
parent
3af23725ca
commit
02079aec8a
@ -1,3 +1,6 @@
|
|||||||
|
import os
|
||||||
|
import warnings
|
||||||
|
|
||||||
from ..Qt import QtCore, QtGui
|
from ..Qt import QtCore, QtGui
|
||||||
from ..python2_3 import asUnicode
|
from ..python2_3 import asUnicode
|
||||||
from .Parameter import Parameter, registerParameterType
|
from .Parameter import Parameter, registerParameterType
|
||||||
@ -7,7 +10,6 @@ from ..widgets.ColorButton import ColorButton
|
|||||||
from ..colormap import ColorMap
|
from ..colormap import ColorMap
|
||||||
from .. import pixmaps as pixmaps
|
from .. import pixmaps as pixmaps
|
||||||
from .. import functions as fn
|
from .. import functions as fn
|
||||||
import os, sys
|
|
||||||
from ..pgcollections import OrderedDict
|
from ..pgcollections import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
@ -34,7 +36,8 @@ class WidgetParameterItem(ParameterItem):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, param, depth):
|
def __init__(self, param, depth):
|
||||||
ParameterItem.__init__(self, param, depth)
|
ParameterItem.__init__(self, param, depth)
|
||||||
|
|
||||||
|
self.asSubItem = False
|
||||||
self.hideWidget = True ## hide edit widget, replace with label when not selected
|
self.hideWidget = True ## hide edit widget, replace with label when not selected
|
||||||
## set this to False to keep the editor widget always visible
|
## set this to False to keep the editor widget always visible
|
||||||
|
|
||||||
@ -42,7 +45,11 @@ class WidgetParameterItem(ParameterItem):
|
|||||||
w = self.makeWidget()
|
w = self.makeWidget()
|
||||||
self.widget = w
|
self.widget = w
|
||||||
self.eventProxy = EventProxy(w, self.widgetEventFilter)
|
self.eventProxy = EventProxy(w, self.widgetEventFilter)
|
||||||
|
|
||||||
|
if self.asSubItem:
|
||||||
|
self.subItem = QtGui.QTreeWidgetItem()
|
||||||
|
self.addChild(self.subItem)
|
||||||
|
|
||||||
self.defaultBtn = QtGui.QPushButton()
|
self.defaultBtn = QtGui.QPushButton()
|
||||||
self.defaultBtn.setAutoDefault(False)
|
self.defaultBtn.setAutoDefault(False)
|
||||||
self.defaultBtn.setFixedWidth(20)
|
self.defaultBtn.setFixedWidth(20)
|
||||||
@ -128,6 +135,15 @@ class WidgetParameterItem(ParameterItem):
|
|||||||
w.value = lambda: asUnicode(w.text())
|
w.value = lambda: asUnicode(w.text())
|
||||||
w.setValue = lambda v: w.setText(asUnicode(v))
|
w.setValue = lambda v: w.setText(asUnicode(v))
|
||||||
w.sigChanging = w.textChanged
|
w.sigChanging = w.textChanged
|
||||||
|
elif t == 'text':
|
||||||
|
w = QtGui.QTextEdit()
|
||||||
|
w.setMaximumHeight(100)
|
||||||
|
w.setReadOnly(opts.get('readonly', False))
|
||||||
|
w.value = lambda: str(w.toPlainText())
|
||||||
|
w.setValue = w.setPlainText
|
||||||
|
w.sigChanged = w.textChanged
|
||||||
|
self.hideWidget = False
|
||||||
|
self.asSubItem = True
|
||||||
elif t == 'color':
|
elif t == 'color':
|
||||||
w = ColorButton()
|
w = ColorButton()
|
||||||
w.sigChanged = w.sigColorChanged
|
w.sigChanged = w.sigColorChanged
|
||||||
@ -259,9 +275,13 @@ class WidgetParameterItem(ParameterItem):
|
|||||||
tree = self.treeWidget()
|
tree = self.treeWidget()
|
||||||
if tree is None:
|
if tree is None:
|
||||||
return
|
return
|
||||||
tree.setItemWidget(self, 1, self.layoutWidget)
|
if self.asSubItem:
|
||||||
self.displayLabel.hide()
|
tree.setFirstItemColumnSpanned(self.subItem, True)
|
||||||
self.selected(False)
|
tree.setItemWidget(self.subItem, 0, self.widget)
|
||||||
|
else:
|
||||||
|
tree.setItemWidget(self, 1, self.layoutWidget)
|
||||||
|
self.displayLabel.hide()
|
||||||
|
self.selected(False)
|
||||||
|
|
||||||
def defaultClicked(self):
|
def defaultClicked(self):
|
||||||
self.param.setToDefault()
|
self.param.setToDefault()
|
||||||
@ -332,6 +352,7 @@ class SimpleParameter(Parameter):
|
|||||||
'float': float,
|
'float': float,
|
||||||
'bool': bool,
|
'bool': bool,
|
||||||
'str': asUnicode,
|
'str': asUnicode,
|
||||||
|
'text': asUnicode,
|
||||||
'color': self._interpColor,
|
'color': self._interpColor,
|
||||||
'colormap': self._interpColormap,
|
'colormap': self._interpColormap,
|
||||||
}[self.opts['type']]
|
}[self.opts['type']]
|
||||||
@ -350,6 +371,7 @@ registerParameterType('int', SimpleParameter, override=True)
|
|||||||
registerParameterType('float', SimpleParameter, override=True)
|
registerParameterType('float', SimpleParameter, override=True)
|
||||||
registerParameterType('bool', SimpleParameter, override=True)
|
registerParameterType('bool', SimpleParameter, override=True)
|
||||||
registerParameterType('str', SimpleParameter, override=True)
|
registerParameterType('str', SimpleParameter, override=True)
|
||||||
|
registerParameterType('text', SimpleParameter, override=True)
|
||||||
registerParameterType('color', SimpleParameter, override=True)
|
registerParameterType('color', SimpleParameter, override=True)
|
||||||
registerParameterType('colormap', SimpleParameter, override=True)
|
registerParameterType('colormap', SimpleParameter, override=True)
|
||||||
|
|
||||||
@ -633,6 +655,10 @@ registerParameterType('action', ActionParameter, override=True)
|
|||||||
|
|
||||||
class TextParameterItem(WidgetParameterItem):
|
class TextParameterItem(WidgetParameterItem):
|
||||||
def __init__(self, param, depth):
|
def __init__(self, param, depth):
|
||||||
|
warnings.warn(
|
||||||
|
"This functionality is now handled directly by WidgetParameterItem.",
|
||||||
|
DeprecationWarning, stacklevel=2
|
||||||
|
)
|
||||||
WidgetParameterItem.__init__(self, param, depth)
|
WidgetParameterItem.__init__(self, param, depth)
|
||||||
self.hideWidget = False
|
self.hideWidget = False
|
||||||
self.subItem = QtGui.QTreeWidgetItem()
|
self.subItem = QtGui.QTreeWidgetItem()
|
||||||
@ -661,10 +687,16 @@ class TextParameterItem(WidgetParameterItem):
|
|||||||
self.textBox.setValue = self.textBox.setPlainText
|
self.textBox.setValue = self.textBox.setPlainText
|
||||||
self.textBox.sigChanged = self.textBox.textChanged
|
self.textBox.sigChanged = self.textBox.textChanged
|
||||||
return self.textBox
|
return self.textBox
|
||||||
|
|
||||||
|
|
||||||
class TextParameter(Parameter):
|
class TextParameter(Parameter):
|
||||||
"""Editable string; displayed as large text box in the tree."""
|
"""Editable string; displayed as large text box in the tree."""
|
||||||
itemClass = TextParameterItem
|
itemClass = TextParameterItem
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
warnings.warn(
|
||||||
registerParameterType('text', TextParameter, override=True)
|
"This functionality is now handled directly by SimpleParameter.",
|
||||||
|
DeprecationWarning, stacklevel=2
|
||||||
|
)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# registerParameterType('text', TextParameter, override=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user