dialogs/BrowseValuesLibraryDialog.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 09 Aug 2017 14:13:17 +0300
changeset 1724 fde6ad246866
parent 1696 8043f32de7b8
child 1730 64d8f52bc8c8
permissions -rw-r--r--
manual: add untranslated po files for French and Korean
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
2f7b3d1de278 Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff changeset
    26
import wx
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
2f7b3d1de278 Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff changeset
    29
class BrowseValuesLibraryDialog(wx.Dialog):
724
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    30
    """
801
435e49e80832 Update list of messages to be translated for internationalization and french translations
laurent
parents: 724
diff changeset
    31
    Modal dialog that helps in selecting predefined XML attributes sets out of hierarchically organized list
724
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    32
    """    
703
2f7b3d1de278 Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff changeset
    33
724
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    34
    def __init__(self, parent, name, library, default=None):
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    35
        wx.Dialog.__init__(self,
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    36
              name='BrowseValueDialog', parent=parent,
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    37
              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
    38
              title=_('Browse %s values library') % name)
724
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    39
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    40
        self.staticText1 = wx.StaticText(
801
435e49e80832 Update list of messages to be translated for internationalization and french translations
laurent
parents: 724
diff changeset
    41
              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
    42
              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
    43
        
724
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    44
        self.ValuesLibrary = wx.TreeCtrl(
703
2f7b3d1de278 Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff changeset
    45
              name='ValuesLibrary', parent=self, pos=wx.Point(0, 0),
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    46
              size=wx.Size(400, 200), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT)
703
2f7b3d1de278 Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff changeset
    47
        
2f7b3d1de278 Adding support for selecting plugin parameter value from a tree of available values
laurent
parents:
diff changeset
    48
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
724
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    49
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    50
        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
    51
        
724
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    52
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    53
        
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    54
        self.flexGridSizer1.AddWindow(self.staticText1, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    55
        self.flexGridSizer1.AddWindow(self.ValuesLibrary, 0, border=20, flag=wx.GROW|wx.LEFT|wx.RIGHT)
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    56
        self.flexGridSizer1.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    57
    
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    58
        self.flexGridSizer1.AddGrowableCol(0)
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    59
        self.flexGridSizer1.AddGrowableRow(1)
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    60
        
e0630d262ac3 refactoring
Edouard Tisserant
parents: 703
diff changeset
    61
        self.SetSizer(self.flexGridSizer1)
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    62
        self.Fit()
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