Skip to content

Commit

Permalink
Improved edit widget layout
Browse files Browse the repository at this point in the history
gui/pipeline_view.py:
 - computeBoundingRect:
   Simplified the way rects are combined
   The default layout should still be the same

core/theme.py:
  New attribute MODULE_EDIT_MARGIN

Fixed issue with contentsChanged in ConstantWidgetMixin subclasses,
the type was wrong, (object, str) -> (tuple):
  gui/modules/constant_configuration.py
  gui/mashups/mashups_widgets.py
  packages/vtk/tf_widget.py

Added missing contentsChanged attributes:
  packages/persistence/widgets.py
  packages/webServices/enumeration_widget.py
  • Loading branch information
rexissimus committed Oct 1, 2014
1 parent 3a77745 commit 992a337
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 97 deletions.
3 changes: 3 additions & 0 deletions vistrails/core/theme.py
Expand Up @@ -63,6 +63,9 @@ def __init__(self):
# Padded space of Module shape into its label
self.MODULE_LABEL_MARGIN = (20, 20, 20, 15)

# Padded space of Module shape into its edit widget
self.MODULE_EDIT_MARGIN = (8, 4, 8, 4)

# Margin of Module shape into its ports
self.MODULE_PORT_MARGIN = (4, 4, 4, 4)

Expand Down
4 changes: 2 additions & 2 deletions vistrails/gui/mashups/mashups_widgets.py
Expand Up @@ -77,7 +77,7 @@ def focusOutEvent(self, event):
###############################################################################

class QSliderWidget(ConstantWidgetMixin, QtGui.QSlider):
contentsChanged = QtCore.pyqtSignal(object, object)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
QtGui.QSlider.__init__(self, QtCore.Qt.Horizontal, parent)
ConstantWidgetMixin.__init__(self, param.strValue)
Expand Down Expand Up @@ -210,7 +210,7 @@ def change_val(self, newval):
###############################################################################

class QNumericStepperFloatWidget(ConstantWidgetMixin, QtGui.QDoubleSpinBox):
contentsChanged = QtCore.pyqtSignal(object, object)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
QtGui.QDoubleSpinBox.__init__(self, parent)
ConstantWidgetMixin.__init__(self, param.strValue)
Expand Down
20 changes: 10 additions & 10 deletions vistrails/gui/modules/constant_configuration.py
Expand Up @@ -60,7 +60,7 @@ def setPlaceholderTextCompat(self, value):
class ConstantWidgetMixin(object):

# superclasses need to add this signal:
# contentsChanged = QtCore.pyqtSignal(object, str)
# contentsChanged = QtCore.pyqtSignal(tuple)

def __init__(self, contents=None):
if not hasattr(self, 'contentsChanged'):
Expand All @@ -75,7 +75,7 @@ def update_parent(self):
if self.parent() and hasattr(self.parent(), 'updateMethod'):
self.parent().updateMethod()
self._last_contents = newContents
self.contentsChanged.emit(self, newContents)
self.contentsChanged.emit((self, newContents))

class ConstantWidgetBase(ConstantWidgetMixin):
def __init__(self, param):
Expand Down Expand Up @@ -148,7 +148,7 @@ def setNonEmpty(self, is_non_empty):
pass

class StandardConstantWidget(QtGui.QLineEdit,ConstantWidgetBase):
contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
QtGui.QLineEdit.__init__(self, parent)
ConstantWidgetBase.__init__(self, param)
Expand Down Expand Up @@ -179,7 +179,7 @@ def setDefault(self, value):
setPlaceholderTextCompat(self, value)

class StandardConstantEnumWidget(QtGui.QComboBox, ConstantEnumWidgetBase):
contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
QtGui.QComboBox.__init__(self, parent)
ConstantEnumWidgetBase.__init__(self, param)
Expand Down Expand Up @@ -227,7 +227,7 @@ def setDefault(self, value):
# Multi-line String Widget

