Beispiel #1
0
 def gettextextent(self, str):
     hdc = winuser.GetDC()
     dc = wingdi.CreateDCFromHandle(hdc)
     self._hfont_org = dc.SelectObject(self._hfont)
     cx, cy = dc.GetTextExtent(str)
     dc.SelectObjectFromHandle(self._hfont_org)
     dc.Detach()
Beispiel #2
0
 def gettextmetrics(self):
     hdc = winuser.GetDC()
     dc = wingdi.CreateDCFromHandle(hdc)
     self._hfont_org = dc.SelectObject(self._hfont)
     tm = dc.GetTextMetrics()
     dc.SelectObject(self._hfont_org)
     dc.Detach()
     return tm
Beispiel #3
0
 def OnPaint(self, params):
     if self.__dict__['_obj_'] is None:
         return 0
     ps = self.BeginPaint()
     hdc, eraceBg, rcPaint = ps[:3]
     dc = wingdi.CreateDCFromHandle(hdc)
     self.paintOn(dc)
     dc.Detach()
     self.EndPaint(ps)
Beispiel #4
0
    def tkStartup(self, params):
        hdc = params
        self.dc = wingdi.CreateDCFromHandle(hdc)

        # context vars
        self.tk = Tk()
        self.saveidorg = self.tk.saveid = self.dc.SaveDC()
        self._tkstack = []

        self.dc.SetGraphicsMode(win32con.GM_ADVANCED)
        self.dc.SetBkMode(win32con.TRANSPARENT)
        self.dc.SetTextAlign(win32con.TA_BASELINE)
Beispiel #5
0
 def strsizePXL(self, str):
     strlist = string.splitfields(str, '\n')
     hdc = winuser.GetDC()
     dc = wingdi.CreateDCFromHandle(hdc)
     self._hfont_org = dc.SelectObject(self._hfont)
     maxwidth = 0
     height = len(strlist) * self.fontheightPXL()
     for str in strlist:
         cx, cy = dc.GetTextExtent(str)
         if cx > maxwidth:
             maxwidth = cx
     dc.SelectObject(self._hfont_org)
     dc.Detach()
     return maxwidth, height
Beispiel #6
0
def GetDeviceCaps():
    import wingdi
    hdc = winuser.GetDC()
    dc = wingdi.CreateDCFromHandle(hdc)

    width_pxl = dc.GetDeviceCaps(wincon.HORZRES)
    height_pxl = dc.GetDeviceCaps(wincon.VERTRES)

    #Number of pxl per logical inch
    dpi_x = dc.GetDeviceCaps(wincon.LOGPIXELSX)
    dpi_y = dc.GetDeviceCaps(wincon.LOGPIXELSY)

    #width_mm=dc.GetDeviceCaps(wincon.HORZSIZE)
    #height_mm=dc.GetDeviceCaps(wincon.VERTSIZE)
    # or compute them (not the same, why?)
    width_mm = (float(width_pxl) * 25.4) / dpi_x
    height_mm = (float(height_pxl) * 25.4) / dpi_y

    depth = dc.GetDeviceCaps(wincon.BITSPIXEL)
    dc.Detach()
    return width_pxl, height_pxl, width_mm, height_mm, dpi_x, dpi_y, depth
