-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
210 lines (179 loc) · 7.44 KB
/
test.py
File metadata and controls
210 lines (179 loc) · 7.44 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import PySimpleGUI as sg
from numpy import ones
from Gauss_method import Gauss_method, right_matrix
import Methods
from funnyerror import funnyerror
def oshibka_vvoda():
layout = [[sg.Text('Некорректные данные!')],
[sg.Button('Решить еще?'), sg.Button('Все.', bind_return_key = True)]]
window = sg.Window('Ошибка', layout)
event, values = window.Read()
if event == 'Решить еще?':
check = False
window.close()
elif event == 'Все.':
check = True
window.close()
elif event is None:
check = True
window.close()
else:
funnyerror()
return check
def build_matrixwithGUI():
text1 = 'Введите количество неизвестных'
layout = [[sg.Text(text1,size=(35, 1), key='answer')],
[sg.InputText(key='c_unknown')],
[sg.Text('')],
[sg.ReadButton('Ok', bind_return_key = True)]]
window = sg.Window('Метод Гаусса').Layout(layout)
clown = True
while clown:
button, values = window.Read()
if button is None:
break
c_unknown = int(values['c_unknown'])
window.FindElement('c_unknown').Update('')
matrix = ones((c_unknown, c_unknown+1))
for i in range(c_unknown):
answer = 'Введите коэффициенты при Х{0}'.format(i+1)
window.FindElement('answer').Update(answer)
button, values = window.Read()
neizv = list(values['c_unknown'].split())
for number_x in range(c_unknown):
matrix[number_x][i] = float(neizv[number_x])
window.FindElement('c_unknown').Update('')
answer = 'Введите свободные коэффициенты'
window.FindElement('answer').Update(answer)
button, values = window.Read()
free_coef = list(values['c_unknown'].split())
for number_free in range(c_unknown):
matrix[number_free][c_unknown] = float(free_coef[number_free])
window.close()
clown = False
matrix = right_matrix(matrix, c_unknown)
check = not(clown)
return matrix, c_unknown
def get_cof_and_vecwithGUI(name):
'''
return mtr_cof, mtr_vec, var
'''
text1 = 'Введите количество неизвестных'
layout = [[sg.Text(text1,size=(35, 1), key='answer')],
[sg.InputText(key='c_unknown')],
[sg.Text('')],
[sg.ReadButton('Ok', bind_return_key = True)]]
window = sg.Window(name).Layout(layout)
clown = True
while clown:
button, values = window.Read()
if button is None:
break
var = int(values['c_unknown'])
window.FindElement('c_unknown').Update('')
mtr_cof = ones((var, var))
for i in range(var):
answer = 'Введите коэффициенты при Х{0}'.format(i+1)
window.FindElement('answer').Update(answer)
button, values = window.Read()
neizv = list(values['c_unknown'].split())
for number_x in range(var):
mtr_cof[number_x][i] = float(neizv[number_x])
window.FindElement('c_unknown').Update('')
answer = 'Введите свободные коэффициенты'
window.FindElement('answer').Update(answer)
button, values = window.Read()
mtr_vec = list(map(float,values['c_unknown'].split()))
window.close()
clown = False
return mtr_cof, mtr_vec, var
def vivod_gwGUI_LOOP(matrix_copy, cool_matrix, cool_vivod, pogreshnost, check):
if check:
lst = ['Расширенная матрица коэффициентов', matrix_copy,
'Приведенная к треугольному виду матрица', cool_matrix,
'Корни', cool_vivod,
'Погрешность', pogreshnost]
temp = [[sg.Text(i)] for i in lst]
buttons = [[sg.Button('Решить еще?'), sg.Button('Все.', bind_return_key = True)]]
layout = temp + buttons
window = sg.Window('Решение').Layout(layout)
else:
layout = [[sg.Text('ДАННУЮ СИСТЕМУ')],
[sg.Text('НЕЛЬЗЯ РЕШИТЬ')],
[sg.Text('МЕТОДОМ ГАУССА')],
[sg.Button('Решить еще?'), sg.Button('Все.', bind_return_key = True)]]
window = sg.Window('Ошибка').Layout(layout)
event, values = window.Read()
if event == 'Решить еще?':
check = False
window.close()
elif event == 'Все.':
check = True
window.close()
elif event is None:
check = True
window.close()
else:
funnyerror()
return check
def vivod_mmGUI_LOOP(mtr_cof, mtr_vec, razn, check, list_x, name):
if check:
lst = ['Матрица коэффициентов', mtr_cof,
'Матрица свободных членов', mtr_vec,
'Корни', list_x,
'Погрешность', razn]
temp = [[sg.Text(i)] for i in lst]
buttons = [[sg.Button('Решить еще?'), sg.Button('Все.', bind_return_key = True)]]
layout = temp + buttons
window = sg.Window('Решение').Layout(layout)
else:
if name == 'Матричный метод':
layout = [[sg.Text('ДАННУЮ СИСТЕМУ')],
[sg.Text('НЕЛЬЗЯ РЕШИТЬ')],
[sg.Text('МАТРИЧНЫМ МЕТОДОМ')],
[sg.Button('Решить еще?'), sg.Button('Все.', bind_return_key = True)]]
window = sg.Window('Ошибка').Layout(layout)
elif name == 'Метод Крамера':
layout = [[sg.Text('ДАННУЮ СИСТЕМУ')],
[sg.Text('НЕЛЬЗЯ РЕШИТЬ')],
[sg.Text('МЕТОДОМ КРАМЕРА')],
[sg.Button('Решить еще?'), sg.Button('Все.', bind_return_key = True)]]
window = sg.Window('Ошибка').Layout(layout)
else:
funnyerror()
return False
event, values = window.Read()
if event == 'Решить еще?':
check = False
window.close()
elif event == 'Все.':
check = True
window.close()
elif event is None:
check = True
window.close()
else:
funnyerror()
return check
def Obr_matrixwithGUI():
name = 'Матричный метод'
mtr_cof, mtr_vec, var = get_cof_and_vecwithGUI(name)
mtr_cof, mtr_vec, var, razn, check, list_x = Methods.Obr_matrix_method(mtr_cof, mtr_vec, var)
check = vivod_mmGUI_LOOP(mtr_cof, mtr_vec, razn, check, list_x, name)
return check
def Kramer_methodwithGUI():
name = 'Метод Крамера'
mtr_cof, mtr_vec, var = get_cof_and_vecwithGUI(name)
mtr_cof, mtr_vec, var, razn, check, list_x = Methods.Kramer_method(mtr_cof, mtr_vec, var)
check = vivod_mmGUI_LOOP(mtr_cof, mtr_vec, razn, check, list_x, name)
return check
def Gauss_methodwithGUI():
'''
return check
'''
matrix, c_unknown, = build_matrixwithGUI()
matrix_copy, cool_matrix, cool_vivod, pogreshnost, check = Gauss_method(matrix, c_unknown)
check = vivod_gwGUI_LOOP(matrix_copy, cool_matrix, cool_vivod, pogreshnost, check)
return check
if __name__ == '__main__':
pass