Debian Codegraph @

examples/kwrite.py

raw
1 #!/usr/bin/env python3
2 # Dogtail demo script using KWrite (QT / KDE)
3 __author__ = "Max Gaukler <[email protected]>"
4
5 # SPDX-License-Identifier: CC0-1.0
6 # To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
7 # You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
8
9 from dogtail import tree
10 from dogtail.predicate import *
11 import subprocess
12 import time
13
14 # Start the KWrite application with English localization and enabled accessibility.
15 # (see also: dogtail.utils.run())
16 # For other languages, you would have to change the texts in this script.
17 subprocess.Popen("LANG=C QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1 kwrite", shell=True)
18
19 # Connect
20 app = tree.root.application("kwrite")
21
22 # Show all elements
23 app.dump()
24
25 # Open the "About KDE" dialog and close it again.
26
27 # Note that to open a sub-menu entry, you must first open the corresponding main menu entry.
28 app.child("Help").click()
29 app.child("About KDE").click()
30 # Most of the time, .child() is good enough. If the label is not unique, you can create a more specific search
31 # - by type (.dialog, .button, ...) and by nesting items
32 # - or by other attributes (roleName, ...)
33 app.dialog("About KDE").button("Close").click()
34
35 # Check that the dialog is gone
36 time.sleep(1)
37 assert not app.isChild(IsADialogNamed("About KDE"))
38
39 # Write something into the text of the new file
40 t = app.child(roleName="text")
41 assert t.text == ""
42 t.set_text_contents("Hello World")
43 assert t.text == "Hello World"
44
45
46 # File -> Quit -> Discard
47 app.child("File").click()
48 app.child("File").child("Quit").click()
49 app.dialog("Close Document").child("Discard").click()