ask for help by printing a BufferedBitmap

*ask for help by printing a <wx._gdi.Bitmap; proxy of C++ wxBitmap instance at _78e43601_p_wxBitmap>*

dear reader,

i ask kindly for your input and help

*I draw to an EmptyBitmap (self._buffer) a few things.*

something like that:

    def MakeBufferBitmap(self):
        # Initialize the buffer bitmap. No real DC is needed at this point.
        self._buffer = wx.EmptyBitmap(self.ScrolledWindowMaxWidth, self.ScrolledWindowMaxHeight)
        dc = wx.BufferedDC(None, self._buffer)
        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()
        return dc
        *When the user presses a SHOW button I show this:*

    def TEST(self):
        #dc = wx.BufferedDC(wx.ClientDC(self), self._buffer) # Short version
        print self._buffer # <wx._gdi.Bitmap; proxy of C++ wxBitmap instance at _78e43601_p_wxBitmap>
        dc = wx.MemoryDC()
        dc.SelectObject(self._buffer)
        wx.ClientDC(self).Blit(0, 0, self.ScrolledWindowMaxWidth, self.ScrolledWindowMaxHeight, dc, 0, 0)
        *When the user presses a SAVE_image button I save this:*

    def Save_AS_Image(self,FileName,FileType):
        ## This will save the contents of the buffer
        ## to the specified file. See the wxWindows docs for
        ## wxBitmap::SaveFile for the details
        self._buffer.SaveFile(FileName,FileType)
        
*When the user presses a PrintPriewView button I want to PrintPreview this and afterwards print it:

*How can I print preview / preview the drawing on self._buffer

Thanks so much - small code would be helpful because I'm a wxpython beginner.

MrJanes

First a few comments on your code:

MJ_Python wrote:

   def MakeBufferBitmap(self):
       # Initialize the buffer bitmap. No real DC is needed at this point.
       self._buffer = wx.EmptyBitmap(self.ScrolledWindowMaxWidth, self.ScrolledWindowMaxHeight)
       dc = wx.BufferedDC(None, self._buffer)

if you only want to draw to a Bitmap, you should use a wxMemoryDC:

dc = wx.MemoryDC(self._Buffer)

wx.BufferedDC is explicitly for drawing to another DC, while keeping a copy in a buffer. Passing None to it may well just give your the MemoryDC, but there is probably at least a little wasted overhead.

   def TEST(self):
       #dc = wx.BufferedDC(wx.ClientDC(self), self._buffer) # Short version
       print self._buffer # <wx._gdi.Bitmap; proxy of C++ wxBitmap instance at _78e43601_p_wxBitmap>
       dc = wx.MemoryDC()
       dc.SelectObject(self._buffer)
       wx.ClientDC(self).Blit(0, 0, self.ScrolledWindowMaxWidth, self.ScrolledWindowMaxHeight, dc, 0, 0)

This can be made easier this way:
def TEST(self):
        wx.ClientDC(self).DrawBitmap(self._buffer,0,0)

   def Save_AS_Image(self,FileName,FileType):
       ## This will save the contents of the buffer
       ## to the specified file. See the wxWindows docs for
       ## wxBitmap::SaveFile for the details
       self._buffer.SaveFile(FileName,FileType)

this looks good.

*When the user presses a PrintPriewView button I want to PrintPreview this and afterwards print it:

*How can I print preview / preview the drawing on self._buffer

You should be able to call .DrawBitmap() on a wx.PrinterDC, just like any other DC call. Look in the docs and demo for the Print Framework, and adapt that code.

By they way, you might want to check out:

http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

for some other ideas.

Another note: How are you creating your _buffer Bitmap? if it is really a buffer, I imagine you are drawing to it with wx.DC calls to create it. In this case, you can just make the same calls to a wx.PrinterDC to print it, rather than trying to directly print the bitmap. This will work much better, because your printer is probably a different resolution than your screen.

Which reminds me: I should perhaps add printing to the above Wiki Page. If you figure it out, maybe you could add it!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thanks Chris,

it really helped me - for now I will use the option with the .DrawBitmap()

By the way: I'm still a real wxpython beginner - I do not feel comfortable to add to the Wiki Page.

-MrJanes

Chris Barker wrote:

···

*How can I print preview / preview the drawing on self._buffer

*When the user presses a PrintPriewView button I want to PrintPreview this and afterwards print it:

You should be able to call .DrawBitmap() on a wx.PrinterDC, just like any other DC call. Look in the docs and demo for the Print Framework, and adapt that code.

By they way, you might want to check out:

http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

for some other ideas.

Another note: How are you creating your _buffer Bitmap? if it is really a buffer, I imagine you are drawing to it with wx.DC calls to create it. In this case, you can just make the same calls to a wx.PrinterDC to print it, rather than trying to directly print the bitmap. This will work much better, because your printer is probably a different resolution than your screen.

Which reminds me: I should perhaps add printing to the above Wiki Page. If you figure it out, maybe you could add it!

-Chris

MJ_Python wrote:

Thanks Chris,

it really helped me - for now I will use the option with the .DrawBitmap()

good to hear.

By the way: I'm still a real wxpython beginner - I do not feel comfortable to add to the Wiki Page.

I understand. If you get printing working with the BufferedWindow demo, which would be a good exercise, please send it to this list and/or to me, and we can review it and maybe post it on the Wiki.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

MJ_Python wrote:

By the way: I'm still a real wxpython beginner - I do not feel comfortable to add to the Wiki Page.

Please don't feel that you need to be a Pro or a Guru to add things to the wiki. The wiki is for anybody who knows or has figured out something that they want to share with those who don't know it yet. If you get something wrong in what you write then somebody will eventually correct it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!