Beispiel #7
0
    def _do_render(self, entry, dc, region):
        cmd = entry[0]
        w = self._window
        if cmd == 'clear' and entry[1]:
            dc.FillSolidRect(self._canvas, RGB(entry[1]))
        elif cmd == 'fg':
            self._curfg = entry[1]
        elif cmd == 'image':
            mask, image, flags, src_x, src_y, dest_x, dest_y, width, height, rcKeep = entry[
                1:]
            if region and not self._overlap_xywh(
                    region, (dest_x, dest_y, width, height)):
                return
            if self._directdraw:
                imghdc = image.GetDC()
                if imghdc:
                    imgdc = wingdi.CreateDCFromHandle(imghdc)
                    dc.BitBlt((dest_x, dest_y), (width, height), imgdc, (0, 0),
                              win32con.SRCCOPY)
                    imgdc.Detach()
                    image.ReleaseDC(imghdc)
            else:
                win32ig.render(dc.GetSafeHdc(),
                               self._bgcolor,
                               mask,
                               image,
                               src_x,
                               src_y,
                               dest_x,
                               dest_y,
                               width,
                               height,
                               rcKeep,
                               aspect="none")
        elif cmd == 'video':
            func = entry[1]
            apply(func, (dc, ))
        elif cmd == 'obj':
            entry[1].draw(dc)
        elif cmd == 'line':
            fg = entry[1]
            points = entry[2]
            x0, y0 = points[0]
            for x, y in points[1:]:
                DrawLine(dc, (x0, y0, x, y), fg)
                x0, y0 = x, y
        elif cmd == '3dhline':
            color1, color2, x0, x1, y = entry[1:]
            if not self._overlap_xywh(region, (x0, y, x1 - x0, 1)):
                return
            DrawLine(dc, (x0, y, x1, y), color1)
            DrawLine(dc, (x0, y + 1, x1, y + 1), color2)
        elif cmd == 'box':
            # XXXX should we subtract 1 from right and bottom edges
            if not self._overlap_ltrb(region, entry[1]):
                return
            DrawRectangle(dc, entry[1], self._curfg)
        elif cmd == 'anchor':
            if not self._overlap_ltrb(region, entry[1]):
                return
            DrawRectangle(dc, entry[1], self._curfg)
            # debug: DrawRectangle(dc,entry[1],(255,0,0))
        elif cmd == 'fbox':
            if not self._overlap_ltrb(region, entry[2]):
                return
            dc.FillSolidRect(entry[2], RGB(entry[1]))
        elif cmd == 'stipplebox':
            if not self._overlap_ltrb(region, entry[2]):
                return
            brush = entry[1]
            rect = entry[2]
            x, y = rect[:2]
            dx, dy = dc.GetViewportOrg()
            x, y = x + dx, y + dy
            oldmode = dc.SetBkMode(win32con.TRANSPARENT)
            oldpen = dc.SelectStockObject(win32con.NULL_PEN)
            brush.UnrealizeObject()
            oldorg = dc.SetBrushOrg((x % 8, y % 8))
            oldbrush = dc.SelectObject(brush)
            dc.Rectangle(rect)
            if 1:  # begin trick for more dense grid pattern
                brush.UnrealizeObject()
                dc.SetBrushOrg(((x + 4) % 8, y % 8))
                dc.SelectObject(brush)
                dc.Rectangle(rect)
                # end_trick
            oldbrush.UnrealizeObject()
            dc.SetBrushOrg(oldorg)
            dc.SelectObject(oldbrush)
            dc.SelectObject(oldpen)
            dc.SetBkMode(oldmode)
        elif cmd == 'font':
            #dc.SetFont(entry[1])
            pass
        elif cmd == 'linewidth':
            #gc.line_width = entry[1]
            pass
        elif cmd == 'fpolygon':
            fg = entry[1]
            FillPolygon(dc, entry[2], fg)
        elif cmd == '3dbox':
            cl, ct, cr, cb = entry[1]
            l, t, w, h = entry[2]
            if not self._overlap_xywh(region, (l, t, w, h)):
                return
            r, b = l + w, t + h
            # l, r, t, b are the corners
            l1 = l + SIZE_3DBORDER
            t1 = t + SIZE_3DBORDER
            r1 = r - SIZE_3DBORDER
            b1 = b - SIZE_3DBORDER
            # draw left side
            FillPolygon(dc, [(l, t), (l1, t1), (l1, b1), (l, b)], cl)
            # draw top side
            FillPolygon(dc, [(l, t), (r, t), (r1, t1), (l1, t1)], ct)
            # draw right side
            FillPolygon(dc, [(r1, t1), (r, t), (r, b), (r1, b1)], cr)
            # draw bottom side
            FillPolygon(dc, [(l1, b1), (r1, b1), (r, b), (l, b)], cb)
