Access to the data defined properties was just fixed today (previously caused a crash). Following your example code, you can access it like so (most QgsPalLayerSettings properties are accessed directly):
layer = iface.activeLayer()
palyr = QgsPalLayerSettings()
palyr.readFromLayer(layer)
# get currently set data definitions as dict of
# {QgsPalLayerSettings.DataDefinedProperties: QgsDataDefined}
# e.g. {18: <qgis.core.QgsDataDefined object at 0x1237daa70>, 10: ...}
ddp = palyr.dataDefinedProperties
# get a data definition from those currently set
ddft = None
if QgsPalLayerSettings.FontTransp in ddp:
ddft = ddp[QgsPalLayerSettings.FontTransp]
# or try to get a data definition directly (returns None if not found)
ddfc = palyr.dataDefinedProperty(QgsPalLayerSettings.FontCase)
ddfc_field = ''
if ddfc is not None:
ddfc_field = ddfc.field()
# you can update the data definition as well
ddfc = palyr.dataDefinedProperty(QgsPalLayerSettings.FontCase)
if ddfc:
ddfc.setField('myfield') # which would need to be a valid field
# you can also add a new data definition
if not QgsPalLayerSettings.Size in ddp:
# add an active definition that defines to use an expression of 36
# (i.e. no attribute field is mapped)
palyr.setDataDefinedProperty(QgsPalLayerSettings.Size, True, True, '36', '')
# whenever you update/add/remove a data definition,
# from your QgsPalLayerSettings object, if you want to
# save it to the project instance and see results on canvas
palyr.writeToLayer(layer)
iface.mapCanvas().refresh()
In order to know what DataDefinedProperties enums to use, review the QgsPalLayerSettings docs. Consult the docs on QgsDataDefined to see how to access/manipulate it.