Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e6d13c

Browse files
committed
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.
1 parent 9a29e7a commit 4e6d13c

2 files changed

Lines changed: 146 additions & 2 deletions

File tree

Mac/Tools/IDE/PyBrowser.py

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import string
55
import types
66
import re
7+
from Carbon import Qd, Icn, Fm, QuickDraw
8+
from Carbon.List import GetListPort
9+
from Carbon.QuickDraw import hilitetransfermode
10+
711

812
nullid = '\0\0'
913
closedid = struct.pack('h', 468)
@@ -44,9 +48,62 @@ def double_repr(key, value, truncvalue = 0,
4448
return key + '\t' + value
4549

4650

47-
class BrowserWidget(W.List):
51+
def truncString(s, maxwid):
52+
if maxwid < 1:
53+
return 1, ""
54+
strlen = len(s)
55+
strwid = Qd.TextWidth(s, 0, strlen);
56+
if strwid <= maxwid:
57+
return 0, s
58+
59+
Qd.TextFace(QuickDraw.condense)
60+
strwid = Qd.TextWidth(s, 0, strlen)
61+
ellipsis = Qd.StringWidth('\xc9')
4862

49-
LDEF_ID = 471
63+
if strwid <= maxwid:
64+
Qd.TextFace(0)
65+
return 1, s
66+
if strwid < 1:
67+
Qd.TextFace(0)
68+
return 1, ""
69+
70+
mid = int(strlen * maxwid / strwid)
71+
while 1:
72+
if mid <= 0:
73+
mid = 0
74+
break
75+
strwid = Qd.TextWidth(s, 0, mid) + ellipsis
76+
strwid2 = Qd.TextWidth(s, 0, mid + 1) + ellipsis
77+
if strwid <= maxwid and maxwid <= strwid2:
78+
if maxwid == strwid2:
79+
mid += 1
80+
break
81+
if strwid > maxwid:
82+
mid -= 1
83+
if mid <= 0:
84+
mid = 0
85+
break
86+
elif strwid2 < maxwid:
87+
mid += 1
88+
Qd.TextFace(0)
89+
return 1, s[:mid] + '\xc9'
90+
91+
92+
def drawTextCell(text, cellRect, ascent, theList):
93+
l, t, r, b = cellRect
94+
cellwidth = r - l
95+
Qd.MoveTo(l + 2, t + ascent)
96+
condense, text = truncString(text, cellwidth - 3)
97+
if condense:
98+
Qd.TextFace(QuickDraw.condense)
99+
Qd.DrawText(text, 0, len(text))
100+
Qd.TextFace(0)
101+
102+
103+
PICTWIDTH = 16
104+
105+
106+
class BrowserWidget(W.CustomList):
50107

51108
def __init__(self, possize, object = None, col = 100, closechildren = 0):
52109
W.List.__init__(self, possize, callback = self.listhit)
@@ -299,6 +356,89 @@ def domenu_copy(self, *args):
299356
sc = Scrap.GetCurrentScrap()
300357
sc.PutScrapFlavor('TEXT', 0, text)
301358

359+
def listDefDraw(self, selected, cellRect, theCell,
360+
dataOffset, dataLen, theList):
361+
self.myDrawCell(0, selected, cellRect, theCell,
362+
dataOffset, dataLen, theList)
363+
364+
def listDefHighlight(self, selected, cellRect, theCell,
365+
dataOffset, dataLen, theList):
366+
self.myDrawCell(1, selected, cellRect, theCell,
367+
dataOffset, dataLen, theList)
368+
369+
def myDrawCell(self, onlyHilite, selected, cellRect, theCell,
370+
dataOffset, dataLen, theList):
371+
savedPort = Qd.GetPort()
372+
Qd.SetPort(GetListPort(theList))
373+
savedClip = Qd.NewRgn()
374+
Qd.GetClip(savedClip)
375+
Qd.ClipRect(cellRect)
376+
savedPenState = Qd.GetPenState()
377+
Qd.PenNormal()
378+
379+
l, t, r, b = cellRect
380+
381+
if not onlyHilite:
382+
Qd.EraseRect(cellRect)
383+
384+
ascent, descent, leading, size, hm = Fm.FontMetrics()
385+
linefeed = ascent + descent + leading
386+
387+
if dataLen >= 6:
388+
data = theList.LGetCell(dataLen, theCell)
389+
iconId, indent, tab = struct.unpack("hhh", data[:6])
390+
key, value = data[6:].split("\t", 1)
391+
392+
if iconId:
393+
theIcon = Icn.GetCIcon(iconId)
394+
rect = (0, 0, 16, 16)
395+
rect = Qd.OffsetRect(rect, l, t)
396+
rect = Qd.OffsetRect(rect, 0, (theList.cellSize[1] - (rect[3] - rect[1])) / 2)
397+
Icn.PlotCIcon(rect, theIcon)
398+
399+
if len(key) >= 0:
400+
cl, ct, cr, cb = cellRect
401+
vl, vt, vr, vb = self._viewbounds
402+
cl = vl + PICTWIDTH + indent
403+
cr = vl + tab
404+
if cr > vr:
405+
cr = vr
406+
if cl < cr:
407+
drawTextCell(key, (cl, ct, cr, cb), ascent, theList)
408+
cl = vl + tab
409+
cr = vr
410+
if cl < cr:
411+
drawTextCell(value, (cl, ct, cr, cb), ascent, theList)
412+
#elif dataLen != 0:
413+
# drawTextCell("???", 3, cellRect, ascent, theList)
414+
415+
# draw nice dotted line
416+
l, t, r, b = cellRect
417+
l = self._viewbounds[0] + tab
418+
r = l + 1;
419+
if not (theList.cellSize[1] & 0x01) or (t & 0x01):
420+
myPat = "\xff\x00\xff\x00\xff\x00\xff\x00"
421+
else:
422+
myPat = "\x00\xff\x00\xff\x00\xff\x00\xff"
423+
Qd.PenPat(myPat)
424+
Qd.PenMode(QuickDraw.srcCopy)
425+
Qd.PaintRect((l, t, r, b))
426+
Qd.PenNormal()
427+
428+
if selected or onlyHilite:
429+
l, t, r, b = cellRect
430+
l = self._viewbounds[0] + PICTWIDTH
431+
r = self._viewbounds[2]
432+
Qd.PenMode(hilitetransfermode)
433+
Qd.PaintRect((l, t, r, b))
434+
435+
# restore graphics environment
436+
Qd.SetPort(savedPort)
437+
Qd.SetClip(savedClip)
438+
Qd.DisposeRgn(savedClip)
439+
Qd.SetPenState(savedPenState)
440+
441+
302442

303443
class Browser:
304444

Mac/Tools/IDE/Wlists.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def createlist(self):
4343
self.SetPort()
4444
rect = self._bounds
4545
rect = rect[0]+1, rect[1]+1, rect[2]-16, rect[3]-1
46+
self._viewbounds = rect
4647
self._list = LNew(rect, (0, 0, self._cols, 0), (0, 0), self.LDEF_ID, self._parentwindow.wid,
4748
0, 1, 0, 1)
4849
if self.drawingmode:
@@ -67,6 +68,8 @@ def adjust(self, oldbounds):
6768
l, t, r, b = self._bounds
6869
width = r - l - 17
6970
height = b - t - 2
71+
vl, vt, vr, vb = self._viewbounds
72+
self._viewbounds = vl, vt, vl + width, vt + height
7073
self._list.LSize(width, height)
7174
# now *why* doesn't the list manager recalc the cellrect???
7275
l, t, r, b = self._list.LRect((0,0))
@@ -383,6 +386,7 @@ def createlist(self):
383386
self.SetPort()
384387
rect = self._bounds
385388
rect = rect[0]+1, rect[1]+1, rect[2]-16, rect[3]-1
389+
self._viewbounds = rect
386390
self._list = CreateCustomList(
387391
rect,
388392
(0, 0, 1, 0),

0 commit comments

Comments
 (0)