|
1 | 1 | from __future__ import division, print_function
|
2 | 2 | """
|
3 |
| -
|
4 |
| - backend_wx.py |
5 |
| -
|
6 | 3 | A wxPython backend for matplotlib, based (very heavily) on
|
7 | 4 | backend_template.py and backend_gtk.py
|
8 | 5 |
|
|
18 | 15 |
|
19 | 16 | """
|
20 | 17 |
|
21 |
| -cvs_id = '$Id$' |
| 18 | +import sys |
| 19 | +import os |
| 20 | +import os.path |
| 21 | +import math |
| 22 | +import StringIO |
| 23 | +import weakref |
| 24 | +import warnings |
22 | 25 |
|
23 |
| - |
24 |
| -import sys, os, os.path, math, StringIO, weakref, warnings |
25 | 26 | import numpy as np
|
26 | 27 |
|
27 | 28 |
|
28 |
| - |
29 | 29 | # Debugging settings here...
|
30 | 30 | # Debug level set here. If the debug level is less than 5, information
|
31 | 31 | # messages (progressively more info for lower value) are printed.
8000
In addition,
|
@@ -188,7 +188,6 @@ def __init__(self, parent, *args, **kwargs):
|
188 | 188 |
|
189 | 189 | # Unbinding causes Wx to stop for some reason. Disabling for now.
|
190 | 190 | # def __del__(self):
|
191 |
| -# import wx |
192 | 191 | # TimerBase.__del__(self)
|
193 | 192 | # self.parent.Bind(wx.EVT_TIMER, None, self._timer)
|
194 | 193 |
|
@@ -410,7 +409,6 @@ def get_gc(self):
|
410 | 409 | assert self.gc != None, "gc must be defined"
|
411 | 410 | return self.gc
|
412 | 411 |
|
413 |
| - |
414 | 412 | def get_wx_font(self, s, prop):
|
415 | 413 | """
|
416 | 414 | Return a wx font. Cache instances in a font dictionary for
|
@@ -448,14 +446,14 @@ def get_wx_font(self, s, prop):
|
448 | 446 |
|
449 | 447 | return font
|
450 | 448 |
|
451 |
| - |
452 | 449 | def points_to_pixels(self, points):
|
453 | 450 | """
|
454 | 451 | convert point measures to pixes using dpi and the pixels per
|
455 | 452 | inch of the display
|
456 | 453 | """
|
457 | 454 | return points*(PIXELS_PER_INCH/72.0*self.dpi/72.0)
|
458 | 455 |
|
| 456 | + |
459 | 457 | class GraphicsContextWx(GraphicsContextBase):
|
460 | 458 | """
|
461 | 459 | The graphics context provides the color, line styles, etc...
|
@@ -627,6 +625,7 @@ def get_wxcolour(self, color):
|
627 | 625 | a *= 255
|
628 | 626 | return wx.Colour(red=int(r), green=int(g), blue=int(b), alpha=int(a))
|
629 | 627 |
|
| 628 | + |
630 | 629 | class FigureCanvasWx(FigureCanvasBase, wx.Panel):
|
631 | 630 | """
|
632 | 631 | The FigureCanvas contains the figure and does event handling.
|
@@ -1421,7 +1420,7 @@ def _create_wx_app():
|
1421 | 1420 | # retain a reference to the app object so it does not get garbage
|
1422 | 1421 | # collected and cause segmentation faults
|
1423 | 1422 | _create_wx_app.theWxApp = wxapp
|
1424 |
| - |
| 1423 | + |
1425 | 1424 |
|
1426 | 1425 | def draw_if_interactive():
|
1427 | 1426 | """
|
@@ -1512,6 +1511,15 @@ def __init__(self, num, fig):
|
1512 | 1511 | self.Fit()
|
1513 | 1512 |
|
1514 | 1513 | self.canvas.SetMinSize((2, 2))
|
| 1514 | + |
| 1515 | + # give the window a matplotlib icon rather than the stock one. |
| 1516 | + # This is not currently working on Linux and is untested elsewhere. |
| 1517 | + #icon_path = os.path.join(matplotlib.rcParams['datapath'], |
| 1518 | + # 'images', 'matplotlib.png') |
| 1519 | + #icon = wx.IconFromBitmap(wx.Bitmap(icon_path)) |
| 1520 | + # for xpm type icons try: |
| 1521 | + #icon = wx.Icon(icon_path, wx.BITMAP_TYPE_XPM) |
| 1522 | + #self.SetIcon(icon) |
1515 | 1523 |
|
1516 | 1524 | self.figmgr = FigureManagerWx(self.canvas, num, self)
|
1517 | 1525 |
|
@@ -1559,15 +1567,14 @@ def Destroy(self, *args, **kwargs):
|
1559 | 1567 | wxapp.Yield()
|
1560 | 1568 | return True
|
1561 | 1569 |
|
| 1570 | + |
1562 | 1571 | class FigureManagerWx(FigureManagerBase):
|
1563 | 1572 | """
|
1564 | 1573 | This class contains the FigureCanvas and GUI frame
|
1565 | 1574 |
|
1566 | 1575 | It is instantiated by GcfWx whenever a new figure is created. GcfWx is
|
1567 | 1576 | responsible for managing multiple instances of FigureManagerWx.
|
1568 | 1577 |
|
1569 |
| - NB: FigureManagerBase is found in _pylab_helpers |
1570 |
| -
|
1571 | 1578 | public attrs
|
1572 | 1579 |
|
1573 | 1580 | canvas - a FigureCanvasWx(wx.Panel) instance
|
@@ -1599,7 +1606,6 @@ def destroy(self, *args):
|
1599 | 1606 | DEBUG_MSG("destroy()", 1, self)
|
1600 | 1607 | self.frame.Destroy()
|
1601 | 1608 | #if self.tb is not None: self.tb.Destroy()
|
1602 |
| - import wx |
1603 | 1609 | #wx.GetApp().ProcessIdle()
|
1604 | 1610 | wx.WakeUpIdle()
|
1605 | 1611 |
|
@@ -1939,11 +1945,6 @@ def set_history_buttons(self):
|
1939 | 1945 |
|
1940 | 1946 | class NavigationToolbarWx(wx.ToolBar):
|
1941 | 1947 | def __init__(self, canvas, can_kill=False):
|
1942 |
| - """ |
1943 |
| - figure is the Figure instance that the toolboar controls |
1944 |
| -
|
1945 |
| - win, if not None, is the wxWindow the Figure is embedded in |
1946 |
| - """ |
1947 | 1948 | wx.ToolBar.__init__(self, canvas.GetParent(), -1)
|
1948 | 1949 | DEBUG_MSG("__init__()", 1, self)
|
1949 | 1950 | self.canvas = canvas
|
|
0 commit comments