Skip to content

Commit 5b459e0

Browse files
authored
Library: Port 'Text Fields' to Python (#734)
1 parent 43bb5d3 commit 5b459e0

File tree

1 file changed

+102
-0
lines changed
  • src/Library/demos/Text Fields

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
gi.require_version("Adw", "1")
5+
from gi.repository import Gtk, Adw
6+
import workbench
7+
8+
entry: Gtk.Entry = workbench.builder.get_object("entry")
9+
entry_placeholder: Gtk.Entry = workbench.builder.get_object("entry_placeholder")
10+
entry_icon: Gtk.Entry = workbench.builder.get_object("entry_icon")
11+
entry_progress: Gtk.Entry = workbench.builder.get_object("entry_progress")
12+
13+
entry.connect(
14+
"activate", lambda _: print(f'Regular Entry: "{entry.get_text()}" entered')
15+
)
16+
17+
entry_placeholder.connect(
18+
"activate",
19+
lambda _: print(f'Placeholder Entry: "{entry_placeholder.get_text()}" entered'),
20+
)
21+
22+
entry_icon.connect(
23+
"activate", lambda _: print(f'Icon Entry: "{entry_icon.get_text()}" entered')
24+
)
25+
26+
entry_icon.connect("icon-press", lambda _, __: print("Icon Pressed!"))
27+
28+
entry_icon.connect("icon-release", lambda _, __: print("Icon Released!"))
29+
30+
entry_progress.connect(
31+
"activate",
32+
lambda _: print(f'Progress Bar Entry: "{entry_progress.get_text()}" entered'),
33+
)
34+
35+
entry_progress.connect("icon-press", lambda _, __: animation.play())
36+
37+
target = Adw.PropertyAnimationTarget.new(
38+
entry_progress,
39+
"progress-fraction",
40+
)
41+
42+
animation = Adw.TimedAnimation(
43+
widget=entry_progress,
44+
value_from=0,
45+
value_to=1,
46+
duration=2000,
47+
easing=Adw.Easing.LINEAR,
48+
target=target,
49+
)
50+
51+
animation.connect("done", lambda _: animation.reset())
52+
53+
entry_completion: Gtk.Entry = workbench.builder.get_object("entry_completion")
54+
completion = Gtk.EntryCompletion()
55+
56+
entry_completion.set_completion(completion)
57+
58+
list_store = Gtk.ListStore.new([str])
59+
words = ("a", "app", "apple", "apples", "applets", "application")
60+
for word in words:
61+
list_store.append([word])
62+
completion.set_model(list_store)
63+
64+
completion.set_text_column(0)
65+
completion.set_inline_completion(True)
66+
completion.set_inline_selection(True)
67+
68+
entry_password: Gtk.PasswordEntry = workbench.builder.get_object("entry_password")
69+
entry_confirm_password: Gtk.PasswordEntry = workbench.builder.get_object(
70+
"entry_confirm_password",
71+
)
72+
label_password: Gtk.Label = workbench.builder.get_object("label_password")
73+
74+
entry_password.connect(
75+
"activate",
76+
lambda _: label_password.set_label(
77+
validate_password(
78+
entry_password.get_text(),
79+
entry_confirm_password.get_text(),
80+
)
81+
),
82+
)
83+
84+
entry_confirm_password.connect(
85+
"activate",
86+
lambda _: label_password.set_label(
87+
validate_password(
88+
entry_password.get_text(),
89+
entry_confirm_password.get_text(),
90+
)
91+
),
92+
)
93+
94+
95+
def validate_password(passwd, confirm_passwd):
96+
if passwd and confirm_passwd:
97+
if passwd == confirm_passwd:
98+
return "Password made successfully!"
99+
else:
100+
return "Both fields should be matching!"
101+
else:
102+
return "Both fields are mandatory!"

0 commit comments

Comments
 (0)