Skip to content

FigureCanvasWx/Agg fixed size #10377

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

Merged
merged 2 commits into from
Feb 11, 2018

Conversation

DietmarSchwertberger
Copy link
Contributor

PR Summary

(replacement for PR #10153)

The embedded FigureCanvasWx currently can't be set to a fixed size.
When it is added to a sizer with proportion=0 and wx.EXPAND not set, then it will not expand over it's defined size, as expected. But when the visible area is reduced below the defined size, it will re-scale itself to fit the visible area because 'self.GetClientSize()' is used to read the size.
This could happen if the window size is reduced or a splitter is used.
When placed on a scrolled window, the problem does not occur, as then the VirtualSize will not change, even when the widget is not 100% visible.

This is not a big issue as the behaviour can easily be modified in a derived class. It would be nice though, to have the correct behaviour by default.

See attached file embedding_in_wx4_fixed.py for an example. With the modification from the pull request the size will stay fixed.
The only change is the sizer.Add call with proportion=0 and without EXPAND:

self.figure = Figure(figsize=(5, 4), dpi=100)
...
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
#self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)
self.sizer.Add(self.canvas, 0, wx.TOP | wx.LEFT)

embedding_in_wx4_fixed.py.txt

I could commit the example file, but that's probably not worth it.

If the canvas is directly used as single child of a frame (i.e. instead of a panel), the behaviour is not modified by the pull request. This could be changed, but I don't see a use case for this.

Btw.: I just noticed that the embedding_in_wx4.py example includes an EVT_PAINT handler. I don't think that this is required, as the plot is static. Instead, it causes unnecessary renderings.

Also, the structure of fourier_demo_wx.py is a bit unusual. The usual hierarchy would be Frame->Panel->Sizer->Canvas. Actually it's now Frame->Sizer->Window->Canvas where the Window does not have any function and the sliders are drawn on the plain frame background.

I could submit a PR to update the demos, if desired.

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

@tacaswell
Copy link
Member

@efiring will like this change :)

PRs to update the examples are very welcome.

@DietmarSchwertberger please send me an email

@tacaswell tacaswell added this to the v2.2 milestone Feb 5, 2018
@tacaswell tacaswell merged commit de1e1f1 into matplotlib:master Feb 11, 2018
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants