Commits

Yuya Nishihara  committed 19eefbd

imporove filter-palette patch

  • Participants
  • Parent commits 79e5745

Comments (0)

Files changed (3)

File filter-palette.patch

 # Date 1345665431 -7200
 # Branch stable
 # Node ID a0f2dad9a121679761124e22533211c749db8a4c
-# Parent  cd0980debb0a5a331ee1d625b00beca032dad375
+# Parent dc3b783b4deb22226101a619d9dbef9c3472f3ce
 repowidget, status, manifest: change background color when a filter is applied
 
 This patch changes the background color of filtered lists and trees.
 diff --git a/tortoisehg/hgqt/manifestdialog.py b/tortoisehg/hgqt/manifestdialog.py
 --- a/tortoisehg/hgqt/manifestdialog.py
 +++ b/tortoisehg/hgqt/manifestdialog.py
-@@ -283,8 +283,13 @@
+@@ -283,8 +283,13 @@ class ManifestWidget(QWidget, qtlib.Task
          self._filterupdatetimer = QTimer(self, interval=200, singleShot=True)
          self.le.returnPressed.connect(self._treeview.expandAll)
          self.le.textChanged.connect(self._filterupdatetimer.start)
  
      @pyqtSlot()
      def _autoexpandtree(self):
-@@ -444,6 +449,11 @@
+@@ -444,6 +449,11 @@ class QManifestLineEdit(QLineEdit):
  
  class QManifestTreeView(QTreeView):
      topreached = pyqtSignal(int)
-+    
++
 +    def __init__(self, *args, **kwargs):
 +        QTreeView.__init__(self, *args, **kwargs)
 +        self._paletteswitcher = qtlib.PaletteSwitcher(self)
-+    
++
      def keyPressEvent(self, event):
          if self.currentIndex().row() == 0 \
                  and not self.currentIndex().parent().isValid():
-@@ -453,3 +463,6 @@
+@@ -453,3 +463,6 @@ class QManifestTreeView(QTreeView):
                  return
          # default handler for event
          super(QManifestTreeView, self).keyPressEvent(event)
 diff --git a/tortoisehg/hgqt/qtlib.py b/tortoisehg/hgqt/qtlib.py
 --- a/tortoisehg/hgqt/qtlib.py
 +++ b/tortoisehg/hgqt/qtlib.py
-@@ -1135,3 +1135,44 @@
+@@ -1135,3 +1135,45 @@ def newshortcutsforstdkey(key, *args, **
      """Create [QShortcut,...] for all key bindings of the given StandardKey"""
      return [QShortcut(keyseq, *args, **kwargs)
              for keyseq in QKeySequence.keyBindings(key)]
 +
 +class PaletteSwitcher(object):
 +    """
-+    Class that can be used to enable a predefined, alterantive background color for a widget
-+    
++    Class that can be used to enable a predefined, alterantive background color
++    for a widget
++
 +    This is normally used to change the color of widgets when they display some
 +    "filtered" content which is a subset of the actual widget contents.
-+    
++
 +    The alternative background color is fixed, and depends on the original
 +    background color (dark and light backgrounds use a different alternative
 +    color).
-+    
++
 +    The alterenative color cannot be changed because the idea is to set a
 +    consistent "filter" style for all widgets.
 +
 +    An instance of this class must be added as a property of the widget whose
 +    background we want to change. The constructor takes the "target widget" as
 +    its only parameter.
-+    
++
 +    In order to enable or disable the background change, simply call the
 +    enablefilterpalette() method.
 +    """
-+    def __init__(self, targetwidget=None):
++    def __init__(self, targetwidget):
 +        self._targetwidget = targetwidget
 +        self._defaultpalette = targetwidget.palette()
 +        bgcolor = self._defaultpalette.color(QPalette.Base)
 +            filterbgcolor = QColor('darkgrey')
 +        self._filterpalette = QPalette()
 +        self._filterpalette.setColor(QPalette.Base, filterbgcolor)
-+    
++
 +    def enablefilterpalette(self, enabled=False):
 +        if enabled:
 +            pl = self._filterpalette
 diff --git a/tortoisehg/hgqt/repoview.py b/tortoisehg/hgqt/repoview.py
 --- a/tortoisehg/hgqt/repoview.py
 +++ b/tortoisehg/hgqt/repoview.py
-@@ -18,7 +18,7 @@
+@@ -18,7 +18,7 @@ from mercurial import error
  
  from tortoisehg.util import hglib
  from tortoisehg.hgqt.i18n import _
  from tortoisehg.hgqt.logcolumns import ColumnSelectDialog
  
  from PyQt4.QtCore import *
-@@ -68,6 +68,7 @@
+@@ -68,6 +68,7 @@ class HgRepoView(QTableView):
          self.setDragDropMode(QAbstractItemView.InternalMove)
  
          self.setStyle(HgRepoViewStyle(self.style()))
  
          self.setSelectionMode(QAbstractItemView.ExtendedSelection)
          self.setSelectionBehavior(QAbstractItemView.SelectRows)
-@@ -321,6 +322,9 @@
+@@ -321,6 +322,9 @@ class HgRepoView(QTableView):
  
          super(HgRepoView, self).resizeEvent(e)
  
 diff --git a/tortoisehg/hgqt/repowidget.py b/tortoisehg/hgqt/repowidget.py
 --- a/tortoisehg/hgqt/repowidget.py
 +++ b/tortoisehg/hgqt/repowidget.py
-@@ -514,6 +514,7 @@
+@@ -514,6 +514,7 @@ class RepoWidget(QWidget):
      def _unapplyRevisionSet(self):
          self.toolbarVisibilityChanged.emit()
          self.outgoingMode = False
          if not self.revset:
              return False
          self.revset = []
-@@ -536,6 +537,7 @@
+@@ -536,6 +537,7 @@ class RepoWidget(QWidget):
              self.refresh()
          self.repoview.resetBrowseHistory(self.revset)
          self._reload_rev = self.revset[0]
 diff --git a/tortoisehg/hgqt/status.py b/tortoisehg/hgqt/status.py
 --- a/tortoisehg/hgqt/status.py
 +++ b/tortoisehg/hgqt/status.py
-@@ -352,6 +352,7 @@
+@@ -352,6 +352,7 @@ class StatusWidget(QWidget):
          model = self.tv.model()
          if model:
              model.setFilter(match)
  
      def updateCheckCount(self):
          model = self.tv.model()
-@@ -500,6 +501,7 @@
+@@ -500,6 +501,7 @@ class WctxFileTree(QTreeView):
          self.setContextMenuPolicy(Qt.CustomContextMenu)
          self.customContextMenuRequested.connect(self.menuRequested)
          self.setTextElideMode(Qt.ElideLeft)
  
      def scrollTo(self, index, hint=QAbstractItemView.EnsureVisible):
          # don't update horizontal position by selection change
-@@ -552,6 +554,9 @@
-             return self.selectionModel().selectedRows()
+@@ -553,6 +555,9 @@ class WctxFileTree(QTreeView):
          # Invalid selectionModel found
          return []
-+    
+ 
 +    def enablefilterpalette(self, enable):
 +        self._paletteswitcher.enablefilterpalette(enable)
- 
++
  class WctxModel(QAbstractTableModel):
      checkToggled = pyqtSignal()
+ 

File mani-applyfilter.diff

+# HG changeset patch
+# Date 1346682042 -32400
+# Parent e54292f5da98433740028f4d0ff85c29dd5dc14f
+manifest: bind applyFilter() to instance for ease of lifecycle handling
+
+GC can be blocked by dynamic function/lambda connected to long-lived signal
+in some cases.
+
+diff --git a/tortoisehg/hgqt/manifestdialog.py b/tortoisehg/hgqt/manifestdialog.py
+--- a/tortoisehg/hgqt/manifestdialog.py
++++ b/tortoisehg/hgqt/manifestdialog.py
+@@ -283,13 +283,13 @@ class ManifestWidget(QWidget, qtlib.Task
+         self._filterupdatetimer = QTimer(self, interval=200, singleShot=True)
+         self.le.returnPressed.connect(self._treeview.expandAll)
+         self.le.textChanged.connect(self._filterupdatetimer.start)
+-        def applyFilter():
+-            filtertext = self.le.text()
+-            self._treemodel.setNameFilter(filtertext)
+-            self._treeview.enablefilterpalette(filtertext)
++        self._filterupdatetimer.timeout.connect(self._applyFilter)
+ 
+-        self._filterupdatetimer.timeout.connect(
+-            applyFilter)
++    @pyqtSlot()
++    def _applyFilter(self):
++        filtertext = self.le.text()
++        self._treemodel.setNameFilter(filtertext)
++        self._treeview.enablefilterpalette(filtertext)
+ 
+     @pyqtSlot()
+     def _autoexpandtree(self):
 shortcut.diff
 docdiff-base.diff
 filter-palette.patch
+mani-applyfilter.diff
 fileview-time.diff
 reporeg-moveactions.diff
 reporeg-saverestore.diff