From 7b295da705fea4e883b94c4b23fc89b5f03937e1 Mon Sep 17 00:00:00 2001 From: Philip Belemezov Date: Sun, 20 Jun 2021 00:31:14 +0200 Subject: [PATCH 1/3] Update wxPython to 4.1.1 --- requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index ff8797eb60..c9dbebd89f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -wxPython == 4.0.6 +wxPython == 4.1.1 logbook >= 1.0.0 -numpy == 1.19.2 -matplotlib == 3.2.2 +numpy == 1.20.2 +matplotlib == 3.4.1 python-dateutil requests >= 2.0.0 sqlalchemy == 1.3.23 From b10599d60d3222ef2127c3bacdbd8b9af5432d93 Mon Sep 17 00:00:00 2001 From: Philip Belemezov Date: Sun, 20 Jun 2021 00:41:16 +0200 Subject: [PATCH 2/3] Avoid Assertion when scale > 1 Since wxBitmap cannot be resized, resize the image before obtaining the bitmap --- gui/bitmap_loader.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gui/bitmap_loader.py b/gui/bitmap_loader.py index 325cbc7e3d..d05a3aad3e 100644 --- a/gui/bitmap_loader.py +++ b/gui/bitmap_loader.py @@ -102,11 +102,13 @@ def loadBitmap(cls, name, location): if img is None: pyfalog.warning("Missing icon file: {0}/{1}".format(location, filename)) return None + return BitmapLoader.getScaledBitmap(image=img, scale=scale) - bmp: wx.Bitmap = img.ConvertToBitmap() + @staticmethod + def getScaledBitmap(image: wx.Image, scale: int) -> wx.Bitmap: if scale > 1: - bmp.SetSize((bmp.GetWidth() // scale, bmp.GetHeight() // scale)) - return bmp + image.Rescale(image.GetWidth() // scale, image.GetHeight() // scale) + return image.ConvertToBitmap() @classmethod def loadScaledBitmap(cls, name, location, scale=0): From fdb9d2366ce7b06f0e51a372c17ccc7a262e81bf Mon Sep 17 00:00:00 2001 From: Philip Belemezov Date: Sun, 20 Jun 2021 00:41:48 +0200 Subject: [PATCH 3/3] Fix Drag and Drop Bitmap Rendering on macOS (#2304) On macOS DC's Blit() and GetAsBitmap() methods cause another paint event, subsequently leading to a infinite recursion. The issue is discussed on wx's forums: https://discuss.wxpython.org/t/dc-blit-causes-evt-paint/23772/12 The solution is to perform offscreen rendering of the item window when a drag and drop operation is being performed. --- gui/builtinShipBrowser/fitItem.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/gui/builtinShipBrowser/fitItem.py b/gui/builtinShipBrowser/fitItem.py index bd37b0b949..60132314a5 100644 --- a/gui/builtinShipBrowser/fitItem.py +++ b/gui/builtinShipBrowser/fitItem.py @@ -418,6 +418,7 @@ def MouseMove(self, event): if self.dragMotionTrigger < 0: if not self.HasCapture(): self.CaptureMouse() + self._updateDragBitmap() self.dragWindow = PFBitmapFrame(self, pos, self.dragTLFBmp) self.dragWindow.Show() self.dragged = True @@ -430,6 +431,18 @@ def MouseMove(self, event): self.dragWindow.SetPosition(pos) return + def _updateDragBitmap(self): + dc = wx.ClientDC(self) + bufferedDC = wx.BufferedDC(dc) + self.DrawItem(dc) + + rect = self.GetRect() + tdc = wx.MemoryDC() + self.dragTLFBmp = wx.Bitmap((self.toolbarx if self.toolbarx < 200 else 200), rect.height, 24) + tdc.SelectObject(self.dragTLFBmp) + tdc.Blit(0, 0, (self.toolbarx if self.toolbarx < 200 else 200), rect.height, bufferedDC, 0, 0, wx.COPY) + tdc.SelectObject(wx.NullBitmap) + def selectFit(self, event=None, newTab=False): if newTab: wx.PostEvent(self.mainFrame, FitSelected(fitID=self.fitID, startup=2)) @@ -477,6 +490,7 @@ def UpdateElementsPos(self, mdc): self.thoverw = wlabel def DrawItem(self, mdc): + self.dragTLFBmp = None rect = self.GetRect() windowColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW) @@ -519,11 +533,6 @@ def DrawItem(self, mdc): if self.tcFitName.IsShown(): self.AdjustControlSizePos(self.tcFitName, self.textStartx, self.toolbarx - self.editWidth - self.padding) - tdc = wx.MemoryDC() - self.dragTLFBmp = wx.Bitmap((self.toolbarx if self.toolbarx < 200 else 200), rect.height, 24) - tdc.SelectObject(self.dragTLFBmp) - tdc.Blit(0, 0, (self.toolbarx if self.toolbarx < 200 else 200), rect.height, mdc, 0, 0, wx.COPY) - tdc.SelectObject(wx.NullBitmap) def AdjustControlSizePos(self, editCtl, start, end): fnEditSize = editCtl.GetSize()