Workaround RubberBand drawing problem on GTK3 wxPython4
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Sun, 05 Sep 2021 05:43:17 +0200
branchwxPython4
changeset 3306 841fb2ee1213
parent 3305 ca11385ea5e9
child 3307 eeec6e0ea269
Workaround RubberBand drawing problem on GTK3
graphics/RubberBand.py
--- a/graphics/RubberBand.py	Sun Sep 05 05:03:36 2021 +0200
+++ b/graphics/RubberBand.py	Sun Sep 05 05:43:17 2021 +0200
@@ -195,3 +195,25 @@
         """
         # Erase last bbox and draw current bbox
         self.DrawBoundingBoxes([self.CurrentBBox], dc)
+
+
+def PatchRubberBandForGTK3():
+    """
+    GTK3 implementation of DC doesn't support SetLogicalFuntion(XOR)
+    Then Rubberband can't be erased by just redrawing it on the same place
+    So this is a complete refresh instead, eating a lot of CPU.
+    """
+    def Redraw(self, dc=None):
+        self.Viewer.Refresh()
+        self.Draw()
+
+    RubberBand.Redraw = Redraw
+
+    def Erase(self, dc=None):
+        self.Viewer.Refresh()
+
+    RubberBand.Erase = Erase
+
+
+if "gtk3" in wx.PlatformInfo:
+    PatchRubberBandForGTK3()