aboutsummaryrefslogtreecommitdiffstats
path: root/Lib/defconQt
diff options
context:
space:
mode:
authorAdrien Tétar2015-05-29 00:09:44 +0200
committerAdrien Tétar2015-05-29 00:09:44 +0200
commitb588ee3ca0dc77c37b7cc180ba1bdab04bd7de4e (patch)
tree583cdab1fadacb8a865d7816bb07c23fed4bb4c0 /Lib/defconQt
parent82a6fe3e119bbc52f76da41c4e430f59ee240d11 (diff)
downloadtrufont-b588ee3ca0dc77c37b7cc180ba1bdab04bd7de4e.tar.bz2
Twix
Diffstat (limited to 'Lib/defconQt')
-rw-r--r--Lib/defconQt/featureTextEditor.py72
-rw-r--r--Lib/defconQt/fontView.py21
-rw-r--r--Lib/defconQt/fontinfo.py12
-rw-r--r--Lib/defconQt/glyphView.py2
-rw-r--r--Lib/defconQt/groupsView.py33
5 files changed, 116 insertions, 24 deletions
diff --git a/Lib/defconQt/featureTextEditor.py b/Lib/defconQt/featureTextEditor.py
index 698bfdd..2c47adb 100644
--- a/Lib/defconQt/featureTextEditor.py
+++ b/Lib/defconQt/featureTextEditor.py
@@ -19,15 +19,36 @@ class MainEditWindow(QMainWindow):
if font is not None: puts = "%s%s%s%s%s" % (title, " – ", self.font.info.familyName, " ", self.font.info.styleName)
else: puts = title
super(MainEditWindow, self).setWindowTitle(puts)
+
+ def closeEvent(self, event):
+ if self.editor.document().isModified():
+ closeDialog = QMessageBox(QMessageBox.Question, "Me", "Save your changes?",
+ QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel, self)
+ closeDialog.setInformativeText("Your changes will be lost if you don’t save them.")
+ closeDialog.setModal(True)
+ ret = closeDialog.exec_()
+ if ret == QMessageBox.Save:
+ self.save()
+ event.accept()
+ elif ret == QMessageBox.Discard:
+ event.accept()
+ else:
+ event.ignore()
+
+ def reload(self):
+ self.font.reloadFeatures()
+ self.editor.setPlainText(self.font.features.text)
def save(self):
- self.editor.write(self.features)
+ self.editor.write(self.font.features.text)
def setupFileMenu(self):
fileMenu = QMenu("&File", self)
self.menuBar().addMenu(fileMenu)
fileMenu.addAction("&Save...", self.save, QKeySequence.Save)
+ fileMenu.addSeparator()
+ fileMenu.addAction("Reload from UFO", self.reload)
fileMenu.addAction("E&xit", self.close, QKeySequence.Quit)
class LineNumberArea(QWidget):
@@ -120,26 +141,43 @@ class TextEditor(QPlainTextEdit):
super(TextEditor, self).resizeEvent(event)
cr = self.contentsRect()
self.lineNumbers.setGeometry(cr.left(), cr.top(), self.lineNumberAreaWidth(), cr.height())
+
+ def findLineIndentLevel(self, cursor):
+ indent = 0
+ cursor.select(QTextCursor.LineUnderCursor)
+ lineLength = len(cursor.selectedText()) // len(self._indent)
+ cursor.movePosition(QTextCursor.StartOfLine)
+ while (lineLength > 0):
+ cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor, len(self._indent))
+ if cursor.selectedText() == self._indent:
+ indent += 1
+ cursor.movePosition(QTextCursor.NoMove)
+ lineLength -= 1
+ cursor.movePosition(QTextCursor.EndOfLine)
+ return indent
def keyPressEvent(self, event):
if event.key() == Qt.Key_Return:
cursor = self.textCursor()
- indentLvl = 0
+ indentLvl = self.findLineIndentLevel(cursor)
newBlock = False
+
cursor.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor)
if cursor.selectedText() == '{':
- indentLvl += 1
- # We don't add a closing tag if there is text right below because
- # in that case the user might just be looking to add a new line
+ # We don't add a closing tag if there is text right below with the same
+ # indentation level because in that case the user might just be looking
+ # to add a new line
ok = cursor.movePosition(QTextCursor.Down)
if ok:
+ downIndentLvl = self.findLineIndentLevel(cursor)
cursor.select(QTextCursor.LineUnderCursor)
- if cursor.selectedText().strip() == '':
+ if cursor.selectedText().strip() == '' or downIndentLvl <= indentLvl:
newBlock = True
cursor.movePosition(QTextCursor.Up)
else: newBlock = True
+ indentLvl += 1
+
cursor.select(QTextCursor.LineUnderCursor)
- lineLength = len(cursor.selectedText()) // len(self._indent)
if newBlock:
txt = cursor.selectedText().lstrip(" ").split(" ")
if len(txt) > 1:
@@ -149,15 +187,8 @@ class TextEditor(QPlainTextEdit):
feature = txt[1]
else:
feature = None
-
- cursor.movePosition(QTextCursor.StartOfLine)
- while (lineLength > 0):
- cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor, len(self._indent))
- if cursor.selectedText() == self._indent:
- indentLvl += 1
- cursor.movePosition(QTextCursor.NoMove)
- lineLength -= 1
cursor.movePosition(QTextCursor.EndOfLine)
+
super(TextEditor, self).keyPressEvent(event)
newLineSpace = "".join((self._indent for _ in range(indentLvl)))
cursor.insertText(newLineSpace)
@@ -168,6 +199,17 @@ class TextEditor(QPlainTextEdit):
cursor.movePosition(QTextCursor.Up)
cursor.movePosition(QTextCursor.EndOfLine)
self.setTextCursor(cursor)
+ elif event.key() == Qt.Key_Tab:
+ cursor = self.textCursor()
+ cursor.insertText(self._indent)
+ elif event.key() == Qt.Key_Backspace:
+ cursor = self.textCursor()
+ cursor.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor,
+ len(self._indent))
+ if cursor.selectedText() == self._indent:
+ cursor.removeSelectedText()
+ else:
+ super(TextEditor, self).keyPressEvent(event)
else:
super(TextEditor, self).keyPressEvent(event)
diff --git a/Lib/defconQt/fontView.py b/Lib/defconQt/fontView.py
index 3b0242f..408d1a1 100644
--- a/Lib/defconQt/fontView.py
+++ b/Lib/defconQt/fontView.py
@@ -51,12 +51,12 @@ class CharacterWidget(QWidget):
def updateFont(self, font):
self.font = font
- self.glyphs = [font[k] for k in font.unicodeData.sortGlyphNames(font.keys(), glyphSortDescriptors)]
+ self.glyphs = [font[k] for k in font.unicodeData.sortGlyphNames(font.keys(), cannedDesign)]
self.adjustSize()
self.update()
def updateGlyphs(self):
- self.glyphs = [self.font[k] for k in self.font.unicodeData.sortGlyphNames(self.font.keys(), glyphSortDescriptors)]
+ self.glyphs = [self.font[k] for k in self.font.unicodeData.sortGlyphNames(self.font.keys(), cannedDesign)]
self.adjustSize()
self.update()
@@ -307,6 +307,7 @@ class MainWindow(QMainWindow):
fontMenu.addAction("&Add glyph", self.addGlyph, "Ctrl+U")
fontMenu.addSeparator()
fontMenu.addAction("&Space center", self.spaceCenter, "Ctrl+Y")
+ fontMenu.addAction("&Groups window", self.fontGroups, "Ctrl+G")
helpMenu = QMenu("&Help", self)
self.menuBar().addMenu(helpMenu)
@@ -374,7 +375,11 @@ class MainWindow(QMainWindow):
def closeEvent(self, event):
if self.font.dirty:
title = "Me"
- body = "%s%s%s" % ("Do you want to save the changes you made to “", os.path.basename(self.font.path.rstrip(os.sep)), "”?")
+ if self.font.path is not None:
+ currentFont = os.path.basename(self.font.path.rstrip(os.sep))
+ else:
+ currentFont = "Untitled.ufo"
+ body = "%s%s%s" % ("Do you want to save the changes you made to “", currentFont, "”?")
closeDialog = QMessageBox(QMessageBox.Question, title, body,
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel, self)
closeDialog.setInformativeText("Your changes will be lost if you don’t save them.")
@@ -452,11 +457,21 @@ class MainWindow(QMainWindow):
glyphs.append(self.characterWidget.glyphs[item])
self.spaceCenterWindow.setGlyphs(glyphs)
+ def fontGroups(self):
+ # TODO: see up here
+ from groupsView import GroupsWindow
+ if not (hasattr(self, 'fontGroupsWindow') and self.fontGroupsWindow.isVisible()):
+ self.fontGroupsWindow = GroupsWindow(self.font, self)
+ self.fontGroupsWindow.show()
+ else:
+ self.fontGroupsWindow.raise_()
+
def addGlyph(self):
gName, ok = QInputDialog.getText(self, "Add glyph", "Name of the glyph:")
# Not overwriting existing glyphs. Should it warn in this case? (rf)
if ok and gName != '':
self.font.newGlyph(gName)
+ self.font[gName].width = 500
self.characterWidget.updateGlyphs()
def about(self):
diff --git a/Lib/defconQt/fontinfo.py b/Lib/defconQt/fontinfo.py
index 492f92f..8adb94e 100644
--- a/Lib/defconQt/fontinfo.py
+++ b/Lib/defconQt/fontinfo.py
@@ -10,13 +10,15 @@ class TabDialog(QDialog):
# TODO: figure a proper correspondence to set and fetch widgets...
self.tabs = {
"General": 0,
- "Metrics": 1
+ "Metrics": 1,
+ "OpenType": 2
}
self.font = font
self.tabWidget = QTabWidget()
self.tabWidget.addTab(GeneralTab(self.font), "General")
- self.tabWidget.addTab(NextTab(self.font), "Metrics")
+ self.tabWidget.addTab(MetricsTab(self.font), "Metrics")
+# self.tabWidget.addTab(ApplicationsTab(fileInfo), "OpenType")
# self.tabWidget.addTab(ApplicationsTab(fileInfo), "PostScript")
# self.tabWidget.addTab(ApplicationsTab(fileInfo), "Miscellaneous")
@@ -158,9 +160,9 @@ class GeneralTab(QWidget):
font.info.openTypeNameLicenseURL = self.licenseURLEdit.text()
font.info.trademark = self.trademarkEdit.text()
-class NextTab(QWidget):
+class MetricsTab(QWidget):
def __init__(self, font, parent=None):
- super(NextTab, self).__init__(parent)
+ super(MetricsTab, self).__init__(parent)
mainLayout = QGridLayout()
styleMapFamilyLabel = QLabel("Style map family name:", self)
@@ -258,4 +260,4 @@ class NextTab(QWidget):
capHeight = self.capHeightEdit.text()
font.info.capHeight = int(capHeight) if capHeight else None
italicAngle = self.italicAngleEdit.text()
- font.info.italicAngle = float(italicAngle) if italicAngle else None \ No newline at end of file
+ font.info.italicAngle = float(italicAngle) if italicAngle else None
diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py
index a4ce3bf..d20753d 100644
--- a/Lib/defconQt/glyphView.py
+++ b/Lib/defconQt/glyphView.py
@@ -408,7 +408,7 @@ class GlyphView(QGraphicsView):
#self.fitInView(0, self._font.info.descender, self._glyph.width, self._font.info.unitsPerEm, Qt.KeepAspectRatio)
#sc = self.height()/self.scene().height()
#self.scale(sc, sc);
- self.scene().setSceneRect(-1500, -1500, 3000, 3000)
+ self.scene().setSceneRect(-1000, -1000, 3000, 3000)
def _glyphChanged(self, event):
pass
diff --git a/Lib/defconQt/groupsView.py b/Lib/defconQt/groupsView.py
new file mode 100644
index 0000000..96d9c86
--- /dev/null
+++ b/Lib/defconQt/groupsView.py
@@ -0,0 +1,33 @@
+from PyQt5.QtCore import *
+from PyQt5.QtGui import *
+from PyQt5.QtWidgets import *
+
+class GroupsWindow(QWidget):
+ def __init__(self, font, parent=None):
+ super(GroupsWindow, self).__init__(parent, Qt.Window)
+ self.font = font
+ self.groups = sorted(font.groups.keys(), key=lambda t: t[0])
+
+ self.groupsList = QListWidget(self)
+ #self.groupsList.addItems(self.font.groups.keys())
+ #self.groupsList.setEditTriggers(QAbstractItemView.DoubleClicked | QAbstractItemView.EditKeyPressed)
+ for groupName in self.font.groups.keys():
+ item = QListWidgetItem(groupName, self.groupsList)
+ #item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable)
+ item.setFlags(item.flags() | Qt.ItemIsEditable)
+ self.groupsList.itemChanged.connect(self._groupRenamed)
+
+ layout = QVBoxLayout(self)
+ layout.addWidget(self.groupsList)
+ self.setLayout(layout)
+
+ self.setWindowTitle("%s%s%s%s" % ("Groups window – ", self.font.info.familyName, " ", self.font.info.styleName))
+
+ def _groupRenamed(self):
+ cur = self.groupsList.currentItem()
+ # XXX: perf?
+ index = self.groupsList.indexFromItem(cur)
+ newKey = cur.text()
+ self.font.groups[newKey] = self.font.groups.pop(self.groups[index])
+ self.groups[index] = newKey
+ #print(self.groupsList.currentItem().text()) \ No newline at end of file