class MultiLineStringWidget(QtGui.QTextEdit, ConstantWidgetBase):
contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
QtGui.QTextEdit.__init__(self, parent)
self.setAcceptRichText(False)
Expand Down Expand Up @@ -261,7 +261,7 @@ class PathChooserWidget(QtGui.QWidget, ConstantWidgetMixin):
selected.
"""
contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
"""__init__(param: core.vistrail.module_param.ModuleParam,
parent: QWidget)
Expand Down Expand Up @@ -349,7 +349,7 @@ class BooleanWidget(QtGui.QCheckBox, ConstantWidgetBase):
_values = ['True', 'False']
_states = [QtCore.Qt.Checked, QtCore.Qt.Unchecked]

contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
"""__init__(param: core.vistrail.module_param.ModuleParam,
parent: QWidget)
Expand Down Expand Up @@ -380,7 +380,7 @@ def change_state(self, state):
# FIXME ColorChooserButton remains because the parameter exploration
# code uses it, really should be removed at some point
class ColorChooserButton(QtGui.QPushButton):
contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, parent=None):
QtGui.QPushButton.__init__(self, parent)
# self.setFrameStyle(QtGui.QFrame.Box | QtGui.QFrame.Plain)
Expand Down Expand Up @@ -465,7 +465,7 @@ def openChooser(self):
self.setColor(qcolor)

class ColorWidget(QColorWidget, ConstantWidgetBase):
contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
QColorWidget.__init__(self, parent)
ConstantWidgetBase.__init__(self, param)
Expand All @@ -478,7 +478,7 @@ def setContents(self, strValue, silent=True):
self.setColorString(strValue, silent)

class ColorEnumWidget(QColorWidget, ConstantEnumWidgetBase):
contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
QColorWidget.__init__(self, parent)
self.setPopupMode(QtGui.QToolButton.MenuButtonPopup)
Expand Down
175 changes: 91 additions & 84 deletions vistrails/gui/pipeline_view.py
Expand Up @@ -1213,50 +1213,54 @@ def setProgress(self, progress):

def computeBoundingRect(self):
""" computeBoundingRect() -> None
Adjust the module size according to the text size
Adjust the module size according to contents
"""
width = 0
height = CurrentTheme.MODULE_LABEL_MARGIN[1]
# for each rect: Add height, adjust min width,
# set pos to distance to top middle corner, to be adjusted when
# paddedRect is known
labelRect = self.labelFontMetric.boundingRect(self.label)
labelRect.setHeight(labelRect.height()+1) # fix cut off bottoms
labelRect.moveTo(-labelRect.width()/2, height)
height += labelRect.height()
padding = labelRect.adjusted(-CurrentTheme.MODULE_LABEL_MARGIN[0], 0,
CurrentTheme.MODULE_LABEL_MARGIN[2], 0)
width = max(width, padding.width())

if self.description:
self.description = '(' + self.description + ')'
descRect = self.descFontMetric.boundingRect(self.description)
# adjust labelRect in case descRect is wider
labelRect = labelRect.united(descRect)
descRect.adjust(0, 0, 0, CurrentTheme.MODULE_PORT_MARGIN[3])
else:
descRect = QtCore.QRectF(0, 0, 0, 0)

edit_width = int(self.edit_rect.width()) + 4
if edit_width:
labelRect = labelRect.united(
QtCore.QRect(0, 0,
int(edit_width) -
CurrentTheme.MODULE_LABEL_MARGIN[0]*2, 0))

labelRect.translate(-labelRect.center().x(), -labelRect.center().y())
self.paddedRect = QtCore.QRectF(
labelRect.adjusted(-CurrentTheme.MODULE_LABEL_MARGIN[0],
-CurrentTheme.MODULE_LABEL_MARGIN[1]
-descRect.height()/2-self.edit_rect.height()/2,
CurrentTheme.MODULE_LABEL_MARGIN[2],
CurrentTheme.MODULE_LABEL_MARGIN[3]
+descRect.height()/2+self.edit_rect.height()/2))

self.labelRect = QtCore.QRectF(
self.paddedRect.left(),
-(labelRect.height()+descRect.height()+self.edit_rect.height())/2,
self.paddedRect.width(),
labelRect.height())
self.descRect = QtCore.QRectF(
self.paddedRect.left(),
self.labelRect.bottom(),
self.paddedRect.width(),
descRect.height())
self.editRect = QtCore.QRectF(
self.paddedRect.left()+2,
self.descRect.bottom(),
self.paddedRect.width(),
self.edit_rect.height())
descRect.moveTo(-descRect.width()/2, height)
height += descRect.height()
padding = descRect.adjusted(-CurrentTheme.MODULE_LABEL_MARGIN[0], 0,
CurrentTheme.MODULE_LABEL_MARGIN[2], 0)
width = max(width, padding.width())

if self.edit_rect.height():
height += CurrentTheme.MODULE_EDIT_MARGIN[1] # top margin
editRect = self.edit_rect
editRect.moveTo(-editRect.width()/2, height)
height += editRect.height()
padding = editRect.adjusted(-CurrentTheme.MODULE_EDIT_MARGIN[0], 0,
CurrentTheme.MODULE_EDIT_MARGIN[2], 0)
width = max(width, padding.width())
height += CurrentTheme.MODULE_EDIT_MARGIN[3] # bottom edit margin

height += CurrentTheme.MODULE_LABEL_MARGIN[3] # bottom margin

# move to final position

self.paddedRect = QtCore.QRectF(-width/2, -height/2, width, height)
labelRect.translate(0, -height/2)
self.labelRect = labelRect
if self.description:
descRect.translate(0, -height/2)
self.descRect = descRect
if self.edit_rect.height():
editRect.translate(0, -height/2)
self.editRect = editRect
self.abstRect = QtCore.QRectF(
self.paddedRect.left(),
-self.labelRect.top()-CurrentTheme.MODULE_PORT_MARGIN[3],
Expand Down Expand Up @@ -1466,44 +1470,44 @@ def setupModule(self, module, read_only=False):
self.description = ''

if module.is_valid and not read_only and get_module_registry(
).is_constant_module(self.module.module_descriptor.module):
desc = self.module.module_descriptor
Widget = get_widget_class(desc)
self.edit_widget = Widget
param = Parameter(desc)
for function in self.module.functions:
if function.name == 'value':
param = function.parameters[0]
if hasattr(Widget, 'GraphicsItem'):
self.value_edit = Widget.GraphicsItem(param, self)
# resize to 150
rect = self.value_edit.boundingRect()
self.value_edit.setZValue(self.zValue()+0.2)
bg = QtGui.QGraphicsRectItem(rect, self.value_edit)
# TODO COLOR
bg.setBrush(QtGui.QBrush(QtGui.QColor('#FFFFFF')))
bg.setZValue(-1)
scale = max(rect.width(), rect.height())
transform = self.value_edit.transform()
# transfer function needs to be inverted right now
transform.scale(150.0/scale,-150.0/scale)
transform.translate(0, -rect.height())
self.value_edit.setTransform(transform)
rect.setSize(rect.size()*150.0/scale)
rect.setHeight(rect.height()+5)
self.edit_rect = rect
else:
self.value_edit = Widget(param)
self.value_edit.setMaximumSize(150, 150)
proxy = QtGui.QGraphicsProxyWidget(self)
proxy.setWidget(self.value_edit)
rect = proxy.boundingRect()
rect.moveTo(0.0,0.0)
rect.setHeight(rect.height()+5)
self.edit_rect = rect
self.value_edit.connect(self.value_edit,
QtCore.SIGNAL('contentsChanged'),
self.value_changed)
).is_constant_module(self.module.module_descriptor.module):
desc = self.module.module_descriptor
Widget = get_widget_class(desc)
self.edit_widget = Widget
param = Parameter(desc)
for function in self.module.functions:
if function.name == 'value':
param = function.parameters[0]
if hasattr(Widget, 'GraphicsItem'):
self.value_edit = Widget.GraphicsItem(param, self)
# resize to 150
rect = self.value_edit.boundingRect()
self.value_edit.setZValue(self.zValue()+0.2)
bg = QtGui.QGraphicsRectItem(rect, self.value_edit)
# TODO COLOR
bg.setBrush(QtGui.QBrush(QtGui.QColor('#FFFFFF')))
bg.setZValue(-1)
scale = max(rect.width(), rect.height())
transform = self.value_edit.transform()
# transfer function needs to be inverted right now
transform.scale(150.0/scale,-150.0/scale)
transform.translate(0, -rect.height())
self.value_edit.setTransform(transform)
rect.setSize(rect.size()*150.0/scale)
rect.setHeight(rect.height()+4)
self.edit_rect = rect
else:
SCALE = 3.0/4
self.value_edit = Widget(param)
self.value_edit.setMaximumSize(150.0/SCALE, 150.0/SCALE)
proxy = QtGui.QGraphicsProxyWidget(self)
proxy.setWidget(self.value_edit)
proxy.setScale(SCALE)
rect = self.value_edit.geometry() #proxy.boundingRect()
rect.setSize(rect.size()*SCALE)# uninitialized bounds need to be scaled
rect.moveTo(0.0,0.0)
self.edit_rect = rect
self.value_edit.contentsChanged.connect(self.value_changed)

if module.is_valid and not read_only and not get_module_registry(
).is_constant_module(self.module.module_descriptor.module) and \
Expand Down Expand Up @@ -3354,8 +3358,9 @@ def __init__(self, function, parent=None):
self.function = function
self.param_widgets = []
self.bounds = None
width = 150
width = 150.0
height = 0
SCALE = 3.0/4
for i in xrange(len(function.parameters)):
param = function.parameters[i]
Widget = get_widget_class(function.get_spec('input').items[i].descriptor)
Expand All @@ -3371,27 +3376,29 @@ def __init__(self, function, parent=None):
scale = max(rect.width(), rect.height())
transform = param_widget.transform()
# transfer function needs to be inverted right now
transform.scale(150.0/scale,-150.0/scale)
transform.scale(width/scale,-width/scale)
transform.translate(0, -rect.height())
param_widget.setTransform(transform)
rect.setSize(rect.size()*150.0/scale)
rect.setSize(rect.size()*width/scale)
param_widget.setPos(0, height)
else:
param_widget = Widget(param)
param_widget.setMaximumSize(150, 150)
param_widget.setMaximumSize(width/SCALE, width/SCALE)
proxy = QtGui.QGraphicsProxyWidget(self)
proxy.setWidget(param_widget)
rect = proxy.boundingRect()
proxy.setScale(SCALE)
rect = param_widget.geometry() #proxy.boundingRect()
rect.setSize(rect.size()*SCALE)# uninitialized bounds need to be scaled
rect.moveTo(0.0,0.0)
proxy.setPos(0, height)
rect.setHeight(rect.height()+5)
rect.setHeight(rect.height())
height += rect.height()
param_widget.contentsChanged.connect(self.param_changed)
self.param_widgets.append(param_widget)

self.bounds = QtCore.QRectF(0.0, 0.0, 150.0, height)
self.bounds = QtCore.QRectF(0.0, 0.0, width, height)

def param_changed(self, widget, values):
def param_changed(self, values):
# get values from all parameters
values = [p.contents() for p in self.param_widgets]
self.function_changed.emit(self.function.name, values)
Expand Down
1 change: 1 addition & 0 deletions vistrails/packages/persistence/widgets.py
Expand Up @@ -985,6 +985,7 @@ def __init__(self, module, controller, parent=None, path_type=None):
False, path_type)

class PersistentRefInlineWidget(QtGui.QWidget, ConstantWidgetMixin):
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
self.param = param
self.strValue = param.strValue
Expand Down
2 changes: 1 addition & 1 deletion vistrails/packages/vtk/tf_widget.py
Expand Up @@ -499,7 +499,7 @@ def mousePressEvent(self, event):
# Scene, view, widget

class QGraphicsTransferFunction(QtGui.QGraphicsWidget, ConstantWidgetMixin):
contentsChanged = QtCore.pyqtSignal(object, str)
contentsChanged = QtCore.pyqtSignal(tuple)
def __init__(self, param, parent=None):
QtGui.QGraphicsWidget.__init__(self, parent)
ConstantWidgetMixin.__init__(self, param.strValue)
Expand Down
1 change: 1 addition & 0 deletions vistrails/packages/webServices/enumeration_widget.py
Expand Up @@ -45,6 +45,7 @@
import vistrails.packages.webServices

class EnumerationWidget(QtGui.QComboBox, ConstantWidgetMixin):
contentsChanged = QtCore.pyqtSignal(tuple)
enumerationlist = []
def __init__(self, param, parent=None):
"""__init__(param: core.vistrail.module_param.ModuleParam,
Expand Down

0 comments on commit 992a337

Please sign in to comment.