author | Edouard Tisserant <edouard@beremiz.fr> |
Fri, 12 Jul 2024 15:36:17 +0200 | |
changeset 3987 | cec48fc7ccd0 |
parent 3789 | 8def429216ca |
permissions | -rw-r--r-- |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
3 |
|
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com> |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
12 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
13 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
14 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
17 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
20 |
# GNU General Public License for more details. |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
22 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
23 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
25 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
26 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
27 |
|
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
28 |
import wx |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
29 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
30 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
31 |
class BrowseValuesLibraryDialog(wx.Dialog): |
724 | 32 |
""" |
801
435e49e80832
Update list of messages to be translated for internationalization and french translations
laurent
parents:
724
diff
changeset
|
33 |
Modal dialog that helps in selecting predefined XML attributes sets out of hierarchically organized list |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
34 |
""" |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
35 |
|
724 | 36 |
def __init__(self, parent, name, library, default=None): |
37 |
wx.Dialog.__init__(self, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
38 |
name='BrowseValueDialog', parent=parent, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
39 |
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
40 |
title=_('Browse %s values library') % name) |
724 | 41 |
|
42 |
self.staticText1 = wx.StaticText( |
|
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
43 |
label=_('Choose a value for %s:') % name, |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
44 |
name='staticText1', parent=self, |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
45 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
46 |
|
724 | 47 |
self.ValuesLibrary = wx.TreeCtrl( |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
48 |
name='ValuesLibrary', parent=self, pos=wx.Point(0, 0), |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
49 |
size=wx.Size(400, 200), |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
50 |
style=wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.SUNKEN_BORDER | wx.TR_HIDE_ROOT | wx.TR_LINES_AT_ROOT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
51 |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
52 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) |
724 | 53 |
|
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
1881
diff
changeset
|
54 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetAffirmativeId()) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
55 |
|
724 | 56 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
57 |
|
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
1881
diff
changeset
|
58 |
self.flexGridSizer1.Add(self.staticText1, 0, border=20, flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) |
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
1881
diff
changeset
|
59 |
self.flexGridSizer1.Add(self.ValuesLibrary, 0, border=20, flag=wx.GROW | wx.LEFT | wx.RIGHT) |
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
1881
diff
changeset
|
60 |
self.flexGridSizer1.Add(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
61 |
|
724 | 62 |
self.flexGridSizer1.AddGrowableCol(0) |
63 |
self.flexGridSizer1.AddGrowableRow(1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
64 |
|
724 | 65 |
self.SetSizer(self.flexGridSizer1) |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
66 |
self.Fit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
67 |
|
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
68 |
root = self.ValuesLibrary.AddRoot("") |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
69 |
self.GenerateValuesLibraryBranch(root, library, default) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
70 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
71 |
def GenerateValuesLibraryBranch(self, root, children, default): |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
72 |
for infos in children: |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
73 |
item = self.ValuesLibrary.AppendItem(root, infos["name"]) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
74 |
self.ValuesLibrary.SetPyData(item, infos["infos"]) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
75 |
if infos["infos"] is not None and infos["infos"] == default: |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
76 |
self.ValuesLibrary.SelectItem(item) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
77 |
self.ValuesLibrary.EnsureVisible(item) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
78 |
self.GenerateValuesLibraryBranch(item, infos["children"], default) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
79 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
80 |
def GetValueInfos(self): |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
81 |
selected = self.ValuesLibrary.GetSelection() |
3789
8def429216ca
fix wxPyDeprecationWarnings
GP Orcullo <kinsamanka@gmail.com>
parents:
3750
diff
changeset
|
82 |
return self.ValuesLibrary.GetItemData(selected) |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
83 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
84 |
def OnOK(self, event): |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
85 |
selected = self.ValuesLibrary.GetSelection() |
3789
8def429216ca
fix wxPyDeprecationWarnings
GP Orcullo <kinsamanka@gmail.com>
parents:
3750
diff
changeset
|
86 |
if not selected.IsOk() or self.ValuesLibrary.GetItemData(selected) is None: |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
87 |
message = wx.MessageDialog(self, _("No valid value selected!"), _("Error"), wx.OK | wx.ICON_ERROR) |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
88 |
message.ShowModal() |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
89 |
message.Destroy() |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
90 |
else: |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
91 |
self.EndModal(wx.ID_OK) |