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
Prev Previous commit
Next Next commit
Adding passthought **kwargs to add_tool, default value for buttons no…
…w in ToolBase
  • Loading branch information
fariza committed Oct 23, 2013
commit a582aeb962c886914fc376a85e0f1aeec2d59a70
82 changes: 52 additions & 30 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ def destroy(self):
self.toolbar.remove()

def resize(self, w, h):
self.parent.resize_manager(self, w, h)
self.parent.resize_child(self, w, h)

def show_popup(self, msg):
self.parent.show_popup(self, msg)
Expand Down Expand Up @@ -3396,15 +3396,12 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
self.ctx.rectangle(rect[0], rect[1], rect[2], rect[3])
self.ctx.set_source_rgb(0, 0, 0)
self.ctx.stroke()

def add_tool(self, *args, **kwargs):
self.parent.add_tool(*args, **kwargs)

def remove_tool(self, pos):
self.parent.remove_tool(pos)

def move_tool(self, pos_ini, pos_fin):
self.parent.move_tool(pos_ini, pos_fin)
def __getattr__(self, name):
#we suposse everything else that we want from this child
#belongs into the parent
return getattr(self.parent, name)



class MultiFigureToolbarBase(object):
Expand Down Expand Up @@ -3482,19 +3479,35 @@ def __init__(self):
self._current = None


def add_tool(self, callback, pos=0, **kwargs):
def add_tool(self, callback, **kwargs):
#this method called from the exterior and from the interior
#will add a tool to the toolbar
#this tool, will behave like normal button
#the first time it is clicked, it will get all the figures
#after that, if it is clicked again, it will call the show method
#if _current changes (switch the active figure from the manager)
#the set_figures method is invoked again
tbutton = self.add_button(pos=pos, **kwargs)

cls = self._get_cls_to_instantiate(callback)
if not cls:
self.set_message('Not available')
return

#if not passed directly from the call, look for them in the class
text = kwargs.pop('text', cls.text)
tooltip_text = kwargs.pop('tooltip_text', cls.tooltip_text)
pos = kwargs.pop('pos', cls.pos)
image = kwargs.pop('image', cls.image)
toggle = kwargs.pop('toggle', cls.toggle)

tbutton = self.add_button(pos=pos, text=text,
tooltip_text=tooltip_text,
image=image,
toggle=toggle)
if not tbutton:
return

self.connect_button(tbutton, 'clicked', '_external_callback', callback)
self.connect_button(tbutton, 'clicked', '_external_callback', cls, **kwargs)

def remove_tool(self, pos):
#remote item from the toolbar,
Expand All @@ -3504,23 +3517,21 @@ def move_tool(self, pos_ini, pos_fin):
#move item in the toolbar
pass

def connect_button(self, button, action, callback, *args):
def connect_button(self, button, action, callback, *args, **kwargs):
#This is specific to each library,
#The idea is to get rid of different formating between libraries and
#be able to call internal functions with clicks, selects, etc...
#
#In Gtk for example
#def connect_button(self, button, action, callback, *args):
# def mcallback(btn, *args):
# cb = args[0]
# other = args[1:]
# getattr(self, cb)(*other)
#In Gtk3 for example
#def connect_button(self, button, action, callback, *args, **kwargs):
# def mcallback(btn, cb, args, kwargs):
# getattr(self, cb)(*args, **kwargs)
#
# button.connect(action, mcallback, callback, *args)

# button.connect(action, mcallback, callback, args, kwargs)
raise NotImplementedError

def _external_callback(self, callback):
def _external_callback(self, callback, **kwargs):
#This handles the invokation of external classes
#this callback class should take only *figures as arguments
#and preform its work on those figures
Expand All @@ -3534,12 +3545,8 @@ def _external_callback(self, callback):
return

figures = self.get_figures()
cls = self._get_cls_to_instantiate(callback)
if not cls:
self.set_message('Not available')
return

external_instance = cls(*figures)
external_instance = callback(*figures, **kwargs)

self._external_instances[id_] = external_instance

Expand Down Expand Up @@ -3637,17 +3644,32 @@ def add_message(self):
#it may cause problems with the space too reduced
pass


class ToolBase(object):
#basic structure for the external tools that work with
#multi-figure-toolbar
def __init__(self, *figures):
self.init_tool()

#Default values for the tool when added to the toolbar
pos=-1
text='_'
tooltip_text=''
image=None
toggle=False

#Be careful with this arguments,
#when adding the tool to the toolbar, we make sure to pass *figures and **kwargs from
#the user
def __init__(self, *figures, **kwargs):
self.init_tool(**kwargs)

if figures:
self.set_figures(*figures)

def init_tool(self):
def init_tool(self, **kwargs):
#do some initialization work as create windows and stuff
#kwargs are the keyword paramters given by the user
if kwargs:
raise TypeError('init_tool() got an unexpected keyword arguments %s' % str(kwargs))
pass

def set_figures(self, *figures):
Expand Down
10 changes: 4 additions & 6 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,13 +824,11 @@ def __init__(self, window):
self.win = window
MultiFigureToolbarBase.__init__(self)

def connect_button(self, button, action, callback, *args):
def mcallback(btn, *args):
cb = args[0]
other = args[1:]
getattr(self, cb)(*other)
def connect_button(self, button, action, callback, *args, **kwargs):
def mcallback(btn, cb, args, kwargs):
getattr(self, cb)(*args, **kwargs)

button.connect(action, mcallback, callback, *args)
button.connect(action, mcallback, callback, args, kwargs)

def add_button(self, text='_', pos=-1,
tooltip_text='', image=None,
Expand Down