wx.FileHistory and wx.Config

Hi,

I'm trying to get my file history to read/write to a wx config file. I currently using the external python module ConfigObj for my configuration files, but it seems wx has a way for the file history to work with wx.config automatically, so that seems the easiest route to take.

        self.filehistory = wx.FileHistory(5)
        self.config = wx.Config("Whyteboard")
        self.config.SetPath(os.path.join(get_home_directory, "directories.list"))
        self.filehistory.Load(self.config)

At this point, no config file exists, but I thought wx would auto-create it or something, can't find too many examples of config
And in my file open handler:

    def handle_files(self, path):
        self.directory = os.path.dirname(path)
        self.filehistory.AddFileToHistory(path)
        self.filehistory.Save(self.config)

        if path.endswith(".wtbd"):
            self.util.load_wtbd(path)
        else:
            self.util.temp_file = path
            self.util.load_file()

And my "utility" function:

def get_home_dir(extra_path=None):
    std_paths = wx.StandardPaths.Get()
    path = wx.StandardPaths.GetUserLocalDataDir(std_paths)
    if extra_path:
        path = os.path.join(path, extra_path, "") # "" forces slash at end

    if not os.path.isdir(path):
        os.makedirs(path)
    return path

I was hoping that the x many "last remembered" files in self.filehistory's constructor would be auto-written into the config file every time I loaded a file, but it's not the case. I'm not sure if I have to explicitly write the changes, or even explicitly create the config file, as it doesn't get created.
regards,

···

--
Steven Sproat, BSc
http://www.basicrpg.com/

Hi all,

Hi,

I’m trying to get my file history to read/write to a wx config file. I currently using the external python module ConfigObj for my configuration files, but it seems wx has a way for the file history to work with wx.config automatically, so that seems the easiest route to take.

   self.filehistory = wx.FileHistory(5)

   self.config = wx.Config("Whyteboard")

   self.config.SetPath(os.path.join(get_home_directory, "directories.list"))

   self.filehistory.Load(self.config)

At this point, no config file exists, but I thought wx would auto-create it or something, can’t find too many examples of config

And in my file open handler:

def handle_files(self, path):

   self.directory = os.path.dirname(path)

   self.filehistory.AddFileToHistory(path)

   self.filehistory.Save(self.config)



   if path.endswith(".wtbd"):

       self.util.load_wtbd(path)

   else:

       self.util.temp_file = path

       self.util.load_file()

And my “utility” function:

def get_home_dir(extra_path=None):

std_paths = wx.StandardPaths.Get()

path = wx.StandardPaths.GetUserLocalDataDir(std_paths)

if extra_path:

   path = os.path.join(path, extra_path, "")   # "" forces slash at end

if not os.path.isdir(path):

   os.makedirs(path)

return path

I was hoping that the x many “last remembered” files in self.filehistory’s constructor would be auto-written into the config file every time I loaded a file, but it’s not the case. I’m not sure if I have to explicitly write the changes, or even explicitly create the config file, as it doesn’t get created.

regards,

I’ve now fixed the issue, with much less code. I wasn’t adding the existing files to the menu.

def init(self):
self.filehistory = wx.FileHistory(8)

    self.config = wx.Config("Whyteboard",style=wx.CONFIG_USE_LOCAL_FILE)
    self.filehistory.Load(self.config)

    recent = wx.Menu()
    self.filehistory.UseMenu(recent)
    self.filehistory.AddFilesToMenu()

def on_open(self, path):
self.filehistory.AddFileToHistory(path)
self.filehistory.Save(self.config)

Here’s hoping it comes in handy to someone. Cheers!

···

2009/12/28 Steven Sproat sproaty@gmail.com

