Printing RTF file under win32

2011-01-21 Thread Mark Carter
I'm using Python 2.6.5 on win32. I would like to print a batch of RTF
files on a printer. I don't want to use the win32api.ShellExecute
command because that invokes Word, and Word has been configured in a
strange way by one of our admins, making it inconvenient to use.

What should I do?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing RTF file under win32

2011-01-21 Thread Chris Rebert
On Fri, Jan 21, 2011 at 2:12 AM, Mark Carter alt.mcar...@gmail.com wrote:
 I'm using Python 2.6.5 on win32. I would like to print a batch of RTF
 files on a printer. I don't want to use the win32api.ShellExecute
 command because that invokes Word, and Word has been configured in a
 strange way by one of our admins, making it inconvenient to use.

 What should I do?

Invoke WordPad instead?
http://en.wikipedia.org/wiki/WordPad

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing RTF file under win32

2011-01-21 Thread Michel Claveau - MVP
Hi!

Try this line:
C:\Program Files\Windows NT\Accessories\wordpad.exe /p D:\data\fil.rtf
(change the path if you have a windows 64 bits)

@-salutations
-- 
Michel Claveau 
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Jerzy

New submission from Jerzy jer...@genesilico.pl:

Hi

When I am outputting unicode strings to terminal my script works OK, but
when I redirect it to file I get a crash:

$ python mailing/message_sender.py -l Bia
Białystok

$ python mailing/message_sender.py -l Bia  ~/tmp/aaa.txt 
Traceback (most recent call last):
  File mailing/message_sender.py, line 71, in module
list_groups(unicode(args[0],'utf-8'))
  File mailing/message_sender.py, line 53, in list_groups
print group[1].name
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0142' in
position 3: ordinal not in range(128)

--
components: Unicode
messages: 92196
nosy: Orlowski
severity: normal
status: open
title: Outputting unicode crushes when printing to file on Linux
type: crash
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

You have to use an encoding that's not ascii then.

--
nosy: +benjamin.peterson
resolution:  - works for me
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Jerzy

Jerzy jer...@genesilico.pl added the comment:

I know how to make it work. The question is why outputting to file makes 
it crush when outputting to terminal does not.

I have never seen $program  file behaving in a different way than 
$program in any other language

Jerzy Orlowski

Benjamin Peterson wrote:
 Benjamin Peterson benja...@python.org added the comment:

 You have to use an encoding that's not ascii then.

 --
 nosy: +benjamin.peterson
 resolution:  - works for me
 status: open - closed

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue6832
 ___





--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

When output goes to a terminal, Python can determine its encoding. For a
file, it cannot, therefore it refuses to guess.

Also, many programs behave differently when used with redirection;
namely, all those that use `isatty()` to determine if stdout is a terminal.

--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Jerzy

Jerzy jer...@genesilico.pl added the comment:

Well, I would suggest using the terminal encoding as default one when 
redirecting. In my opinion sys.stdin and sys.stdout should always have 
the terminal encoding

Alternatively you could make the function sys.setdefaultencoding() 
visible to change it in a reasonable way

Jerzy

Georg Brandl wrote:
 Georg Brandl ge...@python.org added the comment:

 When output goes to a terminal, Python can determine its encoding. For a
 file, it cannot, therefore it refuses to guess.

 Also, many programs behave differently when used with redirection;
 namely, all those that use `isatty()` to determine if stdout is a terminal.

 --
 nosy: +georg.brandl

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue6832
 ___





--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

Using the terminal encoding for sys.stdout does not work in the general
case, as a (background) process may not *have* a controlling terminal
(such as a CGI script, a cron job, or a Windows service). That Python
recognizes the terminal encoding is primarily a convenience feature for
the interactive mode.

Exposing sys.setdefaultencoding is not implementable in a reasonable way.

--
nosy: +loewis

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Jerzy

Jerzy jer...@genesilico.pl added the comment:

OK, I give up.

The problem is that one might test a program on terminal and think that 
everything is running OK and then spend a reasonable amount of time 
trying to find the problem later

