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

MEP27 Decouple pyplot from backends (refactoring Gcf out of backend code) #4143

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 55 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
24caf2b
Refactor pass 1. Refactoring Gcf out of specific backend (backend_gt…
OceanWolf Feb 21, 2015
2b05d38
Refactor Pass 2. Refactored Gcf out of all backend code.
OceanWolf Feb 22, 2015
f4fc354
Quick fix to figure for safe unpickling.
OceanWolf Feb 25, 2015
0b31e3a
GTK3Agg
OceanWolf Feb 26, 2015
6fb452e
Refactored making `FigureManager` a *figure* manager, plus added miss…
OceanWolf Feb 27, 2015
0a868a2
keyword
OceanWolf Feb 27, 2015
61ba2b4
Make add_element more general, and make sure the code complies with it.
OceanWolf Feb 27, 2015
f0eb84c
Better destroy order.
OceanWolf Feb 27, 2015
8fe9cd7
GTK simplifications
OceanWolf Feb 28, 2015
494e5f1
Added doc and cleaned backend_managers, don't want our new file dirty.
OceanWolf Mar 3, 2015
ed16178
Improve layout!
OceanWolf Apr 6, 2015
21b8f58
Move knowledge of the backend to the manager.
OceanWolf Apr 7, 2015
cf42e3b
Incorporate MEP22 into MEP27
OceanWolf Apr 12, 2015
f027b16
Improved new toolbar and updated tool_manager example accoridingly.
OceanWolf Apr 12, 2015
24b7b73
fullscreen
OceanWolf Apr 13, 2015
bc99129
MEP update
OceanWolf Apr 14, 2015
7f7f05e
Finish MEP22 conversion
OceanWolf Apr 14, 2015
713abcb
rename window method
OceanWolf Apr 17, 2015
80adaaf
Add backend anme to widgets
OceanWolf Apr 17, 2015
4e5f69d
Handle FigureManager destroy internaly without pyplot.
OceanWolf Jun 4, 2015
160ef57
Make functionality more consistant for embedded applications
OceanWolf Jun 7, 2015
b6d6acc
Backend getter method for FigureManager
OceanWolf Jun 13, 2015
ecd5038
Improve example after new method
OceanWolf Jun 13, 2015
f8e83fe
Clean up the code a bit
OceanWolf Jun 13, 2015
c53b79a
Remove old code from backend_managers
OceanWolf Jun 15, 2015
34c6b12
Cleanup
OceanWolf Jun 22, 2015
8a4268a
Explicity get set manager as None if appropiate.
OceanWolf Jun 22, 2015
44df199
figure attribute and canvas property
fariza Jun 22, 2015
860a8ed
Fix FigureCanvasBase
OceanWolf Jun 23, 2015
c44e744
super
OceanWolf Jun 25, 2015
2fe9215
figure setter
fariza Jun 25, 2015
3b434ef
Improve MEP22 Tool Searching Structure
OceanWolf Jun 25, 2015
490629f
adding example file
fariza Jun 25, 2015
8eb987b
super dooper
OceanWolf Jun 26, 2015
224a4f3
Revert old example and fix new one.
OceanWolf Jun 26, 2015
cdbd51b
Improve MEP22 tool-searching method.
OceanWolf Jun 27, 2015
50e3719
MEP22 Save Figure Tool
OceanWolf Jun 27, 2015
85be519
pep8
OceanWolf Jun 27, 2015
7edaf5a
Make ToolConfigureSubplots a generic tool
OceanWolf Jun 28, 2015
8e6e252
Improve flow handling and make it a lot more generic
OceanWolf Jun 28, 2015
72575cb
Missing resize method
OceanWolf Jun 28, 2015
4a78246
Convert to new structure for finding tools
OceanWolf Jun 28, 2015
e300707
doc
OceanWolf Jun 29, 2015
ee76451
Add ExpandableBase
OceanWolf Jun 29, 2015
6f0c7ab
Template Backend plus fix FigManager for non-GUI backends and add gen…
OceanWolf Jun 29, 2015
ae9bf5b
rcParam and Travis
OceanWolf Jul 19, 2015
fb004e0
test
OceanWolf Jul 20, 2015
1d2095b
test always MEP27
OceanWolf Jul 20, 2015
24e43b3
Fix FigureManager to allow pyplot to work for non GUI backends
OceanWolf Jul 27, 2015
208c3be
Fix Gcf.show_all()
OceanWolf Jul 27, 2015
a44ebd9
doc
OceanWolf Jul 27, 2015
f8f9cf2
pep8
OceanWolf Jul 27, 2015
0e09a54
remove show_popup
OceanWolf Jul 27, 2015
a38b6d7
AttributeError
OceanWolf Sep 22, 2015
64f0c61
Fixes for MEP27
OceanWolf Aug 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve layout!
  • Loading branch information
OceanWolf committed Aug 3, 2016
commit ed1617892ffdcfd76ae3c9242d74909dd96fa163
5 changes: 4 additions & 1 deletion 5 lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2710,7 +2710,7 @@ def set_window_title(self, title):
"""
pass

def add_element_to_window(self, element, expand, fill, pad, side='bottom'):
def add_element_to_window(self, element, expand, fill, pad, place):
Copy link
Member

Choose a reason for hiding this comment

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

I like it, but, as you said in the comment, how many of our current backends (GUI backends) support all the options?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, I think I want to get rid of pad as I think we always want that as 0? Also either fill or expand as I feel we will always have them both as True or both as False, and feels like extra work to research if methods exist to do it for the different backends.

Also what do you think about renaming this method, to just add_element or add_widget, I think _to_window becomes extraneous, as it gets called on the Window class, but I can't decide between the two names...

Copy link
Member

Choose a reason for hiding this comment

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

I would change it to add_widget

Copy link
Member

Choose a reason for hiding this comment

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

Are these native GUI widgets or mpl widgets?

Copy link
Member

Choose a reason for hiding this comment

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

These are the GUI widgets that are going to be defined for each backend, so far Window, Toolbar, Message

Copy link
Member

Choose a reason for hiding this comment

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

@OceanWolf yes I mean Statusbar, but you have to remove NavigationToolbar2 that I believe it's not compatible with this approach

Copy link
Member Author

Choose a reason for hiding this comment

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

@fariza With which part of this approach? It works fine for me...

Copy link
Member

Choose a reason for hiding this comment

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

I mean that I am not sure NavigationToolbar2 will work in all the backends, as I am not sure they all return just the widget. But it will be matter of testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, well I have gone through all of the GUI backends apart from the Mac specific ones 😒 and GTK2, prior to MEP22 going to master, and got them all to work.

Though if I remember correctly I did have to do this on one them:

if isinstance(element, NavigationToolbar2):
  ...
elif isinstance(element, FigureCanvas):
  ...

but that doesn't matter as we can do that kind of thing on the specific backend 😉.

Copy link
Member Author

Choose a reason for hiding this comment

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

okay, so how about add_element(self, element, expand, place)?

""" Adds a gui widget to the window.
This has no effect for non-GUI backends and properties only apply
to those backends that support them, or have a suitable workaround.
Expand All @@ -2727,6 +2727,9 @@ def add_element_to_window(self, element, expand, fill, pad, side='bottom'):
or go into extra padding? True, False respectfully.
pad : int
The extra amount of space in pixels to pad the element.
place : string
The location to place the element, either compass points north,
east, south, west, or center.
"""
pass

Expand Down
4 changes: 2 additions & 2 deletions 4 lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ def __init__(self, figure, num):
w = int(self.canvas.figure.bbox.width)
h = int(self.canvas.figure.bbox.height)

self.window.add_element_to_window(self.canvas, True, True, 0, 'top')
self.window.add_element_to_window(self.canvas, True, True, 0, 'center')

self.toolbar = self._get_toolbar()
if self.toolbar is not None:
h += self.window.add_element_to_window(self.toolbar,
False, False, 0, 'bottom')
False, False, 0, 'south')

self.window.set_default_size(w, h)

Expand Down
36 changes: 24 additions & 12 deletions 36 lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def stop_event_loop(self):
FigureCanvasBase.stop_event_loop_default(self)
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__

class WindowGTK3(WindowBase, Gtk.Window):
class Window(WindowBase, Gtk.Window):
Copy link
Member

Choose a reason for hiding this comment

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

Why don't keep the name something like WindowGTK3 and at the end of the file Window=WindowGTK3

Copy link
Member Author

Choose a reason for hiding this comment

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

Personally, I don't really see what difference it makes apart from taking up extra hard drive and memory space.

At the moment we have backend_gtk3.Window why do we need backend_gtk3.WindowGTK3 as well? By renaming Window to WindowGTK3 and adding Window = WindowGTK3 we create both names which as I say feels like overkill to me. Note also that under the API that we deprecate here Show also does it like this, we don't have ShowGTK3.

I don't mind renaming it, I just don't see any need for it...

Copy link
Member

Choose a reason for hiding this comment

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

I kind of agree with you, but in that case, why don't we remove all the xxxGTK3 stuff? and leave just xxx like FigureManager, Toolbar, etc...

Copy link
Member

Choose a reason for hiding this comment

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

👍 On making the GUI specific classes have the framework name in them and doing Window = WindowGTK3 at the end. It helps to keep the code a bit more organized. I have poked around in some projects that aggressively shadow names between modules and it gets bad.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess "bad" beats "ugly" (ugly in terms of a list of housekeeping aliases at end of each file. I can't imagine how it could get bad, (on the other hand I found debugging that transform logic a nightmare with multiple layers of transforms to go through and understand what they what they were doing and why they were failing), so meh.

def __init__(self, title):
WindowBase.__init__(self, title)
Gtk.Window.__init__(self)
Expand All @@ -403,22 +403,35 @@ def __init__(self, title):
# better way is - JDH
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])

self.vbox = Gtk.Box()
self.vbox.set_property('orientation', Gtk.Orientation.VERTICAL)
self.add(self.vbox)
self.vbox.show()
self._layout = {}
self._setup_box('_outer', Gtk.Orientation.VERTICAL, False, None)
self._setup_box('north', Gtk.Orientation.VERTICAL, False, '_outer')
Copy link
Member

Choose a reason for hiding this comment

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

I find it a little bit strange the nomenclature north, south, east and west. I'm more used to top, bottom, left and right, or up and down.
But maybe it's just me

Copy link
Member Author

Choose a reason for hiding this comment

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

Meh, the first programming language I learnt, Java, used this nomenclature, so does jquery (for websites, i.e. WebAgg), and also Tk. I have seen Qt use this nomenclature for tabs.

I don't mind which nomenclature, just so long as we stay clear of Parkinson's law 😉.

Also just found this (you don't need to look at it, but just leaving it here for future reference) which should help with Qt http://ftp.ics.uci.edu/pub/centos0/ics-custom-build/BUILD/PyQt-x11-gpl-4.7.2/examples/layouts/borderlayout.py

Copy link
Member

Choose a reason for hiding this comment

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

Yep, it's only me, don't worry, leave it like that

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course I only gave examples of where this nomenclature gets used, so interpret the above as having a strong confirmation bias, but I guess you don't mind either way.

self._setup_box('_middle', Gtk.Orientation.HORIZONTAL, True, '_outer')
self._setup_box('south', Gtk.Orientation.VERTICAL, False, '_outer')

self._setup_box('west', Gtk.Orientation.HORIZONTAL, False, '_middle')
self._setup_box('center', Gtk.Orientation.VERTICAL, True, '_middle')
self._setup_box('east', Gtk.Orientation.HORIZONTAL, False, '_middle')

self.add(self._layout['_outer'])

self.connect('destroy', self.destroy_event)
self.connect('delete_event', self.destroy_event)

def add_element_to_window(self, element, expand, fill, pad, side='bottom'):
def _setup_box(self, name, orientation, grow, parent):
self._layout[name] = Gtk.Box(orientation=orientation)
if parent:
self._layout[parent].pack_start(self._layout[name], grow, grow, 0)
self._layout[name].show()

def add_element_to_window(self, element, expand, fill, pad, place):
element.show()
if side == 'top':
self.vbox.pack_start(element, expand, fill, pad)
elif side == 'bottom':
self.vbox.pack_end(element, expand, fill, pad)
if place in ['north', 'west', 'center']:
self._layout[place].pack_start(element, expand, fill, pad)
elif place in ['south', 'east']:
self._layout[place].pack_end(element, expand, fill, pad)
else:
raise KeyError('Unknown value for side, %s' % side)
raise KeyError('Unknown value for place, %s' % place)
size_request = element.size_request()
return size_request.height

Expand All @@ -430,7 +443,6 @@ def show(self):
Gtk.Window.show(self)

def destroy(self):
self.vbox.destroy()
Gtk.Window.destroy(self)

def set_fullscreen(self, fullscreen):
Expand Down
2 changes: 1 addition & 1 deletion 2 lib/matplotlib/backends/backend_gtk3agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def new_figure_manager_given_figure(num, figure):

FigureCanvas = FigureCanvasGTK3Agg
FigureManager = FigureManagerGTK3Agg
Window = backend_gtk3.WindowGTK3
Window = backend_gtk3.Window
Toolbar2 = backend_gtk3.NavigationToolbar2GTK3
MainLoop = backend_gtk3.MainLoop
show = backend_gtk3.show
2 changes: 1 addition & 1 deletion 2 lib/matplotlib/backends/backend_gtk3cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def new_figure_manager_given_figure(num, figure):

FigureCanvas = FigureCanvasGTK3Cairo
FigureManager = FigureManagerGTK3Cairo
Window = backend_gtk3.WindowGTK3
Window = backend_gtk3.Window
Toolbar2 = backend_gtk3.NavigationToolbar2GTK3
MainLoop = backend_gtk3.MainLoop
show = backend_gtk3.show
Morty Proxy This is a proxified and sanitized view of the page, visit original site.