diff options
| author | Adrien Tétar | 2015-10-31 17:01:25 +0100 | 
|---|---|---|
| committer | Adrien Tétar | 2015-10-31 17:01:25 +0100 | 
| commit | 44e6a231125c4103d8dc8edbb200ce2f327f1e31 (patch) | |
| tree | b3050fbb8509ef54643f4567c0e9a9a6bec9edee | |
| parent | 16c2f16dcdb17c997f2153a89a423c4e1ca86f79 (diff) | |
| parent | 6f131223c6821651dbd97c0c6aaff8aa1e6b90b2 (diff) | |
| download | trufont-44e6a231125c4103d8dc8edbb200ce2f327f1e31.tar.bz2 | |
Merge pull request #104 from trufont/patch-11
Minor improvements throughout
| -rw-r--r-- | Lib/defconQt/fontView.py | 53 | ||||
| -rw-r--r-- | Lib/defconQt/glyphView.py | 22 | ||||
| -rw-r--r-- | Lib/defconQt/objects/defcon.py | 8 | 
3 files changed, 53 insertions, 30 deletions
| diff --git a/Lib/defconQt/fontView.py b/Lib/defconQt/fontView.py index c33f8c3..198e8d9 100644 --- a/Lib/defconQt/fontView.py +++ b/Lib/defconQt/fontView.py @@ -938,14 +938,17 @@ class MainWindow(QMainWindow):      def _set_font(self, font):          if self._font is not None:              self._font.removeObserver(self, "Font.Changed") +            self._font.removeObserver(self, "Font.GlyphOrderChanged")          self._font = font          self._font.addObserver(self, "_fontChanged", "Font.Changed") -        if "public.glyphOrder" in self._font.lib: -            self.sortDescriptor = GlyphSet( -                self._font.lib["public.glyphOrder"]) -        else: +        self._font.addObserver( +            self, "_glyphOrderChanged", "Font.GlyphOrderChanged") +        if self._font.glyphOrder is None:              # TODO: cannedDesign or carry sortDescriptor from previous font?              self.sortDescriptor = cannedDesign +        else: +            # use the glyphOrder from the font +            self.sortDescriptor = None      font = property(_get_font, _set_font, doc="The fontView font. Subscribes \          to the new font, updates the sorting order and cells widget when set.") @@ -954,21 +957,13 @@ class MainWindow(QMainWindow):          return self._sortDescriptor      def _set_sortDescriptor(self, desc): -        if isinstance(desc, GlyphSet): -            glyphs = [] -            for glyphName in desc.glyphNames: -                if glyphName in self._font: -                    glyphs.append(self._font[glyphName]) -            if len(glyphs) < len(self._font): -                # if some glyphs in the font are not present in the glyph -                # order, loop again to add them at the end -                for glyph in self._font: -                    if glyph not in glyphs: -                        glyphs.append(glyph) +        if desc is None: +            self.updateGlyphsFromFont() +        elif isinstance(desc, GlyphSet): +            self._font.glyphOrder = desc.glyphNames          else: -            glyphs = [self._font[k] for k in self._font.unicodeData -                      .sortGlyphNames(self._font.keys(), desc)] -        self.collectionWidget.glyphs = glyphs +            self._font.glyphOrder = self._font.unicodeData.sortGlyphNames( +                self._font.keys(), desc)          self._sortDescriptor = desc      sortDescriptor = property(_get_sortDescriptor, _set_sortDescriptor, @@ -1040,7 +1035,27 @@ class MainWindow(QMainWindow):      def _fontChanged(self, notification):          self.collectionWidget.update() -        self.setWindowModified(True) +        self.setWindowModified(self._font.dirty) + +    def _glyphOrderChanged(self, notification): +        self.updateGlyphsFromFont() + +    def updateGlyphsFromFont(self): +        glyphOrder = self._font.glyphOrder +        if len(glyphOrder): +            glyphs = [] +            for glyphName in glyphOrder: +                if glyphName in self._font: +                    glyphs.append(self._font[glyphName]) +            if len(glyphs) < len(self._font): +                # if some glyphs in the font are not present in the glyph +                # order, loop again to add them at the end +                for glyph in self._font: +                    if glyph not in glyphs: +                        glyphs.append(glyph) +        else: +            glyphs = self._font[:] +        self.collectionWidget.glyphs = glyphs      def _glyphOpened(self, glyph):          glyphViewWindow = MainGfxWindow(glyph, self) diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py index cca153e..fb39e1c 100644 --- a/Lib/defconQt/glyphView.py +++ b/Lib/defconQt/glyphView.py @@ -116,7 +116,10 @@ class AddAnchorDialog(QDialog):      def __init__(self, pos=None, parent=None):          super(AddAnchorDialog, self).__init__(parent)          self.setWindowModality(Qt.WindowModal) -        self.setWindowTitle("Add anchor…") +        if pos is not None: +            self.setWindowTitle("Add anchor…") +        else: +            self.setWindowTitle("Rename anchor…")          layout = QGridLayout(self) @@ -136,8 +139,9 @@ class AddAnchorDialog(QDialog):          l = 0          layout.addWidget(anchorNameLabel, l, 0)          layout.addWidget(self.anchorNameEdit, l, 1, 1, 3) -        l += 1 -        layout.addWidget(anchorPositionLabel, l, 0, 1, 4) +        if pos is not None: +            l += 1 +            layout.addWidget(anchorPositionLabel, l, 0, 1, 4)          l += 1          layout.addWidget(buttonBox, l, 3)          self.setLayout(layout) @@ -363,7 +367,7 @@ class MainGfxWindow(QMainWindow):          oldView = self.view          # Preserve the selected layer (by setting the glyph from that layer)          # Todo: If that layer is already in the glyph, it would be a little bit -        # harder to create it here and may be better or worse. Worse becaue +        # harder to create it here and may be better or worse. Worse because          # we'd alter the data without being explicitly asked to do so.          # Ask someone who does UX.          if oldView: @@ -379,6 +383,7 @@ class MainGfxWindow(QMainWindow):          # GlyphView? If yes, we should make an interface for a          # predecessor -> successor transformation          if oldView: +            self.view._currentTool = oldView._currentTool              self.view.setTransform(oldView.transform())          self._setlayerColorButtonColor() @@ -1017,6 +1022,12 @@ class AnchorItem(QGraphicsPathItem):              scene._blocked = False          return value +    def mouseDoubleClickEvent(self, event): +        view = self.scene().views()[0] +        newAnchorName, ok = AddAnchorDialog.getNewAnchorName(view) +        if ok: +            self._anchor.name = newAnchorName +      def setPointPath(self, scale=None):          path = QPainterPath()          if scale is None: @@ -2300,8 +2311,7 @@ class GlyphView(QGraphicsView):      def _makeLayerGlyph(self, layer):          name = self._name -        layer.newGlyph(name) -        glyph = layer[name] +        glyph = layer.newGlyph(name)          # TODO: generalize this out, can’t use newStandardGlyph unfortunately          glyph.width = self.defaultWidth diff --git a/Lib/defconQt/objects/defcon.py b/Lib/defconQt/objects/defcon.py index 24f585f..496f1c6 100644 --- a/Lib/defconQt/objects/defcon.py +++ b/Lib/defconQt/objects/defcon.py @@ -19,9 +19,7 @@ class TFont(Font):          if not override:              if name in self:                  return None -        # XXX(defcon): newGlyph should return the glyph -        self.newGlyph(name) -        glyph = self[name] +        glyph = self.newGlyph(name)          glyph.width = width          # TODO: list ought to be changeable from AGL2UV          if addUnicode: @@ -117,8 +115,8 @@ class TPoint(Point):  class GlyphSet(object):      __slots__ = ["_name", "_glyphNames"] -    def __init__(self, glyphNames, name=None): -        self._name = name +    def __init__(self, glyphNames, name): +        self._name = str(name)          self._glyphNames = glyphNames      def _get_name(self): | 
