1 from wxPython
.wx
import *
2 from layoutf
import Layoutf
7 class wxScrolledMessageDialog(wxDialog
):
9 def __init__(self
, parent
, msg
, caption
, pos
= None, size
= None):
11 pos
= wxDefaultPosition
13 size
= wxSize(500,300)
14 wxDialog
.__init
__(self
, parent
, -1, caption
, pos
, size
)
15 text
= wxTextCtrl(self
, -1, msg
, wxDefaultPosition
,
17 wxTE_MULTILINE | wxTE_READONLY
)
18 ok
= wxButton(self
, wxID_OK
, "OK")
19 text
.SetConstraints(Layoutf('t=t5#1;b=t5#2;l=l5#1;r=r5#1', (self
,ok
)))
20 ok
.SetConstraints(Layoutf('b=b5#1;x%w50#1;w!80;h!25', (self
,)))
21 self
.SetAutoLayout(TRUE
)
25 class wxMultipleChoiceDialog(wxDialog
):
27 def __init__(self
, parent
, msg
, title
, lst
, pos
= None, size
= None):
29 pos
= wxDefaultPosition
31 size
= wxSize(200,200)
32 wxDialog
.__init
__(self
, parent
, -1, title
, pos
, size
)
35 for line
in string
.split(msg
,'\n'):
36 height
= height
+ dc
.GetTextExtent(msg
)[1] + 4
37 stat
= wxStaticText(self
, -1, msg
)
38 self
.lbox
= wxListBox(self
, 100, wxDefaultPosition
,
39 wxDefaultSize
, lst
, wxLB_MULTIPLE
)
40 ok
= wxButton(self
, wxID_OK
, "OK")
41 cancel
= wxButton(self
, wxID_CANCEL
, "Cancel")
42 stat
.SetConstraints(Layoutf('t=t10#1;l=l5#1;r=r5#1;h!%d' % (height
,),
44 self
.lbox
.SetConstraints(Layoutf('t=b10#2;l=l5#1;r=r5#1;b=t5#3',
46 ok
.SetConstraints(Layoutf('b=b5#1;x%w25#1;w!80;h!25', (self
,)))
47 cancel
.SetConstraints(Layoutf('b=b5#1;x%w75#1;w!80;h!25', (self
,)))
48 self
.SetAutoLayout(TRUE
)
51 EVT_SIZE(self
, self
.OnSize
)
53 def OnSize(self
, event
):
57 return self
.lbox
.GetSelections()
59 def GetValueString(self
):
60 sel
= self
.lbox
.GetSelections()
63 val
.append(self
.lst
[i
])
66 if __name__
== '__main__':
67 class MyFrame(wxFrame
):
69 wxFrame
.__init
__(self
, NULL
, -1, "hello",
70 wxDefaultPosition
, wxSize(200,200))
71 wxButton(self
, 100, "Multiple Test",wxPoint(0,0))
72 wxButton(self
, 101, "Message Test", wxPoint(0,100))
73 EVT_BUTTON(self
, 100, self
.OnMultipleTest
)
74 EVT_BUTTON(self
, 101, self
.OnMessageTest
)
76 def OnMultipleTest(self
, event
):
77 self
.lst
= [ 'apple', 'pear', 'banana', 'coconut', 'orange',
78 'etc', 'etc..', 'etc...' ]
79 dlg
= wxMultipleChoiceDialog(self
,
80 "Pick some from\n this list\nblabla",
82 if (dlg
.ShowModal() == wxID_OK
):
83 print "Selection:", dlg
.GetValue(), " -> ", dlg
.GetValueString()
85 def OnMessageTest(self
, event
):
87 f
= open(sys
.argv
[0],"r")
89 dlg
= wxScrolledMessageDialog(self
, msg
, "message test")
97 self
.SetTopWindow(frame
)