[libadwaita/wip/exalm/accent: 3/13] tmp: Add a button demo
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/accent: 3/13] tmp: Add a button demo
- Date: Fri, 11 Jun 2021 22:19:23 +0000 (UTC)
commit 306d892711a254a3a547e3a3713d9e4828e73a68
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sun May 2 19:03:15 2021 +0500
tmp: Add a button demo
examples/meson.build | 1 +
examples/org.gnome.Adwaita.Demo.json | 2 +-
examples/test.py | 123 +++++++++++++++++++++++++++++++++++
3 files changed, 125 insertions(+), 1 deletion(-)
---
diff --git a/examples/meson.build b/examples/meson.build
index 798b23cf..8de8f253 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -25,4 +25,5 @@ adwaita_demo = executable('adwaita-@0@-demo'.format(apiversion),
install: true,
)
+install_data ('test.py', install_dir: get_option('bindir'))
endif
diff --git a/examples/org.gnome.Adwaita.Demo.json b/examples/org.gnome.Adwaita.Demo.json
index 9b86dd68..d40a2c8f 100644
--- a/examples/org.gnome.Adwaita.Demo.json
+++ b/examples/org.gnome.Adwaita.Demo.json
@@ -3,7 +3,7 @@
"runtime": "org.gnome.Platform",
"runtime-version": "master",
"sdk": "org.gnome.Sdk",
- "command": "adwaita-1-demo",
+ "command": "test.py",
"finish-args": [
"--device=all",
"--share=ipc",
diff --git a/examples/test.py b/examples/test.py
new file mode 100755
index 00000000..c797ce73
--- /dev/null
+++ b/examples/test.py
@@ -0,0 +1,123 @@
+#!/usr/bin/python3
+
+import gi
+
+gi.require_version('Gtk', '4.0')
+gi.require_version('Adw', '1')
+
+from gi.repository import Gtk, Adw
+
+dark = False
+hc = False
+
+def update_theme(widget):
+ s = widget.get_settings()
+ if hc:
+ s.props.gtk_theme_name = 'Adwaita-hc-dark' if dark else 'Adwaita-hc'
+ else:
+ s.props.gtk_theme_name = 'Adwaita-dark' if dark else 'Adwaita'
+
+def toggle_dark_cb(btn):
+ global dark
+ dark = btn.props.active
+ update_theme(btn)
+
+def toggle_high_contrast_cb(btn):
+ global hc
+ hc = btn.props.active
+ update_theme(btn)
+
+def toggle_osd_cb(btn, grid):
+ if btn.props.active:
+ grid.add_css_class('osd')
+ else:
+ grid.remove_css_class('osd')
+
+def create_buttons(grid):
+ STATES = [
+ ('normal', Gtk.StateFlags.NORMAL),
+ ('hover', Gtk.StateFlags.PRELIGHT),
+ ('active', Gtk.StateFlags.PRELIGHT | Gtk.StateFlags.ACTIVE),
+ ('checked', Gtk.StateFlags.CHECKED),
+ ('ch+h', Gtk.StateFlags.CHECKED | Gtk.StateFlags.PRELIGHT),
+ ('ch+a', Gtk.StateFlags.CHECKED | Gtk.StateFlags.PRELIGHT | Gtk.StateFlags.ACTIVE),
+ ('disabled', Gtk.StateFlags.INSENSITIVE),
+ ('dis+ch', Gtk.StateFlags.INSENSITIVE | Gtk.StateFlags.CHECKED),
+ ('drop', Gtk.StateFlags.DROP_ACTIVE),
+ ]
+
+ RELIEF = [None, 'flat', 'outline']
+ COLORS = [None, 'suggested-action', 'destructive-action']
+ classes = [[r, c] for c in COLORS for r in RELIEF]
+ classes = [[c for c in a if c is not None] for a in classes]
+ classes.append(["osd"])
+
+ for j,(n,_) in enumerate(STATES):
+ label = Gtk.Label(label = n, margin_top = 12)
+ label.add_css_class('dim-label')
+ grid.attach(label, j + 1, 0, 1, 1)
+
+ for i,c in enumerate(classes):
+ label = Gtk.Label(label = '.'.join(c), xalign = 1, margin_start = 12)
+ label.add_css_class('dim-label')
+ grid.attach(label, 0, i + 1, 1, 1)
+
+ for j,(_,s) in enumerate(STATES):
+ btn = Gtk.Button(label = 'button', css_classes = c)
+ btn.set_state_flags(s, False)
+ grid.attach(btn, j + 1, i + 1, 1, 1)
+
+ l = len(RELIEF)
+ if i % l == l - 1:
+ btn.props.margin_bottom = 6
+
+ if i == len(classes) - 1:
+ btn.props.margin_bottom = 6
+
+ if j % 3 == 0:
+ btn.props.margin_start = 6
+
+ if j == len(STATES) - 1:
+ btn.props.margin_end = 6
+
+def startup_cb(app):
+ Adw.init()
+
+def activate_cb(app):
+ dark_btn = Gtk.ToggleButton(label = 'Dark')
+ hc_btn = Gtk.ToggleButton(label = 'HC')
+ osd_btn = Gtk.ToggleButton(label = 'OSD')
+
+ header = Gtk.HeaderBar()
+ header.pack_start(dark_btn)
+ header.pack_start(hc_btn)
+ header.pack_start(osd_btn)
+
+ grid = Gtk.Grid(
+ can_target = False,
+ can_focus = False,
+ column_spacing = 6,
+ row_spacing = 6,
+ vexpand = True
+ )
+ create_buttons(grid)
+
+ box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
+ box.append(header)
+ box.append(grid)
+
+ dark_btn.connect('toggled', toggle_dark_cb)
+ hc_btn.connect('toggled', toggle_high_contrast_cb)
+ osd_btn.connect('toggled', toggle_osd_cb, grid)
+
+ win = Adw.ApplicationWindow(
+ application = app,
+ title = 'Buttons',
+ child = box
+ )
+ win.present()
+
+app = Gtk.Application(application_id = 'org.gnome.Adwaita.Demo')
+app.connect('startup', startup_cb)
+app.connect('activate', activate_cb)
+app.run()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]