Mercurial > fife-parpg
annotate engine/python/fife/extensions/fife_settings.py @ 499:3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
All demos and tools now use the new settings extension.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 14 May 2010 17:37:42 +0000 |
parents | 559a26347730 |
children | ee65aa323457 |
rev | line source |
---|---|
497
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # #################################################################### |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # Copyright (C) 2005-2010 by the FIFE team |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # http://www.fifengine.net |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # This file is part of FIFE. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # Lesser General Public License for more details. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # License along with this library; if not, write to the |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # Free Software Foundation, Inc., |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # #################################################################### |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 Settings |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 ================================== |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 This module provides a nice framework for loading and saving game settings. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 It is by no means complete but it does provide a good starting point. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 @note: Please note that you MUST provide a default settings-dist.xml file |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 in the root directory of your project for this module to function correctly. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 import shutil |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 import os |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 from StringIO import StringIO |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 from fife.extensions import pychan |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 from fife.extensions.fife_utils import getUserDataDirectory |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 try: |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 import xml.etree.cElementTree as ET |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 except: |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 import xml.etree.ElementTree as ET |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 SETTINGS_GUI_XML="""\ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 <Window name="Settings" title="Settings"> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 <Label text="Settings menu!" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 <HBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 <VBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 <Label text="Resolution:" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 <Label text="Renderer:" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 </VBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 <VBox min_size="120,60"> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 <DropDown name="screen_resolution" min_size="120,0" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 <DropDown name="render_backend" min_size="120,0" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 </VBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 </HBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 <CheckBox name="enable_fullscreen" text="Use the full screen mode" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 <CheckBox name="enable_sound" text="Enable sound" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 <HBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 <Spacer /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 <Button name="cancelButton" text="Cancel" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 <Button name="okButton" text="Ok" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 <Button name="defaultButton" text="Defaults" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 </HBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 </Window> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 CHANGES_REQUIRE_RESTART="""\ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 <Window title="Changes require restart"> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 <Label text="Some of your changes require you to restart." /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 <HBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 <Spacer /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 <Button name="closeButton" text="Ok" /> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 </HBox> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 </Window> |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 class Setting(object): |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 This class manages loading and saving of game settings. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 Usage:: |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 from fife.extensions.fife_settings import Setting |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 settings = Setting(app_name="myapp") |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 screen_width = settings.readSetting("ScreenWidth") |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 """ |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
90 |
497
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 def __init__(self, app_name="", settings_file="", settings_gui_xml=""): |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 Initializes the Setting object. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 @param app_name: The applications name. If this parameter is provided |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 alone it will try to read the settings file from the users home directory. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 In windows this will be something like: C:\Documents and Settings\user\Application Data\fife |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 @type app_name: C{string} |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 @param settings_file: The name of the settings file. If this parameter is |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 provided it will look for the setting file as you specify it, first looking |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 in the working directory. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 @type settings_file: C{string} |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 @param settings_gui_xml: If you specify this parameter you can customize the look |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 of the settings dialog box. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 @note: As of now you MUST have all the elements of the default settings dialog box. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 At some point we may make it customizable. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 self._app_name = app_name |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 self._settings_file = settings_file |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 self._settings_gui_xml = settings_gui_xml |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 if self._settings_file == "": |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 self._settings_file = "settings.xml" |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 self._appdata = getUserDataDirectory("fife", self._app_name) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 else: |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 self._appdata = os.path.dirname(self._settings_file) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 self._settings_file = os.path.basename(self._settings_file) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 if self._settings_gui_xml == "": |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 self.settings_gui_xml = SETTINGS_GUI_XML |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 if not os.path.exists(os.path.join(self._appdata, self._settings_file)): |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 shutil.copyfile('settings-dist.xml', os.path.join(self._appdata, self._settings_file)) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
128 self._tree = ET.parse(os.path.join(self._appdata, self._settings_file)) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
129 self._root_element = self._tree.getroot() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
130 self.validateTree() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
131 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
132 def validateTree(self): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
133 """ Iterates the settings tree and prints warning when an invalid tag is found """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
134 for c in self._root_element.getchildren(): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
135 if c.tag != "Module": |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
136 print "Invalid tag in settings.xml. Expected Module, got: ", c.tag |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
137 elif c.get("name", "") == "": |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
138 print "Invalid tag in settings.xml. Module name is empty." |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
139 else: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
140 for e in c.getchildren(): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
141 if e.tag != "Setting": |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
142 print "Invalid tag in settings.xml in module: ",c.tag, |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
143 print ". Expected Setting, got: ", e.tag |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
144 elif c.get("name", "") == "": |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
145 print "Invalid tag in settings.xml in module: ",c.tag, |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
146 print ". Setting name is empty", e.tag |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
147 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
148 def getModuleTree(self, module): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
149 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
150 Returns a module element from the settings tree. If no module with the specified |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
151 name exists, a new element will be created. |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
152 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
153 @param module: The module to get from the settings tree |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
154 @type module: C{string} |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
155 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
156 if not isinstance(module, str) and not isinstance(module, unicode): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
157 raise AttributeError("Settings:getModuleTree: Invalid type for module argument.") |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
158 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
159 for c in self._root_element.getchildren(): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
160 if c.tag == "Module" and c.get("name", "") == module: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
161 return c |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
162 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
163 # Create module |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
164 return ET.SubElement(self._root_element, "Module", {"name":module}) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
165 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
166 def get(self, module, name, defaultValue=None): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
167 """ Gets the value of a specified setting |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
168 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
169 @param module: Name of the module to get the setting from |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
170 @param name: Setting name |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
171 @param defaultValue: Specifies the default value to return if the setting is not found |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
172 @type defaultValue: C{str} or C{unicode} or C{int} or C{float} or C{bool} or C{list} or C{dict} |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
173 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
174 if not isinstance(name, str) and not isinstance(name, unicode): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
175 raise AttributeError("Settings:get: Invalid type for name argument.") |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
176 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
177 moduleTree = self.getModuleTree(module) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
178 element = None |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
179 for e in moduleTree.getchildren(): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
180 if e.tag == "Setting" and e.get("name", "") == name: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
181 element = e |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
182 break |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
183 else: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
184 return defaultValue |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
185 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
186 e_value = element.text |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
187 e_strip = element.get("strip", "1").strip().lower() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
188 e_type = str(element.get("type", "str")).strip() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
189 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
190 if e_value is None: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
191 return defaultValue |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
192 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
193 # Strip value |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
194 if e_strip == "" or e_strip == "false" or e_strip == "no" or e_strip == "0": |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
195 e_strip = False |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
196 else: e_strip = True |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
197 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
198 if e_type == "str" or e_type == "unicode": |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
199 if e_strip: e_value = e_value.strip() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
200 else: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
201 e_value = e_value.strip() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
202 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
203 # Return value |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
204 if e_type == 'int': |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
205 return int(e_value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
206 elif e_type == 'float': |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
207 return float(e_value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
208 elif e_type == 'bool': |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
209 e_value = e_value.lower() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
210 if e_value == "" or e_value == "false" or e_value == "no" or e_value == "0": |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
211 return False |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
212 else: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
213 return True |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
214 elif e_type == 'str': |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
215 return str(e_value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
216 elif e_type == 'unicode': |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
217 return unicode(e_value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
218 elif e_type == 'list': |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
219 return self._deserializeList(e_value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
220 elif e_type == 'dict': |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
221 return self._deserializeDict(e_value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
222 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
223 def set(self, module, name, value, extra_attrs={}): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
224 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
225 Sets a setting to specified value. |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
226 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
227 @param module: Module where the setting should be set |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
228 @param name: Name of setting |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
229 @param value: Value to assign to setting |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
230 @type value: C{str} or C{unicode} or C{int} or C{float} or C{bool} or C{list} or C{dict} |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
231 @param extra_attrs: Extra attributes to be stored in the XML-file |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
232 @type extra_attrs: C{dict} |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
233 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
234 if not isinstance(name, str) and not isinstance(name, unicode): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
235 raise AttributeError("Settings:set: Invalid type for name argument.") |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
236 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
237 moduleTree = self.getModuleTree(module) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
238 e_type = "str" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
239 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
240 if isinstance(value, bool): # This must be before int |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
241 e_type = "bool" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
242 value = str(value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
243 elif isinstance(value, int): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
244 e_type = "int" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
245 value = str(value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
246 elif isinstance(value, float): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
247 e_type = "float" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
248 value = str(value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
249 elif isinstance(value, unicode): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
250 e_type = "unicode" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
251 value = unicode(value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
252 elif isinstance(value, list): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
253 e_type = "list" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
254 value = self._serializeList(value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
255 elif isinstance(value, dict): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
256 e_type = "dict" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
257 value = self._serializeDict(value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
258 else: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
259 e_type = "str" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
260 value = str(value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
261 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
262 for e in moduleTree.getchildren(): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
263 if e.tag != "Setting": continue |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
264 if e.get("name", "") == name: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
265 e.text = value |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
266 break |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
267 else: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
268 attrs = {"name":name, "type":e_type} |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
269 for k in extra_attrs: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
270 if k not in attrs: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
271 attrs[k] = extra_args[k] |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
272 elm = ET.SubElement(moduleTree, "Setting", attrs) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
273 elm.text = value |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
274 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
275 def saveSettings(self): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
276 """ Writes the settings to the settings file """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
277 self._indent(self._root_element) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
278 self._tree.write(os.path.join(self._appdata, self._settings_file), 'UTF-8') |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
279 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
280 def _indent(self, elem, level=0): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
281 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
282 Adds whitespace, so the resulting XML-file is properly indented. |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
283 Shamelessly stolen from http://effbot.org/zone/element-lib.htm |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
284 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
285 i = "\n" + level*" " |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
286 if len(elem): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
287 if not elem.text or not elem.text.strip(): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
288 elem.text = i + " " |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
289 if not elem.tail or not elem.tail.strip(): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
290 elem.tail = i |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
291 for elem in elem: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
292 self._indent(elem, level+1) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
293 if not elem.tail or not elem.tail.strip(): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
294 elem.tail = i |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
295 else: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
296 if level and (not elem.tail or not elem.tail.strip()): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
297 elem.tail = i |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
298 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
299 # FIXME: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
300 # These serialization functions are not reliable at all |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
301 # This will only serialize the first level of a dict or list |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
302 # It will not check the types nor the content for conflicts. |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
303 # Perhaps we should add a small serialization library? |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
304 def _serializeList(self, list): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
305 """ Serializes a list, so it can be stored in a text file """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
306 return " ; ".join(list) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
307 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
308 def _deserializeList(self, string): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
309 """ Deserializes a list back into a list object """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
310 return string.split(" ; ") |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
311 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
312 def _serializeDict(self, dict): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
313 """ Serializes a list, so it can be stored in a text file """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
314 serial = "" |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
315 for key in dict: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
316 value = dict[key] |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
317 if serial != "": serial += " ; " |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
318 serial += str(key)+" : "+str(value) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
319 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
320 return serial |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
321 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
322 def _deserializeDict(self, serial): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
323 """ Deserializes a list back into a dict object """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
324 dict = {} |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
325 items = serial.split(" ; ") |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
326 for i in items: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
327 kv_pair = i.split(" : ") |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
328 dict[kv_pair[0]] = kv_pair[1] |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
329 return dict |
497
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
330 |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
331 def onOptionsPress(self): |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
332 """ |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
333 Opens the options dialog box. Usually you would bind this to a button. |
497
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
334 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
335 self.changesRequireRestart = False |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
336 self.isSetToDefault = False |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
337 self.Resolutions = ['640x480', '800x600', '1024x768', '1280x800', '1440x900'] |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
338 if not hasattr(self, 'OptionsDlg'): |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
339 self.OptionsDlg = None |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
340 if not self.OptionsDlg: |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
341 self.OptionsDlg = pychan.loadXML(StringIO(SETTINGS_GUI_XML)) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
342 self.OptionsDlg.distributeInitialData({ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
343 'screen_resolution' : self.Resolutions, |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
344 'render_backend' : ['OpenGL', 'SDL'] |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
345 }) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
346 self.OptionsDlg.distributeData({ |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
347 'screen_resolution' : self.Resolutions.index(str(self.get("FIFE", "ScreenWidth")) + 'x' + str(self.get("FIFE", "ScreenHeight"))), |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
348 'render_backend' : 0 if self.get("FIFE", "RenderBackend") == "OpenGL" else 1, |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
349 'enable_fullscreen' : self.get("FIFE", "FullScreen"), |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
350 'enable_sound' : self.get("FIFE", "PlaySounds") |
497
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
351 }) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
352 self.OptionsDlg.mapEvents({ |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
353 'okButton' : self.applySettings, |
497
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
354 'cancelButton' : self.OptionsDlg.hide, |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
355 'defaultButton' : self.setDefaults |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
356 }) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
357 self.OptionsDlg.show() |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
358 |
499
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
359 def applySettings(self): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
360 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
361 Writes the settings file. If a change requires a restart of the engine |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
362 it notifies you with a small dialog box. |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
363 """ |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
364 screen_resolution, render_backend, enable_fullscreen, enable_sound = self.OptionsDlg.collectData('screen_resolution', 'render_backend', 'enable_fullscreen', 'enable_sound') |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
365 render_backend = 'OpenGL' if render_backend is 0 else 'SDL' |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
366 if render_backend != self.get("FIFE", "RenderBackend"): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
367 self.set("FIFE", 'RenderBackend', render_backend) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
368 self.changesRequireRestart = True |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
369 if int(enable_fullscreen) != int(self.get("FIFE", "FullScreen")): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
370 self.set("FIFE", 'FullScreen', int(enable_fullscreen)) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
371 self.changesRequireRestart = True |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
372 if int(enable_sound) != int(self.get("FIFE", "PlaySounds")): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
373 self.set("FIFE", 'PlaySounds', int(enable_sound)) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
374 self.changesRequireRestart = True |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
375 if screen_resolution != self.Resolutions.index(str(self.get("FIFE", "ScreenWidth")) + 'x' + str(self.get("FIFE", "ScreenHeight"))): |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
376 self.set("FIFE", 'ScreenWidth', int(self.Resolutions[screen_resolution].partition('x')[0])) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
377 self.set("FIFE", 'ScreenHeight', int(self.Resolutions[screen_resolution].partition('x')[2])) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
378 self.changesRequireRestart = True |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
379 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
380 if not self.isSetToDefault: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
381 self.saveSettings() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
382 |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
383 self.OptionsDlg.hide() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
384 if self.changesRequireRestart: |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
385 RestartDlg = pychan.loadXML(StringIO(CHANGES_REQUIRE_RESTART)) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
386 RestartDlg.mapEvents({ 'closeButton' : RestartDlg.hide }) |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
387 RestartDlg.show() |
3dff106b945b
Combined the settings extension with the editor settings module. It is now a little more robust. Note that the settings file format has changed.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
497
diff
changeset
|
388 |
497
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
389 def setDefaults(self): |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
390 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
391 Overwrites the setting file with the default settings-dist.xml file. |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
392 """ |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
393 shutil.copyfile('settings-dist.xml', os.path.join(self._appdata, self._settings_file)) |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
394 self.isSetToDefault = True |
559a26347730
Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
395 self.changesRequireRestart = True |