diff --git a/frappy/modulebase.py b/frappy/modulebase.py index 60856de..2fc0fc9 100644 --- a/frappy/modulebase.py +++ b/frappy/modulebase.py @@ -33,7 +33,7 @@ from frappy.datatypes import ArrayOf, BoolType, EnumType, FloatRange, \ from frappy.errors import BadValueError, CommunicationFailedError, ConfigError, \ ProgrammingError, SECoPError, secop_error, RangeError from frappy.lib import formatException, mkthread, UniqueObject -from frappy.params import Accessible, Command, Parameter, Limit +from frappy.params import Accessible, Command, Parameter, Limit, PREDEFINED_ACCESSIBLES from frappy.properties import HasProperties, Property from frappy.logging import RemoteLogHandler @@ -41,6 +41,7 @@ from frappy.logging import RemoteLogHandler # from .interfaces import SECoP_BASE_CLASSES # WORKAROUND: SECoP_BASE_CLASSES = ['Readable', 'Writable', 'Drivable', 'Communicator'] +PREDEF_ORDER = list(reversed(PREDEFINED_ACCESSIBLES)) Done = UniqueObject('Done') """a special return value for a read_/write_ method @@ -77,7 +78,7 @@ class HasAccessibles(HasProperties): for key, value in base.__dict__.items(): if isinstance(value, Accessible): value.updateProperties(merged_properties.setdefault(key, {})) - if base == cls and key not in accessibles: + if base == cls and key not in accessibles and key not in PREDEFINED_ACCESSIBLES: new_names.append(key) accessibles[key] = value override_values.pop(key, None) @@ -97,17 +98,15 @@ class HasAccessibles(HasProperties): aobj.merge(merged_properties[aname]) accessibles[aname] = aobj - # rebuild order: (1) inherited items, (2) items from paramOrder, (3) new accessibles - # move (2) to the end - paramOrder = cls.__dict__.get('paramOrder', ()) - for aname in paramOrder: - if aname in accessibles: - accessibles.move_to_end(aname) - # ignore unknown names + # rebuild order: + # (1) predefined accessibles, in a predefined order, (2) inherited custom items, (3) new custom items + # move (1) to the beginning + for key in PREDEF_ORDER: + if key in accessibles: + accessibles.move_to_end(key, last=False) # move (3) to the end for aname in new_names: - if aname not in paramOrder: - accessibles.move_to_end(aname) + accessibles.move_to_end(aname) cls.accessibles = accessibles cls.wrappedAttributes = {'isWrapped': True} diff --git a/frappy/params.py b/frappy/params.py index b25147c..b4cb46d 100644 --- a/frappy/params.py +++ b/frappy/params.py @@ -564,15 +564,18 @@ class Limit(Parameter): # list of predefined accessibles with their type +# the order of this list affects the parameter order PREDEFINED_ACCESSIBLES = { 'value': Parameter, 'status': Parameter, 'target': Parameter, 'pollinterval': Parameter, 'ramp': Parameter, - 'user_ramp': Parameter, + 'use_ramp': Parameter, 'setpoint': Parameter, 'time_to_target': Parameter, + 'controlled_by': Parameter, + 'control_active': Parameter, 'unit': Parameter, # reserved name 'loglevel': Parameter, # reserved name 'mode': Parameter, # reserved name diff --git a/test/test_modules.py b/test/test_modules.py index 097b08e..5217cc8 100644 --- a/test/test_modules.py +++ b/test/test_modules.py @@ -141,12 +141,10 @@ def test_ModuleMagic(): # first inherited accessibles - sortcheck1 = ['value', 'status', 'pollinterval', 'target', 'stop', - 'param1', 'param2', 'cmd', 'a1', 'a2', 'cmd2'] + sortcheck1 = ['value', 'status', 'target', 'pollinterval', 'stop', + 'param1', 'param2', 'cmd', 'a1', 'a2', 'cmd2'] class Newclass2(Newclass1): - paramOrder = 'param1', 'param2', 'cmd', 'value' - @Command(description='another stuff') def cmd2(self, arg): return arg @@ -171,9 +169,9 @@ def test_ModuleMagic(): def read_value(self): return 0 - # first inherited items not mentioned, then the ones mentioned in paramOrder, then the other new ones - sortcheck2 = ['status', 'pollinterval', 'target', 'stop', - 'a1', 'a2', 'cmd2', 'param1', 'param2', 'cmd', 'value', 'b2'] + # first predefined parameters, then in the order of inheritance + sortcheck2 = ['value', 'status', 'target', 'pollinterval', 'stop', + 'param1', 'param2', 'cmd', 'a1', 'a2', 'cmd2', 'b2'] updates = {} srv = ServerStub(updates)