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

Class GraphicsContextWx

lib/matplotlib/backends/backend_wx.py:284–390  ·  view source on GitHub ↗

The graphics context provides the color, line styles, etc. This class stores a reference to a wxMemoryDC, and a wxGraphicsContext that draws to it. Creating a wxGraphicsContext seems to be fairly heavy, so these objects are cached based on the bitmap object that is passed in.

Source from the content-addressed store, hash-verified

282
283
284class GraphicsContextWx(GraphicsContextBase):
285 """
286 The graphics context provides the color, line styles, etc.
287
288 This class stores a reference to a wxMemoryDC, and a
289 wxGraphicsContext that draws to it. Creating a wxGraphicsContext
290 seems to be fairly heavy, so these objects are cached based on the
291 bitmap object that is passed in.
292
293 The base GraphicsContext stores colors as an RGB tuple on the unit
294 interval, e.g., (0.5, 0.0, 1.0). wxPython uses an int interval, but
295 since wxPython colour management is rather simple, I have not chosen
296 to implement a separate colour manager class.
297 """
298 _capd = {'butt': wx.CAP_BUTT,
299 'projecting': wx.CAP_PROJECTING,
300 'round': wx.CAP_ROUND}
301
302 _joind = {'bevel': wx.JOIN_BEVEL,
303 'miter': wx.JOIN_MITER,
304 'round': wx.JOIN_ROUND}
305
306 _cache = weakref.WeakKeyDictionary()
307
308 def __init__(self, bitmap, renderer):
309 super().__init__()
310 # assert self.Ok(), "wxMemoryDC not OK to use"
311 _log.debug("%s - __init__(): %s", type(self), bitmap)
312
313 dc, gfx_ctx = self._cache.get(bitmap, (None, None))
314 if dc is None:
315 dc = wx.MemoryDC(bitmap)
316 gfx_ctx = wx.GraphicsContext.Create(dc)
317 gfx_ctx._lastcliprect = None
318 self._cache[bitmap] = dc, gfx_ctx
319
320 self.bitmap = bitmap
321 self.dc = dc
322 self.gfx_ctx = gfx_ctx
323 self._pen = wx.Pen('BLACK', 1, wx.SOLID)
324 gfx_ctx.SetPen(self._pen)
325 self.renderer = renderer
326
327 def select(self):
328 """Select the current bitmap into this wxDC instance."""
329 if sys.platform == 'win32':
330 self.dc.SelectObject(self.bitmap)
331 self.IsSelected = True
332
333 def unselect(self):
334 """Select a Null bitmap into this wxDC instance."""
335 if sys.platform == 'win32':
336 self.dc.SelectObject(wx.NullBitmap)
337 self.IsSelected = False
338
339 def set_foreground(self, fg, isRGBA=None):
340 # docstring inherited
341 # Implementation note: wxPython has a separate concept of pen and

Callers 1

new_gcMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…