]>
Softwares of Agnibho - medscript.git/blob - setting.py
2 # Copyright (C) 2023 Dr. Agnibho Mondal
3 # This file is part of MedScript.
4 # MedScript is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5 # MedScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6 # You should have received a copy of the GNU General Public License along with MedScript. If not, see <https://www.gnu.org/licenses/>.
8 from PyQt6
. QtWidgets
import QWidget
, QMainWindow
, QFormLayout
, QHBoxLayout
, QPushButton
, QLabel
, QLineEdit
, QTextEdit
, QComboBox
, QCheckBox
, QStatusBar
, QMessageBox
, QFileDialog
9 from PyQt6
. QtGui
import QIcon
10 from PyQt6
. QtCore
import pyqtSignal
12 from config
import config
, config_file
, sign_available
14 class EditConfiguration ( QMainWindow
):
18 def select_directory ( self
):
19 d
= QFileDialog
. getExistingDirectory ( self
, "Select Directory" , config
[ "data_directory" ])
21 self
. input_directory
. setText ( d
)
22 def select_prescriber ( self
):
23 f
= QFileDialog
. getOpenFileName ( self
, "Select Prescriber" , config
[ "prescriber_directory" ], "JSON (*.json);; All Files (*)" )[ 0 ]
25 self
. input_prescriber
. setText ( f
)
27 f
= QFileDialog
. getOpenFileName ( self
, "Select Private Key" , os
. path
. expanduser ( "~" ), "PEM (*.pem);; All Files (*)" )[ 0 ]
29 self
. input_key
. setText ( f
)
30 def select_certificate ( self
):
31 f
= QFileDialog
. getOpenFileName ( self
, "Select Certificate" , os
. path
. expanduser ( "~" ), "PEM (*.pem);; All Files (*)" )[ 0 ]
33 self
. input_certificate
. setText ( f
)
34 def select_root ( self
):
35 f
= QFileDialog
. getOpenFileName ( self
, "Select Root Bundle" , os
. path
. expanduser ( "~" ), "PEM (*.pem);; All Files (*)" )[ 0 ]
37 self
. input_root
. setText ( f
)
41 self
. statusbar
. showMessage ( config_file
)
42 self
. input_directory
. setText ( self
. config
[ "data_directory" ])
43 self
. input_prescriber
. setText ( self
. config
[ "prescriber" ])
44 self
. input_newline
. setChecked ( bool ( self
. config
[ "preset_newline" ]))
45 self
. input_delimiter
. setCurrentText ( self
. config
[ "preset_delimiter" ])
46 self
. input_markdown
. setChecked ( bool ( self
. config
[ "markdown" ]))
48 self
. input_smime
. setChecked ( bool ( self
. config
[ "smime" ]))
49 self
. input_key
. setText ( self
. config
[ "private_key" ])
50 self
. input_certificate
. setText ( self
. config
[ "certificate" ])
51 self
. input_root
. setText ( self
. config
[ "root_bundle" ])
52 except Exception as e
:
53 QMessageBox
. critical ( self
, "Failed to load" , "Failed to load the data into the application." )
57 if ( QMessageBox
. StandardButton
. Yes
== QMessageBox
. question ( self
, "Confirm Save" , "This action will overwrite the previous configuration. Continue?" )):
59 self
. config
[ "data_directory" ]= self
. input_directory
. text ()
60 self
. config
[ "prescriber" ]= self
. input_prescriber
. text ()
61 self
. config
[ "preset_newline" ]= self
. input_newline
. isChecked ()
62 self
. config
[ "preset_delimiter" ]= self
. input_delimiter
. currentText ()
63 self
. config
[ "markdown" ]= self
. input_markdown
. isChecked ()
65 self
. config
[ "smime" ]= self
. input_smime
. isChecked ()
66 self
. config
[ "private_key" ]= self
. input_key
. text ()
67 self
. config
[ "certificate" ]= self
. input_certificate
. text ()
68 self
. config
[ "root_bundle" ]= self
. input_root
. text ()
69 with
open ( config_file
, "w" ) as f
:
70 f
. write ( json
. dumps ( self
. config
, indent
= 4 ))
71 QMessageBox
. information ( self
, "Saved" , "Configuration saved. Please restart MedScript." )
73 except Exception as e
:
74 QMessageBox
. critical ( self
, "Failed to save" , "Failed to save the data to the file." )
77 def __init__ ( self
, * args
, ** kwargs
):
78 super () .__ init
__ (* args
, ** kwargs
)
81 with
open ( config_file
) as f
:
82 self
. config
= json
. loads ( f
. read ())
83 except Exception as e
:
87 self
. setWindowTitle ( "MedScript" )
88 self
. setGeometry ( 200 , 200 , 300 , 200 )
91 layout
= QFormLayout ( widget
)
92 self
. input_directory
= QLineEdit ( self
)
93 btn_directory
= QPushButton ( "Select Directory" , self
)
94 btn_directory
. clicked
. connect ( self
. select_directory
)
95 layout_directory
= QHBoxLayout ()
96 layout_directory
. addWidget ( self
. input_directory
)
97 layout_directory
. addWidget ( btn_directory
)
98 layout
. addRow ( "Data Directory" , layout_directory
)
99 self
. input_prescriber
= QLineEdit ( self
)
100 btn_prescriber
= QPushButton ( "Select File" , self
)
101 btn_prescriber
. clicked
. connect ( self
. select_prescriber
)
102 layout_prescriber
= QHBoxLayout ()
103 layout_prescriber
. addWidget ( self
. input_prescriber
)
104 layout_prescriber
. addWidget ( btn_prescriber
)
105 layout
. addRow ( "Prescriber" , layout_prescriber
)
106 self
. input_newline
= QCheckBox ( "Add newline after preset" , self
)
107 layout
. addRow ( "Preset Newline" , self
. input_newline
)
108 self
. input_delimiter
= QComboBox ( self
)
109 self
. input_delimiter
. addItems ([ "," , ";" ])
110 layout
. addRow ( "Preset Delimiter" , self
. input_delimiter
)
111 self
. input_markdown
= QCheckBox ( "Enable markdown formatting" , self
)
112 layout
. addRow ( "Markdown" , self
. input_markdown
)
114 self
. input_smime
= QCheckBox ( "Enable digital signature (experimental)" , self
)
115 layout
. addRow ( "S/MIME" , self
. input_smime
)
116 self
. input_key
= QLineEdit ( self
)
117 btn_key
= QPushButton ( "Select File" , self
)
118 btn_key
. clicked
. connect ( self
. select_key
)
119 layout_key
= QHBoxLayout ()
120 layout_key
. addWidget ( self
. input_key
)
121 layout_key
. addWidget ( btn_key
)
122 layout
. addRow ( "Private Key" , layout_key
)
123 self
. input_certificate
= QLineEdit ( self
)
124 btn_certificate
= QPushButton ( "Select File" , self
)
125 btn_certificate
. clicked
. connect ( self
. select_certificate
)
126 layout_certificate
= QHBoxLayout ()
127 layout_certificate
. addWidget ( self
. input_certificate
)
128 layout_certificate
. addWidget ( btn_certificate
)
129 layout
. addRow ( "X509 Certificate" , layout_certificate
)
130 self
. input_root
= QLineEdit ( self
)
131 btn_root
= QPushButton ( "Select File" , self
)
132 btn_root
. clicked
. connect ( self
. select_root
)
133 layout_root
= QHBoxLayout ()
134 layout_root
. addWidget ( self
. input_root
)
135 layout_root
. addWidget ( btn_root
)
136 layout
. addRow ( "Root Bundle" , layout_root
)
137 button_save
= QPushButton ( "Save" )
138 button_save
. clicked
. connect ( self
. save
)
139 button_reset
= QPushButton ( "Reset" )
140 button_reset
. clicked
. connect ( self
. load
)
141 layout_btn
= QHBoxLayout ()
142 layout_btn
. addWidget ( button_save
)
143 layout_btn
. addWidget ( button_reset
)
144 layout
. addRow ( "" , layout_btn
)
146 self
. statusbar
= QStatusBar ()
147 self
. setStatusBar ( self
. statusbar
)
149 self
. setCentralWidget ( widget
)
150 self
. setWindowIcon ( QIcon ( os
. path
. join ( "resource" , "icon_medscript.ico" )))
154 class EditPrescriber ( QMainWindow
):
156 signal_save
= pyqtSignal ( str )
163 self
. file = config
[ "prescriber" ]
164 self
. statusbar
. showMessage ( self
. file )
165 with
open ( self
. file ) as data
:
166 self
. prescriber
= json
. loads ( data
. read ())
167 self
. input_name
. setText ( self
. prescriber
[ "name" ])
168 self
. input_qualification
. setText ( self
. prescriber
[ "qualification" ])
169 self
. input_registration
. setText ( self
. prescriber
[ "registration" ])
170 self
. input_address
. setText ( self
. prescriber
[ "address" ])
171 self
. input_contact
. setText ( self
. prescriber
[ "contact" ])
172 self
. input_extra
. setText ( self
. prescriber
[ "extra" ])
173 except Exception as e
:
174 QMessageBox
. critical ( self
, "Failed to load" , "Failed to load the data into the application." )
178 if ( QMessageBox
. StandardButton
. Yes
== QMessageBox
. question ( self
, "Confirm Save" , "This action will overwrite the previous information. Continue?" )):
180 self
. prescriber
[ "name" ]= self
. input_name
. text ()
181 self
. prescriber
[ "qualification" ]= self
. input_qualification
. text ()
182 self
. prescriber
[ "registration" ]= self
. input_registration
. text ()
183 self
. prescriber
[ "address" ]= self
. input_address
. toPlainText ()
184 self
. prescriber
[ "contact" ]= self
. input_contact
. text ()
185 self
. prescriber
[ "extra" ]= self
. input_extra
. toPlainText ()
186 with
open ( self
. file , "w" ) as f
:
187 f
. write ( json
. dumps ( self
. prescriber
, indent
= 4 ))
188 QMessageBox
. information ( self
, "Saved" , "Information saved." )
189 self
. signal_save
. emit ( self
. file )
191 except Exception as e
:
192 QMessageBox
. critical ( self
, "Failed to save" , "Failed to save the data to the file." )
195 def __init__ ( self
, * args
, ** kwargs
):
196 super () .__ init
__ (* args
, ** kwargs
)
198 self
. setWindowTitle ( "MedScript" )
199 self
. setGeometry ( 200 , 200 , 300 , 200 )
202 layout
= QFormLayout ( widget
)
203 self
. input_name
= QLineEdit ( self
)
204 layout
. addRow ( "Name" , self
. input_name
)
205 self
. input_qualification
= QLineEdit ( self
)
206 layout
. addRow ( "Qualification" , self
. input_qualification
)
207 self
. input_registration
= QLineEdit ( self
)
208 layout
. addRow ( "Registration" , self
. input_registration
)
209 self
. input_address
= QTextEdit ( self
)
210 layout
. addRow ( "Adress" , self
. input_address
)
211 self
. input_contact
= QLineEdit ( self
)
212 layout
. addRow ( "Contact" , self
. input_contact
)
213 self
. input_extra
= QTextEdit ( self
)
214 layout
. addRow ( "Extra" , self
. input_extra
)
215 button_save
= QPushButton ( "Save" )
216 button_save
. clicked
. connect ( self
. save
)
217 button_reset
= QPushButton ( "Reset" )
218 button_reset
. clicked
. connect ( self
. load
)
219 layout_btn
= QHBoxLayout ()
220 layout_btn
. addWidget ( button_save
)
221 layout_btn
. addWidget ( button_reset
)
222 layout
. addRow ( "" , layout_btn
)
224 self
. statusbar
= QStatusBar ()
225 self
. setStatusBar ( self
. statusbar
)
227 self
. setCentralWidget ( widget
)
228 self
. setWindowIcon ( QIcon ( os
. path
. join ( "resource" , "icon_medscript.ico" )))