From 5f71409f72aa6beb3ae1a5cc963b157cbf6d28d2 Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Tue, 22 Oct 2024 10:34:08 -0400 Subject: [PATCH 1/2] updated 841 --- .flake8 | 2 +- gui/wxpython/psmap/dialogs.py | 28 ++--------- gui/wxpython/psmap/frame.py | 74 +++++++++++++++--------------- gui/wxpython/psmap/instructions.py | 2 +- 4 files changed, 43 insertions(+), 63 deletions(-) diff --git a/.flake8 b/.flake8 index 8211d9e03d4..f01746d140a 100644 --- a/.flake8 +++ b/.flake8 @@ -27,7 +27,7 @@ per-file-ignores = gui/wxpython/nviz/*: E722 gui/wxpython/photo2image/*: F841, E722, E265 gui/wxpython/photo2image/g.gui.photo2image.py: E501, F841 - gui/wxpython/psmap/*: F841, E266, E722 + gui/wxpython/psmap/*: E501, E722 gui/wxpython/vdigit/*: F841, E722, F405, F403 gui/wxpython/animation/g.gui.animation.py: E501 gui/wxpython/tplot/frame.py: F841, E722 diff --git a/gui/wxpython/psmap/dialogs.py b/gui/wxpython/psmap/dialogs.py index c4784525cc9..2bc5010c38c 100644 --- a/gui/wxpython/psmap/dialogs.py +++ b/gui/wxpython/psmap/dialogs.py @@ -5731,8 +5731,6 @@ def updateDialog(self): y = self.unitConv.convert(value=y, fromUnit="inch", toUnit=currUnit) self.positionPanel.position["xCtrl"].SetValue("%5.3f" % x) self.positionPanel.position["yCtrl"].SetValue("%5.3f" % y) - # EN coordinates - e, n = self.textDict["east"], self.textDict["north"] self.positionPanel.position["eCtrl"].SetValue(str(self.textDict["east"])) self.positionPanel.position["nCtrl"].SetValue(str(self.textDict["north"])) @@ -6027,7 +6025,7 @@ def OnImageSelectionChanged(self, event): pImg = PILImage.open(file) img = PilImageToWxImage(pImg) except OSError as e: - GError(message=_("Unable to read file %s") % file) + GError(message=_("Unable to read file %s: %s") % (file, str(e))) self.ClearPreview() return self.SetSizeInfoLabel(img) @@ -6140,15 +6138,8 @@ def update(self): else: self.imageDict["XY"] = False - if self.positionPanel.position["eCtrl"].GetValue(): - e = self.positionPanel.position["eCtrl"].GetValue() - else: - self.imageDict["east"] = self.imageDict["east"] - - if self.positionPanel.position["nCtrl"].GetValue(): - n = self.positionPanel.position["nCtrl"].GetValue() - else: - self.imageDict["north"] = self.imageDict["north"] + self.imageDict["east"] = self.imageDict["east"] + self.imageDict["north"] = self.imageDict["north"] x, y = PaperMapCoordinates( mapInstr=self.instruction[self.mapId], @@ -6211,7 +6202,6 @@ def updateDialog(self): self.positionPanel.position["xCtrl"].SetValue("%5.3f" % x) self.positionPanel.position["yCtrl"].SetValue("%5.3f" % y) # EN coordinates - e, n = self.imageDict["east"], self.imageDict["north"] self.positionPanel.position["eCtrl"].SetValue(str(self.imageDict["east"])) self.positionPanel.position["nCtrl"].SetValue(str(self.imageDict["north"])) @@ -6526,15 +6516,8 @@ def update(self): else: self.pointDict["XY"] = False - if self.positionPanel.position["eCtrl"].GetValue(): - e = self.positionPanel.position["eCtrl"].GetValue() - else: - self.pointDict["east"] = self.pointDict["east"] - - if self.positionPanel.position["nCtrl"].GetValue(): - n = self.positionPanel.position["nCtrl"].GetValue() - else: - self.pointDict["north"] = self.pointDict["north"] + self.pointDict["east"] = self.pointDict["east"] + self.pointDict["north"] = self.pointDict["north"] x, y = PaperMapCoordinates( mapInstr=self.instruction[self.mapId], @@ -6590,7 +6573,6 @@ def updateDialog(self): self.positionPanel.position["xCtrl"].SetValue("%5.3f" % x) self.positionPanel.position["yCtrl"].SetValue("%5.3f" % y) # EN coordinates - e, n = self.pointDict["east"], self.pointDict["north"] self.positionPanel.position["eCtrl"].SetValue(str(self.pointDict["east"])) self.positionPanel.position["nCtrl"].SetValue(str(self.pointDict["north"])) diff --git a/gui/wxpython/psmap/frame.py b/gui/wxpython/psmap/frame.py index 1d937483123..e86b277252c 100644 --- a/gui/wxpython/psmap/frame.py +++ b/gui/wxpython/psmap/frame.py @@ -195,7 +195,6 @@ def __init__( self.getInitMap() # image path - env = gs.gisenv() self.imgName = gs.tempfile() # canvas for preview @@ -513,45 +512,44 @@ def OnCmdDone(self, event): env=self.env, ) # wx.BusyInfo does not display the message - busy = wx.BusyInfo(_("Generating preview, wait please"), parent=self) - wx.GetApp().Yield() - try: - im = PILImage.open(event.userData["filename"]) - if self.instruction[self.pageId]["Orientation"] == "Landscape": - import numpy as np - - im_array = np.array(im) - im = PILImage.fromarray(np.rot90(im_array, 3)) - im.save(self.imgName, format="PNG") - except OSError: - del busy - program = self._getGhostscriptProgramName() - dlg = HyperlinkDialog( - self, - title=_("Preview not available"), - message=_( - "Preview is not available probably because Ghostscript is not " - "installed or not on PATH." - ), - hyperlink="https://www.ghostscript.com/releases/gsdnld.html", - hyperlinkLabel=_( - "You can download {program} {arch} version here." - ).format( - program=program, - arch="64bit" if "64" in program else "32bit", - ), - ) - dlg.ShowModal() - dlg.Destroy() - return + with wx.BusyInfo(_("Generating preview, wait please"), parent=self): + wx.GetApp().Yield() + try: + im = PILImage.open(event.userData["filename"]) + if self.instruction[self.pageId]["Orientation"] == "Landscape": + import numpy as np + + im_array = np.array(im) + im = PILImage.fromarray(np.rot90(im_array, 3)) + im.save(self.imgName, format="PNG") + except OSError: + del busy + program = self._getGhostscriptProgramName() + dlg = HyperlinkDialog( + self, + title=_("Preview not available"), + message=_( + "Preview is not available probably because Ghostscript is not " + "installed or not on PATH." + ), + hyperlink="https://www.ghostscript.com/releases/gsdnld.html", + hyperlinkLabel=_( + "You can download {program} {arch} version here." + ).format( + program=program, + arch="64bit" if "64" in program else "32bit", + ), + ) + dlg.ShowModal() + dlg.Destroy() + return - self.book.SetSelection(1) - self.currentPage = 1 - rect = self.previewCanvas.ImageRect() - self.previewCanvas.image = wx.Image(self.imgName, wx.BITMAP_TYPE_PNG) - self.previewCanvas.DrawImage(rect=rect) + self.book.SetSelection(1) + self.currentPage = 1 + rect = self.previewCanvas.ImageRect() + self.previewCanvas.image = wx.Image(self.imgName, wx.BITMAP_TYPE_PNG) + self.previewCanvas.DrawImage(rect=rect) - del busy self.SetStatusText(_("Preview generated"), 0) gs.try_remove(event.userData["instrFile"]) diff --git a/gui/wxpython/psmap/instructions.py b/gui/wxpython/psmap/instructions.py index 845e99b2e6a..82560353806 100644 --- a/gui/wxpython/psmap/instructions.py +++ b/gui/wxpython/psmap/instructions.py @@ -1751,7 +1751,7 @@ def EstimateHeight(self, raster, discrete, fontsize, cols=None, height=None): rinfo = gs.raster_info(raster) if rinfo["datatype"] in {"DCELL", "FCELL"}: - minim, maxim = rinfo["min"], rinfo["max"] + maxim = rinfo["max"] rows = ceil(maxim / cols) else: cat = ( From 072eac17974de1dc3763ceefb9b92b2a89d86ab2 Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Wed, 23 Oct 2024 13:32:25 -0400 Subject: [PATCH 2/2] updates --- gui/wxpython/psmap/dialogs.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gui/wxpython/psmap/dialogs.py b/gui/wxpython/psmap/dialogs.py index 2bc5010c38c..f086d65dd36 100644 --- a/gui/wxpython/psmap/dialogs.py +++ b/gui/wxpython/psmap/dialogs.py @@ -6138,8 +6138,6 @@ def update(self): else: self.imageDict["XY"] = False - self.imageDict["east"] = self.imageDict["east"] - self.imageDict["north"] = self.imageDict["north"] x, y = PaperMapCoordinates( mapInstr=self.instruction[self.mapId], @@ -6516,8 +6514,6 @@ def update(self): else: self.pointDict["XY"] = False - self.pointDict["east"] = self.pointDict["east"] - self.pointDict["north"] = self.pointDict["north"] x, y = PaperMapCoordinates( mapInstr=self.instruction[self.mapId],