]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/dialogs.py
Refresh of PyCrust
[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 def __init__(self, parent, msg, caption, pos = wxDefaultPosition, size = (500,300)):
9 wxDialog.__init__(self, parent, -1, caption, pos, size)
10 x, y = pos
11 if x == -1 and y == -1:
12 self.CenterOnScreen(wxBOTH)
13 text = wxTextCtrl(self, -1, msg, wxDefaultPosition,
14 wxDefaultSize,
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)
20 self.Layout()
21
22
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)
26 x, y = pos
27 if x == -1 and y == -1:
28 self.CenterOnScreen(wxBOTH)
29 dc = wxClientDC(self)
30 height = 0
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,),
39 (self,)))
40 self.lbox.SetConstraints(Layoutf('t=b10#2;l=l5#1;r=r5#1;b=t5#3',
41 (self, stat, ok)))
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)
45 self.lst = lst
46 self.Layout()
47
48 def GetValue(self):
49 return self.lbox.GetSelections()
50
51 def GetValueString(self):
52 sel = self.lbox.GetSelections()
53 val = []
54 for i in sel:
55 val.append(self.lst[i])
56 return tuple(val)
57
58
59 if __name__ == '__main__':
60 class MyFrame(wxFrame):
61 def __init__(self):
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)
68
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",
74 "m.s.d.", self.lst)
75 if (dlg.ShowModal() == wxID_OK):
76 print "Selection:", dlg.GetValue(), " -> ", dlg.GetValueString()
77
78 def OnMessageTest(self, event):
79 import sys;
80 f = open(sys.argv[0],"r")
81 msg = f.read()
82 dlg = wxScrolledMessageDialog(self, msg, "message test")
83 dlg.ShowModal()
84
85
86 class MyApp(wxApp):
87 def OnInit(self):
88 frame = MyFrame()
89 frame.Show(TRUE)
90 self.SetTopWindow(frame)
91 return TRUE
92
93 app = MyApp(0)
94 app.MainLoop()
95
96
97
98
99
100
101