<commit_before>#!/usr/bin/env python
"""
=======
textext
=======

:Author: <NAME> <<EMAIL>>
:Author: <NAME> <<EMAIL>>
:Date: 2007-07-19
:License: BSD

Textext is an extension for Inkscape_ that allows adding
LaTeX-generated text objects to your SVG drawing. What's more, you can
also *edit* these text objects after creating them.

This brings some of the power of TeX typesetting to Inkscape.

Textext was initially based on InkLaTeX_ written by Toru Araki,
but is now rewritten.

.. note::
   Unfortunately, the TeX input dialog is modal. That is, you cannot
   do anything else with Inkscape while you are composing the LaTeX
   text snippet.

   This is because I have not yet worked out whether it is possible to
   write asynchronous extensions for Inkscape.

.. note::
   Textext requires Pdflatex and one of the following
     - Pdf2svg_
     - Pstoedit_ compiled with the ``plot-svg`` back-end
     - Pstoedit_ and Skconvert_

.. _Pstoedit: http://www.pstoedit.net/pstoedit
.. _Skconvert: http://www.skencil.org/
.. _Pdf2svg: http://www.cityinthesky.co.uk/pdf2svg.html
.. _Inkscape: http://www.inkscape.org/
.. _InkLaTeX: http://www.kono.cis.iwate-u.ac.jp/~arakit/inkscape/inklatex.html
"""

#------------------------------------------------------------------------------

__version__ = "0.3"
__author__ = "<NAME> <<EMAIL>>, <NAME> <<EMAIL>>"
__docformat__ = "restructuredtext en"

import sys, os
sys.path.append('/usr/share/inkscape/extensions')
sys.path.append(r'c:/Program Files/Inkscape/share/extensions')
sys.path.append(os.path.dirname(__file__))

import inkex45 as inkex
import os, sys, tempfile, traceback, glob, re
import xml.dom.ext.reader.Sax2, xml.sax.handler
from xml.dom.NodeFilter import NodeFilter

USE_GTK = False
try:
    import pygtk
    pygtk.require('2.0')
    import gtk
    USE_GTK = True
except ImportError:
    pass

USE_TK = False
try:
    import Tkinter as Tk
    USE_TK = True
except ImportError:
    pass

USE_WINDOWS = ('win' in sys.platform)

TEXTEXT_NS = "http://www.iki.fi/pav/software/textext/"
SVG_NS = "http://www.w3.org/2000/svg"
XLINK_NS = "http://www.w3.org/1999/xlink"

ID_PREFIX = "textext-obj-"

#------------------------------------------------------------------------------
# Inkscape plugin functionality & GUI
#------------------------------------------------------------------------------

if USE_GTK:
    class AskText(object):
        """GUI for editing TexText objects"""
        def __init__(self, text, preamble_file, scale_factor):
            self.text = text
            self.preamble_file = preamble_file
            self.scale_factor = scale_factor
    
        def ask(self):
            window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            window.set_title("TeX Text")
            window.set_default_size(400, 200)
    
            label1 = gtk.Label(u"Preamble file:")
            label2 = gtk.Label(u"Scale factor:")
            label3 = gtk.Label(u"Text:")
    
            self._preamble = gtk.Entry()
            self._preamble.set_text(self.preamble_file)
    
            self._scale_adj = gtk.Adjustment(value=self.scale_factor,
                                             lower=0.01, upper=100,
                                             step_incr=0.1, page_incr=1)
            self._scale = gtk.SpinButton(self._scale_adj, digits=2)
    
            self._text = gtk.TextView()
            self._text.get_buffer().set_text(self.text)
    
            ok = gtk.Button(stock=gtk.STOCK_OK)
    
            # layout
            table = gtk.Table(3, 2, False)
            table.attach(label1,         0,1,0,1,xoptions=0,yoptions=gtk.FILL)
            table.attach(self._preamble, 1,2,0,1,yoptions=gtk.FILL)
            table.attach(label2,         0,1,1,2,xoptions=0,yoptions=gtk.FILL)
            table.attach(self._scale,    1,2,1,2,yoptions=gtk.FILL)
            table.attach(label3,         0,1,2,3,xoptions=0,yoptions=gtk.FILL)
            table.attach(self._text,     1,2,2,3)
    
            vbox = gtk.VBox(False, 5)
            vbox.pack_start(table)
            vbox.pack_end(ok, expand=False)
    
            window.add(vbox)
    
            # signals
            window.connect("delete-event", self.cb_delete_event)
            ok.connect("clicked", self.cb_ok)
    
            # run
            window.show_all()
            gtk.main()
    
            return self.text, self.preamble_file, self.scale_factor
    
        def cb_delete_event(self, widget, event, data=None):
            gtk.main_quit()
            return False
        
        def cb_ok(self, widget, data=None):
            buf = self._text.get_buffer()
            self.text = buf.get_text(buf.get_start_iter(),
                                     buf.get_end_iter())
            self.preamble_file = self._preamble.get_text()
            self.scale_factor = self._scale_adj.get_value()
            gtk.main_quit()<commit_msg>Pimp up the GTK dialog<commit_after>#!/usr/bin/env python
