Giter Club home page Giter Club logo

Comments (12)

bigos avatar bigos commented on July 19, 2024 1

Thank you for your hekp

from cl-gtk4.

bigos avatar bigos commented on July 19, 2024

https://docs.gtk.org/gobject/concepts.html#object-instantiation

from cl-gtk4.

bigos avatar bigos commented on July 19, 2024

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.

bohonghuang avatar bohonghuang commented on July 19, 2024

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.

bigos avatar bigos commented on July 19, 2024

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.

bigos avatar bigos commented on July 19, 2024

https://gtk-rs.org/gtk4-rs/stable/latest/book/actions.html

This appears to be closest to what I want.

from cl-gtk4.

bohonghuang avatar bohonghuang commented on July 19, 2024

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.

bigos avatar bigos commented on July 19, 2024

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.

bohonghuang avatar bohonghuang commented on July 19, 2024

I suggest you close this issue so that you can reopen it anytime if you have any further questions.

from cl-gtk4.

bigos avatar bigos commented on July 19, 2024

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.

bigos avatar bigos commented on July 19, 2024

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.

bohonghuang avatar bohonghuang commented on July 19, 2024

Sure ;)

from cl-gtk4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.