From Jack.Jansen@cwi.nl Sun Mar 2 17:19:02 1997
From: Jack.Jansen@cwi.nl (Jack Jansen)
Date: Sun, 02 Mar 1997 18:19:02 +0100
Subject: [PYTHONMAC-SIG] serial communications
In-Reply-To: Message by Jesse Bregman ,
Fri, 28 Feb 1997 15:45:34 -0800 (PST) ,
Message-ID: <9703021719.AA24699=jack@snelboot.cwi.nl>
Recently, Jesse Bregman said:
> I know this must be possible, but I haven't found information anywhere
> about how to do serial communications using Python. I am used to Basic's
> method of treating the serial port as a file, then just reading or writing
> to it as if it were any other file. Does anyone know of a similarly easy
> way to do this with Python?
Yes, look at the ctb module. You can't read the serial port as if it
were a file, but it is pretty easy to write a wrapper object in Python
that would allow you to do this.
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From jstrout@ucsd.edu Mon Mar 3 22:11:29 1997
From: jstrout@ucsd.edu (Joseph Strout)
Date: Mon, 3 Mar 1997 14:11:29 -0800 (PST)
Subject: [PYTHONMAC-SIG] Re: wxPython (was Re: [PYTHON GUI-SIG] native Python GUI module(s)?)
In-Reply-To: <199703032135.WAA22754@hampton.bsn.com>
Message-ID:
On Mon, 3 Mar 1997, Edward C. Zimmermann wrote:
> > That sounds good... what must I do to try this out on the Mac? (I'm
> > guessing that the answer is: download the Python sources, download wxMac
> > sources, get each to compile (which assumes you have CodeWarrior and there
> > are no nasty version incompatibilities between CW10 and CW11, which in
> Ugh.. Yes.. Unless someone else does it...
> Building wxP for a platform is a pain! But you don't have to build it
> but once its built by someone you can just use it.
Hmm, I hadn't thought of that. This is a good point; I suppose some kind
soul could (for example) build a wxP binary for PowerMac, and upload it to
the Python ftp site. Those who want it would just download it and replace
the out-of-the-box Python executable with that.
> > wxWin doesn't run on the Mac. wxMac didn't even run on the Mac, the last
> > time I tried it -- the first demo promptly crashed my machine. Of course,
> > that was some months ago; I've heard that it has improved since then.
> I have also heard the same.. But that is an issue that can should enough
> people join the wxPython bandwagon that develop Mac.. Its called committee
> development..
Yes, it's a possibility.
> The main problem with wxPython is that we never seemed to get enough
> people joining in.. And I (and probably Harri as well) have not had the
> time to keep things rolling on our own.. We are still committed to wxP
> and shall continue to develop and use it in our applications.. And once
> we have the time probably release a new version..
Well, it sounds like a good alternative to Tk (not that there's anything
wrong with Tk -- I just like to have alternatives!). What platforms does
wxPython run on at the moment? Any chance I could try it out on my
PowerMac, Sun, or SGI?
Thanks,
-- Joe
,------------------------------------------------------------------.
| Joseph J. Strout Department of Neuroscience, UCSD |
| jstrout@ucsd.edu http://www-acs.ucsd.edu/~jstrout/ |
`------------------------------------------------------------------'
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From jurjen@q2c.nl Fri Mar 7 15:50:27 1997
From: jurjen@q2c.nl (Jurjen N.E. Bos)
Date: Fri, 7 Mar 1997 15:50:27 +0000
Subject: [PYTHONMAC-SIG] Please help: Crypto toolkit for Mac
Message-ID:
Did any of you guys try compiling Andrew Kuchling's Python Cryptography Toolkit for the Mac?
If yes, how did you do it?
Thanks in advance,
Jurjen
-- jurjen@q2c.nl ( Jurjen N.E. Bos)
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From jstrout@ucsd.edu Mon Mar 3 22:11:29 1997
From: jstrout@ucsd.edu (Joseph Strout)
Date: Mon, 3 Mar 1997 14:11:29 -0800 (PST)
Subject: [PYTHONMAC-SIG] Re: wxPython (was Re: [PYTHON GUI-SIG] native Python GUI module(s)?)
In-Reply-To: <199703032135.WAA22754@hampton.bsn.com>
Message-ID:
On Mon, 3 Mar 1997, Edward C. Zimmermann wrote:
> > That sounds good... what must I do to try this out on the Mac? (I'm
> > guessing that the answer is: download the Python sources, download wxMac
> > sources, get each to compile (which assumes you have CodeWarrior and there
> > are no nasty version incompatibilities between CW10 and CW11, which in
> Ugh.. Yes.. Unless someone else does it...
> Building wxP for a platform is a pain! But you don't have to build it
> but once its built by someone you can just use it.
Hmm, I hadn't thought of that. This is a good point; I suppose some kind
soul could (for example) build a wxP binary for PowerMac, and upload it to
the Python ftp site. Those who want it would just download it and replace
the out-of-the-box Python executable with that.
> > wxWin doesn't run on the Mac. wxMac didn't even run on the Mac, the last
> > time I tried it -- the first demo promptly crashed my machine. Of course,
> > that was some months ago; I've heard that it has improved since then.
> I have also heard the same.. But that is an issue that can should enough
> people join the wxPython bandwagon that develop Mac.. Its called committee
> development..
Yes, it's a possibility.
> The main problem with wxPython is that we never seemed to get enough
> people joining in.. And I (and probably Harri as well) have not had the
> time to keep things rolling on our own.. We are still committed to wxP
> and shall continue to develop and use it in our applications.. And once
> we have the time probably release a new version..
Well, it sounds like a good alternative to Tk (not that there's anything
wrong with Tk -- I just like to have alternatives!). What platforms does
wxPython run on at the moment? Any chance I could try it out on my
PowerMac, Sun, or SGI?
Thanks,
-- Joe
,------------------------------------------------------------------.
| Joseph J. Strout Department of Neuroscience, UCSD |
| jstrout@ucsd.edu http://www-acs.ucsd.edu/~jstrout/ |
`------------------------------------------------------------------'
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From sdm7g@virginia.edu Thu Mar 13 20:23:42 1997
From: sdm7g@virginia.edu (Steven D. Majewski)
Date: Thu, 13 Mar 1997 15:23:42 -0500 (EST)
Subject: [PYTHONMAC-SIG] SWIG for Macintosh and Tcl (1st attempt) (fwd)
Message-ID:
---------- Forwarded message ----------
Date: Thu, 13 Mar 1997 08:14:12 -0800
From: David Beazley
Reply-To: mactcl@eng.sun.com
To: sdm7g@virginia.edu
Subject: SWIG for Macintosh and Tcl (1st attempt)
Greetings fellow Mac users!
Just thought I would drop a quick note to announce that a highly
experimental version of SWIG is now available for the Macintosh
at
ftp://ftp.cs.utah.edu/pub/beazley/SWIG/swig1.1b5.tar.gz
For the unindoctrinated, SWIG is a code development tool I've been
working on for building scripting language interfaces to C/C++ codes.
In a nutshell, you can take a list of ANSI C/C++ declarations and turn
them into a Tcl/Tk, Python, or Perl interface. However, until
only recently, SWIG has only supported Unix systems. I'd like to
try and change that (especially since I own a Mac).
This release of SWIG is extremely rough---in fact, it's probably
features the worst Mac application interface ever, but it's a start.
Despite this, I have used it to successfully build some simple Mac Tcl
8.0 extensions. If people are interested in this sort of thing (and
willing to live on the edge), I would be extremely interested in
getting feedback about improving MacSWIG and how it can be made to
work easily with Tcl/Tk and Mac code development tools. Being
primarily a Unix programmer, I am by no means an expert at Mac
programming, but I'm hoping some feedback can give SWIG a swift kick
in the right direction (and give me some ideas on how to better
approach the problem).
The SWIG distribution is only currently available in source form.
A project file for Code Warrior 10 is included in the distribution
and it seems to build cleanly on my PowerMac.
Otherwise, the standard disclaimers apply--this is highly
experimental, use at your own peril, etc... In any case, I'd
definitely like to get some feedback and ideas anyone might
have about all of this.
Cheers,
Dave
----------------------------------------------------------------
Dave Beazley
Department of Computer Science
University of Utah
Salt Lake City, Utah 84112
beazley@cs.utah.edu http://www.cs.utah.edu/~beazley
----------------------------------------------------------------
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From Jack.Jansen@cwi.nl Thu Mar 13 21:19:10 1997
From: Jack.Jansen@cwi.nl (Jack Jansen)
Date: Thu, 13 Mar 1997 22:19:10 +0100
Subject: [PYTHONMAC-SIG] SWIG for Macintosh and Tcl (1st attempt) (fwd)
In-Reply-To: Message by "Steven D. Majewski" ,
Thu, 13 Mar 1997 15:23:42 -0500 (EST) ,
Message-ID: <9703132119.AA07696=jack@snelboot.cwi.nl>
If someone is going to have a look at this Mac port of SWIG: please
let me know. I'd love to look into it but I don't have the time:-(
Something that would be pretty handy would be if it could spit out
modules in calldll style, since this would allow people without
development environment and without intricate knowledge of universal
headers to create interfaces to arbitrary C routines. Modifying bgen
to do something similar is still on my list, but it remains to be seen
when I have the time to do this...
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From sdm7g@virginia.edu Thu Mar 13 21:20:48 1997
From: sdm7g@virginia.edu (Steven D. Majewski)
Date: Thu, 13 Mar 1997 16:20:48 -0500 (EST)
Subject: [PYTHONMAC-SIG] Re: SWIG for Macintosh and Tcl (1st attempt)
In-Reply-To: <199703130448.VAA19816@sol.cs.utah.edu>
Message-ID:
On Thu, 13 Mar 1997, David Beazley wrote:
>
> Greetings fellow Mac users!
>
> Just thought I would drop a quick note to announce that a highly
> experimental version of SWIG is now available for the Macintosh
> at
>
> ftp://ftp.cs.utah.edu/pub/beazley/SWIG/swig1.1b5.tar.gz
>
Be careful how you unpack.
Using Stuffit Expander on the tar.gz file, the Mac project file seq.hqx is
corrupted -- probably has the wrong EOLs -- and it crashes my Mac trying
to unstuff it.
Using Mac gzip & Mac tar, I am able to unbin hex and extract the project
files, but the .ps.gz files in the Doc directory are corrupt ( probably
from the Unix->Mac EOL translation done to fix the first problem.
Looks like you've got to do a double unstuff to get it ALL properly
translated.
[ David -- you might consider using Stuffit or something Mac native for
the final finished release! ]
---| Steven D. Majewski (804-982-0831) |---
---| Department of Molecular Physiology and Biological Physics |---
---| University of Virginia Health Sciences Center |---
---| P.O. Box 10011 Charlottesville, VA 22906-0011 |---
By doing just a little every day, you can gradually
let the task completely overwhelm you.
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From beazley@sol.cs.utah.edu Thu Mar 13 21:39:02 1997
From: beazley@sol.cs.utah.edu (David Beazley)
Date: Thu, 13 Mar 1997 14:39:02 -0700
Subject: [PYTHONMAC-SIG] Re: SWIG for Macintosh and Tcl (1st attempt)
In-Reply-To:
References: <199703130448.VAA19816@sol.cs.utah.edu>
Message-ID: <199703132139.OAA21388@sol.cs.utah.edu>
Steven D. Majewski writes:
>
>
> Be careful how you unpack.
>
> Using Stuffit Expander on the tar.gz file, the Mac project file seq.hqx is
> corrupted -- probably has the wrong EOLs -- and it crashes my Mac trying
> to unstuff it.
>
Hmmm. I didn't experience this when I tested it, but I don't think I had any
EOL translation enabled. This is definitely a problem.
> Using Mac gzip & Mac tar, I am able to unbin hex and extract the project
> files, but the .ps.gz files in the Doc directory are corrupt ( probably
> from the Unix->Mac EOL translation done to fix the first problem.
>
>
> Looks like you've got to do a double unstuff to get it ALL properly
> translated.
>
>
> [ David -- you might consider using Stuffit or something Mac native for
> the final finished release! ]
Do you think it would be preferable to pack the entire distribution up as
a sea.hqx file? I'm certainly open to finding the best approach.
Cheers,
Dave
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From drwpci@cis.rit.edu Fri Mar 14 13:37:59 1997
From: drwpci@cis.rit.edu (Dave Wyble)
Date: Fri, 14 Mar 1997 08:37:59 -0500 (EST)
Subject: [PYTHONMAC-SIG] Alpha (editor) Python mode help
Message-ID:
Greetings,
I am currently using Alpha, which seems to be a very nice product. My only
problem is that I don't know Tcl at all and I am having some difficulty
coming up with a good mode file for python file. If anyone has done this
and is willing to share it I would really appreciate the help. If you can
get yourself to Rochester I'll even consider buying dinner ;)
I suppose I would entertain suggestions about other (free or cheap)
programmer's editors customizable for python. Let's keep this nice though,
I don't want to be responsible for starting a religious war!
Thanks.
Dave
David R. Wyble drwpci@cis.rit.edu
Munsell Color Science Laboratory voice: (716)475-7310
Center for Imaging Science fax: (716)475-5988
Rochester Institute of Technology
54 Lomb Memorial Drive
Rochester NY 14623
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From billpy@mail.demon.net Mon Mar 17 00:35:57 1997
From: billpy@mail.demon.net (Bill Bedford)
Date: Mon, 17 Mar 1997 00:35:57 +0000
Subject: [PYTHONMAC-SIG] Waste
Message-ID:
Has anyone tryed to use the Waste engine with Python?
I am trying to put embed graphics into the htmled demo but I can't get it
to work.
I have converted the images to Picts, and can show that the imported WE
instance is a valid pict but when I call DrawPicture nothing happens.
I seem to be missing a step - any ideas?
-----------------------------------------------------------------------
Bill Bedford Designer of Photo-Etches
billb@mousa.demon.co.uk
owner Brit_Rail-L --- british railways historical list
-----------------------------------------------------------------------
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From Jack.Jansen@cwi.nl Mon Mar 17 12:13:23 1997
From: Jack.Jansen@cwi.nl (Jack Jansen)
Date: Mon, 17 Mar 1997 13:13:23 +0100
Subject: [PYTHONMAC-SIG] Waste
In-Reply-To: Message by Bill Bedford ,
Mon, 17 Mar 1997 00:35:57 +0000 ,
Message-ID: <9703171213.AA02594=jack@snelboot.cwi.nl>
> Has anyone tryed to use the Waste engine with Python?
>
> I am trying to put embed graphics into the htmled demo but I can't get it
> to work.
Yup, I got this working. I can send example code of a minimal html widget
using Waste, but I should warn you in advance that the code isn't too pretty
(converting a gif to an incore pixmap involves a hack to get at the address of
a string and such).
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From Jack.Jansen@cwi.nl Mon Mar 17 15:57:37 1997
From: Jack.Jansen@cwi.nl (Jack Jansen)
Date: Mon, 17 Mar 1997 16:57:37 +0100
Subject: [PYTHONMAC-SIG] Waste
In-Reply-To: Message by Jack Jansen ,
Mon, 17 Mar 1997 13:13:23 +0100 , <9703171213.AA02594=jack@snelboot.cwi.nl>
Message-ID: <9703171557.AA04250=jack@snelboot.cwi.nl>
This is a multipart MIME message.
--===_0_Mon_Mar_17_16:53:53_CET_1997
Content-Type: text/plain; charset=us-ascii
Okay, here is the minimal html browser. No guarantees that it'll work out of
the box in a standard python environment, I pulled it out of our multimedia
presentation software. It should be interesting reading, though, if you want
to play with waste.
It has no comments, probably some debugging stuff and *really* isn't fit for
distribution.
Let me know if someone actually wants to use this and misses something,
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm
--===_0_Mon_Mar_17_16:53:53_CET_1997
Content-Type: text/plain; charset=us-ascii
Content-Description: mac_image.py
"""mac_image - Helper routines (hacks) for images"""
import imgformat
import Qd
import time
import struct
#
# Hack alert: this number gives the offset of the string buffer in a
# python string object from the object address (what is returned by id()).
# In some Pythons it is 12, in some 16. An incorrect value here will result
# a shifted image on-screen.
ID_TO_DATA_OFFSET=16
_fmt_to_mac = {
imgformat.macrgb16 : (16, 16, 3, 5),
}
def mkpixmap(w, h, fmt, data):
"""kludge a pixmap together"""
fmtinfo = _fmt_to_mac[fmt]
rv = struct.pack("lhhhhhhhlllhhhhlll",
id(data)+ID_TO_DATA_OFFSET,
w*2 + 0x8000,
0, 0, h, w,
0,
0, 0, # XXXX?
72<<16, 72<<16,
fmtinfo[0], fmtinfo[1],
fmtinfo[2], fmtinfo[3],
0, 0, 0)
## print 'Our pixmap, size %d:'%len(rv)
## dumppixmap(rv)
return Qd.RawBitMap(rv)
def dumppixmap(data):
baseAddr, \
rowBytes, \
t, l, b, r, \
pmVersion, \
packType, packSize, \
hRes, vRes, \
pixelType, pixelSize, \
cmpCount, cmpSize, \
planeBytes, pmTable, pmReserved \
= struct.unpack("lhhhhhhhlllhhhhlll", data)
print 'Base: 0x%x'%baseAddr
print 'rowBytes: %d (0x%x)'%(rowBytes&0x3fff, rowBytes)
print 'rect: %d, %d, %d, %d'%(t, l, b, r)
print 'pmVersion: 0x%x'%pmVersion
print 'packing: %d %d'%(packType, packSize)
print 'resolution: %f x %f'%(float(hRes)/0x10000, float(vRes)/0x10000)
print 'pixeltype: %d, size %d'%(pixelType, pixelSize)
print 'components: %d, size %d'%(cmpCount, cmpSize)
print 'planeBytes: %d (0x%x)'%(planeBytes, planeBytes)
print 'pmTable: 0x%x'%pmTable
print 'pmReserved: 0x%x'%pmReserved
for i in range(0, len(data), 16):
for j in range(16):
if i + j < len(data):
print '%02.2x'%ord(data[i+j]),
print
--===_0_Mon_Mar_17_16:53:53_CET_1997
Content-Type: text/plain; charset=us-ascii
Content-Description: htmlwidget.py
# A minimal html widget.
#
import Win
import Qd
import QuickDraw
import Res
import Fm
import Ctl
import Controls
import waste
import WASTEconst
import os
import regsub
import string
import htmllib
import urllib
import img
import imgformat
import mac_image
import formatter
LEFTMARGIN=4
TOPMARGIN=4
RIGHTMARGIN=2
BOTTOMMARGIN=0
SCROLLBARWIDTH=16
IMAGEBORDER=2
# Sizes for HTML tag types
HTML_SIZE={
'h1': 4,
'h2': 2
}
class HTMLWidget:
def __init__(self, window, rect, name):
init_waste()
self.last_mouse_was_down = 0
self.url = ''
self.bary = None
self.anchor_offsets = []
self.anchor_hrefs = []
self.bg_color = (0xffff, 0xffff, 0xffff)
self.fg_color = (0, 0, 0)
self.an_color = (0xffff, 0, 0)
self.font_normal = Fm.GetFNum('Times')
self.font_tt = Fm.GetFNum('Courier')
self.font_size = 12
self.name = name
self.wid = window
l, t, r, b = rect
self.rect = rect
vr = l+LEFTMARGIN, t+TOPMARGIN, r-RIGHTMARGIN, b-BOTTOMMARGIN
dr = (0, 0, vr[2]-vr[0], 0)
Qd.SetPort(window)
Qd.TextFont(4)
Qd.TextSize(9)
flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite
self.ted = waste.WENew(dr, vr, flags)
self.createscrollbars()
self.do_activate()
def close(self):
Qd.SetPort(self.wid) # XXXX Needed?
if self.bary:
self.bary.DisposeControl()
del self.bary
del self.ted
del self.wid
def setcolors(self, bg, fg, an):
self.bg_color = bg
self.fg_color = fg
self.an_color = an
def setfonts(self, normal, tt, defsize):
if normal != None:
self.font_normal = normal
if tt != None:
self.font_tt = tt
if defsize != None:
self.font_size = defsize
def createscrollbars(self, reset=0):
#
# See if we need them.
#
if self.bary:
self.bary.DisposeControl()
self.bary = None
l, t, r, b = self.rect
if reset:
self.ted.WECalText()
vr = self.ted.WEGetViewRect()
dr = self.ted.WEGetDestRect()
need_bary = ((dr[3]-dr[1]) >= (vr[3]-vr[1]))
if need_bary:
vr = l+LEFTMARGIN, t+TOPMARGIN, r-(RIGHTMARGIN+SCROLLBARWIDTH-1),
b-BOTTOMMARGIN
dr = dr[0], dr[1], dr[0]+vr[2]-vr[0], dr[3]
self.ted.WESetViewRect(vr)
self.ted.WESetDestRect(dr)
self.ted.WECalText()
vr = self.ted.WEGetViewRect()
dr = self.ted.WEGetDestRect()
rect = r-(SCROLLBARWIDTH-1), t-1, r+1, b+1
if reset:
vy = 0
else:
vy = self.getybarvalue()
self.bary = Ctl.NewControl(self.wid, rect, "", 1, vy, 0,
dr[3]-dr[1]-(vr[3]-vr[1]), 16, 0)
if not self.activated: self.bary.HiliteControl(255)
self.updatedocview()
else:
vr = l+LEFTMARGIN, t+TOPMARGIN, r-RIGHTMARGIN, b-BOTTOMMARGIN
dr = dr[0], dr[1], dr[0]+vr[2]-vr[0], dr[3]
self.ted.WESetViewRect(vr)
self.ted.WESetDestRect(dr)
self.ted.WECalText()
self.bary = None
self.ted.WEScroll(vr[0]-dr[0], vr[1]-dr[1]) # Test....
def getybarvalue(self):
vr = self.ted.WEGetViewRect()
dr = self.ted.WEGetDestRect()
return vr[1]-dr[1]
def updatescrollbars(self):
"""Update scrollbars to reflect current state of document"""
if not self.bary or not self.activated:
return 0
vy = self.getybarvalue()
self.bary.SetControlValue(vy)
max = self.bary.GetControlMaximum()
if vy > max:
self.updatedocview()
def updatedocview(self):
"""Update document view to reflect state of scrollbars"""
vr = self.ted.WEGetViewRect()
dr = self.ted.WEGetDestRect()
value = self.bary.GetControlValue()
self.ted.WEScroll(vr[0]-dr[0], vr[1]-dr[1]-value)
def scrollbar_callback(self, which, where):
if which != self.bary:
return 0
#
# Get current position
#
l, t, r, b = self.ted.WEGetViewRect()
#
# "line" size is minimum of top and bottom line size
#
topline_off,dummy = self.ted.WEGetOffset((l+1,t+1))
topline_num = self.ted.WEOffsetToLine(topline_off)
toplineheight = self.ted.WEGetHeight(topline_num, topline_num+1)
botline_off, dummy = self.ted.WEGetOffset((l+1, b-1))
botline_num = self.ted.WEOffsetToLine(botline_off)
botlineheight = self.ted.WEGetHeight(botline_num, botline_num+1)
if botlineheight == 0:
botlineheight = self.ted.WEGetHeight(botline_num-1, botline_num)
if botlineheight < toplineheight:
lineheight = botlineheight
else:
lineheight = toplineheight
if lineheight <= 0:
lineheight = 1
pageheight = (b-t)-lineheight
if pageheight <= 0:
pageheight = lineheight
#
# Now do the command.
#
value = self.bary.GetControlValue()
if where == Controls.inUpButton:
value = value - lineheight
elif where == Controls.inPageUp:
value = value - pageheight
elif where == Controls.inDownButton:
value = value + lineheight
elif where == Controls.inPageDown:
value = value + pageheight
self.bary.SetControlValue(value)
self.updatedocview()
return 1
def do_activate(self):
Qd.SetPort(self.wid)
self.ted.WEActivate()
if self.bary:
self.bary.HiliteControl(0)
self.activated = 1
def do_deactivate(self):
Qd.SetPort(self.wid)
self.ted.WEDeactivate()
if self.bary:
self.bary.HiliteControl(255)
self.activated = 0
def do_update(self):
visregion = self.wid.GetWindowPort().visRgn
myregion = Qd.NewRgn()
Qd.RectRgn(myregion, self.rect) # or is it self.ted.WEGetViewRect() ?
Qd.SectRgn(myregion, visregion, myregion)
# Waste doesn't honour the clipping region, do it ourselves
clipregion = Qd.NewRgn()
Qd.GetClip(clipregion)
Qd.SectRgn(myregion, clipregion, myregion)
if Qd.EmptyRgn(myregion):
return
Qd.RGBBackColor(self.bg_color)
Qd.RGBForeColor((0, 0xffff, 0)) # DBG
Qd.EraseRgn(visregion)
self.ted.WEUpdate(myregion)
## self.updatescrollbars()
def do_moveresize(self, rect):
l, t, r, b = rect
self.rect = rect
Qd.SetPort(self.wid)
Qd.RGBBackColor(self.bg_color)
vr = l+LEFTMARGIN, t+TOPMARGIN, r-RIGHTMARGIN, b-BOTTOMMARGIN
self.ted.WESetViewRect(vr)
Win.InvalRect(self.rect)
self.createscrollbars()
def do_click(self, down, local, evt):
(what, message, when, where, modifiers) = evt
Qd.SetPort(self.wid)
Qd.RGBBackColor(self.bg_color)
if down:
# Check for control
ptype, ctl = Ctl.FindControl(local, self.wid)
if ptype and ctl:
part = ctl.TrackControl(local)
if part:
self.scrollbar_callback(ctl, part)
return
# Remember, so we react to mouse-up next time
self.last_mouse_was_down = 1
else:
if not self.last_mouse_was_down:
# Two ups in a row,
# probably due to window-raise or something
return
self.last_mouse_was_down = 0
# Check for anchor
if not self._cbanchor:
return
off, edge = self.ted.WEGetOffset(local)
for i in range(len(self.anchor_offsets)):
p0, p1 = self.anchor_offsets[i]
if p0 <= off < p1:
href = self.anchor_hrefs[i]
self._cbanchor(href)
return
def do_char(self, ch, event):
pass # Do nothing.
def insert_html(self, data, url):
Qd.SetPort(self.wid)
Qd.RGBBackColor(self.bg_color)
if data == '':
self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 1)
self.ted.WESetSelection(0, 0x3fffffff)
self.ted.WEDelete()
self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 0)
Win.InvalRect(self.rect)
self.createscrollbars(reset=1)
self.anchor_offsets = []
return
f = MyFormatter(self)
# Remember where we are, and don't update
Qd.SetPort(self.wid)
self.ted.WESetSelection(0, 0x3fffffff)
self.ted.WEDelete()
self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 1)
self.html_init()
p = MyHTMLParser(f)
p.url = url # Tell it the URL, for relative images
p.feed(data)
self.anchor_hrefs = p.anchorlist[:]
# Restore updating, recalc, set focus
self.ted.WESetSelection(0, 0)
self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 0)
Win.InvalRect(self.rect)
self.createscrollbars(reset=1)
if self.name == 'HelpHeader':
vr = self.ted.WEGetViewRect()
dr = self.ted.WEGetDestRect()
def mysetstyle(self, which, how):
self.ted.WESelView()
self.ted.WESetStyle(which, how)
self.parent.updatemenubar()
#
# Methods for getting at the anchors
#
def GetHRefs(self):
return self.anchor_hrefs[:]
def setanchorcallback(self, cb):
self._cbanchor = cb
#
# Methods for writer class for html formatter
#
def html_init(self):
self.para_count = 0
self.html_font = [0, 0, 0, 0]
self.html_style = 0
self.html_color = self.fg_color
self.new_font(self.html_font)
self.last_anchor_begin_pos = -1
self.anchor_offsets = []
def new_font(self, font):
self.delayed_para_send()
## print 'FONT', font # DBG
if font == None:
font = (0, 0, 0, 0)
font = map(lambda x:x, font)
for i in range(len(font)):
if font[i] == None:
font[i] = self.html_font[i]
[size, italic, bold, tt] = font
self.html_font = font[:]
if tt:
font = self.font_tt
else:
font = self.font_normal
if HTML_SIZE.has_key(size):
size = HTML_SIZE[size]
else:
size = 0
size = size + self.font_size
face = 0
if bold: face = face | 1
if italic: face = face | 2
face = face | self.html_style
self.ted.WESetStyle(WASTEconst.weDoFont | WASTEconst.weDoFace |
WASTEconst.weDoReplaceFace | WASTEconst.weDoSize | WASTEconst.weDoColor,
(font, face, size, self.html_color))
def new_margin(self, margin, level):
self.delayed_para_send()
self.ted.WEInsert('[Margin %s %s]'%(margin, level), None, None)
def new_spacing(self, spacing):
self.delayed_para_send()
self.ted.WEInsert('[spacing %s]'%spacing, None, None)
def new_styles(self, styles):
self.delayed_para_send()
self.html_style = 0
self.html_color = self.fg_color
if 'anchor' in styles:
self.html_style = self.html_style | 4
self.html_color = self.an_color
dummy, self.anchor_begin_pos = self.ted.WEGetSelection()
elif self.anchor_begin_pos >= 0:
dummy, endpos = self.ted.WEGetSelection()
self.anchor_offsets.append(self.anchor_begin_pos, endpos)
self.anchor_begin_pos = -1
self.new_font(self.html_font)
def send_paragraph(self, blankline):
self.para_count = self.para_count + blankline + 1
def delayed_para_send(self):
if not self.para_count: return
self.ted.WEInsert('\r'*self.para_count, None, None)
self.para_count = 0
def send_line_break(self):
self.delayed_para_send()
self.ted.WEInsert('\r', None, None)
def send_hor_rule(self, *args, **kw):
# Ignore ruler options, for now
self.delayed_para_send()
dummydata = Res.Resource('')
self.ted.WEInsertObject('rulr', dummydata, (0,0))
def send_label_data(self, data):
self.delayed_para_send()
self.ted.WEInsert(data, None, None)
def send_flowing_data(self, data):
self.delayed_para_send()
self.ted.WEInsert(data, None, None)
def send_literal_data(self, data):
self.delayed_para_send()
data = regsub.gsub('\n', '\r', data)
data = string.expandtabs(data)
self.ted.WEInsert(data, None, None)
def send_image(self, data):
self.delayed_para_send()
self.ted.WEInsertObject('GIF ', data, (0, 0))
class MyFormatter(formatter.AbstractFormatter):
def __init__(self, writer):
formatter.AbstractFormatter.__init__(self, writer)
self.parskip = 1
def my_add_image(self, image):
self.writer.send_image(image)
class MyHTMLParser(htmllib.HTMLParser):
def anchor_bgn(self, href, name, type):
self.anchor = href
if self.anchor:
self.anchorlist.append(href)
self.formatter.push_style('anchor')
def anchor_end(self):
if self.anchor:
self.anchor = None
self.formatter.pop_style()
def end_p(self):
# It seems most browsers treat
as ...
self.do_p(())
def start_p(self, attrs):
# It seems most browsers treat
as ...
self.do_p(attrs)
def handle_image(self, src, alt, ismap, align, width, height):
## print 'IMAGE', self.url, src
url = urllib.basejoin(self.url, src)
## print 'URL', url
fname = urllib.urlretrieve(url)[0]
## print 'FILENAME', fname
try:
image = img.reader(imgformat.macrgb16, fname)
except img.error:
print 'Html: failed to get image', fname
self.formatter.add_flowing_data(alt)
return
data = image.read()
handle = _gifkeeper.new(fname, image.width, image.height, data)
self.formatter.my_add_image(handle)
waste_inited = 0
def init_waste():
global waste_inited
if waste_inited:
return
waste_inited = 1
# Ruler handlers
waste.WEInstallObjectHandler('rulr', 'new ', newRuler)
waste.WEInstallObjectHandler('rulr', 'draw', drawRuler)
waste.WEInstallObjectHandler('rulr', 'free', freeRuler)
# GIF handlers
waste.WEInstallObjectHandler('GIF ', 'new ', newGIF)
waste.WEInstallObjectHandler('GIF ', 'draw', drawGIF)
waste.WEInstallObjectHandler('GIF ', 'free', freeGIF)
def newRuler(obj):
"""Insert a new ruler. Make it as wide as the window minus 2 pixels"""
ted = obj.WEGetObjectOwner()
l, t, r, b = ted.WEGetDestRect()
return r-l, 4
def drawRuler((l, t, r, b), obj):
y = (t+b)/2
Qd.MoveTo(l+2, y)
Qd.LineTo(r-2, y)
return 0
def freeRuler(*args):
return 0
def newGIF(obj):
handle = obj.WEGetObjectDataHandle()
width, height, pixmap = _gifkeeper.get(handle.data)
return width+2*IMAGEBORDER, height+2*IMAGEBORDER
def drawGIF((l,t,r,b),obj):
handle = obj.WEGetObjectDataHandle()
width, height, pixmap = _gifkeeper.get(handle.data)
srcrect = 0, 0, width, height
dstrect = l+IMAGEBORDER, t+IMAGEBORDER, r-IMAGEBORDER, b-IMAGEBORDER
port = Qd.GetPort()
bg = port.rgbBkColor
fg = port.rgbFgColor
Qd.RGBBackColor((0xffff, 0xffff, 0xffff))
Qd.RGBForeColor((0,0,0))
## Qd.CopyBits(pixmap, port.portBits, srcrect, dstrect,
## QuickDraw.srcCopy+QuickDraw.ditherCopy, None)
Qd.CopyBits(pixmap, port.portBits, srcrect, dstrect,
QuickDraw.srcCopy, None)
Qd.RGBBackColor(bg)
Qd.RGBForeColor(fg)
# XXXX paste pixmap on screen
return 0
def freeGIF(obj):
handle = obj.WEGetObjectDataHandle()
_gifkeeper.delete(handle.data)
return 0
class _Gifkeeper:
def __init__(self):
self.dict = {}
def new(self, name, width, height, data):
if self.dict.has_key(name):
self.dict[name][0] = self.dict[name][0] + 1
return self.dict[name][1]
pixmap = mac_image.mkpixmap(width, height, imgformat.macrgb16, data)
handle = Res.Resource(name)
self.dict[name] = [1, handle, pixmap, data, width, height]
return handle
def get(self, name):
[cnt, handle, pixmap, data, width, height] = self.dict[name]
return width, height, pixmap
def delete(self, name):
self.dict[name][0] = self.dict[name][0] - 1
if self.dict[name][0] == 0:
del self.dict[name]
_gifkeeper = _Gifkeeper()
--===_0_Mon_Mar_17_16:53:53_CET_1997--
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From just@knoware.nl Tue Mar 18 21:59:20 1997
From: just@knoware.nl (Just van Rossum)
Date: Tue, 18 Mar 1997 22:59:20 +0100
Subject: [PYTHONMAC-SIG] disk-dict for mac?
Message-ID:
Does anybody know of a (PD) disk based dictionary implementation that is
slightly smarter than dumbdbm? That is, it should at least reclaim unused
space. And work on Mac.
Thanks for any pointers,
Just
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From Jack.Jansen@cwi.nl Wed Mar 19 16:16:38 1997
From: Jack.Jansen@cwi.nl (Jack Jansen)
Date: Wed, 19 Mar 1997 17:16:38 +0100
Subject: [PYTHONMAC-SIG] disk-dict for mac?
In-Reply-To: Message by just@knoware.nl (Just van Rossum) ,
Tue, 18 Mar 1997 22:59:20 +0100 ,
Message-ID: <9703191616.AA22837=jack@snelboot.cwi.nl>
Recently, just@knoware.nl (Just van Rossum) said:
> Does anybody know of a (PD) disk based dictionary implementation that is
> slightly smarter than dumbdbm? That is, it should at least reclaim unused
> space. And work on Mac.
Just, you are aware of my gdbm implementation for the mac? If not:
look at http://www.cwi.nl/~jack/macpython.html. If you are aware of it
but it's somehow unsuitable: please let me know why...
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From jurjen@q2c.nl Fri Mar 28 14:29:42 1997
From: jurjen@q2c.nl (Jurjen N.E. Bos)
Date: Fri, 28 Mar 1997 14:29:42 +0000
Subject: [PYTHONMAC-SIG] Python archive generator
Message-ID:
The following Mac Python program can generate archives of text files (for example, Python code :-)
The archive generates spaces for the tabs (3 spaces for a tab), produces proper escape sequences for quotes and backslashes, and warns you for lines longer than 72 chars (that may break on some mailers).
The archive can be unpacked simply by running it through any (not necessarily Mac) python. The produced archives will be checked using MD5, if the unpacking computer has it available. In any case, the length is checked.
Usage:
- run the script
- choose the readme files, and all other files using the dialog boxes
- when all files are done, give "Cancel"
- choose the place to store the archive using the dialog box
(For the transmission, I let it pack itself, of course :-)
#! /usr/local/bin/python
# This is a Python archive; run through your Python to convert.
# Supports bit error detection using MD5 (if available).
# For human readers:
# - File beginnings can be recognized by a "scissors": ----8<----
# - Files begin and end with a triple quote (''').
# - Backslashes and triple quotes are preceded by a backslash.
# Generator written by Jurjen N.E. Bos (jurjen@q2c.nl).
# Files in this archive:
# MakeArchive.py
archive = [
# ----8<---- File: MakeArchive.py.
('MakeArchive.py',2765,'y\0175','''
# Simple Python shar generator for the Mac
# Version 2.4
# uses first three bytes of MD5 as hash function
# Written by Jurjen N.E. Bos
import macfs,string,os,md5
def getFileNames():
fsspec,OK = macfs.PromptGetFile("The README file:","TEXT")
if not OK: return
inFiles = []
while OK:
inFiles.append(fsspec.as_pathname())
fsspec,OK = macfs.PromptGetFile("File #%d:" % len(inFiles),"TEXT")
fsspec,OK = macfs.StandardPutFile("Put the archive in:",
os.path.splitext(os.path.basename(inFiles[0]))[0]+".pyar")
if not OK: return
return inFiles,fsspec.as_pathname()
def convertFile(inputName,outFile):
shortName = os.path.basename(inputName)
print "Archiving file",shortName
data = string.expandtabs(open(inputName).read(),3)
if data[-1] != "\\n": data = data+"\\n"
# write header: name, size, hash
outFile.write("# ----8<---- File: %s.\\n('%s',%d,%s,\'''\\n" %
(shortName,shortName, len(data),
repr(md5.new(data).digest()[:3])
))
# double the backslashes
data = string.join(string.split(data,"\\\\"),"\\\\\\\\")
# handle triple quotes
data = string.join(string.split(data,"\'''"),"\\\\\'''")
outFile.write(data)
outFile.write("\''')")
longLines = filter(lambda x:len(x)>72,string.splitfields(data,"\\n"))
if longLines:
print "The following lines were longer than 72 characters:"
for l in longLines: print l
def main():
inputNames,outputName = getFileNames()
outFile = open(outputName,"w")
outFile.write("""#! /usr/local/bin/python
# This is a Python archive; run through your Python to convert.
# Supports bit error detection using MD5 (if available).
# For human readers:
# - File beginnings can be recognized by a "scissors": ----8<----
# - Files begin and end with a triple quote (\''').
# - Backslashes and triple quotes are preceded by a backslash.
# Generator written by Jurjen N.E. Bos (jurjen@q2c.nl).
# Files in this archive:
""")
for name in inputNames:
outFile.write("# %s\\n" % os.path.basename(name))
outFile.write("\\narchive = [\\n")
for name in inputNames:
convertFile(name,outFile)
if name == inputNames[-1]: outFile.write("]\\n")
else: outFile.write(",\\n")
# watch it! There may be no tabs in the next string!
outFile.write("""
# The unpacking program.
import os
try: import md5
except:
print "Warning: no md5 available; checking size only."
md5 = None
for name,size,hash,contents in archive:
print name,
contents = contents[1:]
if md5 and hash != md5.new(contents).digest()[:3] \\\\
or size != len(contents):
print "corrupt - not written."
elif os.path.isfile(name): print "exists - not written."
else:
open(name,'w').write(contents)
print ": written."
""")
main()
''')]
# The unpacking program.
import os
try: import md5
except:
print "Warning: no md5 available; checking size only."
md5 = None
for name,size,hash,contents in archive:
print name,
contents = contents[1:]
if md5 and hash != md5.new(contents).digest()[:3] \
or size != len(contents):
print "corrupt - not written."
elif os.path.isfile(name): print "exists - not written."
else:
open(name,'w').write(contents)
print ": written."
-- jurjen@q2c.nl ( Jurjen N.E. Bos)
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From jstrout@ucsd.edu Fri Mar 28 16:17:43 1997
From: jstrout@ucsd.edu (Joseph Strout)
Date: Fri, 28 Mar 1997 08:17:43 -0800 (PST)
Subject: [PYTHONMAC-SIG] Python archive generator
In-Reply-To:
Message-ID:
If it converts tabs to 3 spaces, won't this break any code that already
has more than 3 spaces in a row? In minor cases, it won't come out
actually broken, but the checksum won't match. In more serious cases,
this will mess up the indentation (Python assumes tabs are equal to 8
spaces). Why not just convert tabs to "\t" or some such?
-- Joe
,------------------------------------------------------------------.
| Joseph J. Strout Department of Neuroscience, UCSD |
| jstrout@ucsd.edu http://www-acs.ucsd.edu/~jstrout/ |
`------------------------------------------------------------------'
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From tismer@tismer.com Fri Mar 28 16:47:53 1997
From: tismer@tismer.com (Christian Tismer)
Date: Fri, 28 Mar 1997 17:47:53 +0100
Subject: [PYTHONMAC-SIG] Python archive generator
References:
Message-ID: <333BF639.2E09@tismer.com>
Joseph Strout wrote:
>
> If it converts tabs to 3 spaces, won't this break any code that already
> has more than 3 spaces in a row? In minor cases, it won't come out
> actually broken, but the checksum won't match. In more serious cases,
> this will mess up the indentation (Python assumes tabs are equal to 8
> spaces). Why not just convert tabs to "\t" or some such?
Now, here we are. Pipe it through a tab normalizer as I suggested
and everything is fine. Am I right?
ciao - chris
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________
From pete@ike.gams.com Mon Mar 31 16:47:13 1997
From: pete@ike.gams.com (Pete Steacy)
Date: Mon, 31 Mar 1997 11:47:13 -0500
Subject: [PYTHONMAC-SIG] Application Running?
Message-ID:
I need to be able to test if an application that I launched with
findertools.launch(file) is still running. Can anyone tell me how to do
that in Python?
Thanks
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________