author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Thu, 24 Nov 2016 15:46:17 +0300 | |
changeset 1577 | 6a3c29fdcfea |
parent 1571 | 486f94a8032c |
child 1696 | 8043f32de7b8 |
permissions | -rw-r--r-- |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
3 |
|
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
6 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
7 |
# Copyright (C) 2013: Edouard TISSERANT and Laurent BESSARD |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
8 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
10 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
15 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
19 |
# GNU General Public License for more details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
20 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
24 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
25 |
import wx |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
26 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
27 |
from plcopen.structures import TestIdentifier, IEC_KEYWORDS |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
28 |
from graphics.GraphicCommons import FREEDRAWING_MODE |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
29 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
30 |
#------------------------------------------------------------------------------- |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
31 |
# Dialog with preview for graphic block |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
32 |
#------------------------------------------------------------------------------- |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
33 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
34 |
""" |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
35 |
Class that implements a generic dialog containing a preview panel for displaying |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
36 |
graphic created by dialog |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
37 |
""" |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
38 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
39 |
class BlockPreviewDialog(wx.Dialog): |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
40 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
41 |
def __init__(self, parent, controller, tagname, size, title): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
42 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
43 |
Constructor |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
44 |
@param parent: Parent wx.Window of dialog for modal |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
45 |
@param controller: Reference to project controller |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
46 |
@param tagname: Tagname of project POU edited |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
47 |
@param size: wx.Size object containing size of dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
48 |
@param title: Title of dialog frame |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
49 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
50 |
wx.Dialog.__init__(self, parent, size=size, title=title) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
51 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
52 |
# Save reference to |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
53 |
self.Controller = controller |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
54 |
self.TagName = tagname |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
55 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
56 |
# Label for preview |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
57 |
self.PreviewLabel = wx.StaticText(self, label=_('Preview:')) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
58 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
59 |
# Create Preview panel |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
60 |
self.Preview = wx.Panel(self, style=wx.SIMPLE_BORDER) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
61 |
self.Preview.SetBackgroundColour(wx.WHITE) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
62 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
63 |
# Add function to preview panel so that it answers to graphic elements |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
64 |
# like Viewer |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
65 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
66 |
setattr(self.Preview, "GetScaling", lambda:None) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
67 |
setattr(self.Preview, "GetBlockType", controller.GetBlockType) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
68 |
setattr(self.Preview, "IsOfType", controller.IsOfType) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
69 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
70 |
# Bind paint event on Preview panel |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
71 |
self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
72 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
73 |
# Add default dialog buttons sizer |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
74 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
75 |
self.Bind(wx.EVT_BUTTON, self.OnOK, |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
76 |
self.ButtonSizer.GetAffirmativeButton()) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
77 |
|
1244 | 78 |
self.Element = None # Graphic element to display in preview |
79 |
self.MinElementSize = None # Graphic element minimal size |
|
80 |
||
81 |
# Variable containing the graphic element name when dialog is opened |
|
82 |
self.DefaultElementName = None |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
83 |
|
1246 | 84 |
# List of variables defined in POU {var_name: (var_class, var_type),...} |
85 |
self.VariableList = {} |
|
86 |
||
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
87 |
def __del__(self): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
88 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
89 |
Destructor |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
90 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
91 |
# Remove reference to project controller |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
92 |
self.Controller = None |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
93 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
94 |
def _init_sizers(self, main_rows, main_growable_row, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
95 |
left_rows, left_growable_row, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
96 |
right_rows, right_growable_row): |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
97 |
""" |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
98 |
Initialize common sizers |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
99 |
@param main_rows: Number of rows in main sizer |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
100 |
@param main_growable_row: Row that is growable in main sizer, None if no |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
101 |
row is growable |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
102 |
@param left_rows: Number of rows in left grid sizer |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
103 |
@param left_growable_row: Row that is growable in left grid sizer, None |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
104 |
if no row is growable |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
105 |
@param right_rows: Number of rows in right grid sizer |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
106 |
@param right_growable_row: Row that is growable in right grid sizer, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
107 |
None if no row is growable |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
108 |
""" |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
109 |
# Create dialog main sizer |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
110 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
111 |
rows=main_rows, vgap=10) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
112 |
self.MainSizer.AddGrowableCol(0) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
113 |
if main_growable_row is not None: |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
114 |
self.MainSizer.AddGrowableRow(main_growable_row) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
115 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
116 |
# Create a sizer for dividing parameters in two columns |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
117 |
column_sizer = wx.BoxSizer(wx.HORIZONTAL) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
118 |
self.MainSizer.AddSizer(column_sizer, border=20, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
119 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
120 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
121 |
# Create a sizer for left column |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
122 |
self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
123 |
rows=left_rows, vgap=5) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
124 |
self.LeftGridSizer.AddGrowableCol(0) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
125 |
if left_growable_row is not None: |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
126 |
self.LeftGridSizer.AddGrowableRow(left_growable_row) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
127 |
column_sizer.AddSizer(self.LeftGridSizer, 1, border=5, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
128 |
flag=wx.GROW|wx.RIGHT) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
129 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
130 |
# Create a sizer for right column |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
131 |
self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
132 |
rows=right_rows, vgap=0) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
133 |
self.RightGridSizer.AddGrowableCol(0) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
134 |
if right_growable_row is not None: |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
135 |
self.RightGridSizer.AddGrowableRow(right_growable_row) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
136 |
column_sizer.AddSizer(self.RightGridSizer, 1, border=5, |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
137 |
flag=wx.GROW|wx.LEFT) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
138 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
139 |
self.SetSizer(self.MainSizer) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
140 |
|
1244 | 141 |
def SetMinElementSize(self, size): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
142 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
143 |
Define minimal graphic element size |
1244 | 144 |
@param size: Tuple containing minimal size (width, height) |
145 |
""" |
|
146 |
self.MinElementSize = size |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
147 |
|
1249 | 148 |
def GetMinElementSize(self): |
149 |
""" |
|
150 |
Get minimal graphic element size |
|
151 |
@return: Tuple containing minimal size (width, height) or None if no |
|
152 |
element defined |
|
153 |
May be overridden by inherited classes |
|
154 |
""" |
|
155 |
if self.Element is None: |
|
156 |
return None |
|
157 |
||
158 |
return self.Element.GetMinSize() |
|
159 |
||
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
160 |
def SetPreviewFont(self, font): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
161 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
162 |
Set font of Preview panel |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
163 |
@param font: wx.Font object containing font style |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
164 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
165 |
self.Preview.SetFont(font) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
166 |
|
1246 | 167 |
def RefreshVariableList(self): |
168 |
""" |
|
169 |
Extract list of variables defined in POU |
|
170 |
""" |
|
171 |
# Get list of variables defined in POU |
|
172 |
self.VariableList = { |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1311
diff
changeset
|
173 |
var.Name: (var.Class, var.Type) |
1246 | 174 |
for var in self.Controller.GetEditedElementInterfaceVars( |
175 |
self.TagName) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1311
diff
changeset
|
176 |
if var.Edit} |
1246 | 177 |
|
178 |
# Add POU name to variable list if POU is a function |
|
179 |
returntype = self.Controller.GetEditedElementInterfaceReturnType( |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1311
diff
changeset
|
180 |
self.TagName) |
1246 | 181 |
if returntype is not None: |
182 |
self.VariableList[ |
|
183 |
self.Controller.GetEditedElementName(self.TagName)] = \ |
|
184 |
("Output", returntype) |
|
185 |
||
186 |
# Add POU name if POU is a transition |
|
187 |
words = self.TagName.split("::") |
|
188 |
if words[0] == "T": |
|
189 |
self.VariableList[words[2]] = ("Output", "BOOL") |
|
190 |
||
1244 | 191 |
def TestElementName(self, element_name): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
192 |
""" |
1245 | 193 |
Test displayed graphic element name |
1244 | 194 |
@param element_name: Graphic element name |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
195 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
196 |
# Variable containing error message format |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
197 |
message_format = None |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
198 |
# Get graphic element name in upper case |
1244 | 199 |
uppercase_element_name = element_name.upper() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
200 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
201 |
# Test if graphic element name is a valid identifier |
1244 | 202 |
if not TestIdentifier(element_name): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
203 |
message_format = _("\"%s\" is not a valid identifier!") |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
204 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
205 |
# Test that graphic element name isn't a keyword |
1244 | 206 |
elif uppercase_element_name in IEC_KEYWORDS: |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
207 |
message_format = _("\"%s\" is a keyword. It can't be used!") |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
208 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
209 |
# Test that graphic element name isn't a POU name |
1244 | 210 |
elif uppercase_element_name in self.Controller.GetProjectPouNames(): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
211 |
message_format = _("\"%s\" pou already exists!") |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
212 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
213 |
# Test that graphic element name isn't already used in POU by a variable |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
214 |
# or another graphic element |
1244 | 215 |
elif ((self.DefaultElementName is None or |
216 |
self.DefaultElementName.upper() != uppercase_element_name) and |
|
217 |
uppercase_element_name in self.Controller.\ |
|
218 |
GetEditedElementVariables(self.TagName)): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
219 |
message_format = _("\"%s\" element for this pou already exists!") |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
220 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
221 |
# If an error have been identify, show error message dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
222 |
if message_format is not None: |
1244 | 223 |
self.ShowErrorMessage(message_format % element_name) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
224 |
# Test failed |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
225 |
return False |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
226 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
227 |
# Test succeed |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
228 |
return True |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
229 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
230 |
def ShowErrorMessage(self, message): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
231 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
232 |
Show an error message dialog over this dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
233 |
@param message: Error message to display |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
234 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
235 |
dialog = wx.MessageDialog(self, message, |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
236 |
_("Error"), |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
237 |
wx.OK|wx.ICON_ERROR) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
238 |
dialog.ShowModal() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
239 |
dialog.Destroy() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
240 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
241 |
def OnOK(self, event): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
242 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
243 |
Called when dialog OK button is pressed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
244 |
Need to be overridden by inherited classes to check that dialog values |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
245 |
are valid |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
246 |
@param event: wx.Event from OK button |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
247 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
248 |
# Close dialog |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
249 |
self.EndModal(wx.ID_OK) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
250 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
251 |
def RefreshPreview(self): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
252 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
253 |
Refresh preview panel of graphic element |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
254 |
May be overridden by inherited classes |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
255 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
256 |
# Init preview panel paint device context |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
257 |
dc = wx.ClientDC(self.Preview) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
258 |
dc.SetFont(self.Preview.GetFont()) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
259 |
dc.Clear() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
260 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
261 |
# Return immediately if no graphic element defined |
1244 | 262 |
if self.Element is None: |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
263 |
return |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
264 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
265 |
# Calculate block size according to graphic element min size due to its |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
266 |
# parameters and graphic element min size defined |
1249 | 267 |
min_width, min_height = self.GetMinElementSize() |
1244 | 268 |
width = max(self.MinElementSize[0], min_width) |
269 |
height = max(self.MinElementSize[1], min_height) |
|
270 |
self.Element.SetSize(width, height) |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
271 |
|
1253
00b7d3c64c80
Fixed bug when centering element in Preview panel
Laurent Bessard
parents:
1252
diff
changeset
|
272 |
# Get element position and bounding box to center in preview |
00b7d3c64c80
Fixed bug when centering element in Preview panel
Laurent Bessard
parents:
1252
diff
changeset
|
273 |
posx, posy = self.Element.GetPosition() |
1252 | 274 |
bbox = self.Element.GetBoundingBox() |
275 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
276 |
# Get Preview panel size |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
277 |
client_size = self.Preview.GetClientSize() |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
278 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
279 |
# If graphic element is too big to be displayed in preview panel, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
280 |
# calculate preview panel scale so that graphic element fit inside |
1252 | 281 |
scale = (max(float(bbox.width) / client_size.width, |
1253
00b7d3c64c80
Fixed bug when centering element in Preview panel
Laurent Bessard
parents:
1252
diff
changeset
|
282 |
float(bbox.height) / client_size.height) * 1.1 |
1252 | 283 |
if bbox.width * 1.1 > client_size.width or |
284 |
bbox.height * 1.1 > client_size.height |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
285 |
else 1.0) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
286 |
dc.SetUserScale(1.0 / scale, 1.0 / scale) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
287 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
288 |
# Center graphic element in preview panel |
1253
00b7d3c64c80
Fixed bug when centering element in Preview panel
Laurent Bessard
parents:
1252
diff
changeset
|
289 |
x = int(client_size.width * scale - bbox.width) / 2 + posx - bbox.x |
00b7d3c64c80
Fixed bug when centering element in Preview panel
Laurent Bessard
parents:
1252
diff
changeset
|
290 |
y = int(client_size.height * scale - bbox.height) / 2 + posy - bbox.y |
1244 | 291 |
self.Element.SetPosition(x, y) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
292 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
293 |
# Draw graphic element |
1244 | 294 |
self.Element.Draw(dc) |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
295 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
296 |
def OnPaint(self, event): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
297 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
298 |
Called when Preview panel need to be redraw |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
299 |
@param event: wx.PaintEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
300 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
301 |
self.RefreshPreview() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
302 |
event.Skip() |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
303 |