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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
8cceed4
navigation and toolbar coexistence
fariza Jan 23, 2014
3118a5a
mod keypress in figuremanager
fariza Jan 23, 2014
b4d5fcf
helper methods in toolbar and navigation
fariza Jan 24, 2014
1e8af47
Adding doc to base methods
fariza Jan 24, 2014
622cb95
property for active_toggle
fariza Jan 26, 2014
d1a9de4
simulate click
fariza Jan 27, 2014
3f89d52
activate renamed to trigger
fariza Jan 28, 2014
4f3c10b
toggle tools using enable/disable from its trigger method
fariza Jan 29, 2014
6065daa
simplifying _handle_toggle
fariza Jan 29, 2014
f6a2f19
reducing number of locks
fariza Jan 29, 2014
05db3b6
changing toggle and persistent attributes for issubclass
fariza Feb 4, 2014
c08fe56
bug in combined key press
fariza Feb 4, 2014
b207a72
untoggle zoom and pan from keypress while toggled
fariza Feb 4, 2014
9266447
classmethods for default tools modification
fariza Feb 6, 2014
a53419a
adding zaxis and some pep8
fariza May 1, 2014
704c717
removing legacy method dynamic update
fariza May 6, 2014
5056729
tk backend
fariza May 6, 2014
e6a4e1e
example working with Tk
fariza May 6, 2014
8942c47
duplicate code in keymap tool initialization
fariza Jul 24, 2014
022de6f
grammar corrections
fariza Jul 24, 2014
2c9a195
moving views and positions to tools
fariza Jul 24, 2014
cafe668
The views positions mixin automatically adds the clear as axobserver
fariza Jul 25, 2014
224f745
bug when navigation was not defined
fariza Jul 25, 2014
94c711e
Small refactor so that we first initiate the Navigation (ToolManager)…
OceanWolf Jul 28, 2014
67257e7
Moved default_tool initilisation to FigureManagerBase and cleaned.
OceanWolf Jul 29, 2014
ffa65d6
Temporary fix to backends
OceanWolf Jul 29, 2014
6739ee0
removing persistent tools
fariza Sep 3, 2014
d18206f
removing unregister
fariza Sep 4, 2014
34a52c8
change cursor inmediately after toggle
fariza Sep 5, 2014
c2da483
removing intoolbar
fariza Oct 15, 2014
44a9b0e
events working
fariza Oct 16, 2014
a2ed47f
using pydispatch
fariza Oct 17, 2014
0665890
using navigation as signal handler
fariza Oct 20, 2014
411e6e2
removing view positions singleton
fariza Oct 20, 2014
d484ebd
moving set_cursor completely out of navigation
fariza Oct 27, 2014
75bf97b
removing unused event class
fariza Nov 10, 2014
6cc040b
underscore in tool_trigger-xxx
fariza Nov 10, 2014
0ff5997
adding radio_group for toggle tools
fariza Nov 14, 2014
af6734f
scroll to zoom in zoom/pan tools
fariza Nov 28, 2014
78513d2
remove ToolAddedEvent incorporating the functionality into toolevent
fariza Dec 5, 2014
377ff54
eliminating repeated loop
fariza Jan 5, 2015
7dbbf58
replace draw by draw_idle in tools
fariza Jan 21, 2015
dd66b57
rename mpl_connect
fariza Jan 21, 2015
67a414f
cleaning navigation and toolbar dependencies
fariza Feb 4, 2015
e415d8d
Made NavigationBase.get_tool() more useful.
OceanWolf Feb 11, 2015
1213086
Refactored Toolbar out of NavigationBase
OceanWolf Feb 12, 2015
ba61dec
Some short cuts for adding tools
OceanWolf Feb 16, 2015
9f2ee2b
Lots of fixes
OceanWolf Feb 18, 2015
9da2b13
Rename ToolbarBase -> ToolContainerBase
OceanWolf Feb 18, 2015
110253f
Statusbar
OceanWolf Feb 20, 2015
e2804ea
tool group position
fariza Feb 26, 2015
9a64b7e
docstrings and small corrections by WeatherGod
fariza Mar 23, 2015
64f947f
tkbackend updated
fariza Mar 31, 2015
e8cd5d5
tacaswell comments aprl 1
fariza Apr 1, 2015
4bbcf4e
renaming tool_trigger_event
fariza Apr 1, 2015
73a2661
add_tools moved out of base classes
fariza Apr 1, 2015
1b83628
figure.setter in tools
fariza Apr 1, 2015
e4edd23
rename tools to default_tools to avoid confusion
fariza Apr 1, 2015
d4ac2fb
docstring helper add_tools methods
fariza Apr 1, 2015
a7640ef
rename navigation to toolmanager
fariza Apr 2, 2015
48a6971
tkagg updated for toolmanager and tool groups
fariza Apr 2, 2015
8dafe09
doc and minor code organization
fariza Apr 2, 2015
a0695d0
whats new
fariza Apr 3, 2015
328b169
missing object from class declaration
fariza Apr 3, 2015
aac4744
remove comments and docstrings
fariza Apr 3, 2015
f09b9ef
import with original name backend_tools
fariza Apr 3, 2015
def3a52
rename 2 -> to, example without gtk only code
fariza Apr 7, 2015
9ee7e25
zoom pan buttons order
fariza Apr 7, 2015
5eae4e1
matplotlib.rcParams['toolbar'] == 'None' starts toolmanager but not t…
fariza Apr 7, 2015
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
helper methods in toolbar and navigation
  • Loading branch information
