Skip to content

Commit

Permalink
move plot properties to dict
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias47n9e committed Jun 12, 2015
1 parent 76c070b commit 3ab1109
Showing 1 changed file with 51 additions and 46 deletions.
97 changes: 51 additions & 46 deletions innstereo/plot_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,21 @@ def __init__(self):
"""
self.folder_icon = Gtk.IconTheme.get_default().load_icon(
"folder", 16, 0)
self.draw_grid = True
self.equal_area_projection = True
self.minor_grid_spacing = 2
self.major_grid_spacing = 10
self.grid_cutoff_lat = 80
self.show_north = True
self.show_cross = True
self.pixel_density = 75
self.grid_linestyle = "--"
self.grid_color = "#787878"
self.grid_width = 0.4
self.fig = Figure(dpi=self.pixel_density)
self.draw_legend = True
self.canvas_color = "#bfbfbf"
self.props = {"draw_grid": True,
"equal_area_projection": True,
"minor_grid_spacing": 2,
"major_grid_spacing": 10,
"grid_cutoff_lat": 80,
"show_north": True,
"show_cross": True,
"pixel_density": 75,
"grid_linestyle": "--",
"grid_color": "#787878",
"grid_width": 0.4,
"draw_legend": True,
"canvas_color": "#bfbfbf",
}
self.fig = Figure(dpi=self.props["pixel_density"])

def get_fig(self):
"""
Expand All @@ -73,12 +74,14 @@ def get_inverse_transform(self):
InvertedLambertTransform- or else the
InvertedSterreographicTransform-class.
"""
if self.equal_area_projection is True:
if self.props["equal_area_projection"] is True:
return mplstereonet.stereonet_transforms.\
InvertedLambertTransform(0, 0, self.pixel_density)
InvertedLambertTransform(0, 0,
self.props["pixel_density"])
else:
return mplstereonet.stereonet_transforms.\
InvertedStereographicTransform(0, 0, self.pixel_density)
InvertedStereographicTransform(0, 0,
self.props["pixel_density"])

def get_transform(self):
"""
Expand All @@ -87,12 +90,14 @@ def get_transform(self):
If the projection is equal are (True) the function returns the
LambertTransform- or else the SterreographicTransform-class.
"""
if self.equal_area_projection is True:
if self.props["equal_area_projection"] is True:
return mplstereonet.stereonet_transforms.\
LambertTransform(0, 0, self.pixel_density)
LambertTransform(0, 0,
self.props["pixel_density"])
else:
return mplstereonet.stereonet_transforms.\
StereographicTransform(0, 0, self.pixel_density)
StereographicTransform(0, 0,
self.props["pixel_density"])

def get_draw_grid_state(self):
"""
Expand All @@ -102,7 +107,7 @@ def get_draw_grid_state(self):
that no grid should be drawn. This method is called by the MainWindow-
redraw_plot-method.
"""
return self.draw_grid
return self.props["draw_grid"]

def set_draw_grid_state(self, new_state):
"""
Expand All @@ -112,7 +117,7 @@ def set_draw_grid_state(self, new_state):
that no grid should be drawn. This method is called by the
LayerProperties-dialog when the setting is changed.
"""
self.draw_grid = new_state
self.props["draw_grid"] = new_state

def get_folder_icon(self):
"""
Expand All @@ -133,7 +138,7 @@ def get_pixel_density(self):
is called by the LayerProperties-dialog so it can display the current
value.
"""
return self.pixel_density
return self.props["pixel_density"]

def set_pixel_density(self, new_pixel_density):
"""
Expand All @@ -143,7 +148,7 @@ def set_pixel_density(self, new_pixel_density):
The new value will be used when the plot redraws when the settings
in the dialog are applied.
"""
self.pixel_density = new_pixel_density
self.props["pixel_density"] = new_pixel_density

def get_projection(self):
"""
Expand All @@ -153,7 +158,7 @@ def get_projection(self):
between the equal-area and equal-angle projection. This method is only
called from this class when the view is switched.
"""
if self.equal_area_projection is True:
if self.props["equal_area_projection"] is True:
return "equal_area_stereonet"
else:
return "equal_angle_stereonet"
Expand All @@ -166,7 +171,7 @@ def get_projection_state(self):
with equal-area. False mean equal-angle. This method is called by the
StereonetProperties-dialog to load the current setting.
"""
return self.equal_area_projection
return self.props["equal_area_projection"]

def set_projection_state(self, new_state):
"""
Expand All @@ -177,7 +182,7 @@ def set_projection_state(self, new_state):
StereonetProperties-dialog when a new setting for the projection is
applied.
"""
self.equal_area_projection = new_state
self.props["equal_area_projection"] = new_state

def get_grid_linestyle(self):
"""
Expand All @@ -186,7 +191,7 @@ def get_grid_linestyle(self):
The linestyle is returned as a string. Default is "--" (dashed). This
method is called by the MainWindow "redraw_plot"-method.
"""
return self.grid_linestyle
return self.props["grid_linestyle"]

def get_grid_color(self):
"""
Expand All @@ -195,7 +200,7 @@ def get_grid_color(self):
Returns the color as a hex-triplet. The default is "#787878". This
method is called by the MainWindow "redraw_plot"-method.
"""
return self.grid_color
return self.props["grid_color"]

