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 /Lib/defconQt/groupsView.py | |
| parent | c9b4454c3296c8096873fef371221ba5ac8972d7 (diff) | |
| download | trufont-c898a4d61fbaf10d9f8a989b58c028ad3a271157.tar.bz2 | |
fontView,…: some refactorings and nits
Diffstat (limited to 'Lib/defconQt/groupsView.py')
| -rw-r--r-- | Lib/defconQt/groupsView.py | 20 | 
1 files changed, 20 insertions, 0 deletions
| 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() | 
