aboutsummaryrefslogtreecommitdiffstats
path: root/Lib/defconQt/fontView.py
diff options
context:
space:
mode:
authorAdrien Tétar2015-10-31 17:01:25 +0100
committerAdrien Tétar2015-10-31 17:01:25 +0100
commit44e6a231125c4103d8dc8edbb200ce2f327f1e31 (patch)
treeb3050fbb8509ef54643f4567c0e9a9a6bec9edee /Lib/defconQt/fontView.py
parent16c2f16dcdb17c997f2153a89a423c4e1ca86f79 (diff)
parent6f131223c6821651dbd97c0c6aaff8aa1e6b90b2 (diff)
downloadtrufont-44e6a231125c4103d8dc8edbb200ce2f327f1e31.tar.bz2
Merge pull request #104 from trufont/patch-11
Minor improvements throughout
Diffstat (limited to 'Lib/defconQt/fontView.py')
-rw-r--r--Lib/defconQt/fontView.py53
1 files changed, 34 insertions, 19 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)