"""
=======
textext
=======

:Author: <NAME> <<EMAIL>>
:Author: <NAME> <<EMAIL>>
:Date: 2007-07-19
:License: BSD

Textext is an extension for Inkscape_ that allows adding
LaTeX-generated text objects to your SVG drawing. What's more, you can
also *edit* these text objects after creating them.

This brings some of the power of TeX typesetting to Inkscape.

Textext was initially based on InkLaTeX_ written by <NAME>,
but is now rewritten.

.. note::
   Unfortunately, the TeX input dialog is modal. That is, you cannot
   do anything else with Inkscape while you are composing the LaTeX
   text snippet.

   This is because I have not yet worked out whether it is possible to
   write asynchronous extensions for Inkscape.

.. note::
   Textext requires Pdflatex and one of the following
     - Pdf2svg_
     - Pstoedit_ compiled with the ``plot-svg`` back-end
     - Pstoedit_ and Skconvert_

.. _Pstoedit: http://www.pstoedit.net/pstoedit
.. _Skconvert: http://www.skencil.org/
.. _Pdf2svg: http://www.cityinthesky.co.uk/pdf2svg.html
.. _Inkscape: http://www.inkscape.org/
.. _InkLaTeX: http://www.kono.cis.iwate-u.ac.jp/~arakit/inkscape/inklatex.html
"""

#------------------------------------------------------------------------------

__version__ = "0.3"
__author__ = "<NAME> <<EMAIL>>, <NAME> <<EMAIL>>"
__docformat__ = "restructuredtext en"

import sys, os
sys.path.append('/usr/share/inkscape/extensions')
sys.path.append(r'c:/Program Files/Inkscape/share/extensions')
sys.path.append(os.path.dirname(__file__))

import inkex45 as inkex
import os, sys, tempfile, traceback, glob, re
import xml.dom.ext.reader.Sax2, xml.sax.handler
from xml.dom.NodeFilter import NodeFilter

USE_GTK = False
try:
    import pygtk
    pygtk.require('2.0')
    import gtk
    USE_GTK = True
except ImportError:
    pass

USE_TK = False
try:
    import Tkinter as Tk
    USE_TK = True
except ImportError:
    pass

USE_WINDOWS = ('win' in sys.platform)

TEXTEXT_NS = "http://www.iki.fi/pav/software/textext/"
SVG_NS = "http://www.w3.org/2000/svg"
XLINK_NS = "http://www.w3.org/1999/xlink"

ID_PREFIX = "textext-obj-"

#------------------------------------------------------------------------------
# Inkscape plugin functionality & GUI
#------------------------------------------------------------------------------

if USE_GTK:
    class AskText(object):
        """GUI for editing TexText objects"""
        def __init__(self, text, preamble_file, scale_factor):
            self.text = text
            self.preamble_file = preamble_file
            self.scale_factor = scale_factor
    
        def ask(self):
            window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            window.set_title("TeX Text")
            window.set_default_size(600, 600)
    
            label1 = gtk.Label(u"Preamble file:")
            label2 = gtk.Label(u"Scale factor:")
            label3 = gtk.Label(u"Text:")


            if hasattr(gtk, 'FileChooserButton'):
                self._preamble = gtk.FileChooserButton("...")
                self._preamble.set_filename(self.preamble_file)
                self._preamble.set_action(gtk.FILE_CHOOSER_ACTION_OPEN)
            else:
                self._preamble = gtk.Entry()
                self._preamble.set_text(self.preamble_file)

            self._scale_adj = gtk.Adjustment(value=self.scale_factor,
                                             lower=0.01, upper=100,
                                             step_incr=0.1, page_incr=1)
            self._scale = gtk.SpinButton(self._scale_adj, digits=2)

            self._text = gtk.TextView()
            self._text.get_buffer().set_text(self.text)

            sw = gtk.ScrolledWindow()
            sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
            sw.set_shadow_type(gtk.SHADOW_IN)
            sw.add(self._text)
            
            ok = gtk.Button(stock=gtk.STOCK_OK)
    
            # layout
            table = gtk.Table(3, 2, False)
            table.attach(label1,         0,1,0,1,xoptions=0,yoptions=gtk.FILL)
            table.attach(self._preamble, 1,2,0,1,yoptions=gtk.FILL)
            table.attach(label2,         0,1,1,2,xoptions=0,yoptions=gtk.FILL)
            table.attach(self._scale,    1,2,1,2,yoptions=gtk.FILL)
            table.attach(label3,         0,1,2,3,xoptions=0,yoptions=gtk.FILL)
            table.attach(sw,             1,2,2,3)
    
            vbox = gtk.VBox(False, 5)
            vbox.pack_start(table)
            vbox.pack_end(ok, expand=False)
    
            window.add(vbox)
    
            # signals
            window.connect("delete-event", self.cb_delete_event)
            ok.connect("clicked", self.cb_ok)
    
            # run
            window.show_all()
            gtk.main()
    
            return self.text, self.preamble_file, self.scale_factor
    
        def cb_delete_event(self, widget, event, data=None):
            gtk.main_quit()
            return False
        
        def cb_ok(self, widget, data=None):
            buf = self._text.get_buffer()
            self.text = buf.get_text(buf.get_start_iter(),
                                     buf.get_end_iter())
            if isinstance(self._preamble, gtk.FileChooser):
                self.preamble_file = self._preamble.get_filename()
                if not self.preamble_file:
                    self.preamble_file = ""
            else:
                self.preamble_file = self._preamble.get_text()
                
            self.scale_factor = self._scale_adj.get_value()
            gtk.main_quit()
{'fraction_non_alphanumeric': 0.15461560445841668, 'fraction_numerical': 0.015242450223873487, 'mean_word_length': 1.9008013263332413, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 16, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1393641', 'n_tokens_mistral': 3479, 'n_tokens_neox': 3329, 'n_words': 680}