Пример #1
0
 def run_print_operation(self, print_operation, parent):
     """Run a Ready Print Operation"""
     if self.pdf_filepath: print_operation.set_export_filename(self.pdf_filepath)
     print_operation_action = gtk.PRINT_OPERATION_ACTION_EXPORT if self.pdf_filepath else gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG
     try: res = print_operation.run(print_operation_action, parent)
     except gobject.GError, ex:
         support.dialog_error("Error printing file:\n%s (exception catched)" % str(ex), parent)
Пример #2
0
 def rich_text_attributes_update(self, curr_iter, curr_attributes):
     """Updates the list of Attributes for the Current Slice"""
     toggled_off = curr_iter.get_toggled_tags(toggled_on=False)
     for tag in toggled_off:
         tag_name = tag.get_property("name")
         if tag_name and tag_name != cons.GTKSPELLCHECK_TAG_NAME:
             if tag_name.startswith("weight_"): curr_attributes[cons.TAG_WEIGHT] = ""
             elif tag_name.startswith("foreground_"): curr_attributes[cons.TAG_FOREGROUND] = ""
             elif tag_name.startswith("background_"): curr_attributes[cons.TAG_BACKGROUND] = ""
             elif tag_name.startswith("style_"): curr_attributes[cons.TAG_STYLE] = ""
             elif tag_name.startswith("underline_"): curr_attributes[cons.TAG_UNDERLINE] = ""
             elif tag_name.startswith("strikethrough_"): curr_attributes[cons.TAG_STRIKETHROUGH] = ""
             elif tag_name.startswith("scale_"): curr_attributes[cons.TAG_SCALE] = ""
             elif tag_name.startswith("justification_"): curr_attributes[cons.TAG_JUSTIFICATION] = ""
             elif tag_name.startswith("link_"): curr_attributes[cons.TAG_LINK] = ""
             elif tag_name.startswith("family_"): curr_attributes[cons.TAG_FAMILY] = ""
             else: support.dialog_error("Failure processing the toggling OFF tag %s" % tag_name, self.dad.window)
     toggled_on = curr_iter.get_toggled_tags(toggled_on=True)
     for tag in toggled_on:
         tag_name = tag.get_property("name")
         if tag_name and tag_name != cons.GTKSPELLCHECK_TAG_NAME:
             if tag_name.startswith("weight_"): curr_attributes[cons.TAG_WEIGHT] = tag_name[7:]
             elif tag_name.startswith("foreground_"): curr_attributes[cons.TAG_FOREGROUND] = tag_name[11:]
             elif tag_name.startswith("background_"): curr_attributes[cons.TAG_BACKGROUND] = tag_name[11:]
             elif tag_name.startswith("scale_"): curr_attributes[cons.TAG_SCALE] = tag_name[6:]
             elif tag_name.startswith("justification_"): curr_attributes[cons.TAG_JUSTIFICATION] = tag_name[14:]
             elif tag_name.startswith("style_"): curr_attributes[cons.TAG_STYLE] = tag_name[6:]
             elif tag_name.startswith("underline_"): curr_attributes[cons.TAG_UNDERLINE] = tag_name[10:]
             elif tag_name.startswith("strikethrough_"): curr_attributes[cons.TAG_STRIKETHROUGH] = tag_name[14:]
             elif tag_name.startswith("link_"): curr_attributes[cons.TAG_LINK] = tag_name[5:]
             elif tag_name.startswith("family_"): curr_attributes[cons.TAG_FAMILY] = tag_name[7:]
             else: support.dialog_error("Failure processing the toggling ON tag %s" % tag_name, self.dad.window)
Пример #3
0
 def run_print_operation(self, print_operation, parent):
     """Run a Ready Print Operation"""
     if self.pdf_filepath: print_operation.set_export_filename(self.pdf_filepath)
     print_operation_action = gtk.PRINT_OPERATION_ACTION_EXPORT if self.pdf_filepath else gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG
     try: res = print_operation.run(print_operation_action, parent)
     except gobject.GError, ex:
         support.dialog_error("Error printing file:\n%s (exception catched)" % str(ex), parent)
Пример #4
0
 def rich_text_attributes_update(self, curr_iter, curr_attributes):
     """Updates the list of Attributes for the Current Slice"""
     toggled_off = curr_iter.get_toggled_tags(toggled_on=False)
     for tag in toggled_off:
         tag_name = tag.get_property("name")
         if tag_name and tag_name != cons.GTKSPELLCHECK_TAG_NAME:
             if tag_name.startswith("weight_"): curr_attributes[cons.TAG_WEIGHT] = ""
             elif tag_name.startswith("foreground_"): curr_attributes[cons.TAG_FOREGROUND] = ""
             elif tag_name.startswith("background_"): curr_attributes[cons.TAG_BACKGROUND] = ""
             elif tag_name.startswith("style_"): curr_attributes[cons.TAG_STYLE] = ""
             elif tag_name.startswith("underline_"): curr_attributes[cons.TAG_UNDERLINE] = ""
             elif tag_name.startswith("strikethrough_"): curr_attributes[cons.TAG_STRIKETHROUGH] = ""
             elif tag_name.startswith("scale_"): curr_attributes[cons.TAG_SCALE] = ""
             elif tag_name.startswith("justification_"): curr_attributes[cons.TAG_JUSTIFICATION] = ""
             elif tag_name.startswith("link_"): curr_attributes[cons.TAG_LINK] = ""
             elif tag_name.startswith("family_"): curr_attributes[cons.TAG_FAMILY] = ""
             else: support.dialog_error("Failure processing the toggling OFF tag %s" % tag_name, self.dad.window)
     toggled_on = curr_iter.get_toggled_tags(toggled_on=True)
     for tag in toggled_on:
         tag_name = tag.get_property("name")
         if tag_name and tag_name != cons.GTKSPELLCHECK_TAG_NAME:
             if tag_name.startswith("weight_"): curr_attributes[cons.TAG_WEIGHT] = tag_name[7:]
             elif tag_name.startswith("foreground_"): curr_attributes[cons.TAG_FOREGROUND] = tag_name[11:]
             elif tag_name.startswith("background_"): curr_attributes[cons.TAG_BACKGROUND] = tag_name[11:]
             elif tag_name.startswith("scale_"): curr_attributes[cons.TAG_SCALE] = tag_name[6:]
             elif tag_name.startswith("justification_"): curr_attributes[cons.TAG_JUSTIFICATION] = tag_name[14:]
             elif tag_name.startswith("style_"): curr_attributes[cons.TAG_STYLE] = tag_name[6:]
             elif tag_name.startswith("underline_"): curr_attributes[cons.TAG_UNDERLINE] = tag_name[10:]
             elif tag_name.startswith("strikethrough_"): curr_attributes[cons.TAG_STRIKETHROUGH] = tag_name[14:]
             elif tag_name.startswith("link_"): curr_attributes[cons.TAG_LINK] = tag_name[5:]
             elif tag_name.startswith("family_"): curr_attributes[cons.TAG_FAMILY] = tag_name[7:]
             else: support.dialog_error("Failure processing the toggling ON tag %s" % tag_name, self.dad.window)
Пример #5
0
 def append_tree_node(self, dom_iter, tree_father, discard_ids, node_sequence):
     """Given the dom_iter node, adds it to the tree"""
     if not discard_ids and dom_iter.hasAttribute('unique_id'):
         unique_id = long(dom_iter.attributes['unique_id'].value)
     else: unique_id = self.dad.node_id_get()
     if dom_iter.hasAttribute('tags'): node_tags = dom_iter.attributes['tags'].value
     else: node_tags = ""
     if node_tags: self.dad.tags_add_from_node(node_tags)
     if dom_iter.hasAttribute('readonly'): readonly = (dom_iter.attributes['readonly'].value == "True")
     else: readonly = False
     syntax_highlighting = dom_iter.attributes['prog_lang'].value
     if syntax_highlighting not in [cons.RICH_TEXT_ID, cons.PLAIN_TEXT_ID]\
     and syntax_highlighting not in self.dad.available_languages:
         syntax_highlighting = syntax_highlighting.lower().replace("C++", "cpp")
         if syntax_highlighting not in self.dad.available_languages:
             syntax_highlighting = cons.RICH_TEXT_ID
     node_depth = 0 if not tree_father else self.dad.treestore.iter_depth(tree_father)+1
     cherry = self.dad.get_node_icon(node_depth, syntax_highlighting)
     curr_buffer = self.dad.buffer_create(syntax_highlighting)
     if syntax_highlighting != cons.RICH_TEXT_ID: curr_buffer.begin_not_undoable_action()
     # loop into rich text, write into the buffer
     child_dom_iter = dom_iter.firstChild
     while child_dom_iter != None:
         if child_dom_iter.nodeName == "rich_text":
             self.rich_text_deserialize(curr_buffer, child_dom_iter)
         elif child_dom_iter.nodeName == "encoded_png": self.image_deserialize(curr_buffer, child_dom_iter, 2)
         elif child_dom_iter.nodeName == "table": self.table_deserialize(curr_buffer, child_dom_iter)
         elif child_dom_iter.nodeName == "codebox": self.codebox_deserialize(curr_buffer, child_dom_iter)
         elif child_dom_iter.nodeName == "encoded_image": self.image_deserialize(curr_buffer, child_dom_iter, 1)
         elif child_dom_iter.nodeName == "node": break
         child_dom_iter = child_dom_iter.nextSibling
     if syntax_highlighting != cons.RICH_TEXT_ID: curr_buffer.end_not_undoable_action()
     curr_buffer.set_modified(False)
     #print unique_id
     # insert the node containing the buffer into the tree
     tree_iter = self.dad.treestore.append(tree_father, [cherry,
                                                         dom_iter.attributes['name'].value,
                                                         curr_buffer,
                                                         unique_id,
                                                         syntax_highlighting,
                                                         node_sequence,
                                                         node_tags,
                                                         readonly,
                                                         None])
     self.dad.nodes_names_dict[unique_id] = self.dad.treestore[tree_iter][1]
     if discard_ids:
         # we are importing nodes
         self.dad.ctdb_handler.pending_new_db_node(unique_id)
     # loop for child nodes
     child_sequence = 0
     while child_dom_iter!= None:
         if child_dom_iter.nodeName == "node":
             child_sequence += 1
             self.append_tree_node(child_dom_iter, tree_iter, discard_ids, child_sequence)
         elif child_dom_iter.nodeName == 'rich_text':
             support.dialog_error("Rich text instead of child node??!!", self.dad.window)
             break
         child_dom_iter = child_dom_iter.nextSibling
Пример #6
0
 def append_tree_node(self, dom_iter, tree_father, discard_ids, node_sequence):
     """Given the dom_iter node, adds it to the tree"""
     if not discard_ids and dom_iter.hasAttribute('unique_id'):
         unique_id = long(dom_iter.attributes['unique_id'].value)
     else: unique_id = self.dad.node_id_get()
     if dom_iter.hasAttribute('tags'): node_tags = dom_iter.attributes['tags'].value
     else: node_tags = ""
     if node_tags: self.dad.tags_add_from_node(node_tags)
     if dom_iter.hasAttribute('readonly'): readonly = (dom_iter.attributes['readonly'].value == "True")
     else: readonly = False
     syntax_highlighting = dom_iter.attributes['prog_lang'].value
     if syntax_highlighting not in [cons.RICH_TEXT_ID, cons.PLAIN_TEXT_ID]\
     and syntax_highlighting not in self.dad.available_languages:
         syntax_highlighting = syntax_highlighting.lower().replace("C++", "cpp")
         if syntax_highlighting not in self.dad.available_languages:
             syntax_highlighting = cons.RICH_TEXT_ID
     node_depth = 0 if not tree_father else self.dad.treestore.iter_depth(tree_father)+1
     cherry = self.dad.get_node_icon(node_depth, syntax_highlighting)
     curr_buffer = self.dad.buffer_create(syntax_highlighting)
     if syntax_highlighting != cons.RICH_TEXT_ID: curr_buffer.begin_not_undoable_action()
     # loop into rich text, write into the buffer
     child_dom_iter = dom_iter.firstChild
     while child_dom_iter != None:
         if child_dom_iter.nodeName == "rich_text":
             self.rich_text_deserialize(curr_buffer, child_dom_iter)
         elif child_dom_iter.nodeName == "encoded_png": self.image_deserialize(curr_buffer, child_dom_iter, 2)
         elif child_dom_iter.nodeName == "table": self.table_deserialize(curr_buffer, child_dom_iter)
         elif child_dom_iter.nodeName == "codebox": self.codebox_deserialize(curr_buffer, child_dom_iter)
         elif child_dom_iter.nodeName == "encoded_image": self.image_deserialize(curr_buffer, child_dom_iter, 1)
         elif child_dom_iter.nodeName == "node": break
         child_dom_iter = child_dom_iter.nextSibling
     if syntax_highlighting != cons.RICH_TEXT_ID: curr_buffer.end_not_undoable_action()
     curr_buffer.set_modified(False)
     #print unique_id
     # insert the node containing the buffer into the tree
     tree_iter = self.dad.treestore.append(tree_father, [cherry,
                                                         dom_iter.attributes['name'].value,
                                                         curr_buffer,
                                                         unique_id,
                                                         syntax_highlighting,
                                                         node_sequence,
                                                         node_tags,
                                                         readonly])
     self.dad.nodes_names_dict[unique_id] = self.dad.treestore[tree_iter][1]
     if discard_ids:
         # we are importing nodes
         self.dad.ctdb_handler.pending_new_db_node(unique_id)
     # loop for child nodes
     child_sequence = 0
     while child_dom_iter!= None:
         if child_dom_iter.nodeName == "node":
             child_sequence += 1
             self.append_tree_node(child_dom_iter, tree_iter, discard_ids, child_sequence)
         elif child_dom_iter.nodeName == 'rich_text':
             support.dialog_error("Rich text instead of child node??!!", self.dad.window)
             break
         child_dom_iter = child_dom_iter.nextSibling
Пример #7
0
 def node_export_to_ctd(self, tree_iter, filepath, sel_range=None):
     """Export the Selected Node To CTD"""
     if self.dad.filetype in ["d", "z"]:
         try: xml_string = self.dad.xml_handler.treestore_sel_node_only_to_dom(tree_iter, sel_range=sel_range)
         except:
             support.dialog_error("%s write failed - sel node to xml" % filepath, self.dad.window)
             raise
             return
     else: xml_string = ""
     try: self.dad.file_write_low_level(filepath, xml_string, first_write=True, exporting="n", sel_range=sel_range)
     except:
         support.dialog_error("%s write failed - writing to disk" % filepath, self.dad.window)
         raise
Пример #8
0
 def node_and_subnodes_export_to_ctd(self, tree_iter, filepath):
     """Export Node and Subnodes To CTD"""
     if self.dad.filetype in ["d", "z"]:
         try: xml_string = self.dad.xml_handler.treestore_sel_node_and_subnodes_to_dom(tree_iter)
         except:
             support.dialog_error("%s write failed - sel node and subnodes to xml" % filepath, self.dad.window)
             raise
             return
     else: xml_string = ""
     try: self.dad.file_write_low_level(filepath, xml_string, first_write=True, exporting="s")
     except:
         support.dialog_error("%s write failed - writing to disk" % filepath, self.dad.window)
         raise
Пример #9
0
 def nodes_all_export_to_ctd(self, filepath):
     """Export All Nodes To CTD"""
     if self.dad.filetype in ["d", "z"]:
         try: xml_string = self.dad.xml_handler.treestore_to_dom()
         except:
             support.dialog_error("%s write failed - all nodes to xml" % filepath, self.dad.window)
             raise
             return
     else: xml_string = ""
     try: self.dad.file_write_low_level(filepath, xml_string, first_write=True, exporting="a")
     except:
         support.dialog_error("%s write failed - writing to disk" % filepath, self.dad.window)
         raise
Пример #10
0
 def on_treeview_event_after(self, treeview, event):
     """Catches mouse buttons clicks"""
     if event.type not in [gtk.gdk.BUTTON_PRESS, gtk.gdk.KEY_PRESS]: return
     model, list_iter = self.treeviewselection.get_selected()
     if not list_iter: return
     tree_iter = self.dad.get_tree_iter_from_node_id(model[list_iter][0])
     if not tree_iter:
         support.dialog_error(_("The Link Refers to a Node that Does Not Exist Anymore (Id = %s)") % model[list_iter][0], self.dad.window)
         self.liststore.remove(list_iter)
         return
     self.dad.treeview_safe_set_cursor(tree_iter)
     self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_insert(),
                                    self.dad.curr_buffer.get_iter_at_offset(model[list_iter][1]))
     self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_selection_bound(),
                                    self.dad.curr_buffer.get_iter_at_offset(model[list_iter][2]))
     self.dad.sourceview.scroll_to_mark(self.dad.curr_buffer.get_insert(), 0.25)
Пример #11
0
 def on_treeview_event_after(self, treeview, event):
     """Catches mouse buttons clicks"""
     if event.type not in [gtk.gdk.BUTTON_PRESS, gtk.gdk.KEY_PRESS]: return
     model, list_iter = self.treeviewselection.get_selected()
     if not list_iter: return
     tree_iter = self.dad.get_tree_iter_from_node_id(model[list_iter][0])
     if not tree_iter:
         support.dialog_error(_("The Link Refers to a Node that Does Not Exist Anymore (Id = %s)") % model[list_iter][0], self.dad.window)
         self.liststore.remove(list_iter)
         return
     self.dad.treeview_safe_set_cursor(tree_iter)
     self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_insert(),
                                    self.dad.curr_buffer.get_iter_at_offset(model[list_iter][1]))
     self.dad.curr_buffer.move_mark(self.dad.curr_buffer.get_selection_bound(),
                                    self.dad.curr_buffer.get_iter_at_offset(model[list_iter][2]))
     self.dad.sourceview.scroll_to_mark(self.dad.curr_buffer.get_insert(), 0.25)
Пример #12
0
        return print_operation

    def run_print_operation(self, print_operation, parent):
        """Run a Ready Print Operation"""
        if self.pdf_filepath:
            print_operation.set_export_filename(self.pdf_filepath)
        print_operation_action = gtk.PRINT_OPERATION_ACTION_EXPORT if self.pdf_filepath else gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG
        try:
            res = print_operation.run(print_operation_action, parent)
        except gobject.GError, ex:
            support.dialog_error(
                "Error printing file:\n%s (exception catched)" % str(ex),
                parent)
        else:
            if res == gtk.PRINT_OPERATION_RESULT_ERROR:
                support.dialog_error("Error printing file (bad res)", parent)
            elif res == gtk.PRINT_OPERATION_RESULT_APPLY:
                self.settings = print_operation.get_print_settings()
        if not print_operation.is_finished():
            print_operation.connect("status_changed",
                                    self.on_print_status_changed)

    def on_print_status_changed(self, operation):
        """Print Operation Status Changed"""
        if operation.is_finished(): active_prints.remove(operation)

    def print_text(self, window, pango_text, text_font, code_font,
                   pixbuf_table_codebox_vector, text_window_width):
        """Start the Print Operations for Text"""
        self.pango_font = pango.FontDescription(text_font)
        self.codebox_font = pango.FontDescription(code_font)
Пример #13
0
        if self.page_setup is None: self.page_setup = gtk.PageSetup()
        if self.settings is None: self.settings = gtk.PrintSettings()
        print_operation.set_default_page_setup(self.page_setup)
        print_operation.set_print_settings(self.settings)
        return print_operation

    def run_print_operation(self, print_operation, parent):
        """Run a Ready Print Operation"""
        if self.pdf_filepath: print_operation.set_export_filename(self.pdf_filepath)
        print_operation_action = gtk.PRINT_OPERATION_ACTION_EXPORT if self.pdf_filepath else gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG
        try: res = print_operation.run(print_operation_action, parent)
        except gobject.GError, ex:
            support.dialog_error("Error printing file:\n%s (exception catched)" % str(ex), parent)
        else:
            if res == gtk.PRINT_OPERATION_RESULT_ERROR:
                support.dialog_error("Error printing file (bad res)", parent)
            elif res == gtk.PRINT_OPERATION_RESULT_APPLY:
                self.settings = print_operation.get_print_settings()
        if not print_operation.is_finished():
            print_operation.connect("status_changed", self.on_print_status_changed)

    def on_print_status_changed(self, operation):
        """Print Operation Status Changed"""
        if operation.is_finished(): active_prints.remove(operation)

    def print_text(self, window, pango_text, text_font, code_font, pixbuf_table_codebox_vector, text_window_width):
        """Start the Print Operations for Text"""
        self.pango_font = pango.FontDescription(text_font)
        self.codebox_font = pango.FontDescription(code_font)
        self.text_window_width = text_window_width
        self.table_text_row_height = self.pango_font.get_size()/pango.SCALE