]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/dialogs.py
6c82207f0522641e1213f3076e0c00cab52ddd99
[wxWidgets.git] / wxPython / wxPython / lib / dialogs.py
1 from wxPython.wx import *
2 from layoutf import Layoutf
3 import string
4
5
6
7 class wxScrolledMessageDialog(wxDialog):
8
9 def __init__(self, parent, msg, caption, pos = wxDefaultPosition, size = (500,300)):
10 wxDialog.__init__(self, parent, -1, caption, pos, size)
11 text = wxTextCtrl(self, -1, msg, wxDefaultPosition,
12 wxDefaultSize,
13 wxTE_MULTILINE | wxTE_READONLY)
14 ok = wxButton(self, wxID_OK, "OK")
15 text.SetConstraints(Layoutf('t=t5#1;b=t5#2;l=l5#1;r=r5#1', (self,ok)))
16 ok.SetConstraints(Layoutf('b=b5#1;x%w50#1;w!80;h!25', (self,)))
17 self.SetAutoLayout(TRUE)
18 self.Layout()
19
20
21 class wxMultipleChoiceDialog(wxDialog):
22
23 def __init__(self, parent, msg, title, lst, pos = wxDefaultPosition, size = (200,200)):
24 wxDialog.__init__(self, parent, -1, title, pos, size)
25 dc = wxClientDC(self)
26 height = 0
27 for line in string.split(msg,'\n'):
28 height = height + dc.GetTextExtent(msg)[1] + 4
29 stat = wxStaticText(self, -1, msg)
30 self.lbox = wxListBox(self, 100, wxDefaultPosition,
31 wxDefaultSize, lst, wxLB_MULTIPLE)
32 ok = wxButton(self, wxID_OK, "OK")
33 cancel = wxButton(self, wxID_CANCEL, "Cancel")
34 stat.SetConstraints(Layoutf('t=t10#1;l=l5#1;r=r5#1;h!%d' % (height,),
35 (self,)))
36 self.lbox.SetConstraints(Layoutf('t=b10#2;l=l5#1;r=r5#1;b=t5#3',
37 (self, stat, ok)))
38 ok.SetConstraints(Layoutf('b=b5#1;x%w25#1;w!80;h!25', (self,)))
39 cancel.SetConstraints(Layoutf('b=b5#1;x%w75#1;w!80;h!25', (self,)))
40 self.SetAutoLayout(TRUE)
41 self.lst = lst
42 self.Layout()
43
44 def GetValue(self):
45 return self.lbox.GetSelections()
46
47 def GetValueString(self):
48 sel = self.lbox.GetSelections()
49 val = []
50 for i in sel:
51 val.append(self.lst[i])
52 return tuple(val)
53
54
55 if __name__ == '__main__':
56 class MyFrame(wxFrame):
57 def __init__(self):
58 wxFrame.__init__(self, NULL, -1, "hello",
59 wxDefaultPosition, wxSize(200,200))
60 wxButton(self, 100, "Multiple Test",wxPoint(0,0))
61 wxButton(self, 101, "Message Test", wxPoint(0,100))
62 EVT_BUTTON(self, 100, self.OnMultipleTest)
63 EVT_BUTTON(self, 101, self.OnMessageTest)
64
65 def OnMultipleTest(self, event):
66 self.lst = [ 'apple', 'pear', 'banana', 'coconut', 'orange',
67 'etc', 'etc..', 'etc...' ]
68 dlg = wxMultipleChoiceDialog(self,
69 "Pick some from\n this list\nblabla",
70 "m.s.d.", self.lst)
71 if (dlg.ShowModal() == wxID_OK):
72 print "Selection:", dlg.GetValue(), " -> ", dlg.GetValueString()
73
74 def OnMessageTest(self, event):
75 import sys;
76 f = open(sys.argv[0],"r")
77 msg = f.read()
78 dlg = wxScrolledMessageDialog(self, msg, "message test")
79 dlg.ShowModal()
80
81
82 class MyApp(wxApp):
83 def OnInit(self):
84 frame = MyFrame()
85 frame.Show(TRUE)
86 self.SetTopWindow(frame)
87 return TRUE
88
89 app = MyApp(0)
90 app.MainLoop()
91
92
93
94
95
96
97