MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / add_toolitem

Method add_toolitem

lib/matplotlib/backends/backend_wx.py:1222–1265  ·  view source on GitHub ↗
(self, name, group, position, image_file, description,
                     toggle)

Source from the content-addressed store, hash-verified

1220 return pos
1221
1222 def add_toolitem(self, name, group, position, image_file, description,
1223 toggle):
1224 # Find or create the separator that follows this group.
1225 if group not in self._groups:
1226 self._groups[group] = self.InsertSeparator(
1227 self._get_tool_pos(self._space))
1228 sep = self._groups[group]
1229 # List all separators.
1230 seps = [t for t in map(self.GetToolByPos, range(self.ToolsCount))
1231 if t.IsSeparator() and not t.IsStretchableSpace()]
1232 # Find where to insert the tool.
1233 if position >= 0:
1234 # Find the start of the group by looking for the separator
1235 # preceding this one; then move forward from it.
1236 start = (0 if sep == seps[0]
1237 else self._get_tool_pos(seps[seps.index(sep) - 1]) + 1)
1238 else:
1239 # Move backwards from this separator.
1240 start = self._get_tool_pos(sep) + 1
1241 idx = start + position
1242 if image_file:
1243 bmp = NavigationToolbar2Wx._icon(image_file)
1244 kind = wx.ITEM_NORMAL if not toggle else wx.ITEM_CHECK
1245 tool = self.InsertTool(idx, -1, name, bmp, wx.NullBitmap, kind,
1246 description or "")
1247 else:
1248 size = (self.GetTextExtent(name)[0] + 10, -1)
1249 if toggle:
1250 control = wx.ToggleButton(self, -1, name, size=size)
1251 else:
1252 control = wx.Button(self, -1, name, size=size)
1253 tool = self.InsertControl(idx, control, label=name)
1254 self.Realize()
1255
1256 def handler(event):
1257 self.trigger_tool(name)
1258
1259 if image_file:
1260 self.Bind(wx.EVT_TOOL, handler, tool)
1261 else:
1262 control.Bind(wx.EVT_LEFT_DOWN, handler)
1263
1264 self._toolitems.setdefault(name, [])
1265 self._toolitems[name].append((tool, handler))
1266
1267 def toggle_toolitem(self, name, toggled):
1268 if name not in self._toolitems:

Callers

nothing calls this directly

Calls 3

_get_tool_posMethod · 0.95
indexMethod · 0.80
_iconMethod · 0.45

Tested by

no test coverage detected