Legorooj
Legorooj

Reputation: 2757

How to pickle or save a WxPython FontData Object

I've been coding a text editor, and it has the function to change the default font displayed in the wx.stc.SyledTextCtrl.

I would like to be able to save the font as a user preference, and I have so far been unable to save it.

The exact object type is <class 'wx._core.Font'>.

Would anyone know how to pickle/save this?

Upvotes: 0

Views: 135

Answers (1)

Rolf of Saxony
Rolf of Saxony

Reputation: 22443

Probably due to its nature, you cannot pickle a wx.Font.
Your remaining option is to store its constituent parts.
Personally, I store facename, point size, weight, slant, underline, text colour and background colour.
How you store them is your own decision.
I use 2 different options depending on the code.

  • Store the entries in an sqlite3 database, which allows for multiple indexed entries.
  • Store the entries in an .ini file using configobj

Both sqlite3 and configobj are available in the standard python libraries.

Upvotes: 1

Related Questions