-
Notifications
You must be signed in to change notification settings - Fork 5
/
newmodeldialog.py
71 lines (62 loc) · 2.74 KB
/
newmodeldialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
from PyQt4 import QtGui, QtCore,Qt
import config
from mplugin import MoosePluginBase, EditorBase, EditorWidgetBase, PlotBase, RunBase
import re
class DialogWidget(QtGui.QDialog):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self, parent)
self.warning = None
self._currentRadioButton ="kkit"
self.layout = QtGui.QGridLayout()
self.modelPathLabel = QtGui.QLabel('Model Name')
self.modelPathEdit = QtGui.QLineEdit('')
self.layout.addWidget(self.modelPathLabel, 0, 0)
self.layout.addWidget(self.modelPathEdit, 0, 1,1,1)
# self.defaultRadio = QtGui.QRadioButton('default')
# #self.defaultRadio.setChecked(True);
# self.kkitRadio = QtGui.QRadioButton('kkit')
# self.kkitRadio.setChecked(True)
# self.defaultRadio.toggled.connect(lambda : self.setcurrentRadioButton('default'))
# self.kkitRadio.toggled.connect(lambda : self.setcurrentRadioButton('kkit'))
# layout.addWidget(self.defaultRadio,2,1)
# layout.addWidget(self.kkitRadio,2,0)
self.hbox = QtGui.QHBoxLayout()
self.buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
self.connect(self.buttonBox, QtCore.SIGNAL('accepted()'), self.validateAccept)
self.hbox.addWidget(self.buttonBox,1)
self.buttonBox1 = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Cancel)
self.connect(self.buttonBox1, QtCore.SIGNAL('rejected()'), self.Cancel)
self.hbox.addWidget(self.buttonBox1,0)
#self.hbox.setBackgroundColor(Blue)
#self.modelPathEdit.returnPressed.connect(self.validateAccept)
# self.connect(self.buttonBox, QtCore.SIGNAL('rejected()'), self.reject)
#self.hbox.addStretch(1)
self.layout.addLayout(self.hbox,1,1)
self.setLayout(self.layout)
def Cancel (self):
self.close()
def validateAccept(self):
text = str(self.modelPathEdit.text())
self.layout.removeWidget(self.warning)
#replace / to _
text = text.replace('/','_')
#print(self.layout.widgets())
if len(text) == 0:
self.warning = QtGui.QLabel("Model name cannot be empty!")
self.layout.addWidget(self.warning, 1, 0, 1, -1)
elif not re.match("^[a-zA-Z]+.*",text):
self.warning = QtGui.QLabel("Start special characters not allowed!")
self.layout.addWidget(self.warning, 1, 0, 1, -1)
else:
self.accept()
return False
def getcurrentRadioButton(self):
return self._currentRadioButton
if __name__ == '__main__':
app =QtGui.QApplication([])
widget = DialogWidget()
widget.setWindowTitle('New Model')
widget.setMinimumSize(400, 200)
widget.show()
app.exec_()