annotate clients/rio_de_hola/settings.py @ 130:b49714fff478

* Workaround for Segfault_in_cxa_allocate_exception: http://wiki.fifengine.de/Segfault_in_cxa_allocate_exception * Full credit goes to Yonibear from OpenAnno who tracked down the issue
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 18 Aug 2008 23:11:32 +0000
parents 6b2f3a151f81
children 815354ba295e
rev   line source
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
1 import shutil
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
2 import pychan
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
3 try:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
4 import xml.etree.cElementTree as ET
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
5 except:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
6 import xml.etree.ElementTree as ET
107
860d81602a2a - prepared basicapplication to use WindowTitle / WindowIcon from clients settings.py
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 6
diff changeset
7
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
8 class Setting(object):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
9 def onOptionsPress(self):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
10 self.changesRequireRestart = False
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
11 self.isSetToDefault = False
122
6b2f3a151f81 * Small fixes (window icon, additional resolutions, svn:ignore)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
12 self.Resolutions = ['640x480', '800x600', '1024x768', '1280x800', '1440x900']
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
13 if not hasattr(self, 'OptionsDlg'):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
14 self.OptionsDlg = None
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
15 if not self.OptionsDlg:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
16 self.OptionsDlg = pychan.loadXML('gui/settings.xml')
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
17 self.OptionsDlg.distributeInitialData({
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
18 'screen_resolution' : self.Resolutions,
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
19 'render_backend' : ['OpenGL', 'SDL']
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
20 })
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
21 self.OptionsDlg.distributeData({
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
22 'screen_resolution' : self.Resolutions.index(str(self.readSetting("ScreenWidth")) + 'x' + str(self.readSetting("ScreenHeight"))),
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
23 'render_backend' : 0 if str(self.readSetting("RenderBackend")) == "OpenGL" else 1,
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
24 'enable_fullscreen' : int(self.readSetting("FullScreen")),
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
25 'enable_sound' : int(self.readSetting("PlaySounds"))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
26 })
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
27 self.OptionsDlg.mapEvents({
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
28 'okButton' : self.saveSettings,
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
29 'cancelButton' : self.OptionsDlg.hide,
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
30 'defaultButton' : self.setDefaults
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
31 })
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
32 self.OptionsDlg.show()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
34 def setDefaults(self):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
35 shutil.copyfile('settings-dist.xml', 'settings.xml')
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
36 self.isSetToDefault = True
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
37 self.changesRequireRestart = True
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
39 def readSetting(self, name, type='int', strip=True, text=False):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
40 if not hasattr(self, 'tree'):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
41 self.tree = ET.parse('settings.xml')
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
42 self.root_element = self.tree.getroot()
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
43 element = self.root_element.find(name)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
44 if element is not None:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
45 element_value = element.text
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
46 if element_value is None:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
47 if type == 'int':
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
48 return 0
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
49 elif type == 'list':
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
50 list = []
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
51 return list
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
52 else:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
53 if type == 'int':
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
54 return element_value.strip() if strip else element_value
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
55 elif type == 'list':
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
56 list = []
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
57 list_s = []
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
58 list = str(element_value.strip()).split(";")
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
59 for item in list:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
60 item = item.strip()
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
61 if text:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
62 item = item.replace('\\n', '\n')
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
63 list_s.append(item)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
64 return list_s
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
65 elif type == 'bool':
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
66 return False if element_value.strip() == 'False' else True
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
67 else:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
68 print 'Setting,', name, 'does not exist!'
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
70 def setSetting(self, name, value):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
71 element = self.root_element.find(name)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
72 if element is not None:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
73 if value is not element.text:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
74 element.text = str(value)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
75 else:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
76 print 'Setting,', name, 'does not exist!'
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
78 def saveSettings(self):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
79 screen_resolution, render_backend, enable_fullscreen, enable_sound = self.OptionsDlg.collectData('screen_resolution', 'render_backend', 'enable_fullscreen', 'enable_sound')
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
80 render_backend = 'OpenGL' if render_backend is 0 else 'SDL'
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
81 if render_backend != str(self.readSetting("RenderBackend")):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
82 self.setSetting('RenderBackend', render_backend)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
83 self.changesRequireRestart = True
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
84 if int(enable_fullscreen) != int(self.readSetting("FullScreen")):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
85 self.setSetting('FullScreen', int(enable_fullscreen))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
86 self.changesRequireRestart = True
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
87 if int(enable_sound) != int(self.readSetting("PlaySounds")):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
88 self.setSetting('PlaySounds', int(enable_sound))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
89 self.changesRequireRestart = True
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
90 if screen_resolution != self.Resolutions.index(str(self.readSetting("ScreenWidth")) + 'x' + str(self.readSetting("ScreenHeight"))):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
91 self.setSetting('ScreenWidth', int(self.Resolutions[screen_resolution].partition('x')[0]))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
92 self.setSetting('ScreenHeight', int(self.Resolutions[screen_resolution].partition('x')[2]))
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
93 self.changesRequireRestart = True
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
95 if not self.isSetToDefault:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
96 self.tree.write('settings.xml')
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
97 self.OptionsDlg.hide()
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
98 if self.changesRequireRestart:
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
99 RestartDlg = pychan.loadXML('gui/changes_require_restart.xml')
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
100 RestartDlg.mapEvents({ 'closeButton' : RestartDlg.hide })
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 120
diff changeset
101 RestartDlg.show()