1
+ from matplotlib .backend_bases import GraphicsContextBase
2
+
3
+ def style_property (name = 'style' , expected_type = Style ):
4
+ """ Property for style attributes. Performs type checking """
5
+ storage_name = '_' + name
6
+
7
+ @property
8
+ def prop (self ):
9
+ return getattr (self , storage_name )
10
+ @prop .setter
11
+ def prop (self , value ):
12
+ if isinstance (value , expected_type ) or value is None :
13
+ setattr (self , storage_name , value )
14
+ else :
15
+ raise TypeError ('{} must be a {}' .format (name , expected_type ))
16
+
17
+ return prop
18
+
19
+
20
+ class Style (GraphicsContextBase ):
21
+
22
+ _lineStyles = {
23
+ '-' : 'solid' ,
24
+ '--' : 'dashed' ,
25
+ '-.' : 'dashdot' ,
26
+ ':' : 'dotted' }
27
+
28
+ def get_graylevel (self ):
29
+ 'Just returns the foreground color'
30
+ return self ._rgb
31
+
32
+ alpha = property (GraphicsContextBase .get_alpha , GraphicsContextBase .set_alpha )
33
+ antialiased = property (GraphicsContextBase .get_antialiased , GraphicsContextBase .set_antialiased )
34
+ capstyle = property (GraphicsContextBase .get_capstyle , GraphicsContextBase .set_capstyle )
35
+ clip_rectangle = property (GraphicsContextBase .get_clip_rectangle , GraphicsContextBase .set_clip_rectangle )
36
+ clip_path = property (GraphicsContextBase .get_clip_path , GraphicsContextBase .set_clip_path )
37
+ graylevel = property (get_graylevel , GraphicsContextBase .set_graylevel )
38
+ joinstyle = property (GraphicsContextBase .get_joinstyle , GraphicsContextBase .set_joinstyle )
39
+ linewidth = property (GraphicsContextBase .get_linewidth , GraphicsContextBase .set_linewidth )
40
+ linestyle = property (GraphicsContextBase .get_linestyle , GraphicsContextBase .set_linestyle )
41
+ url = property (GraphicsContextBase .get_url , GraphicsContextBase .set_url )
42
+ gid = property (GraphicsContextBase .get_gid , GraphicsContextBase .set_gid )
43
+ snap = property (GraphicsContextBase .get_snap , GraphicsContextBase .set_snap )
44
+ hatch = property (GraphicsContextBase .get_hatch , GraphicsContextBase .set_hatch )
45
+
0 commit comments