473,614 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ 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("so me
text\n")?

Thanks in advance if anyone can give any help.

Mario
Jul 19 '05 #1
10 4958
> 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("so me 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.write lines("T","Ente ring OuterFrame.DO_p rintpreview")
self.SetStatusT ext('Generating Print Preview', 0)
#
# Define the columns on the printout
#
columndefs=(("C ust#", 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.previewfra me=PreviewFrame (None, sys.stdout)
if self._trace:
log.writelines( "T","DO_ppv-Creating PrintTable instance")
prt=PrintTable( self.previewfra me)
#
# Set printout column widths
#
if self._trace: self.logf.write lines("T","DO_p pv-Setting column widths")
prt.set_column=[a[1] for a in columndefs]
#
# Set the column labels (headings)
#
if self._trace:
self.logf.write lines("T","DO-ppv-Setting column headings")
prt.label=[a[0] for a in columndefs]
#
# Set the column alignments
#
if self._trace:
self.logf.write lines("T", "DO-ppv-Setting column alignments")
map(prt.SetColA lignment, range(columncou nt), [a[2] for a in columndefs])
#
# Get the data values from the grid that are selected
#
data=self._getd ata('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=colum ncount*[''] # Create a blank output line
lastcustomer=No ne
pdata=[]
for values in data:
if lastcustomer != None and values[0] != lastcustomer:
pdata.append(bl ankline)

lastcustomer=va lues[0]
pdata.append(va lues)

pdata.append(bl ankline)
prt.data=pdata
prt.left_margin =0.3
prt.SetLandscap e()
prt.SetHeader(" OMMC Recap Listing-Hardware Items")
prt.SetFooter()
prt.SetFooter(" Date: ", type = "Date & Time", \
align=wxALIGN_L EFT, \indent=prt.lef t_margin)
#
# Override the default font sizes
#
prt.text_font_s ize = 8
#prt.label_font _size= 7
prt.cell_left_m argin = 1.0/32.0
prt.Preview()
if self._trace:
self.logf.write lines("T","Ente ring OuterFrame.DO_p rintpreview")
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("so me
text\n")?

Thanks in advance if anyone can give any help.

Mario

Jul 19 '05 #3
Hi Mario,
Something like SendPrinter("so me 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 HtmlEasyPrintin g write-up here:
http://wiki.wxpython.org/index.cgi/Printing

-Jim


On 5/11/05, Mario <ma***@nospam.n oext> 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("so me
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********@via com-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****@syscono nline.com> ha scritto nel messaggio
news:42******** ******@sysconon line.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 HtmlEasyPrintin g 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.or g> 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.or g> 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********@ear thlink.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.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #10

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

Similar topics

4
2768
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 that printing (to a printer :-) wasn't easy (at least on windows - let alone *cross* platform) - and that was dated 2000. Oh and - http://mail.python.org/pipermail/python-list/2002-September/121462.html
2
3008
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 of the printing, I arranged the graphic elements on the page the way it should be. When I got to printing text, it went across the page, not down as I need it to go. I tried to use the hDC.SetWorldTransform(0, -1, 1, 0, 0, 0) command to rotate...
1
2596
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 canvas. Is there an easy way to do this in Python? Also, I can pretty easily use the WaveSurfer "print" function in my program, but taht only prints to a PostScript printer or prints out a PostScript file. I would like to automate the process of...
8
2413
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 support check printing. > Is there a Python check printing application kicking around? OK, I'll assume silence means "no", so new question: What is the current best practice for cross platform printing of PostScript files from Python?
3
4771
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 many objects to handle printing.. i've tryied to use them, but i wasn't able to... Any hint? By now, i solved the problem saving a screenshot if the screen in an image(bmp) and then sending it to printer... (a print preview would be cool...) tnx...
3
1909
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 currently uses Python 2.4 with wxPython and pywin/winpy (whatever it's called, for MS Access ODBC), so if it can be done easily in one of those, that'd be great, but if there's a module which makes it a breeze, I'm happy to download that too. --Max
5
1570
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 a wxSashWindow in wxPython. I'm just starting out with wxPython, and the first thing i need to do is use 3 sash windows, 1 split vertically, and on the left and right of that a SashWindow splitting horizontally. I can make frames, buttons, use...
1
1860
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 wx.StaticBitmap I want to be able to drag an item from the tree onto the static bitmap.
3
1038
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 want to append a node pressing the button I don't know How. My idea is using the wx.EVT_TREE_SEL_CHANGED event somehow get The ID or something of the selected node, so I could know Where to append the his child. I need the ID for the appenditem...
0
8197
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8287
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8443
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4058
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.