1 |
|
---|
2 | from PyQt4.QtCore import *
|
---|
3 | from PyQt4.QtGui import *
|
---|
4 | from PyQt4 import QtCore, QtGui
|
---|
5 | from PyQt4.QtWebKit import *
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 | import Ui_messagesdialog
|
---|
11 | from nosferatu import auto_types
|
---|
12 |
|
---|
13 | class MessagesDialog(QDialog, Ui_messagesdialog.Ui_MessagesDialog):
|
---|
14 |
|
---|
15 | def __init__(self, parent=None, messagesTypesDict=None):
|
---|
16 | super(MessagesDialog, self).__init__(parent)
|
---|
17 | if messagesTypesDict:
|
---|
18 | self.msgs = messagesTypesDict
|
---|
19 | else:
|
---|
20 | self.msgs={}
|
---|
21 | self.msgs['all'] = True
|
---|
22 | for mtype in auto_types.msg_types:
|
---|
23 | if mtype == 'all':
|
---|
24 | continue# self.msgs[mtype] = True
|
---|
25 | self.msgs[mtype] = True
|
---|
26 |
|
---|
27 | print self.msgs
|
---|
28 |
|
---|
29 | self.setupUi(self)
|
---|
30 |
|
---|
31 | self.connect(self.buttonBox, SIGNAL("accepted()"),
|
---|
32 | self, SLOT("accept()"))
|
---|
33 | self.connect(self.buttonBox, SIGNAL("rejected()"),
|
---|
34 | self, SLOT("reject()"))
|
---|
35 | self.setWindowTitle("Edit Message Types")
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | i=0
|
---|
40 | #buttonGroup = QtGui.QButtonGroup()
|
---|
41 | #inclusiveButton = QtGui.QRadioButton('inclusive (choose the following message types)')
|
---|
42 | #exclusiveButton = QtGui.QRadioButton('exclusive (all, except the following message types')
|
---|
43 | #buttonGroup.addButton(inclusiveButton)
|
---|
44 | #buttonGroup.addButton(exclusiveButton)
|
---|
45 | #self.gridLayout_2.addWidget(inclusiveButton,1,1,1,1)
|
---|
46 | #self.gridLayout_2.addWidget(exclusiveButton,2,1,1,1)
|
---|
47 |
|
---|
48 |
|
---|
49 | for mtype in sorted(auto_types.msg_types):
|
---|
50 | if mtype == 'all':
|
---|
51 | #exclusiveButton.setChecked(self.msgs[mtype])
|
---|
52 | continue
|
---|
53 | msgTypeCheckbox = QtGui.QCheckBox()
|
---|
54 | msgTypeCheckbox.setText(mtype)
|
---|
55 | msgTypeCheckbox.setObjectName(mtype)
|
---|
56 |
|
---|
57 | if self.msgs[mtype] != None:
|
---|
58 | checkstate = not(self.msgs[mtype])
|
---|
59 | else:
|
---|
60 | checkstate = False
|
---|
61 |
|
---|
62 | msgTypeCheckbox.setChecked(checkstate)
|
---|
63 | self.connect(msgTypeCheckbox,
|
---|
64 | SIGNAL("toggled(bool)"),
|
---|
65 | self.onCheckboxChecked )
|
---|
66 |
|
---|
67 | self.gridLayout.addWidget(msgTypeCheckbox,(i/2)+2, i%2, 1, 1)
|
---|
68 | i+=1
|
---|
69 |
|
---|
70 | self.updateOutput()
|
---|
71 | #self.web = QWebView()
|
---|
72 | #self.verticalLayout.addWidget(self.web)
|
---|
73 |
|
---|
74 | #self.web.load(QUrl("http://www.bacula.org/5.0.x-manuals/en/main/main/Configuring_Director.html"))
|
---|
75 | #self.web.show()
|
---|
76 | def onCheckboxChecked(self):
|
---|
77 | print "checkbox was checked by:" , self.sender().objectName() , "to:" , self.sender().isChecked()
|
---|
78 | self.msgs[str(self.sender().objectName())] = not(self.sender().isChecked())
|
---|
79 | self.updateOutput()
|
---|
80 | #self.sender().isChecked()
|
---|
81 |
|
---|
82 | def updateOutput(self):
|
---|
83 | s = ''
|
---|
84 | if self.msgs['all']:
|
---|
85 | s += 'all,'
|
---|
86 | for msg,val in sorted(self.msgs.iteritems()):
|
---|
87 |
|
---|
88 | if self.msgs['all']:
|
---|
89 | if val == False:
|
---|
90 | s += '!%s,' % (msg)
|
---|
91 | else:# not all, so write all that are true
|
---|
92 | if val == True:
|
---|
93 | s += '%s,' % (msg)
|
---|
94 | print s[:-1]
|
---|
95 | #print self.msgs
|
---|
96 | self.outputLineEdit.setText(s[:-1]) # cut last comma
|
---|
97 |
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 | if __name__ == "__main__":
|
---|
104 | m={}
|
---|
105 | m['all'] = True
|
---|
106 | for mtype in auto_types.msg_types:
|
---|
107 | if mtype == 'all':
|
---|
108 | continue# self.msgs[mtype] = True
|
---|
109 | m[mtype] = None
|
---|
110 | m['skipped'] = False
|
---|
111 |
|
---|
112 | import sys
|
---|
113 | app = QApplication(sys.argv)
|
---|
114 | dialog = MessagesDialog(messagesTypesDict=m)
|
---|
115 | dialog.show()
|
---|
116 | app.exec_()
|
---|