diff options
| author | Adrien Tétar | 2015-10-17 13:16:24 +0200 |
|---|---|---|
| committer | Adrien Tétar | 2015-10-17 13:19:43 +0200 |
| commit | 816748b6d6b14b8b9f80fc904dc2654fd3e0f7c1 (patch) | |
| tree | 534aaf2468d2e712e9dc1a9a1637787818c6a9d5 /Lib/defconQt/layerSetList.py | |
| parent | 7cc2a144bdbb73b81ffcd4b8ac7fef8b94ee82b6 (diff) | |
| download | trufont-816748b6d6b14b8b9f80fc904dc2654fd3e0f7c1.tar.bz2 | |
glyphView: add startPoints support, consolidate notifications
Diffstat (limited to 'Lib/defconQt/layerSetList.py')
| -rw-r--r-- | Lib/defconQt/layerSetList.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/Lib/defconQt/layerSetList.py b/Lib/defconQt/layerSetList.py index b2d3c9f..485477b 100644 --- a/Lib/defconQt/layerSetList.py +++ b/Lib/defconQt/layerSetList.py @@ -1,15 +1,16 @@ from PyQt5.QtCore import Qt from PyQt5.QtGui import QKeySequence, QColor, QPixmap, QIcon -from PyQt5.QtWidgets import QWidget, QMenu, QListWidget, QListWidgetItem, \ - QAbstractItemView, QVBoxLayout, QAction, QColorDialog +from PyQt5.QtWidgets import (QApplication, QWidget, QMenu, QListWidget, + QListWidgetItem, QAbstractItemView, QVBoxLayout, QAction, QColorDialog) from defconQt import icons_db from defconQt.glyphView import AddLayerDialog class LayerSetList(QListWidget): - def __init__(self, font, parent=None, *args, **kwds): - super().__init__(parent, *args, **kwds) + def __init__(self, parent=None, *args, **kwargs): + super().__init__(parent, *args, **kwargs) - self._layerSet = font.layers + app = QApplication.instance() + self._layerSet = app.currentFont().layers self.setDragDropMode(QAbstractItemView.InternalMove) @@ -45,13 +46,13 @@ class LayerSetList(QListWidget): self.addAction(action) self._layerSet.addObserver(self, '_update', 'LayerSet.Changed') - self._update() + app.currentFontChanged.connect(self.updateFont) + def _update(self, *args): index = self.currentRow() - while self.count(): - self.takeItem(self.count()-1) + self.clear() for i, layer in enumerate(self._layerSet): item = self._makeItem(layer) self.addItem(item) @@ -133,3 +134,11 @@ class LayerSetList(QListWidget): if not layer: return layer.color = None + + def updateFont(self): + if self._layerSet is not None: + self._layerSet.removeObserver(self, 'LayerSet.Changed') + currentFont = QApplication.instance().currentFont() + self._layerSet = currentFont.layers + self._layerSet.addObserver(self, '_update', 'LayerSet.Changed') + self._update() |
