]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/appdirs.py
Tweaks for demos on MacOSX
[wxWidgets.git] / wxPython / samples / ide / activegrid / util / appdirs.py
1 #----------------------------------------------------------------------------
2 # Name: appdirs.py
3 # Purpose: Utilities for retrieving special application dirs
4 #
5 # Author: Kevin Ollivier
6 #
7 # Created: 8/27/05
8 # CVS-ID: $Id$
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
12
13 # NOTE: This was made a separate file because it depends upon the
14 # wx.StandardPaths module, and thus, on wxWidgets, unlike other
15 # utils modules. I wanted to ensure this module is never loaded
16 # from the web server, etc.
17
18 import sys
19 import os
20 import string
21 import wx
22
23 def isWindows():
24 return os.name == 'nt'
25
26 def _generateDocumentsDir():
27 path = ""
28 if sys.platform == "win32":
29 from win32com.shell import shell, shellcon
30 path=shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
31 elif sys.platform == "darwin":
32 import macfs, MACFS
33 fsspec_disk, fsspec_desktop = macfs.FindFolder( MACFS.kOnSystemDisk, MACFS.kDocumentsFolderType, 0)
34 path = macfs.FSSpec((fsspec_disk, fsspec_desktop, '')).as_pathname()
35
36 if path == "":
37 path = os.path.expanduser("~")
38
39 return path
40
41 documents_folder = _generateDocumentsDir()
42
43 # NOTE: We don't set this at startup because wxStandardPaths needs a running
44 # application object. This makes sure the wxApp will always be created when
45 # we get the folder.
46 def getAppDataFolder():
47 # wxStandardPaths requires a running app
48 if wx.GetApp() and wx.Platform != "__WXGTK__":
49 data_folder = wx.StandardPaths.Get().GetUserDataDir()
50 if not os.path.exists(data_folder):
51 os.mkdir(data_folder)
52 return data_folder
53 else:
54 # wxBug: on *nix, it wants to point to ~/.appname, but
55 # so does wxConfig... For now, redirect this to ~/.appbuilder
56 # when this is fixed, we'll migrate settings to the correct place
57 return os.path.join(os.path.expanduser("~"), ".appbuilder")
58
59 return ""