Skip to content

Commit 7fb8191

Browse files
authored
More Python demos (#714)
* Library: Port 'Styling with CSS' to Python * Library: Port 'Breakpoints' to Python * Library: Port 'Overlay' to Python * Library: Port 'Popovers' to Python * Library: Port 'Emoji Chooser' to Python * Library: Port 'Image' to Python * Library: Port 'Separator' to Python * Library: Port 'Menu Button' to Python * Library: Port 'Radio Buttons' to Python * Library: Port 'Link Button' to Python
1 parent 1f22d7b commit 7fb8191

File tree

10 files changed

+141
-0
lines changed

10 files changed

+141
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
breakpoint: Adw.Breakpoint = workbench.builder.get_object("breakpoint")
9+
10+
breakpoint.connect("apply", lambda _widget: print("Breakpoint Applied"))
11+
breakpoint.connect("unapply", lambda _widget: print("Breakpoint Unapplied"))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
from gi.repository import Gtk
5+
import workbench
6+
7+
emoji_chooser: Gtk.EmojiChooser = workbench.builder.get_object("emoji_chooser")
8+
button: Gtk.Button = workbench.builder.get_object("button")
9+
10+
emoji_chooser.connect("emoji-picked", lambda _chooser, emoji: button.set_label(emoji))

src/Library/demos/Image/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
gi.require_version("Gio", "2.0")
5+
from gi.repository import Gtk, Gio
6+
import workbench
7+
8+
path: Gio.File = Gio.File.new_for_uri(workbench.resolve("workbench.png")).get_path()
9+
10+
workbench.builder.get_object("icon1").set_from_file(path)
11+
workbench.builder.get_object("icon2").set_from_file(path)
12+
workbench.builder.get_object("icon3").set_from_file(path)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
from gi.repository import Gtk
5+
import workbench
6+
7+
linkbutton: Gtk.LinkButton = workbench.builder.get_object("linkbutton")
8+
9+
10+
def on_activate_link(button: Gtk.LinkButton):
11+
print(f"About to activate {button.get_uri()}")
12+
13+
# Return True if handling the link manually, or
14+
# False to let the default behavior continue
15+
return False
16+
17+
18+
linkbutton.connect(
19+
"notify::visited", lambda _widget, _params: print("The link has been visited")
20+
)
21+
linkbutton.connect("activate-link", on_activate_link)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
circular_switch: Adw.SwitchRow = workbench.builder.get_object("circular_switch")
9+
secondary_button: Gtk.MenuButton = workbench.builder.get_object("secondary")
10+
11+
12+
def update_css(_widget, _params):
13+
if circular_switch.get_active():
14+
secondary_button.add_css_class("circular")
15+
else:
16+
secondary_button.remove_css_class("circular")
17+
18+
19+
circular_switch.connect("notify::active", update_css)
20+

src/Library/demos/Overlay/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
gi.require_version("Gio", "2.0")
5+
from gi.repository import Gtk, Gio
6+
import workbench
7+
8+
file: Gio.File = Gio.File.new_for_uri(workbench.resolve("./image.png"))
9+
10+
picture: Gtk.Picture = workbench.builder.get_object("picture")
11+
picture.set_file(file)

src/Library/demos/Popovers/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
from gi.repository import Gtk
5+
import workbench
6+
7+
8+
def onClosed(popover):
9+
name = popover.get_name()
10+
print(f"{name} closed.")
11+
12+
13+
popover_ids = ("plain_popover", "popover_menu")
14+
15+
for id in popover_ids:
16+
popover = workbench.builder.get_object(id)
17+
popover.connect("closed", onClosed)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
from gi.repository import Gtk
5+
import workbench
6+
7+
radio_button_1: Gtk.CheckButton = workbench.builder.get_object("radio_button_1")
8+
radio_button_2: Gtk.CheckButton = workbench.builder.get_object("radio_button_2")
9+
10+
radio_button_1.connect("toggled", lambda widget: on_toggled(widget, "Force Light Mode"))
11+
radio_button_2.connect("toggled", lambda widget: on_toggled(widget, "Force Dark Mode"))
12+
13+
14+
def on_toggled(radio_button: Gtk.CheckButton, message):
15+
if radio_button.get_active():
16+
print(message)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
gi.require_version("Gio", "2.0")
5+
from gi.repository import Gtk, Gio
6+
import workbench
7+
8+
picture_one: Gtk.Picture = workbench.builder.get_object("picture_one")
9+
picture_two: Gtk.Picture = workbench.builder.get_object("picture_two")
10+
11+
file: Gio.File = Gio.File.new_for_uri(workbench.resolve("./image.png"))
12+
13+
picture_one.set_file(file)
14+
picture_two.set_file(file)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "4.0")
4+
from gi.repository import Gtk
5+
import workbench
6+
7+
basic_label: Gtk.Label = workbench.builder.get_object("basic_label")
8+
9+
basic_label.add_css_class("css_text")

0 commit comments

Comments
 (0)