]>
Softwares of Agnibho - medscript.git/blob - plugin.py
da9552bc0cbd060d3801ae63f7a04a7c8219aefd
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/>.
9 from PyQt6
. QtWidgets
import QMessageBox
, QInputDialog
, QFileDialog
11 from config
import config
19 if ( config
[ "enable_plugin" ]):
23 plugin_list
= glob ( os
. path
. join ( config
[ "plugin_directory" ], "*" ))
27 spec
= importlib
. util
. spec_from_file_location ( os
. path
. basename ( i
), os
. path
. join ( i
, "main.py" ))
28 mod
= importlib
. util
. module_from_spec ( spec
)
29 spec
. loader
. exec_module ( mod
)
30 self
. plugins
. append ( mod
)
31 except Exception as e
:
34 def get_name ( self
, mod
):
37 except Exception as e
:
42 for i
in self
. plugins
:
43 if ( hasattr ( i
, "run" ) and callable ( i
. run
)):
44 cmds
. append ([ i
, self
. get_name ( i
)])
47 def new ( self
, prescription
):
48 for i
in self
. plugins
:
50 if ( hasattr ( i
, "new" ) and callable ( i
. new
)):
51 if ( hasattr ( i
, "input" ) and callable ( i
. input )):
53 msg
= i
. new ( prescription
)
55 QMessageBox
. information ( None , "Information" , msg
)
56 except Exception as e
:
59 def open ( self
, prescription
):
60 for i
in self
. plugins
:
62 if ( hasattr ( i
, "open" ) and callable ( i
. open )):
63 if ( hasattr ( i
, "input" ) and callable ( i
. input )):
65 msg
= i
. open ( prescription
)
67 QMessageBox
. information ( None , "Information" , msg
)
68 except Exception as e
:
71 def save ( self
, prescription
):
72 for i
in self
. plugins
:
74 if ( hasattr ( i
, "save" ) and callable ( i
. save
)):
75 if ( hasattr ( i
, "input" ) and callable ( i
. input )):
77 msg
= i
. save ( prescription
)
79 QMessageBox
. information ( None , "Information" , msg
)
80 except Exception as e
:
83 def refresh ( self
, prescription
):
84 for i
in self
. plugins
:
86 if ( hasattr ( i
, "refresh" ) and callable ( i
. refresh
)):
87 if ( hasattr ( i
, "input" ) and callable ( i
. input )):
89 msg
= i
. refresh ( prescription
)
91 QMessageBox
. information ( None , "Information" , msg
)
92 except Exception as e
:
95 def run ( self
, module
, prescription
):
97 if ( hasattr ( module
, "run" ) and callable ( module
. run
)):
98 if ( hasattr ( module
, "input" ) and callable ( module
. input )):
99 module
. input ( self
. input ())
100 if ( hasattr ( module
, "fileopen" ) and callable ( module
. fileopen
)):
101 module
. fileopen ( QFileDialog
. getOpenFileName ()[ 0 ])
102 if ( hasattr ( module
, "filesave" ) and callable ( module
. filesave
)):
103 module
. filesave ( QFileDialog
. getSaveFileName ()[ 0 ])
104 msg
= module
. run ( prescription
)
106 QMessageBox
. information ( None , "Information" , msg
)
107 except Exception as e
:
112 text
, ok
= QInputDialog
. getText ( None , "User input" , "Enter text:" )
117 except Exception as e
: