473,493 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HELP Printing with wxPython

Hello all, I'm trying hard to make possible to print some simple text from
python to the default printer using wxPython, after days of internet
searches I found this page: http://wiki.wxpython.org/index.cgi/Printing but
is impossible to use this script even if I do exactly as said there. I think
the script is buggy or I am not able to use it, even if seems very simple to
use...

Anyone can give me an hint on how to easily and simply print some text? Is
there a library ready to download and use? Something like SendPrinter("some
text\n")?

Thanks in advance if anyone can give any help.

Mario
Jul 19 '05 #1
10 4931
> Hello all, I'm trying hard to make possible to print some simple text
from
python to the default printer using wxPython, after days of internet
searches I found this page: http://wiki.wxpython.org/index.cgi/Printing but is impossible to use this script even if I do exactly as said there. I think the script is buggy or I am not able to use it, even if seems very simple to use...

Anyone can give me an hint on how to easily and simply print some text? Is there a library ready to download and use? Something like SendPrinter("some text\n")?


On the strict wxPython front, I can't help
you, but I might be able to offer some help.
Depends a little bit on how much you're tied
to wxPython and how much you need to be cross-platform.

Essentially, if you're on Windows (and have no need
to run on anything else) then consider some of the
solutions here:

http://tgolden.sc.sabren.com/python/...o_i/print.html

If you're on Unix / whatever with no need to do
anything else, then I'm sure there are straightforward
ways to push stuff to a printer. (Something using lpr
he thinks, hoping someone with real knowledge can chip
in).

If you *really* want to use wxPython for cross-platform
needs, or just because you think it's cleaner, then try
on the wxPython lists if you haven't already.

TJG

Jul 19 '05 #2
Mario,

Here is a function stripped from a working program that uses printpreview
from wxWindows to print out cells from a grid that the user is working
on. Hopefully this can point you in the proper direction.

Regards,
Larry Bates

def DO_printpreview(self, event):
if self._trace:
self.logf.writelines("T","Entering OuterFrame.DO_printpreview")
self.SetStatusText('Generating Print Preview', 0)
#
# Define the columns on the printout
#
columndefs=(("Cust#", 8.0/16.0, wxALIGN_LEFT),
("Customer Name", 29.0/16.0, wxALIGN_LEFT),
("Reference", 16.0/16.0, wxALIGN_LEFT),
("Type", 6.0/16.0, wxALIGN_CENTRE),
("Inv. #", 8.0/16.0, wxALIGN_CENTRE),
("InvDate", 9.0/16.0, wxALIGN_CENTRE),
("L#", 4.0/16.0, wxALIGN_CENTRE),
("Item #", 12.0/16.0, wxALIGN_CENTRE),
("Item Description",45.0/16.0, wxALIGN_LEFT),
("Qty", 6.0/16.0, wxALIGN_RIGHT),
("Cost", 10.0/16.0, wxALIGN_RIGHT),
("OMMC $", 10.0/16.0, wxALIGN_RIGHT)
)
columncount=len(columndefs)
#
# Create a new frame for the print preview and give it to PrintTable
#
self.previewframe=PreviewFrame(None, sys.stdout)
if self._trace:
log.writelines("T","DO_ppv-Creating PrintTable instance")
prt=PrintTable(self.previewframe)
#
# Set printout column widths
#
if self._trace: self.logf.writelines("T","DO_ppv-Setting column widths")
prt.set_column=[a[1] for a in columndefs]
#
# Set the column labels (headings)
#
if self._trace:
self.logf.writelines("T","DO-ppv-Setting column headings")
prt.label=[a[0] for a in columndefs]
#
# Set the column alignments
#
if self._trace:
self.logf.writelines("T", "DO-ppv-Setting column alignments")
map(prt.SetColAlignment, range(columncount), [a[2] for a in columndefs])
#
# Get the data values from the grid that are selected
#
data=self._getdata('1')
#
# Skip the first (flag) column and columns 11,13,15,16
# to delete them from the printout.
#
data=[[v[1],v[2],v[3],v[4][0:2],v[5],v[6],
v[7],v[8],v[9],v[10],v[12],v[14]] for v in data]
#
# Loop over the lines and insert a blank line between customers
#
blankline=columncount*[''] # Create a blank output line
lastcustomer=None
pdata=[]
for values in data:
if lastcustomer != None and values[0] != lastcustomer:
pdata.append(blankline)

