]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/Main.py
jconfig.h uses configures results
[wxWidgets.git] / utils / wxPython / demo / Main.py
1 #!/bin/env python
2 #----------------------------------------------------------------------------
3 # Name: Main.py
4 # Purpose: Testing lots of stuff, controls, window types, etc.
5 #
6 # Author: Robin Dunn & Gary Dumer
7 #
8 # Created:
9 # RCS-ID: $Id$
10 # Copyright: (c) 1999 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
13
14 import sys, os
15 from wxPython.wx import *
16
17
18 #---------------------------------------------------------------------------
19
20
21 _treeList = [
22 ('Managed Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame']),
23
24 ('Miscellaneous Windows', ['wxGrid', 'wxSashWindow',
25 'wxScrolledWindow', 'wxSplitterWindow',
26 'wxStatusBar', 'wxToolBar', 'wxNotebook']),
27
28 ('Common Dialogs', ['wxColourDialog', 'wxDirDialog', 'wxFileDialog',
29 'wxSingleChoiceDialog', 'wxTextEntryDialog',
30 'wxFontDialog', 'wxPageSetupDialog', 'wxPrintDialog',
31 'wxMessageDialog']),
32
33 ('Controls', ['wxButton', 'wxCheckBox', 'wxCheckListBox', 'wxChoice',
34 'wxComboBox', 'wxGauge', 'wxListBox', 'wxListCtrl', 'wxTextCtrl',
35 'wxTreeCtrl', 'wxSpinButton', 'wxStaticText', 'wxStaticBitmap',
36 'wxRadioBox', 'wxSlider']),
37
38 ('Window Layout', ['wxLayoutConstraints']),
39
40 ('Micellaneous', ['wxTimer', 'wxGLCanvas', 'DialogUnits', 'wxImage']),
41
42 ('wxPython Library', ['Layoutf', 'wxScrolledMessageDialog',
43 'wxMultipleChoiceDialog', 'wxPlotCanvas']),
44
45 ('Cool Contribs', ['pyTree', 'hangman', 'SlashDot']),
46
47 ]
48
49 #---------------------------------------------------------------------------
50
51 class wxPythonDemo(wxFrame):
52 def __init__(self, parent, id, title):
53 wxFrame.__init__(self, parent, -1, title,
54 wxDefaultPosition, wxSize(700, 550))
55 if wxPlatform == '__WXMSW__':
56 self.icon = wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO)
57 self.SetIcon(self.icon)
58
59 self.otherWin = None
60 EVT_IDLE(self, self.OnIdle)
61
62 self.Centre(wxBOTH)
63 self.CreateStatusBar(1, wxST_SIZEGRIP)
64 splitter = wxSplitterWindow(self, -1)
65 splitter2 = wxSplitterWindow(splitter, -1)
66
67 # Prevent TreeCtrl from displaying all items after destruction
68 self.dying = false
69
70 # Make a File menu
71 self.mainmenu = wxMenuBar()
72 menu = wxMenu()
73 mID = NewId()
74 menu.Append(mID, 'E&xit', 'Get the heck outta here!')
75 EVT_MENU(self, mID, self.OnFileExit)
76 self.mainmenu.Append(menu, '&File')
77
78 # Make a Help menu
79 mID = NewId()
80 menu = wxMenu()
81 menu.Append(mID, '&About', 'wxPython RULES!!!')
82 EVT_MENU(self, mID, self.OnHelpAbout)
83 self.mainmenu.Append(menu, '&Help')
84 self.SetMenuBar(self.mainmenu)
85
86 # Create a TreeCtrl
87 tID = NewId()
88 self.tree = wxTreeCtrl(splitter, tID)
89 root = self.tree.AddRoot("Overview")
90 for item in _treeList:
91 child = self.tree.AppendItem(root, item[0])
92 for childItem in item[1]:
93 self.tree.AppendItem(child, childItem)
94 self.tree.Expand(root)
95 EVT_TREE_ITEM_EXPANDED (self.tree, tID, self.OnItemExpanded)
96 EVT_TREE_ITEM_COLLAPSED (self.tree, tID, self.OnItemCollapsed)
97 EVT_TREE_SEL_CHANGED (self.tree, tID, self.OnSelChanged)
98
99
100 # Create a Notebook
101 self.nb = wxNotebook(splitter2, -1)
102
103 # Set up a TextCtrl on the Overview Notebook page
104 self.ovr = wxTextCtrl(self.nb, -1, '', wxDefaultPosition, wxDefaultSize,
105 wxTE_MULTILINE|wxTE_READONLY)
106 self.nb.AddPage(self.ovr, "Overview")
107
108
109 # Set up a TextCtrl on the Demo Code Notebook page
110 self.txt = wxTextCtrl(self.nb, -1, '', wxDefaultPosition, wxDefaultSize,
111 wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
112 self.nb.AddPage(self.txt, "Demo Code")
113
114
115 # select initial items
116 self.nb.SetSelection(0)
117 self.tree.SelectItem(root)
118
119 # Set up a log on the View Log Notebook page
120 self.log = wxTextCtrl(splitter2, -1, '', wxDefaultPosition, wxDefaultSize,
121 wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
122 (w, self.charHeight) = self.log.GetTextExtent('X')
123 self.WriteText('wxPython Demo Log:\n')
124
125
126 # add the windows to the splitter and split it.
127 splitter.SplitVertically(self.tree, splitter2)
128 splitter.SetSashPosition(180, true)
129 splitter.SetMinimumPaneSize(20)
130
131 splitter2.SplitHorizontally(self.nb, self.log)
132 splitter2.SetSashPosition(360, true)
133 splitter2.SetMinimumPaneSize(20)
134
135 # make our log window be stdout
136 sys.stdout = self
137
138 #---------------------------------------------
139 def WriteText(self, text):
140 self.log.WriteText(text)
141 if wxPlatform == '__WXMSW__':
142 w, h = self.log.GetClientSizeTuple()
143 numLines = h/self.charHeight
144 x, y = self.log.PositionToXY(self.log.GetLastPosition())
145 self.log.ShowPosition(self.log.XYToPosition(x, y-numLines+1))
146
147 def write(self, txt):
148 self.WriteText(txt)
149
150 #---------------------------------------------
151 def OnItemExpanded(self, event):
152 item = event.GetItem()
153 self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
154
155 #---------------------------------------------
156 def OnItemCollapsed(self, event):
157 item = event.GetItem()
158 self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
159
160 #---------------------------------------------
161 def OnSelChanged(self, event):
162 if self.dying:
163 return
164
165 if self.nb.GetPageCount() == 3:
166 if self.nb.GetSelection() == 2:
167 self.nb.SetSelection(0)
168 self.nb.DeletePage(2)
169
170 item = event.GetItem()
171 itemText = self.tree.GetItemText(item)
172
173 if itemText == 'Overview':
174 self.GetDemoFile('Main.py')
175 self.SetOverview('Overview', overview)
176 #self.nb.ResizeChildren();
177 self.nb.Refresh();
178 #wxYield()
179
180 else:
181 if os.path.exists(itemText + '.py'):
182 self.GetDemoFile(itemText + '.py')
183 module = __import__(itemText, globals())
184 self.SetOverview(itemText, module.overview)
185
186 # in case runTest is modal, make sure things look right...
187 self.nb.Refresh();
188 wxYield()
189
190 window = module.runTest(self, self.nb, self)
191 if window:
192 self.nb.AddPage(window, 'Demo')
193 self.nb.SetSelection(2)
194 self.nb.ResizeChildren();
195
196 else:
197 self.ovr.Clear()
198 self.txt.Clear()
199
200
201 #---------------------------------------------
202 # Get the Demo files
203 def GetDemoFile(self, filename):
204 self.txt.Clear()
205 if not self.txt.LoadFile(filename):
206 self.txt.WriteText("Cannot open %s file." % filename)
207
208 self.txt.SetInsertionPoint(0)
209 self.txt.ShowPosition(0)
210
211 #---------------------------------------------
212 def SetOverview(self, name, text):
213 self.ovr.Clear()
214 self.ovr.WriteText(text)
215 self.nb.SetPageText(0, name)
216 self.ovr.SetInsertionPoint(0)
217 self.ovr.ShowPosition(0)
218
219 #---------------------------------------------
220 # Menu methods
221 def OnFileExit(self, event):
222 self.Close()
223
224
225 def OnHelpAbout(self, event):
226 about = wxMessageDialog(self,
227 "wxPython is a Python extension module that\n"
228 "encapsulates the wxWindows GUI classes.\n\n"
229 "This demo shows off some of the capabilities\n"
230 "of wxPython.\n\n"
231 " Developed by Robin Dunn",
232 "About wxPython", wxOK)
233 about.ShowModal()
234 about.Destroy()
235
236
237 #---------------------------------------------
238 def OnCloseWindow(self, event):
239 self.dying = true
240 self.Destroy()
241
242 #---------------------------------------------
243 def OnIdle(self, event):
244 if self.otherWin:
245 self.otherWin.Raise()
246 self.otherWin = None
247
248
249 #---------------------------------------------------------------------------
250 #---------------------------------------------------------------------------
251
252 class MyApp(wxApp):
253 def OnInit(self):
254 wxImage_AddHandler(wxJPEGHandler())
255 wxImage_AddHandler(wxPNGHandler())
256 wxImage_AddHandler(wxGIFHandler())
257 frame = wxPythonDemo(NULL, -1, "wxPython: (A Demonstration)")
258 frame.Show(true)
259 self.SetTopWindow(frame)
260 return true
261
262 #---------------------------------------------------------------------------
263
264 def main():
265 app = MyApp(0)
266 app.MainLoop()
267
268
269 #---------------------------------------------------------------------------
270
271
272
273 overview = """\
274 Python
275 ------------
276
277 Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme, or Java.
278
279 Python combines remarkable power with very clear syntax. It has modules, classes, exceptions, very high level dynamic data types, and dynamic typing. There are interfaces to many system calls and libraries, and new built-in modules are easily written in C or C++. Python is also usable as an extension language for applications that need a programmable interface.
280
281 wxWindows
282 --------------------
283
284 wxWindows is a free C++ framework designed to make cross-platform programming child's play. Well, almost. wxWindows 2 supports Windows 3.1/95/98/NT, Unix with GTK/Motif/Lesstif, with a Mac version underway. Other ports are under consideration.
285
286 wxWindows is a set of libraries that allows C++ applications to compile and run on several different types of computers, with minimal source code changes. There is one library per supported GUI (such as Motif, or Windows). As well as providing a common API (Application Programming Interface) for GUI functionality, it provides functionality for accessing some commonly-used operating system facilities, such as copying or deleting files. wxWindows is a 'framework' in the sense that it provides a lot of built-in functionality, which the application can use or replace as required, thus saving a great deal of coding effort. Basic data structures such as strings, linked lists and hash tables are also supported.
287
288 wxPython
289 ----------------
290
291 wxPython is a Python extension module that encapsulates the wxWindows GUI classes. Currently it is only available for the Win32 and GTK ports of wxWindows, but as soon as the other ports are brought up to the same level as Win32 and GTK, it should be fairly trivial to enable wxPython to be used with the new GUI.
292
293 The wxPython extension module attempts to mirror the class heiarchy of wxWindows as closely as possible. This means that there is a wxFrame class in wxPython that looks, smells, tastes and acts almost the same as the wxFrame class in the C++ version. Unfortunately, because of differences in the languages, wxPython doesn't match wxWindows exactly, but the differences should be easy to absorb because they are natural to Python. For example, some methods that return multiple values via argument pointers in C++ will return a tuple of values in Python.
294
295 There is still much to be done for wxPython, many classes still need to be mirrored. Also, wxWindows is still somewhat of a moving target so it is a bit of an effort just keeping wxPython up to date. On the other hand, there are enough of the core classes completed that useful applications can be written.
296
297 wxPython is close enough to the C++ version that the majority of the wxPython documentation is actually just notes attached to the C++ documents that describe the places where wxPython is different. There is also a series of sample programs included, and a series of documentation pages that assist the programmer in getting started with wxPython.
298 """
299
300
301
302
303
304
305
306 #----------------------------------------------------------------------------
307 #----------------------------------------------------------------------------
308
309 if __name__ == '__main__':
310 main()
311
312 #----------------------------------------------------------------------------
313
314
315
316
317
318
319