fariza committed Apr 7, 2015
commit b4d5fcf0479986ca4c31af3842a7f82294aedaed
40 changes: 38 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3228,8 +3228,10 @@ class NavigationBase(object):
tools.ToolToggleYScale,
tools.ToolHome, tools.ToolBack,
tools.ToolForward,
None,
tools.ToolZoom,
tools.ToolPan,
None,
'ConfigureSubplots',
'SaveFigure']

Expand Down Expand Up @@ -3266,7 +3268,11 @@ def __init__(self, canvas, toolbar=None):
self.canvaslock = self.canvas.widgetlock

for tool in self._default_tools:
self.add_tool(tool)
if tool is None:
if self.toolbar is not None:
self.toolbar.add_separator(-1)
else:
self.add_tool(tool)

self._last_cursor = self._default_cursor

Expand All @@ -3279,7 +3285,28 @@ def _get_toolbar(self, toolbar, canvas):
toolbar = None
return toolbar

#remove persistent instances
def get_active(self):
return {'toggled': self._toggled, 'instances': self._instances.keys()}

def get_tool_keymap(self, name):
keys = [k for k, i in self._keys.items() if i == name]
return keys

def set_tool_keymap(self, name, *keys):
if name not in self._tools:
raise AttributeError('%s not in Tools' % name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This isn't really an AttributeError, is it? Would seem more like a KeyError.


active_keys = [k for k, i in self._keys.items() if i == name]
for k in active_keys:
del self._keys[k]

for key in keys:
for k in validate_stringlist(key):
if k in self._keys:
warnings.warn('Key %s changed from %s to %s' %
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An alternative is to have an overwrite=False kwarg which sets if this raises or silently overwrites.

I started out typing this comment strongly in favor of that, but than half talked my self out of it.

The downside of warnings is that many users don't read them as closely as they should and even if you see and read the warning, if it is coming out of a massive pile of code it gives little indication of where the issue is.

The downside of the raise/silent option is that either it is super annoying when a key you don't care about getting reset either kills your program or a key you really care about is silently remapped.

By the time I finished typing this out I think that warning is on balance better, but leaving this comment anyway.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand your point, but imho, if you really care about a key, you can remap it back later, those who care would take the time to remap it back later, and look to the console to figure out what happened.

Alternatives: with an overwrite=False kwarg, I would have thought it better that if True it overwrites; if False it keeps the existing key, both with warning messages. I think this sits happier with me because it gives an extra feature, rather than adding a show-stopper.

Alternative 2: For a later PR, I think we can add a tool to change the keymaps from the UI. After MEP27 I will come back to the subplots tool to make this dialog use the new WindowBase, eliminating the need for separate backends. If this remap tool needs a dialog then I will do that then.

Finally, about warnings.warn, I have misgivings about the use of this:

  1. It only shows a string once, i.e. here it will only report the first change of that this key got changed from toolA to toolB, annoying when trying to figure out what happened during debug.
  2. As I refactor webagg, I realise that afaik, warning.warn would print to the terminal, i.e. the server, instead of the client, a.k.a user who may well exist as two different people. The only problem here lies in that this opens up a whole new can of worms about messages (do we print to the GUI message area, do we print to terminal, do we print to both, do we need message-types to help determine that, what should they look like etcetera) so I feel this discussion should probably happen later, perhaps even in its own MEP.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the inability to see print statements in callbacks is my greatest frustration with nbagg right now...

(k, self._keys[k], name))
self._keys[k] = name

def unregister(self, name):
if self._toggled == name:
self._handle_toggle(name, from_toolbar=False)
Expand Down Expand Up @@ -3310,6 +3337,9 @@ def add_tool(self, callback_class):
self._tools[name] = tool
if tool.keymap is not None:
for k in validate_stringlist(tool.keymap):
if k in self._keys:
warnings.warn('Key %s changed from %s to %s' %
(k, self._keys[k], name))
self._keys[k] = name

if self.toolbar and tool.position is not None:
Expand Down Expand Up @@ -3573,3 +3603,9 @@ def toggle(self, name, callback=False):

def remove_toolitem(self, name):
pass

def move_toolitem(self, pos_ini, pos_fin):
pass

def set_toolitem_visibility(self, name, visible):
pass
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def activate(self, event):
class ToolEnableNavigation(ToolBase):
name = 'EnableOne'
description = 'Enables one axes navigation'
keymap = range(1, 5)
keymap = range(1, 10)

def activate(self, event):
if event.inaxes is None:
Expand Down
26 changes: 22 additions & 4 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,7 @@ def set_message(self, s):

def toggle(self, name, callback=False):
if name not in self._toolitems:
# TODO: raise a warning
print('Not in toolbar', name)
self.set_message('%s Not in toolbar' % name)
return

status = self._toolitems[name].get_active()
Expand All @@ -822,12 +821,31 @@ def toggle(self, name, callback=False):

def remove_toolitem(self, name):
if name not in self._toolitems:
#TODO: raise warning
print('Not in toolbar', name)
self.set_message('%s Not in toolbar' % name)
return
self._toolbar.remove(self._toolitems[name])
del self._toolitems[name]

def add_separator(self, pos=-1):
toolitem = Gtk.SeparatorToolItem()
self._toolbar.insert(toolitem, pos)
toolitem.show()
return toolitem

def move_toolitem(self, pos_ini, pos_fin):
widget = self._toolbar.get_nth_item(pos_ini)
if not widget:
self.set_message('Impossible to remove tool %d' % pos_ini)
return
self._toolbar.remove(widget)
self._toolbar.insert(widget, pos_fin)

def set_toolitem_visibility(self, name, visible):
if name not in self._toolitems:
self.set_message('%s Not in toolbar' % name)
return
self._toolitems[name].set_visible(visible)


class SaveFigureGTK3(SaveFigureBase):

Expand Down