Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed16178

Browse files
committed
Improve layout!
1 parent 494e5f1 commit ed16178

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,7 +2710,7 @@ def set_window_title(self, title):
27102710
"""
27112711
pass
27122712

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

lib/matplotlib/backend_managers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ def __init__(self, figure, num):
8484
w = int(self.canvas.figure.bbox.width)
8585
h = int(self.canvas.figure.bbox.height)
8686

87-
self.window.add_element_to_window(self.canvas, True, True, 0, 'top')
87+
self.window.add_element_to_window(self.canvas, True, True, 0, 'center')
8888

8989
self.toolbar = self._get_toolbar()
9090
if self.toolbar is not None:
9191
h += self.window.add_element_to_window(self.toolbar,
92-
False, False, 0, 'bottom')
92+
False, False, 0, 'south')
9393

9494
self.window.set_default_size(w, h)
9595

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def stop_event_loop(self):
385385
FigureCanvasBase.stop_event_loop_default(self)
386386
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
387387

388-
class WindowGTK3(WindowBase, Gtk.Window):
388+
class Window(WindowBase, Gtk.Window):
389389
def __init__(self, title):
390390
WindowBase.__init__(self, title)
391391
Gtk.Window.__init__(self)
@@ -403,22 +403,35 @@ def __init__(self, title):
403403
# better way is - JDH
404404
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])
405405

406-
self.vbox = Gtk.Box()
407-
self.vbox.set_property('orientation', Gtk.Orientation.VERTICAL)
408-
self.add(self.vbox)
409-
self.vbox.show()
406+
self._layout = {}
407+
self._setup_box('_outer', Gtk.Orientation.VERTICAL, False, None)
408+
self._setup_box('north', Gtk.Orientation.VERTICAL, False, '_outer')
409+
self._setup_box('_middle', Gtk.Orientation.HORIZONTAL, True, '_outer')
410+
self._setup_box('south', Gtk.Orientation.VERTICAL, False, '_outer')
411+
412+
self._setup_box('west', Gtk.Orientation.HORIZONTAL, False, '_middle')
413+
self._setup_box('center', Gtk.Orientation.VERTICAL, True, '_middle')
414+
self._setup_box('east', Gtk.Orientation.HORIZONTAL, False, '_middle')
415+
416+
self.add(self._layout['_outer'])
410417

411418
self.connect('destroy', self.destroy_event)
412419
self.connect('delete_event', self.destroy_event)
413420

414-
def add_element_to_window(self, element, expand, fill, pad, side='bottom'):
421+
def _setup_box(self, name, orientation, grow, parent):
422+
self._layout[name] = Gtk.Box(orientation=orientation)
423+
if parent:
424+
self._layout[parent].pack_start(self._layout[name], grow, grow, 0)
425+
self._layout[name].show()
426+
427+
def add_element_to_window(self, element, expand, fill, pad, place):
415428
element.show()
416-
if side == 'top':
417-
self.vbox.pack_start(element, expand, fill, pad)
418-
elif side == 'bottom':
419-
self.vbox.pack_end(element, expand, fill, pad)
429+
if place in ['north', 'west', 'center']:
430+
self._layout[place].pack_start(element, expand, fill, pad)
431+
elif place in ['south', 'east']:
432+
self._layout[place].pack_end(element, expand, fill, pad)
420433
else:
421-
raise KeyError('Unknown value for side, %s' % side)
434+
raise KeyError('Unknown value for place, %s' % place)
422435
size_request = element.size_request()
423436
return size_request.height
424437

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

432445
def destroy(self):
433-
self.vbox.destroy()
434446
Gtk.Window.destroy(self)
435447

436448
def set_fullscreen(self, fullscreen):

lib/matplotlib/backends/backend_gtk3agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def new_figure_manager_given_figure(num, figure):
121121

122122
FigureCanvas = FigureCanvasGTK3Agg
123123
FigureManager = FigureManagerGTK3Agg
124-
Window = backend_gtk3.WindowGTK3
124+
Window = backend_gtk3.Window
125125
Toolbar2 = backend_gtk3.NavigationToolbar2GTK3
126126
MainLoop = backend_gtk3.MainLoop
127127
show = backend_gtk3.show

lib/matplotlib/backends/backend_gtk3cairo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def new_figure_manager_given_figure(num, figure):
7272

7373
FigureCanvas = FigureCanvasGTK3Cairo
7474
FigureManager = FigureManagerGTK3Cairo
75-
Window = backend_gtk3.WindowGTK3
75+
Window = backend_gtk3.Window
7676
Toolbar2 = backend_gtk3.NavigationToolbar2GTK3
7777
MainLoop = backend_gtk3.MainLoop
7878
show = backend_gtk3.show

0 commit comments

Comments
 (0)