Another approach: couldn't utf8 be set as default encoding for all 
inputs and outputs?

I know that some of my questions are caused by the fact that I do not 
understand how python works. But You have to bear in mind that most of 
the people don't. Such behaviour of Python (see also 
http://bugs.python.org/issue5092) is illogical in the common sense for 
standard poeple. If interpreter does something illogical for me, I am 
more eager to switch to another language.

Jerzy

Martin v. Löwis wrote:
 Martin v. Löwis mar...@v.loewis.de added the comment:

 Using the terminal encoding for sys.stdout does not work in the general
 case, as a (background) process may not *have* a controlling terminal
 (such as a CGI script, a cron job, or a Windows service). That Python
 recognizes the terminal encoding is primarily a convenience feature for
 the interactive mode.

 Exposing sys.setdefaultencoding is not implementable in a reasonable way.

 --
 nosy: +loewis

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue6832
 ___





--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

If you want to switch to a different language, consider switching to
Python 3. There, all strings are Unicode strings, and files opened in
text mode always use the locale encoding.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6832] Outputting unicode crushes when printing to file on Linux

2009-09-03 Thread Jerzy

Jerzy jer...@genesilico.pl added the comment:

good point!

I will give it a try

Jerzy

Martin v. Löwis wrote:
 Martin v. Löwis mar...@v.loewis.de added the comment:

 If you want to switch to a different language, consider switching to
 Python 3. There, all strings are Unicode strings, and files opened in
 text mode always use the locale encoding.

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue6832
 ___





--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6832
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Printing to file, how do I do it efficiently?

2006-11-10 Thread Cameron Walsh
Robert Kern wrote:
 Cameron Walsh wrote:
 Hi all,

 I have a numpy.array of 89x512x512 uint8's, set up with code like this:
 
 numpy questions are best asked on the numpy list, not here.

At first I thought it was a generic python question, since it had more
to do with writing array data to file rather than the specific format of
the array data.

 
 data=numpy.array([],dtype=uint8)
 data.resize((89,512,512))
 
 You might want to look at using numpy.empty() here, instead.
 

Thanks!

[...]
 I'm guessing that the slow part is the fact that I am converting the
 data to character format and writing it one character at a time.  What
 is a better way of doing this, or where should I look to find a better way?
 
 data.tostring()
 

And here I see I was wrong, it was a numpy question.  I assumed the
tostring() method would produce the same output as printing the array to
the screen by just calling data.  But of course, that would be the job
of the __repr__() method.

It is now ridiculously fast (1second).  Thank you for your help.

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


Printing to file, how do I do it efficiently?

2006-11-09 Thread Cameron Walsh
Hi all,

I have a numpy.array of 89x512x512 uint8's, set up with code like this:


data=numpy.array([],dtype=uint8)
data.resize((89,512,512))
# Data filled in about 4 seconds from 89 image slices
snip lots of processing code


I first tried writing this data to a binary raw format (for use in a
program called Drishti) as follows:

# The slow bit:
volumeFile=file(/tmp/test.raw,wb)
for z in xrange(Z):
for y in xrange(Y):
for x in xrange(X):
volumeFile.write(%c %(data[z,y,x]))
volumeFile.close()

That took about 39 seconds.

My second attempt was as follows:
volumeFile = open(/tmp/test2.raw,wb)
data.resize((X*Y*Z)) # Flatten the array
for i in data:
volumeFile.write(%c %i)
data.resize((Z,Y,X))
volumeFile.close()

This took 32 seconds.  (For those of you unfamiliar with numpy, the
data.resize() operations take negligible amounts of time, all it does is
allow the data to be accessed differently.)

I'm guessing that the slow part is the fact that I am converting the
data to character format and writing it one character at a time.  What
is a better way of doing this, or where should I look to find a better way?


Thanks,

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


Re: Printing to file, how do I do it efficiently?

2006-11-09 Thread Robert Kern
Cameron Walsh wrote:
 Hi all,
 
 I have a numpy.array of 89x512x512 uint8's, set up with code like this:

