-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmatrixcalculator.kv
More file actions
393 lines (343 loc) · 13.7 KB
/
matrixcalculator.kv
File metadata and controls
393 lines (343 loc) · 13.7 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#: import utils kivy.utils
#: import dp kivy.metrics.dp
#: import * uixwidgets
#: import ColorProperty kivy.properties
<MatrixGrid>:
size_hint_x: 1
size_hint_max_x: dp(700)
size_hint_y: None
height: self.minimum_height
padding: [dp(20+(10*(4-self.order[1])) ), dp(30-(7*(self.order[0]-2)))]
spacing: [dp(6.66*3**(4-self.order[1])), dp(6.66*3**(4-self.order[0]))]
row_force_default: True
row_default_height: dp(50)
opacity: 0 if self.order == [0, 0] else 1
canvas.before:
Color:
rgba: utils.get_color_from_hex('#d3dde4')
RoundedRectangle:
size: self.size
pos: self.pos
radius: [dp(10), ]
<MatrixGrid1@MatrixGrid>:
<MatrixGrid2@MatrixGrid>:
<MatrixGridA@MatrixGrid>:
<StepperButton@Button>:
font_size: sp(25)
color: 0,0,0,1
background_normal: ''
background_disabled_color: 0,0,0,0
background_color: 0,0,0,0
<NumberStepper@BoxLayout>:
value: 0
min: 0
max: 999999
orientation: 'horizontal'
size_hint: None, None
height: dp(50)
width: dp(200)
canvas.before:
Color:
rgba: utils.get_color_from_hex('#B2B8C7')
RoundedRectangle:
size: self.size
pos:self.pos
radius: [dp(5),]
StepperButton:
text: '−'
bold: True
size_hint_x: 0.3
on_press: self.parent.value -= 1
disabled: True if self.parent.value <= self.parent.min or self.parent.opacity == 0 else False
Label:
canvas.before:
Color:
rgba: utils.get_color_from_hex('#C6F0C8')
Rectangle:
size: self.size
pos: self.pos
text_size: self.size
font_size: sp(20)
color: 0,0,0,1
size_hint: 0.4, None
text: str(self.parent.value)
halign: 'center'
valign: 'center'
height: dp(50)
StepperButton:
text: '+'
size_hint_x: 0.3
on_press: self.parent.value += 1
disabled: True if self.parent.value >= self.parent.max or self.parent.opacity == 0 else False
# ////// Entry point of our layout structure
<MainWindow>:
orientation: "vertical"
# // Area : Heading
AnchorLayout:
size_hint_y: 0.1071
Label:
id: heading
size_hint_x: 0.9394
size_hint_max_x: dp(500)
size_hint_y: 0.67
canvas.before:
Color:
rgb: utils.get_color_from_hex('#0C335C')
RoundedRectangle:
size: self.size
pos: self.pos
radius: [(dp(27),dp(27)),]
text: "Matrix Calculator "
font_family: 'bold'
font_name: './assets/fonts/Alata-Regular.ttf'
font_size: sp(23)
halign: 'right'
valign: 'center'
text_size: self.size
Image:
pos: (self.parent.x-self.parent.width/3,self.parent.y)
size: self.parent.size
source: './assets/images/icon.png'
# // Area : Input
AnchorLayout:
size_hint_y: 0.1442
BoxLayout:
orientation: "vertical"
size_hint: (0.8788,0.9)
size_hint_max_x: dp(600)
pos_hint: {'center_x':0.5}
canvas.before:
Color:
rgba: utils.get_color_from_hex('#DBE2E6')
RoundedRectangle:
size: self.size
pos: self.pos
radius: [dp(10),]
# ////// Instruct user to enter order
Label:
size_hint_y: 0.4
valign: 'center'
halign: 'center'
text_size: self.size
font_size: sp(19)
font_name: './assets/fonts/BalooBhai2-Regular.ttf'
text: "Choose order of Matrix :"
color: utils.get_color_from_hex('#4E5356')
# // Number stepper to adjust matrix order
BoxLayout:
size_hint_y: 0.6
padding: dp(10)
spacing: dp(10)
NumberStepper: # // Adjust Rows
id: input_order_m
size_hint_x: 0.45
value: root.ids.matrix_screen.current_screen.children[0].order[0]
on_value: root.ids.matrix_screen.current_screen.children[0].order[0] = self.value
opacity: 0 if root.ids.matrix_screen.current == "Ans" else 1
min: 1
max: 4
Label:
text: "✕"
color: 0,0,0,1
font_size: sp(20)
font_name: 'DejaVuSans.ttf'
size_hint_x: 0.1
NumberStepper: # // Adjust columns
id: input_order_n
size_hint_x: 0.45
value: root.ids.matrix_screen.current_screen.children[0].order[1]
on_value: root.ids.matrix_screen.current_screen.children[0].order[1] = self.value
opacity: 0 if root.ids.matrix_screen.current == "Ans" else 1
value: 3
min: 1
max: 4
# // Operation Control Area
AnchorLayout:
size_hint_y: 0.19
BoxLayout:
orientation: "vertical"
size_hint_x: 0.8788
padding: dp(15)
canvas:
Color:
rgba: utils.get_color_from_hex('#D1E0F0')
RoundedRectangle:
size: self.size
pos: self.pos
radius: [dp(10),]
# // Sub-panel for controlling current operations
StackLayout:
padding: dp(10), dp(7)
spacing: dp(15)
size_hint_y: 0.4
canvas:
Color:
rgba: utils.get_color_from_hex('#85ADD7')
RoundedRectangle:
size: self.size
pos: self.pos
radius: [dp(7),]
Label:
size_hint_x: None
size: self.texture_size
text: app.operation_mode + " of"
font_name: "Roboto-Bold.ttf"
ToggleMatrix:
id: M1_button
text: "M1"
state: 'down'
# this button can be selected both programatically and manually
on_state: root.ids.matrix_screen.transition.direction = 'right'
on_state: root.ids.matrix_screen.current = self.text if self.state == 'down' else root.ids.matrix_screen.current
BoxLayout: # // Section visible only if double matrix operation
size_hint_x: None
opacity: 1 if app.operation_config[app.operation_mode][0] == 'double' else 0
spacing: dp(10)
Label:
size_hint_x: None
size: self.texture_size
text: "and"
font_name: "Roboto-Bold.ttf"
ToggleMatrix:
text: "M2"
disabled: True if self.parent.opacity == 0 else False
on_disabled: root.ids.M1_button.state = 'down' if self.state == 'down' else root.ids.M1_button.state; self.state = 'normal'
# this button can be selected only manually
on_release: root.ids.matrix_screen.transition.direction = 'left'
on_release: root.ids.matrix_screen.current = self.text if self.state == 'down' else root.ids.matrix_screen.current
# // Choose between operations
StackLayout:
size_hint_y: 0.6
padding: dp(10)
spacing: [dp(10), dp(5)]
size_hint_x: 0.8788
ToggleOperation:
text: "Determinant"
state: 'down'
ToggleOperation:
text: "Rank"
ToggleOperation:
text: "Addition"
ToggleOperation:
text: "Product"
ToggleOperation:
text: "Inverse"
# // Area : Display
AnchorLayout:
size_hint_y: 0.0814
StackLayout:
padding: dp(10), dp(5)
size_hint: (0.8788,None)
height: root.ids.display_box.height + 2*self.padding[1]
opacity: 1 if root.ids.display_box.text else 0
indicator_color: [0,0,0,0]
canvas.before:
Color:
rgba: utils.get_color_from_hex('#F2E2F3')
RoundedRectangle:
size: self.size
pos: self.pos
radius: [dp(8), ]
Widget: # Indicator of error or answer
size_hint: None, None
pos: self.parent.pos
size: [dp(10), self.parent.height]
canvas:
Color:
rgba: self.parent.indicator_color
RoundedRectangle:
size: self.size
pos: self.parent.pos
radius: [dp(8), 0, 0, dp(8)]
Label:
id: display_box
size_hint: None, None
size: self.texture_size
#padding: dp(10), dp(10)
#halign: 'left'
#valign: 'center'
#height: self.texture_size[1] + dp(20)
markup: True
max_lines: 4
text: ''
font_name: 'Roboto-Bold.ttf'
font_size: sp(15)
#text_size: self.width,None
#:set tiranga_red utils.get_color_from_hex('#EB730A')
#:set dark_green utils.get_color_from_hex('#3C9532')
#:set dark_red utils.get_color_from_hex('#973126')
#:set indicator_red utils.get_color_from_hex('#FF615C')
#:set indicator_green utils.get_color_from_hex('#93EF6B')
color: dark_red if (root.ids.display_box.text).startswith('!') else dark_green
on_text: self.parent.indicator_color = indicator_red if (self.text).startswith('!') else indicator_green
ToggleMatrix:
id: ans_button
text: "Ans"
#disabled: True if app.operation_config[app.operation_mode][2] != "matrix" else False
disabled: True if app.operation_config[app.operation_mode][2] != "matrix" or self.parent.indicator_color == indicator_red or ":" not in root.ids.display_box.text else False
on_state: root.ids.matrix_screen.current = self.text if self.state == 'down' else root.ids.matrix_screen.current
on_state: root.ids.matrix_screen.transition.direction = 'up' if self.state == 'down' else 'down'
opacity: 0 if self.disabled == True else 1
# // Area : Matrix
AnchorLayout:
anchor_y: 'center'
size_hint_y: 0.3771
padding: (self.width*0.0606,0)
ScreenManager:
id: matrix_screen
on_current: root.ids.input_order_m.value = self.current_screen.children[0].order[0]; root.ids.input_order_n.value = self.current_screen.children[0].order[1]
Screen:
name: 'M1'
MatrixGrid1:
id: input_matrix_1
Screen:
name: 'M2'
MatrixGrid2:
id: input_matrix_2
Screen:
name: 'Ans'
MatrixGridA:
id: output_matrix
# // Area : Launchpad
BoxLayout:
orientation: 'horizontal'
size_hint_y: 0.1000
padding: (self.width*0.0606,0)
# // Button to clear matrix_input
Button:
disabled: True if root.ids.matrix_screen.current == "Ans" else False
on_release: root.ids.matrix_screen.current_screen.children[0].on_order()
size_hint_x: 0.3
size_hint_y: 3/5
padding_x: dp(10)
pos_hint: {'center_y':0.5}
background_normal: ''
background_color: 0,0,0,0
text: ' Reset'
font_name: 'Roboto-BoldItalic.ttf'
font_size: sp(16.5)
canvas.before:
Color:
rgb: tiranga_red
Quad:
points: (self.parent.width*4.5/15,self.height+self.y,self.parent.width*5.5/15,self.y,self.x,self.y,self.x,self.height+self.y)
Image:
source: 'assets/images/refresh.png'
size: self.parent.height/2, self.parent.height/2
pos: (self.parent.x+self.parent.padding_x, self.parent.center_y-self.height/2)
# ////// Button to initiate the calculation of provided matrix
Button:
on_release: app.calculate()
text: ' Calculate >>'
font_name: './assets/fonts/ChakraPetch-SemiBoldItalic.ttf'
font_size: sp(25)
size_hint_x: 0.6
size_hint_y: 3/5
pos_hint: {'center_x': 0.5,'center_y':0.5}
background_normal: ''
background_color: 0,0,0,0
canvas.before:
Color:
rgb: dark_green
Quad:
points: (self.parent.width*5/15,self.height+self.y,self.parent.width*6/15,self.y,self.x+self.width,self.y,self.x+self.width,self.height+self.y)