Mailing List Archive

CVS: python/dist/src/Mac/Tools/IDE Wlists.py,1.11,1.12 PyBrowser.py,1.14,1.15
Update of /cvsroot/python/python/dist/src/Mac/Tools/IDE
In directory usw-pr-cvs1:/tmp/cvs-serv18549

Modified Files:
Wlists.py PyBrowser.py
Log Message:
Make object browser work in OSX (by rewriting the old browser
LDEF in Python). If at all possible, this should go into 2.2.1.

Index: Wlists.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Tools/IDE/Wlists.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Wlists.py 31 Dec 2001 14:53:05 -0000 1.11
--- Wlists.py 26 Mar 2002 12:06:11 -0000 1.12
***************
*** 44,47 ****
--- 44,48 ----
rect = self._bounds
rect = rect[0]+1, rect[1]+1, rect[2]-16, rect[3]-1
+ self._viewbounds = rect
self._list = LNew(rect, (0, 0, self._cols, 0), (0, 0), self.LDEF_ID, self._parentwindow.wid,
0, 1, 0, 1)
***************
*** 68,71 ****
--- 69,74 ----
width = r - l - 17
height = b - t - 2
+ vl, vt, vr, vb = self._viewbounds
+ self._viewbounds = vl, vt, vl + width, vt + height
self._list.LSize(width, height)
# now *why* doesn't the list manager recalc the cellrect???
***************
*** 384,387 ****
--- 387,391 ----
rect = self._bounds
rect = rect[0]+1, rect[1]+1, rect[2]-16, rect[3]-1
+ self._viewbounds = rect
self._list = CreateCustomList(
rect,

Index: PyBrowser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Tools/IDE/PyBrowser.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** PyBrowser.py 31 Dec 2001 15:08:04 -0000 1.14
--- PyBrowser.py 26 Mar 2002 12:06:11 -0000 1.15
***************
*** 5,8 ****
--- 5,12 ----
import types
import re
+ from Carbon import Qd, Icn, Fm, QuickDraw
+ from Carbon.List import GetListPort
+ from Carbon.QuickDraw import hilitetransfermode
+

nullid = '\0\0'
***************
*** 45,51 ****


! class BrowserWidget(W.List):

! LDEF_ID = 471

def __init__(self, possize, object = None, col = 100, closechildren = 0):
--- 49,108 ----


! def truncString(s, maxwid):
! if maxwid < 1:
! return 1, ""
! strlen = len(s)
! strwid = Qd.TextWidth(s, 0, strlen);
! if strwid <= maxwid:
! return 0, s

! Qd.TextFace(QuickDraw.condense)
! strwid = Qd.TextWidth(s, 0, strlen)
! ellipsis = Qd.StringWidth('\xc9')
!
! if strwid <= maxwid:
! Qd.TextFace(0)
! return 1, s
! if strwid < 1:
! Qd.TextFace(0)
! return 1, ""
!
! mid = int(strlen * maxwid / strwid)
! while 1:
! if mid <= 0:
! mid = 0
! break
! strwid = Qd.TextWidth(s, 0, mid) + ellipsis
! strwid2 = Qd.TextWidth(s, 0, mid + 1) + ellipsis
! if strwid <= maxwid and maxwid <= strwid2:
! if maxwid == strwid2:
! mid += 1
! break
! if strwid > maxwid:
! mid -= 1
! if mid <= 0:
! mid = 0
! break
! elif strwid2 < maxwid:
! mid += 1
! Qd.TextFace(0)
! return 1, s[:mid] + '\xc9'
!
!
! def drawTextCell(text, cellRect, ascent, theList):
! l, t, r, b = cellRect
! cellwidth = r - l
! Qd.MoveTo(l + 2, t + ascent)
! condense, text = truncString(text, cellwidth - 3)
! if condense:
! Qd.TextFace(QuickDraw.condense)
! Qd.DrawText(text, 0, len(text))
! Qd.TextFace(0)
!
!
! PICTWIDTH = 16
!
!
! class BrowserWidget(W.CustomList):

def __init__(self, possize, object = None, col = 100, closechildren = 0):
***************
*** 299,302 ****
--- 356,442 ----
sc = Scrap.GetCurrentScrap()
sc.PutScrapFlavor('TEXT', 0, text)
+
+ def listDefDraw(self, selected, cellRect, theCell,
+ dataOffset, dataLen, theList):
+ self.myDrawCell(0, selected, cellRect, theCell,
+ dataOffset, dataLen, theList)
+
+ def listDefHighlight(self, selected, cellRect, theCell,
+ dataOffset, dataLen, theList):
+ self.myDrawCell(1, selected, cellRect, theCell,
+ dataOffset, dataLen, theList)
+
+ def myDrawCell(self, onlyHilite, selected, cellRect, theCell,
+ dataOffset, dataLen, theList):
+ savedPort = Qd.GetPort()
+ Qd.SetPort(GetListPort(theList))
+ savedClip = Qd.NewRgn()
+ Qd.GetClip(savedClip)
+ Qd.ClipRect(cellRect)
+ savedPenState = Qd.GetPenState()
+ Qd.PenNormal()
+
+ l, t, r, b = cellRect
+
+ if not onlyHilite:
+ Qd.EraseRect(cellRect)
+
+ ascent, descent, leading, size, hm = Fm.FontMetrics()
+ linefeed = ascent + descent + leading
+
+ if dataLen >= 6:
+ data = theList.LGetCell(dataLen, theCell)
+ iconId, indent, tab = struct.unpack("hhh", data[:6])
+ key, value = data[6:].split("\t", 1)
+
+ if iconId:
+ theIcon = Icn.GetCIcon(iconId)
+ rect = (0, 0, 16, 16)
+ rect = Qd.OffsetRect(rect, l, t)
+ rect = Qd.OffsetRect(rect, 0, (theList.cellSize[1] - (rect[3] - rect[1])) / 2)
+ Icn.PlotCIcon(rect, theIcon)
+
+ if len(key) >= 0:
+ cl, ct, cr, cb = cellRect
+ vl, vt, vr, vb = self._viewbounds
+ cl = vl + PICTWIDTH + indent
+ cr = vl + tab
+ if cr > vr:
+ cr = vr
+ if cl < cr:
+ drawTextCell(key, (cl, ct, cr, cb), ascent, theList)
+ cl = vl + tab
+ cr = vr
+ if cl < cr:
+ drawTextCell(value, (cl, ct, cr, cb), ascent, theList)
+ #elif dataLen != 0:
+ # drawTextCell("???", 3, cellRect, ascent, theList)
+
+ # draw nice dotted line
+ l, t, r, b = cellRect
+ l = self._viewbounds[0] + tab
+ r = l + 1;
+ if not (theList.cellSize[1] & 0x01) or (t & 0x01):
+ myPat = "\xff\x00\xff\x00\xff\x00\xff\x00"
+ else:
+ myPat = "\x00\xff\x00\xff\x00\xff\x00\xff"
+ Qd.PenPat(myPat)
+ Qd.PenMode(QuickDraw.srcCopy)
+ Qd.PaintRect((l, t, r, b))
+ Qd.PenNormal()
+
+ if selected or onlyHilite:
+ l, t, r, b = cellRect
+ l = self._viewbounds[0] + PICTWIDTH
+ r = self._viewbounds[2]
+ Qd.PenMode(hilitetransfermode)
+ Qd.PaintRect((l, t, r, b))
+
+ # restore graphics environment
+ Qd.SetPort(savedPort)
+ Qd.SetClip(savedClip)
+ Qd.DisposeRgn(savedClip)
+ Qd.SetPenState(savedPenState)
+