Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Doesn't work - but I think I've figured out how to fix it. #59

Open
stcmeh opened this issue May 21, 2020 · 0 comments
Open

Doesn't work - but I think I've figured out how to fix it. #59

stcmeh opened this issue May 21, 2020 · 0 comments

Comments

@stcmeh
Copy link

stcmeh commented May 21, 2020

Hi there.

I've recently upgraded to Spyder 4 and this cookie cutter doesn't work. I've figured out what to change to fix it. I've started a new plugin and I'll make notes below on the changes required to make the plugin work in both Spyder 3 and Spyder 4.

  • Line 26 - QObject.init(self, parent) - QObject isn't imported so this fails. Also, the next line is SpyderPluginWidget.init(self, parent). Won't this inherit the QObject constructor? I commented this line out.

  • I then add the following two lines:

        self.main = parent # Spyder3
        self.spyder_version=3
  • I found initialize_plugin fails in spyder 4 so I modify the code thus:
        # Initialize plugin
        try:
            self.initialize_plugin()
        except:
            self.spyder_version=4
  • There's a line that goes "layout.addWidget(self.widget)" but self.widget is undefined. So I modify the setup to create the widget:
        self.widget = [ADD_ON_NAME_GOES_HERE]Widget(self.main)
        layout = QVBoxLayout()
        layout.addWidget(self.widget)
        self.setLayout(layout)
  • The location of the tabify function changes depending on the version of spyder so I changed the on_first_registration function to:
    def on_first_registration(self):
        """Action to be performed on first plugin registration."""
        # Define where the plugin is going to be tabified next to
        # As default, it will be tabbed next to the ipython console
        if self.spyder_version==3:
            self.main.tabify_plugins(self.main.help, self)
        else:
            self.tabify(self.main.help)    
  • Likewise the add_dock_widget function has moved in Spyder 4 - so I change the register_plugin function to:
    def register_plugin(self):
        """Register plugin in Spyder's main window."""
        if self.spyder_version==3:
            self.main.add_dockwidget(self)
        else:
            self.add_dockwidget()

After that it seems to work.

Now, I'll admit that detecting the Spyder version on the basis of whether or not the initialize_plugin call works is pretty lame - so please let me know if there's a better way.

Making Spyder Plugins is a really cool way to extend the power of a great tool. Thanks for developing this system!

Simon

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant