-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathAppconfig.py
More file actions
135 lines (115 loc) · 4.21 KB
/
Appconfig.py
File metadata and controls
135 lines (115 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# =========================================================================
# FILE: Appconfig.py
#
# USAGE: ---
#
# DESCRIPTION: This define all configuration used in Application.
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Fahim Khan, fahim.elex@gmail.com
# MODIFIED: Rahul Paknikar, rahulp@iitb.ac.in
# Sumanto Kar, sumantokar@iitb.ac.in
# ORGANIZATION: eSim Team at FOSSEE, IIT Bombay
# CREATED: Tuesday 24 February 2015
# REVISION: Thursday 29 June 2023
# =========================================================================
from PyQt5 import QtWidgets
import os
import json
from configparser import ConfigParser
class Appconfig(QtWidgets.QWidget):
"""
All configuration goes here.
May change in future for code optimization.
This class also contains function for
- Printing error.
- Showing warnings.
- Displaying information.
"""
# Home directory
if os.name == 'nt':
user_home = os.path.join('library', 'config')
else:
user_home = os.path.expanduser('~')
try:
file = open(os.path.join(
user_home, ".esim/workspace.txt"), 'r'
)
workspace_check, home = file.readline().split(' ', 1)
file.close()
except IOError:
home = os.path.join(os.path.expanduser("~"), "eSim-Workspace")
workspace_check = 0
default_workspace = {"workspace": home}
# Current Project detail
current_project = {"ProjectName": None}
# Current Subcircuit detail
current_subcircuit = {"SubcircuitName": None}
# Workspace detail
workspace_text = "eSim stores your project in a folder called "
workspace_text += "eSim-Workspace. You can choose a different "
workspace_text += "workspace folder to use for this session."
procThread_list = []
proc_dict = {} # hold pids of all external windows of the current project
dock_dict = {} # holds all dockwidgets
dictPath = {"path": os.path.join(
default_workspace["workspace"], ".projectExplorer.txt")
}
noteArea = {"Note": []}
parser_esim = ConfigParser()
parser_esim.read(
os.path.join(user_home, '.esim', 'config.ini')
)
# Try catch added, since eSim cannot be accessed under parser for Win10
try:
modelica_map_json = parser_esim.get('eSim', 'MODELICA_MAP_JSON')
except BaseException as e:
print("Cannot access Modelica map file --- .esim folder")
print(str(e))
try:
project_explorer = json.load(open(dictPath["path"]))
except BaseException:
project_explorer = {}
process_obj = []
def __init__(self):
super(Appconfig, self).__init__()
# Application Details
self._APPLICATION = 'eSim'
self._VERSION = '2.5'
self._AUTHOR = 'Fahim'
self._REVISION = 'Rahul, Sumanto'
# Application geometry setting
self._app_xpos = 100
self._app_ypos = 100
self._app_width = 600
self._app_heigth = 400
def print_info(self, info):
self.noteArea['Note'].append('[INFO]: ' + info)
def print_warning(self, warning):
self.noteArea['Note'].append('[WARNING]: ' + warning)
def print_error(self, error):
self.noteArea['Note'].append('[ERROR]: ' + error)
def save_current_project(self):
try:
path = os.path.join(self.user_home, ".esim", "last_project.json")
with open(path, "w") as f:
json.dump(self.current_project, f)
except Exception as e:
print("Failed to save current project:", str(e))
def load_last_project(self):
try:
path = os.path.join(self.user_home, ".esim", "last_project.json")
with open(path, "r") as f:
data = json.load(f)
project_path = data.get("ProjectName", None)
if project_path and os.path.exists(project_path):
self.current_project["ProjectName"] = project_path
return project_path
else:
print("Project path does not exist: ", project_path)
except Exception as e:
print("Error: ", str(e))
return None