numpy questions are best asked on the numpy list, not here.

  http://www.scipy.org/Mailing_Lists

 data=numpy.array([],dtype=uint8)
 data.resize((89,512,512))

You might want to look at using numpy.empty() here, instead.

 # Data filled in about 4 seconds from 89 image slices
 snip lots of processing code
 
 
 I first tried writing this data to a binary raw format (for use in a
 program called Drishti) as follows:
 
 # The slow bit:
 volumeFile=file(/tmp/test.raw,wb)
 for z in xrange(Z):
 for y in xrange(Y):
 for x in xrange(X):
 volumeFile.write(%c %(data[z,y,x]))
 volumeFile.close()
 
 That took about 39 seconds.
 
 My second attempt was as follows:
 volumeFile = open(/tmp/test2.raw,wb)
 data.resize((X*Y*Z)) # Flatten the array
 for i in data:
 volumeFile.write(%c %i)
 data.resize((Z,Y,X))
 volumeFile.close()
 
 This took 32 seconds.  (For those of you unfamiliar with numpy, the
 data.resize() operations take negligible amounts of time, all it does is
 allow the data to be accessed differently.)

No, if the total size is different, it will also copy the array. Use .reshape()
if you want to simply alter the shape, not the total number of elements.

 I'm guessing that the slow part is the fact that I am converting the
 data to character format and writing it one character at a time.  What
 is a better way of doing this, or where should I look to find a better way?

data.tostring()

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Printing a file

2006-03-03 Thread David Boddie
Fabian Steiner wrote:
 David Boddie wrote:

  In Qt 4, the demos/textedit demo does this with a lot less code.
 
  Or are you think of something else?

 Thank you very much for this hint! Thanks to this example I was able to
 print out my first pages :)

That's good to hear. :-)

 But some questions still remain. At the moment I am using
 QSimpleRichtext and a personal HTML-File. I had a look at the
 example.html of textedit.cpp (/usr/share/doc/qt-4.1.1/demos/textedit)
 and found out that it contains quite a lot of proprietary HTML elements,
 attributes and CSS style definitions. So far I didn't even know that
 QSimpleRichText even supports CSS since I couldn't find anything related
 to this point in the official docs (-- e.g. QStylesheet).

I think I may have confused you by mentioning Qt 4. Since you are using
QSimpleRichText, you must be using Qt 3, so you should probably ignore
what I said about the /usr/share/doc/qt-4.1.1/demos/textedit demo. :-/

 Is there any tool out there with which I can write those special HTML
 files? I am quite familiar with HTML and CSS but I don't want to waste
 my time with that.

You don't need to include all those style attributes in the HTML.
Anyway, that's a different version of Qt to the one you are using, so
you can safely ignore it. You should probably look at the text drawing
part of the demo included in Qt 3 (examples/demo/textdrawing) and see
how printing is done for the rich text editor there (in the
TextEdit::filePrint() function). Translating it to Python _shouldn't_
be a problem.

I hope I didn't confuse you too much by talking about two different
versions of Qt at the same time.

Let us know how it goes.

David

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


Re: Printing a file

2006-03-03 Thread Florian Diesch
Fabian Steiner [EMAIL PROTECTED] wrote:
 I am currently working on an application where the user is able to 
 create new worksheets and to delete existing ones. All of these 
 worksheets have the same structure (-- template?), only some values 
 should be changed. A minimal example would be something like this:

 Name: ...
 Role: 
 Address: 

 The values are stored in a SQLite database. Now I would like to offer 
 the possibility to print out a single record on a DinA4 paper. In order 
 to do this, the dots (...) above of course have to be replaced by the 
 current record's values and the different parts have to fit on one page.

 Unfortunately I don't know how to realize this, since also some images 
 and different boxes should be printed out. As the whole application is 
 based on QT, QPrinter might be used, but I couldn't find any examples 
 how to use it.

 What do you suggest? Which format should the template have? (XML, etc.?)

I would either use something like ReportLab to create PDF or some
external type-setting language like LaTeX, *roff or docbook if they are
availabled.




   Florian