def get_grid_width(self):
"""
Expand All @@ -204,7 +209,7 @@ def get_grid_width(self):
The width of the grid lines is returned as a float or int. The default
is "0.4". This method is called by the MainWindow "redraw_plot"-method.
"""
return self.grid_width
return self.props["grid_width"]

def get_draw_legend(self):
"""
Expand All @@ -214,7 +219,7 @@ def get_draw_legend(self):
if no legend should be drawn. This method is called by the MainWindow
"redraw_plot"-method and the StereonetProperties-dialog.
"""
return self.draw_legend
return self.props["draw_legend"]

def set_draw_legend(self, new_state):
"""
Expand All @@ -224,7 +229,7 @@ def set_draw_legend(self, new_state):
means that no legend should be drawn. This method is called by the
StereonetProperties-dialog when a new setting is applied.
"""
self.draw_legend = new_state
self.props["draw_legend"] = new_state

def get_canvas_rgba(self):
"""
Expand All @@ -234,7 +239,7 @@ def get_canvas_rgba(self):
current canvas color to the ColorButton.
"""
rgba = Gdk.RGBA()
rgba.parse(self.canvas_color)
rgba.parse(self.props["canvas_color"])
return rgba.to_color()

def set_canvas_color(self, new_color):
Expand All @@ -245,7 +250,7 @@ def set_canvas_color(self, new_color):
by the StereonetProperties-dialog when a new color is applied to the
canvas.
"""
self.canvas_color = new_color
self.props["canvas_color"] = new_color

def get_stereonet(self):
"""
Expand All @@ -257,8 +262,8 @@ def get_stereonet(self):
MainWindow "__init__"-method and the "redraw_plot"-method.
"""
self.fig.clf()
self.fig.patch.set_facecolor(self.canvas_color)
self.fig.set_dpi(self.pixel_density)
self.fig.patch.set_facecolor(self.props["canvas_color"])
self.fig.set_dpi(self.props["pixel_density"])
gridspec = GridSpec(1, 1)
sp_stereo = gridspec.new_subplotspec((0, 0))
ax_stereo = self.fig.add_subplot(sp_stereo,
Expand All @@ -276,8 +281,8 @@ def get_stereo_rose(self):
called by the MainWindow "redraw_plot"-method.
"""
self.fig.clf()
self.fig.patch.set_facecolor(self.canvas_color)
self.fig.set_dpi(self.pixel_density)
self.fig.patch.set_facecolor(self.props["canvas_color"])
self.fig.set_dpi(self.props["pixel_density"])
gridspec = GridSpec(1, 2)
sp_stereo = gridspec.new_subplotspec((0, 0),
rowspan=1, colspan=1)
Expand All @@ -298,8 +303,8 @@ def get_rose_diagram(self):
returned. This method is called by the MainWindow "redraw_plot"-method.
"""
self.fig.clf()
self.fig.patch.set_facecolor(self.canvas_color)
self.fig.set_dpi(self.pixel_density)
self.fig.patch.set_facecolor(self.props["canvas_color"])
self.fig.set_dpi(self.props["pixel_density"])
gridspec = GridSpec(1, 1)
sp_rose = gridspec.new_subplotspec((0, 0))
ax_rose = self.fig.add_subplot(sp_rose, projection="northpolar")
Expand All @@ -315,8 +320,8 @@ def get_pt_view(self):
MainWindow "redraw_plot"-method when the view has been changed.
"""
self.fig.clf()
self.fig.patch.set_facecolor(self.canvas_color)
self.fig.set_dpi(self.pixel_density)
self.fig.patch.set_facecolor(self.props["canvas_color"])
self.fig.set_dpi(self.props["pixel_density"])
gridspec = GridSpec(2, 5)
sp_stereo = gridspec.new_subplotspec((0, 0), colspan=3, rowspan=2)
sp_fluc = gridspec.new_subplotspec((0, 3), colspan=2)
Expand All @@ -334,7 +339,7 @@ def get_show_north(self):
Returns True if the North symbol should be drawn (the default value),
or False in which case numbers will be drawn for different degrees.
"""
return self.show_north
return self.props["show_north"]

def set_show_north(self, new_state):
"""
Expand All @@ -343,7 +348,7 @@ def set_show_north(self, new_state):
Expects a boolean. True means the North symbol will be drawn. False
means that the stereonet will show different degrees along the outside.
"""
self.show_north = new_state
self.props["show_north"] = new_state

def get_show_cross(self):
"""
Expand All @@ -352,7 +357,7 @@ def get_show_cross(self):
Returns True if the cross should be drawn (the default value) or False
if the cross should not be drawn.
"""
return self.show_cross
return self.props["show_cross"]

def set_show_cross(self, new_state):
"""
Expand All @@ -361,4 +366,4 @@ def set_show_cross(self, new_state):
Expects a boolean. True means the center cross will be drawn. False
means it will not be drawn.
"""
self.show_cross = new_state
self.props["show_cross"] = new_state

0 comments on commit 3ab1109

Please sign in to comment.