Skip to content

Commit

Permalink
wxGUI: Fixed F841 in psmap/ (OSGeo#4574)
Browse files Browse the repository at this point in the history
  • Loading branch information
arohanajit authored Oct 23, 2024
1 parent 533070d commit 0582709
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 65 deletions.
6 changes: 3 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ per-file-ignores =
gui/scripts/d.wms.py: E501
gui/wxpython/image2target/g.gui.image2target.py: E501
gui/wxpython/nviz/*: E722
gui/wxpython/photo2image/*: E722
gui/wxpython/photo2image/g.gui.photo2image.py: E501
gui/wxpython/psmap/*: F841, E266, E722
gui/wxpython/photo2image/*: F841, E722, E265
gui/wxpython/photo2image/g.gui.photo2image.py: E501, F841
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
Expand Down
24 changes: 1 addition & 23 deletions gui/wxpython/psmap/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -6140,15 +6138,6 @@ 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"]

x, y = PaperMapCoordinates(
mapInstr=self.instruction[self.mapId],
Expand Down Expand Up @@ -6211,7 +6200,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"]))

Expand Down Expand Up @@ -6526,15 +6514,6 @@ 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"]

x, y = PaperMapCoordinates(
mapInstr=self.instruction[self.mapId],
Expand Down Expand Up @@ -6590,7 +6569,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"]))

Expand Down
74 changes: 36 additions & 38 deletions gui/wxpython/psmap/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def __init__(
self.getInitMap()

# image path
env = gs.gisenv()
self.imgName = gs.tempfile()

# canvas for preview
Expand Down Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/psmap/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 0582709

Please sign in to comment.