File: config.py

package info (click to toggle)
pysiogame 4.20.01-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,876 kB
  • sloc: python: 48,742; xml: 3,813; sh: 30; makefile: 11
file content (232 lines) | stat: -rw-r--r-- 10,960 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# -*- coding: utf-8 -*-

import os
import sys

import classes.extras as ex
from classes.cversion import ver


class Config:
    """holds some basic configuration data - screen size among others"""
    def __init__(self, android):
        self.font_multiplier = 1
        self.font_line_height_adjustment = 1
        self.font_start_at_adjustment = 0
        self.font_variant = 0
        self.version = ver
        self.avail_version = ""
        self.update_available = False
        self.settings_changed = False
        self.fs_width = 1024
        self.fs_height = 768
        self.debug_screen_size = None  # [900,600]
        # size_limits - don't let window resizing get out of hand [min_w, min_h, max_w, max_h]
        self.size_limits = [838, 570, 2000, 2000]
        # [670,480,2000,2000] #800 - minimum to fit all buttons, 2000 - with over 2000 pixels each way pygame is not redrawing very well
        # set total size of OS panels and window decorations on both sides - used in windowed version. Not so much important now with resizing enabled.
        # this will not be auto-detected
        self.os_panels_w = 2  # sum of widths of non-hiding vertical Panels (if any) and window border (1px on each side).
        self.os_panels_h = 52  # sum of heights of non-hiding horizontal panels (ie. menu bar(s) + application bar + window bar + border, etc.).

        # the game will 'remember' at what level each game has been left and it will save this data for next session if the save_levels is left at True
        # to reset the game - remove the level_data.txt file check below for the location of these files - it will be recreated next time you close the game
        # if the pickle has been saved with python3 then python2 will not be able to open it and will reset all levels to 1
        # the data is automatically saved to file every time you switch game and on exit.
        self.save_levels = True

        # the following 2 settings will be overridden by configuration file
        # to change any of these do this in the in-game preferences, except fullscreen if there's no config file the value below will be used.
        self.fullscreen = False
        # self.read_inst = False #no longer used
        self.check_updates = True

        self.user_age_group = 0  # default group - showing all games - TO DO: will be overridden by data stored in database
        self.max_age = 7

        # Window title
        self.window_caption = "eduActiv8 - v " + self.version
        self.db_file_name = 'eduactiv8.db'

        """
        #file names paths to level and language files
        $XDG_DATA_HOME defines the base directory relative to which user
        specific data files should be stored. If $XDG_DATA_HOME is either not
        set or empty, a default equal to $HOME/.local/share should be used.
        $XDG_CONFIG_HOME defines the base directory relative to which user
        specific configuration files should be stored. If $XDG_CONFIG_HOME is
        either not set or empty, a default equal to $HOME/.config should be
        used.
        """
        if android is None:
            p = sys.platform
            directory = os.path.dirname(os.path.abspath(os.path.expanduser("~/.config/eduactiv8/")))
            self.window_pos = (3, 30)
            if p == "linux" or p == "linux2":
                # self.window_pos = (10,30)
                self.platform = "linux"
                try:
                    xdg_data_home = os.environ.get('XDG_DATA_HOME')
                except:
                    xdg_data_home = None

                if xdg_data_home is None or xdg_data_home == "":
                    home = os.environ.get('HOME')
                    directory = os.path.join(home, '.local', 'share', 'eduactiv8')
                else:
                    directory = os.path.join(xdg_data_home, 'eduactiv8')

            elif p == "win32" or p == "cygwin":
                #windows or other non linux operating system
                self.platform = "windows"
            elif p == "darwin":
                self.platform = "macos"
                self.window_pos = (0, 0)
                self.os_panels_w = 0  # sum of widths of non-hiding vertical Panels (if any) and window border (1px on each side).
                self.os_panels_h = 120
            self.file_db = os.path.join(directory, self.db_file_name)
        else:
            # android folder creation
            self.platform = "android"
            self.window_pos = (0, 0)
            directory = "assets"
            self.file_db = os.path.join(directory, self.db_file_name)
        try:
            if not os.path.exists(directory):
                os.makedirs(directory)
        except:
            print("Error - can't create directory. The game data won't be saved.")

        # default settings
        self.loaded_settings = False
        """
        lang,
        sounds,
        espeak,
        screenw,
        screenh
        """
        # [0 language, 1 talkative, 2 untranslated languages, 3 full screen, 4 user_name, 5 screen_w, 6 screen_h]

        self.settings = dict()
        try:
            import pyfribidi
            self.fribidi_loaded = True
            self.frididi = pyfribidi
            s = ex.unival('العربية')
            self.arabic = self.frididi.log2vis(s)
        except:
            self.fribidi_loaded = False
            self.frididi = None
            self.arabic = "Arabic"

        self.set_font_family()

        if self.fribidi_loaded:
            self.lang_titles = ["English", "American English", "Català", "Deutsch", "Español", "Français", "Italiano", "Lakȟótiyapi",
                                "Polski", "Português", "Suomalainen", "Ελληνικά", "Български", "Русский", "Српски", "Українська",
                                "תירבע", self.arabic]
            self.all_lng = ["en_GB", "en_US", "ca", "de", "es_ES", "fr", "it", "lkt", "pl", "pt_PT", "fi", "el", "bg", "ru", "sr",
                            "uk", "he", "ar"]
            self.ok_lng = ["en_GB", "en_US", "ca", "de", "es_ES", "fr", "it", "lkt", "pl", "pt_PT", "fi", "el", "bg", "ru", "sr",
                           "uk", "he"]
        else:
            self.lang_titles = ["English", "American English", "Català", "Deutsch", "Español", "Français", "Italiano", "Lakȟótiyapi",
                                "Polski", "Português", "Suomalainen", "Ελληνικά", "Български", "Русский", "Српски", "Українська",
                                "תירבע"]
            self.all_lng = ["en_GB", "en_US", "ca", "de", "es_ES", "fr", "it", "lkt", "pl", "pt_PT", "fi", "el", "bg", "ru", "sr",
                            "uk", "he"]
            self.ok_lng = ["en_GB", "en_US", "ca", "de", "es_ES", "fr", "it", "lkt", "pl", "pt_PT", "fi", "el", "bg", "ru", "sr",
                           "uk", "he"]

        self.id2lng = {1: "English", 5: "Català", 19: "Српски", 12: "Deutsch", 8: "Español", 16: "Ελληνικά",
                       17: "תירבע", 11: "Italiano", 20:  "Lakȟótiyapi", 3: "Polski", 9: "Português", 21: "Български", 13: "Русский", 15: "Suomalainen",
                       14: "Українська", 2: self.arabic, 10: "Français"}
        self.id2imgsuffix = {1: "", 5: "", 18: "ru", 12: "", 8: "", 16: "el", 17: "he", 11: "", 20: "", 3: "", 9: "", 21: "ru", 13: "ru",
                             15: "", 14: "ru", 2: "ar", 10: ""}

        """
        self.id2lng = {1: "English", 5: "Català", 19: "Српски", 12: "Deutsch", 8: "Español", 16: "Ελληνικά",
                       17: "תירבע", 11: "Italiano", 20:  "Lakȟótiyapi", 3: "Polski", 9: "Português", 13: "Русский", 15: "Suomalainen",
                       14: "Українська", 2: self.arabic, 6: "Dansk", 10: "Français", 7: "Nederlands", 4: "Slovenčina"}
        self.id2imgsuffix = {1: "", 5: "", 18: "ru", 12: "", 8: "", 16: "el", 17: "he", 11: "", 20: "", 3: "", 9: "", 13: "ru",
                             15: "", 14: "ru", 2: "ar", 6: "", 10: "", 7: "", 4: ""}
        """

    def set_font_family(self, variant=0):
        self.font_variant = variant
        if variant == 0:
            self.font_dir = 'LinLibertine'
            self.font_name_1 = 'LinBiolinum_RB_merged_with_Kacst.ttf'
            self.font_name_2 = 'LinBiolinum_R_merged_with_Kacst.ttf'
            self.font_multiplier = 1
            self.font_line_height_adjustment = 1.5
            self.font_start_at_adjustment = 5

        elif variant == 1:
            self.font_dir = 'FreeSans'
            self.font_name_1 = 'FreeSansBold.ttf'
            self.font_name_2 = 'FreeSans.ttf'
            self.arabic = "Arabic"
            self.font_multiplier = 1
            self.font_line_height_adjustment = 1
            self.font_start_at_adjustment = 0

        elif variant == 2:
            self.font_dir = 'FreeSans'
            self.font_name_1 = 'FreeSansBold.ttf'
            self.font_name_2 = 'FreeSans.ttf'
            self.arabic = "Arabic"
            self.font_multiplier = 1
            self.font_line_height_adjustment = 1
            self.font_start_at_adjustment = 0

        """
        self.font_dir = 'LinLibertine'
        self.font_name_1 = 'LinBiolinum_RBah.ttf'
        self.font_name_2 = 'LinBiolinum_Rah.ttf'
        """

    def set_start_at(self, scale):
        if self.font_variant == 0:
            self.font_start_at_adjustment = int(scale * 5 / 100)

    def reset_settings(self):
        pass

    def load_settings(self, db, userid):
        'loads saved settings from pickled file - language and screen size dimensions and mode'
        # load user settings
        u = db.load_user_settings(userid)

        self.user_age_group = db.get_age_group(userid=userid)
        # load admin settings
        a = db.get_login_defs()
        # lang, sounds, espeak, screenw, screenh


        self.settings["check_updates"] = int(a[1][2])
        if self.settings["check_updates"] == 1:
            self.check_updates = True
        else:
            self.check_updates = False
        self.settings["full_screen"] = int(a[1][0])

        self.settings["lang"] = u[0]
        self.settings["sounds"] = u[1]
        self.settings["espeak"] = u[2]

        if self.debug_screen_size is None:
            self.settings["screenw"] = u[3]
            self.settings["screenh"] = u[4]
        else:
            self.settings["screenw"] = self.debug_screen_size[0]
            self.settings["screenh"] = self.debug_screen_size[1]

        self.settings["scheme"] = u[5]
        self.loaded_settings = True

    def save_settings(self, db):
        'save settings to file'
        db.save_user_settings(self.settings["lang"], self.settings["sounds"], self.settings["espeak"],
                              self.settings["screenw"], self.settings["screenh"], self.settings["scheme"])