Exemplo n.º 1
0
    def locations_event(self):
        root = self.window()
        path = qtpath.abspath(root, self)

        self.locations_signal.emit(path)
Exemplo n.º 2
0
    def locations_event(self):
        root = self.window()
        path = qtpath.abspath(root, self)

        pubsub.pub.sendMessage('locations', path=path)
Exemplo n.º 3
0
if __name__ == '__main__':
    import sys

    # Set-up PyQt application
    app = QtWidgets.QApplication(sys.argv)
    win = Demo()

    # How we would normally find `Button` within `Demo`
    find_button = win.findChild(QtWidgets.QPushButton, 'Button')

    # Get an instance from `Demo` by serialised path
    button = qtpath.instance(win, '/Body.QWidget/Button.QPushButton')
    button = qtpath.instance(win, '/Button.QPushButton')
    assert find_button == button

    # Get back the serialised path from instance.
    assert qtpath.abspath(win, button) == '/Win.Demo/Button.QPushButton'

    # A path may return nothing
    missing = qtpath.instance(win, '/Body.QWidget/Checkbox.QWidget')
    assert missing is None

    # findPath searches a hierarchy, regardless of proximity to root
    # The following will return `Button` closest to `Win`, there is no
    # way to directly reference the nested `Button`.
    button = win.findChild(QtWidgets.QPushButton, 'Button')
    assert button.parent() == win

    button = qtpath.instance(win, '/Body.QWidget/Button.QPushButton')
    assert button is not find_button