Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
5073b376
Kaydet (Commit)
5073b376
authored
Nis 27, 1998
tarafından
Jack Jansen
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added Just's printing demo code.
üst
4f31694d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
1 deletion
+99
-1
index.html
Mac/Demo/index.html
+6
-1
PrintingDemo.py
Mac/Demo/printing/PrintingDemo.py
+93
-0
No files found.
Mac/Demo/index.html
Dosyayı görüntüle @
5073b376
...
...
@@ -113,6 +113,11 @@ img modules on the mac.
on using the respective managers. In the
<i>
Mac:Lib
</i>
folder you
will also find modules that do useful things with the Communications
Toolbox, the Finder interface, etc.
<LI>
<I>
Printing
</I>
has an example on using the Printing module to, you guessed
it, print from Python. The code is somewhat self-documenting. Donated
by Just van Rossum, who also donated the Printing module itself.
</UL>
At some point in the (possibly distant) future, I will add chapters on
...
...
@@ -131,5 +136,5 @@ documentation. <p>
<HR>
<A
HREF=
"http://www.cwi.nl/~jack"
>
Jack Jansen
</A>
,
<A
HREF=
"mailto:jack@cwi.nl"
>
jack@cwi.nl
</A>
, 2
5-Feb
-98.
<A
HREF=
"mailto:jack@cwi.nl"
>
jack@cwi.nl
</A>
, 2
7-Apr
-98.
</BODY></HTML>
Mac/Demo/printing/PrintingDemo.py
0 → 100644
Dosyayı görüntüle @
5073b376
import
Printing
import
Qd
import
Fm
import
Res
# some constants
PostScriptBegin
=
190
# Set driver state to PostScript
PostScriptEnd
=
191
# Restore QuickDraw state
PostScriptHandle
=
192
# PostScript data referenced in handle
CHUNK_SIZE
=
0x8000
# max size of PicComment
def
PostScript
(
text
):
"""embed text as plain PostScript in print job."""
handle
=
Res
.
Resource
(
''
)
Qd
.
PicComment
(
PostScriptBegin
,
0
,
handle
)
while
text
:
chunk
=
text
[:
CHUNK_SIZE
]
text
=
text
[
CHUNK_SIZE
:]
handle
.
data
=
chunk
Qd
.
PicComment
(
PostScriptHandle
,
len
(
chunk
),
handle
)
handle
.
data
=
''
Qd
.
PicComment
(
PostScriptEnd
,
0
,
handle
)
# create a new print record
printrecord
=
Printing
.
NewTPrintRecord
()
# open the printer
Printing
.
PrOpen
()
try
:
# initialize print record with default values
Printing
.
PrintDefault
(
printrecord
)
# page setup, ok is 0 when user cancelled
ok
=
Printing
.
PrStlDialog
(
printrecord
)
if
not
ok
:
raise
KeyboardInterrupt
# at this stage, you should save the print record in your document for later
# reference.
# print job dialog, ok is 0 when user cancelled
ok
=
Printing
.
PrJobDialog
(
printrecord
)
if
not
ok
:
raise
KeyboardInterrupt
# once per document
port
=
Printing
.
PrOpenDoc
(
printrecord
)
# port is the Printer's GrafPort, it is also the current port, so no need to Qd.SetPort(port)
try
:
# start printing a page
# XXX should really look up what pages to print by
# inspecting the print record.
Printing
.
PrOpenPage
(
port
,
None
)
try
:
# use QuickDraw like in any other GrafPort
Qd
.
FrameRect
((
10
,
250
,
100
,
500
))
Qd
.
FrameRect
((
10
,
510
,
100
,
600
))
Qd
.
MoveTo
(
10
,
100
)
Qd
.
TextSize
(
50
)
Qd
.
TextFont
(
Fm
.
GetFNum
(
"Helvetica"
))
Qd
.
DrawString
(
"It rreally works!"
)
Qd
.
MoveTo
(
10
,
150
)
Qd
.
TextSize
(
20
)
Qd
.
DrawString
(
"(and now for a little PostScript...)"
)
# example PostScript code
ps
=
"""
%
the coordinate system is the quickdraw one, which is flipped
%
compared to the default PS one. That means text will appear
%
flipped when used directly from PostScript.
%
As an example we start by defining a custom scalefont operator
%
that corrects this.
/myscalefont{[exch 0 0 2 index neg 0 0]makefont}def
0.75 setgray
0 0 moveto
0 30 lineto 10000 30 lineto
10000 0 lineto closepath fill
0 setgray
5 25 moveto /Courier findfont 20 myscalefont setfont
(Printed with PostScript!) show
2 setlinewidth [10 10 5 10] 0 setdash 5 5 moveto 400 0 rlineto stroke
"""
# embed the PostScript code in the print job
PostScript
(
ps
)
finally
:
# when done with the page
Printing
.
PrClosePage
(
port
)
finally
:
# when done with the document
Printing
.
PrCloseDoc
(
port
)
finally
:
# when done printing
Printing
.
PrClose
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment