[PYTHON] Try modifying the TortoiseHg file view a bit

Thing you want to do

When you view a file's diff or Blame in TortoiseHg, you'll also see an indicator showing your changes, right? thg-fileview

When I scroll the window, the gray box moves accordingly. Do you want to click here? I would be very happy if you click it and jump to that position. I.

What i did

That's why I tried a little. https://bitbucket.org/iwata0303/thg/commits/bbb613be1df57a43c4e3f6c20aa10ad45fe26c93

I have a file called tortoisehg / hgqt / blockmatcher.py and I'm adding this method to a class called BlockList there.

blockmatcher.py


    def scrollToPos(self, y):
        # Scroll to the position which specified by Y coodinate.
        if not isinstance(self._sbar, QScrollBar):
            return
        ratio = float(y) / self.height()
        minimum, maximum, step = self._minimum, self._maximum, self._pagestep
        value = minimum + (maximum + step - minimum) * ratio - (step * 0.5)
        value = min(maximum, max(minimum, value))  # round to valid range.
        self.setValue(value)

    def mousePressEvent(self, event):
        super(BlockList, self).mousePressEvent(event)
        self.scrollToPos(event.y())

    def mouseMoveEvent(self, event):
        super(BlockList, self).mouseMoveEvent(event)
        self.scrollToPos(event.y())

Now, if you click on the indicator, it will jump to that position, and if you drag it up or down as it is, scrolling will also work.

Try to make it a plug-in

By the way, it's a hassle to get the TortoiseHg source and build it just for this.

** It's not recommended for a good boy **, but I'll try using an extension to apply a monkey patch.

thg_blocklist_patch.py


# -*- coding:utf-8 -*-
def extsetup():
    import sys
    import os
    # thg.exe and thgw.Only process when executed from exe
    if not os.path.basename(sys.argv[0]).startswith('thg'):
        return

    from PyQt4.QtGui import QScrollBar

    from tortoisehg.hgqt.blockmatcher import BlockList
    from types import MethodType

    mousePressEvent_org = BlockList.mousePressEvent
    mouseMoveEvent_org = BlockList.mouseMoveEvent

    def scrollToPos(bl, y):
        # Scroll to the position which specified by Y coodinate.
        if not isinstance(bl._sbar, QScrollBar):
            return
        ratio = float(y) / bl.height()
        minimum, maximum, step = bl._minimum, bl._maximum, bl._pagestep
        value = minimum + (maximum + step - minimum) * ratio - (step * 0.5)
        value = min(maximum, max(minimum, value))  # round to valid range.
        bl.setValue(value)

    def mousePressEvent(self, event):
        mousePressEvent_org(self, event)
        scrollToPos(self, event.y())

    def mouseMoveEvent(self, event):
        mouseMoveEvent_org(self, event)
        scrollToPos(self, event.y())

    BlockList.mousePressEvent = MethodType(mousePressEvent, None, BlockList)
    BlockList.mouseMoveEvent = MethodType(mouseMoveEvent, None, BlockList)

Normally, I don't want to be hurt when I hit the hg command, so I try to process it only when it is executed from thg * .exe. I haven't confirmed it, but on Linux, I think that sys.arg [0] will contain the python path, so in that case, check with sys.arg [1].

If you register this file as an extension properly, you will not have to touch the source of the main body. ** This is a monkey patch, so be careful when upgrading. ** **

Recommended Posts

Try modifying the TortoiseHg file view a bit
Try modifying TortoiseHg's file view a bit more
View the full path (absolute path) of a file in a directory in Linux Bash
Try rewriting the file with the less command
DJango Memo: From the beginning (creating a view)
Save the object to a file with pickle
[Caution] When creating a binary image (1bit / pixel), be aware of the file format!
Get the file name in a folder using glob
Try creating a compressed file using Python and zlib
Try touching the micro: bit with VS Code + Python
DJango Note: From the beginning (using a generic view)
Try loading the image in a separate thread (OpenCV-Python)
Output the output result of sklearn.metrics.classification_report as a CSV file
A little bit from Python using the Jenkins API