diff options
| author | Adrien Tétar | 2015-10-03 21:34:13 +0200 |
|---|---|---|
| committer | Adrien Tétar | 2015-10-03 21:34:13 +0200 |
| commit | c898a4d61fbaf10d9f8a989b58c028ad3a271157 (patch) | |
| tree | 1b83b1d94bc8a1db9845f2be125c2827116068f0 | |
| parent | c9b4454c3296c8096873fef371221ba5ac8972d7 (diff) | |
| download | trufont-c898a4d61fbaf10d9f8a989b58c028ad3a271157.tar.bz2 | |
fontView,…: some refactorings and nits
| -rw-r--r-- | Lib/defconQt/fontView.py | 11 | ||||
| -rw-r--r-- | Lib/defconQt/glyphView.py | 6 | ||||
| -rw-r--r-- | Lib/defconQt/groupsView.py | 20 |
3 files changed, 28 insertions, 9 deletions
diff --git a/Lib/defconQt/fontView.py b/Lib/defconQt/fontView.py index ef9b812..0ec8910 100644 --- a/Lib/defconQt/fontView.py +++ b/Lib/defconQt/fontView.py @@ -385,14 +385,13 @@ class MainWindow(QMainWindow): self.setWindowTitle() #return ok - def close(self): - self.font.removeObserver(self, "Font.Changed") - QApplication.instance().quit() - def closeEvent(self, event): ok = self.maybeSaveBeforeExit() - if not ok: event.ignore() - else: event.accept() + if ok: + self.font.removeObserver(self, "Font.Changed") + event.accept() + else: + event.ignore() def maybeSaveBeforeExit(self): if self.font.dirty: diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py index e33ca99..fe340d1 100644 --- a/Lib/defconQt/glyphView.py +++ b/Lib/defconQt/glyphView.py @@ -208,13 +208,13 @@ class MainGfxWindow(QMainWindow): self.adjustSize() self.setContextMenuPolicy(Qt.ActionsContextMenu) - createAnchorAction = QAction("Add Anchor Point", self) + createAnchorAction = QAction("Add Anchor…", self) createAnchorAction.triggered.connect(self.view.createAnchor) self.addAction(createAnchorAction) - def close(self): + def closeEvent(self, event): self.view._glyph.removeObserver(self, "Glyph.Changed") - super(MainGfxWindow, self).close() + event.accept() def _glyphChanged(self, notification): self.view._glyphChanged(notification) diff --git a/Lib/defconQt/groupsView.py b/Lib/defconQt/groupsView.py index e6ee932..90820be 100644 --- a/Lib/defconQt/groupsView.py +++ b/Lib/defconQt/groupsView.py @@ -10,6 +10,9 @@ class GroupListWidget(QListWidget): self.setSelectionMode(QAbstractItemView.SingleSelection) self.setSortingEnabled(True) + self.fillGroupNames(groupNames) + + def fillGroupNames(self, groupNames): for groupName in groupNames: item = QListWidgetItem(groupName, self) item.setFlags(item.flags() | Qt.ItemIsEditable) @@ -112,6 +115,7 @@ class GroupsWindow(QWidget): def __init__(self, font, parent=None): super(GroupsWindow, self).__init__(parent, Qt.Window) self.font = font + self.font.addObserver(self, "_groupsChanged", "Groups.Changed") groups = self.font.groups.keys() self.groupsList = GroupListWidget(groups, self) @@ -192,8 +196,10 @@ class GroupsWindow(QWidget): newKey = self.groupsList.currentItem() if newKey is None: return newKey = newKey.text() + if newKey == self._cachedName: return self.font.groups[newKey] = self.font.groups[self._cachedName] del self.font.groups[self._cachedName] + self._cachedName = newKey def _groupDelete(self): newKey = self.groupsList.currentItem().text() @@ -202,6 +208,16 @@ class GroupsWindow(QWidget): if not self.font.groups.keys(): self.removeGroupButton.setEnabled(False) self._groupChanged() + # XXX: it seems the notification doesn't trigger... + def _groupsChanged(self, notification): + self._cachedName = None + self.groupsList.blockSignals(True) + self.groupsList.clear() + self.groupsList.fillGroupNames(self) + # TODO: consider transferring currentGroup as well + self.groupsList.blockSignals(False) + #self.groupsList.setCurrentRow(0) + def characterDeleteEvent(self, selection): currentGroup = self.groupsList.currentItem().text() currentGroupList = self.font.groups[currentGroup] @@ -226,6 +242,10 @@ class GroupsWindow(QWidget): event.acceptProposedAction() self._groupChanged() + def closeEvent(self, event): + self.font.removeObserver(self, "Groups.Changed") + event.accept() + def resizeEvent(self, event): if self.isVisible(): margins = self.layout().contentsMargins() |
