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