Project

General

Profile

Codes » History » Version 24

Mitsuki EIKI, 01/16/2025 02:05 PM

1 1 Mitsuki EIKI
h1. Codes
2 2 Mitsuki EIKI
3 3 Man Mong CHAN
[[Wiki]] | [[About_Us]] | [[Project_Overview]] | [[UML_Diagram]] | [[Codes]]
4 4 Kentaro HARATAKE
5 6 Mitsuki EIKI
6 24 Mitsuki EIKI
h1. Config Class Code
7 1 Mitsuki EIKI
8 24 Mitsuki EIKI
h2. config.py: Configuration Class
9
10
~~~ python
11 5 Mitsuki EIKI
#!/usr/bin/env python
12 1 Mitsuki EIKI
# -*- coding: utf-8 -*-
13 16 Mitsuki EIKI
from distutils.util import strtobool
14 1 Mitsuki EIKI
15 7 Mitsuki EIKI
class Config(object):
16 24 Mitsuki EIKI
    def __init__(self, pnd, prd, w, h, p, gamma, overlapWidth, side, isDual, monitorWidth):
17 1 Mitsuki EIKI
        """!
18
        Constructor for Config class.
19 8 Mitsuki EIKI
20
        @param pnd: Projection distance.
21
        @param prd: Projector distance.
22
        @param w: Image width.
23
        @param h: Image height.
24
        @param p: Path to the image.
25
        @param gamma: Gamma value for adjustments.
26
        @param overlapWidth: Width of the overlap area.
27 1 Mitsuki EIKI
        @param side: Side of projection.
28
        """
29 24 Mitsuki EIKI
30 1 Mitsuki EIKI
        self.__projection_distance = pnd
31
        self.__projector_diatance = prd
32
        self.__img_width = w
33 8 Mitsuki EIKI
        self.__img_height = h
34
        self.__img_path = p
35
        self.__gamma = gamma
36 1 Mitsuki EIKI
        self.__overlapWidth = overlapWidth
37 8 Mitsuki EIKI
        self.__side = side
38 24 Mitsuki EIKI
39 8 Mitsuki EIKI
        self.__isDualMonitor = isDual
40
        self.__monitorWidth = monitorWidth
41
42 7 Mitsuki EIKI
    def getProjectionDistance(self):
43 5 Mitsuki EIKI
        """!
44
        Retrieve the projection distance.
45 8 Mitsuki EIKI
46
        @return: Projection distance as an integer.
47 5 Mitsuki EIKI
        """
48
        return int(self.__projection_distance)
49 1 Mitsuki EIKI
50
    def getProjectorDistance(self):
51
        """!
52 5 Mitsuki EIKI
        Retrieve the projector distance.
53 8 Mitsuki EIKI
54
        @return: Projector distance as an integer.
55 1 Mitsuki EIKI
        """
56
        return int(self.__projector_diatance)
57
58 8 Mitsuki EIKI
    def getImgWidth(self):
59
        """!
60
        Retrieve the image width.
61 1 Mitsuki EIKI
62 8 Mitsuki EIKI
        @return: Image width as an integer.
63
        """
64
        return int(self.__img_width)
65
66
    def getImgHeight(self):
67
        """!
68
        Retrieve the image height.
69
70
        @return: Image height as an integer.
71
        """
72
        return int(self.__img_height)
73
74
    def getImgPath(self):
75
        """!
76
        Retrieve the image path.
77
78
        @return: Image path as a string.
79
        """
80
        return str(self.__img_path)
81
82
    def getGamma(self):
83
        """!
84
        Retrieve the gamma value.
85
86
        @return: Gamma value as a float.
87
        """
88
        return float(self.__gamma)
89
90
    def getOverlapWidth(self):
91
        """!
92
        Retrieve the overlap width.
93
94
        @return: Overlap width as an integer.
95
        """
96
        return int(self.__overlapWidth)
97
98
    def getSide(self):
99 1 Mitsuki EIKI
        """!
100 8 Mitsuki EIKI
        Retrieve the side of projection.
101
102 1 Mitsuki EIKI
        @return: Side as a string.
103 8 Mitsuki EIKI
        """
104
        return str(self.__side)
105 24 Mitsuki EIKI
    
106 8 Mitsuki EIKI
    def getIsDualMonitor(self):
107
        return bool(strtobool(self.__isDualMonitor))
108
109
    def getMonitorWidth(self):
110
        return int(self.__monitorWidth)
111
112 1 Mitsuki EIKI
    @staticmethod
113
    def readConfigFile():
114
        """!
115
        Reads the configuration from a config.ini file and returns a Config object.
116 8 Mitsuki EIKI
117
        @return: Config object with settings loaded from config.ini.
118 1 Mitsuki EIKI
        """
119
        import configparser
120 8 Mitsuki EIKI
        config = configparser.ConfigParser()
121
        config.read('config.ini')
122
123
        __img_path = config["settings"]["imagePath"]
124
        __img_width = config["settings"]["imageWidth"]
125
        __img_height = config["settings"]["imageHeight"]
126 1 Mitsuki EIKI
        __projection_distance = config["settings"]["projectionDistance"]
127 8 Mitsuki EIKI
        __projector_diatance = config["settings"]["projectorDistance"]
128
        __gamma = config["settings"]["gamma"]
129 1 Mitsuki EIKI
        __overlapWidth = config["settings"]["overlapWidth"]
130
        __side = config["settings"]["side"]
131 8 Mitsuki EIKI
        __isDualMonitor = config["settings"]["isDualMonitor"]
132 1 Mitsuki EIKI
        __monitorWidth= config["settings"]["monitorWidth"]
133 24 Mitsuki EIKI
        
134 16 Mitsuki EIKI
        return Config(__projection_distance, __projector_diatance, __img_width, __img_height, __img_path, __gamma, __overlapWidth, __side, __isDualMonitor, __monitorWidth)
135 24 Mitsuki EIKI
~~~