Using "preferences"

Actually, this one works, too... Too many choices =)

Thanks again, guys... I'm halfway done

···

-----Original Message-----
From: Joe Brown [mailto:joebrown@rclooke.com]
Sent: Thursday, June 30, 2005 1:58 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Using "preferences"

Maybe I misunderstand your goals, but this sounds like a job
for wx.Config()

class MyApp( wx.App ):
    def OnInit(self):
        self.SetVendor('me')
        self.SetApplication('myprogram')
        config = wx.Config()
        title_setting = config.Read('Title', "Some title")
        frame = MyFirstFrame(None,title_setting)
        frame.Show(True)
        self.SetTopWindow(frame)

# viola, it is really that simple.
# you can do confg = wx.Config() anywhere in your app. Given
that the app
# has vendor and application properties set the same, it will
access the
same
# config file/registry.

Levis, Chris wrote:

>Suppose my entry point is:
>
>class MyApp( wx.App ):
> def OnInit(self):
> #read in config?
> #set wx.App.myConfigData?
> frame = MyFirstFrame(None,"Some title")
> frame.Show(True)
> self.SetTopWindow(frame)
>
>
>So this is where to read in the initial prefs into (e.g.) a
dict, then have the Preferences panel modify that dict and
have the various logic throughout the app use it as well...
>
>If I'm mistaken, please stop me before I hurt myself =)
Otherwise, thanks for this very helpful pointer.
>
>
>
>
>
>
>>-----Original Message-----
>>From: Henning.Ramm@mediapro-gmbh.de
>>[mailto:Henning.Ramm@mediapro-gmbh.de]
>>Sent: Thursday, June 30, 2005 1:38 PM
>>To: wxPython-users@lists.wxwidgets.org
>>Subject: RE: [wxPython-users] Using "preferences"
>>
>>
>>
>>>Hmm... Actually, that could work out, if I understand it
>>>correctly. I've never had occasion to use wx.App before
>>>
>>>So every class that is part of an application shares a wx.App
>>>object? And as such, I can have references to
>>>wx.GetApp().objPrefs that all point to the same Prefs object,
>>>regardless of which class is referring to it?
>>>
>>>I'm gonna try it out while I wait with bated breath for a response.
>>>
>>>
>>Inherit your main class from wx.App and create the main frame
>>of your app in this class' __init__.
>>Call your config reader also in this __init__. Perhaps make
>>your own config class (perhaps derived from dict) that can
>>read & write a (XML) file.
>>
>>I'd send you my code, but it does a lot of stuff that will
>>only confuse you (it's a two-step inherited twisted+wx app
>>class that keeps a proxy database connection, keeps track of
>>running processes etc.), and it would be a lot of work to
>>sort that out.
>>
>>Best regards,
>>Henning Hraban Ramm
>>Südkurier Medienhaus / MediaPro
>>Support/Admin/Development Dept.
>>
>>------------------------------------------------------------
---------
>>To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
>>For additional commands, e-mail:
>>wxPython-users-help@lists.wxwidgets.org
>>
>>
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
>For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

Levis, Chris wrote:

Actually, this one works, too... Too many choices =)

Just to add one more:

This is python, you can store your preferences object in a module, and then anywhere you do:

import PrefModule

You'll have access to it. Any mutable object (dict, class, etc) in that module can be read and altered by any other module that imports it.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                          
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov