Trigger javascript alert popup message from python?

Hi all,
I’m looking for a way to send a popup message from a pre- or post-save hook (python) back to the UI.

I’ve seen a few third-party ‘messagebox’ solutions but wanted to do things "the right way"™ using custom.js, but the examples I’ve seen are all bound to a toolbar widget or something in the UI – is it possible to call a “dialog.modal” javascript from python code? Any tips, examples, links, etc. appreciated.

TIA,
John

I’m not sure if it’s the right or best way, but for anyone else with this issue I’ve found that you can raise HTTPError messages from python; 100s don’t display; 200s result in a messagebox, 300-500s result in a message to the toolbar area.

I then trap the error text in \notebook\static\notebook\js\notebook.js:

    if (data.message) {
        // JD: add custom handling for autosave storage space checking (note: 'data' does not pass the HTTP code, just the message text)
        if(data.message.startsWith("Warning: you are running low on storage space;")){
            var title = i18n.msg._("Storage Capacity Warning");
            body.append($("<p>").text(data.message));
                dialog.modal({
                    notebook: this,
                    keyboard_manager: this.keyboard_manager,
                    title: title,
                    body: body,
                    buttons : {
                        OK : {
                            "class" : "btn-primary"
                        }
                    }
                });
            this.events.trigger('notebook_saved.Notebook');
            this._update_autosave_interval(start);
            if (this._checkpoint_after_save) {
                this.create_checkpoint();
                this._checkpoint_after_save = false;
            }
        }