Re: [GNC] User-defined commands
On Wed, 30 Nov 2022 at 15:55, Helmut Eller wrote: On Tue, Nov 29 2022, john wrote: > See the definition of gnc:add-report-template-menu-item at https:// > github.com/Gnucash/gnucash/blob/maint/gnucash/gnome/report-menus.scm# > L42 for example code. It's all specialized for report templates so > you'll have to copy and modify a lot of code. Note the convention > that functions starting with gnc: are written in Scheme and those > starting with gnc- or xacc are written in C and exposed to Guile via > SWIG. Thank you. With this I was able to add a command to the Tools menu. (See the attached file, in case somebody is interested.) This is indeed interesting... I'd previously experimented with a repl server[1], using nc to connect. Yours is much more elegant. Would you care to add to the wiki? [1] https://wiki.gnucash.org/wiki/Custom_Reports#Command_line_access_to_the_API With yours, one can launch via Tools > Scheme REPL, then (use-modules (gnucash engine)) to import the whole engine api. Can the same strategy also be used to add items to the popup menu? I'm mostly asking if I should look harder or if it is not possible because there are no Scheme bindings for the popup menu. Similarly, is there a Scheme binding for gnc_plugin_page_account_tree_get_current_account? I don't think there is. ___ gnucash-user mailing list gnucash-user@gnucash.org To update your subscription preferences or to unsubscribe: https://lists.gnucash.org/mailman/listinfo/gnucash-user - Please remember to CC this list on all your replies. You can do this by using Reply-To-List or Reply-All.
Re: [GNC] User-defined commands
On Tue, Nov 29 2022, john wrote: > Is this possible? Is it documented somewhere? > > > Yes, it's possible. No, it's not documented. > > See the definition of gnc:add-report-template-menu-item at https:// > github.com/Gnucash/gnucash/blob/maint/gnucash/gnome/report-menus.scm# > L42 for example code. It's all specialized for report templates so > you'll have to copy and modify a lot of code. Note the convention > that functions starting with gnc: are written in Scheme and those > starting with gnc- or xacc are written in C and exposed to Guile via > SWIG. Thank you. With this I was able to add a command to the Tools menu. (See the attached file, in case somebody is interested.) Can the same strategy also be used to add items to the popup menu? I'm mostly asking if I should look harder or if it is not possible because there are no Scheme bindings for the popup menu. Similarly, is there a Scheme binding for gnc_plugin_page_account_tree_get_current_account? Helmut ;; ;; This example shows how to add a menu item from Scheme. The code ;; adds the menu item "Tools/Scheme REPL" and the corresponding ;; command starts a Scheme REPL in the tty. ;; ;; Installation: ;; ;; 1.) Place this file somewhere in your file system. ;; E.g. in ~/hacking/gnucash/commands/repl.scm ;; ;; 2.) Add something like this to your ~/.config/gnucash/config-user.scm: ;; ;; (add-to-load-path "/home/helmut/hacking/gnucash/") ;; (import (only (commands repl) register-repl-command)) ;; (register-repl-command) ;; ;; 3.) Start GnuCash as usual ;; (library (commands repl) (export register-repl-command) (import (rnrs base) (only (guile) format getenv resolve-module current-module set-current-module save-module-excursion) (only (system repl repl) start-repl) (only (ice-9 readline) activate-readline write-history read-history) (only (gnucash gnome-utils) gnc-add-scm-extension) (only (gnucash gnome-utils gnc-menu-extensions) gnc:make-menu-item) (only (gnucash core-utils) G_ N_)) (define history-filename (format #f "~a/.gnucash_history" (getenv "HOME"))) (define previous-module #f) (define (repl) (save-module-excursion (lambda () (set-current-module (or previous-module (begin (activate-readline) (read-history history-filename) (resolve-module '(guile-user) (start-repl) (set! previous-module (current-module)) (write-history history-filename) (format #t "Goodbye~%" (define menuname-tools (N_ "Tools")) (define (register-repl-command) (gnc-add-scm-extension (gnc:make-menu-item "Scheme REPL" "0155032a4b41443388f6cf8effc98169" "Start a Scheme REPL in the tty" (list menuname-tools) (lambda (window) (format #t "window: ~s~%" window) (repl) ) ___ gnucash-user mailing list gnucash-user@gnucash.org To update your subscription preferences or to unsubscribe: https://lists.gnucash.org/mailman/listinfo/gnucash-user - Please remember to CC this list on all your replies. You can do this by using Reply-To-List or Reply-All.
Re: [GNC] User-defined commands
> On Nov 29, 2022, at 4:40 AM, Helmut Eller wrote: > > Is there some easy way to add user-defined commands to the menus? > > I wrote some Scheme code for various tasks and currently I execute this > code via custom reports as a side effect. This works, but it would be > nicer if I could create proper menu items for these commands. Ideally, > the command would be called with some arguments, e.g. the currently > selected transaction. > > Is this possible? Is it documented somewhere? Yes, it's possible. No, it's not documented. See the definition of gnc:add-report-template-menu-item at https://github.com/Gnucash/gnucash/blob/maint/gnucash/gnome/report-menus.scm#L42 for example code. It's all specialized for report templates so you'll have to copy and modify a lot of code. Note the convention that functions starting with gnc: are written in Scheme and those starting with gnc- or xacc are written in C and exposed to Guile via SWIG. Regards, John Ralls ___ gnucash-user mailing list gnucash-user@gnucash.org To update your subscription preferences or to unsubscribe: https://lists.gnucash.org/mailman/listinfo/gnucash-user - Please remember to CC this list on all your replies. You can do this by using Reply-To-List or Reply-All.
[GNC] User-defined commands
Is there some easy way to add user-defined commands to the menus? I wrote some Scheme code for various tasks and currently I execute this code via custom reports as a side effect. This works, but it would be nicer if I could create proper menu items for these commands. Ideally, the command would be called with some arguments, e.g. the currently selected transaction. Is this possible? Is it documented somewhere? Helmut ___ gnucash-user mailing list gnucash-user@gnucash.org To update your subscription preferences or to unsubscribe: https://lists.gnucash.org/mailman/listinfo/gnucash-user - Please remember to CC this list on all your replies. You can do this by using Reply-To-List or Reply-All.