-- 
No no no! In maths things are usually named after Euler, or the first
person to discover them after Euler.
[Steven D'Aprano in [EMAIL PROTECTED]]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing a file

2006-03-02 Thread Jeremy Sanders
David Boddie wrote:

 That's where QPrintDialog comes in:
 
   http://doc.trolltech.com/4.1/qprintdialog.html
 
 It's also secretly available in Qt 3 via the QPrinter.setup() method:
 
   printer = QPrinter()
   printer.setup()
   # Now, paint onto the printer as usual.

No - that was in my example. The work I was refering to was taking the
user's input to the dialog and writing the pages to the device in the right
order (I don't think this is done automatically).

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing a file

2006-03-02 Thread David Boddie
Sorry about that. I must have just skipped over the setup() call in
your code. If you're creating highly customized content then I think
you'll always need to think about getting the pages to the printer in
the right order.

For rich text documents, there's code that does this in the Qt 3 text
drawing demo (see the filePrint() method in the
examples/demo/textdrawing/textedit.cpp file).

In Qt 4, the demos/textedit demo does this with a lot less code.

Or are you think of something else?

David

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


Re: Printing a file

2006-03-02 Thread Fabian Steiner
David Boddie wrote:
 Sorry about that. I must have just skipped over the setup() call in
 your code. If you're creating highly customized content then I think
 you'll always need to think about getting the pages to the printer in
 the right order.
 
 For rich text documents, there's code that does this in the Qt 3 text
 drawing demo (see the filePrint() method in the
 examples/demo/textdrawing/textedit.cpp file).
 
 In Qt 4, the demos/textedit demo does this with a lot less code.
 
 Or are you think of something else?

Thank you very much for this hint! Thanks to this example I was able to 
print out my first pages :)

But some questions still remain. At the moment I am using 
QSimpleRichtext and a personal HTML-File. I had a look at the 
example.html of textedit.cpp (/usr/share/doc/qt-4.1.1/demos/textedit) 
and found out that it contains quite a lot of proprietary HTML elements, 
attributes and CSS style definitions. So far I didn't even know that 
QSimpleRichText even supports CSS since I couldn't find anything related 
to this point in the official docs (-- e.g. QStylesheet).

Is there any tool out there with which I can write those special HTML 
files? I am quite familiar with HTML and CSS but I don't want to waste 
my time with that.

Regards,
Fabian Steiner
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing a file

2006-03-01 Thread Fabian Steiner
Hi!

Thank you so far, but now I got stuck again :-/


Jeremy Sanders wrote:
 QPrinter is easy to use. You just draw to the page the same way as you talk
 to the screen with a QPainter.
 
 prnt = qt.QPrinter()
 # you can also vary options like colour, doc name, dpi here
 
 # display dialog box to user (you can actually leave this out)
 if prnt.setup():
  painter = qt.QPainter()
  painter.begin(printer)
  # do stuff to draw to painter
  painter.end(printer)
  # do this between each page
  printer.newPage()


This is what I have so far:

app = QApplication(sys.argv)
printer = QPrinter(QPrinter.PrinterResolution)
if printer.setup():
 printer.setPageSize(printer.A4)
 painter = QPainter(printer)
 metrics = QPaintDeviceMetrics(painter.device())
 marginHeight = 6
 marginWidth =  8
 body = QRect(marginWidth, marginHeight, metrics.widthMM() - 2 * 
marginWidth, metrics.heightMM() - 2 * marginHeight)
 painter.drawRect(body)
 painter.end()

Doing so I hoped to get a rectangle which is as big as an A4 paper (with 
a small border), but unfortunately it is much smaller. Moreover, I ask 
myself whether it is necessary that in order to write text on the paper, 
I always have to pass the proper x, y values to QPainter.drawText(). 
Isn't there any other possibility? How do I get these values?


Thanks in advance,
Fabian Steiner
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing a file

2006-03-01 Thread David Boddie
Fabian Steiner wrote:

 This is what I have so far:

 app = QApplication(sys.argv)
 printer = QPrinter(QPrinter.PrinterResolution)
 if printer.setup():
  printer.setPageSize(printer.A4)
  painter = QPainter(printer)
  metrics = QPaintDeviceMetrics(painter.device())
  marginHeight = 6
  marginWidth =  8
  body = QRect(marginWidth, marginHeight, metrics.widthMM() - 2 *
 marginWidth, metrics.heightMM() - 2 * marginHeight)
  painter.drawRect(body)
  painter.end()

 Doing so I hoped to get a rectangle which is as big as an A4 paper (with
 a small border), but unfortunately it is much smaller.

Surely you meant to use

body = QRect(marginWidth, marginHeight,
 metrics.width() - 2 * marginWidth,
 metrics.height() - 2 * marginHeight)

 Moreover, I ask myself whether it is necessary that in order to write
 text on the paper, I always have to pass the proper x, y values to
 QPainter.drawText().
 Isn't there any other possibility? How do I get these values?

That depends on what kind of text you're drawing (paragraphs of text
vs. simple labels). See the application.py example in the examples3
directory of the PyQt3 distribution for code that implements a simple
text editor with support for printing. Information about text and font
metrics can be found with the QFontMetrics class:

