Project

General

Profile

Support #1156 ยป SharedData.py

Sushaant Kathirvel Murugan, 10/31/2024 03:54 PM

 
1
import cv2 as cv
2
import numpy as np
3
import tkinter as tk
4
from tkinter import filedialog, messagebox
5
import os
6
from PIL import Image, ImageTk
7
import configparser
8

    
9
class SharedData:
10
    ##
11
    # @brief This class manages the parsing of the configuration file
12
    # When this function is called, it will share the config file information with other classes 
13
    def __init__(self):
14
    ##
15
    # @brief This constructor initializes the SharedData class
16
    # This constructor initializes the left_image, right_image, overlap_region, and leftSide variables
17
    # @return None
18
        self.left_image = None
19
        self.right_image = None
20
        self.overlap_region = 200
21
        self.leftSide = True
22

    
23
    def write_to_config(self, filename='config.ini'):
24
    ##
25
    # @brief This function saves current settings to a configuration file
26
    # This function writes the current values of overlap_region and leftSide to a configuration file. 
27
    # @param filename The name of the configuration fime. "config.ini" will be the default name if there is no input
28
    # @return None
29
    # @warning This function will overwrite the existing configuration file
30
        config = configparser.ConfigParser()
31
        config['DEFAULT'] = {
32
            'overlap_region': str(self.overlap_region),
33
            'leftSide': str(self.leftSide)
34
        }
35
        with open(filename, 'w') as configfile:
36
            config.write(configfile)
37

    
38
    def read_from_config(self, filename='config.ini'):
39

    
40
    ## 
41
    # @brief This function reads the settings from a configuration file
42
    # This function reads the values of overlap_region and leftSide from a configuration file. If the file does not exist, it will use the default values.
43
    # @param filename THe name of the configuration fime. "config.ini" will be the default name if there is no input
44
    # @return None
45
    # @warning If the configuration file contains wrong values, the program will not check
46
        config = configparser.ConfigParser()
47
        config.read(filename)
48
        self.overlap_region = config['DEFAULT'].getint('overlap_region', self.overlap_region)
49
        self.leftSide = config['DEFAULT'].getboolean('leftSide', self.leftSide)
    (1-1/1)