forked from Marianpol/pyclip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scen_ecri_initpente.py
154 lines (137 loc) · 5.9 KB
/
scen_ecri_initpente.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#Embedded file name: /build/PyCLIP/android/app/scen_ecri_codevin.py
import os
import sys
import re
import time
import mod_globals
import mod_utils
import mod_ecu
import mod_zip
import mod_ecu_mnemonic
from mod_utils import pyren_encode
from mod_utils import clearScreen
from mod_utils import ASCIITOHEX
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.textinput import TextInput
from kivy.graphics import Color, Rectangle
fs = mod_globals.fontSize
class MyLabel(Label):
def __init__(self, **kwargs):
if 'bgcolor' in kwargs:
self.bgcolor = kwargs['bgcolor']
else:
self.bgcolor = (0, 0, 0, 0)
super(MyLabel, self).__init__(**kwargs)
self.bind(size=self.setter('text_size'))
self.halign = 'center'
self.valign = 'middle'
if 'size_hint' not in kwargs:
self.size_hint = (1, None)
if 'height' not in kwargs:
fmn = 1.1
lines = len(self.text.split('\n'))
simb = len(self.text) / 60
if lines < simb: lines = simb
if lines < 7: lines = 5
if lines > 20: lines = 15
if 1 > simb: lines = 1.5
if fs > 20:
lines = lines * 1.05
fmn = 1.5
self.height = fmn * lines * fs
if 'font_size' not in kwargs:
self.font_size = fs
def on_size(self, *args):
if not self.canvas:
return
self.canvas.before.clear()
with self.canvas.before:
Color(self.bgcolor[0], self.bgcolor[1], self.bgcolor[2], self.bgcolor[3])
Rectangle(pos=self.pos, size=self.size)
class Scenarii(App):
def __init__(self, **kwargs):
DOMTree = mod_zip.get_xml_scenario(kwargs['data'])
self.ScmRoom = DOMTree.documentElement
ScmParams = self.ScmRoom.getElementsByTagName('ScmParam')
ScmSets = self.ScmRoom.getElementsByTagName('ScmSet')
self.elm = kwargs['elm']
self.command = kwargs['command']
self.ecu = kwargs['ecu']
self.ScmParam = {}
self.ScmSet = {}
for Param in ScmParams:
name = pyren_encode(Param.getAttribute('name'))
value = pyren_encode(Param.getAttribute('value'))
self.ScmParam[name] = value
for Set in ScmSets:
try:
setname = pyren_encode(mod_globals.language_dict[Set.getAttribute('name')])
except:
pass
ScmParams = Set.getElementsByTagName('ScmParam')
for Param in ScmParams:
name = pyren_encode(Param.getAttribute('name'))
value = pyren_encode(Param.getAttribute('value'))
try:
self.ScmSet[setname] = value
except:
pass
self.ScmParam[name] = value
super(Scenarii, self).__init__(**kwargs)
def build(self):
fs = mod_globals.fontSize
header = '[' + self.command.codeMR + '] ' + self.command.label
root = GridLayout(cols=1, spacing=fs * 0.5, size_hint=(1.0, None))
root.bind(minimum_height=root.setter('height'))
root.add_widget(MyLabel(text=header))
root.add_widget(MyLabel(text=self.get_message('TexteTitre'), bgcolor=(1, 1, 0, 0.3)))
root.add_widget(MyLabel(text=self.get_message('TexteConsigne'), bgcolor=(1, 0, 0, 0.3)))
root.add_widget(Button(text=self.command.label, on_press=self.pupp, size_hint=(1, None), height=80))
root.add_widget(Button(text=self.get_message('6218'), on_press=self.stop, size_hint=(1, None), height=80))
rot = ScrollView(size_hint=(1, 1), do_scroll_x=False, pos_hint={'center_x': 0.5,
'center_y': 0.5})
rot.add_widget(root)
return rot
def pupp(self, instance):
cmd = self.ecu.get_ref_cmd(self.ScmParam['Commande1'])
resVal = self.ScmParam['ParametreCommande1']
responce = self.ecu.run_cmd(self.ScmParam['Commande1'], resVal)
codemr, label, value, unit = self.ecu.get_pr(self.ScmParam['ParametreInclinaison'], True)
key = '%s - %s' % (codemr, label)
value = '%s %s' % (value, unit)
layout = GridLayout(cols=1, spacing=5, padding=fs*0.5, size_hint=(1, None))
layout_current = BoxLayout(orientation='horizontal', size_hint=(1, None), height=50)
layout_current.add_widget(MyLabel(text=key, size_hint=(0.6, 1), bgcolor=(0, 0, 1, 0.3)))
layout_current.add_widget(MyLabel(text=value, size_hint=(0.4, 1), bgcolor=(0, 1, 0, 0.3)))
layout.add_widget(layout_current)
layout.add_widget(Button(text=self.get_message('6218'), fonte_size=fs, on_press=self.stop, size_hint=(1, None), height=fs*4))
rootP = ScrollView(size_hint=(1, 1))
rootP.add_widget(layout)
if 'NR' not in responce:
ch = self.get_message('TexteProcedureInterompue')
else:
ch = self.get_message('TexteInitialisationEffectuee')
popup = Popup(title='STATUS', content=rootP, auto_dismiss=True, size=(500, 500), size_hint=(None, None))
popup.open()
def get_message(self, msg):
if msg in self.ScmParam.keys():
value = self.ScmParam[msg]
else:
value = msg
if value.isdigit() and value in mod_globals.language_dict.keys():
value = pyren_encode(mod_globals.language_dict[value])
return value
def get_message_by_id(self, id):
if id.isdigit() and id in mod_globals.language_dict.keys():
value = pyren_encode(mod_globals.language_dict[id])
return value
def run(elm, ecu, command, data):
app = Scenarii(elm=elm,
ecu=ecu, command=command, data=data)
app.run()