Beispiel #1
0
def main():

    if len(sys.argv) > 1:
        font = TFont(os.path.abspath(sys.argv[1]))
    else:
        font = None

    representationFactories.registerAllFactories()
    app = Application(sys.argv)
    # TODO: http://stackoverflow.com/a/21330349/2037879
    app.setOrganizationName("TruFont")
    app.setOrganizationDomain("trufont.github.io")
    app.setApplicationName("TruFont")
    app.setWindowIcon(QIcon(":/resources/app.png"))
    settings = QSettings()
    glyphListPath = settings.value("settings/glyphListPath", "", type=str)
    if glyphListPath and os.path.exists(glyphListPath):
        from defconQt.util import glyphList
        try:
            glyphList = glyphList.parseGlyphList(glyphListPath)
        except Exception as e:
            print(e)
        else:
            app.GL2UV = glyphList
    window = MainWindow(font)
    window.show()
    sys.exit(app.exec_())
Beispiel #2
0
 def setUp(self):
     self.mainWindow = MainWindow(None)
     self.mainWindow.fontInfo()
     self.font = self.mainWindow.font
     self.fontInfo = self.mainWindow.fontInfoWindow
     self.generalTab = self.fontInfo.tabWidget.widget(0)
     self.metricsTab = self.fontInfo.tabWidget.widget(1)
     self.openTypeTab = self.fontInfo.tabWidget.widget(2)
     self.OS2Tab = self.fontInfo.tabWidget.widget(3)
     self.postScriptTab = self.fontInfo.tabWidget.widget(4)
     self.fontInfo.show()
Beispiel #3
0
    def setUp(self):
        font = TFont()
        font.info.unitsPerEm = 1000
        font.info.ascender = 750
        font.info.descender = -250
        font.info.capHeight = 750
        font.info.xHeight = 500

        self.mainWindow = MainWindow(font)
        self.mainWindow.fontInfo()
        self.font = self.mainWindow.font
        self.fontInfo = self.mainWindow.fontInfoWindow
        self.generalTab = self.fontInfo.tabWidget.widget(0)
        self.metricsTab = self.fontInfo.tabWidget.widget(1)
        self.openTypeTab = self.fontInfo.tabWidget.widget(2)
        self.OS2Tab = self.fontInfo.tabWidget.widget(3)
        self.postScriptTab = self.fontInfo.tabWidget.widget(4)
        self.fontInfo.show()
Beispiel #4
0
 def setUp(self):
     self.mainWindow = MainWindow(None)
     self.mainWindow.fontInfo()
     self.font = self.mainWindow.font
     self.fontInfo = self.mainWindow.fontInfoWindow
     self.generalTab = self.fontInfo.tabWidget.widget(0)
     self.metricsTab = self.fontInfo.tabWidget.widget(1)
     self.openTypeTab = self.fontInfo.tabWidget.widget(2)
     self.OS2Tab = self.fontInfo.tabWidget.widget(3)
     self.postScriptTab = self.fontInfo.tabWidget.widget(4)
     self.fontInfo.show()
Beispiel #5
0
    def setUp(self):
        font = TFont()
        font.info.unitsPerEm = 1000
        font.info.ascender = 750
        font.info.descender = -250
        font.info.capHeight = 750
        font.info.xHeight = 500

        self.mainWindow = MainWindow(font)
        self.mainWindow.fontInfo()
        self.font = self.mainWindow.font
        self.fontInfo = self.mainWindow.fontInfoWindow
        self.generalTab = self.fontInfo.tabWidget.widget(0)
        self.metricsTab = self.fontInfo.tabWidget.widget(1)
        self.openTypeTab = self.fontInfo.tabWidget.widget(2)
        self.OS2Tab = self.fontInfo.tabWidget.widget(3)
        self.postScriptTab = self.fontInfo.tabWidget.widget(4)
        self.fontInfo.show()
