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