Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FigureCanvas Designer #11423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed

FigureCanvas Designer #11423

wants to merge 9 commits into from

Conversation

teddyrendahl
Copy link

@teddyrendahl teddyrendahl commented Jun 12, 2018

PR Summary

This adds a QtDesignerPlugin for FigureCanvasQt.

matplotlib

Usage

  1. Point the PYQTDESIGNERPATH environment variable to the file system directory where the new figure_plugin.py file lives
export PYQTDESIGNERPATH=/my/path/matplotlib/lib/matplotlib/backends/qt_editor:$PYQTDESIGNERPATH
  1. Open designer, drag and drop the FigureCanvasQt into your widget and save the file
  2. Load the file in Python using pyuic and access the FigureCanvasQT.
class MatplotlibWidget(QWidget):
      def __init__(self, ui_file):
             # Load saved UI file
             self.ui = uic.loadUi(ui_file, self)
             # Access to matplotlib Figure
             figure = self.ui.FigureCanvasQt.figure
             ....

Notes

  • Qt Versions: I could not find any support for theQtDesigner module in either version of PySide. This works in PyQt4 installed from source but it looks like the version hosted on conda-forge is built with the --no-designer-plugin option.
  • Happy to document this more formally somewhere just wasn't sure where
  • The plugin has the option to display a little icon next to the widget. Is there any matplotlib logo that ships with the repository? I could add it?

Closes #758

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

def createWidget(self, parent):
"""Create a FigureCanvasQT instance"""
# Create the Canvas with a new Figure
fig = FigureCanvasQT(Figure())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this a bit? I'm a bit surprised that you already add the figure to the canvas here. What if the user wants to use a different figure? (This may be a stupid question, as I've never worked with Designer.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of a way to pass in an existing Figure inside the QtDesigner. The idea is that the user creates the .ui file before any Python code is ever written. They then can access this figure (as shown above) by loading the .ui file. I'm not sure how to swap this order and have the Designer be aware of an arbitrary Figure created in user code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with this order of operations an the .ui figure now provides a fully functional Figure to work with.

@ImportanceOfBeingErnest
Copy link
Member

I have no idea how useful this is in total, i.e. if this is a thing many people would actually use. But just suppose it is, I fear people would not be aware of it.
So if this goes into matplotlib, it definitely needs some accompanying documentation and/or example.

@tacaswell tacaswell added this to the v3.0 milestone Jun 13, 2018
@tacaswell
Copy link
Member

I think the right place to put the plugin is in https://github.com/matplotlib/matplotlib/tree/master/examples/user_interfaces which is where we keep the glade file for wx (which I believe is the same thing, but for WX). Not a slick to use as it being directly importable, but it is at least in the codebase / documentation.

The module it is currently in is a vendored interface generator that we use for the artist editor dialogue in Qt.

@tacaswell
Copy link
Member

On a bit more consideration (and looking at the gtk install code) maybe the plugin should go in https://github.com/matplotlib/matplotlib/tree/master/lib/matplotlib/mpl-data

@tacaswell tacaswell modified the milestones: v3.0, v3.1 Jul 15, 2018
@tacaswell
Copy link
Member

As much as I want this, punting to 3.1 😞

@teddyrendahl
Copy link
Author

teddyrendahl commented Jul 15, 2018

Sorry I've been neglecting this. I can drag it to completion. Just so I understand what else is needed.

  • Move designer plugin to mpl-data
  • Add ReSt description to next_whats_new
  • Add unittest (think I can do this with QFormBuilder)

@tacaswell
Copy link
Member

@teddyrendahl Yes.

I would be willing to merge this after the RC so in the next week or so.

@teddyrendahl
Copy link
Author

teddyrendahl commented Jul 15, 2018

Awesome. Also should I create a merge commit here or would you prefer rebase?

@ImportanceOfBeingErnest
Copy link
Member

I addition, as said already, there should be some example or description available. I could imagine that an example inside the Embedding Matplotlib in graphical user interfaces section of the gallery would make sense. This would need to be named with _sgskip at the end, as all other files from that section. And it could include the animated gif used here, as well as some step-by-step instruction.
A "what's new" entry would then consist only of two sentences with a link to that example.

@tacaswell
Copy link
Member

On the other hand we don't install the data directory by default any more....

@anntzer
Copy link
Contributor

anntzer commented Jul 16, 2018

We definitely still install mpl-data by default (and it's not as if we could really change that).

@teddyrendahl
Copy link
Author

teddyrendahl commented Jul 19, 2018

Made progress but realizing that I might need a FigureManagerQt object as well. I'll keep exploring... Getting a black canvas that never shows anything when I try and plot.

screen shot 2018-07-18 at 9 44 11 pm

@teddyrendahl
Copy link
Author

Okay. Spoke a little too soon. Figured out I needed the the FigureCanvasQtAgg specifically. One unfortunate thing I realized is that Qt assumes that any widget that it loads from a .ui file has a initialization that only receives a single widget (its parent) in __init__. I therefore made a stub class of FigureCanvasQtAgg that matches this signature. It is very ugly but the least complicated way I could think of to get this working. Open to suggestions.

@jklymak jklymak added the stale label Feb 11, 2019
@jklymak jklymak modified the milestones: v3.1.0, v3.2.0 Feb 11, 2019
@jklymak
Copy link
Member

jklymak commented Jul 16, 2019

Thanks a lot for the contribution. I'm going to close this as having had no action for quite a while. OTOH, if there is still a community that wants this, please feel free to re-open, with my apologies!

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

Successfully merging this pull request may close these issues.

Qt Designer plugin
7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.