[GRASS-dev] [GRASS GIS] #1554: wxGUI Cartographic Composer: preview broken on Windows

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------
Recently `python-pil` package has been introduced into OSGeo4W framework.
When testing "preview" functionality in cartographic composer I am getting
error bellow

{{{
Traceback (most recent call last):
   File "c:\osgeo4w\usr\src\grass64_release\dist.i686-pc-
mingw32\etc\wxpython\gui_modules\psmap.py", line 317, in OnCmdDone
     im.save(self.imgName, format = 'png')
   File "C:\OSGeo4w\apps\Python27\lib\site-packages\PIL\Image.py", line
1406, in save
     self.load()
   File "C:\OSGeo4w\apps\Python27\lib\site-packages\PIL\EpsImagePlugin.py",
line 283, in load
     self.im = Ghostscript(self.tile, self.size, self.fp)
   File "C:\OSGeo4w\apps\Python27\lib\site-packages\PIL\EpsImagePlugin.py",
line 72, in Ghostscript
     gs.write(s)
IOError: [Errno 32] Broken pipe
c:\osgeo4w\usr\src\grass64_release\dist.i686-pc-
mingw32\etc\wxpython\gui_modules\psmap.py:325: RuntimeWarning: tp_compare
didn't return -1 or -2 for exception
   rect = self.previewCanvas.ImageRect()
Traceback (most recent call last):
   File "c:\osgeo4w\usr\src\grass64_release\dist.i686-pc-
mingw32\etc\wxpython\gui_modules\psmap.py", line 325, in OnCmdDone
     rect = self.previewCanvas.ImageRect()
   File "c:\osgeo4w\usr\src\grass64_release\dist.i686-pc-
mingw32\etc\wxpython\gui_modules\psmap.py", line 1626, in ImageRect
     iW, iH = img.GetWidth(), img.GetHeight()
   File "C:\OSGeo4w\apps\Python27\lib\site-packages\wx-2.8-msw-
unicode\wx\_core.py", line 3031, in GetWidth
     return _core_.Image_GetWidth(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "Ok()" failed at
..\..\src\common\image.cpp(1454) in wxImage::GetWidth(): invalid image
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by annakrat):

I have no idea how to fix this, I've done small changes in r50520 but I
don't think it will help. I found out, that someone had similar problem
but there is no answer:
[http://stackoverflow.com/questions/6281744/python-pil-errno-32-broken-
pipe-when-saving-png]

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by martinl):

Replying to [comment:1 annakrat]:
> I have no idea how to fix this, I've done small changes in r50520 but I
don't think it will help. I found out, that someone had similar problem
but there is no answer:
> [http://stackoverflow.com/questions/6281744/python-pil-errno-32-broken-
pipe-when-saving-png]

yeap, PIL using Ghostscript for converting ps to image. That would
probably require to add ghostscript as new package into OSGeo4W framework.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by martinl):

Replying to [comment:2 martinl]:
> Replying to [comment:1 annakrat]:
> > I have no idea how to fix this, I've done small changes in r50520 but
I don't think it will

anyway the candidate for backport...

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by annakrat):

Replying to [comment:3 martinl]:
> anyway the candidate for backport...
it's done

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by annakrat):

There are a few problems:

* Ghostscript is missing (not in OSGeo4W framework)

* if it is installed it is not on the PATH

* from the PIL source code (C:\OSGeo4W\apps\Python27\Lib\site-
packages\PIL\EpsImagePlugin.py):

{{{
def Ghostscript(tile, size, fp):
     """Render an image using Ghostscript (Unix only)"""

...

     command = ["gs",
                "-q", # quite mode
                "-g%dx%d" % size, # set output geometry (pixels)
                "-dNOPAUSE -dSAFER", # don't pause between pages, safe
mode
                "-sDEVICE=ppmraw", # ppm driver
                "-sOutputFile=%s" % file,# output file
                "- >/dev/null 2>/dev/null"]
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.2
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by martinl):

Replying to [comment:5 annakrat]:
> * Ghostscript is missing (not in OSGeo4W framework)

just a quick test, I have added Ghostscript [1] then I have tried to
produced PS using wxGUI Cartographic Composer, the file has been created.
But if I try to open it using e.g. Gimp, it fails.

Another issue is missing `ps2pdf`. But first we should fix generation of
!PostScript output.

Martin

[1] http://trac.osgeo.org/grass/wiki/CompileOnWindows#Ghostscript

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------
Changes (by martinl):

  * priority: normal => critical
  * milestone: 6.4.2 => 6.4.3

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by annakrat):

Replying to [comment:6 martinl]:
> Replying to [comment:5 annakrat]:
> > * Ghostscript is missing (not in OSGeo4W framework)
>
> just a quick test, I have added Ghostscript [1] then I have tried to
produced PS using wxGUI Cartographic Composer, the file has been created.
But if I try to open it using e.g. Gimp, it fails.

I don't understand much. You tried the preview or exporting PS file? The
creation of the ps file is not related to this ticket, the reading of the
ps file by PIL is the problem. When GIMP on Windows is not able to read
it, it's a problem of ps.map module.

The 'unix only' and '>/dev/null 2>/dev/null' in the ghostscript command
must be a serious problem for Windows or not?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by hellik):

Replying to [comment:6 martinl]:
> Replying to [comment:5 annakrat]:
> > * Ghostscript is missing (not in OSGeo4W framework)
>
> just a quick test, I have added Ghostscript [1] then I have tried to
produced PS using wxGUI Cartographic Composer, the file has been created.
But if I try to open it using e.g. Gimp, it fails.

I've followed your example and exported a simple elevation.ps and
converted it with freepdf [1], a ghostscript based pdf converter,
successfully to a pdf. Gimp not tested.

Helmut