lastcustomer=values[0]
pdata.append(values)

pdata.append(blankline)
prt.data=pdata
prt.left_margin=0.3
prt.SetLandscape()
prt.SetHeader("OMMC Recap Listing-Hardware Items")
prt.SetFooter()
prt.SetFooter("Date: ", type = "Date & Time", \
align=wxALIGN_LEFT, \indent=prt.left_margin)
#
# Override the default font sizes
#
prt.text_font_size = 8
#prt.label_font_size= 7
prt.cell_left_margin = 1.0/32.0
prt.Preview()
if self._trace:
self.logf.writelines("T","Entering OuterFrame.DO_printpreview")
return
Mario wrote:
Hello all, I'm trying hard to make possible to print some simple text from
python to the default printer using wxPython, after days of internet
searches I found this page: http://wiki.wxpython.org/index.cgi/Printing but
is impossible to use this script even if I do exactly as said there. I think
the script is buggy or I am not able to use it, even if seems very simple to
use...

Anyone can give me an hint on how to easily and simply print some text? Is
there a library ready to download and use? Something like SendPrinter("some
text\n")?

Thanks in advance if anyone can give any help.

Mario

Jul 19 '05 #3
Hi Mario,
Something like SendPrinter("some text\n")?
If you are doing this just for yourself, and you know you have a
printer that will really print just the plain text when you send it
plain text (like a dot matrix printer from the early 90s) then you can
probably open the printer device and send it text. Under windows you
can try opening LPT1 or on unix it's probably /dev/lpr or something
like that.

wxPython makes it pretty easy to give full modern support for any
printer, including letting the user select which printer to print to,
and getting a print preview, choosing paper size, etc.

I especially like the HtmlEasyPrinting write-up here:
http://wiki.wxpython.org/index.cgi/Printing

-Jim


On 5/11/05, Mario <ma***@nospam.noext> wrote: Hello all, I'm trying hard to make possible to print some simple text from
python to the default printer using wxPython, after days of internet
searches I found this page: http://wiki.wxpython.org/index.cgi/Printing but
is impossible to use this script even if I do exactly as said there. I think
the script is buggy or I am not able to use it, even if seems very simpleto
use...

Anyone can give me an hint on how to easily and simply print some text? Is
there a library ready to download and use? Something like SendPrinter("some
text\n")?

Thanks in advance if anyone can give any help.

Mario

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #4

"Tim G" <ti********@viacom-outdoor.co.uk> wrote:
Essentially, if you're on Windows (and have no need
to run on anything else) then consider some of the
solutions here:

http://tgolden.sc.sabren.com/python/...o_i/print.html


That was exactly what I needed! Thanks SO MUCH! :) I tested all the
different things and worked perfectly with no problem.

Thanks again, I was trying to do the printing since a lot but never seen
that windows api thing before.

Mario

Jul 19 '05 #5

"Larry Bates" <lb****@syscononline.com> ha scritto nel messaggio
news:42**************@syscononline.com...
Mario,

Here is a function stripped from a working program that uses printpreview
from wxWindows to print out cells from a grid that the user is working
on. Hopefully this can point you in the proper direction.


Thank you very much for the help, I will study all the code that you sent me
for a future and a more professional programming, for now I used a very
simple win32api call, not very evolved but working fine for what I needed,
since what I am doing needs to run only on a windows machine.

Thanks again :)

Mario

Jul 19 '05 #6

"James Carroll" <mr*****@gmail.com> wrote:
I especially like the HtmlEasyPrinting write-up here:
http://wiki.wxpython.org/index.cgi/Printing


Thank you for your suggestion but I'm just not able to make it work, as i
said on the original post, I do exactly what is wrote there, but it gives
errors, I think the script is not updated and not working fine with the
latest versions of python or wxpython.

Mario


Jul 19 '05 #7
James Carroll <mr*****@gmail.com> writes:
If you are doing this just for yourself, and you know you have a
printer that will really print just the plain text when you send it
plain text (like a dot matrix printer from the early 90s) then you can
probably open the printer device and send it text. Under windows you
can try opening LPT1 or on unix it's probably /dev/lpr or something
like that.


Under Unix, you shouldn't be able to open the line printer, whether
it's /dev/lpr or /dev/lpt0 or whater. You shouldn't have
permission.

