diff options
| author | Felipe Corrêa da Silva Sanches | 2015-09-30 19:46:21 -0300 |
|---|---|---|
| committer | Felipe Corrêa da Silva Sanches | 2015-09-30 19:50:20 -0300 |
| commit | 6b32627ff16720adfe32c5eed8223a24a383ad8d (patch) | |
| tree | 03ec03122decd6eb404c109983b6c8643aa73c9b /Lib/defconQt/glyphView.py | |
| parent | 738ea6d84855553061a6ddedda453c037330ca04 (diff) | |
| download | trufont-6b32627ff16720adfe32c5eed8223a24a383ad8d.tar.bz2 | |
GUI for adding anchors (with the cursor hovering the target position, select "context menu"->"add anchor" and provide an anchor name on the "New Anchor Point..." dialog)
Diffstat (limited to 'Lib/defconQt/glyphView.py')
| -rw-r--r-- | Lib/defconQt/glyphView.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py index 1ab9c10..8e41a49 100644 --- a/Lib/defconQt/glyphView.py +++ b/Lib/defconQt/glyphView.py @@ -1,6 +1,7 @@ from enum import Enum from math import copysign import pickle +from defcon import Anchor from defconQt.objects.defcon import TContour, TGlyph from defconQt.pens.copySelectionPen import CopySelectionPen from fontTools.misc import bezierTools @@ -172,6 +173,11 @@ class MainGfxWindow(QMainWindow): self.setWindowTitle(glyph.name, glyph.getParent()) self.adjustSize() + self.setContextMenuPolicy(Qt.ActionsContextMenu) + createAnchorAction = QAction("Add Anchor Point", self) + createAnchorAction.triggered.connect(lambda: self.view.createAnchor(self.view.scene().cursorX , self.view.scene().cursorY)) + self.addAction(createAnchorAction) + def close(self): self.view._glyph.removeObserver(self, "Glyph.Changed") super(MainGfxWindow, self).close() @@ -956,6 +962,8 @@ class GlyphScene(QGraphicsScene): if forceSelect: item.setSelected(True) def mouseMoveEvent(self, event): + self.cursorX = event.scenePos().x() + self.cursorY = event.scenePos().y() if self._editing is True: sel = self.selectedItems() if len(sel) == 1: @@ -1247,6 +1255,49 @@ class GlyphScene(QGraphicsScene): self._cachedIntersections = [] event.accept() +class AddAnchorDialog(QDialog): + def __init__(self, parent=None): + super(AddAnchorDialog, self).__init__(parent) + self.setWindowModality(Qt.WindowModal) + self.setWindowTitle("Add anchor point…") + + layout = QGridLayout(self) +# self.anchorClassesDrop = QComboBox(self) +# self.anchorClassesDrop.addItem("Anchor-point classes…") +# classNames = ["TODO", "iterate", "from", "list of previously", "used", "anchor point names"] +# for className in classNames: +# self.anchorClassesDrop.addItem(className, className) +# self.anchorClassesDrop.currentIndexChanged[int].connect(self.selectAnchorClass) + + self.anchorNameEdit = QLineEdit(self) + self.anchorNameEdit.setFocus(True) + + buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + buttonBox.accepted.connect(self.accept) + buttonBox.rejected.connect(self.reject) + + l = 0 +# layout.addWidget(self.anchorClassesDrop, l, 3) +# l += 1 + layout.addWidget(self.anchorNameEdit, l, 0, 1, 4) + l += 1 + layout.addWidget(buttonBox, l, 3) + self.setLayout(layout) + +# def selectAnchorClass(self, index): +# print ("index: %d" % index) +# if index == 0: return +# className = self.anchorClassesDrop.itemData(index) +# print ("className: %s" % className) +# self.anchorNameEdit.setText(className) + + @staticmethod + def getNewAnchorData(): + dialog = AddAnchorDialog() + result = dialog.exec_() + name = dialog.anchorNameEdit.text().strip() + return (name, result) + class GlyphView(QGraphicsView): Native, OpenGL, Image = range(3) @@ -1402,6 +1453,15 @@ class GlyphView(QGraphicsView): item.setZValue(-996) scene.addItem(item) + def createAnchor(self, x, y): + newAnchorName, ok = AddAnchorDialog.getNewAnchorData() + if ok: + anchor = Anchor() + anchor.x = x + anchor.y = y + anchor.name = newAnchorName + self._glyph.appendAnchor(anchor) + def addAnchors(self): scene = self.scene() for anchor in self._glyph.anchors: |
