-
Notifications
You must be signed in to change notification settings - Fork 0
/
properties.py
138 lines (122 loc) · 5.76 KB
/
properties.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QPushButton, QApplication, QMessageBox, \
QLineEdit, QComboBox, QCheckBox
import qlib as qc
import parameters as gl
class Properties(QDialog):
def __init__(self, data_dict,parent=None):
super(Properties, self).__init__(parent)
self.resize(400, 600)
self.setWindowTitle('Properties')
self.ctrl_list = ['QLineEdit','QLabel','QPushButton','QTableWidget','QToolButton', 'QComboBox','QDateEdit', 'QCheckBox',
'QSpinBox', 'QPlainTextEdit', 'QDoubleSpinBox',
'QListWidget','QCalendarWidget',
'QTimeEdit','QDateTimeEdit',
'QCommandLinkButton','QTreeWidget', 'QVBoxLayout', 'QHBoxLayout','addStretch']
self.ret = {'responce': False}
self.data_dict = data_dict
masterLayout = QVBoxLayout(self)
self.controlCbx = QComboBox()
self.controlCbx.addItems(self.ctrl_list)
self.labelEdt = QLineEdit()
self.controlNameEdt = QLineEdit()
self.addSelf = QCheckBox('Add self.')
self.addSelf.setCheckState(gl.ADD_SELF)
self.layoutCbx = QComboBox()
self.layoutCbx.addItems(gl.layouts_list)
self.maxWight = QLineEdit()
self.maxHeight = QLineEdit()
self.minWight = QLineEdit()
self.minHeight = QLineEdit()
self.onClickEdt = QLineEdit()
masterLayout.addLayout(qc.addHLayout(['Widget', self.controlCbx]))
masterLayout.addLayout(qc.addHLayout(['Label', self.labelEdt]))
masterLayout.addLayout(qc.addHLayout(['Name', self.controlNameEdt,self.addSelf]))
masterLayout.addLayout(qc.addHLayout(['Layout', self.layoutCbx]))
masterLayout.addLayout(qc.addHLayout(['Width', 'max', self.maxWight, 'min', self.minWight]))
masterLayout.addLayout(qc.addHLayout(['Height','max', self.maxHeight, 'min', self.minHeight]))
masterLayout.addLayout(qc.addHLayout(['on click button',self.onClickEdt]))
masterLayout.addStretch()
advanceBtn = QPushButton('Advance')
advanceBtn.clicked.connect(self.advance_click)
masterLayout.addLayout(qc.addHLayout([advanceBtn,True]))
okBtn = QPushButton('O.K.')
okBtn.clicked.connect(self.ok_click)
cancelBtn = QPushButton('Sair')
cancelBtn.clicked.connect(self.cancel_btn_click)
masterLayout.addLayout(qc.addHLayout([okBtn, cancelBtn]))
if not self.data_dict['new']:
self.refresh_form()
else:
self.set_values()
def refresh_form(self):
self.controlCbx.setCurrentText(self.data_dict['widget'])
self.labelEdt.setText(self.data_dict['label'])
self.controlNameEdt.setText(self.data_dict['widget_name'])
self.layoutCbx.setCurrentText(self.data_dict['layout'])
if self.data_dict['max_width'] != '-1':
self.maxWight.setText(self.data_dict['max_width'])
if self.data_dict['min_width'] != '-1':
self.minWight.setText(self.data_dict['min_width'])
if self.data_dict['max_height'] != '-1':
self.maxHeight.setText(self.data_dict['max_height'])
if self.data_dict['min_height'] != '-1':
self.minHeight.setText(self.data_dict['min_height'])
def set_values(self):
if gl.ADD_SELF == 2:
self.controlNameEdt.setText('self.')
def cancel_btn_click(self):
self.close()
def ok_click(self):
gl.ADD_SELF = self.addSelf.checkState()
if self.validate():
ctr_data = {'widget': self.controlCbx.currentText(), 'label': self.labelEdt.text(),
'widget_name': self.controlNameEdt.text(),
'layout': self.layoutCbx.currentText(),
'new': False }
if self.maxWight.text() != '':
ctr_data['max_width'] = self.maxWight.text()
else:
ctr_data['max_width'] = '-1'
if self.minWight.text() != '':
ctr_data['min_width'] = self.minWight.text()
else:
ctr_data['min_width'] = '-1'
if self.maxHeight.text() != '':
ctr_data['max_height'] = self.maxHeight.text()
else:
ctr_data['max_height'] = '-1'
if self.minHeight.text() != '':
ctr_data['min_height'] = self.minHeight.text()
else:
ctr_data['min_height'] = '-1'
self.ret = {'responce': True, 'ctr_data': ctr_data}
self.close()
def advance_click(self):
widget_type = self.controlCbx.currentText()
if widget_type == 'QTableWidget':
print('call table')
def validate(self):
flag = True
if self.controlNameEdt.text() == '' or self.controlNameEdt.text() == 'self.' and self.controlCbx.currentText() != 'addStretch':
QMessageBox.critical(None, "Error", "Missing Widget name")
flag = False
else:
if self.labelEdt.text() == '' and self.controlCbx.currentText() in ['QLabel','QPushButton','QCheckBox']:
QMessageBox.critical(None, "Error", "This widget needs a label")
flag = False
if self.controlCbx.currentText() in ['QVBoxLayout', 'QHBoxLayout']:
if self.controlNameEdt.text() == '':
QMessageBox.critical(None, "Error", "Layouts have to had a name")
flag = False
if self.controlCbx.currentText() == 'addStretch': self.controlNameEdt.setText('')
return flag
def main():
app = QApplication(sys.argv)
form = Properties()
form.show()
app.exec_()
if __name__ == '__main__':
main()