It looks like you're new here. If you want to get involved, click one of these buttons!
Hi KLayout community, Hi @Matthias,
I tried to convert the Ruby code from https://www.klayout.de/forum/discussion/616/add-horizontal-vertical-alignement-on-toolbar to a python code.
Basically the code should add a button to the toolbar, which triggers the the align action from the selection menu.
The code below indeed adds a button to the toolbar and when the button is pressed, the message "The action was triggered" is displayed.
However, the align action is not triggered. I suspect the line menu.action("edit_menu.selection_menu.align").trigger is not correct. Do you know a way to trigger the align action by a new button with python?
Of course I could always use the ruby code, but I try to focus on one coding language and I'd also like to understand the integration with python.
from pya import Action, MessageBox, Application
menu = Application.instance().main_window().menu()
def on_triggered():
menu.action("edit_menu.selection_menu.align").trigger
MessageBox.info("A message", "The action was triggered", MessageBox.Ok)
act = Action()
act.on_triggered = on_triggered
act.title = "My Action"
menu.insert_item("@toolbar.end", "my_action", act)
Comments
Hello, Sepbe
Probably you try to do this?
Vincent
Hi @Vincent,
thanks, but the important part is the line "pya.Application.instance().main_window().menu().action("edit_menu.selection_menu.align").trigger", which does not seem open the align options if the button is clicked.
Sepbe
Hello, Sepbe
I love Ruby more, I have changed my mind
Vincent
@Vincent Lin
I had the same issue myself too many times ... you get used to that
Regarding your solution: a cheap way of getting the same effect is:
Regards,
Matthias