wx.Config and registry

Hi, ALL,

OS: Windows XP

Python: 2.7

wx: 2.9.4.

I’m trying to create a following tree in registry:

myApp

key1 name value

name value

key2 name value

name value

Here is what I have

class MyFrame(wx.Frame,KVObject):

def init(…):

self.config = wx.Config( “MyApp” )

some other initialization stuff

def myFunc():

path = self.config.GetPath()

self.config.SetPath( “/myApp/” + key1 ) #key1 does not exist here

self.config.Write( “name”, value )

AFAIU, this should create a myApp key in the registry, create the key1 key in it and write some “name”=>“value” to it.

However upon executing and loading the registry, nothing is created there and nothing is written.

Am I doing something wrong? Or maybe there is a better way to achive it?

This thread: http://stackoverflow.com/questions/12447353/having-a-hard-time-with-wx-config suggests to use ConfigParser, but

is it an external default python module?

I’d rather avoid it if I can…

Thank you.

Hi,

···

On Saturday, August 24, 2013 2:00:46 AM UTC-5, Igor Korot wrote:

Hi, ALL,

OS: Windows XP

Python: 2.7

wx: 2.9.4.

I’m trying to create a following tree in registry:

myApp

key1 name value

  name            value

key2 name value

  name            value

Here is what I have

class MyFrame(wx.Frame,KVObject):

def init(…):

self.config = wx.Config( “MyApp” )

some other initialization stuff

def myFunc():

path = self.config.GetPath()

self.config.SetPath( “/myApp/” + key1 ) #key1 does not exist here

self.config.Write( “name”, value )

AFAIU, this should create a myApp key in the registry, create the key1 key in it and write some “name”=>“value” to it.

However upon executing and loading the registry, nothing is created there and nothing is written.

Am I doing something wrong? Or maybe there is a better way to achive it?

This thread: http://stackoverflow.com/questions/12447353/having-a-hard-time-with-wx-config suggests to use ConfigParser, but

is it an external default python module?

I’d rather avoid it if I can…

Thank you.

If you need to modify the Windows Registry, I highly recommend just using Python’s _winreg library: 35.3. _winreg — Windows registry access — Python 2.7.18 documentation

I also wrote a tutorial about this module a while back: Python's _winreg: Editing the Windows Registry - Mouse Vs Python

Hope that helps.

Mike

Igor Korot wrote:

Hi, ALL,
OS: Windows XP
Python: 2.7
wx: 2.9.4.

I'm trying to create a following tree in registry:

myApp
key1 name value
                                    name value

key2 name value
                                    name value

Here is what I have

class MyFrame(wx.Frame,KVObject):
         def __init__(...):
               self.config = wx.Config( "MyApp" )

         def myFunc():
               path = self.config.GetPath()
               self.config.SetPath( "/myApp/" + key1 ) #key1 does not
exist here
               self.config.Write( "name", value )

AFAIU, this should create a myApp key in the registry, create the key1
key in it and write some "name"=>"value" to it.

However upon executing and loading the registry, nothing is created
there and nothing is written.

Where are you looking? This should create
    HKEY_CURRENT_USER\Software\MyApp\myApp\key1

If you were running this as a 32-bit app on a 64-bit system, you might
be getting fooled by registry redirection, but on XP that's not a concern.

BTW, just so you're aware, the "root" of your tree will be "MyApp".
When you create "/myApp/" in SetPath, that creates another subkey called
"myApp" within your "MyApp" key.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Hi, Tim,

Igor Korot wrote:

Hi, ALL,
OS: Windows XP
Python: 2.7
wx: 2.9.4.

I’m trying to create a following tree in registry:

myApp
key1 name value

                                name            value

key2 name value
name value

Here is what I have

class MyFrame(wx.Frame,KVObject):
def init(…):
self.config = wx.Config( “MyApp” )

     def myFunc():
           path = self.config.GetPath()
           self.config.SetPath( "/myApp/" + key1 ) #key1 does not

exist here
self.config.Write( “name”, value )

AFAIU, this should create a myApp key in the registry, create the key1
key in it and write some “name”=>“value” to it.

However upon executing and loading the registry, nothing is created

there and nothing is written.

Where are you looking? This should create
HKEY_CURRENT_USER\Software\MyApp\myApp\key1

If you were running this as a 32-bit app on a 64-bit system, you might

be getting fooled by registry redirection, but on XP that’s not a concern.

BTW, just so you’re aware, the “root” of your tree will be “MyApp”.
When you create “/myApp/” in SetPath, that creates another subkey called

