Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Fix #707 (stepping in line edits and spin boxes does not work)
Browse files Browse the repository at this point in the history
The step up/down feature of TaurusValueLineEdit (e.g. using
the up/down keys or the arrows of a TaurusValueSpinBox) was broken when
merging #669 which implemented fragments support in
TaurusValueLineEdit for allowing the display of the wvalue without units
Now we see that supporting fragments generically in TaurusValueLineEdit
is problematic (e.g. it makes little sense to use "rvalue" as a
fragment since "wvalue" will be modified when eventually applying).
Therefore for now limit the fragment support in line edits
to the "wvalue.magnitude" case.

Also fix a hook error introduced in some previous merge.
  • Loading branch information
cpascual committed Feb 28, 2018
1 parent 9d84b3c commit 72ecf52
Showing 1 changed file with 17 additions and 35 deletions.
52 changes: 17 additions & 35 deletions lib/taurus/qt/qtgui/input/tauruslineedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,20 @@ def handleEvent(self, evt_src, evt_type, evt_value):
# handle the case in which the line edit is not yet initialized
if self._last_value is None:
try:
self.getModelObj().read(cache=True)
frag_name = self.modelFragmentName or 'wvalue'
value = self.getModelFragmentObj(fragmentName=frag_name)
self.debug('Overwriting wvalue=None with %s' % (value))
self.setValue(value)
self.setEnabled(value is not None)
value = self.getModelObj().read(cache=True)
self._updateValidator(value)
self.setValue(value.wvalue)
except Exception as e:
self.debug('Failed attempt to initialize value: %r', e)
self.info('Failed attempt to initialize value: %r', e)

self.setEnabled(evt_type != TaurusEventType.Error)

if evt_type in (TaurusEventType.Change, TaurusEventType.Periodic):
self._updateValidator(evt_value)

TaurusBaseWritableWidget.handleEvent(
self, evt_src, evt_type, evt_value)

if evt_type == TaurusEventType.Error:
self.updateStyle()

Expand Down Expand Up @@ -215,36 +215,18 @@ def _stepBy(self, v):
value = self.getValue()
self.setValue(value + Quantity(v, value.units))

def getDisplayValue(self, cache=True, fragmentName=None):
"""Returns a string representation of the model value associated with
this component. As this is a writable widget, if there is no fragment
specified, the default behaviour is to display the wvalue.
:param cache: (bool) (ignored, just for bck-compat).
:param fragmentName: (str or None) the returned value will correspond
to the given fragmentName. If None passed,
self.modelFragmentName will be used, and if None is
set, the defaultFragmentName of the model will be used
instead.
:return: (str) a string representation of the model value.
"""
if fragmentName is None and self.modelFragmentName is None:
return TaurusBaseWritableWidget.getDisplayValue(
self, cache=cache, fragmentName='wvalue')
else:
return TaurusBaseWritableWidget.getDisplayValue(
self, cache=cache, fragmentName=fragmentName)

def setValue(self, v):
model = self.getModelObj()
if model is None:
v_str = str(v)
else:
v_str = str(self.getDisplayValue(v))
v_str = v_str.strip()
"""Set the displayed text from a given value object"""
# Support displaying the value without units (enabled by fragment)
# Other fragments are ignored by setValue
if self.modelFragmentName == "wvalue.magnitude":
try:
units = self.validator().units
v = v.to(units).magnitude
except Exception as e:
self.debug('Cannot enforce fragment. Reason: %r', e)
self._last_value = v
self.setText(v_str)
self.setText(str(self.displayValue(v)).strip())

def getValue(self):
text = self.text()
Expand Down

0 comments on commit 72ecf52

Please sign in to comment.