]> Softwares of Agnibho - ddstorm.git/blob - _extras.py
First commit
[ddstorm.git] / _extras.py
1 # DDStorm
2 # -------
3 # Copyright (c) 2015 Agnibho Mondal
4 # All rights reserved
5
6 # This file is part of DDStorm.
7
8 # DDStorm is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12
13 # DDStorm is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with DDStorm. If not, see <http://www.gnu.org/licenses/>.
20
21 import subprocess, os
22 from PyQt4 import QtGui, QtCore
23 from const import *
24
25 def x_settings():
26 subprocess.Popen(["xdg-open", CONF_FILE])
27
28 def x_lib():
29 if(os.path.isfile(CONF_FILE)):
30 with open(CONF_FILE) as conf:
31 for line in conf:
32 if(line.startswith("library_path=")):
33 library_path=line[13:-1]
34 if(os.path.isdir(library_path)):
35 subprocess.Popen(["xdg-open", library_path])
36
37 def x_save(w, symp, diff):
38 fname=QtGui.QFileDialog.getSaveFileName(w, "Save File", "~", "HTML files('*.html')")
39 if(not fname.endswith(".html")):
40 fname=fname+".html"
41 with open(fname, "w") as f:
42 print("<!DOCTYPE html><html><head><title>Differential Diagnosis</title></head>", file=f)
43 print("<body><h1>Differential Diagnosis</h1>", file=f)
44 print("<table style='width:100%'>", file=f)
45 print("<tr><th>Symptoms</th><th>Diffrential Diagnosis</th></tr>", file=f)
46 print("<tr><td style='vertical-align:text-top'><ol>", file=f)
47 for s in symp:
48 print("<li>"+s+"</li>", file=f)
49 print("</ol></td><td style='vertical-align:text-top'><ol>", file=f)
50 for d in diff:
51 print("<li>"+d+"</li>", file=f)
52 print("</ol></td></tr></table></body></html>", file=f)
53
54 def x_help():
55 if(os.path.isfile(HELP_FILE)):
56 subprocess.Popen(["xdg-open", HELP_FILE])
57 else:
58 subprocess.Popen(["xdg-open", "http://www.agnibho.com"])
59
60 def x_logfile():
61 subprocess.Popen(["xdg-open", LOG_FILE])
62
63 class SettingsDialog(QtGui.QDialog):
64 def __init__(self, conf):
65 super(SettingsDialog, self).__init__()
66 self.setWindowTitle("Settings")
67 self.conf=conf
68 self.initUI()
69 def initUI(self):
70 self.lpLabel=QtGui.QLabel("Libary Path:")
71 self.lpEdit=QtGui.QLineEdit(self.conf.get("library_path"))
72 self.lpBrowse=QtGui.QPushButton("Browse")
73 self.lpBrowse.clicked.connect(self.lpUpdate)
74 self.mpLabel=QtGui.QLabel("Module Path:")
75 self.mpEdit=QtGui.QLineEdit(self.conf.get("module_path"))
76 self.mpBrowse=QtGui.QPushButton("Browse")
77 self.mpBrowse.clicked.connect(self.mpUpdate)
78 self.splash=QtGui.QCheckBox("Show Splash Screen")
79 if(self.conf.get("splash_screen")=="yes"):
80 self.splash.setChecked(True)
81 self.clean=QtGui.QCheckBox("Clean Log on Exit")
82 if(self.conf.get("clean_log")=="yes"):
83 self.clean.setChecked(True)
84 self.status=QtGui.QCheckBox("Show Status Message")
85 if(self.conf.get("status_message")=="on"):
86 self.status.setChecked(True)
87 self.ok=QtGui.QPushButton("Ok")
88 self.ok.clicked.connect(self.save)
89 self.cancel=QtGui.QPushButton("Cancel")
90 self.cancel.clicked.connect(self.close)
91 self.default=QtGui.QPushButton("Default")
92 self.default.clicked.connect(self.reset)
93
94 ctrl=QtGui.QHBoxLayout()
95 ctrl.addWidget(self.ok)
96 ctrl.addWidget(self.cancel)
97 ctrl.addWidget(self.default)
98 layout=QtGui.QGridLayout(self)
99 layout.addWidget(self.lpLabel, 0, 0)
100 layout.addWidget(self.lpEdit, 0, 1)
101 layout.addWidget(self.lpBrowse, 0, 2)
102 layout.addWidget(self.mpLabel, 1, 0)
103 layout.addWidget(self.mpEdit, 1, 1)
104 layout.addWidget(self.mpBrowse, 1, 2)
105 layout.addWidget(self.splash, 2, 0)
106 layout.addWidget(self.clean, 3, 0)
107 layout.addWidget(self.status, 4, 0)
108 layout.addLayout(ctrl, 5, 1)
109
110 self.cancel.setFocus()
111
112 def lpUpdate(self):
113 self.lpEdit.setText(self.getFolder())
114 def cpUpdate(self):
115 self.cpEdit.setText(self.getFolder())
116 def mpUpdate(self):
117 self.mpEdit.setText(self.getFolder())
118
119 def getFolder(self):
120 dn=QtGui.QFileDialog.getExistingDirectory()
121 if(dn.startswith(QtCore.QDir.currentPath())):
122 dn="."+dn[len(QtCore.QDir.currentPath()):]+"/"
123 else:
124 dn=dn+"/"
125 return dn
126
127 def save(self):
128 self.conf.set("library_path", self.lpEdit.text())
129 self.conf.set("class_path", self.cpEdit.text())
130 self.conf.set("module_path", self.mpEdit.text())
131 if(self.splash.isChecked()):
132 self.conf.set("splash_screen", "yes")
133 else:
134 self.conf.set("splash_screen", "no")
135 if(self.clean.isChecked()):
136 self.conf.set("clean_log", "yes")
137 else:
138 self.conf.set("clean_log", "no")
139 if(self.status.isChecked()):
140 self.conf.set("status_message", "on")
141 else:
142 self.conf.set("status_message", "off")
143 QtGui.QMessageBox.information(self, "Restart required", "Some settings takes effect only after restarting DDStorm")
144 self.close()
145 self.conf.write()
146
147 def reset(self):
148 self.conf.default()
149 self.lpEdit.setText(self.conf.get("library_path"))
150 self.cpEdit.setText(self.conf.get("class_path"))
151 self.mpEdit.setText(self.conf.get("module_path"))
152 if(self.conf.get("splash_screen")=="yes"):
153 self.splash.setChecked(True)
154 else:
155 self.splash.setChecked(False)
156 if(self.conf.get("clean_log")=="yes"):
157 self.clean.setChecked(True)
158 else:
159 self.clean.setChecked(False)
160 if(self.conf.get("status_message")=="on"):
161 self.status.setChecked(True)
162 else:
163 self.status.setChecked(False)