Commits

Daniel Atallah committed 1f16cc8

revdetails, email, cmdui: Avoid lambda function in font signal

This is problematic because the font is persistent and will
hold a reference to the lambda function which will, in turn,
hold a reference to the relevant object ("self"), preventing
it from being disposed.

  • Participants
  • Parent commits 9dfebd5
  • Branches stable

Comments (0)

Files changed (3)

tortoisehg/hgqt/cmdui.py

 
     def _initfont(self):
         tf = qtlib.getfont('fontoutputlog')
-        tf.changed.connect(lambda f: self.setFont(f))
+        tf.changed.connect(self.setFont)
         self.setFont(tf.font())
 
     def _initmarkers(self):

tortoisehg/hgqt/hgemail.py

             w.setUtf8(True)
             w.setReadOnly(True)
             w.setMarginWidth(1, 0)  # hide area for line numbers
-            lex = lexers.get_diff_lexer(self)
+            self.lexer = lex = lexers.get_diff_lexer(self)
             fh = qtlib.getfont('fontdiff')
-            fh.changed.connect(lambda f: lex.setFont(f))
-            # TODO: why cannot we connect directly, without lambda?
+            fh.changed.connect(self.forwardFont)
             lex.setFont(fh.font())
             w.setLexer(lex)
             # TODO: better way to setup diff lexer
+          
         initqsci(self._qui.preview_edit)
 
         self._qui.main_tabs.currentChanged.connect(self._refreshpreviewtab)
         self._refreshpreviewtab(self._qui.main_tabs.currentIndex())
 
+    def forwardFont(self, font):
+        if self.lexer:
+            self.lexer.setFont(font)
+
     @pyqtSlot(int)
     def _refreshpreviewtab(self, index):
         """Generate preview text if current tab is preview"""

tortoisehg/hgqt/revdetails.py

         self.message.setMinimumSize(QSize(0, 0))
         f = getfont('fontcomment')
         self.message.setFont(f.font())
-        f.changed.connect(lambda font: self.message.setFont(font))
+        f.changed.connect(self.forwardFont)
 
         self.fileview = HgFileView(self.repo, self.message_splitter)
         sp = SP(SP.Expanding, SP.Expanding)
         self.filelist.fileRevSelected.connect(self.onFileRevSelected)
         self.filelist.clearDisplay.connect(self.fileview.clearDisplay)
 
+    def forwardFont(self, font):
+        self.message.setFont(font)
+
     def createActions(self):
         def fileActivated():
             idx = self.filelist.currentIndex()