-
Notifications
You must be signed in to change notification settings - Fork 21
/
ProceduralTest.py
executable file
·80 lines (58 loc) · 2.27 KB
/
ProceduralTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
"""
This is a little script that tried to demonstrate a simple "procedural"
program using wxPython. The goal is to have a script that runs through a
few questions for the user, popping up dialogs as it goes, but without a
main frame, and all the baggage that usually comes with writing a full,
event drive app.
"""
import wx
from sys import exit
## Here's an example of a custom dialog with no parent
class MyCheckDialog(wx.Dialog):
def __init__(self, Choices):
wx.Dialog.__init__(self, None, -1, 'wxDialog')
self.Choices = Choices
self.clb = wx.CheckListBox(self, -1, wx.DefaultPosition, wx.DefaultSize, self.Choices)
ok = wx.Button(self, wx.ID_OK, 'Ok')
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.clb, 1, wx.EXPAND|wx.ALL, 5)
sizer.Add(ok, 0, wx.ALIGN_RIGHT|wx.ALL^wx.TOP, 5)
self.SetSizer(sizer)
self.Center() # make it come up on the center of the screen
def GetChecked(self):
Checked = []
for (index, item) in enumerate(self.Choices):
if self.clb.IsChecked(index):
Checked.append(item)
return Checked
# You could put some code here, to run before initializing wx.
# you need to start by initializing a wxApp
if __name__ == '__main__':
app = wx.App(False)
## now you can run your script, bringing up various dialogs.
fd = wx.FileDialog(None,"Pick a File")
if fd.ShowModal() != wx.ID_OK:
exit(1)
else:
print("You choose the file: ", fd.GetFilename())
md = wx.MessageDialog(None, 'Continue?')
if md.ShowModal() != wx.ID_OK:
exit(1)
else:
print("You chose to continue")
scd = wx.SingleChoiceDialog(None, 'Pick One',
'A Single Choice Dialog',
['single', 'choice', 'dialog','with','some','choices'])
if scd.ShowModal() != wx.ID_OK:
exit(1)
else:
print("You chose:", scd.GetStringSelection())
# now lets get some input on the command line:
I = raw_input("type something here >>")
print("You typed:", I)
myd = MyCheckDialog(['check', 'list', 'box', 'another'])
if myd.ShowModal() != wx.ID_OK:
exit(1)
else:
print("You checked:", myd.GetChecked())