-
Notifications
You must be signed in to change notification settings - Fork 810
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
Added new extension snippets_menu #827
Conversation
Originally copied from `zenmode`, these are obviously useless.
Actually I think this is quite a bit nicer than the hack I threw together -- what do you think about renaming this to from astropy.constants import G, M_sun
print(G * M_sun) instead of What do you think about leaving a few built-in snippets as examples of the types of things a user might want to automate (e.g., imports, plotting stuff, class template, etc.), and make it really easy to edit / add snippets? I don't have a specific idea on how to do that because the JS in Jupyter confuses me, but others might have ideas! But in any case, I would vote to not ship with all of the current built-in menus, but I suppose I don't feel very strongly because I can always delete things locally... cc @jcb91 |
As far as differences in the two go:
I like the menubar, but others may like the toolbar, or both. We can make this choice configurable through the jupyter_nbextensions_configurator.
Yes, this is neat, let's keep this idea
So, as @adrn mentions, he doesn't like some of the snippets. I think having a broad selection is quite useful, but again, as @adrn mentions, this is largely a matter of taste. Perhaps we could have another configurable option to add (or not) the more extensive set of builtin snippets. Although the user can certainly edit the json themselves, the configuration option can make it a little more user-friendly for common operations. Not sure, I'd have to think about how to implement that.
I like this more than adding whole cells, so would be inclined to have it do that, but then others may prefer cells. Configurable again, I guess 😉
Neat. Keep this.
Yeah, this is a nice idea, but I'm not sure exactly how to implement it. The configurator doesn't handle json specially at the moment, and even then that wouldn't be the most intuitive for the user. We could build a form for editing snippets, accessible as a menu item, and then use the notebook config API to store the json, I guess, although I'm not immediately clear how the more complex system of menus in the boilerplate nbextension would fit into that model. Something to think about, I guess... problems to be addressed:
Yes, the DOM elements are hardcoded parts of the html page, so they should all be present once notebook extensions are loaded. Even the menu's javascript event handlers should also be bound before any extensions are loaded (see menu js instantiation in notebook/js/main.js#L102-L109, and then the nbextension loading later at notebook/js/main.js#L171-L175
The only ways I can think of to do this are
But I'm not really sure that it's necessary. I think a better solution will be to store the snippets using the notebook's config API, then load them in the extension.
Well, the most obvious way to do this is to have the nbextension expose its menus, then you can edit the value directly in
We'll find those as we go, I expect 😄 I think the major change to make is where to load the snippet json from, so that we can avoid using |
I think I've mostly solved the issues brought up above. I feel really strongly that we should keep all of the current snippets as options, but I agree that it needs to be easier to remove unwanted submenus, and to add custom menus. At the moment it requires some JS skills and
I think this is roughly as much customizability as will be possible in this way, since it appears to just use the basic YAML file to create the configuration section — though I'd be happy for anyone to point out ways to really edit things. But I've also restructured things to make the extension easier to customize through Things I haven't addressed:
@adrn. Just to explain my thinking about these huge menus a little more:
Neither would I, but I like having all those constants listed to remind me of what constants are available, and how exactly they're named — e.g., But again, since it's now much easier to deselect sub-menus, I don't think having huge default menus is as much of an issue. |
Nice job @moble, looks good to me :) I actually started similar work in a fork of the original repo, but haven't pushed anything for anyone to see yet, so you win that one 😉 Incidentally, if you're working on top of your original repo, then we could merge those commits in with some renames to keep the two copies in step, which worked nicely with scratchpad.
Yeah, this is about as much as is easy to do without building a full javascript-based editor form. I was thinking of something based on something like https://github.com/vakata/jstree, but it'd be a relatively major hassle, so I think this is good at least for the foreseeable.
Yes, I've had that thought too. I'm starting to think that the two are serving different use-cases, and certainly for the toolbar case, it seems less sensible to have a huge set of snippets, and definitely not easy to have a hierarchical structure. Perhaps we'd be better off keeping the simpler case as toolbar-only in a separate nbextension. The other alternative would be to kep them together, but using different config values for their snippet sets, and ignore and submenus in the toolbar. It would be nice to have them both accept the same object structure for menus, at any rate.
Sure, In fact, in light of point 1, it might be better to keep the two separate-though-related
Nothing springs to mind! |
I've put a few alterations on the jcb branch of my fork of the standalone repo, (that is, https://github.com/jcb91/jupyter_boilerplate/tree/jcb). Mainly making things in options configurable. If you think they still need to be accessible, it'd be easy to export the config as part of the options structure (or even merge the two, and just expose one structure). I'm not sure the pre_config_hook is necessary, as anything in |
Wow, that's much nicer looking code, alright. Thanks! There are a few little bugs that I found:
if (cfg.include_custom_menu) {
var custom_menu_content = JSON.parse(cfg.custom_menu_content);
console.log(mod_log_prefix,
"Inserting custom", custom_menu_content.name, "sub-menu");
options.menus[0]['sub-menu'].push(custom_menu_content);
}
|
@moble haha good list! Ugh, that's what comes of doing my testing only before a bunch of rebases, amateurish of me. I'll be out of the loop for a few days now, so feel free to mess with that set of changes if you like, or I'll get around to it once I get back :) |
Okay, @jcb91, I've merged your commits and those bugfixes. This is all looking just about ready to go, to me. |
Looks good to me. Let's merge. |
Yes, @jcb91 has git magics! Very nice extension, I knew it before and it was already very nice; and it has improved :-) |
Sorry, if I was a little fast :-) |
There's no rush from my end, so I'm happy to wait to see what jcb thinks would be easiest. |
Haha hi all. So, given that this is merged already, I think we may as well just add the upstream copy over the top of it, rather than attempting to rip this out of master and risking peoples histories diverging. I'll try to throw together a relevant PR now... |
@jcb91 suggested here that jupyter_boilerplate should be moved into this repo. This PR is an attempt to do so. This extension appears to be different from @adrn's
snippets
extension in several ways:I've renamed this extension
snippets_menu
to be close enough to @adrn's extension to prompt comparisons, while also being obviously distinct.A number of problems should probably be addressed before it is merged — mostly having to do with the fact that I don't understand the order of operations.
Would it be possible to ensure that
load_ipython_extension
is called only after the usual Jupyter menus have been created (and specifically theHelp
menu item)? At the moment, I've just thrown in a lot ofrequire
s, and it seems to work out, though I'm not sure it always will.How can a function be written in
custom.js
that is guaranteed to be called only afterload_ipython_extension
has finished manipulating the menus? Many of the examples I've written in thereadme.md
(which are basically copied intoexamples_for_custom.js
) could benefit from this.Would it be possible to run
custom.js
, and then check again to ensure that if nothing was added bycustom.js
, at least the default is added? The use ofremove_top_level_snippets_menu_items
in my custom examples is pretty hacky, and could be much more elegant if this were possible.Probably plenty of other problems related to the fact that this is my first JS code, and I'm not really sure how nbextensions are supposed to work...