Skip to content

Commit bc17372

Browse files
OceanWolftacaswell
authored andcommitted
Improve layout!
1 parent 1a47d3b commit bc17372

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
@@ -2749,7 +2749,7 @@ def set_window_title(self, title):
27492749
"""
27502750
pass
27512751

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

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
@@ -372,7 +372,7 @@ def stop_event_loop(self):
372372
FigureCanvasBase.stop_event_loop_default(self)
373373
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
374374

375-
class WindowGTK3(WindowBase, Gtk.Window):
375+
class Window(WindowBase, Gtk.Window):
376376
def __init__(self, title):
377377
WindowBase.__init__(self, title)
378378
Gtk.Window.__init__(self)
@@ -390,22 +390,35 @@ def __init__(self, title):
390390
# better way is - JDH
391391
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])
392392

393-
self.vbox = Gtk.Box()
394-
self.vbox.set_property('orientation', Gtk.Orientation.VERTICAL)
395-
self.add(self.vbox)
396-
self.vbox.show()
393+
self._layout = {}
394+
self._setup_box('_outer', Gtk.Orientation.VERTICAL, False, None)
395+
self._setup_box('north', Gtk.Orientation.VERTICAL, False, '_outer')
396+
self._setup_box('_middle', Gtk.Orientation.HORIZONTAL, True, '_outer')
397+
self._setup_box('south', Gtk.Orientation.VERTICAL, False, '_outer')
398+
399+
self._setup_box('west', Gtk.Orientation.HORIZONTAL, False, '_middle')
400+
self._setup_box('center', Gtk.Orientation.VERTICAL, True, '_middle')
401+
self._setup_box('east', Gtk.Orientation.HORIZONTAL, False, '_middle')
402+
403+
self.add(self._layout['_outer'])
397404

398405
self.connect('destroy', self.destroy_event)
399406
self.connect('delete_event', self.destroy_event)
400407

401-
def add_element_to_window(self, element, expand, fill, pad, side='bottom'):
408+
def _setup_box(self, name, orientation, grow, parent):
409+
self._layout[name] = Gtk.Box(orientation=orientation)
410+
if parent:
411+
self._layout[parent].pack_start(self._layout[name], grow, grow, 0)
412+
self._layout[name].show()
413+
414+
def add_element_to_window(self, element, expand, fill, pad, place):
402415
element.show()
403-
if side == 'top':
404-
self.vbox.pack_start(element, expand, fill, pad)
405-
elif side == 'bottom':
406-
self.vbox.pack_end(element, expand, fill, pad)
416+
if place in ['north', 'west', 'center']:
417+
self._layout[place].pack_start(element, expand, fill, pad)
418+
elif place in ['south', 'east']:
419+
self._layout[place].pack_end(element, expand, fill, pad)
407420
else:
408-
raise KeyError('Unknown value for side, %s' % side)
421+
raise KeyError('Unknown value for place, %s' % place)
409422
size_request = element.size_request()
410423
return size_request.height
411424

@@ -417,7 +430,6 @@ def show(self):
417430
Gtk.Window.show(self)
418431

419432
def destroy(self):
420-
self.vbox.destroy()
421433
Gtk.Window.destroy(self)
422434

423435
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)