~3v1n0/autopilot/badwindow-errors-protect

« back to all changes in this revision

Viewing changes to autopilot/introspection/dbus.py

Allow Custom Proxy Object classes to have a different name to that of the underlying UI Type. Fixes: https://bugs.launchpad.net/bugs/1337004.

Approved by PS Jenkins bot, Max Brustkern.

Show diffs side-by-side

added added

removed removed

Lines of Context:
544
544
        class_name = cls.__name__.encode('utf-8')
545
545
        return state_name == class_name
546
546
 
 
547
    @classmethod
 
548
    def get_type_query_name(cls):
 
549
        """Return the Type node name to use within the search query.
 
550
 
 
551
        This allows for a Custom Proxy Object to be named differently to the
 
552
        underlying node type name.
 
553
 
 
554
        For instance if you have a QML type defined in the file RedRect.qml::
 
555
 
 
556
            import QtQuick 2.0
 
557
            Rectangle {
 
558
                color: red;
 
559
            }
 
560
 
 
561
        You can then define a Custom Proxy Object  for this type like so::
 
562
 
 
563
        class RedRect(DBusIntrospectionObject):
 
564
            @classmethod
 
565
            def get_type_query_name(cls):
 
566
                return 'QQuickRectangle'
 
567
 
 
568
        This is due to the qml engine storing 'RedRect' as a QQuickRectangle in
 
569
        the UI tree and the xpathquery query needs a node type to query for.
 
570
        By default the query will use the class name (in this case RedRect) but
 
571
        this will not match any node type in the tree.
 
572
 
 
573
        """
 
574
 
 
575
        return cls.__name__
 
576
 
547
577
 
548
578
# TODO - can we add a deprecation warning around this somehow?
549
579
CustomEmulatorBase = DBusIntrospectionObject
557
587
 
558
588
    """
559
589
    if not isinstance(maybe_string_or_class, str):
560
 
        return maybe_string_or_class.__name__
 
590
        return _get_class_type_name(maybe_string_or_class)
561
591
    return maybe_string_or_class
 
592
 
 
593
 
 
594
def _get_class_type_name(maybe_cpo_class):
 
595
    if hasattr(maybe_cpo_class, 'get_type_query_name'):
 
596
        return maybe_cpo_class.get_type_query_name()
 
597
    else:
 
598
        return maybe_cpo_class.__name__