How to run a plugin in a secondary LayoutViewWidget

I posted this in a different discussion, but it seems to be overshadowed by a different issue I raised.

The KLayout documentation here mentions that every time a LayoutView is created, a copy of each plugin is created from its PluginFactory, and is activated when the button is pressed on the toolbar. But when created with a LayoutViewWidget, when there is no toolbar, how do you activate the plugin in that particular LayoutView?

My example is the following:

import pya as kl

class PluginTestFactory(kl.PluginFactory):
    def __init__(self):
        self.register(29318, "plugin_name", "test_plugin")
    def create_plugin(self, manager, dispatcher, view):
        return PluginTest(view)
class PluginTest(kl.Plugin):
    def __init__(self,view):
        print("Starting plugin")
        self.outside_view = (view != kl.Application.instance().main_window().current_view())
    def mouse_click_event(self, p, buttons, prio):
        if prio and self.outside_view:
            print("Mouse clicked inside secondary view!")
        elif prio:
            big_menu = kl.QDialog(kl.Application.instance().main_window())
            big_menu.layout = kl.QGridLayout()
            containing_layout = kl.QWidget()
            self.layoutwidg = kl.LayoutViewWidget(containing_layout)
            cv = self.layoutwidg.view().create_layout(True)
            viewing_layout = self.layoutwidg.view().cellview(cv).layout()
            big_menu.layout.addWidget(self.layoutwidg,0,0,1,1)
            big_menu.show()
if __name__ == "__main__":
    PluginTestFactory()

I can't figure out how to get the "Mouse clicked inside secondary view!" string to ever print. How do I activate the plugin in the new LayoutView, so that it can be printed?

Comments

  • Maybe you could just explain what you intend to do.

    You can enable a mode using "switch_mode". In my example the name of the plugin is "plugin_name" (the second argument to register), so I can switch to that plugin using

    view.switch_mode("plugin_name")
    

    I think it needs to be called after the layout has been loaded, but I have not tried.

    You can obtain the names of all modes using LayoutView#mode_names and the name of the current mode using LayoutView#mode_name.

    Matthias

  • Hello Matthias,

    Thanks! I wish for the user to select a box and for the shapes within that box to pop up inside a second layoutview, and for the user to be able grab shapes and move them within this second layoutview. I think modes is what I was looking for, thanks again!

Sign In or Register to comment.