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

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
01b0e78
refactoring FigureManagerBase to include include self in all calls to…
fariza Sep 12, 2013
ec262ad
Modified to use container for figure managers and for toolbars
fariza Sep 13, 2013
4e1d8c4
Adding standaone savefiguredialog
fariza Sep 15, 2013
a7e9968
Subplot tool and save as external clasess, working on weakref to keep…
fariza Sep 15, 2013
6c13b83
Added external buttons, trying to figure out how to keep track of them
fariza Sep 16, 2013
61d8427
Cleanup, commit to show what can be done
fariza Sep 17, 2013
b9204e5
Forgot to include external button
fariza Sep 17, 2013
0f6023e
Placing stuff in backend_bases.py and renaming rc param to single_window
fariza Sep 18, 2013
b48e903
renaming rcparam in demo
fariza Sep 18, 2013
a7ab976
adding remove_tool and move_tool
fariza Sep 18, 2013
a582aeb
Adding passthought **kwargs to add_tool, default value for buttons no…
fariza Sep 19, 2013
375f32e
adding tool for lineproperties
fariza Sep 20, 2013
5ec539f
adding saveall images from http://openiconlibrary.sourceforge.net/gal…
fariza Sep 24, 2013
ecd3c91
Adding image to saveall tool, changing order to have saveall side to …
fariza Sep 25, 2013
0f3abfe
Fixing new buttons not showing after toolbar init
fariza Sep 26, 2013
a6bc104
Saveall image uses same original filesave, the colors and motive match
fariza Sep 26, 2013
2c06a64
rebase for review
fariza Oct 23, 2013
cf80c97
pep8 correction
fariza Oct 23, 2013
7033c46
removing backedn_gtk3cairo.py from test_coding_standards
fariza Oct 23, 2013
84a1911
splitting toolbar and figuremanager examples
fariza Oct 28, 2013
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
Next Next commit
refactoring FigureManagerBase to include include self in all calls to…
… parent
  • Loading branch information
fariza committed Oct 23, 2013
commit 01b0e784d4fffc297cc85704ba1f7fdaa4e75e9e
233 changes: 232 additions & 1 deletion lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def stop_event_loop(self):

FigureCanvas = FigureCanvasGTK3

