BitmapComboBox mit selbst erstellten Bildern

Plattformunabhängige GUIs mit wxWidgets.
Antworten
Benutzeravatar
Mawilo
User
Beiträge: 452
Registriert: Sonntag 22. Februar 2004, 10:58
Wohnort: Sachsen
Kontaktdaten:

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
Benutzeravatar
gerold
Python-Forum Veteran
Beiträge: 5555
Registriert: Samstag 28. Februar 2004, 22:04
Wohnort: Oberhofen im Inntal (Tirol)
Kontaktdaten:

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
:-)
http://halvar.at | Kleiner Bascom AVR Kurs
Wissen hat eine wunderbare Eigenschaft: Es verdoppelt sich, wenn man es teilt.
Benutzeravatar
Mawilo
User
Beiträge: 452
Registriert: Sonntag 22. Februar 2004, 10:58
Wohnort: Sachsen
Kontaktdaten:

Danke Gerold,

dass ist genau, was ich suche :D


Grüße
Mawilo
Antworten