1# -*- coding: utf-8 -*-
2import os
3import sys
4import time
5import test_utils
6import test_constants
7import filecmp
8
9display_name = "main_display"
10folder_name = "default_folder"
11screen_name = "main_screen"
12
13test_scroll_wheel_widget_output_files = [
14"test_scroll_wheel_widget_specifications.c",
15"test_scroll_wheel_widget_specifications.h"]
16
17def get_test_header():
18    notes =  "*          Scroll Wheel Widget Test                   *\n"
19    notes += "*                                                     *\n"
20    notes += "* Add and Edit String Scroll Wheel                    *\n"
21    notes += "* Add and Edit Numeric Scroll Wheel                   *\n"
22    return notes
23
24def run_new_project_create(project_name):
25
26    # create a new project
27    test_utils.toolbar_create()
28    test_utils.set_new_project_path(test_utils.DEFAULT_OUTPUT_FILE_PATH)
29    test_utils.set_new_project_name(project_name)
30    test_utils.save_new_project_create()
31
32    # configure project
33    test_utils.configure_project()
34    test_utils.configure_x_res(640)
35    test_utils.configure_y_res(480)
36    test_utils.configure_display_name(display_name)
37    test_utils.save_project_configure()
38
39    # close message dialog when create new project
40    test_utils.close_message_dialog()
41
42    # add normal font
43    # open font folder
44    test_utils.click_resource_group('FONT_GROUP')
45
46    test_utils.add_font()
47    test_utils.set_font_path('..\\..\\fonts\\Vera.ttf')
48    test_utils.set_font_name('NORMAL_FONT')
49    test_utils.set_font_format('GX_FONT_FORMAT_8BPP')
50    test_utils.set_font_height(28)
51    test_utils.save_font_edit()
52
53    # add selected font
54    test_utils.add_font()
55    test_utils.set_font_path('..\\..\\fonts\\Vera.ttf')
56    test_utils.set_font_name('SELECTED_FONT')
57    test_utils.set_font_format('GX_FONT_FORMAT_8BPP')
58    test_utils.set_font_height(30)
59    test_utils.save_font_edit()
60
61    # cloce font folder
62    test_utils.click_resource_group('FONT_GROUP')
63
64    test_utils.toolbar_save()
65
66def add_main_screen():
67    #---------------------------------------#
68    #add main screen to display             #
69    #---------------------------------------#
70
71    test_utils.select_project_tree_node("window")
72
73    test_utils.edit_widget_props("ID_XPOS", 0)
74    test_utils.edit_widget_props("ID_YPOS", 0)
75    test_utils.edit_widget_props("ID_WIDTH", 640)
76    test_utils.edit_widget_props("ID_HEIGHT", 480)
77    test_utils.edit_widget_props("ID_WIDGET_NAME", screen_name)
78
79
80def add_edit_numeric_scroll_wheel_widget():
81    #---------------------------------------#
82    #add and edti numeric scroll wheel      #
83    #---------------------------------------#
84    test_utils.select_project_tree_node(screen_name)
85    test_utils.add_widget('GX_TYPE_NUMERIC_SCROLL_WHEEL')
86    widget_name = "numeric_scroll_wheel"
87
88    test_utils.edit_widget_props("ID_XPOS", 10)
89    test_utils.edit_widget_props("ID_YPOS", 10)
90    test_utils.edit_widget_props("ID_WIDTH", 160)
91    test_utils.edit_widget_props("ID_HEIGHT", 240)
92    test_utils.edit_widget_props("ID_WIDGET_NAME", widget_name)
93    test_utils.compare_result()
94
95    # edit numeric scroll wheel properties
96    test_utils.select_project_tree_node(widget_name)
97    test_utils.edit_widget_props('ID_TEXT_SCROLL_WHEEL_NORMAL_FONT', 'NORMAL_FONT')
98    test_utils.edit_widget_props('ID_TEXT_SCROLL_WHEEL_SELECTED_FONT', 'SELECTED_FONT')
99    test_utils.edit_widget_props('ID_SCROLL_WHEEL_SELECTED_ROW', 9)
100    test_utils.edit_widget_props('ID_SCROLL_WHEEL_ROW_HEIHGT', 40)
101    test_utils.edit_widget_props('ID_SCROLL_WHEEL_START_ALPHA', 240)
102    test_utils.edit_widget_props('ID_SCROLL_WHEEL_END_ALPHA', 20)
103    test_utils.edit_widget_props('ID_TEXT_SCROLL_WHEEL_ROUND', 1)
104    test_utils.edit_widget_props('ID_NUMERIC_SCROLL_WHEEL_START_VAL', -100)
105    test_utils.edit_widget_props('ID_NUMERIC_SCROLL_WHEEL_END_VAL', 100)
106    test_utils.edit_widget_props('ID_PIXELMAP_1', 'CHECKBOX_OFF')
107    test_utils.edit_widget_props('ID_SCROLL_WHEEL_TOTAL_ROWS', 100)
108    test_utils.compare_result()
109
110    # test copy paste
111    test_utils.select_project_tree_node(widget_name)
112    test_utils.toolbar_copy()
113    test_utils.select_project_tree_node(screen_name)
114    test_utils.toolbar_paste()
115    test_utils.compare_result()
116
117    # test undo
118    # undo paste
119    test_utils.undo()
120    #test_utils.undo()
121    #undo total rows set
122    test_utils.undo()
123    #undo selected pixelmap set
124    test_utils.undo()
125    #undo end value set
126    test_utils.undo()
127    #undo start value set
128    test_utils.undo()
129    #undo round style set
130    test_utils.undo()
131    #undo end alpha set
132    test_utils.undo()
133    #undo start alpha set
134    test_utils.undo()
135    #undo row height set
136    test_utils.undo()
137    #undo selected row set
138    test_utils.undo()
139    #undo selected font set
140    test_utils.undo()
141    #undo normal font set
142    test_utils.undo()
143
144    test_utils.compare_result()
145
146    test_utils.select_project_tree_node(widget_name)
147    test_utils.edit_widget_props('ID_SCROLL_WHEEL_START_ALPHA', 240)
148    test_utils.edit_widget_props('ID_SCROLL_WHEEL_END_ALPHA', 20)
149    test_utils.edit_widget_props('ID_LIST_WRAP', 1)
150    test_utils.edit_widget_props('ID_TEXT_ALIGN', 'Left')
151
152def edit_string_scroll_wheel_widget():
153    #---------------------------------------#
154    #add and edti string scroll wheel       #
155    #---------------------------------------#
156    test_utils.select_project_tree_node(screen_name)
157    test_utils.add_widget('GX_TYPE_STRING_SCROLL_WHEEL')
158    widget_name = "string_scroll_wheel"
159
160    #edit string scroll wheel properties
161    test_utils.edit_widget_props("ID_XPOS", 200)
162    test_utils.edit_widget_props("ID_YPOS", 10)
163    test_utils.edit_widget_props("ID_WIDTH", 160)
164    test_utils.edit_widget_props("ID_HEIGHT", 240)
165    test_utils.edit_widget_props("ID_WIDGET_NAME", widget_name)
166    test_utils.compare_result()
167
168    test_utils.select_project_tree_node(widget_name)
169    test_utils.edit_widget_props('ID_SCROLL_WHEEL_TOTAL_ROWS', 12)
170    test_utils.edit_widget_props_post('ID_STRING_SCROLL_WHEEL_EDIT_STRINGS', 1)
171    test_utils.wait_dialog_open(test_utils.STRING_SCROLL_WHEEL_EDIT_DIALOG)
172
173    #edti string scroll wheel string
174    test_utils.edit_string_scroll_wheel_string(0, 'January')
175    test_utils.edit_string_scroll_wheel_string(2, 'March')
176    test_utils.edit_string_scroll_wheel_string(3, 'April')
177    test_utils.edit_string_scroll_wheel_string(4, 'May')
178    test_utils.edit_string_scroll_wheel_string(5, 'June')
179    test_utils.edit_string_scroll_wheel_string(6, 'July')
180    test_utils.edit_string_scroll_wheel_string(7, 'August')
181    test_utils.edit_string_scroll_wheel_string(8, 'September')
182    test_utils.edit_string_scroll_wheel_string(9, 'October')
183    test_utils.edit_string_scroll_wheel_string(10, 'Novenber')
184    test_utils.edit_string_scroll_wheel_string(11, 'December')
185    test_utils.save_string_scroll_wheel_edit()
186
187    test_utils.compare_result()
188
189    test_utils.select_project_tree_node(widget_name)
190    test_utils.edit_widget_props('ID_LIST_WRAP', 1)
191    test_utils.edit_widget_props('ID_TEXT_SCROLL_WHEEL_NORMAL_FONT', 'NORMAL_FONT')
192    test_utils.edit_widget_props('ID_TEXT_SCROLL_WHEEL_SELECTED_FONT', 'SELECTED_FONT')
193    test_utils.edit_widget_props('ID_SCROLL_WHEEL_SELECTED_ROW', 3)
194    test_utils.edit_widget_props('ID_SCROLL_WHEEL_ROW_HEIHGT', 40)
195    test_utils.edit_widget_props('ID_SCROLL_WHEEL_START_ALPHA', 240)
196    test_utils.edit_widget_props('ID_SCROLL_WHEEL_END_ALPHA', 20)
197    test_utils.edit_widget_props('ID_TEXT_SCROLL_WHEEL_ROUND', 1)
198    test_utils.compare_result()
199
200    #set callback function
201    test_utils.select_project_tree_node(widget_name)
202    test_utils.edit_widget_props('ID_CALLBACK_NAME', 'string_get_callback')
203    test_utils.undo()
204
205    test_utils.select_project_tree_node(widget_name);
206    test_utils.toolbar_copy()
207    test_utils.select_project_tree_node(screen_name);
208    test_utils.toolbar_paste()
209
210    #undo paste
211    test_utils.undo()
212    #test_utils.undo()
213    #undo round style set
214    test_utils.undo()
215    #undo end alpha set
216    test_utils.undo()
217    #undo start alpha set
218    test_utils.undo()
219    #undo row height set
220    test_utils.undo()
221    #undo selected row set
222    test_utils.undo()
223    #undo selected font set
224    test_utils.undo()
225    #undo normal font set
226    test_utils.undo()
227    #undo wrap style set
228    test_utils.undo()
229    #undo string set
230    test_utils.undo()
231    #undo total rows set
232    test_utils.undo()
233
234    test_utils.select_project_tree_node(widget_name)
235    test_utils.edit_widget_props('ID_TEXT_ALIGN', 'Right')
236
237def run_string_scroll_wheel_font_text_set():
238    test_utils.open_project('all_widgets_execute.gxp')
239    test_utils.select_project_tree_node('scroll_wheel_screen')
240
241    #delete font
242    test_utils.click_resource_group('FONT_GROUP')
243    test_utils.delete_font('VERABD')
244    test_utils.click_resource_group('FONT_GROUP')
245
246    test_utils.compare_result()
247
248    #delete string
249    test_utils.click_resource_group('STRING_GROUP')
250    test_utils.edit_string()
251    test_utils.select_string(2)
252    test_utils.delete_string()
253    test_utils.compare_result()
254    #cancel edit
255    test_utils.cancel_string_edit()
256    test_utils.click_resource_group('STRING_GROUP')
257    test_utils.compare_result()
258
259    test_utils.select_project_tree_node('month_wheel')
260
261def string_scroll_wheel_with_callback_func():
262    test_utils.open_project('test_scroll_wheel.gxp')
263    test_utils.edit_string()
264    test_utils.select_string(0)
265    test_utils.delete_string()
266    test_utils.cancel_string_edit()
267
268    #test fit content button
269    test_utils.select_project_tree_node('string_scroll_wheel')
270    test_utils.toolbar_size_to_fit()
271    test_utils.compare_result()
272
273    test_utils.select_project_tree_node('string_scroll_wheel')
274    test_utils.toolbar_copy()
275    test_utils.select_project_tree_node('main_screen')
276    test_utils.toolbar_paste()
277
278    #remove callback function
279    test_utils.select_project_tree_node('string_scroll_wheel')
280    test_utils.edit_widget_props('ID_CALLBACK_NAME', '')
281    test_utils.edit_widget_props_post('ID_STRING_SCROLL_WHEEL_EDIT_STRINGS', 1)
282    test_utils.wait_dialog_open(test_utils.STRING_SCROLL_WHEEL_EDIT_DIALOG)
283
284    #edti string scroll wheel string
285    test_utils.edit_string_scroll_wheel_string(0, 'January')
286    test_utils.save_string_scroll_wheel_edit()
287    test_utils.compare_result()
288
289def text_scroll_wheel_round_style():
290    test_utils.open_project(test_utils.DEFAULT_OUTPUT_FILE_PATH + 'test_scroll_wheel_widget.gxp')
291    test_utils.select_project_tree_node('numeric_scroll_wheel')
292
293    #turn round transform style on
294    test_utils.edit_widget_props('ID_TEXT_SCROLL_WHEEL_ROUND', 1)
295
296    #configure project to set color format to 332rgb
297    test_utils.configure_project()
298    test_utils.configure_display_color_depth(8)
299    test_utils.configure_display_rgb_bits(332)
300    test_utils.save_project_configure()
301
302    test_utils.compare_result()
303
304    #configure project to set color format to 8bit palette
305    test_utils.configure_project()
306    test_utils.configure_display_color_depth(8)
307    test_utils.configure_display_rgb_bits(332)
308    test_utils.save_project_configure()
309
310    test_utils.select_project_tree_node('numeric_scroll_wheel')
311    test_utils.compare_result()
312
313
314def run_scroll_wheel_widget_tests(generate, screenshot):
315
316    test_utils.output_test_header(get_test_header())
317    test_utils.setup(generate, screenshot, 'test_scroll_wheel_widget_golden_file')
318
319    print('create new project')
320    run_new_project_create("test_scroll_wheel_widget")
321
322    print('add main screen')
323    add_main_screen()
324
325    print('add and edit string scroll wheel widget')
326    add_edit_numeric_scroll_wheel_widget()
327
328    print('add and edit numeric scroll wheel widget')
329    edit_string_scroll_wheel_widget()
330
331    test_utils.toolbar_save()
332    test_utils.generate_all()
333    test_utils.click_generate_button()
334    test_utils.cmp_output_files(test_scroll_wheel_widget_output_files)
335
336    #close project with widget been selected
337    test_utils.select_project_tree_node("numeric_scroll_wheel")
338    test_utils.close_project()
339    test_utils.open_project(test_utils.DEFAULT_OUTPUT_FILE_PATH + "\\test_scroll_wheel_widget.gxp")
340    test_utils.select_project_tree_node("string_scroll_wheel")
341    test_utils.close_project()
342
343    print('run string scroll wheel font text set')
344    run_string_scroll_wheel_font_text_set()
345
346    print('test string scroll wheel with callback func')
347    string_scroll_wheel_with_callback_func()
348
349    print('test text scroll wheel round style')
350    text_scroll_wheel_round_style()
351
352    test_utils.write_end('Scroll Wheel Widget Tests')