annotate engine/python/fife/extensions/fife_settings.py @ 664:61a5f86a0db3

* Fixed the warnings that were introduced by the light branch merge.
author helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Nov 2010 15:46:48 +0000
parents e3140f01749d
children
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
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 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
33 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
34 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
35
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 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
37 from fife.extensions.fife_utils import getUserDataDirectory
567
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
38 from fife.extensions.serializers.simplexml import SimpleXMLSerializer
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
39
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 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
41 <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
42 <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
43 <HBox>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 <VBox>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 <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
46 <Label text="Renderer:" />
661
e3140f01749d * Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 626
diff changeset
47 <Label text="Light Model:" />
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 </VBox>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 <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
50 <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
51 <DropDown name="render_backend" min_size="120,0" />
661
e3140f01749d * Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 626
diff changeset
52 <DropDown name="lighting_model" min_size="120,0" />
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 </VBox>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 </HBox>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 <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
56 <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
57 <HBox>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 <Spacer />
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 <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
60 <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
61 <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
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 </Window>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 """
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 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
67 <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
68 <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
69 <HBox>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 <Spacer />
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 <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
72 </HBox>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 </Window>
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 """
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
76 FIFE_MODULE = "FIFE"
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
77
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 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
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 This class manages loading and saving of game settings.
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
81
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 Usage::
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 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
84 settings = Setting(app_name="myapp")
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
85 screen_width = settings.get("FIFE", "ScreenWidth", 1024)
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
86 screen_height = settings.get("FIFE", "ScreenHeight", 768)
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 """
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
88
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
89 def __init__(self, app_name="", settings_file="", default_settings_file= "settings-dist.xml", settings_gui_xml="", changes_gui_xml="", copy_dist=True, serializer=None):
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 """
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 Initializes the Setting object.
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
92
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
93 @param app_name: The applications name. If this parameter is provided
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
94 alone it will try to read the settings file from the users home directory.
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 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
96 @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
97 @param settings_file: The name of the settings file. If this parameter is
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
98 provided it will look for the setting file as you specify it, first looking
505
ee65aa323457 Updated the ApplicationBase settings to use the new and improved fife_setting extension. I was able to remove all the setting related functions from the demos and editor so that the ApplicationBase now takes care of all the FIFE related settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 499
diff changeset
99 in the working directory. It will NOT look in the users home directory.
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 @type settings_file: C{string}
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
101 @param default_settings_file: The name of the default settings file. If the settings_file
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
102 does not exist this file will be copied into the place of the settings_file. This file
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
103 must exist in the root directory of your project!
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
104 @type default_settings_file: C{string}
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 @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
106 of the settings dialog box.
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
107 @param copy_dist: Copies the default settings file to the settings_file location. If
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
108 this is False it will create a new empty setting file.
612
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
109 @param serializer: Overrides the default XML serializer
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
110 @type serializer: C{SimpleSerializer}
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
111
497
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 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
114 self._settings_file = settings_file
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
115 self._default_settings_file = default_settings_file
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 self._settings_gui_xml = settings_gui_xml
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
117 self._changes_gui_xml = changes_gui_xml
626
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
118 self.OptionsDlg = None
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
119
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
120 # Holds SettingEntries
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
121 self._entries = {}
567
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
122
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 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
124 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
125 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
126 else:
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 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
128 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
129
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
130
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 if self._settings_gui_xml == "":
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
132 self._settings_gui_xml = SETTINGS_GUI_XML
532
4da56756a617 Fixed a small bug that didn't allow to use xml files as gui input for the setting extension
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 515
diff changeset
133
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
134 if self._changes_gui_xml == "":
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
135 self._changes_gui_xml = CHANGES_REQUIRE_RESTART
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
136
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
137
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138 if not os.path.exists(os.path.join(self._appdata, self._settings_file)):
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
139 if os.path.exists(self._default_settings_file) and copy_dist:
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
140 shutil.copyfile(self._default_settings_file, os.path.join(self._appdata, self._settings_file))
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
141
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
142 #default settings
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
143 self._resolutions = ['640x480', '800x600', '1024x768', '1280x800', '1440x900']
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
144 self._renderbackends = ['OpenGL', 'SDL']
661
e3140f01749d * Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 626
diff changeset
145 self._lightingmodels = [0, 1, 2]
532
4da56756a617 Fixed a small bug that didn't allow to use xml files as gui input for the setting extension
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 515
diff changeset
146
533
082e919cc348 Setting Extension:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 532
diff changeset
147 #Used to stylize the options gui
082e919cc348 Setting Extension:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 532
diff changeset
148 self._gui_style = "default"
082e919cc348 Setting Extension:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 532
diff changeset
149
612
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
150 #Initialize the serializer
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
151 if serializer:
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
152 self._serializer = serializer
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
153 else:
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
154 self._serializer = SimpleXMLSerializer()
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
155
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
156 self.initSerializer()
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
157
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
158 self._initDefaultSettingEntries()
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
159
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
160 def initSerializer(self):
612
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
161 self._serializer.load(os.path.join(self._appdata, self._settings_file))
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
162
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
163 def _initDefaultSettingEntries(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
164 """Initializes the default fife setting entries. Not to be called from
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
165 outside this class."""
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
166 self.createAndAddEntry(FIFE_MODULE, "PlaySounds", "enable_sound",
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
167 requiresrestart=True)
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
168 self.createAndAddEntry(FIFE_MODULE, "FullScreen", "enable_fullscreen",
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
169 requiresrestart=True)
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
170 self.createAndAddEntry(FIFE_MODULE, "ScreenResolution", "screen_resolution", initialdata = self._resolutions,
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
171 requiresrestart=True)
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
172 self.createAndAddEntry(FIFE_MODULE, "RenderBackend", "render_backend", initialdata = self._renderbackends,
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
173 requiresrestart=True)
661
e3140f01749d * Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 626
diff changeset
174 self.createAndAddEntry(FIFE_MODULE, "Lighting", "lighting_model", initialdata = self._lightingmodels,
e3140f01749d * Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 626
diff changeset
175 requiresrestart=True)
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
176
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
177 def createAndAddEntry(self, module, name, widgetname, applyfunction=None, initialdata=None, requiresrestart=False):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
178 """"
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
179 @param module: The Setting module this Entry belongs to
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
180 @type module: C{String}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
181 @param name: The Setting's name
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
182 @type name: C{String}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
183 @param widgetname: The name of the widget that is used to change this
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
184 setting
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
185 @type widgetname: C{String}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
186 @param applyfunction: function that makes the changes when the Setting is
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
187 saved
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
188 @type applyfunction: C{function}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
189 @param initialdata: If the widget supports the setInitialData() function
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
190 this can be used to set the initial data
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
191 @type initialdata: C{String} or C{Boolean}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
192 @param requiresrestart: Whether or not the changing of this setting
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
193 requires a restart
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
194 @type requiresrestart: C{Boolean}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
195 """
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
196 entry = SettingEntry(module, name, widgetname, applyfunction, initialdata, requiresrestart)
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
197 self.addEntry(entry)
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
198
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
199 def addEntry(self, entry):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
200 """Adds a new C{SettingEntry} to the Settting
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
201 @param entry: A new SettingEntry that is to be added
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
202 @type entry: C{SettingEntry}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
203 """
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
204 if entry.module not in self._entries:
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
205 self._entries[entry.module] = {}
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
206 self._entries[entry.module][entry.name] = entry
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
207
556
1d60e0223117 Added a check when a new entry is added to the settings.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 555
diff changeset
208 # Make sure the new entry is available
1d60e0223117 Added a check when a new entry is added to the settings.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 555
diff changeset
209 if self.get(entry.module, entry.name) is None:
1d60e0223117 Added a check when a new entry is added to the settings.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 555
diff changeset
210 print "Updating", self._settings_file, "to the default, it is missing the entry:"\
1d60e0223117 Added a check when a new entry is added to the settings.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 555
diff changeset
211 , entry.name ,"for module", entry.module
1d60e0223117 Added a check when a new entry is added to the settings.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 555
diff changeset
212 self.setDefaults()
1d60e0223117 Added a check when a new entry is added to the settings.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 555
diff changeset
213 if self.get(entry.module, entry.name) is None:
1d60e0223117 Added a check when a new entry is added to the settings.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 555
diff changeset
214 print "WARNING:", entry.module, ":", entry.name, "still not found!"
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
215
556
1d60e0223117 Added a check when a new entry is added to the settings.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 555
diff changeset
216
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
217 def saveSettings(self, filename=""):
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
218 """ Writes the settings to the settings file
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
219
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
220 @param filename: Specifies the file to save the settings to. If it is not specified
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
221 the original settings file is used.
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
222 @type filename: C{string}
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
223 """
612
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
224 if self._serializer:
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
225 if filename == "":
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
226 self._serializer.save(os.path.join(self._appdata, self._settings_file))
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
227 else:
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
228 self._serializer.save(filename)
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
229
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 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
231 """ Gets the value of a specified setting
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
232
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
233 @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
234 @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
235 @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
236 @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
237 """
612
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
238 if self._serializer:
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
239 return self._serializer.get(module, name, defaultValue)
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
240 else:
567
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
241 return None
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
242
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
243 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
244 """
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 Sets a setting to specified value.
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
246
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
247 @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
248 @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
249 @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
250 @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
251 @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
252 @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
253 """
612
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
254 if self._serializer:
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
255 self._serializer.set(module, name, value, extra_attrs)
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
256
567
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
257 def setGuiStyle(self, style):
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
258 """ Set a custom gui style used for the option dialog.
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
259 @param style: Pychan style to be used
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
260 @type style: C{string}
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
261 """
567
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
262 self._gui_style = style
9152ed2b5bb8 Created SimpleXMLSerializer which makes loading and saving variables to an XML file simple. In the process I removed the the XML code from the Settings class. It now uses SimpleXMLSerializer to load and save settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 558
diff changeset
263
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
264 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
265 """
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
266 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
267 """
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
268 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
269 self.isSetToDefault = False
626
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
270 if not self.OptionsDlg:
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
271 self.loadSettingsDialog()
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
272 self.fillWidgets()
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
273 self.OptionsDlg.show()
532
4da56756a617 Fixed a small bug that didn't allow to use xml files as gui input for the setting extension
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 515
diff changeset
274
626
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
275 def loadSettingsDialog(self):
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
276 """
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
277 Load up the settings xml and return the widget.
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
278 """
555
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
279 self.OptionsDlg = self._loadWidget(self._settings_gui_xml)
533
082e919cc348 Setting Extension:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 532
diff changeset
280 self.OptionsDlg.stylize(self._gui_style)
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
281 self.OptionsDlg.mapEvents({
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
282 'okButton' : self.applySettings,
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
283 'cancelButton' : self.OptionsDlg.hide,
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
284 'defaultButton' : self.setDefaults
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
285 })
626
01994b7e505a * Applied GreyGhosts patch to fife_settings. Allows the user to load the gui XML whenever they want. Also returns a reference to the dialog so it can be worked with outside of fife_settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 615
diff changeset
286 return self.OptionsDlg
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
287
555
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
288 def _loadWidget(self, dialog):
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
289 """Loads a widget. Can load both files and pure xml strings"""
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
290 if os.path.isfile(self._settings_gui_xml):
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
291 return pychan.loadXML(dialog)
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
292 else:
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
293 return pychan.loadXML(StringIO(dialog))
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
294
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
295 def fillWidgets(self):
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
296 for module in self._entries.itervalues():
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
297 for entry in module.itervalues():
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
298 widget = self.OptionsDlg.findChildByName(entry.settingwidgetname)
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
299 value = self.get(entry.module, entry.name)
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
300 if type(entry.initialdata) is list:
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
301 try:
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
302 value = entry.initialdata.index(value)
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
303 except ValueError:
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
304 raise ValueError("\"" + value + "\" is not a valid value for " + entry.name + ". Valid options: " + str(entry.initialdata))
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
305 entry.initializeWidget(widget, value)
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
306
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
307 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
308 """
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 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
310 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
311 """
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
312 for module in self._entries.itervalues():
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
313 for entry in module.itervalues():
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
314 widget = self.OptionsDlg.findChildByName(entry.settingwidgetname)
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
315 data = widget.getData()
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
316
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
317 # If the data is a list we need to get the correct selected data
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
318 # from the list. This is needed for e.g. dropdowns or listboxs
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
319 if type(entry.initialdata) is list:
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
320 data = entry.initialdata[data]
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
321
558
4cb5d0ed33a9 Fixed a small bug introduced in the last commit
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 557
diff changeset
322 # only take action if something really changed
4cb5d0ed33a9 Fixed a small bug introduced in the last commit
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 557
diff changeset
323 if data != self.get(entry.module, entry.name):
557
c62fe35ae67c fife_settings: Make sure onApply is only called if the entry changed
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 556
diff changeset
324 self.set(entry.module, entry.name, data)
c62fe35ae67c fife_settings: Make sure onApply is only called if the entry changed
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 556
diff changeset
325 entry.onApply(data)
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
326
558
4cb5d0ed33a9 Fixed a small bug introduced in the last commit
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 557
diff changeset
327 if entry.requiresrestart:
4cb5d0ed33a9 Fixed a small bug introduced in the last commit
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 557
diff changeset
328 self.changesRequireRestart = True
4cb5d0ed33a9 Fixed a small bug introduced in the last commit
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 557
diff changeset
329
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
330 self.saveSettings()
514
0cdc727f9f66 Honour the "settings_gui_xml" paramater in the Settings class
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 505
diff changeset
331
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
332 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
333 if self.changesRequireRestart:
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
334 self._showChangeRequireRestartDialog()
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
335
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
336
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
337 def _showChangeRequireRestartDialog(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
338 """Shows a dialog that informes the user that a restart is required
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
339 to perform the changes."""
555
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
340 RestartDlg = self._loadWidget(self._changes_gui_xml)
63226105ac45 Load the changes_gui_xml correcty, even if it is set to a file
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 554
diff changeset
341 RestartDlg.stylize(self._gui_style)
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
342 RestartDlg.mapEvents({ 'closeButton' : RestartDlg.hide })
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
343 RestartDlg.show()
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
344
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
345
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
346 def setAvailableScreenResolutions(self, reslist):
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
347 """
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
348 A list of valid default screen resolutions. This should be called once
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
349 right after you instantiate Settings.
532
4da56756a617 Fixed a small bug that didn't allow to use xml files as gui input for the setting extension
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 515
diff changeset
350
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
351 Valid screen resolutions must be strings in the form of: WIDTHxHEIGHT
532
4da56756a617 Fixed a small bug that didn't allow to use xml files as gui input for the setting extension
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 515
diff changeset
352
515
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
353 Example:
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
354 settings.setAvailableScreenResolutions(["800x600", "1024x768"])
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
355 """
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
356 self._resolutions = reslist
520bd1621644 Added a loadSettings function. Added the ability to set the valid screen resolutions. Fixed a problem with the settings dialog that kept the settings you selected even though you pressed cancel. When you press the "defaults" button it now applies the defaults and prompts the user to restart the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 514
diff changeset
357
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
358 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
359 """
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
360 Overwrites the setting file with the default settings file.
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
361 """
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
362 shutil.copyfile(self._default_settings_file, os.path.join(self._appdata, self._settings_file))
497
559a26347730 Forgot to add fife_settings.py in my last commit. Adding it now.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
363 self.changesRequireRestart = True
612
867aad1c01cd Added the ability to use a custom serializer with the fife.Setting class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 569
diff changeset
364 self.initSerializer()
615
6f3f5686a56e Fixed a small bug where the widgets were not being updated with new data when the default settings were loaded.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 614
diff changeset
365
6f3f5686a56e Fixed a small bug where the widgets were not being updated with new data when the default settings were loaded.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 614
diff changeset
366 #update all widgets with the new data
6f3f5686a56e Fixed a small bug where the widgets were not being updated with new data when the default settings were loaded.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 614
diff changeset
367 self.fillWidgets()
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
368
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
369 def _getEntries(self):
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
370 return self._entries
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
371
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
372 def _setEntries(self, entries):
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
373 self._entries = entries
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
374
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
375 def _getSerializer(self):
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
376 return self._serializer
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
377
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
378 entries = property(_getEntries, _setEntries)
614
567d53c1c010 Added the ability to specify the default settings filename. Also added the serializer get property.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 612
diff changeset
379 serializer = property(_getSerializer)
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
380
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
381 class SettingEntry(object):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
382
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
383 def __init__(self, module, name, widgetname, applyfunction=None, initialdata=None, requiresrestart=False):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
384 """
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
385 @param module: The Setting module this Entry belongs to
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
386 @type module: C{String}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
387 @param name: The Setting's name
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
388 @type name: C{String}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
389 @param widgetname: The name of the widget that is used to change this
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
390 setting
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
391 @type widgetname: C{String}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
392 @param applyfunction: function that makes the changes when the Setting is
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
393 saved
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
394 @type applyfunction: C{function}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
395 @param initialdata: If the widget supports the setInitialData() function
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
396 this can be used to set the initial data
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
397 @type initialdata: C{String} or C{Boolean}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
398 @param requiresrestart: Whether or not the changing of this setting
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
399 requires a restart
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
400 @type requiresrestart: C{Boolean}
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
401 """
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
402 self._module = module
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
403 self._name = name
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
404 self._settingwidgetname = widgetname
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
405 self._requiresrestart = requiresrestart
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
406 self._initialdata = initialdata
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
407 self._applyfunction = applyfunction
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
408
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
409 def initializeWidget(self, widget, currentValue):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
410 """Initialize the widget with needed data"""
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
411 if self._initialdata is not None:
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
412 widget.setInitialData(self._initialdata)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
413 widget.setData(currentValue)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
414
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
415 def onApply(self, data):
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
416 """Implement actions that need to be taken when the setting is changed
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
417 here.
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
418 """
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
419 if self._applyfunction is not None:
554
9b549d42f9ea Improved fife_settings:
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 543
diff changeset
420 self._applyfunction(data)
538
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
421
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
422 def _getModule(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
423 return self._module
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
424
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
425 def _setModule(self, module):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
426 self._module = module
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
427
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
428 def _getName(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
429 return self._name
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
430
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
431 def _setName(self, name):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
432 self._name = name
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
433
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
434 def _getSettingWidgetName(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
435 return self._settingwidgetname
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
436
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
437 def _setSettingWidgetName(self, settingwidgetname):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
438 self._settingwidgetname = settingwidgetname
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
439
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
440 def _getRequiresRestart(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
441 return self._requiresrestart
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
442
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
443 def _setRequiresRestart(self, requiresrestart):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
444 self._requiresrestart = requiresrestart
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
445
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
446 def _getInitialData(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
447 return self._initialdata
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
448
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
449 def _setInitialData(self, initialdata):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
450 self._initialdata = initialdata
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
451
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
452 def _getApplyFunction(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
453 return self._applyfunction
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
454
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
455 def _setApplyFunction(self, applyfunction):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
456 self._applyfunction = applyfunction
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
457
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
458 module = property(_getModule, _setModule)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
459 name = property(_getName, _setName)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
460 settingwidgetname = property(_getSettingWidgetName, _setSettingWidgetName)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
461 requiresrestart = property(_getRequiresRestart, _setRequiresRestart)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
462 initialdata = property(_getInitialData, _setInitialData)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
463 applyfunction = property(_getApplyFunction, _setApplyFunction)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
464
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
465 def __str__(self):
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
466 return "SettingEntry: " + self.name + " Module: " + self.module + " Widget: " + \
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
467 self.settingwidgetname + " requiresrestart: " + str(self.requiresrestart) + \
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
468 " initialdata: " + str(self.initialdata)
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
469
00aa20dc8b7f Made the Setting class much more customizable by adding the SettingEntry class.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 533
diff changeset
470