Commits

Yuya Nishihara committed 09d3c77

thgext.debugtools: add menu to start/stop GC timer

Comments (0)

Files changed (1)

thgext/debugtools.py

 from PyQt4.QtGui import *
 
 from mercurial import extensions
-from tortoisehg.hgqt import qtlib, workbench
+from tortoisehg.hgqt import qtlib, run, workbench
 
 class DebugTools(QObject):
     def __init__(self, parent):
         a = self._debugMenu.addAction('Run Full Garbage &Collection')
         a.triggered.connect(self._runGc)
 
+        a = self._debugMenu.addAction('&Enable Garbage Collector')
+        a.setCheckable(True)
+        a.setChecked(self._gcTimer.isActive())
+        a.triggered.connect(self._setGcEnabled)
+
     @pyqtSlot()
     def _updateInvisibleWindowsMenu(self):
         widgets = [w for w in QApplication.topLevelWidgets()
         found = gc.collect()
         self._information('GC Result', 'Found %d unreachable objects' % found)
 
+    @property
+    def _gcTimer(self):
+        return run.qtrun._gc.timer
+
+    @pyqtSlot(bool)
+    def _setGcEnabled(self, enabled):
+        if enabled:
+            self._gcTimer.start()
+        else:
+            self._gcTimer.stop()
+
     def _setupInfoBarMenu(self):
         m = self._debugMenu.addMenu('&InfoBar')
         m.triggered.connect(self._setInfoBar)