]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/py/document.py
Applied patch [ 827011 ] Event-based processing of item tooltips in wxTreeCtrl
[wxWidgets.git] / wxPython / wx / py / document.py
CommitLineData
d14a1e28 1"""Document class."""
1fded56b 2
d14a1e28
RD
3__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
4__cvsid__ = "$Id$"
5__revision__ = "$Revision$"[11:-2]
1fded56b 6
d14a1e28
RD
7import os
8
9try:
10 True
11except NameError:
12 True = 1==1
13 False = 1==0
14
15
16class Document:
17 """Document class."""
18
19 def __init__(self, filename=None):
20 """Create a Document instance."""
21 self.filename = filename
22 self.filepath = None
23 self.filedir = None
24 self.filebase = None
25 self.fileext = None
26 if self.filename:
27 self.filepath = os.path.realpath(self.filename)
28 self.filedir, self.filename = os.path.split(self.filepath)
29 self.filebase, self.fileext = os.path.splitext(self.filename)
30
31 def read(self):
32 """Return contents of file."""
33 if self.filepath and os.path.exists(self.filepath):
34 f = file(self.filepath, 'rb')
35 try:
36 return f.read()
37 finally:
38 f.close()
39 else:
40 return ''
41
42 def write(self, text):
43 """Write text to file."""
44 try:
45 f = file(self.filepath, 'wb')
46 f.write(text)
47 finally:
48 if f:
49 f.close()