Skip to content

Commit

Permalink
wxGUI/psmap: fix show correct error message if Ghostscript isn't inst…
Browse files Browse the repository at this point in the history
…alled (OSGeo#2420)

If Ghostscript (required for rendering output PDF file) isn't
installed on the OS MS Windows platform show correct error message.
  • Loading branch information
tmszi committed Sep 28, 2023
1 parent b989e81 commit c0bf403
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
38 changes: 30 additions & 8 deletions gui/wxpython/psmap/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,14 @@ def OnCmdDone(self, event):

if event.userData["pdfname"]:
if sys.platform == "win32":
import platform

arch = platform.architecture()[0]
pdf_rendering_prog = "gswin64c"
if "32" in arch:
pdf_rendering_prog = "gswin32c"
command = [
"gswin32c",
pdf_rendering_prog,
"-P-",
"-dSAFER",
"-dCompatibilityLevel=1.4",
Expand All @@ -430,14 +436,23 @@ def OnCmdDone(self, event):
"-f",
event.userData["filename"],
]
title = _("Program {} is not available.").format(pdf_rendering_prog)
message = _("{title} Please install it to create PDF.\n\n").format(
title=title
)
else:
pdf_rendering_prog = "ps2pdf"
command = [
"ps2pdf",
pdf_rendering_prog,
"-dPDFSETTINGS=/prepress",
"-r1200",
event.userData["filename"],
event.userData["pdfname"],
]
message = _(
"Program {} is not available."
" Please install it to create PDF.\n\n "
).format(pdf_rendering_prog)
try:
proc = grass.Popen(command)
ret = proc.wait()
Expand All @@ -450,13 +465,20 @@ def OnCmdDone(self, event):
else:
self.SetStatusText(_("PDF generated"), 0)
except OSError as e:
GError(
parent=self,
message=_(
"Program ps2pdf is not available. Please install it to create PDF.\n\n %s"
if sys.platform == "win32":
dlg = HyperlinkDialog(
self,
title=title,
message=message + str(e),
hyperlink="https://www.ghostscript.com/releases/gsdnld.html",
hyperlinkLabel=_("You can download {} version here.").format(
arch
),
)
% e,
)
dlg.ShowModal()
dlg.Destroy()
return
GError(parent=self, message=message + str(e))

elif not event.userData["temp"]:
self.SetStatusText(_("PostScript file generated"), 0)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/psmap/g.gui.psmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ <h3>CARTOGRAPHIC COMPOSER TOOLBAR</h3>
<dd> Generates hardcopy map output in PostScript/EPS file.</dd>
<dt><img src="icons/pdf-export.png" alt="icon">&nbsp;
<em>Generate hardcopy map output in PDF</em></dt>
<dd> Generates hardcopy map output in PDF using ps2pdf.</dd>
<dd> Generates hardcopy map output in PDF using ps2pdf or <a href="https://www.ghostscript.com/releases/gsdnld.html">Ghostscript gswin32c/gswin64c</a> (OS MS Windows platform only).</dd>

</dl>

Expand Down

0 comments on commit c0bf403

Please sign in to comment.