def DrawColonne(self, dc, x, largeur, label="", alignement=None, couleur=None, font=None): """ Dessine une colonne """ render = wx.RendererNative.Get() options = wx.HeaderButtonParams() options.m_labelText = label if alignement : options.m_labelAlignment = alignement if couleur : options.m_labelColour = couleur if font : options.m_labelFont = font render.DrawHeaderButton(self, dc, (x, 1, largeur, self.hauteur), params=options)
def MakeSnapshot(self, maxColumns=1337): if self.FVsnapshot: self.FVsnapshot = None tbmp = wx.Bitmap(16, 16) tdc = wx.MemoryDC() tdc.SelectObject(tbmp) tdc.SetFont(self.font) columnsWidths = [] for i in range(len(self.DEFAULT_COLS)): columnsWidths.append(0) sFit = Fit.getInstance() try: fit = sFit.getFit(self.activeFitID) except Exception as e: pyfalog.critical("Failed to get fit") pyfalog.critical(e) return if fit is None: return slotMap = {} for slot in [e.value for e in FittingSlot]: slotMap[slot] = fit.getSlotsFree(slot) < 0 padding = 2 isize = 16 headerSize = max(isize, tdc.GetTextExtent("W")[0]) + padding * 2 maxRowHeight = isize rows = 0 for st in self.mods: for i, col in enumerate(self.activeColumns): if i > maxColumns: break name = col.getText(st) if not isinstance(name, str): name = "" nx, ny = tdc.GetTextExtent(name) imgId = col.getImageId(st) cw = 0 if imgId != -1: cw += isize + padding if name != "": cw += nx + 4 * padding if imgId == -1 and name == "": cw += isize + padding maxRowHeight = max(ny, maxRowHeight) columnsWidths[i] = max(columnsWidths[i], cw) rows += 1 render = wx.RendererNative.Get() # Fix column widths (use biggest between header or items) for i, col in enumerate(self.activeColumns): if i > maxColumns: break name = col.columnText imgId = col.imageId if not isinstance(name, str): name = "" opts = wx.HeaderButtonParams() if name != "": opts.m_labelText = name if imgId != -1: opts.m_labelBitmap = wx.Bitmap(isize, isize) width = render.DrawHeaderButton(self, tdc, (0, 0, 16, 16), sortArrow=wx.HDR_SORT_ICON_NONE, params=opts) columnsWidths[i] = max(columnsWidths[i], width) tdc.SelectObject(wx.NullBitmap) maxWidth = padding * 2 for i in range(len(self.DEFAULT_COLS)): if i > maxColumns: break maxWidth += columnsWidths[i] mdc = wx.MemoryDC() mbmp = wx.Bitmap(maxWidth, maxRowHeight * rows + padding * 4 + headerSize) mdc.SelectObject(mbmp) mdc.SetBackground(wx.Brush(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))) mdc.Clear() mdc.SetFont(self.font) mdc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)) cx = padding for i, col in enumerate(self.activeColumns): if i > maxColumns: break name = col.columnText imgId = col.imageId if not isinstance(name, str): name = "" opts = wx.HeaderButtonParams() opts.m_labelAlignment = wx.ALIGN_LEFT if name != "": opts.m_labelText = name if imgId != -1: bmp = col.bitmap opts.m_labelBitmap = bmp render.DrawHeaderButton(self, mdc, (cx, padding, columnsWidths[i], headerSize), wx.CONTROL_CURRENT, sortArrow=wx.HDR_SORT_ICON_NONE, params=opts) cx += columnsWidths[i] brush = wx.Brush(wx.Colour(224, 51, 51)) pen = wx.Pen(wx.Colour(224, 51, 51)) mdc.SetPen(pen) mdc.SetBrush(brush) cy = padding * 2 + headerSize for st in self.mods: cx = padding if slotMap[st.slot]: mdc.DrawRectangle(cx, cy, maxWidth - cx, maxRowHeight) for i, col in enumerate(self.activeColumns): if i > maxColumns: break name = col.getText(st) if not isinstance(name, str): name = "" imgId = col.getImageId(st) tcx = cx if imgId != -1: self.imageList.Draw(imgId, mdc, cx, cy, wx.IMAGELIST_DRAW_TRANSPARENT, False) tcx += isize + padding if name != "": nx, ny = mdc.GetTextExtent(name) rect = wx.Rect() rect.top = cy rect.left = cx + 2 * padding rect.width = nx rect.height = maxRowHeight + padding mdc.DrawLabel(name, rect, wx.ALIGN_CENTER_VERTICAL) tcx += nx + padding cx += columnsWidths[i] cy += maxRowHeight mdc.SelectObject(wx.NullBitmap) self.FVsnapshot = mbmp
def OnPaint(self, event): dc = wx.GCDC(wx.PaintDC(self)) #dc = wx.PaintDC(self) render = wx.RendererNative.Get() # Setup Brushes dc.SetBrush(wx.BLACK_BRUSH) dc.SetTextForeground(wx.BLACK) dc.SetFont(wx.NORMAL_FONT) # The below code will use RendererNative to draw controls in # various states. The wx.CONTROL_* flags are used to tell the # Renderer which state to draw the control in. # Draw some checkboxes cb_lbl = "DrawCheckBoxes:" dc.DrawText(cb_lbl, 15, 15) render.DrawCheckBox(self, dc, (25, 35, 16, 16), wx.CONTROL_CHECKED) render.DrawCheckBox(self, dc, (45, 35, 16, 16), wx.CONTROL_CHECKABLE) render.DrawCheckBox(self, dc, (65, 35, 16, 16)) render.DrawCheckBox(self, dc, (85, 35, 16, 16), wx.CONTROL_CHECKED | wx.CONTROL_DISABLED) lbl = "DrawRadioBitmap:" dc.DrawText(lbl, 375, 15) render.DrawRadioBitmap(self, dc, (385, 35, 16, 16), wx.CONTROL_CHECKED) render.DrawRadioBitmap(self, dc, (405, 35, 16, 16), wx.CONTROL_CHECKABLE) render.DrawRadioBitmap(self, dc, (425, 35, 16, 16)) render.DrawRadioBitmap(self, dc, (445, 35, 16, 16), wx.CONTROL_CHECKED | wx.CONTROL_DISABLED) # Draw ComboBoxDropButton xpos = self.GetTextExtent(cb_lbl)[0] + 40 cb_lbl = "DrawComboBoxDropButton:" dc.DrawText(cb_lbl, xpos, 15) render.DrawComboBoxDropButton(self, dc, (xpos + 4, 35, 24, 24), wx.CONTROL_CURRENT) render.DrawComboBoxDropButton(self, dc, (xpos + 44, 35, 24, 24), wx.CONTROL_PRESSED) render.DrawComboBoxDropButton(self, dc, (xpos + 84, 35, 24, 24), wx.CONTROL_CURRENT | wx.CONTROL_DISABLED) render.DrawComboBoxDropButton(self, dc, (xpos + 124, 35, 24, 24), wx.CONTROL_PRESSED | wx.CONTROL_DISABLED) # Draw DropArrow da_lbl = "DrawDropArrow:" dc.DrawText(da_lbl, 15, 80) render.DrawDropArrow(self, dc, (15, 100, 24, 24), wx.CONTROL_CURRENT) render.DrawDropArrow(self, dc, (35, 100, 24, 24), wx.CONTROL_PRESSED) render.DrawDropArrow(self, dc, (55, 100, 24, 24), wx.CONTROL_CURRENT | wx.CONTROL_DISABLED) # Draw HeaderButton dc.DrawText("DrawHeaderButton:", xpos, 80) # Set some extra options for drawing opts = wx.HeaderButtonParams() hb_lbl = "HeaderButton Selected" opts.m_labelText = hb_lbl render.DrawHeaderButton( self, dc, (xpos, 100, self.GetTextExtent(hb_lbl)[0] + 30, 16), wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_DOWN, opts) hb_lbl = "HeaderButton Normal" opts.m_labelText = hb_lbl render.DrawHeaderButton( self, dc, (xpos, 125, self.GetTextExtent(hb_lbl)[0] + 30, 16), sortArrow=wx.HDR_SORT_ICON_UP, params=opts) hb_lbl = "HeaderButton Current" opts.m_labelText = hb_lbl render.DrawHeaderButton( self, dc, (xpos, 150, self.GetTextExtent(hb_lbl)[0] + 30, 16), wx.CONTROL_CURRENT, params=opts) # Draw ItemSelectionRect isr_lbl = "DrawItemSelectionRect:" dc.DrawText(isr_lbl, 15, 185) render.DrawItemSelectionRect(self, dc, (15, 205, 40, 24), wx.CONTROL_SELECTED) render.DrawItemSelectionRect(self, dc, (65, 205, 40, 24), wx.CONTROL_CURRENT) render.DrawItemSelectionRect(self, dc, (115, 205, 40, 24), wx.CONTROL_FOCUSED) # DrawPushButton pb_lbl = "DrawPushButton:" dc.DrawText(pb_lbl, 15, 255) render.DrawPushButton(self, dc, (15, 275, 45, 24), wx.CONTROL_CURRENT) render.DrawPushButton(self, dc, (70, 275, 45, 24), wx.CONTROL_PRESSED | wx.CONTROL_SELECTED) render.DrawPushButton(self, dc, (125, 275, 45, 24), wx.CONTROL_ISDEFAULT) render.DrawPushButton(self, dc, (180, 275, 45, 24), wx.CONTROL_CURRENT | wx.CONTROL_DISABLED) # DrawTreeItemButton ti_lbl = "DrawTreeItemButton:" dc.DrawText(ti_lbl, 15, 330) render.DrawTreeItemButton(self, dc, (15, 350, 16, 16)) render.DrawTreeItemButton(self, dc, (45, 350, 16, 16), wx.CONTROL_EXPANDED) # DrawComboBox dc.DrawText("DrawComboBox:", 270, 185) render.DrawComboBox(self, dc, (270, 205, 100, 21)) render.DrawComboBox(self, dc, (270, 230, 100, 21), wx.CONTROL_DISABLED) render.DrawComboBox(self, dc, (270, 255, 100, 21), wx.CONTROL_CURRENT) render.DrawComboBox(self, dc, (270, 280, 100, 21), wx.CONTROL_PRESSED | wx.CONTROL_SELECTED) render.DrawComboBox(self, dc, (270, 305, 100, 21), wx.CONTROL_FOCUSED) # DrawChoice dc.DrawText("DrawChoice:", 400, 185) render.DrawChoice(self, dc, (400, 205, 100, 21)) render.DrawChoice(self, dc, (400, 230, 100, 21), wx.CONTROL_DISABLED) render.DrawChoice(self, dc, (400, 255, 100, 21), wx.CONTROL_CURRENT) render.DrawChoice(self, dc, (400, 280, 100, 21), wx.CONTROL_PRESSED | wx.CONTROL_SELECTED) render.DrawChoice(self, dc, (400, 305, 100, 21), wx.CONTROL_FOCUSED) # DrawTextCtrl dc.DrawText("DrawTextCtrl:", 270, 350) render.DrawTextCtrl(self, dc, (270, 375, 100, 21)) render.DrawTextCtrl(self, dc, (380, 375, 100, 21), wx.CONTROL_FOCUSED) # DrawItemText render.DrawItemText(self, dc, 'DrawItemText: wx.CONTROL_ISDEFAULT', (270, 420, 300, 21), align=wx.ALIGN_LEFT | wx.ALIGN_TOP, flags=wx.CONTROL_ISDEFAULT, ellipsizeMode=wx.ELLIPSIZE_END) render.DrawItemText(self, dc, 'DrawItemText: wx.CONTROL_SELECTED', (270, 440, 300, 21), align=wx.ALIGN_LEFT | wx.ALIGN_TOP, flags=wx.CONTROL_SELECTED, ellipsizeMode=wx.ELLIPSIZE_END) render.DrawItemText(self, dc, 'DrawItemText: wx.CONTROL_DISABLED', (270, 460, 300, 21), align=wx.ALIGN_LEFT | wx.ALIGN_TOP, flags=wx.CONTROL_DISABLED, ellipsizeMode=wx.ELLIPSIZE_END) # DrawGauge dc.DrawText("DrawGauge:", 15, 380) render.DrawGauge(self, dc, (15, 400, 100, 21), value=20, max=100, flags=wx.CONTROL_ISDEFAULT) render.DrawGauge(self, dc, (15, 430, 100, 21), value=20, max=100, flags=wx.CONTROL_DISABLED) render.DrawGauge(self, dc, (15, 460, 100, 21), value=20, max=100, flags=wx.CONTROL_CURRENT) render.DrawGauge(self, dc, (15, 490, 100, 21), value=20, max=100, flags=wx.CONTROL_FOCUSED)
def test_renderer3(self): hbp = wx.HeaderButtonParams()
def OnPaint(self, evt): dc = wx.PaintDC(self) dc.SetFont(self.GetFont()) r = wx.RendererNative.Get() rect = wx.Rect(40, 10, 95, r.GetHeaderButtonHeight(self)) #print rect # simple helper to make calling DrawHeaderButton so many times a # bit easier and less messy def dhb(idx, rect, flags=0, sort=0, params=None): dc.DrawText("%02d." % idx, rect.x - 25, rect.y) r.DrawHeaderButton(self, dc, rect, flags, sort, params) rect.y += 30 dhb(1, rect) dhb(2, rect, wx.CONTROL_SELECTED) dhb(3, rect, wx.CONTROL_CURRENT) dhb(4, rect, wx.CONTROL_SELECTED | wx.CONTROL_CURRENT) dhb(5, rect, 0, wx.HDR_SORT_ICON_UP) dhb(6, rect, 0, wx.HDR_SORT_ICON_DOWN) dhb(7, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP) dhb(8, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_DOWN) rect.x = 180 rect.y = 10 hp = wx.HeaderButtonParams() hp.m_labelText = "Hello" dhb(9, rect, params=hp) hp.m_labelAlignment = wx.ALIGN_CENTER dhb(10, rect, params=hp) hp.m_labelAlignment = wx.ALIGN_RIGHT dhb(11, rect, params=hp) hp.m_labelAlignment = wx.ALIGN_CENTER dhb(12, rect, wx.CONTROL_SELECTED, 0, hp) dhb(13, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp) hp.m_labelText = "This label is too long" dhb(14, rect, params=hp) dhb(15, rect, wx.CONTROL_SELECTED, 0, hp) dhb(16, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp) rect.x = 320 rect.y = 10 hp = wx.HeaderButtonParams() hp.m_labelBitmap = getBitmap() dhb(17, rect, params=hp) hp.m_labelAlignment = wx.ALIGN_CENTER dhb(18, rect, params=hp) hp.m_labelAlignment = wx.ALIGN_RIGHT dhb(19, rect, params=hp) hp.m_labelAlignment = wx.ALIGN_CENTER dhb(20, rect, wx.CONTROL_SELECTED, 0, hp) dhb(21, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp) hp.m_labelText = "label" hp.m_labelAlignment = wx.ALIGN_LEFT dhb(22, rect, 0, 0, hp) hp.m_labelAlignment = wx.ALIGN_CENTER dhb(23, rect, 0, 0, hp) hp.m_labelAlignment = wx.ALIGN_RIGHT dhb(24, rect, 0, 0, hp) rect.x = 460 rect.y = 10 hp.m_labelAlignment = wx.ALIGN_LEFT dhb(25, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp) hp.m_labelAlignment = wx.ALIGN_CENTER dhb(26, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp) hp.m_labelAlignment = wx.ALIGN_RIGHT dhb(27, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp) hp.m_labelText = "longer label" hp.m_labelAlignment = wx.ALIGN_LEFT dhb(28, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp) hp.m_labelAlignment = wx.ALIGN_CENTER dhb(29, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp) hp.m_labelAlignment = wx.ALIGN_RIGHT dhb(30, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)