About Printing from a wxApp

Hi, Regards from Argentina.
I'm learning wxPython by myself with the demo and some books and
tutorials. The printing action is something that I can't understand. I
really put my energy on it but I can't make a printing.
I put below a simple editor code with a printing function. The dialog
and the setup appears but a white paper is on it. Obviously, I want to
print what I xrite in the wxTextCtrl. Can anybody help me?

Thank you a lot!

#-*- coding: UTF8 -*-
import wx

class MainWIndow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title, pos=(300,
300), size=(400, 400))
        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
        self.CreateStatusBar()
        filemenu = wx.Menu()
        filemenu.Append(3, '&About', 'Data del programa')
        filemenu.Append(4, '&Print', 'Imprimir')
        filemenu.AppendSeparator()
        filemenu.Append(5, '&Exit', 'Salir')
        menuBar= wx.MenuBar()
        menuBar.Append(filemenu, '&File')
        self.SetMenuBar(menuBar)
        wx.EVT_MENU(self, 3, self.OnAbout)
        wx.EVT_MENU(self, 4, self.OnPrint)
        wx.EVT_MENU(self, 5, self.OnExit)
        self.control.SetFocus()
        self.Show(True)

    def OnAbout(self, e):
        info = wx.AboutDialogInfo()
        info.Name = 'Editor Simple'
        info.Version = '0.3'
        wx.AboutBox(info)

    def OnPrint(self, e):
        printout = wx.Printout(self.control.GetValue())
        impresora = wx.Printer()
        impresora.Print(None, printout, prompt=True)

    def OnExit(self, e):
        self.Close()

app = wx.PySimpleApp()
frame = MainWIndow(None, -1, 'Editor Simple')
app.MainLoop()

···

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

I personally recommend using ReportLab instead
(http://www.reportlab.org/). It has its own complications, but the
printing framework in wxPython is so complicated that it's almost
impossible to use unless you're the venerable Robin Dunn. If you have a
simple doc, I hear that the HtmlEasyPrinting widget is fairly easy to use
though. See http://wiki.wxpython.org/Printing

I wish you much luck.

Mike

···

-----Original Message-----
From: Javier Castrillo [mailto:riverplatense@gmail.com]
Sent: Wednesday, October 10, 2007 8:48 AM
To: wxPython-users@lists.wxwidgets.org
Subject: About Printing from a wxApp

Hi, Regards from Argentina.
I'm learning wxPython by myself with the demo and some books
and tutorials. The printing action is something that I can't
understand. I really put my energy on it but I can't make a printing.
I put below a simple editor code with a printing function.
The dialog and the setup appears but a white paper is on it.
Obviously, I want to print what I xrite in the wxTextCtrl.
Can anybody help me?

Thank you a lot!

#-*- coding: UTF8 -*-
import wx

class MainWIndow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title,
pos=(300, 300), size=(400, 400))
        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
        self.CreateStatusBar()
        filemenu = wx.Menu()
        filemenu.Append(3, '&About', 'Data del programa')
        filemenu.Append(4, '&Print', 'Imprimir')
        filemenu.AppendSeparator()
        filemenu.Append(5, '&Exit', 'Salir')
        menuBar= wx.MenuBar()
        menuBar.Append(filemenu, '&File')
        self.SetMenuBar(menuBar)
        wx.EVT_MENU(self, 3, self.OnAbout)
        wx.EVT_MENU(self, 4, self.OnPrint)
        wx.EVT_MENU(self, 5, self.OnExit)
        self.control.SetFocus()
        self.Show(True)

    def OnAbout(self, e):
        info = wx.AboutDialogInfo()
        info.Name = 'Editor Simple'
        info.Version = '0.3'
        wx.AboutBox(info)

    def OnPrint(self, e):
        printout = wx.Printout(self.control.GetValue())
        impresora = wx.Printer()
        impresora.Print(None, printout, prompt=True)

    def OnExit(self, e):
        self.Close()

app = wx.PySimpleApp()
frame = MainWIndow(None, -1, 'Editor Simple')
app.MainLoop()

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo)
<riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

Hi, Regards from Argentina.
I'm learning wxPython by myself with the demo and some books
and tutorials. The printing action is something that I can't
understand. I really put my energy on it but I can't make a printing.
I put below a simple editor code with a printing function.
The dialog and the setup appears but a white paper is on it.
Obviously, I want to print what I xrite in the wxTextCtrl.
Can anybody help me?

Thank you a lot!

#-*- coding: UTF8 -*-
import wx

