Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtk_ui.Button tests #1185

Merged
merged 16 commits into from
Apr 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(BASELINE_DIR "${UVCDAT_GIT_TESTDATA_DIR}/baselines/vcs")


cdat_add_test(vcs_verify_import
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_import.py
Expand Down Expand Up @@ -509,3 +510,5 @@ cdat_add_test(vcs_test_taylor_2_quads
${BASELINE_DIR}/test_vcs_issue_960_labels_2.png
)
endif()

add_subdirectory(vtk_ui)
67 changes: 67 additions & 0 deletions testing/vcs/vtk_ui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
set(BASELINE_DIR "${UVCDAT_GIT_TESTDATA_DIR}/baselines/vcs/vtk_ui")
set(TEST_DIR "${cdat_SOURCE_DIR}/testing/vcs/vtk_ui")

# Button tests
add_test(test_vtk_ui_button_draw
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_draw.py
${BASELINE_DIR}/test_vtk_ui_button_draw.png
)

add_test(test_vtk_ui_button_action
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_action.py
)

add_test(test_vtk_ui_button_corner_radius
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_corner_radius.py
${BASELINE_DIR}/test_vtk_ui_button_corner_radius.png
)

add_test(test_vtk_ui_button_dimensions
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_dimensions.py
${BASELINE_DIR}/test_vtk_ui_button_dimensions.png
)

add_test(test_vtk_ui_button_states
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_states.py
${BASELINE_DIR}/test_vtk_ui_button_states.png
)

add_test(test_vtk_ui_button_click
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_click.py
)

add_test(test_vtk_ui_button_font
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_font.py
${BASELINE_DIR}/test_vtk_ui_button_font.png
)

add_test(test_vtk_ui_button_alignment
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_alignment.py
${BASELINE_DIR}/test_vtk_ui_button_alignment.png
)

add_test(test_vtk_ui_button_image
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_image.py
${BASELINE_DIR}/test_vtk_ui_button_image.png
)

add_test(test_vtk_ui_button_tooltip_show
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_tooltip_show.py
${BASELINE_DIR}/test_vtk_ui_button_tooltip_show.png
)

add_test(test_vtk_ui_button_tooltip_hide
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_button_tooltip_hide.py
${BASELINE_DIR}/test_vtk_ui_button_tooltip_hide.png
)
Binary file added testing/vcs/vtk_ui/Pepper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Test button placement
"""
import vcs.vtk_ui


from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_action(vtk_ui_test):
def action(self, state):
self.passed = 0

def do_test(self):
self.win.SetSize(100, 100)
button = vcs.vtk_ui.Button(self.inter, action=self.action, corner_radius=5, font="Arial", left=10, top=10, label="Test", bgcolor=(.1, .1, .1), fgcolor=(1, 1, 1), size=14, halign=vcs.vtk_ui.button.LEFT_ALIGN, valign=vcs.vtk_ui.button.CENTER_ALIGN)
button.place()
button.show()
button.clicked(None, None)

test_vtk_ui_button_action().test()
19 changes: 19 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_alignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Test button alignment
"""
from vcs.vtk_ui import button

from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_alignment(vtk_ui_test):
def do_test(self):
self.win.SetSize(300, 50)
left_button = button.Button(self.inter, label="Left", halign=button.LEFT_ALIGN, valign=button.TOP_ALIGN, width=125)
left_button.show()
center_button = button.Button(self.inter, label="Center", halign=button.CENTER_ALIGN, valign=button.BOTTOM_ALIGN, top=25, width=125)
center_button.show()
right_button = button.Button(self.inter, label="Right", halign=button.RIGHT_ALIGN, valign=button.CENTER_ALIGN, width=125)
right_button.show()
self.test_file = "test_vtk_ui_button_alignment.png"

test_vtk_ui_button_alignment().test()
25 changes: 25 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_click.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Test button click
"""
import vcs.vtk_ui


from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_click(vtk_ui_test):
def do_test(self):
self.win.SetSize(100, 100)
states = [vcs.vtk_ui.ButtonState(label="State %d" % i, fgcolor=(.1 * i + .5, .1 * i + .5, .1 * i + .5), bgcolor=(.5 - .1 * i,.5 - .1 * i,.5 - .1 * i)) for i in range(5)]

b = vcs.vtk_ui.Button(self.inter, states=states, action=self.pass_me, left=0, top=0)
b.show()

self.click_event(5, 95)

def pass_me(self, state):
if state == 1:
print "Button action executed"
self.passed = 0

if __name__ == "__main__":
test_vtk_ui_button_click().test()
18 changes: 18 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_corner_radius.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Test button placement
"""
import vcs.vtk_ui


from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_corner_radius(vtk_ui_test):
def do_test(self):
self.win.SetSize(100, 300)
for i in range(10):
button = vcs.vtk_ui.Button(self.inter, corner_radius=i, font="Arial", left=10, top=30 * i, label="Test", bgcolor=(.1, .1, .1), fgcolor=(1, 1, 1), size=14, halign=vcs.vtk_ui.button.LEFT_ALIGN, valign=vcs.vtk_ui.button.CENTER_ALIGN)
button.place()
button.show()
self.test_file = "test_vtk_ui_button_corner_radius.png"

test_vtk_ui_button_corner_radius().test()
27 changes: 27 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_dimensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Test button placement
"""
import vcs.vtk_ui


from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_dimensions(vtk_ui_test):
def do_test(self):
self.win.SetSize(290, 300)

button = vcs.vtk_ui.Button(self.inter, corner_radius=5, font="Arial", height=15, width=100, left=10, top=10, label="100 x 15", bgcolor=(.1, .1, .1), fgcolor=(1, 1, 1), size=14, halign=vcs.vtk_ui.button.LEFT_ALIGN, valign=vcs.vtk_ui.button.CENTER_ALIGN)
button.place()
button.show()

button = vcs.vtk_ui.Button(self.inter, corner_radius=5, font="Arial", height=90, width=90, left=10, top=30, label="90 x 90", bgcolor=(.1, .1, .1), fgcolor=(1, 1, 1), size=14, halign=vcs.vtk_ui.button.LEFT_ALIGN, valign=vcs.vtk_ui.button.CENTER_ALIGN)
button.place()
button.show()

button = vcs.vtk_ui.Button(self.inter, corner_radius=5, font="Arial", height=100, width=30, left=10, top=200, label="30\n x \n100", bgcolor=(.1, .1, .1), fgcolor=(1, 1, 1), size=14, halign=vcs.vtk_ui.button.LEFT_ALIGN, valign=vcs.vtk_ui.button.CENTER_ALIGN)
button.place()
button.show()

self.test_file = "test_vtk_ui_button_dimensions.png"

test_vtk_ui_button_dimensions().test()
19 changes: 19 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_draw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Test button placement
"""
import vcs.vtk_ui


from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_draw(vtk_ui_test):
def do_test(self):
self.win.SetSize(100, 250)

for i in range(5):
button = vcs.vtk_ui.Button(self.inter, corner_radius=5, font="Arial", left=10 * i, top=30 * i, label="Test %d" % i, bgcolor=(.1, .1, .1), fgcolor=(1, 1, 1), size=14, halign=vcs.vtk_ui.button.LEFT_ALIGN, valign=vcs.vtk_ui.button.CENTER_ALIGN)
button.place()
button.show()
self.test_file = "test_vtk_ui_button_draw.png"

test_vtk_ui_button_draw().test()
17 changes: 17 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_font.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Test button font/size
"""

import vcs, os
from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_font(vtk_ui_test):
def do_test(self):
self.win.SetSize(100, 80)
fonts = ["Arial", "Courier", os.path.join(os.environ["HOME"], vcs.getdotdirectory()[0], "HelvMono.ttf")]
sizes = [8, 12, 16]
for ind, font in enumerate(fonts):
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()
18 changes: 18 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Test button image
"""
import vcs.vtk_ui

from vtk_ui_test import vtk_ui_test
import os

class test_vtk_ui_button_image(vtk_ui_test):
def do_test(self):
self.win.SetSize(80, 80)
directory = os.path.dirname(__file__)
image = os.path.join(directory, "Pepper.png")
b = vcs.vtk_ui.Button(self.inter, image=image, left=5, top=5)
b.show()
self.test_file = "test_vtk_ui_button_image.png"

test_vtk_ui_button_image().test()
21 changes: 21 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Test button states
"""
import vcs.vtk_ui


from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_states(vtk_ui_test):
def do_test(self):
self.win.SetSize(100, 250)
states = [vcs.vtk_ui.ButtonState(label="State %d" % i, fgcolor=(.1 * i + .5, .1 * i + .5, .1 * i + .5), bgcolor=(.5 - .1 * i,.5 - .1 * i,.5 - .1 * i)) for i in range(5)]

for i in range(5):
button = vcs.vtk_ui.Button(self.inter, corner_radius=5, font="Arial", left=10 * i, top=30 * i, states=states, bgcolor=(.1, .1, .1), fgcolor=(1, 1, 1), size=14, halign=vcs.vtk_ui.button.LEFT_ALIGN, valign=vcs.vtk_ui.button.CENTER_ALIGN)
button.set_state(i)
button.place()
button.show()
self.test_file = "test_vtk_ui_button_states.png"

test_vtk_ui_button_states().test()
28 changes: 28 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_hide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Test button tooltip hides when hovered over
"""
import vcs.vtk_ui

import vtk
from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_tooltip_hide(vtk_ui_test):
def do_test(self):
self.win.SetSize(100, 100)

prop = vtk.vtkTextProperty()
prop.SetColor(.5, .5, .5)
prop.SetBackgroundColor(1, 0, 0)
prop.SetBackgroundOpacity(1)
prop.SetVerticalJustificationToCentered()
b = vcs.vtk_ui.Button(self.inter, label="Hover", tooltip="Hidden", tooltip_property=prop)
b.show()

# Timers only work while interacting, have to fake this ID
b.hover_timer = 1

self.hover(5, 95, .3)
self.test_file = "test_vtk_ui_button_tooltip_hide.png"
self.hover(5, 50, .1)

test_vtk_ui_button_tooltip_hide().test()
27 changes: 27 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_button_tooltip_show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Test button tooltip shows when hovered over
"""
import vcs.vtk_ui

import vtk
from vtk_ui_test import vtk_ui_test

class test_vtk_ui_button_tooltip_show(vtk_ui_test):
def do_test(self):
self.win.SetSize(100, 100)

prop = vtk.vtkTextProperty()
prop.SetColor(.5, .5, .5)
prop.SetBackgroundColor(1, 0, 0)
prop.SetBackgroundOpacity(1)
prop.SetVerticalJustificationToCentered()
b = vcs.vtk_ui.Button(self.inter, label="Hover", tooltip="Hidden", tooltip_property=prop)
b.show()

# Timers only work while interacting, have to fake this ID
b.hover_timer = 1

self.hover(5, 95, .3)
self.test_file = "test_vtk_ui_button_tooltip_show.png"

test_vtk_ui_button_tooltip_show().test()
Loading