Seite 1 von 1

BitmapComboBox mit selbst erstellten Bildern

Verfasst: Montag 6. Oktober 2008, 21:25
von Mawilo
Hallo,

ich möchte gerne in einer BitmapComboBox Bilder anzeigen, die ich selbst über DC erstellt habe. Leider bekomme ich es nicht hin. Es wird nichts angezeigt. Hier ein Code-Beispiel:

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

import wx
import wx.combo

class MainFrame(wx.Frame):
    def __init__(self, ):
        wx.Frame.__init__(self, None, -1, 'Test BitmapComboBox')
        panel = wx.Panel(self)
        self.bcb = wx.combo.BitmapComboBox(panel, -1, size=(250, 21))
        size = (40, 23)
        self.bmp = self.getBitmap(size)
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.drawFigure()
        self.setBitmap()
        
    def setBitmap(self):
        self.bcb.Append('Eintrag1', self.bmp)
        
    def getBitmap(self, size):
        bmp = wx.EmptyBitmap(*size)
        self.dc = wx.MemoryDC(bmp)
        self.dc.SetBackground(wx.WHITE_BRUSH)
        self.dc.Clear()
        self.dc.SelectObject(wx.NullBitmap)
        return bmp
    
    def on_paint(self, event=None):
        wx.BufferedPaintDC(self, self.bmp, style=wx.BUFFER_VIRTUAL_AREA)

    def drawFigure(self):
        color = 'black'
        brush = wx.Brush(color)
        brush.SetStyle(wx.BDIAGONAL_HATCH)
        self.dc.SetBrush(brush)
        pen = wx.Pen(color, 1, wx.DOT)
        self.dc.SetPen(pen)
        self.dc.DrawRectangle(2, 2, 22, 14)
        
if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MainFrame()
    frame.Center()
    frame.Show()
    app.MainLoop()
Hat jemand eine Idee, was da falsch ist?

Grüße
Mawilo

Re: BitmapComboBox mit selbst erstellten Bildern

Verfasst: Dienstag 7. Oktober 2008, 12:43
von gerold
Hallo Mawilo!

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

import wx
import wx.combo

class MainFrame(wx.Frame):
    
    def __init__(self, ):
        wx.Frame.__init__(self, None, -1, 'Test BitmapComboBox')
        panel = wx.Panel(self)
        self.bcb = wx.combo.BitmapComboBox(panel, -1, size=(250, 21))
        size = (40, 23)
        
        bmp = self.getBitmap(size)
        self.setBitmap(bmp)
        
        bmp = self.get_antialiased_bitmap(size)
        self.setBitmap(bmp)
    
    
    def setBitmap(self, bmp):
        self.bcb.Append('Eintrag1', bmp)
    
    
    def getBitmap(self, size):
        bmp = wx.EmptyBitmap(*size)
        dc = wx.MemoryDC(bmp)
        dc.SetBackground(wx.WHITE_BRUSH)
        dc.Clear()
        
        color = 'black'
        brush = wx.Brush(color)
        brush.SetStyle(wx.BDIAGONAL_HATCH)
        dc.SetBrush(brush)
        pen = wx.Pen(color, 1, wx.DOT)
        dc.SetPen(pen)
        dc.DrawRectangle(2, 2, 22, 14)
        
        dc.SelectObject(wx.NullBitmap)
        return bmp
    
    
    def get_antialiased_bitmap(self, size):
        color = 'black'
        bmp = wx.EmptyBitmap(*size)
        dc = wx.MemoryDC(bmp)
        dc.SetBackground(wx.WHITE_BRUSH)
        dc.Clear()
        gc = wx.GraphicsContext_Create(dc)
        
        brush = wx.Brush(color)
        brush.SetStyle(wx.BDIAGONAL_HATCH)
        gc.SetBrush(brush)
        pen = wx.Pen(color, 1, wx.DOT)
        gc.SetPen(pen)
        gc.DrawRectangle(2, 2, 22, 14)
        
        dc.SelectObject(wx.NullBitmap)
        return bmp


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MainFrame()
    frame.Center()
    frame.Show()
    app.MainLoop()
lg
Gerold
:-)

Verfasst: Dienstag 7. Oktober 2008, 13:29
von Mawilo
Danke Gerold,

dass ist genau, was ich suche :D


Grüße
Mawilo