Skip to content

Commit 35a3a70

Browse files
authored
Library: Port 'Account' to Python (#817)
1 parent dbd5db9 commit 35a3a70

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/Library/demos/Account/main.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import gi
2+
3+
gi.require_version("Xdp", "1.0")
4+
gi.require_version("XdpGtk4", "1.0")
5+
from gi.repository import Gdk, Gio, Xdp, XdpGtk4
6+
import workbench
7+
8+
portal = Xdp.Portal()
9+
parent = XdpGtk4.parent_new_gtk(workbench.window)
10+
11+
revealer = workbench.builder.get_object("revealer")
12+
button = workbench.builder.get_object("button")
13+
avatar = workbench.builder.get_object("avatar")
14+
entry = workbench.builder.get_object("entry")
15+
username = workbench.builder.get_object("username")
16+
display = workbench.builder.get_object("name")
17+
18+
19+
def on_information_recieved(_portal, result):
20+
result = portal.get_user_information_finish(result)
21+
22+
"""
23+
result is a GVariant dictionary containing the following fields
24+
id (s): the user ID
25+
name (s): the users real name
26+
image (s): the uri of an image file for the users avatar picture
27+
"""
28+
29+
user_info = result
30+
id = user_info["id"]
31+
name = user_info["name"]
32+
uri = user_info["image"]
33+
file = Gio.File.new_for_uri(uri)
34+
texture = Gdk.Texture.new_from_file(file)
35+
36+
username.set_label(id)
37+
display.set_label(name)
38+
avatar.set_custom_image(texture)
39+
revealer.set_reveal_child(True)
40+
41+
entry.set_text("")
42+
print("Information retrieved")
43+
44+
45+
def on_clicked(_button):
46+
reason = entry.get_text()
47+
portal.get_user_information(
48+
parent, reason, Xdp.UserInformationFlags.NONE, None, on_information_recieved
49+
)
50+
51+
52+
button.connect("clicked", on_clicked)

0 commit comments

Comments
 (0)