Comments (12)
Thank you for your hekp
from cl-gtk4.
https://docs.gtk.org/gobject/concepts.html#object-instantiation
from cl-gtk4.
https://docs.gtk.org/gtk4/class.Builder.html#property-bindings
builder may have a clue, tomorrow I will see if I can use that to create the objects I want
from cl-gtk4.
Sorry, I can't think of a scenario where you would directly create a GObject. If you want to create a subclass object of GObject from another GObject, you can use gobj:coerce
to achieve that.
from cl-gtk4.
I suspect the GTK4 documentation is not precise, and I do not need an instance of Gobject, but an instance of a class that inherits from Gobject. The bindings provide such functions so it is a matter of finding how to make something similar work in Lisp.
https://stackoverflow.com/questions/66509574/gio-menu-items-always-disabled-for-boolean-actions
from cl-gtk4.
https://gtk-rs.org/gtk4-rs/stable/latest/book/actions.html
This appears to be closest to what I want.
from cl-gtk4.
I guess this might be the example you're looking for:
(define-application (:name stateful-menu
:id "org.bohonghuang.gtk4-example.stateful-menu")
(defun stateful-menu-menu ()
(let ((menu (gio:make-menu)))
(let ((submenu (gio:make-menu)))
(gio:menu-append-item submenu (gio:make-menu-item :model menu :label "Fullscreen" :detailed-action "app.fullscreen"))
(gio:menu-append-item submenu (gio:make-menu-item :model menu :label "Always On Top" :detailed-action "app.always-on-top"))
(gio:menu-append-submenu menu "Window" submenu))
(let ((submenu (gio:make-menu)))
(gio:menu-append-item submenu (let ((item (gio:make-menu-item :model menu :label "Light" :detailed-action "app.color-scheme")))
(setf (gio:menu-item-action-and-target-value item) (list "app.color-scheme" (glib:make-string-variant :string "LIGHT")))
item))
(gio:menu-append-item submenu (let ((item (gio:make-menu-item :model menu :label "Dark" :detailed-action "app.color-scheme")))
(setf (gio:menu-item-action-and-target-value item) (list "app.color-scheme" (glib:make-string-variant :string "DARK")))
item))
(gio:menu-append-submenu menu "Color Scheme" submenu))
(values menu)))
(define-main-window (window (make-application-window :application *application*))
(setf (window-title window) "Stateful Menu")
(let ((header-bar (make-header-bar)))
(let ((menu-button (make-menu-button)))
(setf (menu-button-menu-model menu-button) (stateful-menu-menu)
(button-icon-name menu-button) "open-menu-symbolic")
(header-bar-pack-end header-bar menu-button))
(setf (window-titlebar window) header-bar))
(let ((action (gio:make-stateful-simple-action :name "fullscreen" :parameter-type nil :state (glib:make-boolean-variant :value nil))))
(gio:action-map-add-action *application* action))
(let ((action (gio:make-stateful-simple-action :name "always-on-top" :parameter-type nil :state (glib:make-boolean-variant :value t))))
(gio:action-map-add-action *application* action))
(let ((action (gio:make-stateful-simple-action :name "color-scheme"
:parameter-type (glib:make-variant-type :type-string "s")
:state (glib:make-string-variant :string "LIGHT"))))
(gio:action-map-add-action *application* action))
(let ((window-box (make-box :orientation +orientation-vertical+
:spacing 0)))
(let ((menu-bar (make-popover-menu-bar :model (simple-menu-menu))))
(box-append window-box menu-bar))
(let ((empty-box (make-box :orientation +orientation-vertical+
:spacing 0)))
(setf (widget-size-request empty-box) '(400 200))
(box-append window-box empty-box))
(setf (window-child window) window-box))
(unless (widget-visible-p window)
(window-present window))))
from cl-gtk4.
Yes, it appears to be what I was looking for. Thank you very much. I guess that closes the issue. If I have more specific question I will ask it another time.
from cl-gtk4.
I suggest you close this issue so that you can reopen it anytime if you have any further questions.
from cl-gtk4.
Good job the checkbox on the menu shows, but how do I go to the next step and toggle the checkbox on several subsequent clicks? I only managed to uncheck the boolean menu item.
from cl-gtk4.
I figured out the way to toggle the state. Glib:variant-hash returns 1 or 0 for boolean variants. It is not ideal but it works. Can I close the issue now? :-)
;; toggle the state
(gio:action-change-state menu-action (glib:make-boolean-variant
:value (if (zerop (glib:variant-hash (gio:action-state menu-action)))
T
nil)))
from cl-gtk4.
Sure ;)
from cl-gtk4.
Related Issues (20)
- Can you add TODO list to README? HOT 1
- Could you make the library interface more declarative? HOT 11
- DSL for Cairo library. HOT 1
- Can't install CL-GTK.WEBKIT HOT 1
- Returning from dialogs HOT 1
- Error Building via Github Actions HOT 4
- Can't load the library HOT 1
- What about Cairo in Lisp? HOT 3
- Can't make a GStream binding. HOT 1
- Typelib file for namespace 'Gtk', version '4.0' not found HOT 4
- How to make a GListStore of fixnums / How to subclass GObject HOT 2
- Library needs more documentation HOT 1
- Can't create simple application. HOT 4
- FLOATING-POINT-INVALID-OPERATION HOT 5
- arithmetic error DIVISION-BY-ZERO signalled HOT 2
- Cant create wigets to store it in variable HOT 1
- When vertically scaling the window, there is an artifact with the buttons. HOT 1
- No symbol named "POINTER-OBJECT" HOT 2
- Error g_error_free on Windows 11 HOT 6
- Can't properly pass "user_data" to callback for open file dialog HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cl-gtk4.