Example #1
0
 def do_inDrag(self, partcode, window, event):
     where = event[3]
     self.wid.GetWindowContentRgn(scratchRegion)
     was_l, was_t, r, b = GetRgnBounds(scratchRegion)
     window.DragWindow(where, self.draglimit)
     self.wid.GetWindowContentRgn(scratchRegion)
     is_l, is_t, r, b = GetRgnBounds(scratchRegion)
     self._globalbounds = Qd.OffsetRect(self._globalbounds, is_l - was_l,
                                        is_t - was_t)
Example #2
0
 def _calcbounds(self):
     # calculate absolute bounds relative to the window origin from our
     # abstract _possize attribute, which is either a 4-tuple or a callable object
     oldbounds = self._bounds
     pl, pt, pr, pb = self._parent._bounds
     if callable(self._possize):
         # _possize is callable, let it figure it out by itself: it should return
         # the bounds relative to our parent widget.
         width = pr - pl
         height = pb - pt
         self._bounds = Qd.OffsetRect(
             _intRect(self._possize(width, height)), pl, pt)
     else:
         # _possize must be a 4-tuple. This is where the algorithm by Peter Kriens and
         # Petr van Blokland kicks in. (*** Parts of this algorithm are applied for
         # patents by Ericsson, Sweden ***)
         l, t, r, b = self._possize
         # depending on the values of l(eft), t(op), r(right) and b(ottom),
         # they mean different things:
         if l < -1:
             # l is less than -1, this mean it measures from the *right* of it's parent
             l = pr + l
         else:
             # l is -1 or greater, this mean it measures from the *left* of it's parent
             l = pl + l
         if t < -1:
             # t is less than -1, this mean it measures from the *bottom* of it's parent
             t = pb + t
         else:
             # t is -1 or greater, this mean it measures from the *top* of it's parent
             t = pt + t
         if r > 1:
             # r is greater than 1, this means r is the *width* of the widget
             r = l + r
         else:
             # r is less than 1, this means it measures from the *right* of it's parent
             r = pr + r
         if b > 1:
             # b is greater than 1, this means b is the *height* of the widget
             b = t + b
         else:
             # b is less than 1, this means it measures from the *bottom* of it's parent
             b = pb + b
         self._bounds = (l, t, r, b)
     if oldbounds and oldbounds <> self._bounds:
         self.adjust(oldbounds)
     for w in self._widgets:
         w._calcbounds()
Example #3
0
    def myDrawCell(self, onlyHilite, selected, cellRect, theCell,
                    dataOffset, dataLen, theList):
        savedPort = Qd.GetPort()
        Qd.SetPort(theList.GetListPort())
        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])
                try:
                    key, value = data[6:].split("\t", 1)
                except ValueError:
                    # bogus data, at least don't crash.
                    indent = 0
                    tab = 0
                    iconId = 0
                    key = ""
                    value = data[6:]

                if iconId:
                    try:
                        theIcon = Icn.GetCIcon(iconId)
                    except Icn.Error:
                        pass
                    else:
                        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)
            else:
                return  # we have bogus data

            # 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)