Project

General

Profile

Actions

Codes » History » Revision 29

« Previous | Revision 29/33 (diff) | Next »
Mitsuki EIKI, 01/16/2025 02:10 PM


Codes

Wiki | About_Us | Project_Overview | UML_Diagram | Codes

Config Class Code

config.py: Configuration Class

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from distutils.util import strtobool

class Config(object):
    def __init__(self, pnd, prd, w, h, p, gamma, overlapWidth, side, isDual, monitorWidth):
        """!
        Constructor for Config class.

        @param pnd: Projection distance.
        @param prd: Projector distance.
        @param w: Image width.
        @param h: Image height.
        @param p: Path to the image.
        @param gamma: Gamma value for adjustments.
        @param overlapWidth: Width of the overlap area.
        @param side: Side of projection.
        """ 
        self.__projection_distance = pnd
        self.__projector_diatance = prd
        self.__img_width = w
        self.__img_height = h
        self.__img_path = p
        self.__gamma = gamma
        self.__overlapWidth = overlapWidth
        self.__side = side
        self.__isDualMonitor = isDual
        self.__monitorWidth = monitorWidth

    def getProjectionDistance(self):
        """!
        Retrieve the projection distance.

        @return: Projection distance as an integer.
        """ 
        return int(self.__projection_distance)

    def getProjectorDistance(self):
        """!
        Retrieve the projector distance.

        @return: Projector distance as an integer.
        """ 
        return int(self.__projector_diatance)

    def getImgWidth(self):
        """!
        Retrieve the image width.

        @return: Image width as an integer.
        """ 
        return int(self.__img_width)

    def getImgHeight(self):
        """!
        Retrieve the image height.

        @return: Image height as an integer.
        """ 
        return int(self.__img_height)

    def getImgPath(self):
        """!
        Retrieve the image path.

        @return: Image path as a string.
        """ 
        return str(self.__img_path)

    def getGamma(self):
        """!
        Retrieve the gamma value.

        @return: Gamma value as a float.
        """ 
        return float(self.__gamma)

    def getOverlapWidth(self):
        """!
        Retrieve the overlap width.

        @return: Overlap width as an integer.
        """ 
        return int(self.__overlapWidth)

    def getSide(self):
        """!
        Retrieve the side of projection.

        @return: Side as a string.
        """ 
        return str(self.__side)

    def getIsDualMonitor(self):
        return bool(strtobool(self.__isDualMonitor))

    def getMonitorWidth(self):
        return int(self.__monitorWidth)

    @staticmethod
    def readConfigFile():
        """!
        Reads the configuration from a config.ini file and returns a Config object.

        @return: Config object with settings loaded from config.ini.
        """ 
        import configparser
        config = configparser.ConfigParser()
        config.read('config.ini')

        __img_path = config["settings"]["imagePath"]
        __img_width = config["settings"]["imageWidth"]
        __img_height = config["settings"]["imageHeight"]
        __projection_distance = config["settings"]["projectionDistance"]
        __projector_diatance = config["settings"]["projectorDistance"]
        __gamma = config["settings"]["gamma"]
        __overlapWidth = config["settings"]["overlapWidth"]
        __side = config["settings"]["side"]
        __isDualMonitor = config["settings"]["isDualMonitor"]
        __monitorWidth = config["settings"]["monitorWidth"]

        return Config(__projection_distance, __projector_diatance, __img_width, __img_height, __img_path, __gamma, __overlapWidth, __side, __isDualMonitor, __monitorWidth)

Updated by Mitsuki EIKI 4 months ago · 29 revisions