From 9dbb381f4fcca7ad868dd016010c30ad1a6b9d45 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Mon, 4 May 2015 14:53:46 -0700 Subject: [PATCH 01/28] Modified tests to allow for coverage check --- testing/vcs/vtk_ui/test_vtk_ui_button_action.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_button_alignment.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_button_corner_radius.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_button_dimensions.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_button_draw.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_button_font.py | 4 +++- testing/vcs/vtk_ui/test_vtk_ui_button_image.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_button_states.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_hide.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_show.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_contrasting_colors.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py | 3 ++- testing/vcs/vtk_ui/test_vtk_ui_textbox_highlight.py | 3 ++- testing/vcs/vtk_ui/vtk_ui_test.py | 4 ++-- 14 files changed, 29 insertions(+), 15 deletions(-) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_action.py b/testing/vcs/vtk_ui/test_vtk_ui_button_action.py index ca96777b39..1be7e307fe 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_action.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_action.py @@ -17,4 +17,5 @@ def do_test(self): button.show() button.clicked(None, None) -test_vtk_ui_button_action().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_button_action().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_alignment.py b/testing/vcs/vtk_ui/test_vtk_ui_button_alignment.py index 19d5bef32b..d19312bb60 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_alignment.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_alignment.py @@ -16,4 +16,5 @@ def do_test(self): right_button.show() self.test_file = "test_vtk_ui_button_alignment.png" -test_vtk_ui_button_alignment().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_button_alignment().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_corner_radius.py b/testing/vcs/vtk_ui/test_vtk_ui_button_corner_radius.py index f92f916c34..6fbf817b70 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_corner_radius.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_corner_radius.py @@ -15,4 +15,5 @@ def do_test(self): button.show() self.test_file = "test_vtk_ui_button_corner_radius.png" -test_vtk_ui_button_corner_radius().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_button_corner_radius().test() \ No newline at end of file diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_dimensions.py b/testing/vcs/vtk_ui/test_vtk_ui_button_dimensions.py index 414c79e212..c35c0a6aef 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_dimensions.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_dimensions.py @@ -24,4 +24,5 @@ def do_test(self): self.test_file = "test_vtk_ui_button_dimensions.png" -test_vtk_ui_button_dimensions().test() +if __name__ == "__main__": + test_vtk_ui_button_dimensions().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_draw.py b/testing/vcs/vtk_ui/test_vtk_ui_button_draw.py index 5ab80a2fe4..b36a40b9ec 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_draw.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_draw.py @@ -16,4 +16,5 @@ def do_test(self): button.show() self.test_file = "test_vtk_ui_button_draw.png" -test_vtk_ui_button_draw().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_button_draw().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_font.py b/testing/vcs/vtk_ui/test_vtk_ui_button_font.py index 2dad0c455f..43474def91 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_font.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_font.py @@ -14,4 +14,6 @@ def do_test(self): b = vcs.vtk_ui.Button(self.inter, label="Font Test", font=font, top=ind * 25, size=sizes[ind]) b.show() self.test_file = "test_vtk_ui_button_font.png" -test_vtk_ui_button_font().test() \ No newline at end of file + +if __name__ == "__main__": + test_vtk_ui_button_font().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_image.py b/testing/vcs/vtk_ui/test_vtk_ui_button_image.py index 6b8b73af04..b9a7202e2a 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_image.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_image.py @@ -15,4 +15,5 @@ def do_test(self): b.show() self.test_file = "test_vtk_ui_button_image.png" -test_vtk_ui_button_image().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_button_image().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_states.py b/testing/vcs/vtk_ui/test_vtk_ui_button_states.py index 5027430c70..511b8ae465 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_states.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_states.py @@ -18,4 +18,5 @@ def do_test(self): button.show() self.test_file = "test_vtk_ui_button_states.png" -test_vtk_ui_button_states().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_button_states().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_hide.py b/testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_hide.py index 7b5f0ad9f8..27d67ea187 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_hide.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_hide.py @@ -25,4 +25,5 @@ def do_test(self): self.test_file = "test_vtk_ui_button_tooltip_hide.png" self.hover(5, 50, .1) -test_vtk_ui_button_tooltip_hide().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_button_tooltip_hide().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_show.py b/testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_show.py index 3d5b1a4ada..93a22b8866 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_show.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_show.py @@ -24,4 +24,5 @@ def do_test(self): self.hover(5, 95, .3) self.test_file = "test_vtk_ui_button_tooltip_show.png" -test_vtk_ui_button_tooltip_show().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_button_tooltip_show().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_contrasting_colors.py b/testing/vcs/vtk_ui/test_vtk_ui_contrasting_colors.py index 7f5c27eb12..792f9cbfe8 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_contrasting_colors.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_contrasting_colors.py @@ -132,4 +132,5 @@ def do_test(self): else: self.passed = 1 -test_vtk_ui_contrasting_colors().test() +if __name__ == "__main__": + test_vtk_ui_contrasting_colors().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py index 00b1e3c2c0..ebf07ea5dd 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py @@ -26,4 +26,5 @@ def update_test(self, value): if value < 4: self.failed = True -test_vtk_ui_slider_jumps().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_slider_jumps().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_highlight.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_highlight.py index 4a8e3f7a02..bb0afb605b 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_textbox_highlight.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_highlight.py @@ -20,4 +20,5 @@ def do_test(self): self.test_file = "test_vtk_ui_textbox_highlight.png" -test_vtk_ui_textbox_highlight().test() \ No newline at end of file +if __name__ == "__main__": + test_vtk_ui_textbox_highlight().test() diff --git a/testing/vcs/vtk_ui/vtk_ui_test.py b/testing/vcs/vtk_ui/vtk_ui_test.py index 299389d0ef..e4c3030d6a 100644 --- a/testing/vcs/vtk_ui/vtk_ui_test.py +++ b/testing/vcs/vtk_ui/vtk_ui_test.py @@ -105,5 +105,5 @@ def test(self): self.win.Finalize() self.inter.TerminateApp() - print sys.argv[0], "passed" if self.passed == 0 else "failed" - sys.exit(self.passed) + print sys.argv[0], "passed" if self.passed == 0 else "failed" + sys.exit(self.passed) From b6e445795cd9f709c5baa73aeba47ba4326050ce Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Mon, 4 May 2015 14:54:12 -0700 Subject: [PATCH 02/28] Added vtk_ui_coverage to measure code coverage --- testing/vcs/vtk_ui/vtk_ui_coverage.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 testing/vcs/vtk_ui/vtk_ui_coverage.py diff --git a/testing/vcs/vtk_ui/vtk_ui_coverage.py b/testing/vcs/vtk_ui/vtk_ui_coverage.py new file mode 100644 index 0000000000..09227829d1 --- /dev/null +++ b/testing/vcs/vtk_ui/vtk_ui_coverage.py @@ -0,0 +1,19 @@ +from coverage import coverage + +import glob +import os + +c = coverage(auto_data=True, source=["vcs.vtk_ui"]) +c.start() + +for test in glob.iglob("test_*.py"): + module_file = os.path.basename(test) + module_name, ext = os.path.splitext(module_file) + print "Test", module_name + module = __import__(module_name) + test_class = getattr(module, module_name) + test_object = test_class() + test_object.do_test() + +c.stop() +c.html_report(directory="covhtml") \ No newline at end of file From 96405ccaa72f68bef07a14f5b2769dfe161af319 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Mon, 4 May 2015 14:55:05 -0700 Subject: [PATCH 03/28] Added coverage files to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 70320a31ca..14abbffc04 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ sources/ version /.hooks-config /.idea +.coverage +covhtml From 28aca0ed4d1f87dd4d50ae1cedf5ea74318c2350 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Wed, 6 May 2015 09:19:10 -0700 Subject: [PATCH 04/28] Added 'set_value' func to slider and tests Slider now has some basic test coverage of values and retrieval --- Packages/vcs/Lib/vtk_ui/slider.py | 18 +++++++- testing/vcs/vtk_ui/CMakeLists.txt | 18 ++++++++ .../vtk_ui/test_vtk_ui_slider_appearance.py | 21 +++++++++ .../vcs/vtk_ui/test_vtk_ui_slider_jumps.py | 1 - .../vtk_ui/test_vtk_ui_slider_value_func.py | 30 +++++++++++++ .../vcs/vtk_ui/test_vtk_ui_slider_values.py | 43 +++++++++++++++++++ 6 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_slider_values.py diff --git a/Packages/vcs/Lib/vtk_ui/slider.py b/Packages/vcs/Lib/vtk_ui/slider.py index 007e4360e9..deb02d72b3 100644 --- a/Packages/vcs/Lib/vtk_ui/slider.py +++ b/Packages/vcs/Lib/vtk_ui/slider.py @@ -36,7 +36,7 @@ def __init__(self, interactor, value=0, min_val=0, max_val=1, point1=(0,.1), poi self.repr.SetMinimumValue(float(min_val)) self.repr.SetMaximumValue(float(max_val)) if callable(value): - self.repr.SetValue(float(value())) + self.set_value(value()) self.value_func = value else: self.repr.SetValue(float(value)) @@ -62,9 +62,23 @@ def place(self): self.repr.GetPoint1Coordinate().SetValue((self.x1, self.y1, 0)) self.repr.GetPoint2Coordinate().SetValue((self.x2, self.y2, 0)) + def set_value(self, value): + f = float(value) # Ensure value is floating-point + minimum = self.repr.GetMinimumValue() + maximum = self.repr.GetMaximumValue() + + # Make sure value is between min and max + if f < minimum: + raise ValueError("Value for slider should be >= %f; received %f" % (minimum, f)) + if f > maximum: + raise ValueError("Value for slider should be <= %f; received %f" % (maximum, f)) + + self.repr.SetValue(f) + def show(self): if self.value_func: - self.repr.SetValue(float(self.value_func())) + f = self.value_func() + self.set_value(f) super(Slider, self).show() diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index 5bd3b9e78b..dea2cff735 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -217,3 +217,21 @@ cdat_add_test(test_vtk_ui_button_state_advance "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_button_state_advance.py ) + +cdat_add_test(test_vtk_ui_slider_value_func + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_slider_value_func.py + ${BASELINE_DIR}/test_vtk_ui_slider_value_func.png +) + +cdat_add_test(test_vtk_ui_slider_values + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_slider_values.py + ${BASELINE_DIR}/test_vtk_ui_slider_values.png +) + +cdat_add_test(test_vtk_ui_slider_appearance + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_slider_appearance.py + ${BASELINE_DIR}/test_vtk_ui_slider_appearance.png +) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py new file mode 100644 index 0000000000..174c728621 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py @@ -0,0 +1,21 @@ +""" +Test slider basic appearance +""" +import vcs.vtk_ui +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_slider_appearance(vtk_ui_test): + def __init__(self): + self.failed = False + self.updated = False + super(test_vtk_ui_slider_appearance, self).__init__() + def do_test(self): + self.win.SetSize(100, 500) + + slider = vcs.vtk_ui.Slider(self.inter, point1=(.1, .5), point2=(.9, .5)) + slider.show() + + self.test_file = "test_vtk_ui_slider_appearance.png" + +if __name__ == "__main__": + test_vtk_ui_slider_appearance().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py index ebf07ea5dd..3b83b8cc94 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_jumps.py @@ -8,7 +8,6 @@ class test_vtk_ui_slider_jumps(vtk_ui_test): def __init__(self): self.failed = False - self.updated = False super(test_vtk_ui_slider_jumps, self).__init__() def do_test(self): self.win.SetSize(100, 100) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py new file mode 100644 index 0000000000..0f8e730bd9 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py @@ -0,0 +1,30 @@ +""" +Test slider basic appearance +""" +import vcs.vtk_ui +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_slider_value_func(vtk_ui_test): + def __init__(self): + super(test_vtk_ui_slider_value_func, self).__init__() + self.got_value = 0 + + def do_test(self): + self.win.SetSize(200, 200) + + slider = vcs.vtk_ui.Slider(self.inter, value=self.get_value, min_val=.3, max_val=.75, point1=(.1, .5), point2=(.9, .5)) + + assert self.got_value == 1, "Failed to retrieve value from function on init" + + slider.show() + + assert self.got_value == 2, "Failed to retrieve value from function on show" + + self.test_file = "test_vtk_ui_slider_value_func.png" + + def get_value(self): + self.got_value += 1 + return .5 + +if __name__ == "__main__": + test_vtk_ui_slider_value_func().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_values.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_values.py new file mode 100644 index 0000000000..e71cf1990c --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_values.py @@ -0,0 +1,43 @@ +""" +Test slider basic appearance +""" +import vcs.vtk_ui +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_slider_values(vtk_ui_test): + def __init__(self): + self.failed = False + self.updated = False + super(test_vtk_ui_slider_values, self).__init__() + def do_test(self): + self.win.SetSize(200, 200) + + slider = vcs.vtk_ui.Slider(self.inter, value=.5, min_val=.3, max_val=.75, point1=(.1, .5), point2=(.9, .5)) + slider.show() + + try: + slider.set_value(.2) + except ValueError: + print "Correctly caught less than minimum error" + else: + print "Failed to catch less than minimum error" + return + + try: + slider.set_value(1.) + except ValueError: + print "Correctly caught greater than maximum error" + else: + print "Failed to catch greater than maximum error" + return + + try: + slider.set_value(.4) + except ValueError: + print "Incorrectly errored on valid input for set_value" + return + + self.test_file = "test_vtk_ui_slider_values.png" + +if __name__ == "__main__": + test_vtk_ui_slider_values().test() From 74185f4f680e46c1972b7f5c1cb4f9b2bbb43456 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Wed, 6 May 2015 09:39:33 -0700 Subject: [PATCH 05/28] Added test for callbacks for sliders --- .../vtk_ui/test_vtk_ui_slider_callbacks.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_slider_callbacks.py diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_callbacks.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_callbacks.py new file mode 100644 index 0000000000..f73a902eb5 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_callbacks.py @@ -0,0 +1,30 @@ +""" +Test slider callbacks +""" +import vcs.vtk_ui +from vtk_ui_test import vtk_ui_test +from decimal import Decimal +class test_vtk_ui_slider_callbacks(vtk_ui_test): + def do_test(self): + self.win.SetSize(100, 100) + + slider = vcs.vtk_ui.Slider(self.inter, point1=(.1, .5), point2=(.9, .5), end=self.end_callback, update=self.update_callback) + slider.show() + self.click_event(75, 50) + + def end_callback(self, value): + if value == .5 and self.passed == 1: + self.passed = 0 + else: + self.passed = 1 + if value != .5: + print "Did not accept use update_callback value" + + def update_callback(self, value): + if Decimal(str(value)) != Decimal("0.852112676056"): + print "Passed wrong value to update_callback", value + self.passed = 2 + return .5 + +if __name__ == "__main__": + test_vtk_ui_slider_callbacks().test() From 9c79153ec351faf4dff2d59ccc335adc14430761 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Wed, 6 May 2015 09:39:44 -0700 Subject: [PATCH 06/28] Added callback test to cmakelists --- testing/vcs/vtk_ui/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index dea2cff735..bb6394624c 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -235,3 +235,8 @@ cdat_add_test(test_vtk_ui_slider_appearance ${TEST_DIR}/test_vtk_ui_slider_appearance.py ${BASELINE_DIR}/test_vtk_ui_slider_appearance.png ) + +cdat_add_test(test_vtk_ui_slider_callbacks + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_slider_callbacks.py +) From 432555e097625e22d320fb5a07f2506e55d09aa0 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Wed, 6 May 2015 09:39:58 -0700 Subject: [PATCH 07/28] Updated docstring for slider tests --- testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py | 4 ---- testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py | 2 +- testing/vcs/vtk_ui/test_vtk_ui_slider_values.py | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py index 174c728621..e5661d4790 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_appearance.py @@ -5,10 +5,6 @@ from vtk_ui_test import vtk_ui_test class test_vtk_ui_slider_appearance(vtk_ui_test): - def __init__(self): - self.failed = False - self.updated = False - super(test_vtk_ui_slider_appearance, self).__init__() def do_test(self): self.win.SetSize(100, 500) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py index 0f8e730bd9..4a4e64179a 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_value_func.py @@ -1,5 +1,5 @@ """ -Test slider basic appearance +Test slider callable value argument """ import vcs.vtk_ui from vtk_ui_test import vtk_ui_test diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_values.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_values.py index e71cf1990c..2c83418e49 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_slider_values.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_values.py @@ -1,5 +1,5 @@ """ -Test slider basic appearance +Test slider value logic """ import vcs.vtk_ui from vtk_ui_test import vtk_ui_test From 564a5b89b985e2c11da73c0140776673fb98e95f Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Wed, 6 May 2015 12:39:33 -0700 Subject: [PATCH 08/28] Fixed slight bug in place(), added test --- Packages/vcs/Lib/vtk_ui/slider.py | 1 + testing/vcs/vtk_ui/CMakeLists.txt | 6 +++++ .../vcs/vtk_ui/test_vtk_ui_slider_place.py | 25 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_slider_place.py diff --git a/Packages/vcs/Lib/vtk_ui/slider.py b/Packages/vcs/Lib/vtk_ui/slider.py index deb02d72b3..2b88506548 100644 --- a/Packages/vcs/Lib/vtk_ui/slider.py +++ b/Packages/vcs/Lib/vtk_ui/slider.py @@ -61,6 +61,7 @@ def __init__(self, interactor, value=0, min_val=0, max_val=1, point1=(0,.1), poi def place(self): self.repr.GetPoint1Coordinate().SetValue((self.x1, self.y1, 0)) self.repr.GetPoint2Coordinate().SetValue((self.x2, self.y2, 0)) + self.repr.Modified() def set_value(self, value): f = float(value) # Ensure value is floating-point diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index bb6394624c..ce41c56d71 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -240,3 +240,9 @@ cdat_add_test(test_vtk_ui_slider_callbacks "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_slider_callbacks.py ) + +cdat_add_test(test_vtk_ui_slider_place + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_slider_place.py + ${BASELINE_DIR}/test_vtk_ui_slider_place.png +) \ No newline at end of file diff --git a/testing/vcs/vtk_ui/test_vtk_ui_slider_place.py b/testing/vcs/vtk_ui/test_vtk_ui_slider_place.py new file mode 100644 index 0000000000..6b3becf255 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_slider_place.py @@ -0,0 +1,25 @@ +""" +Test slider placement +""" +import vcs.vtk_ui +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_slider_place(vtk_ui_test): + def do_test(self): + self.win.SetSize(500, 500) + + slider = vcs.vtk_ui.Slider(self.inter, point1=(.1, .5), point2=(.9, .5)) + assert slider.x1 == .1, "x1 set incorrectly; expected .1, got %f" % slider.x1 + assert slider.y1 == .5 == slider.y2, "y1 or y2 incorrect; both should be .5, got %f and %f respectively" % (slider.y1, slider.y2) + assert slider.x2 == .9, "x2 set incorrectly; expected .9, got %f" % slider.x2 + slider.show() + + slider.x1 = .2 + slider.y1 = .3 + + slider.place() + self.win.Render() + self.test_file = "test_vtk_ui_slider_place.png" + +if __name__ == "__main__": + test_vtk_ui_slider_place().test() From e3960a1e8801ff916c912103ff220b2e1d63119a Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Wed, 6 May 2015 15:25:46 -0700 Subject: [PATCH 09/28] Added test for keyable --- testing/vcs/vtk_ui/CMakeLists.txt | 5 ++ .../vtk_ui/test_vtk_ui_behavior_keyable.py | 57 +++++++++++++++++++ testing/vcs/vtk_ui/vtk_ui_test.py | 19 +++++-- 3 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index ce41c56d71..0331808fa0 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -245,4 +245,9 @@ cdat_add_test(test_vtk_ui_slider_place "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_slider_place.py ${BASELINE_DIR}/test_vtk_ui_slider_place.png +) + +cdat_add_test(test_vtk_ui_behavior_keyable + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_behavior_keyable.py ) \ No newline at end of file diff --git a/testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py b/testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py new file mode 100644 index 0000000000..4c9858c8bb --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py @@ -0,0 +1,57 @@ +""" +Test button click +""" +import vcs.vtk_ui + + +class KeyableSubclass(vcs.vtk_ui.behaviors.KeyableMixin): + def __init__(self, interactor): + self.interactor = interactor + self.expecting = None + self.matched = False + super(KeyableSubclass, self).__init__() + self.register() + + def key_pressed(self, key, shift=False, alt=False, control=False): + args = (key, shift, alt, control) + assert args == self.expecting, "%s on keydown does not match %s" % (args, self.expecting) + self.expecting = None + + def key_released(self, key, shift=False, alt=False, control=False): + args = (key, shift, alt, control) + assert args == self.expecting, "%s on keyup does not match %s" % (args, self.expecting) + self.expecting = None + +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_behavior_keyable(vtk_ui_test): + def do_test(self): + + keyable = KeyableSubclass(self.inter) + + # Simple test; press a key + simple = ("a", False, False, False) + + self.set_key(*simple) + + keyable.expecting = simple + self.key_down() + assert keyable.expecting is None, "KeyPressEvent was not triggered" + + keyable.expecting = simple + self.key_up() + assert keyable.expecting is None, "KeyReleaseEvent was not triggered" + + modified = ("A", True, True, True) + self.set_key(*modified) + keyable.expecting = modified + self.key_down() + + keyable.expecting = modified + self.key_up() + + self.passed = 0 + +if __name__ == "__main__": + t = test_vtk_ui_behavior_keyable() + t.test() \ No newline at end of file diff --git a/testing/vcs/vtk_ui/vtk_ui_test.py b/testing/vcs/vtk_ui/vtk_ui_test.py index e4c3030d6a..181a8f1074 100644 --- a/testing/vcs/vtk_ui/vtk_ui_test.py +++ b/testing/vcs/vtk_ui/vtk_ui_test.py @@ -65,11 +65,20 @@ def click_event(self, x, y): self.inter.LeftButtonPressEvent() self.inter.LeftButtonReleaseEvent() - def key_event(self, keycode, control=False, shift=False): - self.win.Render() - self.inter.SetKeyEventInformation(keycode, control, shift) - self.inter.KeyPressEvent() - self.inter.KeyReleaseEvent() + def set_key(self, key, shift=False, alt=False, control=False): + self.inter.SetEventInformation(0, 0, 1 if control else 0, 1 if shift else 0, key, 1, None) + self.inter.SetAltKey(alt) + + def key_down(self): + self.inter.InvokeEvent("KeyPressEvent") + + def key_up(self): + self.inter.InvokeEvent("KeyReleaseEvent") + + def key_event(self, key, shift=False, alt=False, control=False): + self.set_key(key, shift, alt, control) + self.key_down() + self.key_up() def do_test(self): raise NotImplementedError("Implement do_test to execute a test.") From a6a8cc379dc7aac20e9312259daeff0779dcfa89 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Wed, 6 May 2015 15:29:57 -0700 Subject: [PATCH 10/28] Added a symbol test to keyable --- testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py | 5 +++++ testing/vcs/vtk_ui/vtk_ui_test.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py b/testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py index 4c9858c8bb..1abee09d10 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_behavior_keyable.py @@ -50,6 +50,11 @@ def do_test(self): keyable.expecting = modified self.key_up() + symbol_char = ("Delete", False, False, False) + self.set_key(*symbol_char) + keyable.expecting = symbol_char + self.key_down() + self.passed = 0 if __name__ == "__main__": diff --git a/testing/vcs/vtk_ui/vtk_ui_test.py b/testing/vcs/vtk_ui/vtk_ui_test.py index 181a8f1074..2953fdae3d 100644 --- a/testing/vcs/vtk_ui/vtk_ui_test.py +++ b/testing/vcs/vtk_ui/vtk_ui_test.py @@ -66,7 +66,11 @@ def click_event(self, x, y): self.inter.LeftButtonReleaseEvent() def set_key(self, key, shift=False, alt=False, control=False): - self.inter.SetEventInformation(0, 0, 1 if control else 0, 1 if shift else 0, key, 1, None) + if len(key) > 1: + # key is a symbol + self.inter.SetEventInformation(0, 0, 1 if control else 0, 1 if shift else 0, '', 1, key) + else: + self.inter.SetEventInformation(0, 0, 1 if control else 0, 1 if shift else 0, key, 1, None) self.inter.SetAltKey(alt) def key_down(self): From f5ecd22814a733bd73985b7cbfa24fda60bd0641 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Thu, 7 May 2015 09:10:46 -0700 Subject: [PATCH 11/28] Added a couple of widget tests, made widgettestable --- Packages/vcs/Lib/vtk_ui/widget.py | 3 + testing/vcs/vtk_ui/CMakeLists.txt | 14 ++++- testing/vcs/vtk_ui/test_vtk_ui_widget_init.py | 22 +++++++ .../vtk_ui/test_vtk_ui_widget_show_hide.py | 59 +++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_widget_init.py create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py diff --git a/Packages/vcs/Lib/vtk_ui/widget.py b/Packages/vcs/Lib/vtk_ui/widget.py index d0bfaa69f7..7470016e69 100644 --- a/Packages/vcs/Lib/vtk_ui/widget.py +++ b/Packages/vcs/Lib/vtk_ui/widget.py @@ -24,6 +24,9 @@ def subscribe(self, event, action): self.subscriptions[event] = self.widget.AddObserver(event, action) + def place(self): + pass + def unsubscribe(self, *events): """ Will unsubscribe from all or none events. If any events are not subscribed to, there will be an exception. diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index 0331808fa0..9daa2dfdab 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -250,4 +250,16 @@ cdat_add_test(test_vtk_ui_slider_place cdat_add_test(test_vtk_ui_behavior_keyable "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_behavior_keyable.py -) \ No newline at end of file +) + +cdat_add_test(test_vtk_ui_widget_init + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_widget_init.py +) + +cdat_add_test(test_vtk_ui_widget_show_hide + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_widget_show_hide.py + ${BASELINE_DIR}/test_vtk_ui_widget_show.png + ${BASELINE_DIR}/test_vtk_ui_widget_hide.png +) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_widget_init.py b/testing/vcs/vtk_ui/test_vtk_ui_widget_init.py new file mode 100644 index 0000000000..2b66c08c9c --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_widget_init.py @@ -0,0 +1,22 @@ +""" +Test widget initialization and registration +""" +import vcs.vtk_ui + +import vtk +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_button_widget_init(vtk_ui_test): + def do_test(self): + vw = vtk.vtkTextWidget() + vr = vtk.vtkTextRepresentation() + vw.SetRepresentation(vr) + w = vcs.vtk_ui.widget.Widget(self.inter, vw) + assert w.repr == vr, "Representation improperly set" + assert w.interactor == self.inter, "Interactor improperly set" + assert w.manager == vcs.vtk_ui.manager.get_manager(self.inter), "Manager improperly set" + assert w in w.manager.widgets, "Widget improperly registered" + self.passed = 0 + +if __name__ == "__main__": + test_vtk_ui_button_widget_init().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py b/testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py new file mode 100644 index 0000000000..c11455d865 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py @@ -0,0 +1,59 @@ +""" +Test widget show/hide +""" +import vcs.vtk_ui + +import vtk +from vtk_ui_test import vtk_ui_test, generate_png + +class test_vtk_ui_widget_show_hide(vtk_ui_test): + def do_test(self): + self.win.SetSize((100, 100)) + + vw = vtk.vtkButtonWidget() + vr = vtk.vtkTexturedButtonRepresentation2D() + + vr.SetNumberOfStates(1) + r = vtk.vtkPNGReader() + r.SetFileName("Pepper.png") + r.Update() + image = r.GetOutput() + vr.SetButtonTexture(0, image) + vw.SetRepresentation(vr) + + w = vcs.vtk_ui.widget.Widget(self.inter, vw) + w.show() + + width, height, _ = image.GetDimensions() + bounds = (0, 0 + width, 0, height, 0, 0) + vr.SetPlaceFactor(1) + vr.PlaceWidget(bounds) + + self.test_file = "test_vtk_ui_widget_show.png" + if self.args: + self.passed = self.check_image(self.args[0]) + if self.passed == 1: + self.win.SetOffScreenRendering(0) + self.win.Render() + raw_input() + print "Failed to show correctly" + return + else: + generate_png(self.win, self.test_file) + + w.hide() + + self.test_file = "test_vtk_ui_widget_hide.png" + if len(self.args) > 1: + self.passed = self.check_image(self.args[1]) + if self.passed == 1: + print "Failed to hide correctly" + return + else: + generate_png(self.win, self.test_file) + self.test_file = None + self.passed = 0 + + +if __name__ == "__main__": + test_vtk_ui_widget_show_hide().test() From 79844a7fdffc7acb3984c3073b403b1e029a0e69 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Thu, 7 May 2015 12:55:43 -0700 Subject: [PATCH 12/28] Added test for widget subscribe/unsubscribe --- Packages/vcs/Lib/vtk_ui/widget.py | 4 +- testing/vcs/vtk_ui/CMakeLists.txt | 5 ++ ...est_vtk_ui_widget_subscribe_unsubscribe.py | 67 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_widget_subscribe_unsubscribe.py diff --git a/Packages/vcs/Lib/vtk_ui/widget.py b/Packages/vcs/Lib/vtk_ui/widget.py index 7470016e69..32271c2aa3 100644 --- a/Packages/vcs/Lib/vtk_ui/widget.py +++ b/Packages/vcs/Lib/vtk_ui/widget.py @@ -20,7 +20,7 @@ def log(self, message): def subscribe(self, event, action): if event in self.subscriptions: - raise Exception("%s already subscribed to %s's %s event." % (action, self.widget, event)) + raise KeyError("%s already subscribed to %s's %s event." % (action, self.widget, event)) self.subscriptions[event] = self.widget.AddObserver(event, action) @@ -34,7 +34,7 @@ def unsubscribe(self, *events): for event in events: if event not in self.subscriptions: - raise Exception("%s not subscribed to %s's %s event." % (self, self.widget, event)) + raise KeyError("%s not subscribed to %s's %s event." % (self, self.widget, event)) for event in events: self.widget.RemoveObserver(self.subscriptions[event]) diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index 9daa2dfdab..91366b8d24 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -263,3 +263,8 @@ cdat_add_test(test_vtk_ui_widget_show_hide ${BASELINE_DIR}/test_vtk_ui_widget_show.png ${BASELINE_DIR}/test_vtk_ui_widget_hide.png ) + +cdat_add_test(test_vtk_ui_widget_subscribe_unsubscribe + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_widget_subscribe_unsubscribe.py +) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_widget_subscribe_unsubscribe.py b/testing/vcs/vtk_ui/test_vtk_ui_widget_subscribe_unsubscribe.py new file mode 100644 index 0000000000..acfa9f951f --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_widget_subscribe_unsubscribe.py @@ -0,0 +1,67 @@ +""" +Test widget event subscribe / unsubscribe +""" +import vcs.vtk_ui + +import vtk +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_widget_subscribe_unsubscribe(vtk_ui_test): + def do_test(self): + self.win.SetSize((100, 100)) + + vw = vtk.vtkButtonWidget() + vr = vtk.vtkTexturedButtonRepresentation2D() + + vr.SetNumberOfStates(1) + r = vtk.vtkPNGReader() + r.SetFileName("Pepper.png") + r.Update() + image = r.GetOutput() + vr.SetButtonTexture(0, image) + vw.SetRepresentation(vr) + + w = vcs.vtk_ui.widget.Widget(self.inter, vw) + w.show() + + def dummy(*args, **kwargs): + pass + + w.subscribe("StartInteractionEvent", dummy) + + # Make sure event was properly subscribed to + assert "StartInteractionEvent" in w.subscriptions, "Event not in subscriptions" + + # Check observers of w for the tag in w.subscriptions + tag = w.subscriptions["StartInteractionEvent"] + c = vw.GetCommand(tag) + assert c is not None, "Listener not attached to widget" + + try: + w.subscribe("StartInteractionEvent", dummy) + print "Failed to notice double event subscription on widget" + return + except KeyError: + pass + + w.unsubscribe("StartInteractionEvent") + assert "StartInteractionEvent" not in w.subscriptions, "Did not remove event from subscriptions on unsubscribe" + + # Test multiple unsubscriptions + w.subscribe("EndInteractionEvent", dummy) + w.subscribe("StartInteractionEvent", dummy) + w.unsubscribe("StartInteractionEvent", "EndInteractionEvent") + assert "EndInteractionEvent" not in w.subscriptions and "StartInteractionEvent" not in w.subscriptions, "Did not remove both events from widget subscriptions" + + try: + w.unsubscribe("StartInteractionEvent") + print "Failed to notice double unsubscribe on widget" + return + except KeyError: + pass + + self.passed = 0 + + +if __name__ == "__main__": + test_vtk_ui_widget_subscribe_unsubscribe().test() From ca6da8ea43a7fb7f5b8719f50a924d04b0382e96 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Thu, 7 May 2015 12:57:55 -0700 Subject: [PATCH 13/28] Fixed a typo in the widget init test's name --- testing/vcs/vtk_ui/test_vtk_ui_widget_init.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_widget_init.py b/testing/vcs/vtk_ui/test_vtk_ui_widget_init.py index 2b66c08c9c..d7ebc0db5e 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_widget_init.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_widget_init.py @@ -6,7 +6,7 @@ import vtk from vtk_ui_test import vtk_ui_test -class test_vtk_ui_button_widget_init(vtk_ui_test): +class test_vtk_ui_widget_init(vtk_ui_test): def do_test(self): vw = vtk.vtkTextWidget() vr = vtk.vtkTextRepresentation() @@ -19,4 +19,4 @@ def do_test(self): self.passed = 0 if __name__ == "__main__": - test_vtk_ui_button_widget_init().test() + test_vtk_ui_widget_init().test() From 3a10f3940d8a2c12633407ac26a2c8623defb2f7 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Thu, 7 May 2015 13:24:01 -0700 Subject: [PATCH 14/28] Added an extra case check in show_hide and detach test --- .../vcs/vtk_ui/test_vtk_ui_widget_detach.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_widget_detach.py diff --git a/testing/vcs/vtk_ui/test_vtk_ui_widget_detach.py b/testing/vcs/vtk_ui/test_vtk_ui_widget_detach.py new file mode 100644 index 0000000000..1cee2b014e --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_widget_detach.py @@ -0,0 +1,39 @@ +""" +Test widget detach +""" +import vcs.vtk_ui + +import vtk +from vtk_ui_test import vtk_ui_test, generate_png + +class test_vtk_ui_widget_detach(vtk_ui_test): + def do_test(self): + vw = vtk.vtkButtonWidget() + vr = vtk.vtkTexturedButtonRepresentation2D() + + vr.SetNumberOfStates(1) + r = vtk.vtkPNGReader() + r.SetFileName("Pepper.png") + r.Update() + image = r.GetOutput() + vr.SetButtonTexture(0, image) + vw.SetRepresentation(vr) + + w = vcs.vtk_ui.widget.Widget(self.inter, vw) + w.show() + + width, height, _ = image.GetDimensions() + bounds = (0, 0 + width, 0, height, 0, 0) + vr.SetPlaceFactor(1) + vr.PlaceWidget(bounds) + + w.detach() + assert vr.GetRenderer() is None and vw.GetCurrentRenderer() is None, "Renderer is set after detach" + assert vw.GetInteractor() is None, "Interactor set after detach" + assert w.showing() == False, "Widget is flagged as Enabled" + assert w not in vcs.vtk_ui.manager.get_manager(self.inter).widgets, "Widget still being managed" + assert w.interactor is None, "Widget has a reference to interactor" + self.passed = 0 + +if __name__ == "__main__": + test_vtk_ui_widget_detach().test() From e91f186ddcec8e6196de125e1b5e7b3836987de2 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Thu, 7 May 2015 13:24:54 -0700 Subject: [PATCH 15/28] Added detach test to cmakelists --- testing/vcs/vtk_ui/CMakeLists.txt | 5 +++++ testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index 91366b8d24..cd29a06837 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -268,3 +268,8 @@ cdat_add_test(test_vtk_ui_widget_subscribe_unsubscribe "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_widget_subscribe_unsubscribe.py ) + +cdat_add_test(test_vtk_ui_widget_detach + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_widget_detach.py +) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py b/testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py index c11455d865..8c0f3ae148 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_widget_show_hide.py @@ -33,16 +33,17 @@ def do_test(self): if self.args: self.passed = self.check_image(self.args[0]) if self.passed == 1: - self.win.SetOffScreenRendering(0) - self.win.Render() - raw_input() print "Failed to show correctly" return else: generate_png(self.win, self.test_file) + assert w.showing(), "showing() thinks hidden while showing" + w.hide() + assert w.showing() == False, "showing() thinks showing while hidden" + self.test_file = "test_vtk_ui_widget_hide.png" if len(self.args) > 1: self.passed = self.check_image(self.args[1]) From 682eec6b33daaf81826e45f131f6f0ca82749b80 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Thu, 7 May 2015 13:52:00 -0700 Subject: [PATCH 16/28] Added assertion to blank text test --- testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py index 649161db1d..b0adc3e8f4 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py @@ -15,8 +15,14 @@ def do_test(self): textbox.show() textbox.start_editing() textbox.stop_editing() - if textbox.text == "Test String": - self.passed = 0 + assert textbox.text == "Test String", "Start/stop editing altered text" + + textbox.text = "" + textbox.start_editing() + textbox.stop_editing() + assert textbox.text == "", "Start/stop editing altered empty string" + + self.passed = 0 if __name__ == "__main__": test_vtk_ui_textbox_blank_text().test() From 0c8f702abf1fef6ec780802802c9d64290e0e7be Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Thu, 7 May 2015 14:23:30 -0700 Subject: [PATCH 17/28] Added textbox basic appearance test --- testing/vcs/vtk_ui/CMakeLists.txt | 16 ++++++++++++---- .../vtk_ui/test_vtk_ui_textbox_appearance.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_textbox_appearance.py diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index cd29a06837..61be1bd8b4 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -78,11 +78,23 @@ cdat_add_test(test_vtk_ui_textbox_highlight ${BASELINE_DIR}/test_vtk_ui_textbox_highlight.png ) +cdat_add_test(test_vtk_ui_textbox_appearance + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_textbox_appearance.py + ${BASELINE_DIR}/test_vtk_ui_textbox_appearance.png +) + +cdat_add_test(test_vtk_ui_textbox_blank_text + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_textbox_blank_text.py +) + cdat_add_test(test_vtk_ui_label_top "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_label_top.py ${BASELINE_DIR}/test_vtk_ui_label_top.png ) + cdat_add_test(test_vtk_ui_label_y "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_label_y.py @@ -173,10 +185,6 @@ cdat_add_test(test_vtk_ui_manager_resize ${TEST_DIR}/test_vtk_ui_manager_resize.py ${BASELINE_DIR}/test_vtk_ui_manager_resize.png ) -cdat_add_test(test_vtk_ui_textbox_blank_text - "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_textbox_blank_text.py -) cdat_add_test(test_vtk_ui_toolbar_label "${PYTHON_EXECUTABLE}" diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_appearance.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_appearance.py new file mode 100644 index 0000000000..cf1607c1d6 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_appearance.py @@ -0,0 +1,19 @@ +""" +Test textbox appearance +""" +import vcs.vtk_ui +import vtk +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_textbox_appearance(vtk_ui_test): + def do_test(self): + self.win.SetSize(200, 75) + + t = vcs.vtk_ui.Textbox(self.inter, "Sample Text", fgcolor=(0,0,0)) + t.left = 25 + t.top = 25 + t.show() + self.test_file = "test_vtk_ui_textbox_appearance.png" + +if __name__ == "__main__": + test_vtk_ui_textbox_appearance().test() From 43a0b108edf9e817921bd349c55c9ba37201ac14 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Fri, 8 May 2015 08:14:42 -0700 Subject: [PATCH 18/28] Made show_cursor and blink_cursor call place_cursor, tested --- Packages/vcs/Lib/vtk_ui/textbox.py | 2 + testing/vcs/vtk_ui/CMakeLists.txt | 95 +++++---- .../vcs/vtk_ui/test_vtk_ui_textbox_cursor.py | 187 ++++++++++++++++++ 3 files changed, 247 insertions(+), 37 deletions(-) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py diff --git a/Packages/vcs/Lib/vtk_ui/textbox.py b/Packages/vcs/Lib/vtk_ui/textbox.py index ec88877552..d35516291d 100644 --- a/Packages/vcs/Lib/vtk_ui/textbox.py +++ b/Packages/vcs/Lib/vtk_ui/textbox.py @@ -43,6 +43,7 @@ def blink_cursor(self, obj, event): self.last_blink = datetime.now() if self.editing: + self.place_cursor() if self.cursor.showing: self.cursor.hide() else: @@ -51,6 +52,7 @@ def blink_cursor(self, obj, event): def show_cursor(self): self.last_blink = datetime.now() + self.place_cursor() self.cursor.show() self.manager.queue_render() diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index 61be1bd8b4..3505854347 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -2,6 +2,7 @@ set(BASELINE_DIR "${UVCDAT_GIT_TESTDATA_DIR}/baselines/vcs/vtk_ui") set(TEST_DIR "${cdat_SOURCE_DIR}/testing/vcs/vtk_ui") # Button tests + cdat_add_test(test_vtk_ui_button_draw "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_button_draw.py @@ -66,12 +67,18 @@ cdat_add_test(test_vtk_ui_button_tooltip_hide ${BASELINE_DIR}/test_vtk_ui_button_tooltip_hide.png ) -cdat_add_test(test_vtk_ui_slider_jumps +cdat_add_test(test_vtk_ui_button_state_advance "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_slider_jumps.py - ${BASELINE_DIR}/test_vtk_ui_slider_jumps.png + ${TEST_DIR}/test_vtk_ui_button_state_advance.py +) + +cdat_add_test(test_vtk_ui_toggle_button_get_text + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_toggle_button_get_text.py ) +# Textbox Tests + cdat_add_test(test_vtk_ui_textbox_highlight "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_textbox_highlight.py @@ -89,6 +96,14 @@ cdat_add_test(test_vtk_ui_textbox_blank_text ${TEST_DIR}/test_vtk_ui_textbox_blank_text.py ) +cdat_add_test(test_vtk_ui_textbox_cursor + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_textbox_cursor.py + ${BASELINE_DIR}/test_vtk_ui_textbox_cursor.png +) + +# Label tests + cdat_add_test(test_vtk_ui_label_top "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_label_top.py @@ -101,16 +116,6 @@ cdat_add_test(test_vtk_ui_label_y ${BASELINE_DIR}/test_vtk_ui_label_y.png ) -cdat_add_test(test_vtk_ui_contrasting_colors - "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_contrasting_colors.py -) - -cdat_add_test(test_vtk_ui_hsv_rgb - "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_hsv_rgb.py -) - cdat_add_test(test_vtk_ui_label_behaviors "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_label_behaviors.py @@ -165,6 +170,18 @@ cdat_add_test(test_vtk_ui_label_x ${BASELINE_DIR}/test_vtk_ui_label_x.png ) +# Text Utility Tests + +cdat_add_test(test_vtk_ui_contrasting_colors + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_contrasting_colors.py +) + +cdat_add_test(test_vtk_ui_hsv_rgb + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_hsv_rgb.py +) + cdat_add_test(test_vtk_ui_set_font "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_set_font.py @@ -180,10 +197,18 @@ cdat_add_test(test_vtk_ui_white_or_black ${TEST_DIR}/test_vtk_ui_white_or_black.py ) -cdat_add_test(test_vtk_ui_manager_resize +# Toolbar Tests + +cdat_add_test(test_vtk_ui_toolbar_in_toolbar_open "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_manager_resize.py - ${BASELINE_DIR}/test_vtk_ui_manager_resize.png + ${TEST_DIR}/test_vtk_ui_toolbar_in_toolbar_open.py + ${BASELINE_DIR}/test_vtk_ui_toolbar_in_toolbar_open.png +) + +cdat_add_test(test_vtk_ui_toolbar_in_toolbar_closed + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_toolbar_in_toolbar_closed.py + ${BASELINE_DIR}/test_vtk_ui_toolbar_in_toolbar_closed.png ) cdat_add_test(test_vtk_ui_toolbar_label @@ -204,27 +229,7 @@ cdat_add_test(test_vtk_ui_toolbar_close ${BASELINE_DIR}/test_vtk_ui_toolbar_close.png ) -cdat_add_test(test_vtk_ui_toggle_button_get_text - "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_toggle_button_get_text.py -) - -cdat_add_test(test_vtk_ui_toolbar_in_toolbar_open - "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_toolbar_in_toolbar_open.py - ${BASELINE_DIR}/test_vtk_ui_toolbar_in_toolbar_open.png -) - -cdat_add_test(test_vtk_ui_toolbar_in_toolbar_closed - "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_toolbar_in_toolbar_closed.py - ${BASELINE_DIR}/test_vtk_ui_toolbar_in_toolbar_closed.png -) - -cdat_add_test(test_vtk_ui_button_state_advance - "${PYTHON_EXECUTABLE}" - ${TEST_DIR}/test_vtk_ui_button_state_advance.py -) +# Slider tests cdat_add_test(test_vtk_ui_slider_value_func "${PYTHON_EXECUTABLE}" @@ -255,6 +260,22 @@ cdat_add_test(test_vtk_ui_slider_place ${BASELINE_DIR}/test_vtk_ui_slider_place.png ) +cdat_add_test(test_vtk_ui_slider_jumps + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_slider_jumps.py + ${BASELINE_DIR}/test_vtk_ui_slider_jumps.png +) + +# Manager Tests + +cdat_add_test(test_vtk_ui_manager_resize + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_manager_resize.py + ${BASELINE_DIR}/test_vtk_ui_manager_resize.png +) + +# Base class tests + cdat_add_test(test_vtk_ui_behavior_keyable "${PYTHON_EXECUTABLE}" ${TEST_DIR}/test_vtk_ui_behavior_keyable.py diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py new file mode 100644 index 0000000000..98f87d2547 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py @@ -0,0 +1,187 @@ +""" +Test textbox cursor +""" +import vcs.vtk_ui +import datetime +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_textbox_cursor(vtk_ui_test): + def do_test(self): + self.win.SetSize(575, 75) + + # Cursor showing + left = 0 + + t = vcs.vtk_ui.Textbox(self.inter, "A", fgcolor=(0,0,0)) + t.show() + t.row = 0 + t.column = 1 + t.show_cursor() + + should_blink_time = datetime.datetime.now() - datetime.timedelta(0, 0, 0, 400) + + w, h = t.get_dimensions() + left += w + + # Cursor blink on + t = vcs.vtk_ui.Textbox(self.inter, "C", fgcolor=(0,0,0)) + t.left = left + t.show() + t.row = 0 + t.column = 1 + t.editing = True + t.last_blink = should_blink_time + t.blink_cursor(None, None) + + w, h = t.get_dimensions() + left += w + + # Cursor blink off + t = vcs.vtk_ui.Textbox(self.inter, "D", fgcolor=(0,0,0)) + t.left = left + t.show() + t.row = 0 + t.column = 1 + t.editing = True + t.last_blink = should_blink_time + t.blink_cursor(None, None) + t.last_blink = should_blink_time + t.blink_cursor(None, None) + + w, h = t.get_dimensions() + left += w + + # Cursor blink fails + t = vcs.vtk_ui.Textbox(self.inter, "E", fgcolor=(0,0,0)) + t.left = left + t.show() + t.row = 0 + t.column = 1 + t.editing = True + t.last_blink = datetime.datetime.now() + t.blink_cursor(None, None) + + w, h = t.get_dimensions() + left += w + + # Rotated cursor + t = vcs.vtk_ui.Textbox(self.inter, "F", fgcolor=(0,0,0)) + t.left = left + t.top = 25 + t.show() + t.row = 0 + t.column = 1 + p = t.actor.GetTextProperty() + p.SetOrientation(75) + p.SetJustification(1) + p.SetVerticalJustification(1) + t.show_cursor() + + w, h = t.get_dimensions() + left += w + + # Rotated multi-line cursor + t = vcs.vtk_ui.Textbox(self.inter, "G\nH", fgcolor=(0,0,0)) + t.left = left + t.top = 25 + t.row = 1 + t.column = 1 + p = t.actor.GetTextProperty() + p.SetOrientation(75) + p.SetJustification(1) + p.SetVerticalJustification(1) + t.show() + t.show_cursor() + + w, h = t.get_dimensions() + left += w + + # Multi-line cursor + t = vcs.vtk_ui.Textbox(self.inter, "I\nJ", fgcolor=(0,0,0)) + t.left = left + t.row = 1 + t.column = 1 + t.show() + t.show_cursor() + + w, h = t.get_dimensions() + left += w + + # Multi-column cursor + t = vcs.vtk_ui.Textbox(self.inter, "KL", fgcolor=(0,0,0)) + t.left = left + t.row = 0 + t.column = 2 + t.show() + t.show_cursor() + + w, h = t.get_dimensions() + left += w + + # Multi-column cursor (Middle of text) + t = vcs.vtk_ui.Textbox(self.inter, "MN", fgcolor=(0,0,0)) + t.left = left + t.row = 0 + t.column = 1 + t.show() + t.show_cursor() + + w, h = t.get_dimensions() + left += w + + # Multi-column and row cursor + t = vcs.vtk_ui.Textbox(self.inter, "OP\nQR", fgcolor=(0,0,0)) + t.left = left + t.row = 1 + t.column = 2 + t.show() + t.show_cursor() + + w, h = t.get_dimensions() + left += w + + # Multi-column and row cursor (Middle col) + t = vcs.vtk_ui.Textbox(self.inter, "ST\nUV", fgcolor=(0,0,0)) + t.left = left + t.row = 1 + t.column = 1 + t.show() + t.show_cursor() + + w, h = t.get_dimensions() + left += w + + # Use all horizontal justifications to test these: + for h in range(3): + # Shorter text on second line + t = vcs.vtk_ui.Textbox(self.inter, "WX\nY", fgcolor=(0,0,0)) + t.left = left + 25 * h + t.top = 25 + t.row = 1 + t.column = 1 + p = t.actor.GetTextProperty() + p.SetJustification(h) + t.show() + t.show_cursor() + + w, _ = t.get_dimensions() + left += w + + # Shorter text on first line + t = vcs.vtk_ui.Textbox(self.inter, "Z\nAB", fgcolor=(0,0,0)) + t.left = left + 25 * h + t.top = 25 + t.row = 0 + t.column = 1 + p = t.actor.GetTextProperty() + p.SetJustification(h) + t.show() + t.show_cursor() + + w, _ = t.get_dimensions() + left += w + + self.test_file = "test_vtk_ui_textbox_cursor.png" + +if __name__ == "__main__": + test_vtk_ui_textbox_cursor().test() From c24fc7a0a42fc3a08da39155f933e3e35bc0dc66 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Fri, 8 May 2015 08:46:20 -0700 Subject: [PATCH 19/28] Added vertical justification variance for completeness' sake --- .../vcs/vtk_ui/test_vtk_ui_textbox_cursor.py | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py index 98f87d2547..2ed697b44c 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py @@ -7,7 +7,7 @@ class test_vtk_ui_textbox_cursor(vtk_ui_test): def do_test(self): - self.win.SetSize(575, 75) + self.win.SetSize(815, 75) # Cursor showing left = 0 @@ -181,6 +181,36 @@ def do_test(self): w, _ = t.get_dimensions() left += w + # Use all vertical justifications to test these: + for v in range(3): + # Shorter text on second line + t = vcs.vtk_ui.Textbox(self.inter, "CD\nE", fgcolor=(0,0,0)) + t.left = left + 25 * v + t.top = 25 + t.row = 1 + t.column = 1 + p = t.actor.GetTextProperty() + p.SetVerticalJustification(v) + t.show() + t.show_cursor() + + w, _ = t.get_dimensions() + left += w + + # Shorter text on first line + t = vcs.vtk_ui.Textbox(self.inter, "F\nGH", fgcolor=(0,0,0)) + t.left = left + 25 * v + t.top = 25 + t.row = 0 + t.column = 1 + p = t.actor.GetTextProperty() + p.SetVerticalJustification(v) + t.show() + t.show_cursor() + + w, _ = t.get_dimensions() + left += w + self.test_file = "test_vtk_ui_textbox_cursor.png" if __name__ == "__main__": From f5d7e7758d917e3077d80c34cf159af04a249326 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Fri, 8 May 2015 09:27:38 -0700 Subject: [PATCH 20/28] Fixed alignment issues with textbox cursor test --- .../vcs/vtk_ui/test_vtk_ui_textbox_cursor.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py index 2ed697b44c..68ba2a87f9 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_cursor.py @@ -7,7 +7,7 @@ class test_vtk_ui_textbox_cursor(vtk_ui_test): def do_test(self): - self.win.SetSize(815, 75) + self.win.SetSize(1050, 55) # Cursor showing left = 0 @@ -155,61 +155,61 @@ def do_test(self): for h in range(3): # Shorter text on second line t = vcs.vtk_ui.Textbox(self.inter, "WX\nY", fgcolor=(0,0,0)) - t.left = left + 25 * h - t.top = 25 t.row = 1 t.column = 1 p = t.actor.GetTextProperty() p.SetJustification(h) + t.left = left + t.top = 0 t.show() t.show_cursor() w, _ = t.get_dimensions() - left += w + left += w + 25 # Shorter text on first line t = vcs.vtk_ui.Textbox(self.inter, "Z\nAB", fgcolor=(0,0,0)) - t.left = left + 25 * h - t.top = 25 t.row = 0 t.column = 1 p = t.actor.GetTextProperty() p.SetJustification(h) + t.left = left + t.top = 0 t.show() t.show_cursor() w, _ = t.get_dimensions() - left += w + left += w + 25 # Use all vertical justifications to test these: for v in range(3): # Shorter text on second line t = vcs.vtk_ui.Textbox(self.inter, "CD\nE", fgcolor=(0,0,0)) - t.left = left + 25 * v - t.top = 25 t.row = 1 t.column = 1 p = t.actor.GetTextProperty() p.SetVerticalJustification(v) + t.left = left + t.top = 0 t.show() t.show_cursor() w, _ = t.get_dimensions() - left += w + left += w + 25 # Shorter text on first line t = vcs.vtk_ui.Textbox(self.inter, "F\nGH", fgcolor=(0,0,0)) - t.left = left + 25 * v - t.top = 25 t.row = 0 t.column = 1 p = t.actor.GetTextProperty() p.SetVerticalJustification(v) + t.left = left + t.top = 0 t.show() t.show_cursor() w, _ = t.get_dimensions() - left += w + left += w + 25 self.test_file = "test_vtk_ui_textbox_cursor.png" From 3d159809aa86635642097d5347550ace3f9a628a Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Fri, 8 May 2015 09:47:55 -0700 Subject: [PATCH 21/28] Added proper testing for blank feature in textbox --- .../vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py index b0adc3e8f4..661dab60ab 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py @@ -22,6 +22,19 @@ def do_test(self): textbox.stop_editing() assert textbox.text == "", "Start/stop editing altered empty string" + textbox.text = "Hi" + textbox.on_editing_end = self.end + textbox.start_editing() + textbox.delete_character() + textbox.delete_character() + textbox.stop_editing() + + if self.passed != 0: + print "Did not call editing end callback" + return + + def end(self, textbox): + assert textbox.text == "", "Deleting all characters should send blank string to editing end" self.passed = 0 if __name__ == "__main__": From 894f0a5b0acc2d53ad64c0f4570e9c25825c0692 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Fri, 8 May 2015 13:57:42 -0700 Subject: [PATCH 22/28] Added test of typing functionality --- testing/vcs/vtk_ui/CMakeLists.txt | 5 +++ .../vcs/vtk_ui/test_vtk_ui_textbox_typing.py | 44 +++++++++++++++++++ testing/vcs/vtk_ui/vtk_ui_test.py | 1 + 3 files changed, 50 insertions(+) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_textbox_typing.py diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index 3505854347..fedfe3b6a3 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -102,6 +102,11 @@ cdat_add_test(test_vtk_ui_textbox_cursor ${BASELINE_DIR}/test_vtk_ui_textbox_cursor.png ) +cdat_add_test(test_vtk_ui_textbox_typing + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_textbox_typing.py +) + # Label tests cdat_add_test(test_vtk_ui_label_top diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_typing.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_typing.py new file mode 100644 index 0000000000..c116671f0d --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_typing.py @@ -0,0 +1,44 @@ +""" +Test textbox typing +""" +import vcs.vtk_ui + +from vtk_ui_test import vtk_ui_test +import difflib + +class test_vtk_ui_textbox_typing(vtk_ui_test): + def do_test(self): + t = vcs.vtk_ui.Textbox(self.inter, "", fgcolor=(0, 0, 0)) + t.start_editing() + # Run through whole range of typeable characters + self.key_event("space") + for key in range(33, 127): + self.key_event(chr(key)) + + assert t.editing is True, "Something ended editing early" + self.key_event("Escape") + assert t.editing is False, "Escape did not end editing" + t.start_editing() + # Make sure QQ works (always typed on accident when trying to exit) + self.key_event("Q") + self.key_event("Q") + assert t.editing is False, "QQ did not end editing" + assert t.text[-2:] != "QQ", "QQ not removed from text" + + ascii = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" + if t.text != ascii: + print "Text did not match range of ascii characters" + diff = difflib.SequenceMatcher(a=t.text, b=ascii) + for op, i1, i2, j1, j2 in diff.get_opcodes(): + if op == "insert": + print "Missing '''%s'''" % ascii[j1:j2], "from text" + elif op != "equal": + print "%s '''%s''' via '''%s'''" % (op, t.text[i1:i2], ascii[j1:j2]) + return + + self.passed = 0 + + + +if __name__ == "__main__": + test_vtk_ui_textbox_typing().test() diff --git a/testing/vcs/vtk_ui/vtk_ui_test.py b/testing/vcs/vtk_ui/vtk_ui_test.py index 2953fdae3d..67bdebaf35 100644 --- a/testing/vcs/vtk_ui/vtk_ui_test.py +++ b/testing/vcs/vtk_ui/vtk_ui_test.py @@ -82,6 +82,7 @@ def key_up(self): def key_event(self, key, shift=False, alt=False, control=False): self.set_key(key, shift, alt, control) self.key_down() + self.set_key(key, shift, alt, control) self.key_up() def do_test(self): From f068dbb1a366c990f7e7564ac0cff07c471fec22 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Fri, 8 May 2015 15:48:42 -0700 Subject: [PATCH 23/28] Fixed a couple of small bugs in textbox and added tests up to 99% --- Packages/vcs/Lib/vtk_ui/textbox.py | 24 ++-- testing/vcs/vtk_ui/CMakeLists.txt | 10 ++ .../test_vtk_ui_textbox_coordinate_editing.py | 56 +++++++++ .../vcs/vtk_ui/test_vtk_ui_textbox_detach.py | 25 ++++ .../vcs/vtk_ui/test_vtk_ui_textbox_typing.py | 110 ++++++++++++++++-- 5 files changed, 206 insertions(+), 19 deletions(-) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_textbox_coordinate_editing.py create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py diff --git a/Packages/vcs/Lib/vtk_ui/textbox.py b/Packages/vcs/Lib/vtk_ui/textbox.py index d35516291d..c337547513 100644 --- a/Packages/vcs/Lib/vtk_ui/textbox.py +++ b/Packages/vcs/Lib/vtk_ui/textbox.py @@ -68,11 +68,11 @@ def add_character(self, character): row = rows[self.row] if self.column >= len(row): - if self.blank: - self.blank = False - row = character - else: - row += character + # It shouldn't be possible for self.blank to be true here + # self.column will only be >= len(row) if we're navigating + # up from another row (indicating that blank is false, because + # there's text on another line) + row += character rows[self.row] = row if character == "\n": self.column = 0 @@ -114,7 +114,7 @@ def delete_character(self): self.column -= 1 else: rows[self.row] = row[:-1] - self.column = len(row) + self.column = len(row) - 1 self.text = "\n".join(rows) if self.text == "": @@ -161,8 +161,11 @@ def typed(self, obj, event): else: self.column = min(self.column + 1, len(rows[self.row])) elif c == "Up": - self.row = max(0, self.row - 1) - self.column = min(len(rows[self.row]), self.column) + if self.row == 0: + self.column = 0 + else: + self.row = self.row - 1 + #self.column = min(len(rows[self.row]), self.column) elif c == "Down": if self.row == len(rows) - 1: self.column = len(rows[self.row]) @@ -311,7 +314,7 @@ def row_col_at_point(self, x, y): row_at_point = rows.index(row) if row_at_point is None: - row_at_point = len(rows) - 1 + row_at_point = 0 # List was assembled backwards row_bounds.reverse() @@ -348,7 +351,8 @@ def row_col_at_point(self, x, y): # Start from left w = 0 ind = 1 - while row_left + w < x: + + while row_left + w < x and ind < len(text): w, _ = text_dimensions(text[:ind], prop, dpi) ind += 1 diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index fedfe3b6a3..fca3e649eb 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -107,6 +107,16 @@ cdat_add_test(test_vtk_ui_textbox_typing ${TEST_DIR}/test_vtk_ui_textbox_typing.py ) +cdat_add_test(test_vtk_ui_textbox_coordinate_editing + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_textbox_coordinate_editing.py +) + +cdat_add_test(test_vtk_ui_textbox_detach + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_textbox_detach.py +) + # Label tests cdat_add_test(test_vtk_ui_label_top diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_coordinate_editing.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_coordinate_editing.py new file mode 100644 index 0000000000..2d0757c840 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_coordinate_editing.py @@ -0,0 +1,56 @@ +""" +Test textbox coordinate detection/editing +""" +import vcs.vtk_ui +import vtk +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_textbox_coordinate_editing(vtk_ui_test): + def do_test(self): + self.win.SetSize(200, 75) + t = vcs.vtk_ui.Textbox(self.inter, "Sample\nText", fgcolor=(0,0,0)) + t.left = 25 + t.top = 25 + t.show() + t.start_editing((65, 35)) + assert t.row == 0 and t.column == 3, "Selected wrong character" + + t.start_editing((.325, .5)) + assert t.row == 0 and t.column == 3, "Selected wrong character" + + t.stop_editing() + + t.text = "\nHi\n" + t.left = 25 + t.top = 25 + print "Getting dimensions" + w, _ = t.get_dimensions() + print "Got dimensions" + t.start_editing((int(25 + w / 2.), 45)) + assert t.row == 0 and t.column == 0, "Clicked on blank row but got wrong info" + + t.stop_editing() + t.text = "Sample\nText" + # Start outside bounds + t.start_editing((65, 1000)) + assert t.row == 1 and t.column == 4, "Defaults didn't work" + + p = t.actor.GetTextProperty() + p.SetJustification(0) + + t.left = 25 + t.top = 25 + + t.start_editing((0, 0)) + assert t.row == 1 and t.column == 2 + + p.SetJustification(2) + t.left = 25 + t.top = 25 + t.start_editing((1000, 1000)) + assert t.row == 1 and t.column == 4 + + self.passed = 0 + +if __name__ == "__main__": + test_vtk_ui_textbox_coordinate_editing().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py new file mode 100644 index 0000000000..02f1b15222 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py @@ -0,0 +1,25 @@ +""" +Test textbox detach +""" +import vcs.vtk_ui +import vtk +from vtk_ui_test import vtk_ui_test + +class test_vtk_ui_textbox_detach(vtk_ui_test): + def do_test(self): + self.win.SetSize(200, 75) + + t = vcs.vtk_ui.Textbox(self.inter, "Sample Text", fgcolor=(0,0,0)) + t.left = 25 + t.top = 25 + t.show() + t.start_editing() + assert t.cursor is not None, "Cursor not initialized" + t.detach() + assert t.cursor is None, "Cursor not detached" + assert self.inter.GetTimerDuration(t.blink_timer) == 0, "Timer not destroyed" + assert self.inter.GetCommand(t.blink_observer) is None, "Blink observer not destroyed" + assert self.inter.GetCommand(t.keyboard_observer) is None, "Keyboard observer not destroyed" + +if __name__ == "__main__": + test_vtk_ui_textbox_detach().test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_typing.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_typing.py index c116671f0d..dd4a958422 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_textbox_typing.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_typing.py @@ -6,6 +6,23 @@ from vtk_ui_test import vtk_ui_test import difflib +def strings_are_the_same(a, b): + diff = difflib.SequenceMatcher(a=a, b=b) + if diff.ratio() == 1: + return True + + print "Diff-ing:" + print a + print b + for op, i1, i2, j1, j2 in diff.get_opcodes(): + if op == "insert": + print "Missing '''%s'''" % b[j1:j2], "from text" + if op == "delete": + print "Delete '''%s''' at %d:%d" % (a[i1:i2], i1, i2) + if op == "replace": + print "Replace '''%s''' with '''%s'''" % (a[i1:i2], b[j1:j2]) + return False + class test_vtk_ui_textbox_typing(vtk_ui_test): def do_test(self): t = vcs.vtk_ui.Textbox(self.inter, "", fgcolor=(0, 0, 0)) @@ -26,15 +43,90 @@ def do_test(self): assert t.text[-2:] != "QQ", "QQ not removed from text" ascii = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" - if t.text != ascii: - print "Text did not match range of ascii characters" - diff = difflib.SequenceMatcher(a=t.text, b=ascii) - for op, i1, i2, j1, j2 in diff.get_opcodes(): - if op == "insert": - print "Missing '''%s'''" % ascii[j1:j2], "from text" - elif op != "equal": - print "%s '''%s''' via '''%s'''" % (op, t.text[i1:i2], ascii[j1:j2]) - return + assert strings_are_the_same(t.text, ascii), "Text did not match range of ascii characters" + + t.text = "" + + self.key_event("space") + + assert t.text != " ", "Accepted key input while not editing" + + t.start_editing() + + for char in "This is a test string": + if char == " ": + char = "space" + self.key_event(char) + + assert strings_are_the_same(t.text, "This is a test string"), "Did not match simple string" + + current_column = t.column + self.key_event("Backspace") + assert t.column == current_column - 1, "Backspace did not move the cursor; should be %d, is %d" % (current_column - 1, t.column) + assert strings_are_the_same(t.text, "This is a test strin"), "Did not delete the last character" + + current_column = t.column + + self.key_event("Left") + assert t.column == current_column - 1, "Left arrow did not navigate correctly: should be at %s, is at %s" % (current_column - 1, t.column) + + self.key_event("Return") + assert strings_are_the_same(t.text, "This is a test stri\nn"), "Did not add newline at correct position" + + self.key_event("Shift") + assert strings_are_the_same(t.text, "This is a test stri\nn"), "Shift was not a noop" + + self.key_event("Up") + self.key_event("Right") + self.key_event("Return") + assert strings_are_the_same(t.text, "T\nhis is a test stri\nn"), "Did not add newline at correct position" + + self.key_event("Down") + self.key_event("Backspace") + assert strings_are_the_same(t.text, "T\nhis is a test strin"), "Did not delete newline" + + self.key_event("Tab") + assert strings_are_the_same(t.text, "T\nhis is a test stri\tn"), "Did not insert tab at correct position" + + self.key_event("Backspace") + assert strings_are_the_same(t.text, "T\nhis is a test strin"), "Did not delete from middle of string" + # Advance to the last position + self.key_event("Right") + + # Clear out the string to empty + for _ in range(len("T\nhis is a test strin")): + self.key_event("Backspace") + + assert t.blank is True, "Textbox not blank ('''%s''')" % t.text + + self.key_event("A") + assert t.blank is False, "Textbox did not reset blank after adding text" + assert strings_are_the_same(t.text, "A"), "Textbox did not set string correctly after blank" + + self.key_event("Return") + assert strings_are_the_same(t.text, "A\n") + + self.key_event("Left") + assert t.row == 0 and t.column == 1, "Did not line wrap on left arrow" + + self.key_event("Right") + assert t.row == 1 and t.column == 0, "Did not line wrap on right arrow" + + self.key_event("B") + + self.key_event("Down") + assert t.row == 1 and t.column == 1, "Did not jump to end of line of last row on down arrow" + + self.key_event("C") + + self.key_event("Up") + assert t.row == 0 and t.column == 2, "Did not keep position on up arrow; column is %d" % t.column + + self.key_event("D") + assert t.row == 0 and t.column == 2 and strings_are_the_same(t.text, "AD\nBC"), "Did not append character at end of line" + + self.key_event("Up") + assert t.row == 0 and t.column == 0, "Did not jump to start of line of first row on up arrow" self.passed = 0 From 223f25768dd4c932fb7eacfaaf2d1a2d8fe092a5 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Fri, 8 May 2015 15:51:21 -0700 Subject: [PATCH 24/28] Forgot to make the detach test pass --- testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py b/testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py index 02f1b15222..8c65503efe 100644 --- a/testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py +++ b/testing/vcs/vtk_ui/test_vtk_ui_textbox_detach.py @@ -20,6 +20,7 @@ def do_test(self): assert self.inter.GetTimerDuration(t.blink_timer) == 0, "Timer not destroyed" assert self.inter.GetCommand(t.blink_observer) is None, "Blink observer not destroyed" assert self.inter.GetCommand(t.keyboard_observer) is None, "Keyboard observer not destroyed" + self.passed = 0 if __name__ == "__main__": test_vtk_ui_textbox_detach().test() From 7f09e628dcc5fd7fe7101d0ff10ca6bd94f2bff2 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Mon, 11 May 2015 07:47:04 -0700 Subject: [PATCH 25/28] Added missing newline at the end of coverage --- testing/vcs/vtk_ui/vtk_ui_coverage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/vcs/vtk_ui/vtk_ui_coverage.py b/testing/vcs/vtk_ui/vtk_ui_coverage.py index 09227829d1..3ffe15d50c 100644 --- a/testing/vcs/vtk_ui/vtk_ui_coverage.py +++ b/testing/vcs/vtk_ui/vtk_ui_coverage.py @@ -16,4 +16,4 @@ test_object.do_test() c.stop() -c.html_report(directory="covhtml") \ No newline at end of file +c.html_report(directory="covhtml") From 2132c044c9bf4dafc025eaca956d0bca52ee8494 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Mon, 11 May 2015 09:57:51 -0700 Subject: [PATCH 26/28] Added tests for handles --- testing/vcs/vtk_ui/CMakeLists.txt | 26 ++++++++ .../vtk_ui/test_vtk_ui_handle_appearance.py | 19 ++++++ .../vtk_ui/test_vtk_ui_handle_interaction.py | 61 +++++++++++++++++++ .../vtk_ui/test_vtk_ui_handle_normalize.py | 25 ++++++++ .../vcs/vtk_ui/test_vtk_ui_handle_sizing.py | 25 ++++++++ testing/vcs/vtk_ui/vtk_ui_test.py | 17 +++++- 6 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_handle_appearance.py create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_handle_interaction.py create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_handle_normalize.py create mode 100644 testing/vcs/vtk_ui/test_vtk_ui_handle_sizing.py diff --git a/testing/vcs/vtk_ui/CMakeLists.txt b/testing/vcs/vtk_ui/CMakeLists.txt index fca3e649eb..d99e3ef439 100644 --- a/testing/vcs/vtk_ui/CMakeLists.txt +++ b/testing/vcs/vtk_ui/CMakeLists.txt @@ -1,6 +1,8 @@ set(BASELINE_DIR "${UVCDAT_GIT_TESTDATA_DIR}/baselines/vcs/vtk_ui") set(TEST_DIR "${cdat_SOURCE_DIR}/testing/vcs/vtk_ui") +# WIDGET TESTS + # Button tests cdat_add_test(test_vtk_ui_button_draw @@ -77,6 +79,30 @@ cdat_add_test(test_vtk_ui_toggle_button_get_text ${TEST_DIR}/test_vtk_ui_toggle_button_get_text.py ) +# Handle tests + +cdat_add_test(test_vtk_ui_handle_appearance + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_handle_appearance.py + ${BASELINE_DIR}/test_vtk_ui_handle_appearance.png +) + +cdat_add_test(test_vtk_ui_handle_normalize + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_handle_normalize.py +) + +cdat_add_test(test_vtk_ui_handle_sizing + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_handle_sizing.py + ${BASELINE_DIR}/test_vtk_ui_handle_sizing.png +) + +cdat_add_test(test_vtk_ui_handle_interaction + "${PYTHON_EXECUTABLE}" + ${TEST_DIR}/test_vtk_ui_handle_interaction.py +) + # Textbox Tests cdat_add_test(test_vtk_ui_textbox_highlight diff --git a/testing/vcs/vtk_ui/test_vtk_ui_handle_appearance.py b/testing/vcs/vtk_ui/test_vtk_ui_handle_appearance.py new file mode 100644 index 0000000000..e1b3e00087 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_handle_appearance.py @@ -0,0 +1,19 @@ +""" +Tests handle's basic appearance. +""" + +import vcs.vtk_ui +import vtk_ui_test + +class test_vtk_ui_handle_appearance(vtk_ui_test.vtk_ui_test): + def do_test(self): + self.win.SetSize(100, 100) + + h = vcs.vtk_ui.Handle(self.inter, (50, 50)) + h.show() + + self.test_file = "test_vtk_ui_handle_appearance.png" + +if __name__ == "__main__": + t = test_vtk_ui_handle_appearance() + t.test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_handle_interaction.py b/testing/vcs/vtk_ui/test_vtk_ui_handle_interaction.py new file mode 100644 index 0000000000..5cbac9524c --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_handle_interaction.py @@ -0,0 +1,61 @@ +""" +Tests handle's interactivity. +""" + +import vcs.vtk_ui +import vtk_ui_test +import decimal + +class test_vtk_ui_handle_interaction(vtk_ui_test.vtk_ui_test): + def __init__(self): + super(test_vtk_ui_handle_interaction, self).__init__() + self.h = None + self.h2 = None + + def do_test(self): + self.win.SetSize(100, 100) + + self.h = vcs.vtk_ui.Handle(self.inter, (5, 5), clicked=self.clicked, dragged=self.dragged, released=self.released) + self.h.show() + + self.mouse_down(5, 5) + self.mouse_move(10, 10) + self.mouse_up(10, 10) + + # Test normalized drag provides normalized dx/dy + self.h2 = vcs.vtk_ui.Handle(self.inter, (.3, .3), dragged=self.norm_drag, normalize=True) + self.h2.show() + self.mouse_down(30, 30) + self.mouse_move(40, 40) + self.mouse_up(40, 40) + + assert self.passed == 5, "Did not trigger drag on normalized" + + self.passed = 0 + + def norm_drag(self, handle, dx, dy): + assert handle == self.h2, "Normalized passed wrong handle to drag" + assert decimal.Decimal("%f" % dx) == decimal.Decimal("%f" % .1), "DX normalized incorrectly; %f when expecting %f" % (dx, .1) + assert decimal.Decimal("%f" % dy) == decimal.Decimal("%f" % .1), "DY normalized incorrectly; %f when expecting %f" % (dy, .1) + assert self.passed == 4, "Did not trigger released" + self.passed = 5 + + def clicked(self, handle): + assert handle == self.h, "Clicked received argument that was not the handle" + self.passed = 2 + + def dragged(self, handle, dx, dy): + assert handle == self.h, "Dragged received argument that was not the handle" + assert dx == 5, "DX was different from expected value" + assert dy == 5, "DY was different from expected value" + assert self.passed == 2, "Did not trigger clicked before dragging" + self.passed = 3 + + def released(self, handle): + assert handle == self.h, "Released received argument that was not the handle" + assert self.passed == 3, "Did not trigger dragged before released" + self.passed = 4 + +if __name__ == "__main__": + t = test_vtk_ui_handle_interaction() + t.test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_handle_normalize.py b/testing/vcs/vtk_ui/test_vtk_ui_handle_normalize.py new file mode 100644 index 0000000000..620526c1e1 --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_handle_normalize.py @@ -0,0 +1,25 @@ +""" +Tests handle's normalization. +""" + +import vcs.vtk_ui +import vtk_ui_test + +class test_vtk_ui_handle_normalize(vtk_ui_test.vtk_ui_test): + def do_test(self): + self.win.SetSize(100, 100) + + h = vcs.vtk_ui.Handle(self.inter, (.5, .5), normalize=True) + pos = h.__get_position__() + + assert pos == (50, 50), "Did not denormalize position when normalize set to true" + + h2 = vcs.vtk_ui.Handle(self.inter, (50, 50), normalize=False) + pos = h2.__get_position__() + + assert pos == (50, 50), "Normalized position when normalize set to false" + self.passed = 0 + +if __name__ == "__main__": + t = test_vtk_ui_handle_normalize() + t.test() diff --git a/testing/vcs/vtk_ui/test_vtk_ui_handle_sizing.py b/testing/vcs/vtk_ui/test_vtk_ui_handle_sizing.py new file mode 100644 index 0000000000..893784558d --- /dev/null +++ b/testing/vcs/vtk_ui/test_vtk_ui_handle_sizing.py @@ -0,0 +1,25 @@ +""" +Tests handle's sizing. +""" + +import vcs.vtk_ui +import vtk_ui_test + +class test_vtk_ui_handle_sizing(vtk_ui_test.vtk_ui_test): + def do_test(self): + self.win.SetSize(100, 100) + + h1 = vcs.vtk_ui.Handle(self.inter, (10, 10), width=20, height=10) + h1.show() + + h2 = vcs.vtk_ui.Handle(self.inter, (30, 25), width=20, height=20) + h2.show() + + h3 = vcs.vtk_ui.Handle(self.inter, (45, 50), width=10, height=30) + h3.show() + + self.test_file = "test_vtk_ui_handle_sizing.png" + +if __name__ == "__main__": + t = test_vtk_ui_handle_sizing() + t.test() \ No newline at end of file diff --git a/testing/vcs/vtk_ui/vtk_ui_test.py b/testing/vcs/vtk_ui/vtk_ui_test.py index 67bdebaf35..10be9735aa 100644 --- a/testing/vcs/vtk_ui/vtk_ui_test.py +++ b/testing/vcs/vtk_ui/vtk_ui_test.py @@ -58,13 +58,24 @@ def hover(self, x, y, duration): self.inter.InvokeEvent("TimerEvent") self.win.Render() - def click_event(self, x, y): - self.win.Render() + def mouse_down(self, x, y): self.inter.SetEventInformation(x, y) - self.inter.MouseMoveEvent() self.inter.LeftButtonPressEvent() + + def mouse_move(self, x, y): + self.inter.SetEventInformation(x, y) + self.inter.MouseMoveEvent() + + def mouse_up(self, x, y): + self.inter.SetEventInformation(x, y) self.inter.LeftButtonReleaseEvent() + def click_event(self, x, y): + self.win.Render() + self.mouse_move(x, y) + self.mouse_down(x, y) + self.mouse_up(x, y) + def set_key(self, key, shift=False, alt=False, control=False): if len(key) > 1: # key is a symbol From af86f82466d111673621c0617f1dfb3d3b8ec3c2 Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Wed, 15 Jul 2015 12:19:12 -0700 Subject: [PATCH 27/28] Whitespace to retrigger build --- testing/vcs/vtk_ui/vtk_ui_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/vcs/vtk_ui/vtk_ui_test.py b/testing/vcs/vtk_ui/vtk_ui_test.py index 10be9735aa..facfd7f451 100644 --- a/testing/vcs/vtk_ui/vtk_ui_test.py +++ b/testing/vcs/vtk_ui/vtk_ui_test.py @@ -7,7 +7,6 @@ def init(): win = vtk.vtkRenderWindow() - win.SetNumberOfLayers(3) win.SetSize(100, 250) win.SetMultiSamples(0) From 32a434f4d917d7986a23f539eb88eeb6d119a30e Mon Sep 17 00:00:00 2001 From: Sam Fries Date: Thu, 23 Jul 2015 10:25:24 -0700 Subject: [PATCH 28/28] Fixed pep8 --- Packages/vcs/Lib/vtk_ui/textbox.py | 1 - Packages/vcs/Lib/vtk_ui/widget.py | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Packages/vcs/Lib/vtk_ui/textbox.py b/Packages/vcs/Lib/vtk_ui/textbox.py index 39cdbecfb3..2df1cff546 100644 --- a/Packages/vcs/Lib/vtk_ui/textbox.py +++ b/Packages/vcs/Lib/vtk_ui/textbox.py @@ -176,7 +176,6 @@ def typed(self, obj, event): self.column = 0 else: self.row = self.row - 1 - #self.column = min(len(rows[self.row]), self.column) elif c == "Down": if self.row == len(rows) - 1: self.column = len(rows[self.row]) diff --git a/Packages/vcs/Lib/vtk_ui/widget.py b/Packages/vcs/Lib/vtk_ui/widget.py index c75c0f2916..cf7b107383 100644 --- a/Packages/vcs/Lib/vtk_ui/widget.py +++ b/Packages/vcs/Lib/vtk_ui/widget.py @@ -22,8 +22,8 @@ def log(self, message): def subscribe(self, event, action): if event in self.subscriptions: raise KeyError("%s already subscribed to %s's %s event." % - (action, self.widget, event) - ) + (action, self.widget, event) + ) self.subscriptions[event] = self.widget.AddObserver(event, action) @@ -38,8 +38,8 @@ def unsubscribe(self, *events): for event in events: if event not in self.subscriptions: raise KeyError("%s not subscribed to %s's %s event." % - (self, self.widget, event) - ) + (self, self.widget, event) + ) for event in events: self.widget.RemoveObserver(self.subscriptions[event])