Skip to content

Commit 717bb15

Browse files
author
Agnibho Mondal
committed
Major code rearrangement
1 parent ad3c926 commit 717bb15

10 files changed

+627
-293
lines changed

__main__.py

+20-132
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,29 @@
11
#! /usr/bin/python3
22

3-
# DDStorm
4-
# -------
5-
# Copyright (c) 2015 Agnibho Mondal
6-
# All rights reserved
3+
'''
4+
Start the application
5+
'''
6+
'''
7+
Copyright (c) 2015 Agnibho Mondal
8+
All rights reserved
79
8-
# This file is part of DDStorm.
10+
This file is part of DDStorm.
911
10-
# DDStorm is free software: you can redistribute it and/or modify
11-
# it under the terms of the GNU General Public License as published by
12-
# the Free Software Foundation, either version 3 of the License, or
13-
# (at your option) any later version.
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.
1416
15-
# DDStorm is distributed in the hope that it will be useful,
16-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18-
# GNU General Public License for more details.
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.
1921
20-
# You should have received a copy of the GNU General Public License
21-
# along with DDStorm. If not, see <http://www.gnu.org/licenses/>.
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+
'''
2225

23-
import sys, time, subprocess
24-
from PyQt4 import QtGui, QtCore
25-
from _symptoms import Symptoms
26-
from _differentials import Differentials
27-
from ddstorm import DDStorm
28-
from conf import Conf
29-
from _extras import *
30-
from const import *
31-
32-
conf=False
33-
34-
class Content(QtGui.QWidget):
35-
change=QtCore.pyqtSignal()
36-
def __init__(self):
37-
super(Content, self).__init__()
38-
self.dd=DDStorm(True,conf)
39-
if(not self.dd.compiler.clean):
40-
ret=QtGui.QMessageBox.warning(self, "Compilation Error", "Error was encountered while compiling the Knowledgebase.", "Ignore", "View Log")
41-
if(ret==1):
42-
x_logfile()
43-
self.initUI()
44-
def initUI(self):
45-
global conf
46-
47-
grid=QtGui.QGridLayout()
48-
self.setLayout(grid)
49-
50-
self.symp=Symptoms(self.dd.symptoms())
51-
self.symp.setFrameShape(QtGui.QFrame.StyledPanel)
52-
self.symp.changed.connect(self.update)
53-
54-
self.diff=Differentials()
55-
self.diff.setFrameShape(QtGui.QFrame.StyledPanel)
56-
57-
grid.addWidget(self.symp, 0, 0)
58-
grid.addWidget(self.diff, 0, 1)
59-
grid.setColumnStretch(0, 1)
60-
grid.setColumnStretch(1, 1)
61-
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create("Cleanlooks"))
62-
def update(self, data):
63-
self.diff.update(self.dd.dd(data))
64-
self.change.emit()
65-
66-
class Window(QtGui.QMainWindow):
67-
def __init__(self):
68-
super(Window, self).__init__()
69-
self.initUI()
70-
def initUI(self):
71-
global conf
72-
self.con=Content()
73-
self.sett=SettingsDialog(conf)
74-
if(conf.get("status_message")=="on"):
75-
self.con.change.connect(self.showStatus)
76-
77-
menu=self.menuBar()
78-
menuFile=menu.addMenu("&File")
79-
menuFile.addAction("&Save").triggered.connect(self.savefile)
80-
menuFile.addAction("E&xit").triggered.connect(self.close)
81-
menuEdit=menu.addMenu("&Edit")
82-
menuEdit.addAction("&Add").triggered.connect(self.con.symp.addItem)
83-
menuEdit.addAction("&Browse Symptoms").triggered.connect(self.con.symp.browseSymptoms)
84-
rmAction=QtGui.QAction("&Remove", self)
85-
rmAction.setShortcut("Delete")
86-
rmAction.triggered.connect(self.con.symp.remove)
87-
menuEdit.addAction(rmAction)
88-
menuEdit.addAction("&Clear All").triggered.connect(self.con.symp.removeAll)
89-
menuTool=menu.addMenu("&Tools")
90-
menuTool.addAction("&Library").triggered.connect(x_lib)
91-
menuTool.addAction("&Settings").triggered.connect(self.settings)
92-
menuTool.addAction("&View Log").triggered.connect(x_logfile)
93-
menuHelp=menu.addMenu("&Help")
94-
menuHelp.addAction("&Help").triggered.connect(x_help)
95-
menuHelp.addAction("&About").triggered.connect(self.about)
96-
97-
self.setCentralWidget(self.con)
98-
self.status=self.statusBar()
99-
self.setGeometry(200, 200, 600, 400)
100-
self.setWindowTitle("D/D Storm")
101-
self.setWindowIcon(QtGui.QIcon("icons/icon.png"))
102-
self.showMaximized()
103-
self.con.symp.new.setFocus()
104-
def showStatus(self):
105-
if(self.con.symp.getList() and self.con.diff.getList()):
106-
self.status.showMessage(str(len(self.con.diff.getList()))+" differential diagnosis for "+str(len(self.con.symp.getList()))+" symptom(s).")
107-
else:
108-
self.status.showMessage("")
109-
def savefile(self):
110-
x_save(self, self.con.symp.getList(), self.con.diff.getList())
111-
def settings(self):
112-
self.sett.exec_()
113-
def about(self):
114-
QtGui.QMessageBox.about(self, "About", "<h1>DDStorm</h1>\nBrainstorm Medicine")
115-
116-
def main():
117-
app=QtGui.QApplication(sys.argv)
118-
119-
global conf
120-
conf=Conf()
121-
if(conf.get("clean_log")=="yes"):
122-
open(LOG_FILE, "w").close()
123-
if(conf.get("splash_screen")=="yes"):
124-
ss=True
125-
else:
126-
ss=False
127-
if(ss):
128-
splash=QtGui.QSplashScreen(QtGui.QPixmap("icons/splash.png"))
129-
splash.show()
130-
time.sleep(0.1)
131-
app.processEvents()
132-
splash.showMessage("Loading...")
133-
134-
w=Window()
135-
if(ss):
136-
splash.finish(w)
137-
138-
sys.exit(app.exec_())
26+
import gui
13927

