Dear Uwe,

On Tue, Aug 18, 2009 at 7:49 PM, Uwe Hoffmann<[email protected]> wrote:
> Am Montag, den 17.08.2009, 23:48 +0200 schrieb Greg Landrum:
>
> in principle yes, but it was a quick hack to get the ball running.
> it's possible that some other AttributeErrors will be masked so i think
> the following version will be better.
>
>      try:
>        cairo.ImageSurface.format_stride_for_width
>      except AttributeError:
>        stride = image.size[0] * 4
>      else:
>        stride = cairo.ImageSurface.format_stride_for_width (
>          cairo.FORMAT_ARGB32,
>          image.size[0])
>        if stride != image.size[0] * 4:
>          raise Exception ,"invalid stride"

Since this code is enforcing that stride==image.size[0]*4 anyway, I
just checked in a version where it's set directly that way:

   38       #if hasattr(cairo.ImageSurface,'format_stride_for_width'):
   39       #  stride =
cairo.ImageSurface.format_stride_for_width(cairo.FORMAT_ARGB32,
   40       #
image.size[0])
   41       #else:
   42       #  stride=image.size[0]*4
   43       #if stride != image.size[0] * 4:
   44       #  raise Exception ,"invalid stride"
   45       stride=image.size[0]*4

(from here:
http://rdkit.svn.sourceforge.net/viewvc/rdkit/trunk/rdkit/Chem/Draw/cairoCanvas.py?revision=1212&view=markup
)

I left your proposed code in there (lines 38-44), but it's commented out.

Can you explain the test that's at line 43 or should I leave things
the way they are now?

-greg



>
> i found some other problem if pycairo is not available:
> Chem.Draw.__init__.py should contain the follwing line (MolToImage):
> *** 24,29 ****
> --- 24,30 ----
>        from cairoCanvas import Canvas
>        useCAIRO=True
>      except:
> +       useCAIRO=False
>        from rdkit.sping.PIL.pidPIL import PILCanvas as Canvas
>        canvas = Canvas(size=size,name='MolToImageFile')
>        img = canvas._image
>
> otherwise useCairo can be used without defined.
>
> regards
>   Uwe
>
>

Reply via email to