author | Laurent Bessard |
Fri, 08 Jun 2012 12:36:24 +0200 | |
changeset 707 | e850bc674852 |
parent 700 | cf3db1775105 |
child 714 | 131ea7f237b9 |
permissions | -rw-r--r-- |
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): |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
32 |
wx.Dialog.__init__(self, id=-1, parent=parent, |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
33 |
name='ProjectDialog', title=_('Project properties'), |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
34 |
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
|
35 |
self.SetClientSize(wx.Size(500, 350)) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
36 |
|
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
37 |
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
|
38 |
main_sizer.AddGrowableCol(0) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
39 |
main_sizer.AddGrowableRow(0) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
40 |
|
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
41 |
self.ProjectProperties = ProjectPropertiesPanel(self, enable_required=enable_required) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
42 |
main_sizer.AddWindow(self.ProjectProperties, 0, border=0, flag=wx.GROW) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
43 |
|
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
44 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
45 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
46 |
main_sizer.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
47 |
|
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
48 |
self.SetSizer(main_sizer) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
49 |
|
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
50 |
def OnOK(self, event): |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
51 |
values = self.ProjectProperties.GetValues() |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
52 |
error = [] |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
53 |
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
|
54 |
("productName", "Product Name"), |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
55 |
("productVersion", "Product Version"), |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
56 |
("companyName", "Company Name")]: |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
57 |
if values[param] == "": |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
58 |
error.append(name) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
59 |
if len(error) > 0: |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
60 |
text = "" |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
61 |
for i, item in enumerate(error): |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
62 |
if i == 0: |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
63 |
text += item |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
64 |
elif i == len(error) - 1: |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
65 |
text += " and %s"%item |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
66 |
else: |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
67 |
text += ", %s"%item |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
68 |
message = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
69 |
message.ShowModal() |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
70 |
message.Destroy() |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
71 |
else: |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
72 |
self.EndModal(wx.ID_OK) |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
73 |
|
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
74 |
def SetValues(self, values): |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
75 |
self.ProjectProperties.SetValues(values) |
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 GetValues(self): |
cf3db1775105
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents:
diff
changeset
|
78 |
return self.ProjectProperties.GetValues() |