Instead, as was suggested earlier, use the "lpr" command and send it
the text/data on standard input. Any reasonably managed Unix system
should be able to handle a fair range of graphics formats, though
postscript is preferred.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #8
On Thursday 12 May 2005 04:56 am, Mike Meyer wrote:
James Carroll <mr*****@gmail.com> writes:
If you are doing this just for yourself, and you know you have a
printer that will really print just the plain text when you send it
plain text (like a dot matrix printer from the early 90s) then you can
probably open the printer device and send it text. Under windows you
can try opening LPT1 or on unix it's probably /dev/lpr or something
like that.


Under Unix, you shouldn't be able to open the line printer, whether
it's /dev/lpr or /dev/lpt0 or whater. You shouldn't have
permission.

Instead, as was suggested earlier, use the "lpr" command and send it
the text/data on standard input. Any reasonably managed Unix system
should be able to handle a fair range of graphics formats, though
postscript is preferred.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more
information.


I've been using:

p=os.popen('lp','w')
p.write("some text')
p.Close()
Jeff

Jul 19 '05 #9
jeff elkins <je********@earthlink.net> writes:
Instead, as was suggested earlier, use the "lpr" command and send it
the text/data on standard input. Any reasonably managed Unix system
should be able to handle a fair range of graphics formats, though
postscript is preferred.

I've been using:

p=os.popen('lp','w')
p.write("some text')
p.Close()


Yeah. System V called it lp. BSD called it lpr. Most modern systems
have both, as they are just a front end to the line printer (when was
the last time you saw an honest-to-gods line printer?) daemon.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #10
There's a working version in the wxPython Demo...

If you run the wxpython demo, and choose Print Framework under
Miscellaneous it has code that looks a whole lot like what's on the
wiki, only you can test it and try it out and see if it's broken for
you there. If anything doesn't work, let the wxPython mailing list
people know about it, and they'll have a work-around or a fix (or show
you what you should be doing) in no time.

-Jim
On 5/11/05, Mario <ma***@nospam.noext> wrote:

"James Carroll" <mr*****@gmail.com> wrote:
I especially like the HtmlEasyPrinting write-up here:
http://wiki.wxpython.org/index.cgi/Printing


Thank you for your suggestion but I'm just not able to make it work, as i
said on the original post, I do exactly what is wrote there, but it gives
errors, I think the script is not updated and not working fine with the
latest versions of python or wxpython.

Mario

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2754
by: Fuzzyman | last post by:
I looked through the manual, I looked on the web and could find very little on this subject.... The closest I could find was : http://www.faqts.com/knowledge_base/view.phtml/aid/4549. Saying...
2
2978
by: Darcy Kahle | last post by:
I am trying to do some advanced printing in python using the win32ui module, and have run into an issue. I need to print a page landscape. As I could not determine how to specify the orientation...
1
2588
by: uri bushey | last post by:
So I have a tkinter based little program in Python that has a canvas loaded with a WaveSurfer (http://www.speech.kth.se/wavesurfer/) widget. I am trying to print the contents of the WaveSurfer...
8
2394
by: David Isaac | last post by:
"Alan Isaac" <aisaac0@verizon.net> wrote in message news:_A34e.2207$1r6.248@trnddc02... > I'd like to try personal financial management using Python. > I just found PyCheckbook, but it does not...
3
4765
by: Fabio Pliger | last post by:
Hi! I'm using wxPython to handle my application gui.. So, I have a notebook widget and i have to print the object inside it's tab ... Maybe doing a preview before printing... I know that wx has...
3
1901
by: Max | last post by:
How can I print (as in laser printer, not the python print statement) HTML from Python (actually it doesn't have to be HTML - it's tabular data with some rows/columns highlited). The project...
5
1566
by: MatthewWarren | last post by:
Hi, I'm wondering if anyone can tell me here, or point to a specific tutorial ( I have searched for 1/2hour, but can find only reference style docs or not-quite-what-im-after help) on how to build...
1
1855
by: Eric von Horst | last post by:
Hi, I need some advice on Drag&Drop. What I want to achieve is the following: - I have a window that is divided in two : on the left hand I have a wx.TreeCtlr and on the other hand a...
3
1032
by: azrael | last post by:
I need to implement a tree which will append a root. Any other node in the tree will be triggered when a button is pressed. I created the button, all the needed events, tree and a root. But when I...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.