Laurent@814: #!/usr/bin/env python
Laurent@814: # -*- coding: utf-8 -*-
Laurent@814: 
Laurent@814: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
Laurent@814: #based on the plcopen standard. 
Laurent@814: #
Laurent@814: #Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
Laurent@814: #
Laurent@814: #See COPYING file for copyrights details.
Laurent@814: #
Laurent@814: #This library is free software; you can redistribute it and/or
Laurent@814: #modify it under the terms of the GNU General Public
Laurent@814: #License as published by the Free Software Foundation; either
Laurent@814: #version 2.1 of the License, or (at your option) any later version.
Laurent@814: #
Laurent@814: #This library is distributed in the hope that it will be useful,
Laurent@814: #but WITHOUT ANY WARRANTY; without even the implied warranty of
Laurent@814: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Laurent@814: #General Public License for more details.
Laurent@814: #
Laurent@814: #You should have received a copy of the GNU General Public
Laurent@814: #License along with this library; if not, write to the Free Software
Laurent@814: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Laurent@814: 
Laurent@814: import wx
Laurent@814: 
laurent@815: from controls.ProjectPropertiesPanel import ProjectPropertiesPanel
Laurent@814: 
Laurent@814: class ProjectDialog(wx.Dialog):
Laurent@814:     
Laurent@814:     def __init__(self, parent, enable_required=True):
Laurent@814:         wx.Dialog.__init__(self, parent, title=_('Project properties'), 
Laurent@814:               size=wx.Size(500, 350), style=wx.DEFAULT_DIALOG_STYLE)
Laurent@814:         
Laurent@814:         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
Laurent@814:         main_sizer.AddGrowableCol(0)
Laurent@814:         main_sizer.AddGrowableRow(0)
Laurent@814:         
Laurent@814:         self.ProjectProperties = ProjectPropertiesPanel(self, 
Laurent@814:               enable_required=enable_required)
Laurent@814:         main_sizer.AddWindow(self.ProjectProperties, flag=wx.GROW)
Laurent@814:         
Laurent@814:         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
Laurent@814:         self.Bind(wx.EVT_BUTTON, self.OnOK, 
Laurent@814:                   self.ButtonSizer.GetAffirmativeButton())
Laurent@814:         main_sizer.AddSizer(self.ButtonSizer, border=20, 
Laurent@814:               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
Laurent@814:         
Laurent@814:         self.SetSizer(main_sizer)
Laurent@814:         
Laurent@814:     def OnOK(self, event):
Laurent@814:         values = self.ProjectProperties.GetValues()
Laurent@814:         error = []
Laurent@814:         for param, name in [("projectName", "Project Name"),
Laurent@814:                             ("productName", "Product Name"),
Laurent@814:                             ("productVersion", "Product Version"),
Laurent@814:                             ("companyName", "Company Name")]:
Laurent@814:             if values[param] == "":
Laurent@814:                 error.append(name)
Laurent@814:         if len(error) > 0:
Laurent@814:             text = ""
Laurent@814:             for i, item in enumerate(error):
Laurent@814:                 if i == 0:
Laurent@814:                     text += item
Laurent@814:                 elif i == len(error) - 1:
Laurent@814:                     text += " and %s"%item
Laurent@814:                 else:
Laurent@814:                     text += ", %s"%item
Laurent@814:             dialog = wx.MessageDialog(self, 
Laurent@814:                 _("Form isn't complete. %s must be filled!") % text, 
Laurent@814:                 _("Error"), wx.OK|wx.ICON_ERROR)
Laurent@814:             dialog.ShowModal()
Laurent@814:             dialog.Destroy()
Laurent@814:         else:
Laurent@814:             self.EndModal(wx.ID_OK)
Laurent@814: 
Laurent@814:     def SetValues(self, values):
Laurent@814:         self.ProjectProperties.SetValues(values)
Laurent@814:         
Laurent@814:     def GetValues(self):
Laurent@814:         return self.ProjectProperties.GetValues()