1import os
2import sys
3import time
4import test_utils
5import test_constants
6import logging
7
8def get_test_header():
9
10    notes =  "*      Studio Lock/Unlock Widget Position Tests       *\n"
11    notes += "*                                                     *\n"
12    notes += "* Test widget move with widget position been locked   *\n"
13    notes += "* Test drag resize with widget position been locked   *\n"
14    notes += "* Test position edit with widget position been locked *\n"
15    notes += "* Test following toolbar buttons                      *\n"
16    notes += "*   with widget position been locked:                 *\n"
17    notes += "*   align left                                        *\n"
18    notes += "*   align right                                       *\n"
19    notes += "*   align top                                         *\n"
20    notes += "*   align bottom                                      *\n"
21    notes += "*   vertical space equally                            *\n"
22    notes += "*   horizontal space equally                          *\n"
23    notes += "*   equal width                                       *\n"
24    notes += "*   equal height                                      *\n"
25    notes += "*   size to fit                                       *"
26    return notes
27
28def select_three_widgets():
29    test_utils.select_multi_widgets('window_1')
30    test_utils.select_multi_widgets('prompt_1')
31    test_utils.select_multi_widgets('text_view_1')
32
33def run_lock_unlock_widget_pos_tests(generate, screenshot):
34
35    test_utils.output_test_header(get_test_header())
36    test_utils.setup(generate, screenshot, 'test_lock_unlock_widget_pos_golden_file')
37
38    # open test project
39    test_utils.open_project('generic_16bpp.gxp')
40
41    # lock widget position
42    test_utils.lock_unlock_widget_positions(1)
43
44    #lock widget position
45    widget_name = 'prompt_2'
46    test_utils.select_project_tree_node(widget_name)
47    test_utils.toolbar_size_to_fit()
48
49    test_utils.select_project_tree_node(widget_name)
50    test_utils.drag_left_top(widget_name, -5, -8, test_utils.CLOSE_NOTIFICATION_MSG)
51    test_utils.drag_left_top(widget_name, 1, 1, test_utils.CLOSE_NOTIFICATION_MSG)
52    test_utils.drag_right_top(widget_name, 11, -10, test_utils.CLOSE_NOTIFICATION_MSG)
53    test_utils.drag_right_top(widget_name, -3, 3, test_utils.CLOSE_NOTIFICATION_MSG)
54    test_utils.drag_left_bottom(widget_name, -5, 8, test_utils.CLOSE_NOTIFICATION_MSG)
55    test_utils.drag_left_bottom(widget_name, 5, -6, test_utils.CLOSE_NOTIFICATION_MSG)
56    test_utils.drag_right_bottom(widget_name, 19, 19, test_utils.CLOSE_NOTIFICATION_MSG)
57    test_utils.drag_right_bottom(widget_name, -9, -9, test_utils.CLOSE_NOTIFICATION_MSG)
58    test_utils.drag_move(widget_name, 10, 10, 0)
59    test_utils.compare_result()
60
61    # select two more widgets
62    test_utils.select_multi_widgets('window_1')
63    test_utils.select_multi_widgets('prompt_1')
64    test_utils.select_multi_widgets('text_view_1')
65
66    # Test resize with toolbar buttons with widget position been locked
67    test_utils.toolbar_vspace_equally()
68    select_three_widgets()
69    test_utils.toolbar_hspace_equally()
70    select_three_widgets()
71    test_utils.toolbar_equal_width()
72    select_three_widgets()
73    test_utils.toolbar_equal_height()
74    select_three_widgets()
75    test_utils.toolbar_align_left()
76    select_three_widgets()
77    test_utils.toolbar_align_top()
78    select_three_widgets()
79    test_utils.toolbar_align_right()
80    select_three_widgets()
81    test_utils.toolbar_align_bottom()
82
83    test_utils.select_project_tree_node('window')
84
85    test_utils.edit_widget_props_post("ID_XPOS", 7)# a notify message will show up to tell the widget is locked, resize is not allowed
86    test_utils.close_message_dialog()
87    test_utils.edit_widget_props_post("ID_YPOS", 7)# a notify message will show up to tell the widget is locked, resize is not allowed
88    test_utils.close_message_dialog()
89    test_utils.edit_widget_props_post("ID_WIDTH", 600)# a notify message will show up to tell the widget is locked, resize is not allowed
90    test_utils.close_message_dialog()
91    test_utils.edit_widget_props_post("ID_HEIGHT", 400)# a notify message will show up to tell the widget is locked, resize is not allowed
92    test_utils.close_message_dialog()
93
94    #unlock widget position
95    test_utils.lock_unlock_widget_positions(0)
96    test_utils.select_project_tree_node('window')
97    test_utils.edit_widget_props("ID_XPOS", 7)
98    test_utils.compare_result()
99
100    test_utils.write_end("Test Lock/Unlock Widget Position")
101
102