grass.run_command
or grass.read_command
.. which take as input a command name which is associated to some parameters
i know it's a bit hard to explain, I'm tring :) .. essentially I do have menu items (like the snippets_menu) and once trigged it will render the widget (which is just a dialog to collect user inputs) .. the widget is called this way:
from ipygrass import guimodule
guimodule('command_name')
where command_name
is the name of the menu item
ok
button is pressed, it will print out as a new cell a command like: grass.run_command('command_name',
option1='value1',
option2='value2',
option3='value3')
new_cell.execute();
on run_init_cells execute the cell with no glitch :) i can attempt to add some 'keyword' in the snippet associated with my custom menu .. and handle the execution with some 'if' statment ..
I got something that is close enough to what I was looking for, by changing insert_snippet_code
to:
function insert_snippet_code (snippet_code) {
if (cfg.insert_as_new_cell) {
var new_cell = Jupyter.notebook.insert_cell_above('code');
new_cell.set_text(snippet_code);
console.log('sono una cella viva')
console.log(typeof snippet_code);
new_cell.focus_cell();
if (snippet_code.startsWith('#GRASS')) {
new_cell.execute();
new_cell.element.find("div.input").hide()
}
}
else {
var selected_cell = Jupyter.notebook.get_selected_cell();
Jupyter.notebook.edit_mode();
selected_cell.code_mirror.replaceSelection(snippet_code, 'around');
}
}
In the custom snippet_menu, each entry I want to have executed, start with the string "#GRASS", I then execute and hid the input
ipygrass.guimodule
, so I guess it depends on what they're doing...