def OnDrawItem(self, dc, rect, n): 'Invoked by VListBox to draw one menu item' item = self.menu[n] kind = item.Kind s = self.skin iconsize = s.iconsize submenuicon = s.submenuicon padx = self.padding.x selected = self.IsSelected(n) drawbitmap, drawlabel = dc.DrawBitmap, dc.DrawLabel if kind == ITEM_SEPARATOR: s.separatorimage.Draw(dc, rect, n) else: dc.Font = self.font if not item.IsEnabled(): fg = 'disabled' elif selected: fg = 'selection' else: fg = 'normal' dc.TextForeground = getattr(s.fontcolors, fg) grect = Rect(*rect) grect.width = padx + iconsize + padx # icon bitmap bmap = item.Bitmap if bmap and bmap.Ok(): bmap = bmap.ResizedSmaller(iconsize) drawbitmap(bmap, grect.HCenter(bmap), rect.VCenter(bmap), True) # checks and radio circles if item.IsCheckable() and item.IsChecked(): # if there is a menu icon, show the check in the bottom right # otherwise center it if bmap: checkx = grect.Right - s.checkedicon.Width else: checkx = grect.HCenter(s.checkedicon) if kind == ITEM_CHECK: drawbitmap(s.checkedicon, checkx, rect.VCenter(s.checkedicon), True) elif kind == ITEM_RADIO: drawbitmap(s.checkedicon, checkx, rect.VCenter(s.checkedicon), True) # main label rect.Subtract(left = iconsize + 3 * padx) drawlabel(item.Label, rect, indexAccel = item.Text.split('\t')[0].find('&'), alignment = ALIGN_CENTER_VERTICAL) # submenu icon rect.Subtract(right = submenuicon.Width + padx) if item.SubMenu is not None: drawbitmap(submenuicon, rect.Right, rect.VCenter(submenuicon), True) # accelerator text acceltext = item.AccelText if acceltext: rect.x = self.accelColumnX + padx drawlabel(acceltext, rect, alignment = ALIGN_CENTER_VERTICAL)
def CheckBoxHitTest(self, pos): rect = Rect(0, 0, self.ClientSize.width, self.OnMeasureItem(0)) rect = rect.AddMargins(self.margins) for i, r in enumerate(self.CheckBoxRects(rect)): if r.Contains(pos): return i return -1 # not found
def onleftdown(self, e): rem_ico_size = self.rem_ico.Size rect = Rect(self.Size.width - rem_ico_size.width - 4, self.Size.height // 2 - rem_ico_size.height // 2, *rem_ico_size) if rect.Contains(e.Position): self.mouse_flag = True else: e.Skip()
def CheckBoxRects(self, rect): cbsize = self.CheckBoxSize num_checkboxes = 2 rects = [] y = rect.VCenterH(cbsize) for i in reversed(range(num_checkboxes)): r1 = Rect(rect.Right - W * (i+1), y, W, rect.height) r1.x, r1.y = r1.HCenterW(cbsize) + 4, r1.y r1.width = r1.height = cbsize rects.append(r1) return rects
def GetItemRect(self, item, include_children=True): ''' Return a rectangle (in client coordinates) for the given item. If include_children is True (default) children items will be included in the rectangle calculation. ''' if not include_children: return TreeListBase.GetItemRect(self, self.model.index_of(item)) model = self.model modellen = len(self.model) measure = self.OnMeasureItem i = model.index_of(item) rect = Rect(0, self.GetItemY(i), self.ClientRect.width, measure(i)) if include_children: i += 1 while i < modellen and self.GetParent(model[i]) is item: rect.height += measure(i) i += 1 return rect
def OnPaint(self, event): dc = wx.AutoBufferedPaintDC(self) rect = RectS(self.Size) padx, pady = self.padding self.bg.Draw(dc, rect) dc.Font = self.headerfont font_height = self.headerfont.Height dc.TextForeground = self.headerfc dc.DrawBitmap(self.icon, padx, padx + (font_height // 2) - self.icon.Height // 2, True) printable = rect.width - padx curserx = rect.x + 2 * padx + self.icon.Width cursery = rect.y + pady dc.DrawLabel( self.account.display_name, wx.Rect(curserx, cursery, printable - curserx, font_height)) curserx += dc.GetTextExtent(self.account.display_name + ' ')[0] # TODO: remove this hack! if getattr(self.account, 'service', None) != 'twitter': dc.DrawLabel(('' if not hasattr(self.account, 'count') else '(' + str(self.account.count) + ')'), Rect(curserx, cursery, printable - curserx, dc.Font.Height))
def OnDrawSeparator(self, dc, rect, n): 'Draws visual feedback when dragging.' bar, box = self.dragimgs.bar, self.dragimgs.box hilite = getattr(self, 'hilite') if hilite: area, i, drop_to = hilite s = bar.Size # print "area: %s, n: %d, i: %d, (drop_to): %r" % (area, n, i, drop_to) if area == 'below_group' and self.model.is_expanded(i): if n == i + len(drop_to): bar.Draw( dc, Rect(rect.X, rect.Bottom - s.height / 2 + 1, rect.Width, s.height)) return elif area == 'below_group': area = 'below' if n == i: if area == 'box': box.Draw(dc, rect, n) elif area == 'above': bar.Draw( dc, Rect(rect.X, rect.Y - s.height / 2, rect.Width, s.height)) elif area == 'below': bar.Draw( dc, Rect(rect.X, rect.Bottom - s.height / 2 + 1, rect.Width, s.height)) elif n == i + 1: if area == 'below': bar.Draw( dc, Rect(rect.X, rect.Y - s.height / 2, rect.Width, s.height)) elif n == i - 1: if area == 'above': bar.Draw( dc, Rect(rect.X, rect.Bottom - s.height / 2 + 1, rect.Width, s.height))
def DrawContent(self, dc): 'Draws the contents of the button to the DC provided.' offset = ((self.Size.width / 2 - self.ssize[0] / 2) if (not self.menu or self.label != '' and self.icon and self.style == VERTICAL or self.label == '') and not (self.label != '' and self.icon and self.style == HORIZONTAL) else 0, self.Size.height / 2 - self.ssize[1] / 2) ml, mt, mr, mb = self.margins #Draw Icons if self.icon: dc.DrawBitmap(self.icon if self.IsEnabled() else self.dicon, self.iconcurser[0] + offset[0] + ml, self.iconcurser[1] + offset[1] + mt, True) #Draw Labels if self.label != '': dc.Font = self.Font #Set the font color currentstate = 6 if self.state and self.notified else \ 5 if self.isdown else \ self.state + (self.hovered * 2) if self.state else \ 0 dc.TextForeground = self.fontcolors[currentstate] dc.Font = self.Font labelcurser = self.labelcurser loffset = (max(offset[0], 0), max(offset[1], 0)) w = min( self.labelsize.x, self.Rect.Width - labelcurser.x - loffset[0] - self.padding[0] - mr - ((self.menuicon.Width + self.padding[0]) if self.menu and not self.menubarmode else 0)) + 2 lrect = Rect(labelcurser.x + loffset[0] + ml, labelcurser.y + loffset[1] + mt, w, self.labelsize[1]) # dc.Pen=wx.Pen(wx.Color(0,255,0)) # dc.Brush=wx.TRANSPARENT_BRUSH # dc.DrawRectangleRect(lrect) dc.DrawLabel(TruncateText(self.label.replace('&', ''), w, None, dc), lrect, LEFT_VCENTER, indexAccel=self.label.find('&')) #Lastly draw the dropmenu icon if there is a menu if self.type == 'menu' and not self.menubarmode: dc.DrawBitmapPoint( self.menuicon, wx.Point( self.Size.width - self.menuicon.Width - self.padding[0] - mr, (self.Size.height - (mt + mb)) / 2 + mt - self.menuicon.Height / 2), True)
def Draw(self, grid, attr, dc, rect, row, col, isSelected): """ Draw the appropriate icon into the specified grid cell. """ # clear the cell first if isSelected: bgcolor = grid.GetSelectionBackground() else: bgcolor = grid.GetCellBackgroundColour(row, col) dc.SetBackgroundMode(SOLID) dc.SetBrush(Brush(bgcolor, SOLID)) dc.SetPen(TRANSPARENT_PEN) dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height) # find the correct image for this cell bmp = self._get_image(grid, row, col) # find the correct text for this cell text = self._get_text(grid, row, col) # figure out placement -- we try to center things! # fixme: we should be responding to the horizontal/vertical # alignment info in the attr object! size = self.GetBestSize(grid, attr, dc, row, col) halign, valign = attr.GetAlignment() # width first wdelta = rect.width - size.GetWidth() x = rect.x if halign == wx.ALIGN_CENTRE and wdelta > 0: x += wdelta / 2 # now height hdelta = rect.height - size.GetHeight() y = rect.y if valign == wx.ALIGN_CENTRE and hdelta > 0: y += hdelta / 2 dc.SetClippingRegion(*rect) if bmp is not None: # now draw our image into it dc.DrawBitmap(bmp, x, y, 1) x += bmp.GetWidth() if text is not None and text != '': width = rect.x + rect.width - x height = rect.y + rect.height - y # draw any text that should be included new_rect = Rect(x, y, width, height) self._string_renderer.Draw(grid, attr, dc, new_rect, row, col, isSelected) dc.DestroyClippingRegion() return
def leftup(self, e): rem_ico_size = self.rem_ico.Size rect = Rect(self.Size.width - rem_ico_size.width - 4, self.Size.height // 2 - rem_ico_size.height // 2, *rem_ico_size) if rect.Contains(e.Position): if self.mouse_flag: remove_row = getattr(self.Parent, 'remove_row', None) if remove_row is not None: remove_row(self.data) else: p = self.Parent.Parent.Parent wx.CallAfter(p.remove_item, self.data) else: e.Skip() self.mouse_flag = False
def GetItemRect(self, n): pos = self.ScreenRect.Position x = pos.x width = self.Size.x y = pos.y + sum(self.OnMeasureItem(i) for i in xrange(n)) height = self.OnMeasureItem(n) return Rect(x, y, width, height)
def PaintMoreBackground(self, dc, rect): 'Invoked by SkinnedVList, used to draw the gutter.' # draw a gutter down the length of the menu g = self.skin.backgrounds.gutter if g: g.Draw( dc, Rect(rect.x, rect.y, self.skin.iconsize + self.padding.x * 2, rect.height))
def __is_correct_element(self, element, area, location_offset): bad_element_tags = ['option', 'script'] if area: if type(area) not in (tuple, list) or len(area) != 4: raise Exception(u"Bad area data '%s'" % str(area)) area = Rect(*area) x, y = self.browser.get_location(element) if location_offset: # fixing location because it is located inside frame x += location_offset[0] y += location_offset[1] w, h = self.browser.get_dimensions(element) element_center = Point(x + w / 2, y + h / 2) is_element_inside = area.Contains(element_center) else: is_element_inside = True return (self.browser.is_visible(element) and not element.tag_name in bad_element_tags and is_element_inside)
def __paint(self, e): dc = AutoDC(self) dc.Font = self.Font rect = self.list.ClientRect if platformName != 'mac': dc.Pen = TRANSPARENT_PEN dc.Brush = WHITE_BRUSH dc.DrawRectangle(0, 0, self.ClientRect.width, H) r1 = Rect( rect.Right - W * 2, rect.y, W, H ) r2 = Rect( rect.Right - W, rect.y, W, H ) r3 = Rect(*self.list.Rect) r3.Inflate(1,1) dc.DrawLabel(_('Sound'), r1, _hdralign) dc.DrawLabel(_('Popup'), r2, _hdralign) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetPen(wx.Pen(wx.Colour(213,213,213))) dc.DrawRectangleRect(r3)
def _draw_selected_area(self, start_pos, end_pos): # TODO: reimplement - remove lagging x = start_pos[0] if start_pos[0] < end_pos[0] else end_pos[0] y = start_pos[1] if start_pos[1] < end_pos[1] else end_pos[1] w = abs(end_pos[0] - start_pos[0]) h = abs(end_pos[1] - start_pos[1]) self.__selected_area = (x, y, w, h) selected_bitmap = self.original_bitmap.GetSubBitmap(Rect(x, y, w, h)) bitmap = self._get_bitmap(self.greyscaled_bitmap, selected_bitmap, x, y, w, h) self.static_bitmap.SetBitmap(bitmap)
def OnPaint(self, event): "Draws the button's background." # excape if native if self.native: event.Skip() return rect = RectS(self.Size) parent, grandparent = self.Parent, self.GrandParent if parent.__class__.__name__ == "Tab" and self.side_tabs: #Clipping the button for when partualy hidden cliptangle = RectS(self.Size) sy = self.Rect.y sw, sh = self.Size py = parent.Position.y pph = grandparent.Size.height - 16 if parent.Position.y + parent.Size.height > grandparent.Size.height-16 and \ sy + sh + py > pph: cliptangle = Rect(0, 0, sw, pph - (sy + py)) dc = wx.PaintDC(self) dc.SetClippingRect(cliptangle) else: dc = AutoBufferedPaintDC(self) # actual drawing of background currentstate=5 if self.isdown else \ 6 if self.state and self.notified else \ self.state+(self.hovered*2) if self.state else \ 0 if self.rendernative: nrect = rect if self.type == 'combo' else rect.Inflate(1, 1) #wx.RendererNative.Get().DrawPushButton(self,dc,nrect,self.backgrounds[currentstate]) part = 1 state = self.backgrounds[currentstate] self.DrawNativeLike(dc, part, state, nrect) else: background = self.backgrounds[currentstate] from cgui import SplitImage4 if isinstance(background, SplitImage4): ApplySmokeAndMirrors(self, background.GetBitmap(self.Size)) else: ApplySmokeAndMirrors(self) background.Draw(dc, rect) #TODO: Backgroundless icon buttons if not (self.type == 'combo' and self.rendernative): self.DrawContent(dc)
def OnPaint(self, event): dc = wx.PaintDC(self) rect = RectS(self.Size) if not self.side_tabs: rcount = min(len(self.rows), pref('tabs.rows', 2)) height = self.tabs[0].Size.height y=0 for unused_i in xrange(rcount): self.bg.Draw(dc, Rect(rect.x, y, rect.width, height)) y += height else: self.bg.Draw(dc,rect)
def get_field(self, position): position = self._get_fixed_position(position) position = Point(*position) if self.__po_fields: fields_sorted_by_dimensions = sorted(self.__po_fields, key=lambda f: f.dimensions) for field in fields_sorted_by_dimensions: field_x, field_y = field.location w, h = field.dimensions if Rect(field_x, field_y, w, h).Contains(position): return field return None else: return None
def OnDrawItem(self, dc, rect, n): dc.Font=self.Font dc.TextForeground = wx.WHITE if self.Selection==n else wx.BLACK x = rect.x + 3 y = rect.y + rect.height//2 - 8 item = self.buddies[n] dc.DrawBitmap(self.renderer.get_icon(item),x,y,True) textrect = Rect(x + 16 + 3, rect.y, rect.Width - x - 38, rect.Height) dc.DrawLabel(self.renderer.get_label(item), textrect, ALIGN_CENTER_VERTICAL|ALIGN_LEFT)
def test_duckduckgo_search_results_area(self): folder = tempfile.gettempdir() name = 'DuckDuckGo' area = (50, 156, 615, 244) po_class = self.generator.get_po_class_for_url( u'https://duckduckgo.com/?q=selenium&ia=about', name, folder, area) for f in po_class.fields: x, y = f.location w, d = f.dimensions p = Point(x + w / 2, y + d / 2) self.assertTrue(Rect(*area).Contains(p), f) selectors = [f.selector for f in po_class.fields] bys = [f.by for f in po_class.fields] self.assertIn('link text', bys) self.assertIn(u'Selenium - Web Browser Automation', selectors)
def paint(ctrl, e): dc = wx.AutoBufferedPaintDC(ctrl) try: ctrl.PrepareDC(dc) except AttributeError: pass dc.Brush = wx.WHITE_BRUSH dc.Clear() p = wx.BLACK_DASHED_PEN p.SetWidth(10) dc.Pen = p gc = wx.GraphicsContext.Create(dc) r = Rect(0, 0, *f2.Size) b = gc.CreateLinearGradientBrush(r.x, r.y, r.width, r.height, wx.WHITE, wx.BLACK) gc.SetBrush(b) gc.DrawRectangle(*r)
def _get_bitmap(self, bitmap, bitmap_to_draw, x, y, w, h, draw_frame=True): bitmap = bitmap.GetSubBitmap( Rect(0, 0, bitmap.GetWidth(), bitmap.GetHeight())) dc = MemoryDC() bdc = BufferedDC(dc) bdc.SelectObject(bitmap) bdc.DrawBitmap(bitmap_to_draw, x, y) if draw_frame: # Black rect to support white pages bdc.SetPen(BLACK_PEN) bdc.SetBrush(TRANSPARENT_BRUSH) bdc.DrawRectangle(x, y, w, h) # Grey rect to support black pages bdc.SetPen(GREY_PEN) bdc.SetBrush(TRANSPARENT_BRUSH) bdc.DrawRectangle(x + 1, y + 1, w - 2, h - 2) bdc.SelectObject(NullBitmap) return bitmap
def load_image(self, path, area=None): self.Scroll(0, 0) self.img_path = path self.wx_image = Image(path, BITMAP_TYPE_ANY) width = self.wx_image.GetWidth() height = self.wx_image.GetHeight() if area: x, y, w, h = area bitmap = Bitmap(self.wx_image) bitmap_to_draw = bitmap.GetSubBitmap(Rect(x, y, w, h)) bitmap = bitmap.ConvertToImage().ConvertToGreyscale( 0.156, 0.308, 0.060).ConvertToBitmap() self.original_bitmap = self._get_bitmap(bitmap, bitmap_to_draw, x, y, w, h, False) else: self.original_bitmap = Bitmap(self.wx_image) self.greyscaled_bitmap = self.original_bitmap.ConvertToImage( ).ConvertToGreyscale(0.209, 0.411, 0.080).ConvertToBitmap() self.static_bitmap.SetBitmap(self.original_bitmap) self.SetScrollbars(self.MIN_SCROLL, self.MIN_SCROLL, width / self.MIN_SCROLL, height / self.MIN_SCROLL)
def __paint(self, e): dc = wx.AutoBufferedPaintDC(self, style = wx.BUFFER_VIRTUAL_AREA) size = self.ClientSize viewstartx, viewstarty = self.ViewStart viewend = viewstarty + size[1] #region = self.GetUpdateRegion() #regioniter = wx.RegionIterator(region) #while regioniter: # print regioniter.Next() self.bg.Draw(dc, RectPS((viewstartx, viewstarty), size)) #wxRegionIterator upd(GetUpdateRegion()); // get the update rect list left, top, right, bottom = self.GetItemMargins() r = Rect(left, top, *size) r.SetSize((r.Width - right, 0)) visible = self.visible visappend = visible.append del visible[:] selection = self._selection measureitem, drawitem, drawbg = self.OnMeasureItem, self.OnDrawItem, self.OnDrawBackground offset = r.Offset for n in xrange(self._itemcount): itemHeight = measureitem(n) if r.Y > viewend: break if r.Y + itemHeight >= viewstarty:# and region.IntersectRect(wx.Rect(r.X, r.Y + viewstarty, r.Width, r.Height)): r.Height = itemHeight visappend((r.Y - top, r.Y + r.Height + bottom, n)) drawbg(dc, Rect(*r), n, n in selection) drawitem(dc, Rect(*r), n, n in selection) offset((0, itemHeight + top + bottom))
def CalcLayout(self): """ Calculates the layout and height of the pannel based off of it's width and the size of the elements """ dc = MemoryDC() #x and y are the cursor for were the next item will be placed #padx and pady are just local refs to padding.x and padding.y x, y = padx, pady = self.padding sz = self.Size linkfont = self.linkfont minorfont = self.minorfont majorfont = self.majorfont licon = self.licon link = self.link #Positiong the service icon and the status/close icon to the left or # right respectivly self.liconpos = Point(x, y) self.riconpos = Point(sz.width - 16 - padx, y) #incriment x position to right of icon x += licon.Width + padx #Which is taller, the label or the icon h = max(majorfont.Height, 16) #Place title rect with the erlier calculated values and width whats left # of the overall width for the width left for the label self.titlerect = Rect(x, y, sz.width - 4 * padx - licon.Width - 16, h) #incriment y to below the filled space y += h + pady #Find the link width because it's needed to know how much room the # reason rect needs linkwidth = GetTextWidth(link, linkfont) #Determine the horizantal space left for the reason, then wrap it reasonwidth = sz.width - x - (linkwidth + 2 * padx) reason = self.reason() if callable(self.reason) else self.reason wrappedreason = self.wrappedreason = Wrap(reason, reasonwidth, minorfont, dc) #Get the height needed for the label from the wraped string reasonheight = dc.GetMultiLineTextExtent(wrappedreason, minorfont)[1] #combine into a rectangle self.reasonrect = Rect(x, y, reasonwidth, reasonheight) #Figure the rest of the link size information self.linksize = Size(linkwidth, linkfont.LineHeight) #figure out the height the panel has to be in order to fit the content h = max(y + reasonheight + pady, self.liconsize + 2 * padx) newSize = Size(self.MinSize.width, h) if self.MinSize != newSize: self.MinSize = newSize self.Refresh()
def Draw(self, dc, rect, selected, obj, depth, expanded, index, hover, Rect = Rect): DrawBitmap = dc.DrawBitmap DrawTruncatedText = dc.DrawTruncatedText idle_string = get_idle_string(obj) extrafont = self.extrafont extra_info = self.extra_info if self.show_extra else None msg = get_contact_status(obj) padding, extra_padding = self.padding, self.extra_padding contact_name = obj.alias mainfont_height = self.mainfont_height # draw all icons for method, r, align in self.calcdraw(rect.width, rect.height): try: b = method(obj) except: print_exc() else: if b: b.Draw(dc, Rect(rect.x + r.x, rect.y + r.y, r.width, r.height), align) rect = rect.AddMargins(wx.Rect(*self.skin.margins)) rect.x, rect.width = self.inforect.x, self.inforect.width # draw the status message (if necessary) if msg and extra_info in ('status', 'both'): th = self.mainfont.LineHeight + extra_padding + self.extrafont_height rect = Rect(rect.x, rect.VCenterH(th), rect.width, rect.height) namerect = Rect(rect.x, rect.y + 1, rect.Width, self.mainfont.LineHeight) inforect = Rect(rect.x, rect.y + self.mainfont.LineHeight + extra_padding, rect.Width, self.extrafont_height) DrawTruncatedText(self.get_contact_info(obj, dc, selected, expanded, hover), inforect, alignment = lmiddle) else: namerect = rect # draw idle time hpadding = 4 if idle_string and extra_info in ('idle', 'both'): # do some measurements to see if # a) idle time needs to be left aligned against the buddy name, or # b) right aligned and cutting off the buddy name (i.e., buddy na...IDLE) namew, nameh, namedescent, __ = dc.GetFullTextExtent(contact_name, self.mainfont) w, h, desc, __ = dc.GetFullTextExtent(idle_string, extrafont) iy = 3 diff = namew + w + hpadding - namerect.width if diff > 0: x, y = namerect.Pos((-w, 0))[0], namerect.Y r = Rect(x, y, w, namerect.Height) namerect = namerect.Subtract(right = w + hpadding) else: r = Rect(namerect.X + namew + hpadding, namerect.Y, w, namerect.Height) self.set_idle_time_dc(obj, dc, selected, expanded, hover) dc.DrawLabel(idle_string, r, ALIGN_LEFT | ALIGN_CENTER_VERTICAL) # draw buddy name self.set_contact_name_dc(obj, dc, selected, expanded, hover) DrawTruncatedText(contact_name, namerect, alignment = lmiddle)
def calcdraw(self, w, h, Rect = Rect): if self._lastcalc == (w, h): return self._lastseq s = self.skin rect = Rect(0, 0, w, h).AddMargins(wx.Rect(*s.margins)) icons = sorted(((icon, getattr(self, icon + '_pos')) for icon in self.icons), key = lambda o: {'f': -1, 'b': 1}.get(o[1][0], 0)) seq = [] last = Rect() badge_size = min(self.badge_max_size, max(self.badge_min_size, int(self.buddy_icon_size * self.badge_ratio))) frame_size = s.icon_frame_size padding = self.padding hpadding = 4 for icon, pos in icons: if getattr(self, 'show_' + icon): pos = pos.lower() size = getattr(self, icon + '_size') left = pos.endswith('left') iconpos = Point(-size * int(not left), 0) if icon == 'buddy_icon': # special case for buddy icon, which can optionally have a frame around it. iconw = size + frame_size.left + frame_size.right frameRect = Rect(0, 0, iconw, size + frame_size.top + frame_size.bottom) frameRect.x, frameRect.y = rect.Pos(wx.Point(-frameRect.width * int(not left), 0))[0], rect.VCenterH(frameRect.height) last = Rect(frameRect.x + frame_size.left, frameRect.y + frame_size.top, size, size) seq += [(getattr(self, 'get_buddy_icon'), last, 0)] seq += [(getattr(self, 'get_frame_icon'), frameRect, 0)] rect = rect.Subtract(**{'left' if left else 'right': iconw + hpadding}) bitmap = getattr(self, 'get_' + icon) else: if not pos.startswith('b'): # non badge r = Rect(rect.Pos(iconpos)[0], rect.VCenterH(size), size, size) rect = rect.Subtract(**{'left' if left else 'right': size + hpadding}) last = r alignment = ALIGN_CENTER bitmap = getattr(self, 'get_' + icon) else: # badge bp = badge_size alignment = LBOTTOM if left else RBOTTOM badgepos = last.Pos(wx.Point(0 if left else -bp, -bp)) r = Rect(badgepos[0], badgepos[1], badge_size, badge_size) bitmap = lambda obj, icon=icon: getattr(self, 'get_' + icon)(obj).ResizedSmaller(badge_size) seq.append((bitmap, r, alignment)) self.inforect = rect self._lastcalc = (w, h) self._lastseq = seq return seq
def cskin_drawcallback(self, dc, rect, n): self.OnDrawBackground(dc, Rect(*rect), n) self.OnDrawItem(dc, Rect(*rect), n)
def paint(self, e): # # translation from C++ version in VListBox::OnPaint # clientSize = self.ClientSize dc = BufferedPaintDC(self) # the update rectangle rectUpdate = self.GetUpdateClientRect() # fill background crect = self.ClientRect if self.bg is not None: self.bg.Draw(dc, crect) else: dc.Brush = Brush(self.BackgroundColour) dc.Pen = wx.TRANSPARENT_PEN #@UndefinedVariable dc.DrawRectangleRect(RectS(self.Size)) self.PaintMoreBackground(dc, crect) # the bounding rectangle of the current line rectLine = Rect(0, 0, clientSize.x, 0) # iterate over all visible lines lineMax = self.GetVisibleEnd() lineh = self.OnMeasureItem drawbg = self.OnDrawBackground drawsep = self.OnDrawSeparator drawitem = self.OnDrawItem margins = self.GetMargins() for line in xrange(self.GetFirstVisibleLine(), lineMax): try: hLine = lineh(line) except TypeError: log.critical('self.OnMeasureItem was None, returning') del dc return rectLine.height = hLine # and draw the ones which intersect the update rect if rectLine.Intersects(rectUpdate): # don't allow drawing outside of the lines rectangle clip = DCClipper(dc, rectLine) rect = Rect(*rectLine) try: drawbg(dc, Rect(*rect), line) except Exception: print_exc() try: drawsep(dc, Rect(*rect), line) except Exception: print_exc() rect.Deflate(margins.x, margins.y) try: drawitem(dc, rect, line) except Exception: print_exc() del clip else: # no intersection if rectLine.Top > rectUpdate.Bottom: # we are already below the update rect, no need to continue # further break else: #the next line may intersect the update rect pass rectLine.y += hLine return dc
def OnPaint(self, event): 'EVT_PAINT handling' dc = AutoBufferedPaintDC(self) rect = RectS(self.Size) # draw the background background = self.Parent.hoverbg if self.hover else self.Parent.normalbg background.Draw(dc, rect) margins = self.Parent.margins padding = self.Parent.padding # Font setup font = None sp = self.Parent.menu.spine sel = sp.Selection if sel > len(sp.items): sel = sp.Selection = -1 if sel != -1 and sel < len( sp.items) and sel >= 0 and sp.items[sel].font: font = sp.items[sel].font #font.PointSize=self.Font.PointSize else: font = self.Font dc.Font = font color = self.Parent.hoverfc if self.hover else self.Parent.normalfc dc.TextForeground = color fontHeight = font.Height # initial cursor setup if self.Parent.ForceTextFieldBackground: self.Parent.activebg.Draw(dc, rect) label = self.DisplayLabel # Draw text if value is just a string if isinstance(label, basestring): cursor = Point(rect.x + margins.left + padding.x, margins.top + padding.y) if not label and self.empty_text: text = self.empty_text dc.SetTextForeground(self.Parent.hintfc) else: text = label text_rect = Rect(cursor.x, cursor.y, rect.width - cursor.x - margins.right - padding.x, fontHeight) text_rect, text = self.music_note_hack(dc, text_rect, text, fontHeight) dc.DrawTruncatedText(text.split('\n', 1)[0], text_rect, alignment=wx.ALIGN_LEFT | wx.ALIGN_TOP) # or draw each part of the value else: cursor = Point(rect.x + margins.left + padding.x, ((rect.height - margins.top - margins.bottom) / 2) + margins.top) if label is not None: for i in label.content: if isinstance(i, Bitmap): dc.DrawBitmapPoint(i, (cursor.x, cursor.y - i.Height / 2), True) cursor += Point(i.Width + padding.x, 0) elif isinstance(i, basestring): dc.DrawTruncatedText( i.split('\n', 1)[0], wx.Rect( cursor.x, cursor.y - fontHeight / 2, rect.width - cursor.x - margins.right - padding.x, fontHeight), alignment=wx.ALIGN_LEFT | wx.ALIGN_CENTRE_VERTICAL) cursor += Point(dc.GetTextExtent(i)[0] + padding.x, 0) # Draw a background for the textfield if self.txtfld.Shown: # or self.Parent.ForceTextFieldBackground: # dc.Brush = wx.Brush(self.Parent.activebg) # dc.Pen = wx.TRANSPARENT_PEN # # dc.DrawRectangleRect(rect) self.Parent.activebg.Draw(dc, rect)
def RECTtuple_to_rect(r): return Rect(r[0], r[1], r[2]-r[0], r[3]-r[1])