-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprefs.py
93 lines (71 loc) · 3.25 KB
/
prefs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import wx
import wx.lib.newevent
import platform
from pathlib import Path
PrefsChangedEvent, EVT_PREFS_CHANGED = wx.lib.newevent.NewEvent()
# set us up XDG please
if platform.system() == "Linux":
wx.StandardPaths.Get().SetFileLayout(wx.StandardPaths.Get().FileLayout.FileLayout_XDG)
def get_prefs_dir():
return Path(wx.StandardPaths.Get().GetUserConfigDir()) / 'wxpymoo'
def Initialize():
_defaults = {
'font' : wx.Font( 12, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL ).GetNativeFontInfoDesc(),
'save_window_size' : True,
'window_width' : 800,
'window_height' : 600,
'input_height' : 25,
'use_ansi' : True,
'use_ansi_blink' : True,
'highlight_urls' : True,
'save_mcp_window_size' : True,
'autoconnect_last_world' : True,
'local_echo' : False,
'scroll_on_output' : True,
'editor_path' : '',
'mcp_window_width' : 600,
'mcp_window_height' : 400,
'use_x_copy_paste' : platform.system() == 'Linux',
'theme' : 'ANSI',
}
if platform.system() == "Windows":
_defaults['editor_picker'] = "notepad"
elif platform.system() == "Linux":
_defaults['editor_picker'] = "Default Editor"
#elif platform.system() == "Darwin":
# TODO what goes here?
prefs_dir = get_prefs_dir()
if not prefs_dir.exists():
prefs_dir.mkdir(parents = True)
config_file = prefs_dir / 'config'
wx.ConfigBase.Set(wx.FileConfig(localFilename = str(config_file)))
for key, def_val in _defaults.items():
# if nothing exists for that key, set it to the default.
if get(key) == None:
set(key, str(def_val))
def get(key): return wx.ConfigBase.Get().Read(key)
def set(param, val):
config = wx.ConfigBase.Get()
if param in ['save_window_size', 'use_ansi', 'use_ansi_blink', 'highlight_urls', 'save_mcp_window_size', 'autoconnect_last_world', 'local_echo', 'scroll_on_output', 'use_x_copy_paste',]:
config.WriteBool(param, val)
elif param in ['theme', 'editor_picker', 'editor_path']:
config.Write(param, val)
else:
config.WriteInt(param, val)
config.Flush()
def update(pw):
config = wx.ConfigBase.Get()
# pw == prefs_window
config.WriteBool('save_window_size', pw.save_size_checkbox.GetValue() )
config.WriteBool('autoconnect_last_world', pw.autoconnect_checkbox.GetValue() )
config.WriteBool('use_x_copy_paste', pw.xmouse_checkbox.GetValue() )
config.WriteBool('local_echo', pw.local_echo_checkbox.GetValue() )
config.WriteBool('scroll_on_output', pw.scroll_on_output_checkbox.GetValue() )
config.Write('font', pw.font_ctrl.GetSelectedFont().GetNativeFontInfoDesc())
config.WriteBool('use_ansi', pw.ansi_checkbox.GetValue() )
config.WriteBool('use_ansi_blink', pw.ansi_blink_checkbox.GetValue() )
config.Write('theme', pw.theme_picker.GetStringSelection() )
config.Write('editor_picker', pw.editor_picker.GetString(pw.editor_picker.GetSelection()))
config.Write('editor_path' , pw.editor_path.GetValue() )
config.Flush()
wx.PostEvent(pw.parent, PrefsChangedEvent())