“myApp” within your “MyApp” key.

Just as a proof that something strange is going on, I opened the python console and did this:

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import wx
conf = wx.Config( “python-test” )
<wx._misc.Config; proxy of <Swig Object of type ‘wxConfig *’ at 0x1012e68> >
conf.SetPath( “key1” )

conf.WriteInt( “name”, 1 )
True
exit()

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import wx
conf = wx.Config( “python-test” )
num = conf.GetNumberOfEntries()
print num
0

Is this function implemented in wxPython?

Basically what I’m looking for is the custom “recent used” menu.

Also, the documentation talks about enumerating keys, but the actual enumerating functions are not documented.

I understand that people are encouraged to look at main wxWidgets documentation, but it would be helpful to

have at least mentioning of those functions.

Thank you.

···

On Mon, Aug 26, 2013 at 10:50 AM, Tim Roberts timr@probo.com wrote:


Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.


You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Hi Igor,

...

Also, the documentation talks about enumerating keys, but the actual enumerating functions are not documented.
I understand that people are encouraged to look at main wxWidgets documentation, but it would be helpful to
have at least mentioning of those functions.

You might want to look at the Phoenix doc, even if you don't use Phoenix I find it very handy.

wxpython.org/Phoenix/docs/html/ConfigBase.html

Werner

···

On 26/08/2013 20:30, Igor Korot wrote:

Hi Igor,

···

On 26/08/2013 20:30, Igor Korot wrote:

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> conf = wx.Config( "python-test" )
<wx._misc.Config; proxy of <Swig Object of type 'wxConfig *' at 0x1012e68> >
>>> conf.SetPath( "key1" )
>>> conf.WriteInt( "name", 1 )
True
>>> exit()

Can you try to do a conf.Flush()

Werner

Werner,

Hi Igor,

Also, the documentation talks about enumerating keys, but the actual enumerating functions are not documented.

I understand that people are encouraged to look at main wxWidgets documentation, but it would be helpful to
have at least mentioning of those functions.

You might want to look at the Phoenix doc, even if you don’t use Phoenix I find it very handy.

wxpython.org/Phoenix/docs/html/ConfigBase.html

This is where I am looking. :wink:

···

On Mon, Aug 26, 2013 at 11:37 AM, werner wbruhin@free.fr wrote:

On 26/08/2013 20:30, Igor Korot wrote:

Werner


You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Werner,

Hi Igor,

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.

import wx
conf = wx.Config( “python-test” )
<wx._misc.Config; proxy of <Swig Object of type ‘wxConfig *’ at 0x1012e68> >

conf.SetPath( “key1” )
conf.WriteInt( “name”, 1 )
True
exit()

Can you try to do a conf.Flush()

I just tried to continue the second session with this:

conf.SetPath( “key1” )
num = conf.GetNumberOfEntries()
print num
1

I will try to call Flush() now.

Will post the results in a second.

Thank you.

···

On Mon, Aug 26, 2013 at 11:38 AM, werner wbruhin@free.fr wrote:

On 26/08/2013 20:30, Igor Korot wrote:

Werner


You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Werner,

Werner,

Hi Igor,

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.

import wx
conf = wx.Config( “python-test” )
<wx._misc.Config; proxy of <Swig Object of type ‘wxConfig *’ at 0x1012e68> >

conf.SetPath( “key1” )
conf.WriteInt( “name”, 1 )
True
exit()

Can you try to do a conf.Flush()

I just tried to continue the second session with this:

conf.SetPath( “key1” )

num = conf.GetNumberOfEntries()
print num

1

I will try to call Flush() now.

Will post the results in a second.

Absolutely no differences. I removed the whole “python-test” tree and did:

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import wx
conf = wx.Config( “python-test” )
conf.SetPath( “key1” )
conf.WriteInt( “value1”, 1 )
True
conf.Flush()

True

exit()

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import wx
conf = wx.Config( “python-test” )
num = conf.GetNumberOfEntries()
print num
0

Thank you.

···

On Mon, Aug 26, 2013 at 11:47 AM, Igor Korot ikorot01@gmail.com wrote:

On Mon, Aug 26, 2013 at 11:38 AM, werner wbruhin@free.fr wrote:

On 26/08/2013 20:30, Igor Korot wrote:

Thank you.

Werner


You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Igor Korot wrote:

Absolutely no differences. I removed the whole "python-test" tree and did:

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> conf = wx.Config( "python-test" )
>>> conf.SetPath( "key1" )
>>> conf.WriteInt( "value1", 1 )
True
>>> conf.Flush()
True
>>> exit()

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> conf = wx.Config( "python-test" )
>>> num = conf.GetNumberOfEntries()
>>> print num
0
>>>

