XRC to HTML or printing wxFrames

Is it possible to convert stuff defined in XRC to HTML so it can be
printed. Is this where XSL would come into play? Or wouild it be
possible to directly print a wxFrame or wxWindow?

Thanks
Matt

···

--
Don't be a pioneeer. A pioneer is the guy with the arrow through his
chest. -- John J. Rakos

Is it possible to convert stuff defined in XRC to HTML so it can be
printed. Is this where XSL would come into play? Or wouild it be
possible to directly print a wxFrame or wxWindow?

There's no reason you couldn't transform XRC to (X)HTML via XSLT, but
figuring out how to replicate sizers as HTML layout, or various wx
controls that don't have HTML equivilents would be pretty tricky.

The simplest way to print a wxFrame or wxWindow is probably to just
grab a bitmap of it via wxClientDC and print that.

···

On 6/15/05, Matt Kubilus <mattkubilus@gmail.com> wrote:

Thanks
Matt

--
Don't be a pioneeer. A pioneer is the guy with the arrow through his
chest. -- John J. Rakos

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Matt Kubilus wrote:

Is it possible to convert stuff defined in XRC to HTML so it can be
printed. Is this where XSL would come into play? Or wouild it be
possible to directly print a wxFrame or wxWindow?

You can use a wx.WindowDC to Blit a copy of the onscreen image of the window (and its children) into a bitmap which is selected into a wx.MemoryDC. You can then use that bitmap for printing or whatever.

···

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

So, I implemented the following. However I get an error "
wxDIB::Create(): invalid bitmap" at the BLIT command. I do get a very
tiny picture of the frame (I think it's my frame) in the upper left
corner of the page. Any idea what is wrong with my DC.

Thanks,
Matt

from wxPython.wx import *
from wxPython.xrc import *

GUI_FILENAME = "testFramePrintout.xrc"
GUI_MAINFRAME_NAME = "frame_1"

class MyPrintout(wx.Printout):
    def __init__(self, frame, title):
        self.frame1 = frame
        wxPrintout.__init__(self)

    def OnPrintPage(self, pgno):
        dc = self.GetDC()
        dc.BeginDrawing()
        pandc = wx.WindowDC(self.frame1)
        sz = pandc.GetSizeTuple()
        dc.Blit(wxPoint(0,0), wxSize(sz[0], sz[1]), pandc, wxPoint(0,0))
        dc.EndDrawing()

    def GetPageInfo(self):
        return (1, 1, 1, 1)

class MyApp( wx.App ):
    def OnInit( self ):
        self.res = wxXmlResource( GUI_FILENAME )
        self.frame = self.res.LoadFrame(None, GUI_MAINFRAME_NAME )
        self.frame.Show(1)

        printer = wx.Printer()
        printout = MyPrintout(self.frame, "My printout")
        printer.Print(None, printout)

        return 1

if __name__ == '__main__':
    app = MyApp(0)
    app.MainLoop()

Matt Kubilus wrote:

So, I implemented the following. However I get an error "
wxDIB::Create(): invalid bitmap" at the BLIT command.

Try making an intermediate wx.MemoryDC with a bitmap selected into it, then Blit to that and then Blit from there to the page, (or just do a DrawBitmap to get it on the page.)

I do get a very
tiny picture of the frame (I think it's my frame) in the upper left
corner of the page.

Keep in mind that the DPI on screen is fairly small, and on the page it is at least several times larger. So you'll probably want to scale the printer DC so that the bitmap will be larger on the page.

···

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

Thanks Robin,

So I see, I create a MemoryDC and SelectObject a bitmap onto it. Then
when I blit the panel DC onto the MemoryDC, the bitmap becomes a
bitmap 'picture' of the panel DC. So I can then scale this bitmap
which scales by panel picture, and then blit that onto the printer DC.

So as I see it, the bitmap object I originally created remains a
pointer to a location in memory, the SelectObject function associates
that pointer with the MemoryDC, and the Blit function copies data into
the same location that the bitmap points to in memory. Or maybe I'm a
little off.

Whew. A little bit of voodoo here, this is where wxPython shows its C roots.

Heres what I did if anyone else is interested. It works just fine,it
just temporarily uses an awful lot of memory:

    def OnPrintPage(self, pgno):
        dc = self.GetDC()
        dc.StartDoc("Start")
        dc.StartPage()

        printerWidth, printerHeight = dc.GetSizeTuple()

        panelDC = wx.WindowDC(self.panel1)
        panelWidth, panelHeight = panelDC.GetSizeTuple()
        bm = wx.EmptyBitmap(panelWidth, panelHeight)

        temp_dc = wx.MemoryDC()
        temp_dc.SelectObject(bm)
        temp_dc.Blit(wx.Point(0,0), wx.Size(panelWidth, panelHeight),
panelDC, wx.Point(0,0))

        image = wx.ImageFromBitmap(bm)
        image.Rescale(printerWidth, printerHeight)

        bm2 = wx.BitmapFromImage(image)
        dc.DrawBitmap(bm2, wx.Point(0,0))

        dc.EndPage()
        dc.EndDoc()