class FigureManagerGTK3(FigureManagerBase):
class SingleFigureManagerGTK3(FigureManagerBase):
"""
Public attributes

Expand Down Expand Up @@ -476,6 +476,237 @@ def resize(self, width, height):
self.window.resize(width, height)


class FigureManagerBase2(FigureManagerBase):
def __init__(self, parent, canvas, num):
FigureManagerBase.__init__(self, canvas, num)
self.parent = parent

def show(self):
try:
self.parent.show(self)
except AttributeError:
pass

def destroy(self):
try:
self.parent.destroy(self)
except AttributeError:
pass

def full_screen_toggle(self):
try:
self.parent.full_screen_toggle(self)
except AttributeError:
pass

def resize(self, w, h):
try:
self.parent.resize(self, w, h)
except AttributeError:
pass

# def key_press(self, event):
# key_press_handler(event, self.canvas, self.canvas.toolbar)

def show_popup(self, msg):
try:
self.parent.show_popup(self, msg)
except AttributeError:
pass

def get_window_title(self):
try:
self.parent.get_window_title(self)
except AttributeError:
return 'image'

def set_window_title(self, title):
try:
self.parent.set_window_title(self.title)
except AttributeError:
pass

class TabbedFigureManagerGTK3(FigureManagerBase):
_canvas = {}
_labels = {}
_w_min = 0
_h_min = 0
_managers = {}
def __init__(self, *args):
print ('calling init', args)

self.window = Gtk.Window()
self.set_window_title("Figuremanager")
try:
self.window.set_icon_from_file(window_icon)
except (SystemExit, KeyboardInterrupt):
# re-raise exit type Exceptions
raise
except:
# some versions of gtk throw a glib.GError but not
# all, so I am not sure how to catch it. I am unhappy
# doing a blanket catch here, but am not sure what a
# 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.vbox.show()

self.notebook = Gtk.Notebook()

self.notebook.set_scrollable(True)
vp = Gtk.Viewport()
vp.add(self.notebook)
self.vbox.pack_start(vp, True, True, 0)
# self.vbox.pack_start(self.notebook, True, True, 0)
self.window.add(self.vbox)

self.notebook.connect('switch-page', self._on_switch_page)




self.toolbar = self._get_toolbar()

if self.toolbar is not None:
self.toolbar.show()
self.vbox.pack_end(self.toolbar, False, False, 0)

size_request = self.window.size_request()
self._h_def = size_request.height
self._w_def = size_request.width


def destroy_window(*args):
for num in self._canvas.keys():
Gcf.destroy(num)
self.window.connect("destroy", destroy_window)
self.window.connect("delete_event", destroy_window)

self.vbox.show_all()

if matplotlib.is_interactive():
self.window.show()



def destroy(self, *args):
if _debug: print('FigureManagerGTK3.%s' % fn_name())
if not self._canvas:
self.vbox.destroy()
self.window.destroy()
if self.toolbar:
self.toolbar.destroy()
#
if Gcf.get_num_fig_managers() == 0 and \
not matplotlib.is_interactive() and \
Gtk.main_level() >= 1:
Gtk.main_quit()

def _on_remove_canvas(self, btn, num):

canvas = self._canvas[num]
id_ = self.notebook.page_num(canvas)
if id_ > -1:
del self._canvas[num]
del self._labels[num]
self.notebook.remove_page(id_)
Gcf.destroy(num)

def set_window_title(self, title):
pass

def _on_switch_page(self, *args):
pass

def _get_toolbar(self):
# must be inited after the window, drawingArea and figure
# attrs are set
if rcParams['toolbar'] == 'toolbar2':
# toolbar = NavigationToolbar2GTK3 (canvas, self.window)
toolbar = None
else:
toolbar = None
return toolbar

def _add_canvas(self, canvas, num):
#I don't like to call init of the base several times,
#I could just set the variables that it needs and never call init....
FigureManagerBase.__init__(self, canvas, num)

manager = FigureManagerBase2(self, canvas, num)



title = 'Fig %d' % num
box = Gtk.Box()
box.set_orientation(Gtk.Orientation.HORIZONTAL)
box.set_spacing(5)

label = Gtk.Label(title)
box.pack_start(label, True, True, 0)

# close button
button = Gtk.Button()

button.set_relief(Gtk.ReliefStyle.NONE)
button.set_focus_on_click(False)
button.add(Gtk.Image.new_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU))



box.pack_end(button, False, False, 0)

box.show_all()
self.notebook.append_page(canvas, box)
canvas.show()

button.connect("clicked", self._on_remove_canvas, num)

self._canvas[num] = canvas
self._labels[num] = label


# calculate size for window
w = int (self.canvas.figure.bbox.width)
h = int (self.canvas.figure.bbox.height)

if w > self._w_min:
self._w_min = w
if h > self._h_min:
self._h_min = h


self.window.set_default_size (self._w_def + self._w_min, self._h_def + self._h_min)

if self.toolbar:
self.toolbar.add_canvas(canvas)

def notify_axes_change(fig):
'this will be called whenever the current axes is changed'
if self.toolbar is not None: self.toolbar.update()
self.canvas.figure.add_axobserver(notify_axes_change)

self.canvas.grab_focus()

def show(self):
# show the figure window
self.window.show()


def __call__(self, canvas, num):
self._add_canvas(canvas, num)
return self


if rcParams['backend.gtk3.tabbed']:
FigureManagerGTK3 = TabbedFigureManagerGTK3()
else:
FigureManagerGTK3 = SingleFigureManagerGTK3



class NavigationToolbar2GTK3(NavigationToolbar2, Gtk.Toolbar):
def __init__(self, canvas, window):
self.win = window
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_gtk3cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def on_draw_event(self, widget, ctx):
return False # finish event propagation?


class FigureManagerGTK3Cairo(backend_gtk3.FigureManagerGTK3):
pass

#class FigureManagerGTK3Cairo(backend_gtk3.FigureManagerGTK3):
# pass
FigureManagerGTK3Cairo = backend_gtk3.FigureManagerGTK3

def new_figure_manager(num, *args, **kwargs):
"""
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ def __call__(self, s):
# present
'backend_fallback': [True, validate_bool], # agg is certainly present
'backend.qt4': ['PyQt4', validate_qt4],
'backend.gtk3.tabbed': [False, validate_bool],
'webagg.port': [8988, validate_int],
'webagg.open_in_browser': [True, validate_bool],
'webagg.port_retries': [50, validate_int],
Expand Down
5 changes: 5 additions & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ backend : %(backend)s
# the underlying Qt4 toolkit.
#backend.qt4 : PyQt4 # PyQt4 | PySide

# If you are using one of the GTK3 backends (GTK3Agg or GTK3Cairo)
# you can set to use only one window with tabbed figures instead of
# multiple windows one for each figure
#backend.gtk3.tabbed : True

# Note that this can be overridden by the environment variable
# QT_API used by Enthought Tool Suite (ETS); valid values are
# "pyqt" and "pyside". The "pyqt" setting has the side effect of
Expand Down