Skip to content

Commit

Permalink
Merge pull request #40 from tobias47n9e/master
Browse files Browse the repository at this point in the history
Eigenvectors, Printing, Testing
  • Loading branch information
tobias47n9e committed Jul 23, 2015
2 parents 76083a5 + c1ecd04 commit d91cd62
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 91 deletions.
73 changes: 3 additions & 70 deletions innstereo/dialog_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module contains dialog windows.
Each dialog window has its own class that controls its behaviour. This module
stores the AboutDialog-, PrintDialog-, StereonetProperties-, LayerProperties-,
stores the AboutDialog-, StereonetProperties-, LayerProperties-,
and FileChooserParse-class.
"""

Expand Down Expand Up @@ -69,73 +69,6 @@ def on_aboutdialog_close(self):
self.ab.hide()


class PrintDialog(object):

"""
This class handles the signals of the GtkPrintUnixDialog.
The properties and signals of the Print dialog are set in Glade. This
class parses the Glade file and controls the signals of the dialog.
"""

def __init__(self):
"""
Initializes the Print dialog.
Loads the Gtk.Builder and parses the Glade file. An instance of the
Print dialog is created and the signals are connected to this class.
"""
self.builder = Gtk.Builder()
script_dir = os.path.dirname(__file__)
rel_path = "gui_layout.glade"
abs_path = os.path.join(script_dir, rel_path)
self.builder.add_objects_from_file(abs_path,
("printdialog", ""))
self.pd = self.builder.get_object("printdialog")
self.builder.connect_signals(self)

def run(self):
"""
Runs the GtkPrintUnixDialog.
This method is called from the MainWindow-class when the user clicks on
the print button (on_toolbutton_print_figure_clicked). This method
calls the intrinsic run()-function that all GtkDialogs have.
"""
self.pd.run()

def on_printdialog_destroy(self, widget):
# pylint: disable=unused-argument
"""
Hides the GtkPrintUnixDialog.
This method is called when the dialog is destroyed. It hides the dialog.
"""
self.pd.hide()

def on_printdialog_close(self):
"""
Hides the GtkPrintUnixDialog.
This method is called when the dialog is closed. It hides the dialog.
"""
self.pd.hide()

def on_printdialog_response(self, widget, response):
# pylint: disable=unused-argument
"""
Catches the response of the GtkPrintUnixDialog.
This method is triggered by the DialogResponse. If the response is
OK the figure should be printed. If the response is Cancel the dialog
should be hidden.
"""
if response == Gtk.ResponseType.OK:
pass
elif response == Gtk.ResponseType.CANCEL:
pass


class StereonetProperties(object):

"""
Expand All @@ -149,7 +82,7 @@ class StereonetProperties(object):

def __init__(self, settings, redraw_function, main_window, change_night_mode):
"""
Initializes the plot-properties dialog.
Initializes the plot-properties dialog.
Initializes the plot-properties dialog. Connects the Gtk.Builder
loads the current settings and connects the signals of the dialog
Expand Down Expand Up @@ -182,7 +115,7 @@ def __init__(self, settings, redraw_function, main_window, change_night_mode):
self.builder.get_object("switch_show_cross")
self.switch_highlight = self.builder.get_object("switch_highlight")
self.switch_night_mode = self.builder.get_object("switch_night_mode")

self.redraw = redraw_function
self.change_night_mode = change_night_mode
self.changes = []
Expand Down
33 changes: 15 additions & 18 deletions innstereo/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,18 +892,6 @@ def on_toolbutton_plot_properties_clicked(self, widget):
self.change_night_mode)
plot_properties.run()

def on_toolbutton_print_figure_clicked(self, widget):
# pylint: disable=unused-argument
"""
Prints the figure.
Triggered from the GUI. This function creates an instance of the
GtkPrintUnixDialog and runs it.
"""
pass
#print_dialog = PrintDialog()
#print_dialog.run()

def on_toolbutton_save_figure_clicked(self, widget):
# pylint: disable=unused-argument
"""
Expand Down Expand Up @@ -1447,7 +1435,8 @@ def on_toolbutton_create_plane_dataset_clicked(self, widget):
creates a new dataset in the currently active layer group.
Each dataset has a corresponding data sheet.
"""
self.add_layer_dataset("plane")
store, lyr_obj_new = self.add_layer_dataset("plane")
return store, lyr_obj_new

def on_toolbutton_create_faultplane_dataset_clicked(self, widget):
# pylint: disable=unused-argument
Expand All @@ -1456,21 +1445,24 @@ def on_toolbutton_create_faultplane_dataset_clicked(self, widget):
creates a new dataset in the currently active layer group.
Each dataset has a corresponding data sheet.
"""
self.add_layer_dataset("faultplane")
store, lyr_obj_new = self.add_layer_dataset("faultplane")
return store, lyr_obj_new

def on_toolbutton_create_line_dataset_clicked(self, widget):
# pylint: disable=unused-argument
"""
Creates a new line data layer.
"""
self.add_layer_dataset("line")
store, lyr_obj_new = self.add_layer_dataset("line")
return store, lyr_obj_new

def on_toolbutton_create_small_circle_clicked(self, widget):
# pylint: disable=unused-argument
"""
Creates a new small circle layer.
"""
self.add_layer_dataset("smallcircle")
store, lyr_obj_new = self.add_layer_dataset("smallcircle")
return store, lyr_obj_new

