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