Laurent@814: #!/usr/bin/env python
Laurent@814: # -*- coding: utf-8 -*-
Laurent@814: 
andrej@1571: # This file is part of Beremiz, a Integrated Development Environment for
andrej@1571: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
Laurent@814: #
andrej@1571: # Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
andrej@1696: # Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com>
Laurent@814: #
andrej@1571: # See COPYING file for copyrights details.
Laurent@814: #
andrej@1571: # This program is free software; you can redistribute it and/or
andrej@1571: # modify it under the terms of the GNU General Public License
andrej@1571: # as published by the Free Software Foundation; either version 2
andrej@1571: # of the License, or (at your option) any later version.
Laurent@814: #
andrej@1571: # This program is distributed in the hope that it will be useful,
andrej@1571: # but WITHOUT ANY WARRANTY; without even the implied warranty of
andrej@1571: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
andrej@1571: # GNU General Public License for more details.
Laurent@814: #
andrej@1571: # You should have received a copy of the GNU General Public License
andrej@1571: # along with this program; if not, write to the Free Software
andrej@1571: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Laurent@814: 
andrej@1881: 
andrej@1881: from __future__ import absolute_import
Laurent@814: import wx
Laurent@814: 
laurent@815: from controls.ProjectPropertiesPanel import ProjectPropertiesPanel
Laurent@814: 
andrej@1736: 
Laurent@814: class ProjectDialog(wx.Dialog):
andrej@1730: 
Laurent@814:     def __init__(self, parent, enable_required=True):
andrej@1730:         wx.Dialog.__init__(self, parent, title=_('Project properties'),
andrej@1768:                            style=wx.DEFAULT_DIALOG_STYLE)
andrej@1730: 
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)
andrej@1730: 
andrej@1768:         self.ProjectProperties = ProjectPropertiesPanel(
andrej@2228:             self, enable_required=enable_required, scrolling=False)
Laurent@814:         main_sizer.AddWindow(self.ProjectProperties, flag=wx.GROW)
andrej@1730: 
andrej@1745:         self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE)
andrej@1730:         self.Bind(wx.EVT_BUTTON, self.OnOK,
Laurent@814:                   self.ButtonSizer.GetAffirmativeButton())
andrej@1730:         main_sizer.AddSizer(self.ButtonSizer, border=20,
andrej@1768:                             flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)
andrej@1730: 
Laurent@814:         self.SetSizer(main_sizer)
andrej@1696:         self.ProjectProperties.Fit()
andrej@1696:         self.Fit()
andrej@1730: 
Laurent@814:     def OnOK(self, event):
Laurent@814:         values = self.ProjectProperties.GetValues()
Laurent@814:         error = []
andrej@1495:         for param, name in [("projectName", _("Project Name")),
andrej@1495:                             ("productName", _("Product Name")),
andrej@1495:                             ("productVersion", _("Product Version")),
andrej@1495:                             ("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:
andrej@1734:                     text += _(" and %s") % item
Laurent@814:                 else:
andrej@1734:                     text += ", %s" % item
andrej@1768:             dialog = wx.MessageDialog(
andrej@1768:                 self,
andrej@1730:                 _("Form isn't complete. %s must be filled!") % text,
andrej@1745:                 _("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)
andrej@1730: 
Laurent@814:     def GetValues(self):
Laurent@814:         return self.ProjectProperties.GetValues()