dialogs/ProjectDialog.py
author Laurent Bessard
Fri, 13 Jul 2012 12:42:38 +0200
changeset 725 7c44fc339889
parent 714 131ea7f237b9
permissions -rw-r--r--
Fix bug with FBDBlockDialog on Beremiz
700
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     3
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     6
#
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     8
#
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    10
#
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    15
#
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    20
#
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    24
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    25
import wx
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    26
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    27
from controls import ProjectPropertiesPanel
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    28
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    29
class ProjectDialog(wx.Dialog):
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    30
    
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    31
    def __init__(self, parent, enable_required=True):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    32
        wx.Dialog.__init__(self, parent, title=_('Project properties'), 
700
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    33
              size=wx.Size(500, 350), style=wx.DEFAULT_DIALOG_STYLE)
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    34
        
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    35
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    36
        main_sizer.AddGrowableCol(0)
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    37
        main_sizer.AddGrowableRow(0)
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    38
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    39
        self.ProjectProperties = ProjectPropertiesPanel(self, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    40
              enable_required=enable_required)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    41
        main_sizer.AddWindow(self.ProjectProperties, flag=wx.GROW)
700
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    42
        
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    43
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    44
        self.Bind(wx.EVT_BUTTON, self.OnOK, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    45
                  self.ButtonSizer.GetAffirmativeButton())
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    46
        main_sizer.AddSizer(self.ButtonSizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    47
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
700
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    48
        
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    49
        self.SetSizer(main_sizer)
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    50
        
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    51
    def OnOK(self, event):
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    52
        values = self.ProjectProperties.GetValues()
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    53
        error = []
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    54
        for param, name in [("projectName", "Project Name"),
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    55
                            ("productName", "Product Name"),
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    56
                            ("productVersion", "Product Version"),
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    57
                            ("companyName", "Company Name")]:
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    58
            if values[param] == "":
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    59
                error.append(name)
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    60
        if len(error) > 0:
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    61
            text = ""
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    62
            for i, item in enumerate(error):
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    63
                if i == 0:
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    64
                    text += item
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    65
                elif i == len(error) - 1:
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    66
                    text += " and %s"%item
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    67
                else:
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    68
                    text += ", %s"%item
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    69
            dialog = wx.MessageDialog(self, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    70
                _("Form isn't complete. %s must be filled!") % text, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    71
                _("Error"), wx.OK|wx.ICON_ERROR)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    72
            dialog.ShowModal()
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 700
diff changeset
    73
            dialog.Destroy()
700
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    74
        else:
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    75
            self.EndModal(wx.ID_OK)
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    76
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    77
    def SetValues(self, values):
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    78
        self.ProjectProperties.SetValues(values)
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    79
        
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    80
    def GetValues(self):
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff changeset
    81
        return self.ProjectProperties.GetValues()