##             l = l+1
##             t = t+1
##             r = r-1
##             b = b-1
##             l1 = l - 1
##             t1 = t - 1
##             r1 = r
##             b1 = b
##             ll = l + 2
##             tt = t + 2
##             rr = r - 2
##             bb = b - 3
##             fg = cl
##             ls = [(l1,t1),(ll,tt),(ll,bb),(l1,b1)]
##             FillPolygon(dc,ls, fg)
##             fg = ct
##             ls = [(l1,t1),(r1,t1),(rr,tt),(ll,tt)]
##             FillPolygon(dc,ls, fg)
##             fg = cr
##             ls = [(r1,t1),(r1,b1),(rr,bb),(rr,tt)]
##             FillPolygon(dc,ls, fg)
##             fg = cb
##             ls = [(l1,b1),(ll,bb),(rr,bb),(r1,b1)]
##             FillPolygon(dc,ls, fg)
        elif cmd == 'diamond':
            fg = self._fgcolor
            x, y, w, h = entry[1]
            if not self._overlap_xywh(region, (x, y, w, h)):
                return

            d, m = divmod(w, 2)
            if m == 1:
                w = w + 1

            d, m = divmod(h, 2)
            if m == 1:
                h = h + 1

            ls = [(x, y + h / 2), (x + w / 2, y), (x + w, y + h / 2),
                  (x + w / 2, y + h), (x, y + h / 2)]
            DrawLines(dc, ls, fg)
        elif cmd == 'fdiamond':
            fg = entry[1]  #gc.foreground
            #gc.foreground = entry[1]
            x, y, w, h = entry[2]
            if not self._overlap_xywh(region, (x, y, w, h)):
                return

            d, m = divmod(w, 2)
            if m == 1:
                w = w + 1

            d, m = divmod(h, 2)
            if m == 1:
                h = h + 1

            ls = [(x, y + h / 2), (x + w / 2, y), (x + w, y + h / 2),
                  (x + w / 2, y + h), (x, y + h / 2)]
            FillPolygon(dc, ls, fg)

        elif cmd == '3ddiamond':
            cl, ct, cr, cb = entry[1]
            l, t, w, h = entry[2]
            if not self._overlap_xywh(region, (x, y, w, h)):
                return

            d, m = divmod(w, 2)
            if m == 1:
                w = w + 1

            d, m = divmod(h, 2)
            if m == 1:
                h = h + 1

            r = l + w
            b = t + h
            x = l + w / 2
            y = t + h / 2
            n = int(3.0 * w / h + 0.5)
            ll = l + n
            tt = t + 3
            rr = r - n
            bb = b - 3
            fg = cl  #gc.foreground
            #gc.foreground = cl
            ls = [(l, y), (x, t), (x, tt), (ll, y)]
            FillPolygon(dc, ls, fg)
            fg = ct
            ls = [(x, t), (r, y), (rr, y), (x, tt)]
            FillPolygon(dc, ls, fg)
            fg = cr
            ls = [(r, y), (x, b), (x, bb), (rr, y)]
            FillPolygon(dc, ls, fg)
            fg = cb
            ls = [(l, y), (ll, y), (x, bb), (x, b)]
            FillPolygon(dc, ls, fg)
        elif cmd == 'arrow':
            fg = entry[1]
            if not self._overlap_xywh(region, entry[2]):
                return
            DrawLine(dc, entry[2], fg)
            FillPolygon(dc, entry[3], fg)
        elif cmd == 'text':
            modeorg = dc.SetBkMode(win32con.TRANSPARENT)
            dc.SetTextAlign(win32con.TA_BOTTOM)
            clr_org = dc.SetTextColor(RGB(entry[1]))
            horg = dc.SelectObjectFromHandle(entry[2].handle())
            x, y, str = entry[3:]
            dc.TextOut(x, y, str)
            dc.SetTextColor(clr_org)
            dc.SelectObjectFromHandle(horg)
            dc.SetBkMode(modeorg)
        elif cmd == 'icon':
            if entry[2] != None:
                x, y, w, h = entry[1]
                if not self._overlap_xywh(region, (x, y, w, h)):
                    return
                dc.DrawIcon((x, y), entry[2])
