On Saturday, July 11, 2020 at 12:19:12 PM UTC-5, Félix wrote:
To shed some light on my implementation, here are the few lines it took on
> the leo/python side of things:
>
> def getButtons(self, p_package):
> '''Gets the currently opened file's @buttons list'''
> w_buttons = []
> w_dict = self.commander.theScriptingController.buttonsDict
>
> for w_key in w_dict:
> w_entry = {"name": w_dict[w_key], "index": str(w_key)}
> w_buttons.append(w_entry)
>
> return self.sendLeoBridgePackage("buttons", w_buttons)
>
> def clickButton(self, p_package):
> '''Handles buttons clicked in vscode from the '@button' panel'''
> w_index = p_package['index']
> w_dict = self.commander.theScriptingController.buttonsDict
> w_button = None
> for w_key in w_dict:
> if(str(w_key) == w_index):
> w_button = w_key
> w_button.command() # run clicked button command
> return self.outputPNode(self.commander.p) # return selected node when done
>
This is clever. It uses c.scriptingController.buttonsDict to get the
required data. So yes, nothing more is needed on Leo's end.
I just now took a look at mod_scripting.py. Somehow I mis-remembered that
it depended on the qt gui. But it doesn't! Let's see what's going on:
1. The docstring says: "This plugin puts buttons in the icon area." No
wonder I thought there was gui code involved.
2. sc.createIconButton attempts to creates each icon button this way:
b = self.iconBar.add(text=truncatedText, command=command, kind=kind)
if not b:
return None
ScriptingController.__init__ does:
self.iconBar = c.frame.getIconBarObject()
So sc.iconBar will either be None or a do-nothing object. Either way, the
code will work with any gui.
Yes, it's a cowboy implementation and i should have had protected some of
> those lines with "if's" and try/catch blocks.
>
I think it's very clever.
Eventually, there is no need now, I would like leoInteg to support
right-clicking of the buttons. In Leo, this brings up a popup menu
containing two items: "Remove Button" and "Goto Script". Remove button can
happen purely in leoInteg. However, the logic behind "Goto Script" is
complicated. Iirc, the AtButtonCallback class is involved. "Goto Script"
can find the global scripts that are defined, say, in leoSettings.leo or
myLeoSettings.leo that might not even be open. Again, iirc.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/0a95e2bf-4133-4364-a1eb-6373adca82dbo%40googlegroups.com.