def openFile(self, path=None): if not path: fileFormat = self.tr("UFO Fonts {}") if platformSpecific.treatPackageAsFile(): ext = "(*.ufo)" else: ext = "(metainfo.plist)" path, _ = QFileDialog.getOpenFileName( self.activeWindow(), self.tr("Open File"), '', fileFormat.format(ext) ) if not path: return if ".plist" in path: path = os.path.dirname(path) path = os.path.normpath(path) for widget in self.topLevelWidgets(): if isinstance(widget, FontWindow): font = widget.font_() if font is not None and font.path == path: widget.raise_() return try: font = TFont(path) window = FontWindow(font) except Exception as e: msg = self.tr( "There was an issue when opening the font at {}.".format( path)) errorReports.showCriticalException(e, msg) return window.show() self.setCurrentFile(font.path)
def _loadBinary(self, path): font = TFont() try: font.extract(path) except Exception as e: errorReports.showCriticalException(e) return window = FontWindow(font) window.show()
def setUp(self): self.font = TFont.new() self.mainWindow = FontWindow(self.font) self.mainWindow.fontInfo() self.fontInfo = self.mainWindow._infoWindow self.generalTab = self.fontInfo.tabWidget.widget(0) self.legalTab = self.fontInfo.tabWidget.widget(1) self.openTypeTab = self.fontInfo.tabWidget.widget(2) self.postScriptTab = self.fontInfo.tabWidget.widget(3) self.fontInfo.show()
def _loadFont(self, font): currentFont = self.currentFont() # Open new font in current font window if it contains an unmodified # empty font (e.g. after startup). if currentFont is not None and currentFont.path is None and \ currentFont.binaryPath is None and currentFont.dirty is False: window = self._currentFontWindow window.setFont_(font) else: window = FontWindow(font) window.show()
def _loadUFO(self, path): for widget in self.topLevelWidgets(): if isinstance(widget, FontWindow): font = widget.font_() if font is not None and font.path == path: widget.raise_() return try: font = TFont(path) window = FontWindow(font) except Exception as e: msg = self.tr("There was an issue opening the font at {}.".format(path)) errorReports.showCriticalException(e, msg) return window.show() self.setCurrentFile(font.path)
def _loadBinary(self, path): for widget in self.topLevelWidgets(): if isinstance(widget, FontWindow): font = widget.font_() if font is not None and font.binaryPath == path: widget.raise_() return font = TFont() try: font.extract(path) except Exception as e: errorReports.showCriticalException(e) return window = FontWindow(font) window.show() self.setCurrentFile(font.binaryPath)
def openFile(self, path): if ".plist" in path: path = os.path.dirname(path) path = os.path.normpath(path) for window in self.topLevelWidgets(): if isinstance(window, FontWindow): font = window.font_() if font is not None and font.path == path: window.raise_() return try: font = TFont(path) window = FontWindow(font) except Exception as e: errorReports.showCriticalException(e) return window.show()
def newFile(self): font = TFont.newStandardFont() window = FontWindow(font) window.show()
def newFile(self): font = TFont.new() window = FontWindow(font) window.show()
class TabTestCase(unittest.TestCase): app = Application(sys.argv) def __init__(self, methodName): unittest.TestCase.__init__(self, methodName) def setUp(self): self.font = TFont.new() self.mainWindow = FontWindow(self.font) self.mainWindow.fontInfo() self.fontInfo = self.mainWindow._infoWindow self.generalTab = self.fontInfo.tabWidget.widget(0) self.legalTab = self.fontInfo.tabWidget.widget(1) self.openTypeTab = self.fontInfo.tabWidget.widget(2) self.postScriptTab = self.fontInfo.tabWidget.widget(3) self.fontInfo.show() def tearDown(self): self.fontInfo.close() def checkString(self, attrName): attrEdit = getattr(self.tab, attrName + "Edit") attrEdit.setEnabled(True) self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.text(), "") attrEdit.setText("Typeface " + attrName) self.fontInfo.accept() self.assertEqual(getattr(self.font.info, attrName), "Typeface " + attrName) attrEdit.setEnabled(False) self.fontInfo.accept() self.assertIsNone(getattr(self.font.info, attrName)) def checkMultilineString(self, attrName): attrEdit = getattr(self.tab, attrName + "Edit") attrEdit.setEnabled(True) self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.toPlainText(), "") attrEdit.setPlainText("Typeface \n" + attrName) self.fontInfo.accept() self.assertEqual(getattr(self.font.info, attrName), "Typeface \n" + attrName) attrEdit.setEnabled(False) self.fontInfo.accept() self.assertIsNone(getattr(self.font.info, attrName)) def checkInteger(self, attrName, value=0): attrEdit = getattr(self.tab, attrName + "Edit") attrEdit.setEnabled(True) if value == 0: self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.value(), 0) else: self.assertIsNotNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.value(), value) attrEdit.setValue(123) self.fontInfo.accept() self.assertEqual(getattr(self.font.info, attrName), 123) attrEdit.setValue(0) self.fontInfo.accept() self.assertEqual(getattr(self.font.info, attrName), 0) attrEdit.setValue(-123) self.fontInfo.accept() self.assertEqual(getattr(self.font.info, attrName), -123) attrEdit.setEnabled(False) self.fontInfo.accept() self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.minimum(), -2147483648) self.assertEqual(attrEdit.maximum(), 2147483647) def checkPositiveInteger(self, attrName, value=0): attrEdit = getattr(self.tab, attrName + "Edit") attrEdit.setEnabled(True) if value == 0: self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.value(), 0) else: self.assertIsNotNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.value(), value) attrEdit.setValue(123) self.fontInfo.accept() self.assertEqual(getattr(self.font.info, attrName), 123) attrEdit.setValue(0) self.fontInfo.accept() self.assertEqual(getattr(self.font.info, attrName), 0) attrEdit.setEnabled(False) self.fontInfo.accept() self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.minimum(), 0) self.assertEqual(attrEdit.maximum(), 2147483647) def checkIntegerFloat(self, attrName, value=0): attrEdit = getattr(self.tab, attrName + "Edit") attrEdit.setEnabled(True) if value == 0: self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.value(), 0) else: self.assertIsNotNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.value(), value) attrEdit.setValue(123) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, 123) attrEdit.setValue(123.000) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, 123) attrEdit.setValue(123.456) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, float)) self.assertEqual(attr, 123.456) attrEdit.setValue(0) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, 0) attrEdit.setValue(0.0) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, 0) attrEdit.setValue(-123) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, -123) attrEdit.setValue(-123.000) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, -123) attrEdit.setValue(-123.456) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, float)) self.assertEqual(attr, -123.456) attrEdit.setEnabled(False) self.fontInfo.accept() self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.minimum(), -2147483648) self.assertEqual(attrEdit.maximum(), 2147483647) def checkPositiveIntegerFloat(self, attrName, value=0): attrEdit = getattr(self.tab, attrName + "Edit") attrEdit.setEnabled(True) if value == 0: self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.value(), 0) else: self.assertIsNotNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.value(), value) attrEdit.setValue(123) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, 123) attrEdit.setValue(123.000) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, 123) attrEdit.setValue(123.456) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, float)) self.assertEqual(attr, 123.456) attrEdit.setValue(0) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, 0) attrEdit.setValue(0.0) self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertTrue(isinstance(attr, int)) self.assertEqual(attr, 0) attrEdit.setEnabled(False) self.fontInfo.accept() self.assertIsNone(getattr(self.font.info, attrName)) self.assertEqual(attrEdit.minimum(), 0) self.assertEqual(attrEdit.maximum(), 2147483647) # XXX: Implement maxLen, evenLen? def checkIntegerFloatList(self, attrName, maxLen=None, evenLen=None): attrEdit = getattr(self.tab, attrName + "Edit") attrEdit.setEnabled(True) attrEdit.setText("") self.fontInfo.accept() self.assertEqual(getattr(self.font.info, attrName), []) attrEdit.setText("123 456 789 0") self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertEqual(attr, [123, 456, 789, 0]) attrEdit.setText("123,0 456,1 789.11111112 789,11111113 790 791") self.fontInfo.accept() attr = getattr(self.font.info, attrName) self.assertEqual(attr, [123, 456.1, 789.11111112, 789.11111113, 790, 791]) attrEdit.setEnabled(False) self.fontInfo.accept() attr = getattr(self.font.info, attrName) # These are apparently always [], never None. if attrName in ["postscriptBlueValues", "postscriptOtherBlues", "postscriptFamilyBlues", "postscriptFamilyOtherBlues", "postscriptStemSnapH", "postscriptStemSnapV"]: self.assertEqual(attr, []) else: self.assertIsNone(attr) def checkBoolean(self, attrName): attrEdit = getattr(self.tab, attrName + "Edit") attrEdit.setEnabled(True) # Most checkboxes are governed by a parent checkbox for the field (see # Postscript tab for examples), meaning that if the field is unchecked, # it is assumed that the user doesn't want to set an explicit value. If # the field is checked, the actual checkbox can be either checked or # not. self.assertFalse(attrEdit.isTristate()) attrEdit.setCheckState(Qt.Checked) self.fontInfo.accept() value = attrEdit.checkState() self.assertEqual(value, Qt.Checked) self.assertEqual(getattr(self.font.info, attrName), True) attrEdit.setCheckState(Qt.Unchecked) self.fontInfo.accept() value = attrEdit.checkState() self.assertEqual(value, Qt.Unchecked) self.assertEqual(getattr(self.font.info, attrName), False) attrEdit.setEnabled(False) self.fontInfo.accept() self.assertIsNone(getattr(self.font.info, attrName))