~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/wx/lib/msgpanel.py

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#----------------------------------------------------------------------
 
2
# Name:        wx.lib.msgpanel
 
3
# Purpose:     The MessagePanel class  (Note: this class used to live
 
4
#              in the demo's Main module.)
 
5
#
 
6
# Author:      Robin Dunn
 
7
#
 
8
# Created:     19-Oct-2009
 
9
# RCS-ID:      $Id: $
 
10
# Copyright:   (c) 2009 by Total Control Software
 
11
# Licence:     wxWindows license
 
12
#----------------------------------------------------------------------
 
13
 
 
14
"""
 
15
MessagePanel is a simple panel class for displaying a message, very
 
16
much like how wx.MessageDialog works, including the icon flags.
 
17
"""
 
18
 
 
19
import wx
 
20
 
 
21
#----------------------------------------------------------------------
 
22
 
 
23
class MessagePanel(wx.Panel):
 
24
    def __init__(self, parent, message, caption='', flags=0):
 
25
        wx.Panel.__init__(self, parent)
 
26
 
 
27
        # Make widgets
 
28
        icon = None
 
29
        if flags:
 
30
            artid = None
 
31
            if flags & wx.ICON_EXCLAMATION:
 
32
                artid = wx.ART_WARNING            
 
33
            elif flags & wx.ICON_ERROR:
 
34
                artid = wx.ART_ERROR
 
35
            elif flags & wx.ICON_QUESTION:
 
36
                artid = wx.ART_QUESTION
 
37
            elif flags & wx.ICON_INFORMATION:
 
38
                artid = wx.ART_INFORMATION
 
39
 
 
40
            if artid is not None:
 
41
                bmp = wx.ArtProvider.GetBitmap(artid, wx.ART_MESSAGE_BOX, (32,32))
 
42
                icon = wx.StaticBitmap(self, -1, bmp)
 
43
 
 
44
        if not icon:
 
45
            icon = (32,32) # make a spacer instead
 
46
 
 
47
        if caption:
 
48
            caption = wx.StaticText(self, -1, caption)
 
49
            caption.SetFont(wx.Font(24, wx.SWISS, wx.NORMAL, wx.BOLD))
 
50
 
 
51
        message = wx.StaticText(self, -1, message)
 
52
 
 
53
        # add to sizers for layout
 
54
        tbox = wx.BoxSizer(wx.VERTICAL)
 
55
        if caption:
 
56
            tbox.Add(caption)
 
57
            tbox.Add((10,10))
 
58
        tbox.Add(message)
 
59
        
 
60
        hbox = wx.BoxSizer(wx.HORIZONTAL)
 
61
        hbox.Add((10,10), 1)
 
62
        hbox.Add(icon)
 
63
        hbox.Add((10,10))
 
64
        hbox.Add(tbox)
 
65
        hbox.Add((10,10), 1)
 
66
 
 
67
        box = wx.BoxSizer(wx.VERTICAL)
 
68
        box.Add((10,10), 1)
 
69
        box.Add(hbox, 0, wx.EXPAND)
 
70
        box.Add((10,10), 2)
 
71
 
 
72
        self.SetSizer(box)
 
73
        self.Fit()
 
74
 
 
75
        
 
76
#----------------------------------------------------------------------
 
77
 
 
78
 
 
79
if __name__ == '__main__':
 
80
    app = wx.App(redirect=False)
 
81
    frm = wx.Frame(None, title='MessagePanel Test')
 
82
    pnl = MessagePanel(frm, flags=wx.ICON_EXCLAMATION,
 
83
                       caption="Please stand by...",
 
84
                       message="""\
 
85
This is a test.  This is a test of the emergency broadcast
 
86
system.  Had this been a real emergency, you would have
 
87
already been reduced to a pile of radioactive cinders and
 
88
wondering why 'duck and cover' didn't help.
 
89
 
 
90
This is only a test...""")
 
91
    frm.Sizer = wx.BoxSizer()
 
92
    frm.Sizer.Add(pnl, 1, wx.EXPAND)
 
93
    frm.Fit()
 
94
    frm.Show()
 
95
    app.MainLoop()
 
96