def switch_welcome_window(self, direction='left'): screen = self.base_screens[0] root = find_parent(self, TenFingers) self.switch_to(screen, direction=direction) root.play.children[0].game_on = False self.best() self.last()
def modify_block(ast_tree, epoch, epoch_name): """ modifies the block, assigns the bB variable properly :param ast_tree: :param epoch: :param epoch_name: :return: """ parent_comp = find_parent(ast_tree, epoch) epoch_index = parent_comp.block_items.index(epoch) cond = BinaryOp('!=', ID('iter'), ID(epoch_name)) new_if = If(cond, None, None, epoch.coord) assign_unique_coord(new_if, epoch.coord) assign_b_tofalse = create_new_assign('false', 'b' + str(var_b), epoch.coord) assign_unique_coord(assign_b_tofalse, epoch.coord) assign_b_totrue = create_new_assign('true', 'b' + str(var_b), epoch.coord) assign_unique_coord(assign_b_totrue, epoch.coord) cont = Continue(epoch.coord) if_true = Compound([assign_b_tofalse, cont], epoch.coord) assign_unique_coord(if_true, epoch.coord) if_false = Compound([assign_b_totrue], epoch.coord) assign_unique_coord(if_false, epoch.coord) new_if.iftrue = if_true new_if.iffalse = if_false parent_comp.block_items.insert(epoch_index + 1, new_if)
def detect_correct_word(self): if not self.error and self.text[-1] == ' ': root = find_parent(self, TenFingersPlay) root.score += 1 root.original_text = ''.join(root.original_text.split(' ', 1)[1:]) root.initial_index = 0 self.text = '' write_text(root)
def identify_block_b(ast, epoch, epoch_name): """ identifies and creates the bB block :param ast: :param epoch: :param epoch_name: :return: """ global var_b ast_tree = duplicate_element(ast) parent_comp = find_parent(ast_tree, epoch) parent = find_parentUpdated(ast_tree, epoch) # print generator.visit(parent_comp) epoch_index = parent_comp.block_items.index(epoch) to_add = parent_comp.block_items[epoch_index + 1:] changed_parent = True while changed_parent: grandparent_comp = find_parent(ast_tree, parent) grandparent = find_parentUpdated(ast_tree, parent) # print type(grandparent_comp.block_items) # print generator.visit(grandparent_comp) # print generator.visit(parent) index = grandparent_comp.block_items.index(parent) to_add = to_add + grandparent_comp.block_items[index + 1:] parent = grandparent if grandparent_comp == grandparent: changed_parent = False # print index block_b = Compound(to_add, epoch.coord) assign_unique_coord(block_b, epoch.coord) var_b += 1 assign = create_new_assign('true', 'b' + str(var_b), epoch.coord) # create assign b = true assign_unique_coord(assign, epoch.coord) block_b.block_items.insert(len(block_b.block_items), assign) modify_block(ast, epoch, epoch_name) return block_b
def counter(self): if self.game_on: time_diff = datetime.now() - self.game_at self.game_since.text = str(time_diff).rsplit(".", 1)[0][3:] self.current_score.text = '{} wpm'.format(self.score) if time_diff.total_seconds() >= self.max_seconds: root = find_parent(self, TenFingers) root.switch_final_window() DB.store_put(datetime.now().timestamp(), self.score) DB.store_sync() root.current_screen.children[0].score.text = '{} wpm'.format( self.score) else: Clock.schedule_once(lambda dt: self.counter(), .1)
def insert_text(self, substring, from_undo=False): root = find_parent(self, TenFingersPlay) if check_char(get_char(root.original_text, root.initial_index), substring) and not self.error: write_text(root, SUCCESS) if not self.is_forward: self.is_forward = True root.initial_index += 1 self.error = False else: self.error = True write_text(root, ERROR) super(TenFingerInputText, self).insert_text(substring, from_undo=from_undo) self.detect_correct_word() self.focus = True
def add_ghost_assign_in_tree(tree, context, used_old_vars, added_ifs_assignment, aux_dict): global added_vars """ adauga in copac assignmentul de variabila si intoarce o lista de tupluri de genul (if de modificat, noile nume de variabile) :param tree: :param ifs_to_des: :param label: :return: """ for elem in context: conds_list = [] new_conds_list = [] take_cond_name(elem.cond, conds_list) for cond in conds_list: # print "aaaaaaaaa", cond parent = find_parent(tree, elem) index = parent.block_items.index(elem) count = used_old_vars.count(cond) if elem not in added_ifs_assignment: used_old_vars.append(cond) new_cond = create_new_cond_name(cond, count) new_conds_list.append(new_cond) assign = create_new_assign(cond, new_cond, elem.coord) # print generator.visit(assign) parent.block_items.insert(index, assign) # # added_vars.append(new_cond) # new_conds_list.append(new_cond) # # assign = create_new_assign(cond, new_cond, elem.coord) # # # aux = (elem, new_conds_list) # ifs_new_names.append(aux) # # print new_names added_ifs_assignment.append(elem) if new_conds_list: aux_dict[elem] = new_conds_list
def do_backspace(self, from_undo=False, mode='bkspc'): try: super(TenFingerInputText, self).do_backspace(from_undo=from_undo, mode='bkspc') except IndexError: return root = find_parent(self, TenFingersPlay) if self.is_forward: self.is_forward = False if not self.error: root.initial_index = max(0, root.initial_index - 1) if not root.original_text[:root.initial_index]: color = BLACK self.error = False elif check_wordish(root.original_text[:root.initial_index + 1], self.text): color = SUCCESS self.error = False else: color = ERROR self.error = True write_text(root, color) self.focus = True
def direct_welcome_screen(self, direction='left'): root = find_parent(self, TenFingers) root.switch_welcome_window(direction=direction)
def identify_nested(ast_tree): ast = ast_tree old_stdout = sys.stdout sys.stdout = mystdout = StringIO() aux_ast = duplicate_element(ast) list = [] extern_while = get_extern_while_body(aux_ast) identify_nested_algorithms_bodies(extern_while, list) labelname_inner = config.variables_2['round'] rounds_list_inner = config.rounds_list_2 delete_round_phase_inner = config.delete_round_phase message_inner = config.msg_structure_fields_2 variables_inner = config.variables_2 if list: list.reverse() labels = config.rounds_list_2 labels.append('ERR_ROUND') code = None cop = duplicate_element(ast) if len(list) >= config.number_of_nested_algorithms: extern = get_extern_while_body(cop) if isinstance(extern.block_items[0], If): myif = extern.block_items[0] list1 = [] list2 = [] aux1 = [] aux2 = [] identify_nested_algorithms_bodies(extern.block_items[0].iftrue, list1) if list1: sys.stdout = old_stdout for elem in list1: conditii = [] whiles_to_if(elem.stmt, conditii) identify_recv_exits(elem.stmt, conditii) remove_mbox(elem.stmt, config.mailbox_2, config.clean_mailbox_2) aux1 = elem.stmt parent = find_parent(ast, elem) index = parent.block_items.index(elem) parent.block_items.remove(elem) coord = elem.coord new_id = ID("inner_algorithm", coord) func = FuncCall(new_id, None, coord) assign_unique_coord(func, coord) parent.block_items.insert(index, func) identify_nested_algorithms_bodies( extern.block_items[0].iffalse, list2) if list2: for elem in list2: conditii = [] whiles_to_if(elem.stmt, conditii) identify_recv_exits(elem.stmt, conditii) remove_mbox(elem.stmt, config.mailbox_2, config.clean_mailbox_2) aux2 = elem.stmt parent = find_parent(ast, elem) index = parent.block_items.index(elem) parent.block_items.remove(elem) coord = elem.coord new_id = ID("inner_algorithm", coord) func = FuncCall(new_id, None, coord) assign_unique_coord(func, coord) parent.block_items.insert(index, func) if aux1 and aux2: myif.iftrue = None myif.iffalse = None myif.iftrue = aux1 myif.iffalse = aux2 trees_dict, trees_paths_dict, is_job = get_paths_trees( cop, labels, labels, config.variables_2['round']) print_rounds(labels, trees_dict, trees_paths_dict, config.variables_2['round'], is_job, delete_round_phase_inner, message_inner, variables_inner, rounds_list_inner[0]) code = mystdout.getvalue() sys.stdout = old_stdout return ast, code else: for elem in list: # print generator.visit(elem), "AAAAAAAAAAA" conditii = [] whiles_to_if(elem.stmt, conditii) identify_recv_exits(elem.stmt, conditii) remove_mbox(elem.stmt, config.mailbox_2, config.clean_mailbox_2) # print generator.visit(elem) trees_dict, trees_paths_dict, is_job = get_paths_trees( elem.stmt, labels, labels, config.variables_2['round']) # print_code(trees_dict, trees_paths_dict, labels) print_rounds(labels, trees_dict, trees_paths_dict, config.variables_2['round'], is_job, delete_round_phase_inner, message_inner, variables_inner, rounds_list_inner[0]) parent = find_parent(ast, elem) index = parent.block_items.index(elem) parent.block_items.remove(elem) coord = elem.coord new_id = ID("inner_algorithm", coord) func = FuncCall(new_id, None, coord) assign_unique_coord(func, coord) parent.block_items.insert(index, func) # print generator.visit(parent.block_items[index]) # print generator.visit(ast) # print generator.visit(func) funcdecl = FuncDecl( None, TypeDecl('inner_algorithm', None, IdentifierType(['int']))) decl = Decl('inner_algorithm', None, None, None, funcdecl, None, None) funcdef = FuncDef(decl, None, None) code = mystdout.getvalue() funcdef.body = Compound([code]) # print generator.visit(ast) sys.stdout = old_stdout return ast, code else: sys.stdout = old_stdout print "pe else" return ast_tree