Commits

Yuya Nishihara committed 93da8ae

workbench: bundle titleChanged signals to avoid buggy sender() (refs #3393)

It uses old-style connection because of
http://www.riverbankcomputing.com/pipermail/pyqt/2010-March/026113.html

Backed out 80ca560b54d6 which is no longer needed.

  • Participants
  • Parent commits 2a801eb

Comments (0)

Files changed (1)

tortoisehg/hgqt/workbench.py

         # Create the actions that will be displayed on the context menu
         self.createActions()
         self.lastClosedRepoRootList = []
+        self._repoTabTitleChangedMapper = mapper = QSignalMapper(self)
+        mapper.mapped[QWidget].connect(self._updateRepoTabTitle)
+
         self.progressDialog.close()
         self.progressDialog = None
         self._dialogs = qtlib.DialogKeeper(
             self.mqpatches.setRepoAgent(None)
             self.reporegistry.setActiveTabRepo('')
 
-    #@pyqtSlot(unicode)
-    def _updateRepoTabTitle(self, title):
-        index = self.repoTabsWidget.indexOf(self.sender())
-        self.repoTabsWidget.setTabText(index, title)
+    @pyqtSlot(QWidget)
+    def _updateRepoTabTitle(self, rw):
+        index = self.repoTabsWidget.indexOf(rw)
+        self.repoTabsWidget.setTabText(index, rw.title())
         if index == self.repoTabsWidget.currentIndex():
             self._updateWindowTitle()
 
             index = self.repoTabsWidget.addTab(rw, rw.title())
         tw.setTabToolTip(index, repoagent.rootPath())
         tw.setCurrentIndex(index)
-        rw.titleChanged.connect(self._updateRepoTabTitle)
+        # PyQt 4.6 cannot find compatible signal by new-style connection
+        QObject.connect(rw, SIGNAL('titleChanged(QString)'),
+                        self._repoTabTitleChangedMapper, SLOT('map()'))
+        self._repoTabTitleChangedMapper.setMapping(rw, rw)
         rw.showIcon.connect(self._updateRepoTabIcon)
         self.reporegistry.addRepo(repoagent.rootPath())
 
 
         return forwarder
 
-    # no @pyqtSlot(); as of PyQt 4.9.3, it makes self.sender() wrong through
-    # the following path: reload -> titleChanged -> _updateRepoTabTitle,
-    # if _updateRepoTabTitle is not decorated as @pyqtSlot.
+    @pyqtSlot()
     def refresh(self):
         w = self.repoTabsWidget.currentWidget()
         if w:
             self.mqpatches.reload()
 
     # no @pyqtSlot(QAction) to avoid wrong self.sender() at
-    # _appendRepoWidgetOutput, _updateRepoTabTitle and _updateRepoTabIcon
+    # _appendRepoWidgetOutput and _updateRepoTabIcon
     # during QMessageBox.exec at SyncWidget.pushclicked. See #3320.
     def _runSyncAction(self, action):
         w = self.repoTabsWidget.currentWidget()
         if w:
             qtlib.openshell(w.repo.root, w.repo.displayname, w.repo.ui)
 
-    # no @pyqtSlot() to avoid wrong self.sender() at _updateRepoTabTitle
-    # on repositoryChanged signal in 'Restart all TortoiseHg applications'
-    # message box of SettingsDialog.  See #3393.
-    def editSettings(self):
-        self._editSettings(None)
-
-    def _editSettings(self, focus):
+    @pyqtSlot()
+    def editSettings(self, focus=None):
         tw = self.repoTabsWidget
         w = tw.currentWidget()
         twrepo = (w and w.repo.root or '')
                             parent=self, root=twrepo)
         sd.exec_()
 
-    # no @pyqtSlot() to avoid segfault or "python: malloc.c: int_free:
-    # Assertion `nextchunk->bk_nextsize->fd_nextsizewrong == nextchunk"
-    # failure at exit, which is probably due to repositoryChanged signal in
-    # 'Restart all TortoiseHg applications' message box of SettingsDialog.
+    @pyqtSlot()
     def _editCustomToolsSettings(self):
-        self._editSettings('tools')
+        self.editSettings('tools')