author | Edouard Tisserant <edouard@beremiz.fr> |
Thu, 05 Dec 2024 13:56:59 +0100 | |
changeset 4060 | d2f5eb3c7d6e |
parent 4056 | 4b2de1a0fbf9 |
permissions | -rw-r--r-- |
4056
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
1 |
<?xml version='1.0' encoding='utf-8'?> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
2 |
<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
3 |
<variables> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
4 |
<variable name="FileNotify" type="HMI_INT"/> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
5 |
<variable name="CurrentPath" type="HMI_STRING" initial="..."/> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
6 |
<variable name="FileName" type="HMI_STRING"/> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
7 |
</variables> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
8 |
<globals> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
9 |
<xhtml:p><![CDATA[ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
10 |
from twisted.web.resource import Resource |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
11 |
from os import getcwd, listdir |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
12 |
from os.path import dirname, isfile, join |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
13 |
import collections, json |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
14 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
15 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
16 |
class FilesJsonResource(Resource): |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
17 |
image_cache = {} |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
18 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
19 |
def render_GET(self, request): |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
20 |
request.setHeader('content-type', 'image/png') |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
21 |
img_name = request.args[b'name'][0].decode('utf-8') |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
22 |
p = getcwd() + '/' + img_name |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
23 |
if p not in self.image_cache: |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
24 |
with open(p, 'rb') as image_file: |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
25 |
img_bytes = image_file.read() |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
26 |
self.image_cache[p] = img_bytes |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
27 |
else: |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
28 |
img_bytes = self.image_cache[p] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
29 |
return img_bytes |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
30 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
31 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
32 |
def render_POST(self, request): |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
33 |
newstr = request.content.getvalue() |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
34 |
newdata = json.loads(newstr) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
35 |
args = newdata['args'] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
36 |
range_feedback = newdata['range'] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
37 |
slider_position = newdata['position'] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
38 |
visible = newdata['visible'] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
39 |
extra = newdata['extra'] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
40 |
options = newdata['options'] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
41 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
42 |
path = PLCGlobals.CurrentPath |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
43 |
if path == '...': |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
44 |
PLCGlobals.CurrentPath = path = getcwd() |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
45 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
46 |
if len(options) == 1 : |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
47 |
action, = options |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
48 |
if action == 'action_reset': |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
49 |
PLCGlobals.CurrentPath = path = getcwd() |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
50 |
elif len(options) == 2 : |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
51 |
action, sent_path = options |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
52 |
if action == 'onClick[acknowledge]': |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
53 |
if sent_path.endswith('.csv'): |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
54 |
PLCGlobals.FileName = sent_path |
4060
d2f5eb3c7d6e
py_ext: fix CSV Writer
Edouard Tisserant <edouard@beremiz.fr>
parents:
4056
diff
changeset
|
55 |
pyext_csv_reload() |
4056
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
56 |
else: |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
57 |
PLCGlobals.CurrentPath = path = sent_path |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
58 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
59 |
ld = listdir(path) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
60 |
ld.sort() |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
61 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
62 |
if path != '/': |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
63 |
FileList = [ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
64 |
{ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
65 |
'name': '..', |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
66 |
'path': dirname(path), |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
67 |
'type': 'folder', |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
68 |
'status': 'active', |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
69 |
'thumbnail': '/files?name=folder.png' |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
70 |
} |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
71 |
] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
72 |
else: |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
73 |
FileList = [] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
74 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
75 |
FileList.extend([ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
76 |
{ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
77 |
'name': f, |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
78 |
'path': join(path, f), |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
79 |
'type': 'folder', |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
80 |
'status': 'active', |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
81 |
'thumbnail': '/files?name=folder.png' |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
82 |
} |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
83 |
for f in ld |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
84 |
if not (isfile(join(path, f)) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
85 |
or f.startswith(".")) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
86 |
]) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
87 |
FileList.extend([ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
88 |
{ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
89 |
'name': f, |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
90 |
'path': join(path, f), |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
91 |
'type': 'file', |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
92 |
'status': 'active', |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
93 |
'thumbnail': '/files?name=file.png' |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
94 |
} |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
95 |
for f in ld |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
96 |
if isfile(join(path, f)) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
97 |
and f.endswith(".csv") |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
98 |
]) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
99 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
100 |
answer = self.renderTable( |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
101 |
FileList, range_feedback, slider_position, visible, extra |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
102 |
) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
103 |
janswer = json.dumps(answer) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
104 |
return janswer.encode() |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
105 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
106 |
def renderTable(self, FileList, old_range, old_position, visible, extra): |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
107 |
if len(extra) > 0 and extra[0] != "": |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
108 |
fFiles = [fl for fl in FileList if extra[0] in fl] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
109 |
else: |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
110 |
fFiles = FileList[:] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
111 |
new_range = len(fFiles) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
112 |
delta = new_range - visible |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
113 |
new_position = 0 if delta <= 0 else delta if old_position > delta else old_position |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
114 |
new_visible = new_range if delta <= 0 else visible |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
115 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
116 |
visible_files = [] |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
117 |
for desc in fFiles[new_position:new_position + new_visible]: |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
118 |
visible_files.append(desc) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
119 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
120 |
return new_range, new_position, visible_files |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
121 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
122 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
123 |
]]></xhtml:p> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
124 |
</globals> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
125 |
<init> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
126 |
<xhtml:p><![CDATA[ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
127 |
]]></xhtml:p> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
128 |
</init> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
129 |
<cleanup> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
130 |
<xhtml:p><![CDATA[ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
131 |
]]></xhtml:p> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
132 |
</cleanup> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
133 |
<start> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
134 |
<xhtml:p><![CDATA[ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
135 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
136 |
AddPathToSVGHMIServers(b"files", FilesJsonResource) |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
137 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
138 |
|
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
139 |
]]></xhtml:p> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
140 |
</start> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
141 |
<stop> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
142 |
<xhtml:p><![CDATA[ |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
143 |
]]></xhtml:p> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
144 |
</stop> |
4b2de1a0fbf9
Extend HMI:JsonTable, create Edit CSV POU, create example, add some doc (#41)
Dino Kosic <44305363+kraskrom@users.noreply.github.com>
parents:
diff
changeset
|
145 |
</PyFile> |