]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/lib/dialogs.py
wxPython 2.0b9, first phase (win32)
[wxWidgets.git] / utils / 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 = None, size = None):
10 if not pos:
11 pos = wxDefaultPosition
12 if not size:
13 size = wxSize(500,300)
14 wxDialog.__init__(self, parent, -1, caption, pos, size)
15 text = wxTextCtrl(self, -1, msg, wxDefaultPosition,
16 wxDefaultSize,
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)
22
23
24
25 class wxMultipleChoiceDialog(wxDialog):
26
27 def __init__(self, parent, msg, title, lst, pos = None, size = None):
28 if not pos:
29 pos = wxDefaultPosition
30 if not size:
31 size = wxSize(200,200)
32 wxDialog.__init__(self, parent, -1, title, pos, size)
33 dc = wxClientDC(self)
34 height = 0
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,),
43 (self,)))
44 self.lbox.SetConstraints(Layoutf('t=b10#2;l=l5#1;r=r5#1;b=t5#3',
45 (self, stat, ok)))
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)
49 self.lst = lst
50
51 def OnSize(self, event):
52 self.Layout()
53
54 def GetValue(self):
55 return self.lbox.GetSelections()
56
57 def GetValueString(self):
58 sel = self.lbox.GetSelections()
59 val = []
60 for i in sel:
61 val.append(self.lst[i])
62 return tuple(val)
63
64 if __name__ == '__main__':
65 class MyFrame(wxFrame):
66 def __init__(self):
67 wxFrame.__init__(self, NULL, -1, "hello",
68 wxDefaultPosition, wxSize(200,200))
69 wxButton(self, 100, "Multiple Test",wxPoint(0,0))
70 wxButton(self, 101, "Message Test", wxPoint(0,100))
71 EVT_BUTTON(self, 100, self.OnMultipleTest)
72 EVT_BUTTON(self, 101, self.OnMessageTest)
73
74 def OnMultipleTest(self, event):
75 self.lst = [ 'apple', 'pear', 'banana', 'coconut', 'orange',
76 'etc', 'etc..', 'etc...' ]
77 dlg = wxMultipleChoiceDialog(self,
78 "Pick some from\n this list\nblabla",
79 "m.s.d.", self.lst)
80 if (dlg.ShowModal() == wxID_OK):
81 print "Selection:", dlg.GetValue(), " -> ", dlg.GetValueString()
82
83 def OnMessageTest(self, event):
84 import sys;
85 f = open(sys.argv[0],"r")
86 msg = f.read()
87 dlg = wxScrolledMessageDialog(self, msg, "message test")
88 dlg.ShowModal()
89
90
91 class MyApp(wxApp):
92 def OnInit(self):
93 frame = MyFrame()
94 frame.Show(TRUE)
95 self.SetTopWindow(frame)
96 return TRUE
97
98 app = MyApp(0)
99 app.MainLoop()
100
101
102
103
104
105
106