Skip to content

Commit

Permalink
wxGUI/psmap: Ghostscript HyperlinkDialog is needed (OSGeo#2441)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi committed Jul 19, 2022
1 parent 877f3ab commit a621250
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions gui/wxpython/psmap/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from core.utils import PilImageToWxImage
from gui_core.forms import GUI
from gui_core.widgets import GNotebook
from gui_core.dialogs import HyperlinkDialog
from gui_core.ghelp import ShowAboutDialog
from gui_core.wrap import ClientDC, PseudoDC, Rect, StockCursor, EmptyBitmap
from psmap.menudata import PsMapMenuData
Expand Down Expand Up @@ -257,6 +258,15 @@ def _switchToPage(self, page_index=0):
self.book.SetSelection(page_index)
self.currentPage = page_index

def _getGhostscriptProgramName(self):
"""Get Ghostscript program name
:return: Ghostscript program name
"""
import platform

return "gswin64c" if "64" in platform.architecture()[0] else "gswin32c"

def InstructionFile(self):
"""Creates mapping instructions"""

Expand Down Expand Up @@ -461,13 +471,35 @@ def OnCmdDone(self, event):
# wx.BusyInfo does not display the message
busy = wx.BusyInfo(_("Generating preview, wait please"), parent=self)
wx.GetApp().Yield()
im = PILImage.open(event.userData["filename"])
if self.instruction[self.pageId]["Orientation"] == "Landscape":
import numpy as np
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 (IOError, 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 donwload {program} {arch} version here."
).format(
program=program,
arch="64bit" if "64" in program else "32bit",
),
)
dlg.ShowModal()
dlg.Destroy()
return

im_array = np.array(im)
im = PILImage.fromarray(np.rot90(im_array, 3))
im.save(self.imgName, format="PNG")
self.book.SetSelection(1)
self.currentPage = 1
rect = self.previewCanvas.ImageRect()
Expand Down

0 comments on commit a621250

Please sign in to comment.