[956] | 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 | import Ui_messagesdialog
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | class ListSelectDialog(QDialog, Ui_messagesdialog.Ui_MessagesDialog):
|
---|
| 13 | '''
|
---|
| 14 | This dialog expects a Dictionary with the possible options as keys, and
|
---|
| 15 | fills the values with Frue or False.
|
---|
| 16 | '''
|
---|
| 17 | def __init__(self, parent=None, configDict=None, title='please select...'):
|
---|
| 18 | super(ListSelectDialog, self).__init__(parent)
|
---|
| 19 | self.setupUi(self)
|
---|
| 20 | if configDict:
|
---|
| 21 | self.msgs = configDict
|
---|
| 22 | else:
|
---|
| 23 | self.msgs={}
|
---|
| 24 |
|
---|
| 25 | self.setWindowTitle(title)
|
---|
| 26 | self.groupBox.setTitle(title)
|
---|
| 27 | # self.msgs['all'] = True
|
---|
| 28 | # for mtype in configrules.msg_types:
|
---|
| 29 | # if mtype == 'all':
|
---|
| 30 | # continue# self.msgs[mtype] = True
|
---|
| 31 | # self.msgs[mtype] = True
|
---|
| 32 |
|
---|
| 33 | #print self.msgs
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | self.connect(self.buttonBox, SIGNAL("accepted()"),
|
---|
| 38 | self, SLOT("accept()"))
|
---|
| 39 | self.connect(self.buttonBox, SIGNAL("rejected()"),
|
---|
| 40 | self, SLOT("reject()"))
|
---|
| 41 | #self.setWindowTitle("Edit Message Types")
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | i=0
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | for mtype in sorted(self.msgs.keys()):
|
---|
| 49 | msgTypeCheckbox = QtGui.QCheckBox()
|
---|
| 50 | msgTypeCheckbox.setText(mtype)
|
---|
| 51 | msgTypeCheckbox.setObjectName(mtype)
|
---|
| 52 |
|
---|
| 53 | if self.msgs[mtype] != None:
|
---|
| 54 | checkstate = self.msgs[mtype]
|
---|
| 55 | else:
|
---|
| 56 | checkstate = False
|
---|
| 57 |
|
---|
| 58 | msgTypeCheckbox.setChecked(checkstate)
|
---|
| 59 | self.connect(msgTypeCheckbox,
|
---|
| 60 | SIGNAL("toggled(bool)"),
|
---|
| 61 | self.onCheckboxChecked )
|
---|
| 62 |
|
---|
| 63 | #self.gridLayout.addWidget(msgTypeCheckbox, i%10,(i/10)+2, 1, 1)
|
---|
| 64 | self.gridLayout.addWidget(msgTypeCheckbox, i, 1, 1, 1)
|
---|
| 65 | i+=1
|
---|
| 66 |
|
---|
| 67 | self.updateOutput()
|
---|
| 68 | #self.web = QWebView()
|
---|
| 69 | #self.verticalLayout.addWidget(self.web)
|
---|
| 70 |
|
---|
| 71 | #self.web.load(QUrl("http://www.bacula.org/5.0.x-manuals/en/main/main/Configuring_Director.html"))
|
---|
| 72 | #self.web.show()
|
---|
| 73 | def onCheckboxChecked(self):
|
---|
| 74 | print "checkbox was checked by:" , self.sender().objectName() , "to:" , self.sender().isChecked()
|
---|
| 75 | self.msgs[str(self.sender().objectName())] = self.sender().isChecked()
|
---|
| 76 | self.updateOutput()
|
---|
| 77 | #self.sender().isChecked()
|
---|
| 78 |
|
---|
| 79 | def updateOutput(self):
|
---|
| 80 | s = ''
|
---|
| 81 | for msg,val in sorted(self.msgs.iteritems()):
|
---|
| 82 | if val == True:
|
---|
| 83 | s += '%s,' % (msg)
|
---|
| 84 | print s[:-1]
|
---|
| 85 | #print self.msgs
|
---|
| 86 | self.outputLineEdit.setText(s[:-1]) # cut last comma
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | if __name__ == "__main__":
|
---|
| 94 | from nosferatu import auto_configrules
|
---|
| 95 | m={}
|
---|
| 96 | #m['all'] = True
|
---|
| 97 | for mtype in auto_configrules.commands.keys():
|
---|
| 98 | #if mtype == 'all':
|
---|
| 99 | # continue# self.msgs[mtype] = True
|
---|
| 100 | m[mtype] = None
|
---|
| 101 | #m['skipped'] = False
|
---|
| 102 |
|
---|
| 103 | import sys
|
---|
| 104 |
|
---|
| 105 | app = QApplication(sys.argv)
|
---|
| 106 | dialog = ListSelectDialog(configDict=m,title="please select")
|
---|
| 107 | dialog.show()
|
---|
| 108 | app.exec_()
|
---|