def onMESSAGE(self, hwnd, msg, wp, lp): # paint the progressbar from scratch to display text if msg == self.Msg.WM_PAINT: if not self._client_text: return hDC, ps = self.BeginPaint() dc = gdi.DCFromHandle(hDC) dc.SetBkMode('transparent') pos, stop = self.GetPosition(), self.GetRange()[1] rc = self.GetClientRect() # paint left/bottom side of the bar if self.GetStyleL('style') & self.Style.PBS_VERTICAL: rcBar = RECT(0, rc.bottom - rc.top - (pos * rc.bottom / stop), rc.right, rc.bottom) else: rcBar = RECT(0, 0, pos * rc.right / stop, rc.bottom) if not rcBar.IsEmpty(): rg = gdi.RectRegion(rcBar) dc.SetClipRegion(rg) brFg = gdi.SolidBrush(self._client_clrBar) brFg.FillRegion(dc, rg) brFg.Close() dc.SetTextColor(self._client_clrTextHi) font = dc.GetFont() font.DrawText(dc, rc, self._client_text, 'center', 'vcenter', 'singleline') dc.SetClipRegion(None) font.Close() rg.Close() # paint right/top side of the bar if self.GetStyleL('style') & self.Style.PBS_VERTICAL: rcBar.top = rc.top rcBar.bottom = rc.bottom - rc.top - (pos * rc.bottom / stop) - 1 else: rcBar.left = pos * rc.right / stop + 1 rcBar.right = rc.right if not rcBar.IsEmpty(): rg = gdi.RectRegion(rcBar) brBk = gdi.SolidBrush(self._client_clrBk) brBk.FillRegion(dc, rg) brBk.Close() dc.SetClipRegion(rg) dc.SetTextColor(self._client_clrText) font = dc.GetFont() font.DrawText(dc, rc, self._client_text, 'center', 'vcenter', 'singleline') dc.SetClipRegion(None) rg.Close() dc.Close() self.EndPaint(ps) return 0 elif msg == self.Msg.WM_DESTROY: self.onMSG(hwnd, "destroy", 0, 0)
def GetTextExtendM(self, *text): hDC = user32.GetDC(self.Hwnd) if hDC: WM_GETFONT = 49 hFont = self.SendMessage(self.Hwnd, WM_GETFONT, 0, 0) if hFont: hOldFont = gdi32.SelectObject(hDC, hFont) rc = RECT() DT_CALCRECT = 1024 maxL, maxT, maxR, maxB = 0, 0, 0, 0 for i in text: result = user32.DrawTextA(hDC, i, len(i), byref(rc), DT_CALCRECT) maxL, maxT, maxR, maxB = max(maxL, rc.left), max( maxT, rc.top), max(maxR, rc.right), max(maxB, rc.bottom) if not result: if hFont: gdi32.SelectObject(hDC, hOldFont) user32.ReleaseDC(self.Hwnd, hDC) raise RuntimeError( "could not retrieve text extend") # WinError NT only user32.ReleaseDC(self.Hwnd, hDC) if hFont: gdi32.SelectObject(hDC, hOldFont) return maxR - maxL, maxB - maxT return rc.right - rc.left, rc.bottom - rc.top else: raise RuntimeError( "could not retrieve device context") # WinError NT only
def onMESSAGE(self, hwnd, msg, wp, lp): # paint the progressbar from scratch to display text if msg==self.Msg.WM_PAINT: if not self._client_text: return hDC, ps=self.BeginPaint() dc=gdi.DCFromHandle(hDC) dc.SetBkMode('transparent') pos, stop=self.GetPosition(), self.GetRange()[1] rc=self.GetClientRect() # paint left/bottom side of the bar if self.GetStyleL('style') & self.Style.PBS_VERTICAL: rcBar=RECT(0, rc.bottom-rc.top -(pos*rc.bottom/stop), rc.right, rc.bottom) else: rcBar=RECT(0, 0, pos*rc.right/stop, rc.bottom) if not rcBar.IsEmpty(): rg=gdi.RectRegion(rcBar) dc.SetClipRegion(rg) brFg=gdi.SolidBrush(self._client_clrBar) brFg.FillRegion(dc, rg) brFg.Close() dc.SetTextColor(self._client_clrTextHi) font= dc.GetFont() font.DrawText(dc, rc, self._client_text, 'center', 'vcenter', 'singleline') dc.SetClipRegion(None) font.Close() rg.Close() # paint right/top side of the bar if self.GetStyleL('style') & self.Style.PBS_VERTICAL: rcBar.top=rc.top rcBar.bottom= rc.bottom-rc.top -(pos*rc.bottom/stop)-1 else: rcBar.left=pos*rc.right/stop+1 rcBar.right=rc.right if not rcBar.IsEmpty(): rg=gdi.RectRegion(rcBar) brBk=gdi.SolidBrush(self._client_clrBk) brBk.FillRegion(dc, rg) brBk.Close() dc.SetClipRegion(rg) dc.SetTextColor(self._client_clrText) font= dc.GetFont() font.DrawText(dc, rc, self._client_text, 'center', 'vcenter', 'singleline') dc.SetClipRegion(None) rg.Close() dc.Close() self.EndPaint(ps) return 0 elif msg==self.Msg.WM_DESTROY: self.onMSG(hwnd, "destroy", 0, 0)
def GetWindowRect(self): rc = RECT() if user32.GetWindowRect(self.Hwnd, byref(rc)): return rc raise WinError(GetLastError())
def GetChannelRect(self): rc = RECT() self.SendMessage(self.Hwnd, self.Msg.TBM_GETCHANNELRECT, 0, byref(rc)) return rc
def GetThumbRect(self): rc = RECT() self.SendMessage(self.Hwnd, self.Msg.TBM_GETTHUMBRECT, 0, byref(rc)) return rc
def GetLayout(self, Rect): wp= WINDOWPOS() lo= HDLAYOUT(pointer(Rect), pointer(wp)) if self.SendMessage(self.Hwnd, self.Msg.HDM_LAYOUT, 0, byref(lo)): return RECT(wp.x, wp.y, wp.cx, wp.cy) raise RuntimeError("could not retrieve header layout")
def GetItemRect(self, i): rc= RECT() if self.SendMessage(self.Hwnd, self.Msg.HDM_GETITEMRECT, i, byref(rc)): return rc raise RuntimeError("could not retrive item rect")
def GetFormatingRect(self): rc = RECT() self.SendMessage(self.Hwnd, self.Msg.EM_GETRECT, 0, byref(rc)) return rc
def SetMargins(self, left=0, top=0, right=0, bottom=0): rc = RECT(left, top, right, bottom) self.SendMessage(self.Hwnd, self.Msg.TTM_SETMARGIN, 0, byref(rc))
def GetMargins(self, ): rc = RECT() self.SendMessage(self.Hwnd, self.Msg.TTM_GETMARGIN, 0, byref(rc)) return rc.left, rc.top, rc.right, rc.bottom
def GetPartRect(self, i=0): rc = RECT() if not self.SendMessage(self.Hwnd, self.Msg.SB_GETRECT, i, byref(rc)): raise RuntimeError("could not retrieve part rect") return rc
def GetBandRect(self, ID): rc = RECT() if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDRECT, self.IDToIndex(ID), byref(rc)): raise "could not retrieve band rect" return rc
def GetBandBorders(self, ID): rc = RECT() self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDBORDERS, self.IDToIndex(ID), byref(rc)) return rc
def GetItemRect(self, i): rc = RECT() result = self.SendMessage(self.Hwnd, self.Msg.LB_GETITEMRECT, i, byref(rc)) if result == LB_ERR: raise "could not retrieve item rect" return rc