Beispiel #8
0
 def getDC(self, dds):
     hdc = dds.GetDC()
     if not hdc: return None
     return wingdi.CreateDCFromHandle(hdc)
Beispiel #9
0
 def __getDC(self, dds):
     hdc = dds.GetDC()
     return wingdi.CreateDCFromHandle(hdc)
Beispiel #10
0
    def _paintOnDDS(self, dds, dst, rgn=None):
        x, y, w, h = dst
        if w==0 or h==0:
            return

        if rgn:
            xc, yc, wc, hc = self.xywh(rgn.GetRgnBox())
        else:
            xc, yc, wc, hc = dst

        if wc==0 or hc==0:
            return

        if dds.IsLost():
            return

        if self._active_displist:
            entry = self._active_displist._list[0]
            bgcolor = None
            if entry[0] == 'clear' and entry[1]:
                bgcolor = entry[1]
            elif not self._transparent:
                bgcolor = self._bgcolor
            if bgcolor:
                r, g, b = bgcolor
                convbgcolor = dds.GetColorMatch((r,g,b))
                dds.BltFill((xc, yc, xc+wc, yc+hc), convbgcolor)
            if self._redrawdds:
                # get redraw dds info
                vdds, vrcDst, vrcSrc = self._redrawdds
                if self._mediadisplayrect:
                    vrcDst = self._mediadisplayrect

                # src rect taking into account fit
                ws, hs = vrcSrc[2:]
                vrcSrc = self._getmediacliprect(vrcSrc[2:], vrcDst, fit=self._fit)

                # split rects
                ls, ts, rs, bs = self.ltrb(vrcSrc)
                xd, yd, wd, hd = vrcDst
                ld, td, rd, bd = x+xd, y+yd, x+xd+wd, y+yd+hd

                # clip destination
                ldc, tdc, rdc, bdc = self.ltrb(self.rectAnd((xc, yc, wc, hc),
                        (ld, td, rd-ld, bd-td)))

                # find src clip ltrb given the destination clip
                lsc, tsc, rsc, bsc =  self._getsrcclip((ld, td, rd, bd), (ls, ts, rs, bs), (ldc, tdc, rdc, bdc))

                if self._canscroll:
                    dx, dy = self._scrollpos
                    lsc, tsc, rsc, bsc = lsc+dx, tsc+dy, rsc+dx, bsc+dy

                # we are ready, blit it
                if not vdds.IsLost():
                    dds.Blt((ldc, tdc, rdc, bdc), vdds, (lsc, tsc, rsc, bsc), ddraw.DDBLT_WAIT)
                else:
                    vdds.Restore()

            if self._active_displist._issimple:
                try:
                    self._active_displist._ddsrender(dds, dst, rgn, clear=0, mediadisplayrect = self._mediadisplayrect, fit=self._fit)
                except:
                    pass
            else:
                # draw display list but after clear
                try:
                    hdc = dds.GetDC()
                except ddraw.error, arg:
                    print arg
                    return

                dc = wingdi.CreateDCFromHandle(hdc)
                if rgn:
                    dc.SelectClipRgn(rgn)
                x0, y0 = dc.SetWindowOrg((-x,-y))

                try:
                    self._active_displist._render(dc, None, clear=0)
                except:
                    dc.Detach()
                    dds.ReleaseDC(hdc)
                    return

                if self._showing:
                    pass # FrameRect(dc, self._rect,self._showing)

                dc.SetWindowOrg((x0,y0))
                dc.Detach()
                dds.ReleaseDC(hdc)

            # if we have an os-subwindow invalidate its area
            # but do not update it since we want this to happen
            # after the surfaces flipping
            if self._oswnd:
                self._oswnd.InvalidateRect(self._oswnd.GetClientRect())