1#!/usr/local/bin/python3.8 2# This file is part of the LibreOffice UI_logger project. 3# 4# This file contain the implementation of the Compiler 5# for the new logger grammar 6# 7# ul stands for Ui_Logger 8 9import os 10import sys 11import argparse 12import keyword 13 14try: 15 from textx.metamodel import metamodel_from_file 16except ImportError: 17 print("textx is a required package.") 18 print('Please install the package for example with "pip3 install --user textx"') 19 sys.exit(1) 20 21tab = " " 22double_tab = " " 23 24 25def parse_args(): 26 """ 27 This function parses the command-line arguments 28 to get the input and output file details 29 """ 30 parser = argparse.ArgumentParser(description="Generate a UI test file from log") 31 parser.add_argument("input_address", type=str, help="The log file address") 32 parser.add_argument("output_address", type=str, help="The test file address") 33 args = parser.parse_args() 34 return args 35 36 37class ul_Compiler: 38 prev_command = "" 39 variables = [] 40 objects = dict() 41 current_app = "" 42 parent_hierarchy_count = 0 43 last_parent = [] 44 flag_for_QuerySaveDialog = False 45 46 def __init__(self, input_address, output_address): 47 self.ui_dsl_mm = metamodel_from_file("ui_logger_dsl_grammar.tx") 48 self.output_stream = self.initiate_test_generation(output_address) 49 self.input_address = input_address 50 51 def get_log_file(self, input_address): 52 try: 53 # load the program 54 content = self.ui_dsl_mm.model_from_file(input_address) 55 except IOError as err: 56 print("IO error: {0}".format(err)) 57 print( 58 "Use " + os.path.basename(sys.argv[0]) + " -h to get usage instructions" 59 ) 60 sys.exit(1) 61 62 return content 63 64 def initiate_test_generation(self, output_address): 65 self.last_parent.append("MainWindow") 66 try: 67 f = open(output_address, "w") 68 except IOError as err: 69 print("IO error: {0}".format(err)) 70 print( 71 "Use " + os.path.basename(sys.argv[0]) + " -h to get usage instructions" 72 ) 73 sys.exit(1) 74 line = ( 75 "# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-\n\n" 76 + "from uitest.framework import UITestCase\n" 77 + "from libreoffice.uno.propertyvalue import mkPropertyValues\n" 78 + "import importlib\n\n" 79 + "class TestClass(UITestCase):\n" 80 + tab 81 + "def test_function(self):\n" 82 ) 83 84 self.variables.append(line) 85 86 return f 87 88 def compile(self): 89 self.ui_dsl_mm.register_obj_processors( 90 { 91 "UNOCommand": self.handle_uno, 92 "StarterCommand": self.handle_start, 93 "CloseDialog": self.handle_Dialog, 94 "OpenModelessDialog": self.handle_Dialog, 95 "OpenModalDialog": self.handle_Dialog, 96 "ButtonUIObject": self.handle_button, 97 "CheckBoxUIObject": self.handle_check_box, 98 "TabControlUIObject": self.handle_tab, 99 "ComboBoxUIObject": self.handle_Combo_box, 100 "RadioButtonUIObject": self.handle_Radio_button, 101 "ListBoxUIObject": self.handle_List_box, 102 "SpinFieldUIObject": self.handle_spin_field, 103 "EditUIObject": self.handle_Edit_uiObject, 104 "writer_Type_command": self.handle_writer_type, 105 "writer_Select_command": self.handle_writer_select, 106 "writer_GOTO_command": self.handle_writer_goto, 107 "calc_Select_cell": self.handle_calc_select, 108 "calc_switch_sheet": self.handle_calc_switch_sheet, 109 "calc_Type_command": self.handle_calc_Type_command, 110 "calc_AutoFill_filter": self.handle_calc_AutoFill_filter, 111 "impress_Type_command": self.handle_impress_Type_command, 112 "math_element_selector": self.handle_math_element_selector, 113 "math_Type_command": self.handle_math_Type_command, 114 "setZoom_command": self.handle_setZoom_command, 115 "draw_Type_command": self.handle_draw_Type_command, 116 "SideBar": self.handle_SideBar, 117 "writer_Copy_Text": self.do_nothing, 118 "writer_Cut_Text": self.do_nothing, 119 "writer_Paste_Text": self.do_nothing, 120 "writer_Insert_BreakPage": self.do_nothing, 121 "writer_Create_table": self.do_nothing, 122 "calc_Remove_Content": self.do_nothing, 123 "calc_Delete_Cells": self.do_nothing, 124 "calc_insert_cells": self.do_nothing, 125 "calc_Cut_Cells": self.do_nothing, 126 "calc_Copy_Cells": self.do_nothing, 127 "calc_Merge_Cells": self.do_nothing, 128 "calc_UNMerge_Cells": self.do_nothing, 129 "calc_Rename_Sheet": self.do_nothing, 130 "calc_Insert_sheet": self.do_nothing, 131 "impress_Insert_Slide": self.do_nothing, 132 "impress_Delete_Page": self.do_nothing, 133 "impress_Duplicate_Slide": self.do_nothing, 134 "impress_Rename_Slide": self.do_nothing, 135 "draw_Insert_Page": self.do_nothing, 136 "draw_Delete_Page": self.do_nothing, 137 "draw_Rename_Page": self.do_nothing, 138 } 139 ) 140 141 self.log_lines = self.get_log_file(self.input_address) 142 143 def init_app(self): 144 if self.current_app in self.objects: 145 self.objects[self.current_app] += 1 146 else: 147 self.objects[self.current_app] = 1 148 line = ( 149 double_tab 150 + self.current_app 151 + ' = MainWindow.getChild("' 152 + self.current_app 153 + '")\n' 154 ) 155 self.variables.append(line) 156 157 def init_Object(self, Id_of_Object, name_of_child, Obj_parent): 158 159 if Id_of_Object in self.objects: 160 self.objects[Id_of_Object] += 1 161 else: 162 self.objects[Id_of_Object] = 1 163 line = ( 164 double_tab 165 + Id_of_Object 166 + " = " 167 + Obj_parent 168 + '.getChild("' 169 + name_of_child 170 + '")\n' 171 ) 172 self.variables.append(line) 173 174 def write_line_without_parameters(self, Action_holder, Action, Action_type): 175 line = ( 176 double_tab 177 + Action_holder 178 + '.executeAction("' 179 + Action 180 + '",' 181 + Action_type 182 + "())\n" 183 ) 184 self.variables.append(line) 185 186 def write_line_with_one_parameters( 187 self, Action_holder, Action, Paramerter_name, parameter_value 188 ): 189 line = ( 190 double_tab 191 + Action_holder 192 + '.executeAction("' 193 + Action 194 + '", mkPropertyValues({"' 195 + Paramerter_name 196 + '": "' 197 + str(parameter_value) 198 + '"}))\n' 199 ) 200 self.variables.append(line) 201 202 def write_line_with_two_parameters( 203 self, 204 Action_holder, 205 Action, 206 Paramerter_name_1, 207 parameter_value_1, 208 Paramerter_name_2, 209 parameter_value_2, 210 ): 211 212 line = ( 213 double_tab 214 + Action_holder 215 + '.executeAction("' 216 + Action 217 + '", mkPropertyValues({"' 218 + Paramerter_name_1 219 + '": "' 220 + str(parameter_value_1) 221 + '", "' 222 + Paramerter_name_2 223 + '": "' 224 + str(parameter_value_2) 225 + '"}))\n' 226 ) 227 self.variables.append(line) 228 229 def handle_uno(self, UNOCommand): 230 if UNOCommand.parameters == None: 231 line = ( 232 double_tab 233 + 'self.xUITest.executeCommand("' 234 + UNOCommand.uno_command_name 235 + '")\n' 236 ) 237 else: 238 parameters = "" 239 for p in UNOCommand.parameters.parameter_data: 240 parameters = parameters + '"' + p.key + '" : ' + str(p.value) + " ," 241 parameters = parameters[:-1] 242 243 line = ( 244 double_tab 245 + 'self.xUITest.executeCommandWithParameters("' 246 + UNOCommand.uno_command_name 247 + '", mkPropertyValues({' 248 + parameters 249 + "}) )\n" 250 ) 251 252 self.variables.append(line) 253 self.prev_command = UNOCommand 254 255 def handle_start(self, StarterCommand): 256 line = ( 257 double_tab 258 + 'MainDoc = self.ui_test.create_doc_in_start_center("' 259 + StarterCommand.program_name 260 + '")\n' 261 ) 262 self.variables.append(line) 263 264 line = double_tab + "MainWindow = self.xUITest.getTopFocusWindow()\n" 265 self.variables.append(line) 266 app = { 267 "writer": "writer_edit", 268 "calc": "grid_window", 269 "impress": "impress_win", 270 "math": "math_edit", 271 "draw": "draw_win", 272 } 273 self.current_app = app[StarterCommand.program_name] 274 self.prev_command = StarterCommand 275 276 def handle_SideBar(self, SideBar): 277 278 line = ' self.xUITest.executeCommand(".uno:Sidebar")\n' 279 self.variables.append(line) 280 281 self.write_line_with_one_parameters( 282 "MainWindow", "SIDEBAR", "PANEL", SideBar.name 283 ) 284 285 self.prev_command = SideBar 286 287 def handle_Dialog(self, DialogCommand): 288 289 if DialogCommand.__class__.__name__ == "OpenModalDialog": 290 291 if DialogCommand.dialog_name != "QuerySaveDialog": 292 # This part is just to ignore saving the Save dialog while closing the app 293 294 old_line = self.variables.pop() 295 if self.prev_command.__class__.__name__ == "UNOCommand": 296 key_word = self.prev_command.uno_command_name[-6:] 297 else: 298 key_word = old_line[-9:-3] 299 300 if key_word == "Dialog": 301 old_line = ( 302 double_tab 303 + 'self.ui_test.execute_dialog_through_command("' 304 + self.prev_command.uno_command_name 305 + '")\n' 306 ) 307 self.variables.append(old_line) 308 line = ( 309 double_tab 310 + DialogCommand.dialog_name 311 + " = self.xUITest.getTopFocusWindow()\n" 312 ) 313 self.variables.append(line) 314 self.last_parent.append(DialogCommand.dialog_name) 315 self.parent_hierarchy_count = self.parent_hierarchy_count + 1 316 317 else: 318 self.flag_for_QuerySaveDialog = True 319 320 elif DialogCommand.__class__.__name__ == "OpenModelessDialog": 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] 326 327 if key_word == "Dialog": 328 old_line = ( 329 double_tab 330 + 'self.ui_test.execute_modeless_dialog_through_command("' 331 + self.prev_command.uno_command_name 332 + '")\n' 333 ) 334 self.variables.append(old_line) 335 line = ( 336 double_tab 337 + DialogCommand.dialog_name 338 + " = self.xUITest.getTopFocusWindow()\n" 339 ) 340 self.variables.append(line) 341 self.last_parent.append(DialogCommand.dialog_name) 342 self.parent_hierarchy_count = self.parent_hierarchy_count + 1 343 344 elif DialogCommand.__class__.__name__ == "CloseDialog": 345 346 if not (self.flag_for_QuerySaveDialog): 347 # This part is just to ignore saving the Save dialog while closing the app 348 349 if self.prev_command.__class__.__name__ == "ButtonUIObject": 350 old_line = self.variables.pop() 351 line = "" 352 if keyword.iskeyword(self.prev_command.ui_button): 353 line = ( 354 double_tab 355 + "self.ui_test.close_dialog_through_button(x" 356 + self.prev_command.ui_button 357 + ")\n" 358 ) 359 else: 360 line = ( 361 double_tab 362 + "self.ui_test.close_dialog_through_button(" 363 + self.prev_command.ui_button 364 + ")\n" 365 ) 366 self.variables.append(line) 367 self.last_parent.pop() 368 self.parent_hierarchy_count = self.parent_hierarchy_count - 1 369 else: 370 self.flag_for_QuerySaveDialog = False 371 372 self.prev_command = DialogCommand 373 374 def handle_button(self, ButtonUIObject): 375 376 if ButtonUIObject.parent_id != "QuerySaveDialog": 377 # This part is just to ignore saving the Save dialog while closing the app 378 379 name_of_obj = "" 380 if keyword.iskeyword(ButtonUIObject.ui_button): 381 name_of_obj = "x" + ButtonUIObject.ui_button 382 else: 383 name_of_obj = ButtonUIObject.ui_button 384 385 if ButtonUIObject.parent_id == "": 386 self.init_Object( 387 name_of_obj, 388 ButtonUIObject.ui_button, 389 self.last_parent[self.parent_hierarchy_count], 390 ) 391 else: 392 self.init_Object( 393 name_of_obj, ButtonUIObject.ui_button, ButtonUIObject.parent_id 394 ) 395 396 self.write_line_without_parameters(name_of_obj, "CLICK", "tuple") 397 398 self.prev_command = ButtonUIObject 399 400 def handle_check_box(self, CheckBoxUIObject): 401 402 name_of_obj = "" 403 if keyword.iskeyword(CheckBoxUIObject.Check_box_id): 404 name_of_obj = "x" + CheckBoxUIObject.Check_box_id 405 else: 406 name_of_obj = CheckBoxUIObject.Check_box_id 407 408 if CheckBoxUIObject.parent_id == "": 409 self.init_Object( 410 name_of_obj, 411 CheckBoxUIObject.Check_box_id, 412 self.last_parent[self.parent_hierarchy_count], 413 ) 414 else: 415 self.init_Object( 416 name_of_obj, CheckBoxUIObject.Check_box_id, CheckBoxUIObject.parent_id 417 ) 418 419 self.write_line_without_parameters(name_of_obj, "CLICK", "tuple") 420 421 self.prev_command = CheckBoxUIObject 422 423 def handle_tab(self, TabControlUIObject): 424 425 name_of_obj = "" 426 if keyword.iskeyword(TabControlUIObject.tab_id): 427 name_of_obj = "x" + TabControlUIObject.tab_id 428 else: 429 name_of_obj = TabControlUIObject.tab_id 430 431 if TabControlUIObject.parent_id == "": 432 self.init_Object( 433 name_of_obj, 434 TabControlUIObject.tab_id, 435 self.last_parent[self.parent_hierarchy_count], 436 ) 437 else: 438 self.init_Object( 439 name_of_obj, TabControlUIObject.tab_id, TabControlUIObject.parent_id 440 ) 441 442 self.write_line_with_one_parameters( 443 name_of_obj, "SELECT", "POS", TabControlUIObject.tab_page_number 444 ) 445 446 self.prev_command = TabControlUIObject 447 448 def handle_Combo_box(self, ComboBoxUIObject): 449 450 name_of_obj = "" 451 if keyword.iskeyword(ComboBoxUIObject.Combo_box_id): 452 name_of_obj = "x" + ComboBoxUIObject.Combo_box_id 453 else: 454 name_of_obj = ComboBoxUIObject.Combo_box_id 455 456 if ComboBoxUIObject.parent_id == "": 457 self.init_Object( 458 name_of_obj, 459 ComboBoxUIObject.Combo_box_id, 460 self.last_parent[self.parent_hierarchy_count], 461 ) 462 else: 463 self.init_Object( 464 name_of_obj, ComboBoxUIObject.Combo_box_id, ComboBoxUIObject.parent_id 465 ) 466 467 self.write_line_with_one_parameters( 468 name_of_obj, "SELECT", "POS", ComboBoxUIObject.item_num 469 ) 470 471 self.prev_command = ComboBoxUIObject 472 473 def handle_Radio_button(self, RadioButtonUIObject): 474 475 name_of_obj = "" 476 if keyword.iskeyword(RadioButtonUIObject.Radio_button_id): 477 name_of_obj = "x" + RadioButtonUIObject.Radio_button_id 478 else: 479 name_of_obj = RadioButtonUIObject.Radio_button_id 480 481 if RadioButtonUIObject.parent_id == "": 482 self.init_Object( 483 name_of_obj, 484 RadioButtonUIObject.Radio_button_id, 485 self.last_parent[self.parent_hierarchy_count], 486 ) 487 else: 488 self.init_Object( 489 name_of_obj, 490 RadioButtonUIObject.Radio_button_id, 491 RadioButtonUIObject.parent_id, 492 ) 493 494 self.write_line_without_parameters(name_of_obj, "CLICK", "tuple") 495 496 self.prev_command = RadioButtonUIObject 497 498 def handle_List_box(self, ListBoxUIObject): 499 500 name_of_obj = "" 501 if keyword.iskeyword(ListBoxUIObject.list_id): 502 name_of_obj = "x" + ListBoxUIObject.list_id 503 else: 504 name_of_obj = ListBoxUIObject.list_id 505 506 if ListBoxUIObject.parent_id == "": 507 self.init_Object( 508 name_of_obj, 509 ListBoxUIObject.list_id, 510 self.last_parent[self.parent_hierarchy_count], 511 ) 512 else: 513 self.init_Object( 514 name_of_obj, ListBoxUIObject.list_id, ListBoxUIObject.parent_id 515 ) 516 517 self.write_line_with_one_parameters( 518 name_of_obj, "SELECT", "POS", ListBoxUIObject.POS 519 ) 520 521 self.prev_command = ListBoxUIObject 522 523 def handle_spin_field(self, SpinFieldUIObject): 524 525 name_of_obj = "" 526 if keyword.iskeyword(SpinFieldUIObject.Spin_id): 527 name_of_obj = "x" + SpinFieldUIObject.Spin_id 528 else: 529 name_of_obj = SpinFieldUIObject.Spin_id 530 531 if SpinFieldUIObject.parent_id == "": 532 self.init_Object( 533 name_of_obj, 534 SpinFieldUIObject.Spin_id, 535 self.last_parent[self.parent_hierarchy_count], 536 ) 537 else: 538 self.init_Object( 539 name_of_obj, SpinFieldUIObject.Spin_id, SpinFieldUIObject.parent_id 540 ) 541 542 if SpinFieldUIObject.change == "Increase": 543 self.write_line_without_parameters(name_of_obj, "UP", "tuple") 544 elif SpinFieldUIObject.change == "Decrease": 545 self.write_line_without_parameters(name_of_obj, "DOWN", "tuple") 546 self.prev_command = SpinFieldUIObject 547 548 def handle_Edit_uiObject(self, EditUIObject): 549 550 name_of_obj = "" 551 if keyword.iskeyword(EditUIObject.action.edit_button): 552 name_of_obj = "x" + EditUIObject.action.edit_button 553 else: 554 name_of_obj = EditUIObject.action.edit_button 555 556 if EditUIObject.parent_id == "": 557 self.init_Object( 558 name_of_obj, 559 EditUIObject.action.edit_button, 560 self.last_parent[self.parent_hierarchy_count], 561 ) 562 else: 563 self.init_Object( 564 name_of_obj, EditUIObject.action.edit_button, EditUIObject.parent_id 565 ) 566 567 if EditUIObject.action.__class__.__name__ == "Type_action": 568 569 if EditUIObject.action.what_to_type.__class__.__name__ == "char": 570 self.write_line_with_one_parameters( 571 name_of_obj, 572 "TYPE", 573 "TEXT", 574 EditUIObject.action.what_to_type.input_char, 575 ) 576 577 elif EditUIObject.action.what_to_type.__class__.__name__ == "KeyCode": 578 self.write_line_with_one_parameters( 579 name_of_obj, 580 "TYPE", 581 "KEYCODE", 582 EditUIObject.action.what_to_type.input_key_code, 583 ) 584 585 if EditUIObject.action.__class__.__name__ == "SELECT": 586 587 self.write_line_with_two_parameters( 588 name_of_obj, 589 "SELECT", 590 "FROM", 591 EditUIObject.action.from_pos, 592 "TO", 593 EditUIObject.action.to_pos, 594 ) 595 596 if EditUIObject.action.__class__.__name__ == "Clear": 597 598 self.write_line_without_parameters(name_of_obj, "CLEAR", "tuple") 599 600 self.prev_command = EditUIObject 601 602 def handle_writer_type(self, writer_Type_command): 603 604 self.init_app() 605 606 if writer_Type_command.what_to_type.__class__.__name__ == "char": 607 self.write_line_with_one_parameters( 608 self.current_app, 609 "TYPE", 610 "TEXT", 611 writer_Type_command.what_to_type.input_char, 612 ) 613 614 elif writer_Type_command.what_to_type.__class__.__name__ == "KeyCode": 615 self.write_line_with_one_parameters( 616 self.current_app, 617 "TYPE", 618 "KEYCODE", 619 writer_Type_command.what_to_type.input_key_code, 620 ) 621 622 self.prev_command = writer_Type_command 623 624 def handle_writer_select(self, writer_Select_command): 625 626 self.init_app() 627 628 self.write_line_with_two_parameters( 629 self.current_app, 630 "SELECT", 631 "END_POS", 632 writer_Select_command.from_pos, 633 "START_POS", 634 writer_Select_command.to_pos, 635 ) 636 637 self.prev_command = writer_Select_command 638 639 def handle_writer_goto(self, writer_GOTO_command): 640 641 self.init_app() 642 643 self.write_line_with_one_parameters( 644 self.current_app, "GOTO", "PAGE", writer_GOTO_command.page_num 645 ) 646 647 self.prev_command = writer_GOTO_command 648 649 def handle_calc_select(self, calc_Select_cell): 650 651 self.init_app() 652 653 if calc_Select_cell.select_op.__class__.__name__ == "range_of_cells": 654 self.write_line_with_one_parameters( 655 self.current_app, 656 "SELECT", 657 "RANGE", 658 calc_Select_cell.select_op.input_range, 659 ) 660 661 elif calc_Select_cell.select_op.__class__.__name__ == "one_cell": 662 self.write_line_with_one_parameters( 663 self.current_app, 664 "SELECT", 665 "CELL", 666 calc_Select_cell.select_op.input_cell, 667 ) 668 669 self.prev_command = calc_Select_cell 670 671 def handle_calc_switch_sheet(self, calc_switch_sheet): 672 673 self.init_app() 674 675 self.write_line_with_one_parameters( 676 self.current_app, "SELECT", "TABLE", calc_switch_sheet.sheet_num 677 ) 678 679 self.prev_command = calc_switch_sheet 680 681 def handle_calc_Type_command(self, calc_Type_command): 682 683 self.init_app() 684 685 if calc_Type_command.what_to_type.__class__.__name__ == "char": 686 self.write_line_with_one_parameters( 687 self.current_app, 688 "TYPE", 689 "TEXT", 690 calc_Type_command.what_to_type.input_char, 691 ) 692 693 elif calc_Type_command.what_to_type.__class__.__name__ == "KeyCode": 694 self.write_line_with_one_parameters( 695 self.current_app, 696 "TYPE", 697 "KEYCODE", 698 calc_Type_command.what_to_type.input_key_code, 699 ) 700 701 self.prev_command = calc_Type_command 702 703 def handle_calc_AutoFill_filter(self, calc_AutoFill_filter): 704 705 self.init_app() 706 707 line = ( 708 double_tab 709 + self.current_app 710 + '.executeAction("LAUNCH", mkPropertyValues' 711 + '({"AUTOFILTER": "", "COL": "' 712 + str(calc_AutoFill_filter.col_num) 713 + '"' 714 + ', "ROW": "' 715 + str(calc_AutoFill_filter.row_num) 716 + '"}))\n' 717 ) 718 719 self.variables.append(line) 720 self.prev_command = calc_AutoFill_filter 721 722 def handle_impress_Type_command(self, impress_Type_command): 723 724 self.init_app() 725 726 if impress_Type_command.what_to_type.__class__.__name__ == "char": 727 self.write_line_with_one_parameters( 728 self.current_app, 729 "TYPE", 730 "TEXT", 731 impress_Type_command.what_to_type.input_char, 732 ) 733 734 elif impress_Type_command.what_to_type.__class__.__name__ == "KeyCode": 735 self.write_line_with_one_parameters( 736 self.current_app, 737 "TYPE", 738 "KEYCODE", 739 impress_Type_command.what_to_type.input_key_code, 740 ) 741 742 self.prev_command = impress_Type_command 743 744 def handle_math_Type_command(self, math_Type_command): 745 746 self.init_app() 747 if math_Type_command.what_to_type.__class__.__name__ == "char": 748 self.write_line_with_one_parameters( 749 self.current_app, 750 "TYPE", 751 "TEXT", 752 math_Type_command.what_to_type.input_char, 753 ) 754 755 elif math_Type_command.what_to_type.__class__.__name__ == "KeyCode": 756 self.write_line_with_one_parameters( 757 self.current_app, 758 "TYPE", 759 "KEYCODE", 760 math_Type_command.what_to_type.input_key_code, 761 ) 762 763 self.prev_command = math_Type_command 764 765 def handle_draw_Type_command(self, draw_Type_command): 766 767 self.init_app() 768 if draw_Type_command.what_to_type.__class__.__name__ == "char": 769 self.write_line_with_one_parameters( 770 self.current_app, 771 "TYPE", 772 "TEXT", 773 draw_Type_command.what_to_type.input_char, 774 ) 775 776 elif draw_Type_command.what_to_type.__class__.__name__ == "KeyCode": 777 self.write_line_with_one_parameters( 778 self.current_app, 779 "TYPE", 780 "KEYCODE", 781 draw_Type_command.what_to_type.input_key_code, 782 ) 783 784 self.prev_command = draw_Type_command 785 786 def handle_math_element_selector(self, math_element_selector): 787 788 line = ( 789 double_tab 790 + str(math_element_selector.element_no) 791 + ' = element_selector.getChild("' 792 + str(math_element_selector.element_no) 793 + '")\n' 794 ) 795 self.variables.append(line) 796 797 self.write_line_without_parameters( 798 str(math_element_selector.element_no), "SELECT", "tuple" 799 ) 800 801 self.prev_command = math_element_selector 802 803 def handle_setZoom_command(self, setZoom_command): 804 805 self.init_app() 806 807 self.write_line_with_one_parameters( 808 self.current_app, "SET", "ZOOM", setZoom_command.zoom_value 809 ) 810 811 self.prev_command = setZoom_command 812 813 def Generate_UI_test(self): 814 line = double_tab + "self.ui_test.close_doc()" 815 self.variables.append(line) 816 817 line = "\n\n# vim: set shiftwidth=4 softtabstop=4 expandtab:" 818 self.variables.append(line) 819 820 for line in self.variables: 821 self.output_stream.write(str(line)) 822 823 def do_nothing(self, Command): 824 line = "to be added in the future" 825 826 def __del__(self): 827 self.output_stream.close() 828 829 830def main(): 831 args = parse_args() 832 ui_logger = ul_Compiler(args.input_address, args.output_address) 833 ui_logger.compile() 834 for statement in ui_logger.log_lines.commands: 835 print(statement) 836 ui_logger.Generate_UI_test() 837 del ui_logger 838 839 840if __name__ == "__main__": 841 main() 842