[2] http://freepdfxp.de/

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by annakrat):

There is a [http://code.activestate.com/lists/python-image-sig/6877/
patch] for Windows but nobody seems to react on it. To make it work on
windows I could copy the code from EpsImagePlugin.py, change it (according
to the patch) and force it to use the new code at runtime. This a ugly
hack but Python allows it.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by annakrat):

After some changes, preview seems to work. Tested with winGRASS 7. Please
could anyone test the tomorrow snapshot?

Anna

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:11&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by martinl):

Replying to [comment:11 annakrat]:
> After some changes, preview seems to work. Tested with winGRASS 7.
Please could anyone test the tomorrow snapshot?

after putting gswin32c.exe to PATH, it works. At least partially. I have
added raster and line vector map. In the preview only vector map is
rendered. Previewing raster seems to be broken (the maps have same
extent). See attachment:wxpsmap1.png

I noticed also a small bug, labels are not centered and they are in one
line (draft mode, see attachment:wxpsmap0.png).

OSGeo4W doesn't provide `gs` package. We have two options - to add new
package for `gs` or provide it within `grass` package.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:12&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by martinl):

Replying to [comment:12 martinl]:

> after putting gswin32c.exe to PATH, it works. At least partially. I have
added raster and line vector map. In the preview only vector map is
rendered. Previewing raster seems to be broken (the maps have same
extent). See attachment:wxpsmap1.png

update: final ps file is fine (raster is included)

one note: I would expect that when switching to 'preview' mode, the
preview is automatically generated. At this moment it's generated only
when the button is pushed.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1554#comment:13&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by hamish):

Replying to [comment:13 martinl]:
> one note: I would expect that when switching to 'preview' mode,
> the preview is automatically generated. At this moment it's
> generated only when the button is pushed.

is it possible in wxPy to give the button a 3px wide yellow border, or
otherwise make it blink?

Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1554#comment:14&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by annakrat):

Replying to [comment:14 hamish]:
> Replying to [comment:13 martinl]:
> > one note: I would expect that when switching to 'preview' mode,
> > the preview is automatically generated. At this moment it's
> > generated only when the button is pushed.

I am not sure about that. Switching tabs usually does nothing in most
applications.
Also to generate the picture is quite time-consuming and I think users
don't mind waiting after pressing button 'run' but they might be surprised
by waiting after switching tabs.

>
> is it possible in wxPy to give the button a 3px wide yellow border, or
otherwise make it blink?

There is a way to distinguish between active and nonactive tabs it (text
color) but I think it's not possible to highlight individual tabs. What
exactly you would like it for?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1554#comment:15&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by annakrat):

Replying to [comment:13 martinl]:
> Replying to [comment:12 martinl]:
>
> > after putting gswin32c.exe to PATH, it works. At least partially. I
have added raster and line vector map. In the preview only vector map is
rendered. Previewing raster seems to be broken (the maps have same
extent). See attachment:wxpsmap1.png
>
> update: final ps file is fine (raster is included)
>

Is there anything we can do about that? It seems to be the problem of PIL
(which uses ghostscript), or maybe something is wrong with the PS file
generated by ps.map?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1554#comment:16&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by wenzeslaus):

Replying to [comment:15 annakrat]:
> Replying to [comment:14 hamish]:
> > Replying to [comment:13 martinl]:
> > > one note: I would expect that when switching to 'preview' mode,
> > > the preview is automatically generated. At this moment it's
> > > generated only when the button is pushed.
>
> I am not sure about that. Switching tabs usually does nothing in most
applications.
> Also to generate the picture is quite time-consuming and I think users
don't mind waiting after pressing button 'run' but they might be surprised
by waiting after switching tabs.
>
Maybe there is one (for programmer) complicated and (for user) unclear way
to deal with generation. Start a timer after switching a tab and after a
while if the tab is still active start with generation.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1554#comment:17&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by hamish):

Replying to [comment:15 annakrat]:
> There is a way to distinguish between active and nonactive tabs
> it (text color) but I think it's not possible to highlight
> individual tabs. What exactly you would like it for?

I didn't mean to highlight the tab, but rather to give the green triangle
run button a backlit yellow sun glow when the Preview tab was switched to
-- trade out the icon, then trade it back once the rendering was done.

Replying to [comment:17 wenzeslaus]:
> Maybe there is one (for programmer) complicated and (for user)
> unclear way to deal with generation. Start a timer after switching
> a tab and after a while if the tab is still active start with
> generation.

If the computation were relatively cheap that could be ok, but since it
can be expensive I'd vote to stick with the user-initiated approach. (just
make it more obvious)

Along the line to make it more obvious: how about if the initial preview
document loaded a dummy graphic which had a picture of the green triangle
button circled and an arrow pointing NW saying "click up there to generate
preview".
?

Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1554#comment:18&gt;
GRASS GIS <http://grass.osgeo.org>

#1554: wxGUI Cartographic Composer: preview broken on Windows
----------------------------------------------------+-----------------------
Reporter: martinl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: critical | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: cartographic composer, psmap, wingrass | Platform: MSWindows XP
      Cpu: Unspecified |
----------------------------------------------------+-----------------------

Comment(by wenzeslaus):

Replying to [comment:18 hamish]:
> Along the line to make it more obvious: how about if the initial preview
document loaded a dummy graphic which had a picture of the green triangle
button circled and an arrow pointing NW saying "click up there to generate
preview".
> ?
>
Good idea. Generally, we should try to add some hints this and there in
the GUI to guide user what to do, what does this and that mean. Example of
this is a recently added gray text in command console with hint to use
Ctrl+Space and Tab keys.

The text would be enough for me. The graphics seems to be little bit too
much.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1554#comment:19&gt;
GRASS GIS <http://grass.osgeo.org>