]> Softwares of Agnibho - ddstorm.git/blob - gui.py
Added documentation
[ddstorm.git] / gui.py
1 #! /usr/bin/python3
2
3 '''
4 This module provides the main graphical user interface for DDStorm
5 '''
6 '''
7 Copyright (c) 2015 Agnibho Mondal
8 All rights reserved
9
10 This file is part of DDStorm.
11
12 DDStorm is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 DDStorm is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with DDStorm. If not, see <http://www.gnu.org/licenses/>.
24 '''
25
26 import sys
27 import time
28 import subprocess
29
30 from PyQt5 import QtWidgets, QtGui, QtCore
31
32 from panes import Symptoms, Differentials
33 from ddstorm import DDStorm
34 from conf import Conf
35 from extras import *
36 from const import *
37
38 conf=False
39
40 class Content(QtWidgets.QWidget):
41 '''
42 Provides the main content widget. Contains the sysmptoms and
43 the diagnosis panes. Also creates the DDStorm object and performs
44 the main operation.
45 '''
46
47 # Signal to detect when
48 change=QtCore.pyqtSignal()
49
50 def __init__(self):
51 ''' Initiate the content widget '''
52 super(Content, self).__init__()
53
54 # Create DDStorm object with the global configuration
55 self.dd=DDStorm(True, conf)
56
57 # Show warning if any error happened during data compilation
58 if(not self.dd.compiler.is_clean()):
59 ret=QtWidgets.QMessageBox.warning(self, "Compilation Error", "Error was encountered while compiling the Knowledgebase.", "Ignore", "View Log")
60 if(ret==1):
61 x_logfile()
62
63 self.initUI()
64
65 def initUI(self):
66 ''' Create the user interface of the widget '''
67
68 global conf
69
70 grid=QtWidgets.QGridLayout()
71 self.setLayout(grid)
72
73 self.symp=Symptoms(self.dd.symptoms())
74 self.symp.setFrameShape(QtWidgets.QFrame.StyledPanel)
75 self.symp.changed.connect(self.update)
76
77 self.diff=Differentials()
78 self.diff.setFrameShape(QtWidgets.QFrame.StyledPanel)
79
80 grid.addWidget(self.symp, 0, 0)
81 grid.addWidget(self.diff, 0, 1)
82 grid.setColumnStretch(0, 1)
83 grid.setColumnStretch(1, 1)
84 QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create("Cleanlooks"))
85
86 def update(self, data):
87 ''' Update the inteface with refreshed information '''
88 self.diff.update(self.dd.dd(data))
89 self.change.emit()
90
91
92 class Window(QtWidgets.QMainWindow):
93 '''
94 Provides main application window. Acts as a container for the
95 content widget. Also contains the menubar and the status bar.
96 '''
97
98 def __init__(self):
99 ''' Initiate the main window '''
100 super(Window, self).__init__()
101 self.initUI()
102
103 def initUI(self):
104 ''' Create the user interface '''
105 global conf
106 self.con=Content()
107 self.sett=SettingsDialog(conf)
108 if(conf.get("status_message")=="on"):
109 self.con.change.connect(self.showStatus)
110
111 menu=self.menuBar()
112 menuFile=menu.addMenu("&File")
113 menuFile.addAction("&Save").triggered.connect(self.savefile)
114 menuFile.addAction("E&xit").triggered.connect(self.close)
115 menuEdit=menu.addMenu("&Edit")
116 menuEdit.addAction("&Add").triggered.connect(self.con.symp.addItem)
117 menuEdit.addAction("&Browse Symptoms").triggered.connect(self.con.symp.browseSymptoms)
118 rmAction=QtWidgets.QAction("&Remove", self)
119 rmAction.setShortcut("Delete")
120 rmAction.triggered.connect(self.con.symp.remove)
121 menuEdit.addAction(rmAction)
122 menuEdit.addAction("&Clear All").triggered.connect(self.con.symp.removeAll)
123 menuTool=menu.addMenu("&Tools")
124 menuTool.addAction("&Library").triggered.connect(x_lib)
125 menuTool.addAction("&Settings").triggered.connect(self.settings)
126 menuTool.addAction("&View Log").triggered.connect(x_logfile)
127 menuHelp=menu.addMenu("&Help")
128 menuHelp.addAction("&Help").triggered.connect(x_help)
129 menuHelp.addAction("&About").triggered.connect(self.about)
130
131 self.setCentralWidget(self.con)
132 self.status=self.statusBar()
133 self.setGeometry(200, 200, 600, 400)
134 self.setWindowTitle("D/D Storm")
135 self.setWindowIcon(QtGui.QIcon("icons/icon.png"))
136 self.showMaximized()
137 self.con.symp.new.setFocus()
138
139 def showStatus(self):
140 ''' Show status message '''
141 if(self.con.symp.getList() and self.con.diff.getList()):
142 self.status.showMessage(str(len(self.con.diff.getList()))+" differential diagnosis for "+str(len(self.con.symp.getList()))+" symptom(s).")
143 else:
144 self.status.showMessage("")
145
146 def savefile(self):
147 ''' Save data to a file '''
148 x_save(self, self.con.symp.getList(), self.con.diff.getList())
149
150 def settings(self):
151 ''' Open the settings dialog '''
152 self.sett.exec_()
153
154 def about(self):
155 ''' Show information about this application '''
156 QtWidgets.QMessageBox.about(self, "About", "<h1>DDStorm</h1>\nBrainstorm Medicine")
157
158
159 def main():
160 ''' Start the main application interface '''
161 app=QtWidgets.QApplication(sys.argv)
162
163 # Initiate the global configuration
164 global conf
165 conf=Conf()
166
167 # Clean the log file
168 if(conf.get("clean_log")=="yes"):
169 open(LOG_FILE, "w").close()
170
171 # Show splash-screen
172 if(conf.get("splash_screen")=="yes"):
173 ss=True
174 else:
175 ss=False
176 if(ss):
177 splash=QtWidgets.QSplashScreen(QtWidgets.QPixmap("icons/splash.png"))
178 splash.show()
179 time.sleep(0.1)
180 app.processEvents()
181 splash.showMessage("Loading...")
182
183 # Create main window
184 w=Window()
185 if(ss):
186 splash.finish(w)
187
188 # Start application
189 sys.exit(app.exec_())
190
191 if(__name__=="__main__"):
192 main()