-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectPropertiesPanel.py
386 lines (331 loc) · 17.1 KB
/
ProjectPropertiesPanel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of Beremiz, a Integrated Development Environment for
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
#
# Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
# Copyright (C) 2017: Andrey Skvortsov <[email protected]>
#
# See COPYING file for copyrights details.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from __future__ import absolute_import
import wx
from wx.lib.scrolledpanel import ScrolledPanel
from xmlclass.xmlclass import URI_model
# -------------------------------------------------------------------------------
# Helpers
# -------------------------------------------------------------------------------
REQUIRED_PARAMS = ["projectName", "productName", "productVersion", "companyName"]
[
TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
] = range(10)
# -------------------------------------------------------------------------------
# Project Properties Panel
# -------------------------------------------------------------------------------
class ProjectPropertiesPanel(wx.Notebook):
def AddSizerParams(self, parent, sizer, params):
for idx, (name, label) in enumerate(params):
border = 0
if idx == 0:
border |= wx.TOP
elif idx == len(params) - 1:
border |= wx.BOTTOM
st = wx.StaticText(parent, label=label)
sizer.AddWindow(st, border=10,
flag=wx.ALIGN_CENTER_VERTICAL | border | wx.LEFT)
tc = wx.TextCtrl(parent, style=wx.TE_PROCESS_ENTER)
setattr(self, name, tc)
callback = self.GetTextCtrlChangedFunction(tc, name)
self.Bind(wx.EVT_TEXT_ENTER, callback, tc)
tc.Bind(wx.EVT_KILL_FOCUS, callback)
sizer.AddWindow(tc, border=10,
flag=wx.GROW | border | wx.RIGHT)
def __init__(self, parent, controller=None, window=None, enable_required=True, scrolling=True):
wx.Notebook.__init__(self, parent)
self.Controller = controller
self.ParentWindow = window
self.Values = None
# Project Panel elements
self.ProjectPanel = ScrolledPanel(self, style=wx.TAB_TRAVERSAL)
self.ProjectPanel.SetAutoLayout(1)
if scrolling:
self.ProjectPanel.SetupScrolling()
projectpanel_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=5, vgap=15)
projectpanel_sizer.AddGrowableCol(1)
self.ProjectPanel.SetSizer(projectpanel_sizer)
self.AddSizerParams(self.ProjectPanel, projectpanel_sizer,
[("projectName", _('Project Name (required):')),
("projectVersion", _('Project Version (optional):')),
("productName", _('Product Name (required):')),
("productVersion", _('Product Version (required):')),
("productRelease", _('Product Release (optional):'))])
self.AddPage(self.ProjectPanel, _("Project"))
# Author Panel elements
self.AuthorPanel = ScrolledPanel(self, style=wx.TAB_TRAVERSAL)
self.AuthorPanel.SetAutoLayout(1)
if scrolling:
self.AuthorPanel.SetupScrolling()
authorpanel_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=4, vgap=15)
authorpanel_sizer.AddGrowableCol(1)
self.AuthorPanel.SetSizer(authorpanel_sizer)
self.AddSizerParams(self.AuthorPanel, authorpanel_sizer,
[("companyName", _('Company Name (required):')),
("companyURL", _('Company URL (optional):')),
("authorName", _('Author Name (optional):')),
("organization", _('Organization (optional):'))])
self.AddPage(self.AuthorPanel, _("Author"))
# Graphics Panel elements
self.GraphicsPanel = ScrolledPanel(self, style=wx.TAB_TRAVERSAL)
self.GraphicsPanel.SetAutoLayout(1)
if scrolling:
self.GraphicsPanel.SetupScrolling()
graphicpanel_sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=4, vgap=5)
graphicpanel_sizer.AddGrowableCol(0)
graphicpanel_sizer.AddGrowableRow(3)
self.GraphicsPanel.SetSizer(graphicpanel_sizer)
pageSize_st = wx.StaticText(self.GraphicsPanel,
label=_('Page Size (optional):'))
graphicpanel_sizer.AddWindow(
pageSize_st, border=10,
flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.LEFT | wx.RIGHT)
pageSize_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
pageSize_sizer.AddGrowableCol(1)
graphicpanel_sizer.AddSizer(pageSize_sizer, border=10,
flag=wx.GROW | wx.LEFT | wx.RIGHT)
for name, label in [('PageWidth', _('Width:')),
('PageHeight', _('Height:'))]:
st = wx.StaticText(self.GraphicsPanel, label=label)
pageSize_sizer.AddWindow(st, border=12,
flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT)
sp = wx.SpinCtrl(self.GraphicsPanel,
min=0, max=2**16, style=wx.TE_PROCESS_ENTER)
setattr(self, name, sp)
callback = self.GetPageSizeChangedFunction(sp, name)
self.Bind(wx.EVT_TEXT_ENTER, callback, sp)
sp.Bind(wx.EVT_KILL_FOCUS, callback)
pageSize_sizer.AddWindow(sp, flag=wx.GROW)
scaling_st = wx.StaticText(self.GraphicsPanel,
label=_('Grid Resolution:'))
graphicpanel_sizer.AddWindow(scaling_st, border=10,
flag=wx.GROW | wx.LEFT | wx.RIGHT)
scaling_nb = wx.Notebook(self.GraphicsPanel)
graphicpanel_sizer.AddWindow(scaling_nb, border=10,
flag=wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
self.Scalings = {}
for language, translation in [("FBD", _("FBD")), ("LD", _("LD")), ("SFC", _("SFC"))]:
scaling_panel = wx.Panel(scaling_nb, style=wx.TAB_TRAVERSAL)
scalingpanel_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=5)
scalingpanel_sizer.AddGrowableCol(1)
scaling_panel.SetSizer(scalingpanel_sizer)
scaling_controls = []
for idx, (name, label) in enumerate([('XScale', _('Horizontal:')),
('YScale', _('Vertical:'))]):
if idx == 0:
border = wx.TOP
else:
border = wx.BOTTOM
st = wx.StaticText(scaling_panel, label=label)
scalingpanel_sizer.AddWindow(
st, border=10,
flag=wx.ALIGN_CENTER_VERTICAL | border | wx.LEFT)
sp = wx.SpinCtrl(scaling_panel,
min=0, max=2**16, style=wx.TE_PROCESS_ENTER)
scaling_controls.append(sp)
callback = self.GetScalingChangedFunction(sp, language, name)
self.Bind(wx.EVT_TEXT_ENTER, callback, sp)
sp.Bind(wx.EVT_KILL_FOCUS, callback)
scalingpanel_sizer.AddWindow(sp, border=10,
flag=wx.GROW | border | wx.RIGHT)
self.Scalings[language] = scaling_controls
scaling_nb.AddPage(scaling_panel, translation)
self.AddPage(self.GraphicsPanel, _("Graphics"))
# Miscellaneous Panel elements
self.MiscellaneousPanel = ScrolledPanel(parent=self,
name='MiscellaneousPanel',
style=wx.TAB_TRAVERSAL)
self.MiscellaneousPanel.SetAutoLayout(1)
if scrolling:
self.MiscellaneousPanel.SetupScrolling()
miscellaneouspanel_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=15)
miscellaneouspanel_sizer.AddGrowableCol(1)
miscellaneouspanel_sizer.AddGrowableRow(1)
self.MiscellaneousPanel.SetSizer(miscellaneouspanel_sizer)
language_label = wx.StaticText(self.MiscellaneousPanel,
label=_('Language (optional):'))
miscellaneouspanel_sizer.AddWindow(language_label, border=10,
flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.LEFT)
self.Language = wx.ComboBox(self.MiscellaneousPanel,
style=wx.CB_READONLY)
self.Bind(wx.EVT_COMBOBOX, self.OnLanguageChanged, self.Language)
miscellaneouspanel_sizer.AddWindow(self.Language, border=10,
flag=wx.GROW | wx.TOP | wx.RIGHT)
description_label = wx.StaticText(
self.MiscellaneousPanel, label=_('Content Description (optional):'))
miscellaneouspanel_sizer.AddWindow(description_label, border=10,
flag=wx.BOTTOM | wx.LEFT)
self.ContentDescription = wx.TextCtrl(
self.MiscellaneousPanel, size=wx.Size(240, 150),
style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER)
self.Bind(wx.EVT_TEXT_ENTER, self.OnContentDescriptionChanged,
self.ContentDescription)
self.ContentDescription.Bind(wx.EVT_KILL_FOCUS,
self.OnContentDescriptionChanged)
miscellaneouspanel_sizer.AddWindow(self.ContentDescription, border=10,
flag=wx.GROW | wx.BOTTOM | wx.RIGHT)
self.AddPage(self.MiscellaneousPanel, _("Miscellaneous"))
for param in REQUIRED_PARAMS:
getattr(self, param).Enable(enable_required)
languages = ["", "en-US", "fr-FR", "zh-CN", "ru-RU"]
for language in languages:
self.Language.Append(language)
def RefreshView(self):
if self.Controller is not None:
self.SetValues(self.Controller.GetProjectProperties())
def SetValues(self, values):
self.Values = values
for item, value in values.items():
if item == "language":
self.Language.SetStringSelection(value)
elif item == "contentDescription":
self.ContentDescription.SetValue(value)
elif item == "pageSize":
self.PageWidth.SetValue(value[0])
self.PageHeight.SetValue(value[1])
elif item == "scaling":
for language, (x, y) in value.items():
if language in self.Scalings:
self.Scalings[language][0].SetValue(x)
self.Scalings[language][1].SetValue(y)
else:
tc = getattr(self, item, None)
if tc is not None:
tc.SetValue(value)
def GetValues(self):
values = {}
for param in ["projectName", "projectVersion",
"productName", "productVersion",
"productRelease", "companyName",
"companyURL", "authorName",
"organization"]:
value = getattr(self, param).GetValue()
if param in REQUIRED_PARAMS or value != "":
values[param] = value
else:
values[param] = None
language = self.Language.GetStringSelection()
if language != "":
values["language"] = language
else:
values["language"] = None
content_description = self.ContentDescription.GetValue()
if content_description != "":
values["contentDescription"] = content_description
else:
values["contentDescription"] = None
values["pageSize"] = (self.PageWidth.GetValue(), self.PageHeight.GetValue())
values["scaling"] = {}
for language in ["FBD", "LD", "SFC"]:
values["scaling"][language] = (self.Scalings[language][0].GetValue(),
self.Scalings[language][1].GetValue())
return values
def GetTextCtrlChangedFunction(self, textctrl, name):
def TextCtrlChangedFunction(event):
if self.Controller is not None and self.Values is not None:
old_value = self.Values.get(name)
new_value = textctrl.GetValue()
if name in REQUIRED_PARAMS and new_value == "":
new_value = None
if name == 'companyURL':
if not URI_model.match(new_value):
new_value = None
dialog = wx.MessageDialog(self, _('Invalid URL!\n'
'Please enter correct URL address.'),
_("Error"), wx.OK | wx.ICON_ERROR)
dialog.ShowModal()
dialog.Destroy()
if old_value != new_value:
self.Controller.SetProjectProperties(properties={name: new_value})
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU,
PROJECTTREE, PAGETITLES)
wx.CallAfter(self.RefreshView)
event.Skip()
return TextCtrlChangedFunction
def GetPageSizeChangedFunction(self, spinctrl, name):
def PageSizeChangedFunction(event):
if self.Controller is not None:
if self.Values is not None:
old_value = self.Values.get("pageSize")
else:
old_value = (0, 0)
if name == 'PageWidth':
new_value = (spinctrl.GetValue(), old_value[1])
else:
new_value = (old_value[0], spinctrl.GetValue())
if old_value != new_value:
self.Controller.SetProjectProperties(properties={"pageSize": new_value})
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU,
PAGETITLES, SCALING)
wx.CallAfter(self.RefreshView)
event.Skip()
return PageSizeChangedFunction
def GetScalingChangedFunction(self, spinctrl, language, name):
def ScalingChangedFunction(event):
if self.Controller is not None:
old_value = (0, 0)
if self.Values is not None:
scaling = self.Values.get("scaling")
if scaling is not None:
old_value = scaling.get(language)
if name == 'XScale':
new_value = (spinctrl.GetValue(), old_value[1])
else:
new_value = (old_value[0], spinctrl.GetValue())
if old_value != new_value:
self.Controller.SetProjectProperties(properties={"scaling": {language: new_value}})
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU,
PAGETITLES, SCALING)
wx.CallAfter(self.RefreshView)
event.Skip()
return ScalingChangedFunction
def OnLanguageChanged(self, event):
if self.Controller is not None:
if self.Values is not None:
old_value = self.Values.get("language")
else:
old_value = None
new_value = self.Language.GetStringSelection()
if new_value == "":
new_value = None
if old_value != new_value:
self.Controller.SetProjectProperties(properties={"language": new_value})
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES)
wx.CallAfter(self.RefreshView)
event.Skip()
def OnContentDescriptionChanged(self, event):
if self.Controller is not None:
if self.Values is not None:
old_value = self.Values.get("contentDescription")
else:
old_value = None
new_value = self.ContentDescription.GetValue()
if new_value == "":
new_value = None
if old_value != new_value:
self.Controller.SetProjectProperties(properties={"contentDescription": new_value})
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES)
wx.CallAfter(self.RefreshView)
event.Skip()