http://doc.trolltech.com/3.3/qfontmetrics.html

PyQt4 supports Qt 4's new rich text facilities, so it's easier to
format text for printing than it is in Qt 3. A more advanced rich text
editor is only available in the C++ Qt 4 demos, but there are other
examples bundled with PyQt4 that show how to print simple documents:

http://www.riverbankcomputing.co.uk/

Finally, it's worth pointing out that there's a higher concentration of
people with experience in these matters reading the PyQt/PyKDE mailing
list:

http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Good luck with your printing,

David

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


Printing a file

2006-02-28 Thread Fabian Steiner
Hello!

I am currently working on an application where the user is able to 
create new worksheets and to delete existing ones. All of these 
worksheets have the same structure (-- template?), only some values 
should be changed. A minimal example would be something like this:

Name: ...
Role: 
Address: 

The values are stored in a SQLite database. Now I would like to offer 
the possibility to print out a single record on a DinA4 paper. In order 
to do this, the dots (...) above of course have to be replaced by the 
current record's values and the different parts have to fit on one page.

Unfortunately I don't know how to realize this, since also some images 
and different boxes should be printed out. As the whole application is 
based on QT, QPrinter might be used, but I couldn't find any examples 
how to use it.

What do you suggest? Which format should the template have? (XML, etc.?)

Any hints appreciated!

Cheers,
Fabian Steiner
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing a file

2006-02-28 Thread Jeremy Sanders
Fabian Steiner wrote:

 Unfortunately I don't know how to realize this, since also some images
 and different boxes should be printed out. As the whole application is
 based on QT, QPrinter might be used, but I couldn't find any examples
 how to use it.

QPrinter is easy to use. You just draw to the page the same way as you talk
to the screen with a QPainter.

prnt = qt.QPrinter()
# you can also vary options like colour, doc name, dpi here

# display dialog box to user (you can actually leave this out)
if prnt.setup():
 painter = qt.QPainter()
 painter.begin(printer)
 # do stuff to draw to painter
 painter.end(printer)
 # do this between each page
 printer.newPage()

 # ... more pages can be printed to a painter

It's very easy to do. If you want to handle multiple pages and so on,
there's a bit of work to do to interface to the dialog to get the
user-selected page range, etc.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing a file

2006-02-28 Thread David Boddie
Jeremy Sanders wrote:
 Fabian Steiner wrote:

  Unfortunately I don't know how to realize this, since also some images
  and different boxes should be printed out. As the whole application is
  based on QT, QPrinter might be used, but I couldn't find any examples
  how to use it.

[...]

 It's very easy to do. If you want to handle multiple pages and so on,
 there's a bit of work to do to interface to the dialog to get the
 user-selected page range, etc.

That's where QPrintDialog comes in:

  http://doc.trolltech.com/4.1/qprintdialog.html

It's also secretly available in Qt 3 via the QPrinter.setup() method:

  printer = QPrinter()
  printer.setup()
  # Now, paint onto the printer as usual.

David

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