author | Edouard Tisserant |
Tue, 23 Apr 2013 20:01:56 +0900 | |
changeset 1049 | ebf53b5f0777 |
parent 814 | 5743cbdff669 |
child 1571 | 486f94a8032c |
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 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
4 |
#This file is part of Beremiz, a Integrated Development Environment for |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
6 |
# |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
8 |
# |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
9 |
#See COPYING file for copyrights details. |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
10 |
# |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
11 |
#This library is free software; you can redistribute it and/or |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
12 |
#modify it under the terms of the GNU General Public |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
13 |
#License as published by the Free Software Foundation; either |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
15 |
# |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
16 |
#This library is distributed in the hope that it will be useful, |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
19 |
#General Public License for more details. |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
20 |
# |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
21 |
#You should have received a copy of the GNU General Public |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
22 |
#License along with this library; if not, write to the Free Software |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
24 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
25 |
import wx |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
26 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
27 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
28 |
class BrowseValuesLibraryDialog(wx.Dialog): |
724 | 29 |
""" |
801
435e49e80832
Update list of messages to be translated for internationalization and french translations
laurent
parents:
724
diff
changeset
|
30 |
Modal dialog that helps in selecting predefined XML attributes sets out of hierarchically organized list |
724 | 31 |
""" |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
32 |
|
724 | 33 |
def __init__(self, parent, name, library, default=None): |
34 |
wx.Dialog.__init__(self, |
|
35 |
name='BrowseValueDialog', parent=parent, |
|
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
36 |
size=wx.Size(600, 400), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, |
801
435e49e80832
Update list of messages to be translated for internationalization and french translations
laurent
parents:
724
diff
changeset
|
37 |
title=_('Browse %s values library') % name) |
724 | 38 |
|
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
39 |
self.SetClientSize(wx.Size(600, 400)) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
40 |
|
724 | 41 |
self.staticText1 = wx.StaticText( |
801
435e49e80832
Update list of messages to be translated for internationalization and french translations
laurent
parents:
724
diff
changeset
|
42 |
label=_('Choose a value for %s:') % name, name='staticText1', parent=self, |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
43 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
44 |
|
724 | 45 |
self.ValuesLibrary = wx.TreeCtrl( |
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
46 |
name='ValuesLibrary', parent=self, pos=wx.Point(0, 0), |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
47 |
size=wx.Size(0, 0), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
48 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
49 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
724 | 50 |
|
51 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
|
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
52 |
|
724 | 53 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
54 |
||
55 |
self.flexGridSizer1.AddWindow(self.staticText1, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
56 |
self.flexGridSizer1.AddWindow(self.ValuesLibrary, 0, border=20, flag=wx.GROW|wx.LEFT|wx.RIGHT) |
|
57 |
self.flexGridSizer1.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
58 |
||
59 |
self.flexGridSizer1.AddGrowableCol(0) |
|
60 |
self.flexGridSizer1.AddGrowableRow(1) |
|
61 |
||
62 |
self.SetSizer(self.flexGridSizer1) |
|
703
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
63 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
64 |
root = self.ValuesLibrary.AddRoot("") |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
65 |
self.GenerateValuesLibraryBranch(root, library, default) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
66 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
67 |
def GenerateValuesLibraryBranch(self, root, children, default): |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
68 |
for infos in children: |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
69 |
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
|
70 |
self.ValuesLibrary.SetPyData(item, infos["infos"]) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
71 |
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
|
72 |
self.ValuesLibrary.SelectItem(item) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
73 |
self.ValuesLibrary.EnsureVisible(item) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
74 |
self.GenerateValuesLibraryBranch(item, infos["children"], default) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
75 |
|
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
76 |
def GetValueInfos(self): |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
77 |
selected = self.ValuesLibrary.GetSelection() |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
78 |
return self.ValuesLibrary.GetPyData(selected) |
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 OnOK(self, event): |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
81 |
selected = self.ValuesLibrary.GetSelection() |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
82 |
if not selected.IsOk() or self.ValuesLibrary.GetPyData(selected) is None: |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
83 |
message = wx.MessageDialog(self, _("No valid value selected!"), _("Error"), wx.OK|wx.ICON_ERROR) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
84 |
message.ShowModal() |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
85 |
message.Destroy() |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
86 |
else: |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
87 |
self.EndModal(wx.ID_OK) |
2f7b3d1de278
Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff
changeset
|
88 |