Printing from STC

Let's say I have an app that uses a wx.stc.StyledTextCtrl to display some lengthy Python code in all its syntax-colored glory. Is there a way to print out the entire document, preserving all the formatting and such? I've googled around, and while the HtmlEasyPrinting looks like it could handle some basic things, it doesn't do very well with WYSIWYG printing of documents.

  So is there a way to do this, or is this not possible in wxPython?

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

Have a look at the wx.stc.StyledTextCtrl.FormatRange function it will let you render the screen into a Printout DC. Prior to the call to FormatRange you set the print mode of control using SetPrintColourMode with either wx.stc.STC_PRINT_COLOURONWHITE or wx.stc.STC_PRINT_COLOURONWHITEDEFAULTBG you can get the output to include all the coloring.

Regards,
Cody Precord

···

On Jun 10, 2007, at 8:39 AM, Ed Leafe wrote:

  Let's say I have an app that uses a wx.stc.StyledTextCtrl to display some lengthy Python code in all its syntax-colored glory. Is there a way to print out the entire document, preserving all the formatting and such? I've googled around, and while the HtmlEasyPrinting looks like it could handle some basic things, it doesn't do very well with WYSIWYG printing of documents.

  So is there a way to do this, or is this not possible in wxPython?

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

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

Cool, thanks for your help. I had just stumbled upon Editra in the course of my googling, and it looks to be a much more polished version of the Dabo Editor. I'll take a look at your printing code, because it seems to work well, and there is a real lack of good examples for printing from wxPython.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Jun 10, 2007, at 9:52 AM, Cody Precord wrote:

Have a look at the wx.stc.StyledTextCtrl.FormatRange function it will let you render the screen into a Printout DC. Prior to the call to FormatRange you set the print mode of control using SetPrintColourMode with either wx.stc.STC_PRINT_COLOURONWHITE or wx.stc.STC_PRINT_COLOURONWHITEDEFAULTBG you can get the output to include all the coloring.

Looking through the Editra source, I found your reference to Riaan Booysen's STCPrinting.py, which is just what I need for Dabo, since its license is compatible with Dabo's MIT license, so I can adapt that code to be used in Dabo.
  
  Thanks again!

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Jun 10, 2007, at 10:52 AM, Ed Leafe wrote:

  Cool, thanks for your help. I had just stumbled upon Editra in the course of my googling, and it looks to be a much more polished version of the Dabo Editor. I'll take a look at your printing code, because it seems to work well, and there is a real lack of good examples for printing from wxPython.

No problem,

Regards,

Cody Precord

···

On Jun 10, 2007, at 2:07 PM, Ed Leafe wrote:

Riaan Booyse

Ed / Cody,

Could one of you guys post how to do this on the wxPython wiki so the
newbs will be able to print too? I still haven't figured out a good way to
print with wxPython, so I create my print jobs using ReportLab, which is
pretty tedious at best.

Mike

···

-----Original Message-----
From: Ed Leafe [mailto:ed@leafe.com]
Sent: Sunday, June 10, 2007 9:52 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Printing from STC

On Jun 10, 2007, at 9:52 AM, Cody Precord wrote:

> Have a look at the wx.stc.StyledTextCtrl.FormatRange
function it will
> let you render the screen into a Printout DC. Prior to the call to
> FormatRange you set the print mode of control using
SetPrintColourMode
> with either wx.stc.STC_PRINT_COLOURONWHITE or
> wx.stc.STC_PRINT_COLOURONWHITEDEFAULTBG you can get the output to
> include all the coloring.

  Cool, thanks for your help. I had just stumbled upon
Editra in the course of my googling, and it looks to be a
much more polished version of the Dabo Editor. I'll take a
look at your printing code, because it seems to work well,
and there is a real lack of good examples for printing from wxPython.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

I'm still getting the kinks worked out of Linux printing, but I've gotten it working on Windows and Mac.

  Bear in mind that this only works with STC content, and is not a generic wxPython printing solution. I don't think such a beast exists.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Jun 11, 2007, at 5:27 PM, Mike Driscoll wrote:

Could one of you guys post how to do this on the wxPython wiki so the
newbs will be able to print too? I still haven't figured out a good way to
print with wxPython, so I create my print jobs using ReportLab, which is
pretty tedious at best.

Ed Leafe wrote:

Is not a
generic wxPython printing solution. I don't think such a beast exists.

