-
Notifications
You must be signed in to change notification settings - Fork 0
/
py2save.py
72 lines (58 loc) · 2.3 KB
/
py2save.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
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 25 19:44:25 2014
@author: Pyltsin
"""
from PyQt4 import QtCore, QtGui
def save2file(fil, widgetList):
'''сама запись и возврат 1 если ошибка, 0 - если все ок'''
f= open(fil, 'w')
for item in widgetList:
if type(item)==QtGui.QComboBox:
txt=str(item.currentIndex()).rstrip()+u'\n'
f.write(txt)
# print txt
if type(item)==QtGui.QSpinBox:
txt=str(item.value()).rstrip()+u'\n'
f.write(txt)
# print txt
if type(item)==QtGui.QTableWidget:
columnCount=item.columnCount()
rowCount=item.rowCount()
for i in range(columnCount):
for j in range(rowCount):
if item.cellWidget(j,i)==None:
txt=str(item.item(j,i).text()).rstrip()+u'\n'
f.write(txt)
# print txt
else:
txt=str(item.cellWidget(j,i).currentIndex()).rstrip()+u'\n'
f.write(txt)
# print txt
# if self.input_table.cellWidget(j,i)==None and self.input_table.item(j, i).text()=="" :
# self.input_table.item(j,i).setText(u"0")
f.close()
def load2form(fil, lst):
f=open(fil, 'r')
for item in lst:
if type(item)==QtGui.QComboBox:
txt=int(f.readline())
item.setCurrentIndex(txt)
elif type(item)==QtGui.QSpinBox:
txt=int(f.readline())
item.setValue(txt)
elif type(item)==QtGui.QTableWidget:
columnCount=item.columnCount()
rowCount=item.rowCount()
for i in range(columnCount):
for j in range(rowCount):
if item.cellWidget(j,i)==None:
txt=(f.readline())
# print txt
item.setItem(j, i, QtGui.QTableWidgetItem(""))
item.item(j,i).setText(txt)
else:
txt=int(f.readline())
# print txt
item.cellWidget(j,i).setCurrentIndex(txt)
f.close()