-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I make Gobject? #27
Comments
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 |
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 |
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 |
https://gtk-rs.org/gtk4-rs/stable/latest/book/actions.html This appears to be closest to what I want. |
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)))) |
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. |
I suggest you close this issue so that you can reopen it anytime if you have any further questions. |
Thank you for your hekp |
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. |
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? :-)
|
Sure ;) |
I need it for radio and checkbox menus.
https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application9/exampleappwin.c
https://docs.gtk.org/gobject/ctor.Object.new.html
The text was updated successfully, but these errors were encountered: