Exemplo n.º 1
0
    def on_inline_latex(self, window, tag):
        """Callback for inserting different latex objects based on tag"""

        widget = self._widget_focus.get(window, None)

        if isinstance(widget, gtk.TextView):

            # Following gets the notebook
            notebook = window.get_notebook()
            if notebook is None:
               return

            nodes = window.get_selected_nodes()
            if len(nodes) == 0:
               return
            else:
               sibling = nodes[0]

            datadir=self.get_base_dir()
            imfile=icons[tag]
            origfilename=os.path.join(datadir, imfile)
            img = RichTextImage()
            img.set_from_pixbuf(gdk.pixbuf_new_from_file(origfilename.encode()))
            widget.get_buffer().insert_image(img, imfile)
            image_path=os.path.join(sibling.get_path(), img.get_filename())
            tagstr=_("%i") %(tag+3)
            ReLoad = Updating(sibling,window.get_viewer(),widget)
            dialog = dialog_latex.LaTeXDialog(ReLoad,tagstr,image_path)
            dialog.show()
Exemplo n.º 2
0
def latex2pixbuf(permeable,out_txt,latex_type):
    """
    Converting latex objects to RichTextImage
    """
    try:
        # Set the working directory
        workdir = tempfile.gettempdir()
        if latex_type== "InlineEquation":
            latex_name='formula.png'
            origfilename=os.path.join(workdir,latex_name )
            result_tag=math2png(out_txt[1:-1], origfilename,permeable)
            if result_tag is -1:
                result_tag=error2png(origfilename)
            tag="3"
            tex=out_txt[1:-1].encode()
            caption=""
            label=""
        if latex_type== "Footnote":
            latex_name='footnote.png'
            origfilename=os.path.join(workdir,latex_name )
            result_tag=footnote2png(origfilename)
            tag="8"
            tex=out_txt[10:-1].encode()
            caption=""
            label=""
        if latex_type== "LaTeX":
            latex_name='latex.png'
            origfilename=os.path.join(workdir,latex_name )
            result_tag=latex2png(out_txt, origfilename,permeable)
            if result_tag is -1:
                result_tag=error2png(origfilename)
            tag="7"
            tex=out_txt.encode()
            caption=""
            label=""
        if latex_type== "Citation":
            latex_name='cite.png'
            origfilename=os.path.join(workdir,latex_name )
            result_tag=cite2png(out_txt[14:-1], origfilename,permeable)
            if result_tag is -1:
                result_tag=error2png(origfilename)
            tag="6"
            tex=out_txt[14:-1].encode()
            caption=""
            label=""
        if result_tag is not -1:
            img = RichTextImage()
            pixbuf=gdk.pixbuf_new_from_file(origfilename)
            pixbuf.save(origfilename,"png", {"tEXt::tag":tag,"tEXt::label":label,\
            "tEXt::caption":caption,"tEXt::tex":tex})
            img.set_from_pixbuf(gdk.pixbuf_new_from_file(origfilename.encode()))
            img.set_filename(latex_name)
        else:
            img=None
    finally:
        if os.path.exists(origfilename):
            os.remove(origfilename)


    return img
Exemplo n.º 3
0
    def on_inline_latex(self, window, tag):
        """Callback for inserting different latex objects based on tag"""

        widget = self._widget_focus.get(window, None)

        if isinstance(widget, gtk.TextView):

            # Following gets the notebook
            notebook = window.get_notebook()
            if notebook is None:
                return

            nodes = window.get_selected_nodes()
            if len(nodes) == 0:
                return
            else:
                sibling = nodes[0]

            datadir = self.get_base_dir()
            imfile = icons[tag]
            origfilename = os.path.join(datadir, imfile)
            img = RichTextImage()
            img.set_from_pixbuf(gdk.pixbuf_new_from_file(
                origfilename.encode()))
            widget.get_buffer().insert_image(img, imfile)
            image_path = os.path.join(sibling.get_path(), img.get_filename())
            tagstr = _("%i") % (tag + 3)
            ReLoad = Updating(sibling, window.get_viewer(), widget)
            dialog = dialog_latex.LaTeXDialog(ReLoad, tagstr, image_path)
            dialog.show()
Exemplo n.º 4
0
def latex2pixbuf(permeable, out_txt, latex_type):
    """
    Converting latex objects to RichTextImage
    """
    try:
        # Set the working directory
        workdir = tempfile.gettempdir()
        if latex_type == "InlineEquation":
            latex_name = 'formula.png'
            origfilename = os.path.join(workdir, latex_name)
            result_tag = math2png(out_txt[1:-1], origfilename, permeable)
            if result_tag is -1:
                result_tag = error2png(origfilename)
            tag = "3"
            tex = out_txt[1:-1].encode()
            caption = ""
            label = ""
        if latex_type == "Footnote":
            latex_name = 'footnote.png'
            origfilename = os.path.join(workdir, latex_name)
            result_tag = footnote2png(origfilename)
            tag = "8"
            tex = out_txt[10:-1].encode()
            caption = ""
            label = ""
        if latex_type == "LaTeX":
            latex_name = 'latex.png'
            origfilename = os.path.join(workdir, latex_name)
            result_tag = latex2png(out_txt, origfilename, permeable)
            if result_tag is -1:
                result_tag = error2png(origfilename)
            tag = "7"
            tex = out_txt.encode()
            caption = ""
            label = ""
        if latex_type == "Citation":
            latex_name = 'cite.png'
            origfilename = os.path.join(workdir, latex_name)
            result_tag = cite2png(out_txt[14:-1], origfilename, permeable)
            if result_tag is -1:
                result_tag = error2png(origfilename)
            tag = "6"
            tex = out_txt[14:-1].encode()
            caption = ""
            label = ""
        if result_tag is not -1:
            img = RichTextImage()
            pixbuf = gdk.pixbuf_new_from_file(origfilename)
            pixbuf.save(origfilename,"png", {"tEXt::tag":tag,"tEXt::label":label,\
            "tEXt::caption":caption,"tEXt::tex":tex})
            img.set_from_pixbuf(gdk.pixbuf_new_from_file(
                origfilename.encode()))
            img.set_filename(latex_name)
        else:
            img = None
    finally:
        if os.path.exists(origfilename):
            os.remove(origfilename)

    return img