使用PySide渲染LaTeX / MathML

3

我有一个小程序,使用SymPy的“漂亮打印”功能实时呈现输入的方程式。这个功能可以正常工作,但看起来不太专业。由于SymPy可以生成Latex或MML,我想知道它们是否可以通过PySide小部件以图形方式呈现?我显然需要更改“QTextBrowser()”,但我不确定要更改为什么。我知道诺基亚提供了QtMmlWidget,但我不确定它是否可以被PySide使用。

感谢您的帮助和祝福。

from __future__ import division
import sys
import sympy

from PySide.QtGui import *
from PySide.QtCore import *
from PySide.QtXml import *

class Form(QDialog):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.browser = QTextBrowser()
        self.browser.setCurrentFont(QFont("Courier New",10,QFont.Bold))
        self.lineedit = QLineEdit("please type an expression")
        self.lineedit.selectAll()
        layout = QVBoxLayout()
        layout.addWidget(self.browser)
        layout.addWidget(self.lineedit)
        self.setLayout(layout)
        self.lineedit.setFocus()
        self.connect(self.lineedit, SIGNAL("textChanged (const QString&)"),self.updateUi)

    def updateUi(self):
        text = unicode(self.lineedit.text())
        for z in range(0,9):
            text = text.replace('x'+str(z),'x^'+str(z))
            text = text.replace(')'+str(z),')^'+str(z))
            text = text.replace(str(z)+'x',str(z)+'*x')
            text = text.replace(str(z)+'(',str(z)+'*(')

        try:
            self.browser.append(sympy.printing.pretty(sympy.sympify(text)))
            self.browser.clear()
            self.browser.append(sympy.printing.pretty(sympy.sympify(text)))
        except Exception:
            if text=='': self.browser.clear()

app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接