Update git submodules
[LibreOffice.git] / uitest / ui_logger_dsl / dsl_core.py
blob798dc43256e987503aba05f54bba5588849fcdcd
1 #!/usr/bin/env python3
2 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
4 # This file is part of the LibreOffice UI_logger project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # This file contains the implementation of the Compiler
11 # for the new logger grammar
13 # ul stands for Ui_Logger
15 import os
16 import sys
17 import argparse
18 import keyword
20 try:
21 from textx.metamodel import metamodel_from_file
22 except ImportError:
23 print("textx is a required package.")
24 print('Please install the package for example with "pip3 install --user textx"')
25 sys.exit(1)
27 tab = " "
29 def parse_args():
30 """
31 This function parses the command-line arguments
32 to get the input and output file details
33 """
34 parser = argparse.ArgumentParser(description="Generate a UI test file from log")
35 parser.add_argument("input_address", type=str, help="The log file address")
36 parser.add_argument("output_address", type=str, help="The test file address")
37 args = parser.parse_args()
38 return args
41 class ul_Compiler:
42 prev_command = ""
43 variables = []
44 objects = dict()
45 current_app = ""
46 parent_hierarchy_count = 0
47 last_parent = []
48 flag_for_QuerySaveDialog = False
49 math_element_selector_initializer= False;
51 def __init__(self, input_address, output_address):
52 self.ui_dsl_mm = metamodel_from_file("ui_logger_dsl_grammar.tx")
53 self.output_stream = self.initiate_test_generation(output_address)
54 self.input_address = input_address
56 def get_log_file(self, input_address):
57 try:
58 # load the program
59 content = self.ui_dsl_mm.model_from_file(input_address)
60 except IOError as err:
61 print("IO error: {0}".format(err))
62 print(
63 "Use " + os.path.basename(sys.argv[0]) + " -h to get usage instructions"
65 sys.exit(1)
67 return content
69 def initiate_test_generation(self, output_address):
70 self.last_parent.append("MainWindow")
71 try:
72 f = open(output_address, "w")
73 except IOError as err:
74 print("IO error: {0}".format(err))
75 print(
76 "Use " + os.path.basename(sys.argv[0]) + " -h to get usage instructions"
78 sys.exit(1)
79 line = (
80 "# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-\n"
81 + "#\n"
82 + "# This file is part of the LibreOffice project.\n"
83 + "#\n"
84 + "# This Source Code Form is subject to the terms of the Mozilla Public\n"
85 + "# License, v. 2.0. If a copy of the MPL was not distributed with this\n"
86 + "# file, You can obtain one at http://mozilla.org/MPL/2.0/\n"
87 + "#\n\n"
88 + "from uitest.framework import UITestCase\n"
89 + "from libreoffice.uno.propertyvalue import mkPropertyValues\n"
90 + "from uitest.uihelper.common import get_state_as_dict\n"
91 + "import importlib\n\n"
92 + "class TestClass(UITestCase):\n"
93 + tab
94 + "def test_function(self):\n"
97 self.variables.append(line)
99 return f
101 def compile(self):
102 self.ui_dsl_mm.register_obj_processors(
104 "UNOCommand": self.handle_uno,
105 "StarterCommand": self.handle_start,
106 "CloseDialog": self.handle_Dialog,
107 "OpenModelessDialog": self.handle_Dialog,
108 "OpenModalDialog": self.handle_Dialog,
109 "ButtonUIObject": self.handle_button,
110 "CheckBoxUIObject": self.handle_check_box,
111 "TabControlUIObject": self.handle_tab,
112 "ComboBoxUIObject": self.handle_Combo_box,
113 "RadioButtonUIObject": self.handle_Radio_button,
114 "ListBoxUIObject": self.handle_List_box,
115 "SpinFieldUIObject": self.handle_spin_field,
116 "EditUIObject": self.handle_Edit_uiObject,
117 "ToolBoxUIObject": self.handle_ToolBox_uiObject,
118 "ValueSetUIObject": self.handle_ValueSet_uiObject,
119 "MenuBtnUIObjectOpen":self.handle_MenuBtnUIObjectOpen,
120 "MenuBtnUIObjectSelect":self.handle_MenuBtnUIObjectSelect,
121 "MenuBtnUIObjectClose":self.handle_MenuBtnUIObjectClose,
122 "writer_Type_command": self.handle_writer_type,
123 "writer_Select_command": self.handle_writer_select,
124 "writer_GOTO_command": self.handle_writer_goto,
125 "calc_Select_cell": self.handle_calc_select,
126 "calc_switch_sheet": self.handle_calc_switch_sheet,
127 "calc_Type_command": self.handle_calc_Type_command,
128 "calc_AutoFill_filter": self.handle_calc_AutoFill_filter,
129 "calc_SelectMenu_filter": self.handle_calc_SelectMenu_filter,
130 "calc_Open_Comment": self.handle_calc_Open_Comment,
131 "calc_Close_Comment": self.handle_calc_Close_Comment,
132 "impress_Type_command": self.handle_impress_Type_command,
133 "math_element_selector": self.handle_math_element_selector,
134 "math_Type_command": self.handle_math_Type_command,
135 "setZoom_command": self.handle_setZoom_command,
136 "draw_Type_command": self.handle_draw_Type_command,
137 "SideBar": self.handle_SideBar,
138 "writer_Comment_leave":self.handle_writer_Comment_leave,
139 "writer_Comment_show":self.handle_writer_Comment_show,
140 "writer_Comment_hide":self.handle_writer_Comment_hide,
141 "writer_Comment_delete":self.handle_writer_Comment_delete,
142 "writer_Comment_setresolved":self.handle_writer_Comment_setresolved,
143 "writer_Copy_Text": self.do_nothing,
144 "writer_Cut_Text": self.do_nothing,
145 "writer_Paste_Text": self.do_nothing,
146 "writer_Insert_BreakPage": self.do_nothing,
147 "writer_Create_table": self.do_nothing,
148 "calc_Remove_Content": self.do_nothing,
149 "calc_Delete_Cells": self.do_nothing,
150 "calc_insert_cells": self.do_nothing,
151 "calc_Cut_Cells": self.do_nothing,
152 "calc_Copy_Cells": self.do_nothing,
153 "calc_Merge_Cells": self.do_nothing,
154 "calc_UNMerge_Cells": self.do_nothing,
155 "calc_Rename_Sheet": self.do_nothing,
156 "calc_Insert_sheet": self.do_nothing,
157 "impress_Insert_Slide": self.do_nothing,
158 "impress_Delete_Page": self.do_nothing,
159 "impress_Duplicate_Slide": self.do_nothing,
160 "impress_Rename_Slide": self.do_nothing,
161 "draw_Insert_Page": self.do_nothing,
162 "draw_Delete_Page": self.do_nothing,
163 "draw_Rename_Page": self.do_nothing,
167 self.log_lines = self.get_log_file(self.input_address)
169 def init_app(self):
170 if self.current_app in self.objects:
171 self.objects[self.current_app] += 1
172 else:
173 self.objects[self.current_app] = 1
174 line = (
175 tab * 4
176 + self.current_app
177 + ' = MainWindow.getChild("'
178 + self.current_app
179 + '")\n'
181 self.variables.append(line)
183 def init_Object(self, Id_of_Object, name_of_child, Obj_parent):
185 if Id_of_Object in self.objects:
186 self.objects[Id_of_Object] += 1
187 else:
188 self.objects[Id_of_Object] = 1
189 line = (
190 tab * 4
191 + Id_of_Object
192 + " = "
193 + Obj_parent
194 + '.getChild("'
195 + name_of_child
196 + '")\n'
199 self.variables.append(line)
201 def write_line_without_parameters(self, Action_holder, Action, Action_type):
202 line = (
203 tab * 4
204 + Action_holder
205 + '.executeAction("'
206 + Action
207 + '",'
208 + Action_type
209 + "())\n"
211 self.variables.append(line)
213 def write_line_with_one_parameters(
214 self, Action_holder, Action, Parameter_name, parameter_value
216 line = (
217 tab * 4
218 + Action_holder
219 + '.executeAction("'
220 + Action
221 + '", mkPropertyValues({"'
222 + Parameter_name
223 + '": "'
224 + str(parameter_value)
225 + '"}))\n'
227 self.variables.append(line)
229 def write_line_with_two_parameters(
230 self,
231 Action_holder,
232 Action,
233 Parameter_name_1,
234 parameter_value_1,
235 Parameter_name_2,
236 parameter_value_2,
239 line = (
240 tab * 3
241 + Action_holder
242 + '.executeAction("'
243 + Action
244 + '", mkPropertyValues({"'
245 + Parameter_name_1
246 + '": "'
247 + str(parameter_value_1)
248 + '", "'
249 + Parameter_name_2
250 + '": "'
251 + str(parameter_value_2)
252 + '"}))\n'
254 self.variables.append(line)
256 def handle_uno(self, UNOCommand):
257 if UNOCommand.parameters == None:
258 line = (
259 tab * 3
260 + 'self.xUITest.executeCommand("'
261 + UNOCommand.uno_command_name
262 + '")\n'
264 else:
265 parameters = ""
266 for p in UNOCommand.parameters.parameter_data:
267 parameters = parameters + '"' + p.key + '" : ' + str(p.value) + " ,"
268 parameters = parameters[:-1]
270 line = (
271 tab * 3
272 + 'self.xUITest.executeCommandWithParameters("'
273 + UNOCommand.uno_command_name
274 + '", mkPropertyValues({'
275 + parameters
276 + "}) )\n"
279 self.variables.append(line)
280 self.prev_command = UNOCommand
282 def handle_start(self, StarterCommand):
283 line = (
284 tab * 2
285 + 'with self.ui_test.create_doc_in_start_center("'
286 + StarterCommand.program_name
287 + '") as document:\n'
289 self.variables.append(line)
291 line = tab * 3 + "MainWindow = self.xUITest.getTopFocusWindow()\n"
292 self.variables.append(line)
293 app = {
294 "writer": "writer_edit",
295 "calc": "grid_window",
296 "impress": "impress_win",
297 "math": "math_edit",
298 "draw": "draw_win",
300 self.current_app = app[StarterCommand.program_name]
301 self.prev_command = StarterCommand
303 def handle_SideBar(self, SideBar):
305 line = ' self.xUITest.executeCommand(".uno:Sidebar")\n'
306 self.variables.append(line)
308 self.write_line_with_one_parameters(
309 "MainWindow", "SIDEBAR", "PANEL", SideBar.name
312 self.prev_command = SideBar
314 def handle_Dialog(self, DialogCommand):
316 if DialogCommand.__class__.__name__ == "OpenModalDialog":
318 if DialogCommand.dialog_name != "QuerySaveDialog":
319 # This part is just to ignore saving the Save dialog while closing the app
321 old_line = self.variables.pop()
322 if self.prev_command.__class__.__name__ == "UNOCommand":
323 key_word = self.prev_command.uno_command_name[-6:]
324 else:
325 key_word = old_line[-9:-3]
327 if key_word == "Dialog":
328 old_line = (
329 tab * 3
330 + 'with self.ui_test.execute_dialog_through_command("'
331 + self.prev_command.uno_command_name
332 + '") as '
333 + DialogCommand.dialog_name
334 + ':\n'
336 self.variables.append(old_line)
337 self.last_parent.append(DialogCommand.dialog_name)
338 self.parent_hierarchy_count = self.parent_hierarchy_count + 1
340 else:
341 self.flag_for_QuerySaveDialog = True
343 elif DialogCommand.__class__.__name__ == "OpenModelessDialog":
344 old_line = self.variables.pop()
345 if self.prev_command.__class__.__name__ == "UNOCommand":
346 key_word = self.prev_command.uno_command_name[-6:]
347 else:
348 key_word = old_line[-9:-3]
350 if key_word == "Dialog":
351 old_line = (
352 tab * 3
353 + 'with self.ui_test.execute_modeless_dialog_through_command("'
354 + self.prev_command.uno_command_name
355 + '") as '
356 + DialogCommand.dialog_name
357 + ':\n'
359 self.variables.append(old_line)
360 self.last_parent.append(DialogCommand.dialog_name)
361 self.parent_hierarchy_count = self.parent_hierarchy_count + 1
363 elif DialogCommand.__class__.__name__ == "CloseDialog":
365 if not (self.flag_for_QuerySaveDialog):
366 # This part is just to ignore saving the Save dialog while closing the app
368 if self.prev_command.__class__.__name__ == "ButtonUIObject":
369 old_line = self.variables.pop()
370 line = ""
371 if keyword.iskeyword(self.prev_command.ui_button):
372 line = (
373 tab * 4
374 + "self.ui_test.close_dialog_through_button(x"
375 + self.prev_command.ui_button
376 + ")\n"
378 else:
379 line = (
380 tab * 4
381 + "self.ui_test.close_dialog_through_button("
382 + self.prev_command.ui_button
383 + ")\n"
385 self.variables.append(line)
386 self.last_parent.pop()
387 self.parent_hierarchy_count = self.parent_hierarchy_count - 1
388 else:
389 self.flag_for_QuerySaveDialog = False
391 # This is to solve the problem of re-using the same id again in different Dialogs
393 self.objects.clear()
395 self.prev_command = DialogCommand
397 def handle_button(self, ButtonUIObject):
399 if ButtonUIObject.parent_id != "QuerySaveDialog":
400 # This part is just to ignore saving the Save dialog while closing the app
402 name_of_obj = ""
403 if keyword.iskeyword(ButtonUIObject.ui_button):
404 name_of_obj = "x" + ButtonUIObject.ui_button
405 else:
406 name_of_obj = ButtonUIObject.ui_button
408 if ButtonUIObject.parent_id == "":
409 self.init_Object(
410 name_of_obj,
411 ButtonUIObject.ui_button,
412 self.last_parent[self.parent_hierarchy_count],
414 else:
415 self.init_Object(
416 name_of_obj, ButtonUIObject.ui_button, ButtonUIObject.parent_id
419 self.write_line_without_parameters(name_of_obj, "CLICK", "tuple")
421 self.prev_command = ButtonUIObject
423 def handle_check_box(self, CheckBoxUIObject):
425 name_of_obj = ""
426 if keyword.iskeyword(CheckBoxUIObject.Check_box_id):
427 name_of_obj = "x" + CheckBoxUIObject.Check_box_id
428 else:
429 name_of_obj = CheckBoxUIObject.Check_box_id
431 if CheckBoxUIObject.parent_id == "":
432 self.init_Object(
433 name_of_obj,
434 CheckBoxUIObject.Check_box_id,
435 self.last_parent[self.parent_hierarchy_count],
437 else:
438 self.init_Object(
439 name_of_obj, CheckBoxUIObject.Check_box_id, CheckBoxUIObject.parent_id
442 self.write_line_without_parameters(name_of_obj, "CLICK", "tuple")
444 self.prev_command = CheckBoxUIObject
446 def handle_tab(self, TabControlUIObject):
448 name_of_obj = ""
449 if keyword.iskeyword(TabControlUIObject.tab_id):
450 name_of_obj = "x" + TabControlUIObject.tab_id
451 else:
452 name_of_obj = TabControlUIObject.tab_id
454 if TabControlUIObject.parent_id == "":
455 self.init_Object(
456 name_of_obj,
457 TabControlUIObject.tab_id,
458 self.last_parent[self.parent_hierarchy_count],
460 else:
461 self.init_Object(
462 name_of_obj, TabControlUIObject.tab_id, TabControlUIObject.parent_id
465 self.write_line_with_one_parameters(
466 name_of_obj, "SELECT", "POS", TabControlUIObject.tab_page_number
469 self.prev_command = TabControlUIObject
471 def handle_Combo_box(self, ComboBoxUIObject):
473 name_of_obj = ""
474 if keyword.iskeyword(ComboBoxUIObject.Combo_box_id):
475 name_of_obj = "x" + ComboBoxUIObject.Combo_box_id
476 else:
477 name_of_obj = ComboBoxUIObject.Combo_box_id
479 if ComboBoxUIObject.parent_id == "":
480 self.init_Object(
481 name_of_obj,
482 ComboBoxUIObject.Combo_box_id,
483 self.last_parent[self.parent_hierarchy_count],
485 else:
486 self.init_Object(
487 name_of_obj, ComboBoxUIObject.Combo_box_id, ComboBoxUIObject.parent_id
490 self.write_line_with_one_parameters(
491 name_of_obj, "SELECT", "POS", ComboBoxUIObject.item_num
494 self.prev_command = ComboBoxUIObject
496 def handle_Radio_button(self, RadioButtonUIObject):
498 name_of_obj = ""
499 if keyword.iskeyword(RadioButtonUIObject.Radio_button_id):
500 name_of_obj = "x" + RadioButtonUIObject.Radio_button_id
501 else:
502 name_of_obj = RadioButtonUIObject.Radio_button_id
504 if RadioButtonUIObject.parent_id == "":
505 self.init_Object(
506 name_of_obj,
507 RadioButtonUIObject.Radio_button_id,
508 self.last_parent[self.parent_hierarchy_count],
510 else:
511 self.init_Object(
512 name_of_obj,
513 RadioButtonUIObject.Radio_button_id,
514 RadioButtonUIObject.parent_id,
517 self.write_line_without_parameters(name_of_obj, "CLICK", "tuple")
519 self.prev_command = RadioButtonUIObject
521 def handle_List_box(self, ListBoxUIObject):
523 name_of_obj = ""
524 if keyword.iskeyword(ListBoxUIObject.list_id):
525 name_of_obj = "x" + ListBoxUIObject.list_id
526 else:
527 name_of_obj = ListBoxUIObject.list_id
529 if ListBoxUIObject.parent_id == "":
530 self.init_Object(
531 name_of_obj,
532 ListBoxUIObject.list_id,
533 self.last_parent[self.parent_hierarchy_count],
535 else:
536 self.init_Object(
537 name_of_obj, ListBoxUIObject.list_id, ListBoxUIObject.parent_id
540 self.write_line_with_one_parameters(
541 name_of_obj, "SELECT", "POS", ListBoxUIObject.POS
544 self.prev_command = ListBoxUIObject
546 def handle_spin_field(self, SpinFieldUIObject):
548 name_of_obj = ""
549 if keyword.iskeyword(SpinFieldUIObject.Spin_id):
550 name_of_obj = "x" + SpinFieldUIObject.Spin_id
551 else:
552 name_of_obj = SpinFieldUIObject.Spin_id
554 if SpinFieldUIObject.parent_id == "":
555 self.init_Object(
556 name_of_obj,
557 SpinFieldUIObject.Spin_id,
558 self.last_parent[self.parent_hierarchy_count],
560 else:
561 self.init_Object(
562 name_of_obj, SpinFieldUIObject.Spin_id, SpinFieldUIObject.parent_id
565 if SpinFieldUIObject.change == "Increase":
566 self.write_line_without_parameters(name_of_obj, "UP", "tuple")
567 elif SpinFieldUIObject.change == "Decrease":
568 self.write_line_without_parameters(name_of_obj, "DOWN", "tuple")
569 self.prev_command = SpinFieldUIObject
571 def handle_Edit_uiObject(self, EditUIObject):
573 name_of_obj = ""
574 if keyword.iskeyword(EditUIObject.action.edit_button):
575 name_of_obj = "x" + EditUIObject.action.edit_button
576 else:
577 name_of_obj = EditUIObject.action.edit_button
579 if EditUIObject.parent_id == "":
580 self.init_Object(
581 name_of_obj,
582 EditUIObject.action.edit_button,
583 self.last_parent[self.parent_hierarchy_count],
585 else:
586 self.init_Object(
587 name_of_obj, EditUIObject.action.edit_button, EditUIObject.parent_id
590 if EditUIObject.action.__class__.__name__ == "Type_action":
592 if EditUIObject.action.what_to_type.__class__.__name__ == "char":
593 self.write_line_with_one_parameters(
594 name_of_obj,
595 "TYPE",
596 "TEXT",
597 EditUIObject.action.what_to_type.input_char,
600 elif EditUIObject.action.what_to_type.__class__.__name__ == "KeyCode":
601 self.write_line_with_one_parameters(
602 name_of_obj,
603 "TYPE",
604 "KEYCODE",
605 EditUIObject.action.what_to_type.input_key_code,
608 if EditUIObject.action.__class__.__name__ == "SELECT":
610 self.write_line_with_two_parameters(
611 name_of_obj,
612 "SELECT",
613 "FROM",
614 EditUIObject.action.from_pos,
615 "TO",
616 EditUIObject.action.to_pos,
619 if EditUIObject.action.__class__.__name__ == "Clear":
621 self.write_line_without_parameters(name_of_obj, "CLEAR", "tuple")
623 self.prev_command = EditUIObject
625 def handle_ToolBox_uiObject(self, ToolBoxUIObject):
626 name_of_obj = ""
627 if keyword.iskeyword(ToolBoxUIObject.toolbox_id):
628 name_of_obj = "x" + ToolBoxUIObject.toolbox_id
629 else:
630 name_of_obj = ToolBoxUIObject.toolbox_id
632 self.init_Object(
633 name_of_obj,
634 ToolBoxUIObject.toolbox_id,
635 self.last_parent[self.parent_hierarchy_count],
638 self.write_line_with_one_parameters(
639 name_of_obj, "CLICK", "POS", ToolBoxUIObject.POS
642 self.prev_command = ToolBoxUIObject
644 def handle_ValueSet_uiObject(self, ValueSetUIObject):
646 name_of_obj = ""
647 if keyword.iskeyword(ValueSetUIObject.value_set_id):
648 name_of_obj = "x" + ValueSetUIObject.value_set_id
649 else:
650 name_of_obj = ValueSetUIObject.value_set_id
652 parent_txt = ValueSetUIObject.parent_id.split("/")
653 parent = parent_txt[len(parent_txt)-2]
654 if( parent.upper() != self.last_parent[self.parent_hierarchy_count].upper()):
655 self.init_Object(
656 parent,
657 parent,
658 self.last_parent[self.parent_hierarchy_count],
661 self.init_Object(
662 name_of_obj, ValueSetUIObject.value_set_id, parent
665 else:
666 self.init_Object(
667 name_of_obj, ValueSetUIObject.value_set_id, self.last_parent[self.parent_hierarchy_count]
670 self.write_line_with_one_parameters(
671 name_of_obj, "CHOOSE", "POS", ValueSetUIObject.POS
674 self.prev_command = ValueSetUIObject
676 def handle_MenuBtnUIObjectOpen(self, MenuBtnUIObjectOpen):
677 name_of_obj = ""
678 if keyword.iskeyword(MenuBtnUIObjectOpen.MenuBtn_ID):
679 name_of_obj = "x" + MenuBtnUIObjectOpen.MenuBtn_ID
680 else:
681 name_of_obj = MenuBtnUIObjectOpen.MenuBtn_ID
683 self.init_Object(
684 name_of_obj,
685 MenuBtnUIObjectOpen.MenuBtn_ID,
686 self.last_parent[self.parent_hierarchy_count],
689 self.write_line_with_one_parameters(
690 name_of_obj, "OPENLIST", "", ""
693 self.prev_command = MenuBtnUIObjectOpen
695 def handle_MenuBtnUIObjectClose(self, MenuBtnUIObjectClose):
696 name_of_obj = ""
697 if keyword.iskeyword(MenuBtnUIObjectClose.MenuBtn_ID):
698 name_of_obj = "x" + MenuBtnUIObjectClose.MenuBtn_ID
699 else:
700 name_of_obj = MenuBtnUIObjectClose.MenuBtn_ID
702 self.init_Object(
703 name_of_obj,
704 MenuBtnUIObjectClose.MenuBtn_ID,
705 self.last_parent[self.parent_hierarchy_count],
708 self.write_line_with_one_parameters(
709 name_of_obj, "CLOSELIST", "", ""
712 self.prev_command = MenuBtnUIObjectClose
714 def handle_MenuBtnUIObjectSelect(self, MenuBtnUIObjectSelect):
715 name_of_obj = ""
716 if keyword.iskeyword(MenuBtnUIObjectSelect.MenuBtn_ID):
717 name_of_obj = "x" + MenuBtnUIObjectSelect.MenuBtn_ID
718 else:
719 name_of_obj = MenuBtnUIObjectSelect.MenuBtn_ID
721 self.init_Object(
722 name_of_obj,
723 MenuBtnUIObjectSelect.MenuBtn_ID,
724 self.last_parent[self.parent_hierarchy_count],
727 self.write_line_with_one_parameters(
728 name_of_obj, "OPENFROMLIST", "POS", MenuBtnUIObjectSelect.item_num[0]
731 self.prev_command = MenuBtnUIObjectSelect
733 def handle_writer_type(self, writer_Type_command):
735 self.init_app()
737 if writer_Type_command.what_to_type.__class__.__name__ == "char":
738 self.write_line_with_one_parameters(
739 self.current_app,
740 "TYPE",
741 "TEXT",
742 writer_Type_command.what_to_type.input_char,
745 elif writer_Type_command.what_to_type.__class__.__name__ == "KeyCode":
746 self.write_line_with_one_parameters(
747 self.current_app,
748 "TYPE",
749 "KEYCODE",
750 writer_Type_command.what_to_type.input_key_code,
753 self.prev_command = writer_Type_command
755 def handle_writer_select(self, writer_Select_command):
757 self.init_app()
759 self.write_line_with_two_parameters(
760 self.current_app,
761 "SELECT",
762 "END_POS",
763 writer_Select_command.from_pos,
764 "START_POS",
765 writer_Select_command.to_pos,
768 self.prev_command = writer_Select_command
770 def handle_writer_goto(self, writer_GOTO_command):
772 self.init_app()
774 self.write_line_with_one_parameters(
775 self.current_app, "GOTO", "PAGE", writer_GOTO_command.page_num
778 self.prev_command = writer_GOTO_command
780 def handle_calc_select(self, calc_Select_cell):
782 self.init_app()
784 if calc_Select_cell.select_op.__class__.__name__ == "range_of_cells":
785 self.write_line_with_one_parameters(
786 self.current_app,
787 "SELECT",
788 "RANGE",
789 calc_Select_cell.select_op.input_range,
792 elif calc_Select_cell.select_op.__class__.__name__ == "one_cell":
793 self.write_line_with_one_parameters(
794 self.current_app,
795 "SELECT",
796 "CELL",
797 calc_Select_cell.select_op.input_cell,
800 self.prev_command = calc_Select_cell
802 def handle_calc_switch_sheet(self, calc_switch_sheet):
804 self.init_app()
806 self.write_line_with_one_parameters(
807 self.current_app, "SELECT", "TABLE", calc_switch_sheet.sheet_num
810 self.prev_command = calc_switch_sheet
812 def handle_calc_Type_command(self, calc_Type_command):
814 self.init_app()
816 if calc_Type_command.what_to_type.__class__.__name__ == "char":
817 self.write_line_with_one_parameters(
818 self.current_app,
819 "TYPE",
820 "TEXT",
821 calc_Type_command.what_to_type.input_char,
824 elif calc_Type_command.what_to_type.__class__.__name__ == "KeyCode":
825 self.write_line_with_one_parameters(
826 self.current_app,
827 "TYPE",
828 "KEYCODE",
829 calc_Type_command.what_to_type.input_key_code,
832 self.prev_command = calc_Type_command
834 def handle_calc_AutoFill_filter(self, calc_AutoFill_filter):
836 self.init_app()
838 line = (
839 tab * 3
840 + self.current_app
841 + '.executeAction("LAUNCH", mkPropertyValues'
842 + '({"AUTOFILTER": "", "COL": "'
843 + str(calc_AutoFill_filter.col_num)
844 + '"'
845 + ', "ROW": "'
846 + str(calc_AutoFill_filter.row_num)
847 + '"}))\n'
850 self.variables.append(line)
851 self.prev_command = calc_AutoFill_filter
853 def handle_calc_Open_Comment(self, calc_Open_Comment):
855 line = (
856 tab * 3
857 + self.current_app
858 + '.executeAction("COMMENT", mkPropertyValues'
859 + '({"OPEN": " "}))\n'
862 self.variables.append(line)
864 self.prev_command = calc_Open_Comment
866 def handle_calc_Close_Comment(self, calc_Close_Comment):
868 line = (
869 tab * 3
870 + self.current_app
871 + '.executeAction("COMMENT", mkPropertyValues'
872 + '({"CLOSE": " "}))\n'
875 self.variables.append(line)
877 self.prev_command = calc_Close_Comment
879 def handle_calc_SelectMenu_filter(self, calc_SelectMenu_filter):
881 self.init_app()
883 line = (
884 tab * 3
885 + self.current_app
886 + '.executeAction("LAUNCH", mkPropertyValues'
887 + '({"SELECTMENU": "", "COL": "'
888 + str(calc_SelectMenu_filter.col_num)
889 + '"'
890 + ', "ROW": "'
891 + str(calc_SelectMenu_filter.row_num)
892 + '"}))\n'
895 self.variables.append(line)
896 self.prev_command = calc_SelectMenu_filter
898 def handle_impress_Type_command(self, impress_Type_command):
900 self.init_app()
902 if impress_Type_command.what_to_type.__class__.__name__ == "char":
903 self.write_line_with_one_parameters(
904 self.current_app,
905 "TYPE",
906 "TEXT",
907 impress_Type_command.what_to_type.input_char,
910 elif impress_Type_command.what_to_type.__class__.__name__ == "KeyCode":
911 self.write_line_with_one_parameters(
912 self.current_app,
913 "TYPE",
914 "KEYCODE",
915 impress_Type_command.what_to_type.input_key_code,
918 self.prev_command = impress_Type_command
920 def handle_math_Type_command(self, math_Type_command):
922 self.init_app()
923 if math_Type_command.what_to_type.__class__.__name__ == "char":
924 self.write_line_with_one_parameters(
925 self.current_app,
926 "TYPE",
927 "TEXT",
928 math_Type_command.what_to_type.input_char,
931 elif math_Type_command.what_to_type.__class__.__name__ == "KeyCode":
932 self.write_line_with_one_parameters(
933 self.current_app,
934 "TYPE",
935 "KEYCODE",
936 math_Type_command.what_to_type.input_key_code,
939 self.prev_command = math_Type_command
941 def handle_draw_Type_command(self, draw_Type_command):
943 self.init_app()
944 if draw_Type_command.what_to_type.__class__.__name__ == "char":
945 self.write_line_with_one_parameters(
946 self.current_app,
947 "TYPE",
948 "TEXT",
949 draw_Type_command.what_to_type.input_char,
952 elif draw_Type_command.what_to_type.__class__.__name__ == "KeyCode":
953 self.write_line_with_one_parameters(
954 self.current_app,
955 "TYPE",
956 "KEYCODE",
957 draw_Type_command.what_to_type.input_key_code,
960 self.prev_command = draw_Type_command
962 def handle_math_element_selector(self, math_element_selector):
964 if( self.math_element_selector_initializer == False ):
965 # This part is for initializing the element selector in the Math application
966 self.math_element_selector_initializer = True
967 line = (
968 tab * 4
969 + "element_selector"
970 + ' = MainWindow.getChild("'
971 + "element_selector"
972 + '")\n'
974 self.variables.append(line)
976 # This inserts a prefix of 'x' to avoid creating variables with only numeric characters
977 element_name="x"+str(math_element_selector.element_no)
979 self.init_Object(element_name,str(math_element_selector.element_no),"element_selector")
981 self.write_line_without_parameters(
982 str(element_name), "SELECT", "tuple"
985 self.prev_command = math_element_selector
987 def handle_writer_Comment_leave(self,writer_Comment_leave):
989 self.init_app()
991 self.init_Object(
992 writer_Comment_leave.comment_id, writer_Comment_leave.comment_id, "MainWindow"
995 self.write_line_with_one_parameters(
996 writer_Comment_leave.comment_id, "LEAVE", "", ""
999 self.prev_command = writer_Comment_leave
1001 def handle_writer_Comment_show(self,writer_Comment_show):
1003 self.init_app()
1005 self.init_Object(
1006 writer_Comment_show.comment_id, writer_Comment_show.comment_id, "MainWindow"
1009 self.write_line_with_one_parameters(
1010 writer_Comment_show.comment_id, "SHOW", "", ""
1013 self.prev_command = writer_Comment_show
1015 def handle_writer_Comment_hide(self,writer_Comment_hide):
1017 self.init_app()
1019 self.init_Object(
1020 writer_Comment_hide.comment_id, writer_Comment_hide.comment_id, "MainWindow"
1023 self.write_line_with_one_parameters(
1024 writer_Comment_hide.comment_id, "HIDE", "", ""
1027 self.prev_command = writer_Comment_hide
1029 def handle_writer_Comment_delete(self,writer_Comment_delete):
1031 self.init_app()
1033 self.init_Object(
1034 writer_Comment_delete.comment_id, writer_Comment_delete.comment_id, "MainWindow"
1037 self.write_line_with_one_parameters(
1038 writer_Comment_delete.comment_id, "DELETE", "", ""
1041 self.prev_command = writer_Comment_delete
1043 def handle_writer_Comment_setresolved(self,writer_Comment_setresolved):
1045 self.init_app()
1047 self.init_Object(
1048 writer_Comment_setresolved.comment_id, writer_Comment_setresolved.comment_id, "MainWindow"
1051 self.write_line_with_one_parameters(
1052 writer_Comment_setresolved.comment_id, "RESOLVE", "", ""
1055 self.prev_command = writer_Comment_setresolved
1057 def handle_setZoom_command(self, setZoom_command):
1059 self.init_app()
1061 self.write_line_with_one_parameters(
1062 self.current_app, "SET", "ZOOM", setZoom_command.zoom_value
1065 self.prev_command = setZoom_command
1067 def Generate_UI_test(self):
1068 line = "\n\n# vim: set shiftwidth=4 softtabstop=4 expandtab:"
1069 self.variables.append(line)
1071 for line in self.variables:
1072 self.output_stream.write(str(line))
1074 def do_nothing(self, Command):
1075 # to be added in the future
1076 pass
1078 def __del__(self):
1079 self.output_stream.close()
1082 def main():
1083 args = parse_args()
1084 ui_logger = ul_Compiler(args.input_address, args.output_address)
1085 ui_logger.compile()
1086 for statement in ui_logger.log_lines.commands:
1087 print(statement)
1088 ui_logger.Generate_UI_test()
1089 del ui_logger
1092 if __name__ == "__main__":
1093 main()