FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/lib/matplotlib/backends/backend_wxagg.py at master · feisuo/matplotlib · GitHub
feisuo
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
lib
/
matplotlib
/
backends
/
backend_wxagg.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
197 lines (150 loc) · 5.7 KB
Breadcrumbs
matplotlib
/
lib
/
matplotlib
/
backends
/
backend_wxagg.py
Copy path
File metadata and controls
197 lines (150 loc) · 5.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
from
__future__
import
(
absolute_import
,
division
,
print_function
,
unicode_literals
)
import
six
import
matplotlib
from
matplotlib
.
figure
import
Figure
from
.
backend_agg
import
FigureCanvasAgg
from
.
import
wx_compat
as
wxc
from
.
import
backend_wx
from
.
backend_wx
import
(
FigureManagerWx
,
FigureCanvasWx
,
FigureFrameWx
,
DEBUG_MSG
,
NavigationToolbar2Wx
,
Toolbar
)
import
wx
show
=
backend_wx
.
Show
()
class
FigureFrameWxAgg
(
FigureFrameWx
):
def
get_canvas
(
self
,
fig
):
return
FigureCanvasWxAgg
(
self
,
-
1
,
fig
)
def
_get_toolbar
(
self
,
statbar
):
if
matplotlib
.
rcParams
[
'toolbar'
]
==
'toolbar2'
:
toolbar
=
NavigationToolbar2WxAgg
(
self
.
canvas
)
toolbar
.
set_status_bar
(
statbar
)
else
:
toolbar
=
None
return
toolbar
class
FigureCanvasWxAgg
(
FigureCanvasAgg
,
FigureCanvasWx
):
"""
The FigureCanvas contains the figure and does event handling.
In the wxPython backend, it is derived from wxPanel, and (usually)
lives inside a frame instantiated by a FigureManagerWx. The parent
window probably implements a wxSizer to control the displayed
control size - but we give a hint as to our preferred minimum
size.
"""
def
draw
(
self
,
drawDC
=
None
):
"""
Render the figure using agg.
"""
DEBUG_MSG
(
"draw()"
,
1
,
self
)
FigureCanvasAgg
.
draw
(
self
)
self
.
bitmap
=
_convert_agg_to_wx_bitmap
(
self
.
get_renderer
(),
None
)
self
.
_isDrawn
=
True
self
.
gui_repaint
(
drawDC
=
drawDC
,
origin
=
'WXAgg'
)
def
blit
(
self
,
bbox
=
None
):
"""
Transfer the region of the agg buffer defined by bbox to the display.
If bbox is None, the entire buffer is transferred.
"""
if
bbox
is
None
:
self
.
bitmap
=
_convert_agg_to_wx_bitmap
(
self
.
get_renderer
(),
None
)
self
.
gui_repaint
()
return
l
,
b
,
w
,
h
=
bbox
.
bounds
r
=
l
+
w
t
=
b
+
h
x
=
int
(
l
)
y
=
int
(
self
.
bitmap
.
GetHeight
()
-
t
)
srcBmp
=
_convert_agg_to_wx_bitmap
(
self
.
get_renderer
(),
None
)
srcDC
=
wx
.
MemoryDC
()
srcDC
.
SelectObject
(
srcBmp
)
destDC
=
wx
.
MemoryDC
()
destDC
.
SelectObject
(
self
.
bitmap
)
destDC
.
Blit
(
x
,
y
,
int
(
w
),
int
(
h
),
srcDC
,
x
,
y
)
destDC
.
SelectObject
(
wx
.
NullBitmap
)
srcDC
.
SelectObject
(
wx
.
NullBitmap
)
self
.
gui_repaint
()
filetypes
=
FigureCanvasAgg
.
filetypes
def
print_figure
(
self
,
filename
,
*
args
,
**
kwargs
):
# Use pure Agg renderer to draw
FigureCanvasAgg
.
print_figure
(
self
,
filename
,
*
args
,
**
kwargs
)
# Restore the current view; this is needed because the
# artist contains methods rely on particular attributes
# of the rendered figure for determining things like
# bounding boxes.
if
self
.
_isDrawn
:
self
.
draw
()
class
NavigationToolbar2WxAgg
(
NavigationToolbar2Wx
):
def
get_canvas
(
self
,
frame
,
fig
):
return
FigureCanvasWxAgg
(
frame
,
-
1
,
fig
)
def
new_figure_manager
(
num
,
*
args
,
**
kwargs
):
"""
Create a new figure manager instance
"""
# in order to expose the Figure constructor to the pylab
# interface we need to create the figure here
DEBUG_MSG
(
"new_figure_manager()"
,
3
,
None
)
backend_wx
.
_create_wx_app
()
FigureClass
=
kwargs
.
pop
(
'FigureClass'
,
Figure
)
fig
=
FigureClass
(
*
args
,
**
kwargs
)
return
new_figure_manager_given_figure
(
num
,
fig
)
def
new_figure_manager_given_figure
(
num
,
figure
):
"""
Create a new figure manager instance for the given figure.
"""
frame
=
FigureFrameWxAgg
(
num
,
figure
)
figmgr
=
frame
.
get_figure_manager
()
if
matplotlib
.
is_interactive
():
figmgr
.
frame
.
Show
()
figure
.
canvas
.
draw_idle
()
return
figmgr
#
# agg/wxPython image conversion functions (wxPython >= 2.8)
#
def
_convert_agg_to_wx_image
(
agg
,
bbox
):
"""
Convert the region of the agg buffer bounded by bbox to a wx.Image. If
bbox is None, the entire buffer is converted.
Note: agg must be a backend_agg.RendererAgg instance.
"""
if
bbox
is
None
:
# agg => rgb -> image
image
=
wxc
.
EmptyImage
(
int
(
agg
.
width
),
int
(
agg
.
height
))
image
.
SetData
(
agg
.
tostring_rgb
())
return
image
else
:
# agg => rgba buffer -> bitmap => clipped bitmap => image
return
wx
.
ImageFromBitmap
(
_WX28_clipped_agg_as_bitmap
(
agg
,
bbox
))
def
_convert_agg_to_wx_bitmap
(
agg
,
bbox
):
"""
Convert the region of the agg buffer bounded by bbox to a wx.Bitmap. If
bbox is None, the entire buffer is converted.
Note: agg must be a backend_agg.RendererAgg instance.
"""
if
bbox
is
None
:
# agg => rgba buffer -> bitmap
return
wxc
.
BitmapFromBuffer
(
int
(
agg
.
width
),
int
(
agg
.
height
),
agg
.
buffer_rgba
())
else
:
# agg => rgba buffer -> bitmap => clipped bitmap
return
_WX28_clipped_agg_as_bitmap
(
agg
,
bbox
)
def
_WX28_clipped_agg_as_bitmap
(
agg
,
bbox
):
"""
Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.
Note: agg must be a backend_agg.RendererAgg instance.
"""
l
,
b
,
width
,
height
=
bbox
.
bounds
r
=
l
+
width
t
=
b
+
height
srcBmp
=
wxc
.
BitmapFromBuffer
(
int
(
agg
.
width
),
int
(
agg
.
height
),
agg
.
buffer_rgba
())
srcDC
=
wx
.
MemoryDC
()
srcDC
.
SelectObject
(
srcBmp
)
destBmp
=
wxc
.
EmptyBitmap
(
int
(
width
),
int
(
height
))
destDC
=
wx
.
MemoryDC
()
destDC
.
SelectObject
(
destBmp
)
x
=
int
(
l
)
y
=
int
(
int
(
agg
.
height
)
-
t
)
destDC
.
Blit
(
0
,
0
,
int
(
width
),
int
(
height
),
srcDC
,
x
,
y
)
srcDC
.
SelectObject
(
wx
.
NullBitmap
)
destDC
.
SelectObject
(
wx
.
NullBitmap
)
return
destBmp
FigureCanvas
=
FigureCanvasWxAgg
FigureManager
=
FigureManagerWx
Back
|
FazBrowse Home
|
New Git URL