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