wxPython: MessageDialog mit eigenem Bildchen

Code-Stücke können hier veröffentlicht werden.
Antworten
Benutzeravatar
gerold
Python-Forum Veteran
Beiträge: 5555
Registriert: Samstag 28. Februar 2004, 22:04
Wohnort: Oberhofen im Inntal (Tirol)
Kontaktdaten:

Damit der Gedanke nicht verloren geht...

Bild

Code: Alles auswählen

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

import wx

wx.SetDefaultPyEncoding("iso-8859-1")


class MyDialog(wx.Dialog):
    """
    MessageDialog mit eigenem Bildchen
    """
    
    def __init__(
        self, parent = None, id = -1, title = "My Dialog",
        style = wx.DEFAULT_DIALOG_STYLE, message = wx.EmptyString, 
        bitmap = None
    ):
        
        wx.Dialog.__init__(self, parent, id, title = title, style = style)
        
        # vbox_main
        vbox_main = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(vbox_main)
        
        # hbox_content
        hbox_content = wx.BoxSizer(wx.HORIZONTAL)
        vbox_main.Add(hbox_content, 1, wx.EXPAND | wx.ALL, 5)
        
        # Bitmap
        if bitmap:
            staticbmp = wx.StaticBitmap(self, bitmap = bitmap)
            hbox_content.Add(staticbmp, 0, wx.ALL, 10)
        
        # Message
        lab_message = wx.StaticText(self, -1, message)
        lab_message.Wrap(300)
        hbox_content.Add(lab_message, 1, wx.ALL, 10)
        
        # Linie
        vbox_main.Add(wx.StaticLine(self), 0, wx.EXPAND)
        
        # hbox_buttons
        hbox_buttons = wx.BoxSizer(wx.HORIZONTAL)
        vbox_main.Add(hbox_buttons, 0, wx.EXPAND | wx.ALL, 5)
        
        # Cancel-Button
        btn_cancel = wx.Button(self, wx.ID_CANCEL, "Abbrechen")
        hbox_buttons.Add(btn_cancel, 0, wx.ALL, 5)
        
        # Spreizer
        hbox_buttons.Add((0, 0), 1)
        
        # OK-Button
        btn_ok = wx.Button(self, wx.ID_OK, "OK")
        hbox_buttons.Add(btn_ok, 0, wx.ALL, 5)
        btn_ok.SetFocus()
        
        self.Fit()


def main():
    """Testing"""
    
    app = wx.PySimpleApp()
    
    bitmap = wx.ArtProvider_GetBitmap(wx.ART_FIND, size = (32, 32))
    
    message = (
        "Das ist die perfekte Welle. "
        "Das ist der perfekte Tag. "
        "Wir sind gekommen um zu bleiben. "
        "Das ist die perfekte Welle. "
        "Das ist der perfekte Tag. "
        "Wir sind gekommen um zu bleiben. "
    )
    
    diag = MyDialog(message = message, bitmap = bitmap)
    if diag.ShowModal() == wx.ID_OK:
        print "OK"
    else:
        print "Cancel"
    

if __name__ == "__main__":
    main()
http://halvar.at | Kleiner Bascom AVR Kurs
Wissen hat eine wunderbare Eigenschaft: Es verdoppelt sich, wenn man es teilt.
Antworten