Beispiel #6
0
class TabTestCase(unittest.TestCase):

    app = Application(sys.argv)

    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)

    def setUp(self):
        self.mainWindow = MainWindow(None)
        self.mainWindow.fontInfo()
        self.font = self.mainWindow.font
        self.fontInfo = self.mainWindow.fontInfoWindow
        self.generalTab = self.fontInfo.tabWidget.widget(0)
        self.metricsTab = self.fontInfo.tabWidget.widget(1)
        self.openTypeTab = self.fontInfo.tabWidget.widget(2)
        self.OS2Tab = self.fontInfo.tabWidget.widget(3)
        self.postScriptTab = self.fontInfo.tabWidget.widget(4)
        self.fontInfo.show()

    def tearDown(self):
        self.fontInfo.close()

    def checkString(self, attr, attrName):
        attrEdit = getattr(self.tab, attr + "Edit")
        self.assertIsNone(getattr(self.font.info, attrName))
        self.assertEqual(attrEdit.text(), "")

        attrEdit.setText("Typeface " + attr)
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), "Typeface " + attr)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

    def checkMultilineString(self, attr, attrName):
        attrEdit = getattr(self.tab, attr + "Edit")
        self.assertIsNone(getattr(self.font.info, attrName))
        self.assertEqual(attrEdit.toPlainText(), "")

        attrEdit.setPlainText("Typeface " + attr)
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), "Typeface " + attr)

        attrEdit.setPlainText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

    def checkInteger(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("-123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), -123)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QIntValidator)
        self.assertEqual(validator.bottom(), QIntValidator().bottom())
        self.assertEqual(validator.top(), QIntValidator().top())

    def checkPositiveInteger(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QIntValidator)
        self.assertEqual(validator.bottom(), 0)
        self.assertEqual(validator.top(), QIntValidator().top())

    def checkNegativeInteger(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("-123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), -123)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QIntValidator)
        self.assertEqual(validator.top(), 0)
        self.assertEqual(validator.bottom(), QIntValidator().bottom())

    def checkIntegerFloat(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123)

        attrEdit.setText("123.456")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123.456)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("0.0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0.0)

        attrEdit.setText("-123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), -123)

        attrEdit.setText("-123.456")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), -123.456)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QDoubleValidator)
        self.assertEqual(validator.bottom(), QDoubleValidator().bottom())
        self.assertEqual(validator.top(), QDoubleValidator().top())

    def checkPositiveIntegerFloat(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123)

        attrEdit.setText("123.456")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123.456)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("0.0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0.0)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QDoubleValidator)
        self.assertEqual(validator.bottom(), 0)
        self.assertEqual(validator.top(), QDoubleValidator().top())

    def checkIntegerFloatList(self, attr, attrName, maxLen=None, evenLen=None):
        attrEdit = getattr(self.tab, attr + "Edit")
        values = attrEdit.text()
        if values is "":
            self.assertEqual(getattr(self.font.info, attrName), [])
        else:
            attrEdit.setText("123 456 789 0")
            self.fontInfo.accept()
            self.assertIsNotNone(getattr(self.font.info, attrName))

        values = attrEdit.text().split(" ")
        for i, val in enumerate(values):
            if val != "":
                self.assertEqual(
                    int(val), getattr(self.font.info, attrName)[i])

        attrEdit.setText("123 456 789 0")
        self.fontInfo.accept()
        self.assertIsNotNone(getattr(self.font.info, attrName))

        # TODO: test validation

    def checkBoolean(self, attr, attrName):
        attrBox = getattr(self.tab, attr + "Box")
        self.assertTrue(attrBox.isTristate())

        value = attrBox.checkState()
        self.assertEqual(value, Qt.PartiallyChecked)
        self.assertEqual(getattr(self.font.info, attrName), None)

        attrBox.setCheckState(Qt.Checked)
        self.fontInfo.accept()
        value = attrBox.checkState()
        self.assertEqual(value, Qt.Checked)
        self.assertEqual(getattr(self.font.info, attrName), True)

        attrBox.setCheckState(Qt.Unchecked)
        self.fontInfo.accept()
        value = attrBox.checkState()
        self.assertEqual(value, Qt.Unchecked)
        self.assertEqual(getattr(self.font.info, attrName), False)
Beispiel #7
0
class TabTestCase(unittest.TestCase):

    app = Application(sys.argv)

    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)

    def setUp(self):
        font = TFont()
        font.info.unitsPerEm = 1000
        font.info.ascender = 750
        font.info.descender = -250
        font.info.capHeight = 750
        font.info.xHeight = 500

        self.mainWindow = MainWindow(font)
        self.mainWindow.fontInfo()
        self.font = self.mainWindow.font
        self.fontInfo = self.mainWindow.fontInfoWindow
        self.generalTab = self.fontInfo.tabWidget.widget(0)
        self.metricsTab = self.fontInfo.tabWidget.widget(1)
        self.openTypeTab = self.fontInfo.tabWidget.widget(2)
        self.OS2Tab = self.fontInfo.tabWidget.widget(3)
        self.postScriptTab = self.fontInfo.tabWidget.widget(4)
        self.fontInfo.show()

    def tearDown(self):
        self.fontInfo.close()

    def checkString(self, attr, attrName):
        attrEdit = getattr(self.tab, attr + "Edit")
        self.assertIsNone(getattr(self.font.info, attrName))
        self.assertEqual(attrEdit.text(), "")

        attrEdit.setText("Typeface " + attr)
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), "Typeface " + attr)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

    def checkMultilineString(self, attr, attrName):
        attrEdit = getattr(self.tab, attr + "Edit")
        self.assertIsNone(getattr(self.font.info, attrName))
        self.assertEqual(attrEdit.toPlainText(), "")

        attrEdit.setPlainText("Typeface " + attr)
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), "Typeface " + attr)

        attrEdit.setPlainText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

    def checkInteger(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("-123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), -123)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QIntValidator)
        self.assertEqual(validator.bottom(), QIntValidator().bottom())
        self.assertEqual(validator.top(), QIntValidator().top())

    def checkPositiveInteger(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QIntValidator)
        self.assertEqual(validator.bottom(), 0)
        self.assertEqual(validator.top(), QIntValidator().top())

    def checkNegativeInteger(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("-123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), -123)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QIntValidator)
        self.assertEqual(validator.top(), 0)
        self.assertEqual(validator.bottom(), QIntValidator().bottom())

    def checkIntegerFloat(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123)

        attrEdit.setText("123.456")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123.456)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("0.0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0.0)

        attrEdit.setText("-123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), -123)

        attrEdit.setText("-123.456")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), -123.456)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QDoubleValidator)
        self.assertEqual(validator.bottom(), QDoubleValidator().bottom())
        self.assertEqual(validator.top(), QDoubleValidator().top())

    def checkPositiveIntegerFloat(self, attr, attrName, value=0):
        attrEdit = getattr(self.tab, attr + "Edit")
        if value == 0:
            self.assertIsNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), "")
        else:
            self.assertIsNotNone(getattr(self.font.info, attrName))
            self.assertEqual(attrEdit.text(), str(value))

        attrEdit.setText("123")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123)

        attrEdit.setText("123.456")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 123.456)

        attrEdit.setText("0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0)

        attrEdit.setText("0.0")
        self.fontInfo.accept()
        self.assertEqual(getattr(self.font.info, attrName), 0.0)

        attrEdit.setText("")
        self.fontInfo.accept()
        self.assertIsNone(getattr(self.font.info, attrName))

        validator = attrEdit.validator()
        self.assertIsInstance(validator, QDoubleValidator)
        self.assertEqual(validator.bottom(), 0)
        self.assertEqual(validator.top(), QDoubleValidator().top())

    def checkIntegerFloatList(self, attr, attrName, maxLen=None, evenLen=None):
        attrEdit = getattr(self.tab, attr + "Edit")
        values = attrEdit.text()
        if values is "":
            self.assertEqual(getattr(self.font.info, attrName), [])
        else:
            attrEdit.setText("123 456 789 0")
            self.fontInfo.accept()
            self.assertIsNotNone(getattr(self.font.info, attrName))

        values = attrEdit.text().split(" ")
        for i, val in enumerate(values):
            if val != "":
                self.assertEqual(int(val),
                                 getattr(self.font.info, attrName)[i])

        attrEdit.setText("123 456 789 0")
        self.fontInfo.accept()
        self.assertIsNotNone(getattr(self.font.info, attrName))

        # TODO: test validation

    def checkBoolean(self, attr, attrName):
        attrBox = getattr(self.tab, attr + "Box")
        self.assertTrue(attrBox.isTristate())

        value = attrBox.checkState()
        self.assertEqual(value, Qt.PartiallyChecked)
        self.assertEqual(getattr(self.font.info, attrName), None)

        attrBox.setCheckState(Qt.Checked)
        self.fontInfo.accept()
        value = attrBox.checkState()
        self.assertEqual(value, Qt.Checked)
        self.assertEqual(getattr(self.font.info, attrName), True)

        attrBox.setCheckState(Qt.Unchecked)
        self.fontInfo.accept()
        value = attrBox.checkState()
        self.assertEqual(value, Qt.Unchecked)
        self.assertEqual(getattr(self.font.info, attrName), False)
Beispiel #8
0
from defconQt.objects.defcon import TFont
from defconQt import representationFactories
from defconQt import icons_db  # noqa
from defconQt.fontView import Application, MainWindow
import sys
import os
from PyQt5.QtGui import QIcon

if len(sys.argv) > 1:
    font = TFont(os.path.abspath(sys.argv[1]))
else:
    font = None

# from pycallgraph import PyCallGraph
# from pycallgraph.output import GraphvizOutput
representationFactories.registerAllFactories()
# with PyCallGraph(output=GraphvizOutput()):
app = Application(sys.argv)
# TODO: http://stackoverflow.com/a/21330349/2037879
app.setOrganizationName("A. Tétar & Co.")
app.setApplicationName("TruFont")
app.setWindowIcon(QIcon(":/resources/app.png"))
window = MainWindow(font)
window.show()
sys.exit(app.exec_())