SetPath does not set the path or filename of the file used to store the config data. It sets the name of the active group within the config data. (Hierarchical groups are allowed, that's why it allows the use of path syntax.)

Unless you explicitly use wx.FileConfig then on Windows it will actually put the stuff in the registry. Look under HKCU/Software/Whyteboard

···

On 12/28/09 9:19 AM, Steven Sproat wrote:

Hi,

I'm trying to get my file history to read/write to a wx config file. I
currently using the external python module ConfigObj for my
configuration files, but it seems wx has a way for the file history to
work with wx.config automatically, so that seems the easiest route to take.

         self.filehistory = wx.FileHistory(5)
         self.config = wx.Config("Whyteboard")
         self.config.SetPath(os.path.join(get_home_directory,
"directories.list"))
         self.filehistory.Load(self.config)

At this point, no config file exists, but I thought wx would auto-create
it or something, can't find too many examples of config

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

···

On 12/28/09 9:19 AM, Steven Sproat wrote:
  

Hi,

I'm trying to get my file history to read/write to a wx config file. I
currently using the external python module ConfigObj for my
configuration files, but it seems wx has a way for the file history to
work with wx.config automatically, so that seems the easiest route to take.

         self.filehistory = wx.FileHistory(5)
         self.config = wx.Config("Whyteboard")
         self.config.SetPath(os.path.join(get_home_directory,
"directories.list"))
         self.filehistory.Load(self.config)

At this point, no config file exists, but I thought wx would auto-create
it or something, can't find too many examples of config
    
SetPath does not set the path or filename of the file used to store the
config data. It sets the name of the active group within the config
data. (Hierarchical groups are allowed, that's why it allows the use of
path syntax.)

Unless you explicitly use wx.FileConfig then on Windows it will actually
put the stuff in the registry. Look under HKCU/Software/Whyteboard

ah right. However, this doesn't work under gtk (python 2.6.2, wx
2.8.10.1 - is there anytyhing linux-specific that I'm not doing? all is
well on winxp sp3

Try specifying the vendor name in addition to the app name. If that still has problems then you can use wx.FileConfig and also specify the filename to use.

···

On 12/28/09 6:15 PM, Steven Sproat wrote:

Robin Dunn wrote:

On 12/28/09 9:19 AM, Steven Sproat wrote:

Hi,

I'm trying to get my file history to read/write to a wx config file. I
currently using the external python module ConfigObj for my
configuration files, but it seems wx has a way for the file history to
work with wx.config automatically, so that seems the easiest route to take.

          self.filehistory = wx.FileHistory(5)
          self.config = wx.Config("Whyteboard")
          self.config.SetPath(os.path.join(get_home_directory,
"directories.list"))
          self.filehistory.Load(self.config)

At this point, no config file exists, but I thought wx would auto-create
it or something, can't find too many examples of config

SetPath does not set the path or filename of the file used to store the
config data. It sets the name of the active group within the config
data. (Hierarchical groups are allowed, that's why it allows the use of
path syntax.)

Unless you explicitly use wx.FileConfig then on Windows it will actually
put the stuff in the registry. Look under HKCU/Software/Whyteboard

ah right. However, this doesn't work under gtk (python 2.6.2, wx
2.8.10.1 - is there anytyhing linux-specific that I'm not doing? all is
well on winxp sp3

--
Robin Dunn
Software Craftsman

Here is my code using wx.FileConfig

self.filehistory = wx.FileHistory(9)
        self.fileConfig = wx.FileConfig(appName="ApplicationName",
                                    vendorName="VendorName",
                                    localFilename="file.cfg",
                                    style=wx.CONFIG_USE_LOCAL_FILE)
        self.filehistory.Load(self.fileConfig)
        self.filehistory.UseMenu(file_menu)
        self.filehistory.AddFilesToMenu()

Where is the location of the file "file.cfg"?

Two files are added to .cfg. Once application starts, It shows
complete file path in menu. Either open another file or click file
menu item, all the file menu items suddenly changes to short file name
(name.ext). Is there something wrong here?

Thanks

Prashant
Python 2.6.2
wxPython 2.8.10.1
XP 32

Here is my code using wx.FileConfig

self.filehistory = wx.FileHistory(9)
         self.fileConfig = wx.FileConfig(appName="ApplicationName",
                                     vendorName="VendorName",
                                     localFilename="file.cfg",
                                     style=wx.CONFIG_USE_LOCAL_FILE)
         self.filehistory.Load(self.fileConfig)
         self.filehistory.UseMenu(file_menu)
         self.filehistory.AddFilesToMenu()

Where is the location of the file "file.cfg"?

On Windows If you have HOME set in the environment then it will go there. Otherwise it is under your "c:\Documents and Settings\userName" folder, but I don't remember exactly where. Try searching for it with Explorer.

Two files are added to .cfg. Once application starts, It shows
complete file path in menu. Either open another file or click file
menu item, all the file menu items suddenly changes to short file name
(name.ext). Is there something wrong here?

No. The paths are shown relative to the current working directory, so if that changes to the same location as the files then they are shown with no path.

···

On 1/5/10 2:22 AM, King wrote:

--
Robin Dunn
Software Craftsman