class MainWIndow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title,
pos=(300, 300), size=(400, 400))
        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
        self.CreateStatusBar()
        filemenu = wx.Menu()
        filemenu.Append(3, '&About', 'Data del programa')
        filemenu.Append(4, '&Print', 'Imprimir')
        filemenu.AppendSeparator()
        filemenu.Append(5, '&Exit', 'Salir')
        menuBar= wx.MenuBar()
        menuBar.Append(filemenu, '&File')
        self.SetMenuBar(menuBar)
        wx.EVT_MENU(self, 3, self.OnAbout)
        wx.EVT_MENU(self, 4, self.OnPrint)
        wx.EVT_MENU(self, 5, self.OnExit)
        self.control.SetFocus()
        self.Show(True)

    def OnAbout(self, e):
        info = wx.AboutDialogInfo()
        info.Name = 'Editor Simple'
        info.Version = '0.3'
        wx.AboutBox(info)

    def OnPrint(self, e):
        printout = wx.Printout(self.control.GetValue())
        impresora = wx.Printer()
        impresora.Print(None, printout, prompt=True)

    def OnExit(self, e):
        self.Close()

app = wx.PySimpleApp()
frame = MainWIndow(None, -1, 'Editor Simple')
app.MainLoop()

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo)
<riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre

I personally recommend using ReportLab instead
(http://www.reportlab.org/). It has its own complications, but the
printing framework in wxPython is so complicated that it's almost
impossible to use unless you're the venerable Robin Dunn. If you have a
simple doc, I hear that the HtmlEasyPrinting widget is fairly easy to use
though. See http://wiki.wxpython.org/Printing

I wish you much luck.

Mike

Yeah, the print framework takes an hour or two to mess with the print framework and get it figured out, but it really works remarkably well once you "get" it. I would not say that it's near impossible at all. It's really flexible, plus it's fully cross-platform and takes no installation effort. It's nothing to be afraid of.

But for simple docs, HtmlEasyPrinting is much easier.

David

Javier Castrillo wrote:

Hi, Regards from Argentina.
I'm learning wxPython by myself with the demo and some books and
tutorials. The printing action is something that I can't understand. I
really put my energy on it but I can't make a printing.
I put below a simple editor code with a printing function. The dialog
and the setup appears but a white paper is on it. Obviously, I want to
print what I xrite in the wxTextCtrl. Can anybody help me?

    def OnPrint(self, e):
        printout = wx.Printout(self.control.GetValue())
        impresora = wx.Printer()
        impresora.Print(None, printout, prompt=True)

You need to derive your own class from wx.Printout and override methods that control how the print job is drawn on each page that is printed. There is a good example in the book, you can see it in the source repository here:

http://svn.wxwidgets.org/viewvc/wx/wxPython/branches/WX_2_8_BRANCH/samples/wxPIA_book/Chapter-17/printing.py?revision=47034&view=markup

···

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

e

>>
>
> I personally recommend using ReportLab instead
> (http://www.reportlab.org/). It has its own complications, but the
> printing framework in wxPython is so complicated that it's almost
> impossible to use unless you're the venerable Robin Dunn.
If you have
> a simple doc, I hear that the HtmlEasyPrinting widget is
fairly easy
> to use though. See http://wiki.wxpython.org/Printing
>
> I wish you much luck.
>
> Mike

Yeah, the print framework takes an hour or two to mess with
the print framework and get it figured out, but it really
works remarkably well once you "get" it. I would not say
that it's near impossible at all.
It's really flexible, plus it's fully cross-platform and
takes no installation effort. It's nothing to be afraid of.

But for simple docs, HtmlEasyPrinting is much easier.

David

Maybe I should have qualified it better. It's obviously an amazing piece
of code, but for a newbie, it's very hard to get your mind around. I've
been using wxPython almost daily for a year now and I still don't "get
it". Hopefully I will understand it eventually as I would much rather
print with it than create a PDF and use goofy win32 calls to force it to
print.

Mike

Mike, Robin, David, thanks a lot

Regards

···

On 11/10/2007, Mike Driscoll <mdriscoll@co.marshall.ia.us> wrote:

--
Javier Castrillo

=========================================================
GNU / Linux User #242275

-------------------------------
pub 1024D/B482896F 2006-09-04
uid Javier Castrillo (El Palo) <riverplatense@gmail.com>
sub 2048g/52C99A4E 2006-09-04

Clave pública: carapa.com.ar/public.asc
http://carapa.com.ar
http://javiercastrillo.com.ar
http://riverplatense.googlepages.com

Usá Software Libre