Python Forum
Create dictionary containing wxpython standard paths
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create dictionary containing wxpython standard paths
#1
The following was written using python 3.6.1 on windows 7
It has not been tested on other platforms

Creates a dictionary (self.std_paths) with the following format:
key: concatenated key like: ExecutablePath
value - list with two items:
   Display name like: Executable Path
   Directory Location Like: C:\Python36\lib\site-packages\wx\_core.cp36-win_amd64.pyd
"""
Author: Larz60+

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

===== Notes for this program =====
Creates a dictionary (self.std_paths) with the following format:
key: concatenated key like: ExecutablePath
value - list with two items:
   Display name like: Executable Path
   Directory Location Like: C:\Python36\lib\site-packages\wx\_core.cp36-win_amd64.pyd
"""
import wx
import re


class wxGetStdPaths():
   def __init__(self):
       self.sp = wx.StandardPaths.Get()
       self.cmds = [
            'GetAppDocumentsDir', 'GetConfigDir', 'GetDataDir',
            'GetDocumentsDir', 'GetExecutablePath', 'GetInstallPrefix',
            'GetLocalDataDir', 'GetPluginsDir', 'GetResourcesDir',
            'GetTempDir', 'GetUserConfigDir', 'GetUserDataDir',
            'GetUserLocalDataDir',
        ]

       self.std_paths = {}
       for name in self.cmds:
           self.getinfo(name)

   def getinfo(self, name, *args):
       func = getattr(self.sp, name)
       func_loc = func(*args)
       fname = func.__doc__
       fname = fname[3:fname.index('(')]
       fwords = re.findall('[A-Z][^A-Z]*', fname)
       spc = ' '
       pname = spc.join(fwords)
       self.std_paths[fname] = [pname, func_loc]


if __name__ == "__main__":
   app = wx.App(False)
   gsp = wxGetStdPaths()
   for key, value in gsp.std_paths.items():
       print('{}: {}: {}'.format(key, value[0], value[1]))
   app.MainLoop()
Output:
AppDocumentsDir: App Documents Dir: C:\Users\...\Documents ConfigDir: Config Dir: C:\ProgramData\appname DataDir: Data Dir: C:\Python36 DocumentsDir: Documents Dir: C:\Users\...\Documents ExecutablePath: Executable Path: C:\Python36\lib\site-packages\wx\_core.cp36-win_amd64.pyd InstallPrefix: Install Prefix: LocalDataDir: Local Data Dir: C:\Python36 PluginsDir: Plugins Dir: C:\Python36 ResourcesDir: Resources Dir: C:\Python36 TempDir: Temp Dir: C:\Users\...\AppData\Local\Temp UserConfigDir: User Config Dir: C:\Users\...\AppData\Roaming UserDataDir: User Data Dir: C:\Users\...\AppData\Roaming\appname UserLocalDataDir: User Local Data Dir: C:\Users\...\AppData\Local\appname
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020