def test_callbackregistry_default_exception_handler(capsys, monkeypatch): cb = cbook.CallbackRegistry() cb.connect("foo", lambda: None) monkeypatch.setattr(cbook, "_get_running_interactive_framework", lambda: None) with pytest.raises(TypeError): cb.process("foo", "argument mismatch") outerr = capsys.readouterr() assert outerr.out == outerr.err == "" monkeypatch.setattr(cbook, "_get_running_interactive_framework", lambda: "not-none") cb.process("foo", "argument mismatch") # No error in that case. outerr = capsys.readouterr() assert outerr.out == "" assert "takes 0 positional arguments but 1 was given" in outerr.err
def __init__(self, norm=None, cmap=None): """ *norm* is an instance of :class:`colors.Normalize` or one of its subclasses, used to map luminance to 0-1. *cmap* is a :mod:`cm` colormap instance, for example :data:`cm.jet` """ self.callbacksSM = cbook.CallbackRegistry(('changed', )) if cmap is None: cmap = get_cmap() if norm is None: norm = colors.Normalize() self._A = None self.norm = norm self.cmap = cmap self.colorbar = None self.update_dict = {'array': False}
def __init__(self, figure=None): warnings.warn('Treat the new Tool classes introduced in v1.5 as ' + 'experimental for now, the API will likely change in ' + 'version 2.1 and perhaps the rcParam as well') self._key_press_handler_id = None self._tools = {} self._keys = {} self._toggled = {} self._callbacks = cbook.CallbackRegistry() # to process keypress event self.keypresslock = widgets.LockDraw() self.messagelock = widgets.LockDraw() self._figure = None self.set_figure(figure)
def __init__(self, norm=None, cmap=None): """ Parameters ---------- norm : `matplotlib.colors.Normalize` (or subclass thereof) The normalizing object which scales data, typically into the interval ``[0, 1]``. If *None*, *norm* defaults to a *colors.Normalize* object which initializes its scaling based on the first data processed. cmap : str or `~matplotlib.colors.Colormap` The colormap used to map normalized data values to RGBA colors. """ self._A = None self.norm = None # So that the setter knows we're initializing. self.set_norm(norm) # The Normalize instance of this ScalarMappable. self.cmap = None # So that the setter knows we're initializing. self.set_cmap(cmap) # The Colormap instance of this ScalarMappable. #: The last colorbar associated with this ScalarMappable. May be None. self.colorbar = None self.callbacksSM = cbook.CallbackRegistry()
def __init__( self, ax, orientation, closedmin, closedmax, valmin, valmax, valfmt, dragging, valstep ): if ax.name == "3d": raise ValueError("Sliders cannot be added to 3D Axes") super().__init__(ax) self.orientation = orientation self.closedmin = closedmin self.closedmax = closedmax self.valmin = valmin self.valmax = valmax self.valstep = valstep self.drag_active = False self.valfmt = valfmt if orientation == "vertical": ax.set_ylim((valmin, valmax)) axis = ax.yaxis else: ax.set_xlim((valmin, valmax)) axis = ax.xaxis self._fmt = axis.get_major_formatter() if not isinstance(self._fmt, ticker.ScalarFormatter): self._fmt = ticker.ScalarFormatter() self._fmt.set_axis(axis) self._fmt.set_useOffset(False) # No additive offset. self._fmt.set_useMathText(True) # x sign before multiplicative offset. ax.set_xticks([]) ax.set_yticks([]) ax.set_navigate(False) self.connect_event("button_press_event", self._update) self.connect_event("button_release_event", self._update) if dragging: self.connect_event("motion_notify_event", self._update) self._observers = cbook.CallbackRegistry()
def clf(self): """ Clear the figure """ self.callbacks = cbook.CallbackRegistry(('dpi_changed', )) for ax in tuple(self.axes): # Iterate over the copy. ax.cla() self.delaxes(ax) # removes ax from self.axes toolbar = getattr(self.canvas, 'toolbar', None) if toolbar is not None: toolbar.update() self._axstack.clear() self._seen = {} self.lines = [] self.patches = [] self.texts=[] self.images = [] self.legends = [] self._axobservers = []
def __init__( self, figsize=None, # defaults to rc figure.figsize dpi=None, # defaults to rc figure.dpi facecolor=None, # defaults to rc figure.facecolor edgecolor=None, # defaults to rc figure.edgecolor linewidth=0.0, # the default linewidth of the frame frameon=True, # whether or not to draw the figure frame subplotpars=None, # default to rc ): """ *figsize* w,h tuple in inches *dpi* dots per inch *facecolor* the figure patch facecolor; defaults to rc ``figure.facecolor`` *edgecolor* the figure patch edge color; defaults to rc ``figure.edgecolor`` *linewidth* the figure patch edge linewidth; the default linewidth of the frame *frameon* if ``False``, suppress drawing the figure frame *subplotpars* a :class:`SubplotParams` instance, defaults to rc """ Artist.__init__(self) self.callbacks = cbook.CallbackRegistry() if figsize is None: figsize = rcParams['figure.figsize'] if dpi is None: dpi = rcParams['figure.dpi'] if facecolor is None: facecolor = rcParams['figure.facecolor'] if edgecolor is None: edgecolor = rcParams['figure.edgecolor'] self.dpi_scale_trans = Affine2D() self.dpi = dpi self.bbox_inches = Bbox.from_bounds(0, 0, *figsize) self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans) self.frameon = frameon self.transFigure = BboxTransformTo(self.bbox) # the figurePatch name is deprecated self.patch = self.figurePatch = Rectangle( xy=(0, 0), width=1, height=1, facecolor=facecolor, edgecolor=edgecolor, linewidth=linewidth, ) self._set_artist_props(self.patch) self.patch.set_aa(False) self._hold = rcParams['axes.hold'] self.canvas = None if subplotpars is None: subplotpars = SubplotParams() self.subplotpars = subplotpars self._axstack = AxesStack() # track all figure axes and current axes self.clf() self._cachedRenderer = None
def test_pickling(self): assert hasattr(pickle.loads(pickle.dumps(cbook.CallbackRegistry())), "callbacks")
def setup(self): self.signal = 'test' self.callbacks = cbook.CallbackRegistry()
def __init__(self, r, formatd=None, stringd=None): """ r is a numpy record array formatd is a dict mapping dtype name to mlab.FormatObj instances stringd, if not None, is a dict mapping dtype names to a list of valid strings for a combo drop down editor """ if stringd is None: stringd = dict() if formatd is None: formatd = mlab.get_formatd(r) self.stringd = stringd self.callbacks = cbook.CallbackRegistry(['cell_changed']) self.r = r self.headers = r.dtype.names self.formats = [ gtkformat_factory(formatd.get(name, mlab.FormatObj()), i) for i, name in enumerate(self.headers) ] # use the gtk attached versions self.formatd = formatd = dict(zip(self.headers, self.formats)) types = [] for format in self.formats: if isinstance(format, mlab.FormatBool): types.append(gobject.TYPE_BOOLEAN) else: types.append(gobject.TYPE_STRING) self.combod = dict() if len(stringd): types.extend([gobject.TYPE_INT] * len(stringd)) keys = stringd.keys() keys.sort() valid = set(r.dtype.names) for ikey, key in enumerate(keys): assert (key in valid) combostore = gtk.ListStore(gobject.TYPE_STRING) for s in stringd[key]: combostore.append([s]) self.combod[key] = combostore, len(self.headers) + ikey gtk.ListStore.__init__(self, *types) for row in r: vals = [] for formatter, val in zip(self.formats, row): if isinstance(formatter, mlab.FormatBool): vals.append(val) else: vals.append(formatter.tostr(val)) if len(stringd): # todo, get correct index here? vals.extend([0] * len(stringd)) self.append(vals)
def __init__(self, kl, label=None): self._callbacks = cbook.CallbackRegistry(signals=["pchanged"]) self._remove_method = None self.set_label(label)
def __init__(self, kl, label=None): self.eventson = False # fire events only if eventson self._callbacks = cbook.CallbackRegistry() self._remove_method = None self.set_label(label)
def __init__(self, kl, label=None): self._callbacks = cbook.CallbackRegistry() self._remove_method = None self.set_label(label)