]>
Softwares of Agnibho - ddstorm.git/blob - extras.py
2 This module provides some extra functionalities to the main window.
5 Copyright (c) 2015 Agnibho Mondal
8 This file is part of DDStorm.
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.
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.
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/>.
26 from PyQt5
import QtWidgets
, QtCore
30 ''' Open the configuration file '''
31 subprocess
.Popen(["xdg-open", CONF_FILE
])
34 ''' Open the library path '''
35 if(os
.path
.isfile(CONF_FILE
)):
36 with
open(CONF_FILE
) as conf
:
38 if(line
.startswith("library_path=")):
39 library_path
=line
[13:-1]
40 if(os
.path
.isdir(library_path
)):
41 subprocess
.Popen(["xdg-open", library_path
])
43 def x_save(w
, symp
, diff
):
44 ''' Save data to a file '''
45 fname
=QtWidgets
.QFileDialog
.getSaveFileName(w
, "Save File", "~", "HTML files('*.html')")
46 if(not fname
.endswith(".html")):
48 with
open(fname
, "w") as f
:
49 print("<!DOCTYPE html><html><head><title>Differential Diagnosis</title></head>", file=f
)
50 print("<body><h1>Differential Diagnosis</h1>", file=f
)
51 print("<table style='width:100%'>", file=f
)
52 print("<tr><th>Symptoms</th><th>Diffrential Diagnosis</th></tr>", file=f
)
53 print("<tr><td style='vertical-align:text-top'><ol>", file=f
)
55 print("<li>"+s
+"</li>", file=f
)
56 print("</ol></td><td style='vertical-align:text-top'><ol>", file=f
)
58 print("<li>"+d
+"</li>", file=f
)
59 print("</ol></td></tr></table></body></html>", file=f
)
63 if(os
.path
.isfile(HELP_FILE
)):
64 subprocess
.Popen(["xdg-open", HELP_FILE
])
66 subprocess
.Popen(["xdg-open", "http://www.agnibho.com"])
70 subprocess
.Popen(["xdg-open", LOG_FILE
])
73 class SettingsDialog(QtWidgets
.QDialog
):
75 Provides a dialog box to configure application settings with a
76 graphical user interface.
79 def __init__(self
, conf
):
80 ''' Initiate the dialog '''
81 super(SettingsDialog
, self
).__init
__()
82 self
.setWindowTitle("Settings")
87 ''' Initiate the user interface '''
88 self
.lpLabel
=QtWidgets
.QLabel("Libary Path:")
89 self
.lpEdit
=QtWidgets
.QLineEdit(self
.conf
.get("library_path"))
90 self
.lpBrowse
=QtWidgets
.QPushButton("Browse")
91 self
.lpBrowse
.clicked
.connect(self
.lpUpdate
)
92 self
.cpLabel
=QtWidgets
.QLabel("Custom Path:")
93 self
.cpEdit
=QtWidgets
.QLineEdit(self
.conf
.get("custom_path"))
94 self
.cpBrowse
=QtWidgets
.QPushButton("Browse")
95 self
.cpBrowse
.clicked
.connect(self
.cpUpdate
)
96 self
.mpLabel
=QtWidgets
.QLabel("Module Path:")
97 self
.mpEdit
=QtWidgets
.QLineEdit(self
.conf
.get("module_path"))
98 self
.mpBrowse
=QtWidgets
.QPushButton("Browse")
99 self
.mpBrowse
.clicked
.connect(self
.mpUpdate
)
100 self
.splash
=QtWidgets
.QCheckBox("Show Splash Screen")
101 if(self
.conf
.get("splash_screen")=="yes"):
102 self
.splash
.setChecked(True)
103 self
.clean
=QtWidgets
.QCheckBox("Clean Log on Exit")
104 if(self
.conf
.get("clean_log")=="yes"):
105 self
.clean
.setChecked(True)
106 self
.status
=QtWidgets
.QCheckBox("Show Status Message")
107 if(self
.conf
.get("status_message")=="on"):
108 self
.status
.setChecked(True)
109 self
.ok
=QtWidgets
.QPushButton("Ok")
110 self
.ok
.clicked
.connect(self
.save
)
111 self
.cancel
=QtWidgets
.QPushButton("Cancel")
112 self
.cancel
.clicked
.connect(self
.close
)
113 self
.default
=QtWidgets
.QPushButton("Default")
114 self
.default
.clicked
.connect(self
.reset
)
116 ctrl
=QtWidgets
.QHBoxLayout()
117 ctrl
.addWidget(self
.ok
)
118 ctrl
.addWidget(self
.cancel
)
119 ctrl
.addWidget(self
.default
)
120 layout
=QtWidgets
.QGridLayout(self
)
121 layout
.addWidget(self
.lpLabel
, 0, 0)
122 layout
.addWidget(self
.lpEdit
, 0, 1)
123 layout
.addWidget(self
.lpBrowse
, 0, 2)
124 layout
.addWidget(self
.cpLabel
, 1, 0)
125 layout
.addWidget(self
.cpEdit
, 1, 1)
126 layout
.addWidget(self
.cpBrowse
, 1, 2)
127 layout
.addWidget(self
.mpLabel
, 2, 0)
128 layout
.addWidget(self
.mpEdit
, 2, 1)
129 layout
.addWidget(self
.mpBrowse
, 2, 2)
130 layout
.addWidget(self
.splash
, 3, 0)
131 layout
.addWidget(self
.clean
, 4, 0)
132 layout
.addWidget(self
.status
, 5, 0)
133 layout
.addLayout(ctrl
, 6, 1)
135 self
.cancel
.setFocus()
138 ''' Updates the library path '''
139 self
.lpEdit
.setText(self
.getFolder())
142 ''' Updates the custom path '''
143 self
.cpEdit
.setText(self
.getFolder())
146 ''' Updates the module path '''
147 self
.mpEdit
.setText(self
.getFolder())
150 ''' Returns the selected directory '''
151 dn
=QtWidgets
.QFileDialog
.getExistingDirectory()
152 if(dn
.startswith(QtCore
.QDir
.currentPath())):
153 dn
="."+dn
[len(QtCore
.QDir
.currentPath()):]+"/"
159 ''' Saves the configuration to disk '''
160 self
.conf
.set("library_path", self
.lpEdit
.text())
161 self
.conf
.set("custom_path", self
.cpEdit
.text())
162 self
.conf
.set("module_path", self
.mpEdit
.text())
163 if(self
.splash
.isChecked()):
164 self
.conf
.set("splash_screen", "yes")
166 self
.conf
.set("splash_screen", "no")
167 if(self
.clean
.isChecked()):
168 self
.conf
.set("clean_log", "yes")
170 self
.conf
.set("clean_log", "no")
171 if(self
.status
.isChecked()):
172 self
.conf
.set("status_message", "on")
174 self
.conf
.set("status_message", "off")
175 QtWidgets
.QMessageBox
.information(self
, "Restart required", "Some settings takes effect only after restarting DDStorm")
180 ''' Resests the settings to the default factory value '''
182 self
.lpEdit
.setText(self
.conf
.get("library_path"))
183 self
.cpEdit
.setText(self
.conf
.get("class_path"))
184 self
.mpEdit
.setText(self
.conf
.get("module_path"))
185 if(self
.conf
.get("splash_screen")=="yes"):
186 self
.splash
.setChecked(True)
188 self
.splash
.setChecked(False)
189 if(self
.conf
.get("clean_log")=="yes"):
190 self
.clean
.setChecked(True)
192 self
.clean
.setChecked(False)
193 if(self
.conf
.get("status_message")=="on"):
194 self
.status
.setChecked(True)
196 self
.status
.setChecked(False)