How to show standard paths (Phoenix)

Keywords : Path, Standard paths.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


First example

img_sample_one.png

ICON file : wxwin.ico

   1 # sample_one.py
   2 
   3 import os
   4 import wx
   5 
   6 # class MyFrame
   7 # class MyApp
   8 
   9 #---------------------------------------------------------------------------
  10 
  11 class MyFrame(wx.Frame):
  12     def __init__(self):
  13         wx.Frame.__init__(self, None, title=wx.GetApp().GetAppName())
  14         self.SetIcon(wx.Icon('wxwin.ico'))
  15 
  16         self._createControls()
  17 
  18         self._updateValues()
  19 
  20     def _createControls(self):
  21         # A Statusbar in the bottom of the window
  22         self.CreateStatusBar(1)
  23         sMsg = 'wxPython ' + wx.version()
  24         self.SetStatusText(sMsg)
  25 
  26         # Add a panel to the frame (needed under Windows to have a nice background)
  27         pnl = wx.Panel(self, wx.ID_ANY)
  28 
  29         szrMain = wx.BoxSizer(wx.VERTICAL)
  30         self._lstResults = wx.ListView(pnl, wx.ID_ANY)
  31         self._lstResults.AppendColumn('Name', wx.LIST_FORMAT_RIGHT)
  32         self._lstResults.AppendColumn('Value')
  33         szrMain.Add(self._lstResults, 1, wx.ALL|wx.EXPAND, 5)
  34         pnl.SetSizer(szrMain)
  35 
  36     def _updateValues(self):
  37         stdPth = wx.StandardPaths.Get()
  38 
  39         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'AppDocumentsDir')
  40         self._lstResults.SetItem(lIndex, 1, stdPth.GetAppDocumentsDir())
  41 
  42         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'ConfigDir')
  43         self._lstResults.SetItem(lIndex, 1, stdPth.GetConfigDir())
  44 
  45         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'DataDir')
  46         self._lstResults.SetItem(lIndex, 1, stdPth.GetDataDir())
  47 
  48         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'DocumentsDir')
  49         self._lstResults.SetItem(lIndex, 1, stdPth.GetDocumentsDir())
  50 
  51         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'ExecutablePath')
  52         self._lstResults.SetItem(lIndex, 1, stdPth.GetExecutablePath())
  53 
  54         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'InstallPrefix')
  55         sValue = stdPth.GetInstallPrefix()
  56         if sValue != '':
  57             self._lstResults.SetItem(lIndex, 1, sValue)
  58         else:
  59             self._lstResults.SetItem(lIndex, 1, 'Unavailable for this system')
  60 
  61         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'LocalDataDir')
  62         self._lstResults.SetItem(lIndex, 1, stdPth.GetLocalDataDir())
  63 
  64         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'LocalizedResourcesDir("lang")')
  65         self._lstResults.SetItem(lIndex, 1, stdPth.GetLocalizedResourcesDir('lang', wx.StandardPaths.ResourceCat_None))
  66 
  67         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'PluginsDir')
  68         self._lstResults.SetItem(lIndex, 1, stdPth.GetPluginsDir())
  69 
  70         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'ResourcesDir')
  71         self._lstResults.SetItem(lIndex, 1, stdPth.GetResourcesDir())
  72 
  73         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'TempDir')
  74         self._lstResults.SetItem(lIndex, 1, stdPth.GetTempDir())
  75 
  76         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'UserConfigDir')
  77         self._lstResults.SetItem(lIndex, 1, stdPth.GetUserConfigDir())
  78 
  79         lIndex = self._lstResults.InsertItem(self._lstResults.GetItemCount(), 'UserDataDir')
  80         self._lstResults.SetItem(lIndex, 1, stdPth.GetUserDataDir())
  81 
  82         for i in range(self._lstResults.ColumnCount):
  83             self._lstResults.SetColumnWidth(i, wx.LIST_AUTOSIZE)
  84 
  85 #---------------------------------------------------------------------------
  86 
  87 class MyApp(wx.App):
  88     def OnInit(self):
  89         print('Running wxPython ' + wx.version())
  90         # Set Current directory to the one containing this file
  91         os.chdir(os.path.dirname(os.path.abspath(__file__)))
  92 
  93         self.SetAppName('wxStandardPaths')
  94 
  95         # Create the main window
  96         frm = MyFrame()
  97         self.SetTopWindow(frm)
  98 
  99         frm.Show()
 100         return True
 101 
 102 #---------------------------------------------------------------------------
 103 
 104 if __name__ == '__main__':
 105     app = MyApp()
 106     app.MainLoop()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Xaviou (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

28/08/19 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to show standard paths (Phoenix) (last edited 2020-12-13 17:28:58 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.