Right, because there are no items in "python-test". They're all in
"key1". GetNumberOfEntries does not count subkeys. If you do
    conf.SetPath('key1')
    conf.GetNumberOfEntries()
that will do what you expect.

If you need more sophisticated enumeration, you should use the Python
built-in registry stuff, not the wx wrapper.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Tim,

Igor Korot wrote:

Absolutely no differences. I removed the whole “python-test” tree and did:

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit

(Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import wx
conf = wx.Config( “python-test” )

conf.SetPath( “key1” )
conf.WriteInt( “value1”, 1 )
True
conf.Flush()
True
exit()

C:\Documents and Settings\Igor.FORDANWORK>python

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import wx

conf = wx.Config( “python-test” )
num = conf.GetNumberOfEntries()
print num
0

Right, because there are no items in “python-test”. They’re all in

“key1”. GetNumberOfEntries does not count subkeys. If you do
conf.SetPath(‘key1’)
conf.GetNumberOfEntries()
that will do what you expect.

If you need more sophisticated enumeration, you should use the Python

built-in registry stuff, not the wx wrapper.

So I need “GetNumberOfGroups()” instead.

Thank you and sorry for the noise.

···

On Mon, Aug 26, 2013 at 11:58 AM, Tim Roberts timr@probo.com wrote:


Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.


You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Igor Korot wrote:

Just as a proof that something strange is going on, I opened the python
console and did this:

C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> conf = wx.Config( "python-test" )
<wx._misc.Config; proxy of <Swig Object of type 'wxConfig *' at 0x1012e68> >
>>> conf.SetPath( "key1" )
>>> conf.WriteInt( "name", 1 )
True
>>> exit()
C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> conf = wx.Config( "python-test" )
>>> num = conf.GetNumberOfEntries()
>>> print num
0
>>>

There are no entries at the root level, just the "key1" group. Once you set the path to that group then you can get the entries within the group.

Also, you should be creating a wx.App object before using wx.Config. Some platforms will explicitly require it, others may not be so strict but it would still be smart to never use a wx.Config without a wx.App.

Is this function implemented in wxPython?
Basically what I'm looking for is the custom "recent used" menu.

The wx.FileHistory class will automatically take care of that for you. See the demo for an example.

Also, the documentation talks about enumerating keys, but the actual
enumerating functions are not documented.

They are documented in the Phoenix source. I'm not sure why that's not being picked up by the sphinx generator...

http://trac.wxwidgets.org/browser/wxPython/Phoenix/trunk/etg/config.py#L102

···

--
Robin Dunn
Software Craftsman

Hi, Robin,

Igor Korot wrote:

Just as a proof that something strange is going on, I opened the python
console and did this:

C:\Documents and Settings\Igor.FORDANWORK>python

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import wx

conf = wx.Config( “python-test” )
<wx._misc.Config; proxy of <Swig Object of type ‘wxConfig *’ at 0x1012e68> >
conf.SetPath( “key1” )
conf.WriteInt( “name”, 1 )

True

exit()
C:\Documents and Settings\Igor.FORDANWORK>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import wx
conf = wx.Config( “python-test” )
num = conf.GetNumberOfEntries()
print num
0

There are no entries at the root level, just the “key1” group. Once you set the path to that group then you can get the entries within the group.

Yes, GetNumberOfGroups() is what I need.

Also, you should be creating a wx.App object before using wx.Config. Some platforms will explicitly require it, others may not be so strict but it would still be smart to never use a wx.Config without a wx.App.

This is just to test that something was not right…

Is this function implemented in wxPython?
Basically what I’m looking for is the custom “recent used” menu.

The wx.FileHistory class will automatically take care of that for you. See the demo for an example.

What I’m looking for is a menu with different database to open as a “recent files”. Currently I’m working with SQLite and mySQL.

They have different options to open and the names will be different. That’s why I wrote “custom”. :wink:

Also, the documentation talks about enumerating keys, but the actual
enumerating functions are not documented.

They are documented in the Phoenix source. I’m not sure why that’s not being picked up by the sphinx generator…

http://trac.wxwidgets.org/browser/wxPython/Phoenix/trunk/etg/config.py#L102

So I’m not the only one who does not see them on the site?

Good, means I’m not crazy… :wink:

Thank you.

···

On Mon, Aug 26, 2013 at 12:26 PM, Robin Dunn robin@alldunn.com wrote:


Robin Dunn
Software Craftsman
http://wxPython.org


You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.