def parse_planes(self, treestore, subset=None):
"""
Expand Down Expand Up @@ -2304,6 +2296,7 @@ def layer_name_edited(self, widget, path, new_label):
When the layer name is edited this function passes the new label to the
TreeStore along with the correct path.
"""
print(path, type(path))
self.layer_store[path][2] = new_label
lyr_obj = self.layer_store[path][3]

Expand Down Expand Up @@ -2467,6 +2460,8 @@ def add_feature(self, layer_type, store, *args):
itr = self.add_faultplane_feature(store, *args)
if layer_type == "smallcircle":
itr = self.add_smallcircle_feature(store, *args)
if layer_type == "eigenvector":
itr = self.add_eigenvector_feature(store, *args)

def on_toolbutton_add_feature_clicked(self, widget):
"""
Expand Down Expand Up @@ -2814,7 +2809,7 @@ def on_menuitem_report_bug_activate(self, menuitem):
"https://github.com/innstereo/innstereo/issues")


def startup():
def startup(testing=False):
"""
Starts the GUI and the application main-loop.
Expand All @@ -2841,7 +2836,9 @@ def startup():

gui_instance = MainWindow(builder)
builder.connect_signals(gui_instance)
Gtk.main()
if testing == False:
Gtk.main()
return gui_instance

if __name__ == "__main__":
startup()
3 changes: 3 additions & 0 deletions tests/HOWTO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Run this command in the project directory:

python3 -m pytest
128 changes: 128 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/python3

import pytest
import innstereo

gui = innstereo.startup(testing=True)

def test_create_plane_layer():
"""
Creates a layer. Asserts whether number of rows is 1.
"""
gui.on_toolbutton_create_plane_dataset_clicked(widget=None)
num_rows = 0
for row in gui.layer_store:
num_rows += 1
assert num_rows == 1

def test_delete_layer():
"""
Deletes the layer from the previous test. Asserts whether number of
rows is 0.
"""
selection = gui.layer_view.get_selection()
selection.select_all()
gui.on_toolbutton_delete_layer_clicked(widget=None)
num_rows = 0
for row in gui.layer_store:
num_rows += 1
assert num_rows == 0

def test_rename_layer():
"""
Creates a layer and then renames it. Asserts whether the layer has the
new label.
"""
new_lbl = "New Label"
gui.on_toolbutton_create_plane_dataset_clicked(widget=None)
gui.layer_name_edited(widget=None, path="0", new_label=new_lbl)
lbl = gui.layer_store[0][3].get_label()
assert lbl == new_lbl
selection = gui.layer_view.get_selection()
selection.select_all()
gui.on_toolbutton_delete_layer_clicked(widget=None)

def test_create_line_layer():
"""
Creates a linear layer.
"""
gui.on_toolbutton_create_line_dataset_clicked(widget=None)

def test_create_faultplane_layer():
"""
Creates a faultplane layer.
"""
gui.on_toolbutton_create_faultplane_dataset_clicked(widget=None)

def test_create_smallcircle_layer():
"""
Creates a smallcircle layer.
"""
gui.on_toolbutton_create_small_circle_clicked(widget=None)

def test_create_group_layer_no_selection():
"""
Creates a group layer without a selection.
"""
selection = gui.layer_view.get_selection()
selection.unselect_all()
gui.on_toolbutton_create_group_layer_clicked(widget=None)

def test_create_group_layer_with_selectin():
"""
Creates a group layer with a selection.
"""
selection = gui.layer_view.get_selection()
selection.select_all()
gui.on_toolbutton_create_group_layer_clicked(widget=None)

def test_toggle_drawing_features():
"""
Toggles feature drawing on and asserts whether the boolean is True.
"""
gui.on_toolbutton_draw_features_toggled(widget=None)
assert gui.draw_features == True

def test_add_planar_feature():
"""
Creates a planar layer and adds an empty row to it.
"""
selection = gui.layer_view.get_selection()
selection.select_all()
gui.on_toolbutton_delete_layer_clicked(widget=None)
store, lyr_obj_new = gui.on_toolbutton_create_plane_dataset_clicked(widget=None)
selection.select_path(0)
gui.on_toolbutton_add_feature_clicked(widget=None)

def test_add_linear_feature():
"""
Creates a linear layer and adds an empty row to it.
"""
selection = gui.layer_view.get_selection()
selection.select_all()
gui.on_toolbutton_delete_layer_clicked(widget=None)
store, lyr_obj_new = gui.on_toolbutton_create_line_dataset_clicked(widget=None)
selection.select_path(0)
gui.on_toolbutton_add_feature_clicked(widget=None)

def test_add_faultplane_feature():
"""
Creates a faultplane layer and adds an empty row to it.
"""
selection = gui.layer_view.get_selection()
selection.select_all()
gui.on_toolbutton_delete_layer_clicked(widget=None)
store, lyr_obj_new = gui.on_toolbutton_create_faultplane_dataset_clicked(widget=None)
selection.select_path(0)
gui.on_toolbutton_add_feature_clicked(widget=None)

def test_add_smallcircle_feature():
"""
Creates a smallcircle layer and adds an empty row to it.
"""
selection = gui.layer_view.get_selection()
selection.select_all()
gui.on_toolbutton_delete_layer_clicked(widget=None)
store, lyr_obj_new = gui.on_toolbutton_create_small_circle_clicked(widget=None)
selection.select_path(0)
gui.on_toolbutton_add_feature_clicked(widget=None)
3 changes: 0 additions & 3 deletions tests/test_startup.py

This file was deleted.

0 comments on commit d91cd62

Please sign in to comment.