]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/pseudo.py
call wxApp::OnExit() when wxExit() is called and don't do wxLogError from it (replace...
[wxWidgets.git] / wxPython / wxPython / lib / PyCrust / pseudo.py
1 """Provides a variety of classes to create pseudo keywords and pseudo files."""
2
3 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
4 __cvsid__ = "$Id$"
5 __revision__ = "$Revision$"[11:-2]
6
7 class PseudoKeyword:
8 """A callable class that calls a method passed as a parameter.
9
10 Good for creating a pseudo keyword in the python runtime
11 environment. The keyword is really an object that has a repr()
12 that calls itself which calls the method that was passed in the
13 init of the object. All this just to avoid having to type in the
14 closing parens on a method. So, for example:
15
16 >>> quit = PseudoKeyword(SomeObject.someMethod)
17 >>> quit
18
19 SomeObject.someMethod gets executed as if it had been called
20 directly and the user didn't have to type the parens, like
21 "quit()". This technique is most applicable for pseudo keywords
22 like quit, exit and help.
23
24 If SomeObject.someMethod can take parameters, they can still be
25 passed by using the keyword in the traditional way with parens.
26 """
27 def __init__(self, method):
28 """Create a callable object that executes method when called."""
29
30 if callable(method):
31 self.method = method
32 else:
33 raise ValueError, 'method must be callable'
34
35 def __call__(self, *args, **kwds):
36 self.method(*args, **kwds)
37
38 def __repr__(self):
39 self()
40 return ''
41
42
43 class PseudoFile:
44
45 def __init__(self):
46 """Create a file-like object."""
47 pass
48
49 def readline(self):
50 pass
51
52 def write(self, s):
53 pass
54
55 def writelines(self, l):
56 map(self.write, l)
57
58 def flush(self):
59 pass
60
61 def isatty(self):
62 pass
63
64
65 class PseudoFileIn(PseudoFile):
66
67 def __init__(self, readline):
68 if callable(readline):
69 self.readline = readline
70 else:
71 raise ValueError, 'readline must be callable'
72
73 def isatty(self):
74 return 1
75
76
77 class PseudoFileOut(PseudoFile):
78
79 def __init__(self, write):
80 if callable(write):
81 self.write = write
82 else:
83 raise ValueError, 'write must be callable'
84
85 def isatty(self):
86 return 1
87
88
89 class PseudoFileErr(PseudoFile):
90
91 def __init__(self, write):
92 if callable(write):
93 self.write = write
94 else:
95 raise ValueError, 'write must be callable'
96
97 def isatty(self):
98 return 1
99
100
101