The right way to persist GUI state + app state

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

The right way to persist GUI state + app state

Mark Summerfield-2
I want to persist some state: the window geometry of my main window (a wx.Frame) and some app data (a couple of strings, some ints). Right now I do: config = wx.Config.Get() and use the Read & Write methods. But it is a bit tedious saving 4 ints just for the window geometry.

Also I've noticed that on Linux it saves to ~/.appname rather than ~/.config/appname which I would have expected.

Now I've discovered the wx.lib.agw.persist* classes. Yet the Usage example in https://docs.wxpython.org/wx.lib.agw.persist.html#module-wx.lib.agw.persist creates a local config file that seems to have nothing to do with wx.ConfigBase. Using a file like this is fine on Linux, but seems unsuitable for Windows. So are the persist classes really for Unices?

So, is there a bridge between agw.persist and ConfigBase? Or is one preferred over the other?

Thanks.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: The right way to persist GUI state + app state

James Scholes
I don't have any opinion either way on the built-in support for
persisting state that ships with wx, but it's worth remembering that
you're absolutely not required to only use the utilities and
functionality included with wxPython.  You can very easily persist app
and GUI state using any other mechanism supported by Python, for example
a simple JSON/YAML/TOML/INI file, leaving you to decide where the file
goes, what name it has, its default values, etc.

Regards,

James Scholes
https://twitter.com/JamesScholes

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: The right way to persist GUI state + app state

Mark Summerfield-2
I understand that, but had wondered if there was an 'official' preference. Anyway, I'm using wx.Config.Get() since that seems to work on both Linux and WIndows.

On Thursday, October 19, 2017 at 8:44:50 PM UTC+1, James Scholes wrote:
I don't have any opinion either way on the built-in support for
persisting state that ships with wx, but it's worth remembering that
you're absolutely not required to only use the utilities and
functionality included with wxPython.  You can very easily persist app
and GUI state using any other mechanism supported by Python, for example
a simple JSON/YAML/TOML/INI file, leaving you to decide where the file
goes, what name it has, its default values, etc.

Regards,

James Scholes
<a href="https://twitter.com/JamesScholes" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftwitter.com%2FJamesScholes\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPMF-3XJ257ViDJaExNM-eIkvhwA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftwitter.com%2FJamesScholes\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPMF-3XJ257ViDJaExNM-eIkvhwA&#39;;return true;">https://twitter.com/JamesScholes

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: The right way to persist GUI state + app state

James Scholes
'Mark Summerfield' via wxPython-users wrote:
> I understand that, but had wondered if there was an 'official'
> preference.

It's very rare in these sorts of cases to find wrong and right answers.
The best tool for the job is the one which makes your application work
for your users.  Additionally, there's something to be said for keeping
config functionality separated from your GUI code, in case one day you
decide to move away from wxPython towards Qt, a command line app, or
even a web UI.

Regards,

James Scholes
https://twitter.com/JamesScholes

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.