Skip to content

Commit

Permalink
Merge pull request #47 from tobias47n9e/master
Browse files Browse the repository at this point in the history
Tests for UI, Input validation
  • Loading branch information
tobias47n9e committed Jul 30, 2015
2 parents f682b95 + 936fb7c commit 95c6587
Show file tree
Hide file tree
Showing 5 changed files with 622 additions and 53 deletions.
227 changes: 194 additions & 33 deletions innstereo/dataview_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def truncate(self, number):
number = round(number, 1)
return number

def truncate_vector(self, number):
"""
Rounds and truncates a number to 3 decimal places. Used for vector
magnitude.
"""
number = round(number, 3)
return number

def set_layer_object(self, lyr_obj):
"""
Passes a layer object to this class.
Expand Down Expand Up @@ -103,6 +111,76 @@ def data_selection_changed(self, selection):
if self.settings.get_highlight() is True:
self.redraw()

def validate_numeric_input(self, inp, inp_type):
"""
Validates a numeric input.
Comma decimal places are replaced by dot decimal places. For the
different angles the boundaries are checked. Returns the valid
number or None.
"""
if inp == "":
return 0
else:
try:
inp = float(inp.replace(",", "."))
except:
return None

if inp_type == "dir":
while inp < 0 or inp > 360:
if inp < 0:
inp += 360
else:
inp -= 360
return inp
elif inp_type == "dip":
if inp < 0 or inp > 90:
return None
else:
return inp
elif inp_type == "vector":
if inp < 0 or inp > 1:
return None
else:
return inp
elif inp_type == "angle":
if inp < 0 or inp > 360:
return None
else:
return inp

def validate_sense(self, inp):
"""
Validates the movement or shear sense.
The column accepts a set of valid strings or numbers that are
replaced with the valid strings. Returns the valid string or None.
"""
val_inp = ["", "uk", "up", "dn", "dex", "sin"]

try:
inp = int(inp)
if inp == 0:
sense = "uk"
elif inp == 1:
sense = "up"
elif inp == 2:
sense = "dn"
elif inp == 3:
sense = "dex"
elif inp == 4:
sense = "sin"
else:
sense = None
return sense
except:
if inp in val_inp:
return str(inp)
else:
return None


class PlaneDataView(DataTreeView):

"""
Expand Down Expand Up @@ -159,17 +237,27 @@ def renderer_dir_edited(self, widget, path, new_string):
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][0] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dir")
if new_number is not None:
self.store[path][0] = new_number
self.redraw()
return new_number
else:
return None

def renderer_dip_edited(self, widget, path, new_string):
"""
If the dip angle is edited, replace the existing value.
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][1] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dip")
if new_number is not None:
self.store[path][1] = new_number
self.redraw()
return new_number
else:
return None

def renderer_strat_edited(self, widget, path, new_string):
"""
Expand All @@ -179,6 +267,7 @@ def renderer_strat_edited(self, widget, path, new_string):
self.store[path][2] = new_string
self.redraw()


class FaultPlaneDataView(DataTreeView):

"""
Expand Down Expand Up @@ -262,43 +351,69 @@ def renderer_dir_edited(self, widget, path, new_string):
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][0] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dir")
if new_number is not None:
self.store[path][0] = new_number
self.redraw()
return new_number
else:
return None

def renderer_dip_edited(self, widget, path, new_string):
"""
If the dip angle is edited, replace the existing value.
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][1] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dip")
if new_number is not None:
self.store[path][1] = new_number
self.redraw()
return new_number
else:
return None

def renderer_ldir_edited(self, widget, path, new_string):
"""
If the linear dip direction is edited, replace the existing value.
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][2] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dir")
if new_number is not None:
self.store[path][2] = new_number
self.redraw()
return new_number
else:
return None

def renderer_ldip_edited(self, widget, path, new_string):
"""
If the linear dip is edited, replace the existing value.
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][3] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dip")
if new_number is not None:
self.store[path][3] = new_number
self.redraw()
return new_number
else:
return None

def renderer_sense_edited(self, widget, path, new_string):
"""
If the linear shear sense is edited, replace the existing value.
The the values is replaced by the raw input-string.
"""
self.store[path][4] = new_string
self.redraw()
new_string = self.validate_sense(new_string)
if new_string is not None:
self.store[path][4] = new_string
self.redraw()
return new_string
else:
return None


class LineDataView(DataTreeView):

Expand Down Expand Up @@ -359,25 +474,41 @@ def renderer_dir_edited(self, widget, path, new_string):
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][0] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dir")
if new_number is not None:
self.store[path][0] = new_number
self.redraw()
return new_number
else:
return None

def renderer_dip_edited(self, widget, path, new_string):
"""
If the dip angle is edited, replace the existing value.
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][1] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dip")
if new_number is not None:
self.store[path][1] = new_number
self.redraw()
return new_number
else:
return None

def renderer_sense_edited(self, widget, path, new_string):
"""
If the sense of the linear is edited, replace the existing value.
The new values is the raw input-string.
"""
self.store[path][2] = new_string
self.redraw()
new_string = self.validate_sense(new_string)
if new_string is not None:
self.store[path][2] = new_string
self.redraw()
return new_string
else:
return None


class SmallCircleDataView(DataTreeView):

Expand Down Expand Up @@ -440,26 +571,41 @@ def renderer_dir_edited(self, widget, path, new_string):
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][0] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dir")
if new_number is not None:
self.store[path][0] = new_number
self.redraw()
return new_number
else:
return None

def renderer_dip_edited(self, widget, path, new_string):
"""
If the dip is edited, replace the existing value.
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][1] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dip")
if new_number is not None:
self.store[path][1] = new_number
self.redraw()
return new_number
else:
return None

def renderer_angle_edited(self, widget, path, new_string):
"""
If the opening angle is edited, replace the existing value.
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][2] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "angle")
if new_number is not None:
self.store[path][2] = new_number
self.redraw()
return new_number
else:
return None


class EigenVectorView(DataTreeView):
Expand Down Expand Up @@ -512,7 +658,7 @@ def __init__(self, store, redraw_plot, add_feature, settings):
column_value.set_cell_data_func(renderer_value,
lambda col, cell, model, iter, unused:
cell.set_property("text",
"{0}".format(self.truncate(model.get(iter, 2)[0]))))
"{0}".format(self.truncate_vector(model.get(iter, 2)[0]))))
self.append_column(column_value)

renderer_dir.connect("edited", self.renderer_dir_edited)
Expand All @@ -525,17 +671,27 @@ def renderer_dir_edited(self, widget, path, new_string):
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][0] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dir")
if new_number is not None:
self.store[path][0] = new_number
self.redraw()
return new_number
else:
return None

def renderer_dip_edited(self, widget, path, new_string):
"""
If the dip angle is edited, replace the existing value.
The function replaces a ","- with a "."-comma. Converts
the string value to a float.
"""
self.store[path][1] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "dip")
if new_number is not None:
self.store[path][1] = new_number
self.redraw()
return new_number
else:
return None

def renderer_value_edited(self, widget, path, new_string):
"""
Expand All @@ -544,5 +700,10 @@ def renderer_value_edited(self, widget, path, new_string):
The new value is converted to a float and commas are replaced by
dots. Then the new value is assigned to the cell.
"""
self.store[path][2] = float(new_string.replace(",", "."))
self.redraw()
new_number = self.validate_numeric_input(new_string, "vector")
if new_number is not None:
self.store[path][2] = new_number
self.redraw()
return new_number
else:
return None
5 changes: 3 additions & 2 deletions innstereo/layer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

from gi.repository import Gdk, GdkPixbuf
from collections import OrderedDict


class PlaneLayer(object):
Expand All @@ -36,7 +37,7 @@ def __init__(self, treestore, treeview):
self.data_treestore = treestore
self.data_treeview = treeview

self.props = {"type": "plane",
self.props = OrderedDict(sorted({"type": "plane",
"label": "Plane layer",
"page": 0,
#Great circle / Small circle properties
Expand Down Expand Up @@ -92,7 +93,7 @@ def __init__(self, treestore, treeview):
"lower_limit": 1,
"upper_limit": 10,
"steps": 10
}
}.items()))
self.props["label"] = _("Plane Layer")

def get_page(self):
Expand Down

0 comments on commit 95c6587

Please sign in to comment.