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