Menu

Image in header?

Python
2009-06-06
2015-02-19
  • Bernhard Schönhammer

    Hello,

    is it possible to have an image (e.g. company logo) displayed in page or list header?
    .. at least when printing with ListCtrlPrinter?

    Thanks,
    Bernhard

     
  • Gregory Papadopoulos

    I've just started using ObjectListView and have/had the same requirement.
    I found that we can add an ImageDecoration to the ListHeader.
    i.e.
    prt.ReportFormat.ListHeader.Add(ImageDecoration(image = companylogo, horizontalAlign=wx.LEFT))

    This will solve only part of the problem though. I am using PNGs and there are transparency problems, which can be solved by replacing
    dc.DrawBitmap(self.bitmap, x, y, True) ListCtrlPrinter.py Line 2845 -def DrawDecoration
    with a blit.
    mdc = wx.MemoryDC()
    mdc.SelectObject(self.bitmap)
    dc.Blit( x, y, self.bitmap.GetWidth(), self.bitmap.GetHeight(), mdc, xsrc=-1, ysrc=-1, rop=wx.COPY, useMask=True)
    mdc.SelectObject(wx.NullBitmap)
    Now my only problem is that this seams only to work for the actual printout and not for the preview window.
    Any thoughts?
    BTW GREAT WORK. This component can save you so much time!
    Thanks.
    Gregory

     
  • Werner F. Bruhin

    Hi Gregory,

    What is 'rop=wx.COPY', should that be 'logicalFunction=wx.COPY'? If yes, it could just be left out as wx.COPY is the default.

    If I add an image to e.g. the footer it shows in preview, but it is behind the back ground colour when using e.g. ReportFormat.Normal, so it is mostly hidden.

    ImageDecoration has a param 'over' which defaults to 'True' but it doesn't seem to be used.

     
  • Werner F. Bruhin

    Hi Gregory,

    I pushed a few changes to https://bitbucket.org/wbruhin/objectlistview, including your suggestion above.

    Let us know if it helps.
    Werner

     
  • Gregory Papadopoulos

    :)
    That's nice. I was not expecting the change to be pushed.
    You are correct about the logicalFunction of course ( http://wxpython.org/Phoenix/docs/html/DC.html#DC.Blit ), although I had to use rop on one platform
    ( http://www.wxpython.org/docs/api/wx.DC-class.html#Blit )
    I had thought that the image would be behind the background so I tried to remove it from normal.
    Unfortunately I am facing the same problem. When I use a PNG with transparency I can't see it in the preview (it prints as normally). On the other hand if a jpg is used I can see it normally.

     
  • Werner F. Bruhin

    Hi,

    I pushed it, if it is found not worthwhile it can always be removed again:).

    wxPython 2.8.9 is very very .... very old:), I wouldn't got back to less then 2.8.12

    Did you use the code from Bitbucket to test, the thing which made it work for me was the addition of the 'IsDrawOver' method in ListCtrlPrinter.ImageDecoration.

     
  • Gregory Papadopoulos

    Hi,
    yes I am using the latest code from Bitbucket.
    Obviously 2.8.12 is not my main profile, but I have to test my code over Linux (Mint).
    I am running latest wxPython Python 2.7 on Windows 7

     
  • Werner F. Bruhin

    Hi,

    I see it the problem now too - used a wrong image before. Will keep looking into it.

    Werner

     
  • Werner F. Bruhin

    Hhm, the DC used is different for preview see:
    http://wxpython.org/Phoenix/docs/html/Printout.html#Printout.GetDC

    Can you try with this code in ImageDecoration.DrawDecoration, seems to work for me:

        if isinstance(dc, wx.PrinterDC):
            # as suggested by G. Papadopoulos on ovl discussion list
            # nicer handling of e.g. .png images, but doesn't work on preview
            mdc = wx.MemoryDC()
            mdc.SelectObject(self.bitmap)
            dc.Blit(x, y, self.bitmap.GetWidth(), self.bitmap.GetHeight(),
                    mdc, xsrc=0, ysrc=0, useMask=True)
            mdc.SelectObject(wx.NullBitmap)         
        else:
            dc.DrawBitmap(self.bitmap, x, y, True)
    
     
  • Gregory Papadopoulos

    Yes it works!
    To be honest I was thinking a similar (most probably identical) solution. Perfect!
    Just a quick question. Shouldn't we implement the check for "other platforms" as well:
    if isinstance(dc, wx.PrinterDC) or isinstance(dc, wx.PostScriptDC):

     
  • Werner F. Bruhin

    Great that it works.

    Can't test other platforms at this point, but you are right it should handle both.

    Werner

     
  • Gregory Papadopoulos

    A quick test showed that it works on Linux as well.

    Thanks a lot for your help. As I said I am new at working with olv, if any other ideas come to mind...

     

Log in to post a comment.