Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    epifanio
    @epifanio
    is it that possible from the snippet_menu extension? perhaps with some modification?
    Josh Barnes
    @jcb91
    I don't think it's possible as it stands at the moment, but it would probably be relatively easy to implement with some modification
    epifanio
    @epifanio
    Hi @jcb91 , I was looking at the init_cel extension to see how it does the execution
    Josh Barnes
    @jcb91
    Ok...
    epifanio
    @epifanio
    and try to call the run cell from insert_snippet_code
    but I'm only guessing, that's not idal for what I've in mind but will be an awesome start
    Josh Barnes
    @jcb91
    So are you aiming to have a snippets_menu entry which ensures that the cell it gets inserted into is then executed? Or one that just executes the snippet in the current kernel without inserting the snippet into the notebook at all?
    epifanio
    @epifanio
    you got me :) I'm aiming for the second option .. but I don't know how/if doable, what I've in mind is to have menu connected to the execution of simple widgets
    when the menu gets trigged, the widget is rendered (ideally) in a fixed part of the notebook page
    like you do with the scratchpad widget
    but as I said, a good start will be to hack the snippet_menu and get the widget code added to a new cell and then executed (i guess it will be possible to hide the cell input as further step)
    Josh Barnes
    @jcb91
    Hmm well, you can call notebook.kernel.execute, but if you want widgets, it sounds like a more complicated use-case
    Sounds like you might be after something like https://github.com/jupyter/dashboards ?
    epifanio
    @epifanio
    The dashboard is too complex (I guess). what I'm tring to do is to replace code-cell with simple widgets in a long workflow like this one https://epinux.com/epinux_data/shared/geosciences-250279-latest/geosciences-250279-latest.html
    in that notebook there are a number of calls to the same function which is: grass.run_command or grass.read_command .. which take as input a command name which is associated to some parameters
    what I'm aiming is to expose all this commads in the notebook menu .. like: https://www.dropbox.com/s/ttxu233apwzqold/Screenshot%202018-01-30%2019.39.34.png?dl=0
    epifanio
    @epifanio
    the commands are ~300 all organized in a menu with specific sections (raster, vector, db, etc ... ) and each command has an UI interface description (in xml) which I'm parsing to generate a gui using the IPywidgets framework
    Josh Barnes
    @jcb91
    I'm not sure I follow what you mean 🤔
    What exactly would the menu item do?
    epifanio
    @epifanio

    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

    make sense?
    epifanio
    @epifanio
    what the menu_item gets triggered, the guimodule (which is UI dialog) should be rendered below the current selected cell.
    What the UI dialog does is to collect user inputs. and once the 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')
    which is the ready for execution with a standard shift+enter from the notebook user
    epifanio
    @epifanio
    adding 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 ..
    epifanio
    @epifanio

    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

    something I'm missing is: how to render a cell outside the main notebook layout? in my use case will be great to have the option of rendered the menu-item-widget in a dedicated div in the main notebook page. Something similar to what is done for the scratchpad extension
    also for now the hiding is not persistant between page reloads. I'm still not writing in the cell metadata
    Josh Barnes
    @jcb91
    something I'm missing is: how to render a cell outside the main notebook layout? in my use case will be great to have the option of rendered the menu-item-widget in a dedicated div in the main notebook page. Something similar to what is done for the scratchpad extension
    As I understand it, the code which is doing the display of the widget is provided by ipygrass.guimodule, so I guess it depends on what they're doing...
    Josh Barnes
    @jcb91
    I can only find https://github.com/masat76/ipygrass, which doesn't seem to provide a guimodule object/function/module at all 🤷
    epifanio
    @epifanio
    Hi Josh, you are right IPyGrass is not on github, and it is just a proof of concept. For now it is written in PyQt and PyZMQ.
    epifanio
    @epifanio
    The PyQt GUI displays a menu (like the snippets menu) client side, and GRASS is installed on a remote server. The workflow is the following:
    • The user select an item in the GUI menu (which correspond to one of the 300+ GRASS commands)
    • send a "GRASS command description" request to the server,
    • once the client receive the reply from the server (which is a pandas dataframe) then the description is parsed and rendered using pyqt
    Now I want replace the UI framework with ipywidgets and remove the server-client game ... by having all running in a notebook
    Josh Barnes
    @jcb91
    Ah, ok, I think I follow that. So in the desired operation mode, your 'client' will render it's menus as html elements, rather than using pyqt? That sounds like a good use case for ipywidgets, I think
    epifanio
    @epifanio
    I'm tring to make a scrren cast of what actually does, but cloudapp has an unfair limit of 25 sec for animated gif :)
    Josh Barnes
    @jcb91
    Haha nothing's ever easy, eh?
    epifanio
    @epifanio
    I was quick .. so what the ui does .. is to complete a command line which is printed at the bottom of the module UI
    this command line is what the Ipywidget will send to the notebook kernel
    Josh Barnes
    @jcb91
    Ok, that sounds reasonable
    I'm on a train, and the WiFi doesn't seem to want to load the screencast, but I can maybe take a look when I get home
    epifanio
    @epifanio
    cool! I'll see how long will take to port the code from pyqt to ipywidget
    sure much more than your train .. unless you are traveling in south italy :P
    Shravan Shetty
    @shravankumar9892
    I have installed jupyter_contrib_nbextensions, and have followed up till step number 2
    Now i want to enable auto-completion extension, so what should be my step number 3? refering to README.md of the repo ...
    Yasin Maan Yousif
    @engyasin
    hi
    hey
    where i can find a tutorial on how to write jupyter nbextension?
    Buddhabhushan Nagrale
    @BuddhabhushanNagrale
    hello.. can somebody tell me how to change font type in markdown cells