コード例 #1
0
ファイル: fontInfo_test.py プロジェクト: mandel59/trufont
class InfoTabWidgetTest(unittest.TestCase):

    app = Application(sys.argv)

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

    def setUp(self):
        self.infoTab = InfoTabWidget(None)

    def test_addNamedTab(self):
        tab1 = QWidget(None)
        tab1.name = "Test1"
        self.infoTab.addNamedTab(tab1)
        tab2 = self.infoTab.widget(0)
        self.assertEqual(tab1, tab2)
        self.assertEqual(tab1.name, tab2.name)

        tab2 = QWidget(None)
        tab2.name = "Test2"
        self.infoTab.addNamedTab(tab2)
        tab2 = self.infoTab.widget(0)
        self.assertEqual(tab1, tab2)
        self.assertEqual(tab1.name, tab2.name)
コード例 #2
0
ファイル: __main__.py プロジェクト: davelab6/trufont
def main():
    # register representation factories
    representationFactories.registerAllFactories()
    # initialize the app
    app = Application(sys.argv)
    app.setOrganizationName("TruFont")
    app.setOrganizationDomain("trufont.github.io")
    app.setApplicationName("TruFont")
    app.setApplicationVersion(__version__)
    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
    # parse options and open fonts
    parser = QCommandLineParser()
    parser.setApplicationDescription("The TruFont font editor.")
    parser.addHelpOption()
    parser.addVersionOption()
    parser.addPositionalArgument("files", "The UFO files to open.")
    parser.process(app)
    args = parser.positionalArguments()
    if not len(args):
        fontPath = None
        # maybe load recent file
        settings = QSettings()
        loadRecentFile = settings.value("misc/loadRecentFile", False, bool)
        if loadRecentFile:
            recentFiles = settings.value("core/recentFiles", [], type=str)
            if len(recentFiles):
                fontPath = recentFiles[0]
                app.openFile(fontPath)
        # otherwise, create a new file
        if fontPath is None:
            app.newFile()
    else:
        for fontPath in args:
            app.openFile(fontPath)
    sys.exit(app.exec_())
コード例 #3
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_())
コード例 #4
0
ファイル: fontInfo_test.py プロジェクト: mandel59/trufont
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)
コード例 #5
0
ファイル: __main__.py プロジェクト: adrientetar/trufont
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_())
コード例 #6
0
def main():
    # register representation factories
    representationFactories.registerAllFactories()
    # initialize the app
    app = Application(sys.argv)
    app.setOrganizationName("TruFont")
    app.setOrganizationDomain("trufont.github.io")
    app.setApplicationName("TruFont")
    app.setApplicationVersion(__version__)
    app.setWindowIcon(QIcon(":/resources/app.png"))

    # Qt's translation for itself. May not be installed.
    qtTranslator = QTranslator()
    qtTranslator.load("qt_" + QLocale.system().name(),
                      QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    app.installTranslator(qtTranslator)

    appTranslator = QTranslator()
    appTranslator.load("trufont_" + QLocale.system().name(),
                       os.path.dirname(os.path.realpath(__file__)) +
                       "/resources")
    app.installTranslator(appTranslator)

    app.loadGlyphList()
    # parse options and open fonts
    parser = QCommandLineParser()
    parser.setApplicationDescription(QApplication.translate(
        "Command-line parser", "The TruFont font editor."))
    parser.addHelpOption()
    parser.addVersionOption()
    parser.addPositionalArgument(QApplication.translate(
        "Command-line parser", "files"), QApplication.translate(
        "Command-line parser", "The UFO files to open."))
    parser.process(app)
    args = parser.positionalArguments()
    if not len(args):
        fontPath = None
        # maybe load recent file
        settings = QSettings()
        loadRecentFile = settings.value("misc/loadRecentFile", False, bool)
        if loadRecentFile:
            recentFiles = settings.value("core/recentFiles", [], type=str)
            if len(recentFiles) and os.path.exists(recentFiles[0]):
                fontPath = recentFiles[0]
                app.openFile(fontPath)
        # otherwise, create a new file
        if fontPath is None:
            app.newFile()
    else:
        for fontPath in args:
            app.openFile(fontPath)
    sys.exit(app.exec_())