-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaveConfiguration.py
72 lines (64 loc) · 2.46 KB
/
saveConfiguration.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
#!/usr/bin/env python
from PyQt5.QtWidgets import *
def saveMacroConfiguration(tableWidget):
#++++++++++++++++++++++++++++++++++++++++
# collect macro configuration
#++++++++++++++++++++++++++++++++++++++++
textOut = ''
row_count = tableWidget.rowCount()
for i in range(row_count):
if type(tableWidget.item(i,0))==QTableWidgetItem:
macro = tableWidget.item(i,0).text()
value = ''
if type(tableWidget.cellWidget(i,1))==QComboBox:
value = tableWidget.cellWidget(i,1).currentText()
#if macro and value:
textOut = textOut+'%s = %s\n' % (macro,value)
return textOut
def saveUnitConfiguration(treeWidget):
#++++++++++++++++++++++++++++++++++++++++
# collect design configuration
#++++++++++++++++++++++++++++++++++++++++
textOut='''
config cfg;
design chip_tb;
default worklib;
'''
tree_col_count = treeWidget.columnCount()
it = QTreeWidgetItemIterator(treeWidget)
while it.value():
item = it.value()
#print (item.toolTip(0))
if not item.isHidden():
if item.toolTip(0):
hdl_path = item.toolTip(0)
cell_name = treeWidget.itemWidget(item,1).currentText().split(':')[1]
textOut = textOut + ' instance %s use worklib.%s;\n' % (hdl_path,cell_name)
it.__iadd__(1)
textOut = textOut + 'endconfig\n'
return textOut
def saveConfigFileFromGui(tableWidget,treeWidget):
#++++++++++++++++++++++++++++++
# save macro value
#++++++++++++++++++++++++++++++
textOut = saveMacroConfiguration(tableWidget)
#++++++++++++++++++++++++++++++
# save unit value
#++++++++++++++++++++++++++++++
it = QTreeWidgetItemIterator(treeWidget)
while it.value():
item = it.value()
#print (item.toolTip(0))
if not item.isHidden():
if item.toolTip(0):
item_name = item.text(2)
item_value = treeWidget.itemWidget(item,1).currentText().split(':')[0]
textOut = textOut + '%s = %s\n' % (item_name,item_value)
it.__iadd__(1)
return textOut
def saveConfigFile(cfg_out_dict):
textOut = '#//Generate automatic by CMT,don\'t change!'
key_list = sorted(cfg_out_dict.keys(),reverse=False)
for key in key_list:
textOut = textOut + '\n' + key + ' = ' + cfg_out_dict[key] + '\n'
return textOut