summaryrefslogtreecommitdiff
path: root/grc/gui/Config.py
blob: 0f40e06fcee9554ac2df2d25ef0aaa06d32c8b45 (plain)
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
"""
Copyright 2016 Free Software Foundation, Inc.
This file is part of GNU Radio

GNU Radio Companion is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

GNU Radio Companion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""

from __future__ import absolute_import, print_function

import sys
import os

from ..core.Config import Config as _Config
from . import Constants


class Config(_Config):

    name = 'GNU Radio Companion'

    gui_prefs_file = os.environ.get(
        'GRC_PREFS_PATH', os.path.expanduser('~/.gnuradio/grc.conf'))

    def __init__(self, install_prefix, *args, **kwargs):
        _Config.__init__(self, *args, **kwargs)
        self.install_prefix = install_prefix
        Constants.update_font_size(self.font_size)

    @property
    def editor(self):
        return self._gr_prefs.get_string('grc', 'editor', '')

    @editor.setter
    def editor(self, value):
        self._gr_prefs.get_string('grc', 'editor', value)
        self._gr_prefs.save()

    @property
    def xterm_executable(self):
        return self._gr_prefs.get_string('grc', 'xterm_executable', 'xterm')

    @property
    def default_canvas_size(self):
        try:  # ugly, but matches current code style
            raw = self._gr_prefs.get_string('grc', 'canvas_default_size', '1280, 1024')
            value = tuple(int(x.strip('() ')) for x in raw.split(','))
            if len(value) != 2 or not all(300 < x < 4096 for x in value):
                raise Exception()
            return value
        except:
            print("Error: invalid 'canvas_default_size' setting.", file=sys.stderr)
            return Constants.DEFAULT_CANVAS_SIZE_DEFAULT

    @property
    def font_size(self):
        try:  # ugly, but matches current code style
            font_size = self._gr_prefs.get_long('grc', 'canvas_font_size',
                                                Constants.DEFAULT_FONT_SIZE)
            if font_size <= 0:
                raise Exception()
        except:
            font_size = Constants.DEFAULT_FONT_SIZE
            print("Error: invalid 'canvas_font_size' setting.", file=sys.stderr)

        return font_size

    @property
    def default_qss_theme(self):
        return self._gr_prefs.get_string('qtgui', 'qss', '')

    @default_qss_theme.setter
    def default_qss_theme(self, value):
        self._gr_prefs.set_string("qtgui", "qss", value)
        self._gr_prefs.save()