14028
if(__name__=="__main__"):
141-
main()
29+
gui.main()

_differentials.py

-47
This file was deleted.

alias.py

+41-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
#! /usr/bin/python3
22

3-
# DDStorm
4-
# -------
5-
# Copyright (c) 2015 Agnibho Mondal
6-
# All rights reserved
3+
''' This module handles the aliases of the symptoms. '''
4+
'''
5+
Copyright (c) 2015 Agnibho Mondal
6+
All rights reserved
77
8-
# This file is part of DDStorm.
8+
This file is part of DDStorm.
99
10-
# DDStorm is free software: you can redistribute it and/or modify
11-
# it under the terms of the GNU General Public License as published by
12-
# the Free Software Foundation, either version 3 of the License, or
13-
# (at your option) any later version.
10+
DDStorm is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
1414
15-
# DDStorm is distributed in the hope that it will be useful,
16-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18-
# GNU General Public License for more details.
15+
DDStorm is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License for more details.
1919
20-
# You should have received a copy of the GNU General Public License
21-
# along with DDStorm. If not, see <http://www.gnu.org/licenses/>.
20+
You should have received a copy of the GNU General Public License
21+
along with DDStorm. If not, see <http://www.gnu.org/licenses/>.
22+
'''
2223

23-
import sys, os
24+
import sys
25+
import os
2426
from fnmatch import fnmatch
27+
2528
from conf import Conf
2629
from const import *
2730

2831
class Alias:
32+
''' Provides the class to handle symptom aliases '''
33+
2934
def __init__(self, conf=False):
35+
'''
36+
Initiates the alias object
37+
Accepts a Conf object as parameter
38+
'''
3039
self.data={}
3140
if(conf):
3241
self.conf=conf
@@ -35,19 +44,25 @@ def __init__(self, conf=False):
3544
self.compile()
3645

3746
def compile(self):
47+
''' Compile the plaintext index files to a program usable format '''
48+
# Loop over the alias files
3849
for path, subdirs, files in os.walk(self.conf.get("alias_path")):
3950
for name in files:
4051
if(fnmatch(name, "*.txt")):
52+
# Open the *.txt files
4153
with open(self.conf.get("alias_path")+name, "r") as f:
4254
for line in f:
55+
# Ignore lines starting with #
4356
line=line.rstrip().split("#")[0]
4457
if(len(line)==0):
4558
pass
4659
else:
4760
terms=[]
61+
# Split words separated by ; and add to the terms
4862
for i in line.split(";"):
4963
if(i.strip()):
5064
terms.append(i.strip())
65+
# If alias present, add terms to the data
5166
if(len(terms)==2):
5267
self.data[terms[-1]]=terms[0]
5368
elif(len(terms)>2):
@@ -56,12 +71,22 @@ def compile(self):
5671
self.data[i]=t
5772

5873
def get(self, term):
74+
'''
75+
Return the alias of the queried symptom
76+
77+
Parameter:
78+
term - Queried string
79+
80+
Return value:
81+
String containing the alias of the term
82+
'''
5983
if(term in self.data):
6084
return self.data[term]
6185
else:
6286
return term
6387

6488
def main():
89+
''' Print the alias of the command line argument '''
6590
a=Alias()
6691
if(len(sys.argv)>1):
6792
print(a.get(sys.argv[1]))

0 commit comments

Comments
 (0)