from xasyqtui.labelTextEditor import Ui_Dialog
import PyQt5.QtWidgets as QtWidgets
import PyQt5.QtSvg as QtSvg
import PyQt5.QtGui as QtGui
import PyQt5.QtCore as QtCore
import xasyArgs as xasyArgs
import xasy2asy as xasy2asy
import xasyOptions as xasyOptions
import xasyUtils as xasyUtils
import subprocess
import tempfile
import uuid
import os
import io
class labelEditor(QtWidgets.QDialog):
def __init__(self, text=''):
super().__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
def initializeText(self, text: str):
if text[0] == '$' and text[-1] == '$':
self.ui.chkMathMode.setChecked(True)
text = text.strip('$')
if text.startswith('\\displaystyle{'):
self.ui.cmbMathStyle.setCurrentText('Display Style')
text = text.rstrip('}')
text = text.replace('\\displaystyle{', '', 1)
elif text.startswith('\\scriptstyle{'):
self.ui.cmbMathStyle.setCurrentText('Script Style')
text = text.rstrip('}')
text = text.replace('\\scriptstyle{', '', 1)
self.svgPreview = QtSvg.QSvgRenderer()
with tempfile.TemporaryDirectory(prefix='xasylbl_') as tmpdir:
id = str(uuid.uuid4())
tmpFile = os.path.join(tmpdir, 'lbl-{0}.svg'.format(id))
with subprocess.Popen(args=[path, '-fsvg', '-o', tmpFile, '-'], encoding='utf-8', stdin=subprocess.PIPE,
stdout=subprocess.PIPE) as asy:
asy.stdin.write(asyInput.format(self.getText()))
asy.stdin.close()
out = asy.stdout.read()
raw_array = out.splitlines()
bounds_1, bounds_2 = [val.strip() for val in raw_array]