Esempio n. 1
0
 def toc_insert_all(self, text_buffer, top_tree_iter):
     """Insert a TOC at top of text_buffer, including Node and Subnodes starting from top_tree_iter"""
     config.get_tree_expanded_collapsed_string(self.dad)
     starting_tree_iter = self.dad.curr_tree_iter.copy()
     if top_tree_iter: toc_list_per_node = self.toc_insert_all_iter(top_tree_iter)
     else:
         top_tree_iter = self.dad.treestore.get_iter_first()
         toc_list_per_node = []
         while top_tree_iter != None:
             toc_list_per_node.extend(self.toc_insert_all_iter(top_tree_iter))
             top_tree_iter = self.dad.treestore.iter_next(top_tree_iter)
     config.set_tree_expanded_collapsed_string(self.dad)
     self.dad.treeview_safe_set_cursor(starting_tree_iter)
     self.dad.objects_buffer_refresh()
     #print toc_list_per_node
     curr_node_id = -1
     curr_node_level = 0
     if toc_list_per_node:
         tag_property = cons.TAG_LINK
         curr_offset = 0
         text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
         curr_offset += 1
         for element in toc_list_per_node:
             property_value = cons.LINK_TYPE_NODE + cons.CHAR_SPACE + str(element[2])
             if curr_node_id != element[2]:
                 curr_node_id = element[2]
                 node_tree_iter = self.dad.get_tree_iter_from_node_id(curr_node_id)
                 curr_node_level = self.dad.treestore.iter_depth(node_tree_iter)
                 node_name = self.dad.treestore[node_tree_iter][1].replace(cons.CHAR_NEWLINE, cons.CHAR_SPACE).replace(cons.CHAR_CR, "")
                 tag_names = [self.dad.apply_tag_exist_or_create(tag_property, property_value)]
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), 2*curr_node_level*cons.CHAR_SPACE + cons.CHAR_LISTARR + cons.CHAR_SPACE)
                 curr_offset += 2 + 2*curr_node_level
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
                 text_buffer.insert_with_tags_by_name(text_buffer.get_iter_at_offset(curr_offset), node_name, *tag_names)
                 curr_offset += 1
                 while text_buffer.get_iter_at_offset(curr_offset).get_char() != cons.CHAR_NEWLINE:
                     curr_offset += 1
                 curr_offset += 1
             tag_names = [self.dad.apply_tag_exist_or_create(tag_property, property_value + cons.CHAR_SPACE + element[0])]
             if not element[0]: continue
             if element[0][:2] == cons.TAG_PROP_H1:
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), (2+2*curr_node_level)*cons.CHAR_SPACE + cons.CHAR_LISTBUL + cons.CHAR_SPACE)
                 curr_offset += 4 + 2*curr_node_level
             elif element[0][:2] == cons.TAG_PROP_H2:
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), (4+2*curr_node_level)*cons.CHAR_SPACE + cons.CHAR_LISTBUL + cons.CHAR_SPACE)
                 curr_offset += 6 + 2*curr_node_level
             else:
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), (6+2*curr_node_level)*cons.CHAR_SPACE + cons.CHAR_LISTBUL + cons.CHAR_SPACE)
                 curr_offset += 8 + 2*curr_node_level
             text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
             text_buffer.insert_with_tags_by_name(text_buffer.get_iter_at_offset(curr_offset), element[1], *tag_names)
             curr_offset += 1
             while text_buffer.get_iter_at_offset(curr_offset).get_char() != cons.CHAR_NEWLINE:
                 curr_offset += 1
             curr_offset += 1
         text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
     return toc_list_per_node
Esempio n. 2
0
 def toc_insert_all(self, text_buffer, top_tree_iter):
     """Insert a TOC at top of text_buffer, including Node and Subnodes starting from top_tree_iter"""
     config.get_tree_expanded_collapsed_string(self.dad)
     starting_tree_iter = self.dad.curr_tree_iter.copy()
     if top_tree_iter: toc_list_per_node = self.toc_insert_all_iter(top_tree_iter)
     else:
         top_tree_iter = self.dad.treestore.get_iter_first()
         toc_list_per_node = []
         while top_tree_iter != None:
             toc_list_per_node.extend(self.toc_insert_all_iter(top_tree_iter))
             top_tree_iter = self.dad.treestore.iter_next(top_tree_iter)
     config.set_tree_expanded_collapsed_string(self.dad)
     self.dad.treeview_safe_set_cursor(starting_tree_iter)
     self.dad.objects_buffer_refresh()
     #print toc_list_per_node
     curr_node_id = -1
     curr_node_level = 0
     if toc_list_per_node:
         tag_property = cons.TAG_LINK
         curr_offset = 0
         text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
         curr_offset += 1
         for element in toc_list_per_node:
             property_value = cons.LINK_TYPE_NODE + cons.CHAR_SPACE + str(element[2])
             if curr_node_id != element[2]:
                 curr_node_id = element[2]
                 node_tree_iter = self.dad.get_tree_iter_from_node_id(curr_node_id)
                 curr_node_level = self.dad.treestore.iter_depth(node_tree_iter)
                 node_name = self.dad.treestore[node_tree_iter][1].replace(cons.CHAR_NEWLINE, cons.CHAR_SPACE).replace(cons.CHAR_CR, "")
                 tag_names = [self.dad.apply_tag_exist_or_create(tag_property, property_value)]
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), 2*curr_node_level*cons.CHAR_SPACE + cons.CHAR_LISTARR + cons.CHAR_SPACE)
                 curr_offset += 2 + 2*curr_node_level
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
                 text_buffer.insert_with_tags_by_name(text_buffer.get_iter_at_offset(curr_offset), node_name, *tag_names)
                 curr_offset += 1
                 while text_buffer.get_iter_at_offset(curr_offset).get_char() != cons.CHAR_NEWLINE:
                     curr_offset += 1
                 curr_offset += 1
             tag_names = [self.dad.apply_tag_exist_or_create(tag_property, property_value + cons.CHAR_SPACE + element[0])]
             if not element[0]: continue
             if element[0][:2] == cons.TAG_PROP_H1:
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), (2+2*curr_node_level)*cons.CHAR_SPACE + cons.CHAR_LISTBUL + cons.CHAR_SPACE)
                 curr_offset += 4 + 2*curr_node_level
             elif element[0][:2] == cons.TAG_PROP_H2:
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), (4+2*curr_node_level)*cons.CHAR_SPACE + cons.CHAR_LISTBUL + cons.CHAR_SPACE)
                 curr_offset += 6 + 2*curr_node_level
             else:
                 text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), (6+2*curr_node_level)*cons.CHAR_SPACE + cons.CHAR_LISTBUL + cons.CHAR_SPACE)
                 curr_offset += 8 + 2*curr_node_level
             text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
             text_buffer.insert_with_tags_by_name(text_buffer.get_iter_at_offset(curr_offset), element[1], *tag_names)
             curr_offset += 1
             while text_buffer.get_iter_at_offset(curr_offset).get_char() != cons.CHAR_NEWLINE:
                 curr_offset += 1
             curr_offset += 1
         text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
     return toc_list_per_node
Esempio n. 3
0
 def find_in_all_nodes(self, father_tree_iter):
     """Search for a pattern in all the Tree Nodes"""
     if not self.from_find_iterated:
         iter_insert = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_insert())
         iter_bound = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_selection_bound())
         entry_predefined_text = self.dad.curr_buffer.get_text(iter_insert, iter_bound)
         if entry_predefined_text:
             self.dad.search_replace_dict['find'] = entry_predefined_text
         if self.replace_active:
             if father_tree_iter: title = _("Replace in Selected Node and Subnodes")
             else: title = _("Replace in All Nodes")
         else:
             if father_tree_iter: title = _("Search in Selected Node and Subnodes")
             else: title = _("Search in All Nodes")
         pattern = self.dad.dialog_search(title, self.replace_active)
         if entry_predefined_text != "":
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_insert(), iter_insert)
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_selection_bound(), iter_bound)
         if pattern != None:
             if not father_tree_iter: self.curr_find = ["in_all_nodes", pattern]
             else: self.curr_find = ["in_sel_nod_n_sub", pattern]
         else: return
     else: pattern = self.curr_find[1]
     starting_tree_iter = self.dad.curr_tree_iter.copy()
     current_cursor_pos = self.dad.curr_buffer.get_property(cons.STR_CURSOR_POSITION)
     forward = self.dad.search_replace_dict['fw']
     if self.from_find_back:
         forward = not forward
         self.from_find_back = False
     first_fromsel = self.dad.search_replace_dict['a_ff_fa'] == 1
     all_matches = self.dad.search_replace_dict['a_ff_fa'] == 0
     if first_fromsel or father_tree_iter:
         self.first_useful_node = False # no one node content was parsed yet
         node_iter = self.dad.curr_tree_iter.copy()
     else:
         self.first_useful_node = True # all range will be parsed so no matter
         if forward: node_iter = self.dad.treestore.get_iter_first()
         else: node_iter = self.dad.get_tree_iter_last_sibling(None)
     self.matches_num = 0
     if all_matches: self.liststore.clear()
     config.get_tree_expanded_collapsed_string(self.dad)
     # searching start
     if self.dad.user_active:
         self.dad.user_active = False
         user_active_restore = True
     else: user_active_restore = False
     self.processed_nodes = 0
     self.latest_matches = 0
     self.dad.update_num_nodes()
     if all_matches:
         self.dad.progressbar.set_text("0")
         self.dad.progresstop.show()
         self.dad.progressbar.show()
         while gtk.events_pending(): gtk.main_iteration()
     search_start_time = time.time()
     while node_iter:
         self.all_matches_first_in_node = True
         while self.parse_given_node_content(node_iter, pattern, forward, first_fromsel, all_matches):
             self.matches_num += 1
             if not all_matches or self.dad.progress_stop: break
         if self.matches_num == 1 and not all_matches: break
         if father_tree_iter and not self.from_find_iterated: break
         last_top_node_iter = node_iter.copy() # we need this if we start from a node that is not in top level
         if forward: node_iter = self.dad.treestore.iter_next(node_iter)
         else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
         if not node_iter and father_tree_iter: break
         # code that, in case we start from a node that is not top level, climbs towards the top
         while not node_iter:
             node_iter = self.dad.treestore.iter_parent(last_top_node_iter)
             if node_iter:
                 last_top_node_iter = node_iter.copy()
                 # we do not check the father on purpose, only the uncles in the proper direction
                 if forward: node_iter = self.dad.treestore.iter_next(node_iter)
                 else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
             else: break
         if self.dad.progress_stop: break
         self.processed_nodes += 1
         if all_matches:
             self.update_all_matches_progress()
     search_end_time = time.time()
     print search_end_time - search_start_time, "sec"
     if user_active_restore: self.dad.user_active = True
     config.set_tree_expanded_collapsed_string(self.dad)
     if not self.matches_num or all_matches:
         self.dad.treeview_safe_set_cursor(starting_tree_iter)
         self.dad.objects_buffer_refresh()
         self.dad.sourceview.grab_focus()
         self.dad.curr_buffer.place_cursor(self.dad.curr_buffer.get_iter_at_offset(current_cursor_pos))
         self.dad.sourceview.scroll_to_mark(self.dad.curr_buffer.get_insert(), 0.3)
     if not self.matches_num:
         support.dialog_info(_("The pattern '%s' was not found") % pattern, self.dad.window)
     else:
         if all_matches:
             self.allmatchesdialog.set_title(str(self.matches_num) + cons.CHAR_SPACE + _("Matches"))
             self.allmatchesdialog.run()
             self.allmatchesdialog.hide()
         else:
             self.dad.treeview_safe_set_cursor(self.dad.curr_tree_iter)
             if self.dad.search_replace_dict['idialog']:
                 self.iterated_find_dialog()
     if all_matches:
         assert self.processed_nodes == self.dad.num_nodes or self.dad.progress_stop
         self.dad.progresstop.hide()
         self.dad.progressbar.hide()
         self.dad.progress_stop = False
Esempio n. 4
0
 def find_in_all_nodes(self, father_tree_iter):
     """Search for a pattern in all the Tree Nodes"""
     if not self.from_find_iterated:
         iter_insert = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_insert())
         iter_bound = self.dad.curr_buffer.get_iter_at_mark(self.dad.curr_buffer.get_selection_bound())
         entry_predefined_text = self.dad.curr_buffer.get_text(iter_insert, iter_bound)
         if entry_predefined_text:
             self.dad.search_replace_dict['find'] = entry_predefined_text
         if self.replace_active:
             if father_tree_iter: title = _("Replace in Selected Node and Subnodes")
             else: title = _("Replace in All Nodes")
         else:
             if father_tree_iter: title = _("Search in Selected Node and Subnodes")
             else: title = _("Search in All Nodes")
         pattern = self.dad.dialog_search(title, self.replace_active)
         if entry_predefined_text != "":
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_insert(), iter_insert)
             self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_selection_bound(), iter_bound)
         if pattern != None:
             if not father_tree_iter: self.curr_find = ["in_all_nodes", pattern]
             else: self.curr_find = ["in_sel_nod_n_sub", pattern]
         else: return
     else: pattern = self.curr_find[1]
     starting_tree_iter = self.dad.curr_tree_iter.copy()
     current_cursor_pos = self.dad.curr_buffer.get_property(cons.STR_CURSOR_POSITION)
     forward = self.dad.search_replace_dict['fw']
     if self.from_find_back:
         forward = not forward
         self.from_find_back = False
     first_fromsel = self.dad.search_replace_dict['a_ff_fa'] == 1
     all_matches = self.dad.search_replace_dict['a_ff_fa'] == 0
     if first_fromsel or father_tree_iter:
         self.first_useful_node = False # no one node content was parsed yet
         node_iter = self.dad.curr_tree_iter.copy()
     else:
         self.first_useful_node = True # all range will be parsed so no matter
         if forward: node_iter = self.dad.treestore.get_iter_first()
         else: node_iter = self.dad.get_tree_iter_last_sibling(None)
     self.matches_num = 0
     if all_matches: self.liststore.clear()
     config.get_tree_expanded_collapsed_string(self.dad)
     # searching start
     if self.dad.user_active:
         self.dad.user_active = False
         user_active_restore = True
     else: user_active_restore = False
     while node_iter:
         self.all_matches_first_in_node = True
         while self.parse_given_node_content(node_iter, pattern, forward, first_fromsel, all_matches):
             self.matches_num += 1
             if not all_matches: break
         if self.matches_num == 1 and not all_matches: break
         if father_tree_iter and not self.from_find_iterated: break
         last_top_node_iter = node_iter.copy() # we need this if we start from a node that is not in top level
         if forward: node_iter = self.dad.treestore.iter_next(node_iter)
         else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
         if not node_iter and father_tree_iter: break
         # code that, in case we start from a node that is not top level, climbs towards the top
         while not node_iter:
             node_iter = self.dad.treestore.iter_parent(last_top_node_iter)
             if node_iter:
                 last_top_node_iter = node_iter.copy()
                 # we do not check the father on purpose, only the uncles in the proper direction
                 if forward: node_iter = self.dad.treestore.iter_next(node_iter)
                 else: node_iter = self.dad.get_tree_iter_prev_sibling(self.dad.treestore, node_iter)
             else: break
     if user_active_restore: self.dad.user_active = True
     config.set_tree_expanded_collapsed_string(self.dad)
     if not self.matches_num or all_matches:
         self.dad.treeview_safe_set_cursor(starting_tree_iter)
         self.dad.objects_buffer_refresh()
         self.dad.sourceview.grab_focus()
         self.dad.curr_buffer.place_cursor(self.dad.curr_buffer.get_iter_at_offset(current_cursor_pos))
         self.dad.sourceview.scroll_to_mark(self.dad.curr_buffer.get_insert(), 0.3)
     if not self.matches_num:
         support.dialog_info(_("The pattern '%s' was not found") % pattern, self.dad.window)
     else:
         if all_matches:
             self.allmatchesdialog.set_title(str(self.matches_num) + cons.CHAR_SPACE + _("Matches"))
             self.allmatchesdialog.run()
             self.allmatchesdialog.hide()
         else:
             self.dad.treeview_safe_set_cursor(self.dad.curr_tree_iter)
             if self.dad.search_replace_dict['idialog']:
                 self.iterated_find_dialog()