author | Dino Kosic <44305363+kraskrom@users.noreply.github.com> |
Mon, 02 Dec 2024 11:33:19 +0100 | |
changeset 4056 | 4b2de1a0fbf9 |
child 4060 | d2f5eb3c7d6e |
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 |
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
|
55 |
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
|
56 |
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
|
57 |
|
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 |
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
|
59 |
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
|
60 |
|
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 |
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
|
62 |
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
|
63 |
{ |
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 |
'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
|
65 |
'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
|
66 |
'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
|
67 |
'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
|
68 |
'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
|
69 |
} |
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 |
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
|
72 |
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
|
73 |
|
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 |
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
|
75 |
{ |
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 |
'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
|
77 |
'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
|
78 |
'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
|
79 |
'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
|
80 |
'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
|
81 |
} |
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 |
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
|
83 |
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
|
84 |
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
|
85 |
]) |
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 |
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
|
87 |
{ |
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 |
'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
|
89 |
'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
|
90 |
'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
|
91 |
'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
|
92 |
'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
|
93 |
} |
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 |
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
|
95 |
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
|
96 |
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
|
97 |
]) |
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 |
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
|
100 |
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
|
101 |
) |
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 |
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
|
103 |
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
|
104 |
|
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 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
|
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 |
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
|
116 |
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
|
117 |
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
|
118 |
|
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 |
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
|
120 |
|
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 |
]]></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
|
123 |
</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
|
124 |
<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
|
125 |
<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
|
126 |
]]></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
|
127 |
</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
|
128 |
<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
|
129 |
<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
|
130 |
]]></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
|
131 |
</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
|
132 |
<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
|
133 |
<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
|
134 |
|
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 |
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
|
136 |
|
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 |
]]></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
|
139 |
</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
|
140 |
<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
|
141 |
<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
|
142 |
]]></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
|
143 |
</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
|
144 |
</PyFile> |