I think what people want (and doesn't exist), is not a printing solution (wxPrintDC works pretty well), but rather a layout/typesetting solution.

wxHTMLEasyPrinting

is the closest we have.

Unfortunately, layout and typesetting (particularly decent typesetting) is a very hard problem. I know I'd love to have TeX embedded to do typesetting for me, but alas, TeX is not designed to be embedded. There have been folks working on it in the past, but I don't think anything has come of those efforts.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (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

> Could one of you guys post how to do this on the wxPython
wiki so the
> newbs will be able to print too? I still haven't figured out a good
> way to
> print with wxPython, so I create my print jobs using ReportLab,
> which is
> pretty tedious at best.

  I'm still getting the kinks worked out of Linux
printing, but I've
gotten it working on Windows and Mac.

  Bear in mind that this only works with STC content, and
is not a
generic wxPython printing solution. I don't think such a beast exists.

You know, it could be pretty close to a generic wxPython printing solution
when you're done, at least for text-based printing needs.

For the last several years, I've used the wxPrintOut class to produce
print-preview style reports for Transana. It worked okay, in a limited sort
of a way, but my users wanted to be able to do things like save their output
to RTF or text, and to edit the reports live. I'm just about done
converting all of my reports to being wx.STC-based. To create a report, I
define a few styles, and create the report as a wx.stc document, which I can
then edit, export to RTF (in a VERY limited way,) or print. (My method for
sending my wx.stc output to the printer really sucks, especially compared to
what you're discussing, which is why I've stayed quiet on this topic up to
now.)

My point is that the STC can be used to create a generic text-based report
generator pretty easily. Adding graphics is of course another story, but I
would think this would meet the needs of a lot of users.

And how hard would it be to move from STC to the RichTextCtrl when that's a
little more mature? That's solve your line-height problems and you'd be
able to insert graphics.

Just a thought.

David

And how hard would it be to move from STC to the RichTextCtrl when that's a
little more mature? That's solve your line-height problems and you'd be
able to insert graphics.
  

I'm just a newbie to Python,
but isn't possible to use an existing activeX or Java Rich Edit component,
almost each wiki system has one ow adays.

cheers,
Stef Mientki

I figured as much. Still, there's not much for printing documentation
anyway and I'm not seeing much but source docs on STC on the wiki either.

Mike

···

-----Original Message-----
From: Ed Leafe [mailto:ed@leafe.com]
Sent: Monday, June 11, 2007 4:39 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Printing from STC

On Jun 11, 2007, at 5:27 PM, Mike Driscoll wrote:

> Could one of you guys post how to do this on the wxPython
wiki so the
> newbs will be able to print too? I still haven't figured out a good
> way to print with wxPython, so I create my print jobs using
ReportLab,
> which is pretty tedious at best.

  I'm still getting the kinks worked out of Linux
printing, but I've gotten it working on Windows and Mac.

  Bear in mind that this only works with STC content, and
is not a generic wxPython printing solution. I don't think
such a beast exists.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

hello Ed,

Ed Leafe wrote:

Could one of you guys post how to do this on the wxPython wiki so the
newbs will be able to print too? I still haven't figured out a good way to
print with wxPython, so I create my print jobs using ReportLab, which is
pretty tedious at best.

    I'm still getting the kinks worked out of Linux printing, but I've gotten it working on Windows and Mac.

Is your code available ?
I (and maybe a few others on this list?) love to see more examples for STC printing (and other things :wink:
I just downloaded STCPrinting.py from BOA,
but it has a lot of dependancies to modules that I don't have.

thanks,
Stef Mientki

···

On Jun 11, 2007, at 5:27 PM, Mike Driscoll wrote:
    Bear in mind that this only works with STC content, and is not a generic wxPython printing solution. I don't think such a beast exists.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

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

You can see the current state of the code in the dabo.ui.dEditor class. You can either download the framework, or view it online:

http://svn.dabodev.com/trac/dabo/browser/trunk/dabo/ui/uiwx/dEditor.py
( -or- http://tinyurl.com/2ft7ft )

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Oct 6, 2007, at 3:24 PM, Stef Mientki wrote:

Could one of you guys post how to do this on the wxPython wiki so the
newbs will be able to print too? I still haven't figured out a good way to
print with wxPython, so I create my print jobs using ReportLab, which is
pretty tedious at best.

    I'm still getting the kinks worked out of Linux printing, but I've gotten it working on Windows and Mac.

Is your code available ?
I (and maybe a few others on this list?) love to see more examples for STC printing (and other things :wink:
I just downloaded STCPrinting.py from BOA,
but it has a lot of dependancies to modules that I don't have.

Ed Leafe wrote:

Could one of you guys post how to do this on the wxPython wiki so the
newbs will be able to print too? I still haven't figured out a good way to
print with wxPython, so I create my print jobs using ReportLab, which is
pretty tedious at best.

    I'm still getting the kinks worked out of Linux printing, but I've gotten it working on Windows and Mac.

Is your code available ?
I (and maybe a few others on this list?) love to see more examples for STC printing (and other things :wink:
I just downloaded STCPrinting.py from BOA,
but it has a lot of dependancies to modules that I don't have.

    You can see the current state of the code in the dabo.ui.dEditor class. You can either download the framework, or view it online:

http://svn.dabodev.com/trac/dabo/browser/trunk/dabo/ui/uiwx/dEditor.py
( -or- http://tinyurl.com/2ft7ft )

thanks very much Ed,
after borrowing 10 lines of code from you,
I got the printpreview and from there the printer working
(nicely filename on top, now pagenr on bottom and it's complete :wink:
Scaling is not yet good.
PrintPreview has weird scaling settings (sorry Robin if your reading this ;-),
why not simple: fit width / fit height / 100%
And I wonder why we need po1 and po2 to send to PrintPreview.

cheers,
Stef Mientki

···

On Oct 6, 2007, at 3:24 PM, Stef Mientki wrote:

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

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

Stef Mientki wrote:

Ed Leafe wrote:

Could one of you guys post how to do this on the wxPython wiki so the
newbs will be able to print too? I still haven't figured out a good way to
print with wxPython, so I create my print jobs using ReportLab, which is
pretty tedious at best.

    I'm still getting the kinks worked out of Linux printing, but I've gotten it working on Windows and Mac.

Is your code available ?
I (and maybe a few others on this list?) love to see more examples for STC printing (and other things :wink:
I just downloaded STCPrinting.py from BOA,
but it has a lot of dependancies to modules that I don't have.

    You can see the current state of the code in the dabo.ui.dEditor class. You can either download the framework, or view it online:

http://svn.dabodev.com/trac/dabo/browser/trunk/dabo/ui/uiwx/dEditor.py
( -or- http://tinyurl.com/2ft7ft )

thanks very much Ed,
after borrowing 10 lines of code from you,
I got the printpreview and from there the printer working
(nicely filename on top, now pagenr on bottom and it's complete :wink:
Scaling is not yet good.
PrintPreview has weird scaling settings (sorry Robin if your reading this ;-),

No offense taken. I've also always been at least partially bewildered by the wx printing framework.

why not simple: fit width / fit height / 100%
And I wonder why we need po1 and po2 to send to PrintPreview.

In case there needs to be different methods or settings for rendering the pages in preview vs. print modes, since the user can select to print from the preview window.

···

On Oct 6, 2007, at 3:24 PM, Stef Mientki wrote:

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

hi Ed,

I think I improved the code a little bit.
scaling is better now and solved some problems with header fonts and stc fonts.
Printing and page-setup works perfect,
printpreview is clumsy,
but I guess that's due to limitations in either or both PrintPreview / Scintilla rendering
(or my not fully understanding of scaling etc. :wink:

thanks and cheers,
Stef

Ed Leafe wrote:

stc_printer_code.py (6.63 KB)

···

On Oct 6, 2007, at 3:24 PM, Stef Mientki wrote:

Could one of you guys post how to do this on the wxPython wiki so the
newbs will be able to print too? I still haven't figured out a good way to
print with wxPython, so I create my print jobs using ReportLab, which is
pretty tedious at best.

    I'm still getting the kinks worked out of Linux printing, but I've gotten it working on Windows and Mac.

Is your code available ?
I (and maybe a few others on this list?) love to see more examples for STC printing (and other things :wink:
I just downloaded STCPrinting.py from BOA,
but it has a lot of dependancies to modules that I don't have.

    You can see the current state of the code in the dabo.ui.dEditor class. You can either download the framework, or view it online:

http://svn.dabodev.com/trac/dabo/browser/trunk/dabo/ui/uiwx/dEditor.py
( -or- http://tinyurl.com/2ft7ft )

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com