author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 14 Apr 2020 17:31:45 +0200 | |
branch | svghmi |
changeset 2931 | f51c0e2e0bcb |
parent 2591 | 5f685bcd3ad6 |
child 3303 | 0ffb41625592 |
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 |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com> |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
9 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
10 |
# 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
|
11 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
12 |
# 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
|
13 |
# 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
|
14 |
# 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
|
15 |
# 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
|
16 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
17 |
# 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
|
18 |
# 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
|
19 |
# 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
|
20 |
# 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
|
21 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1347
diff
changeset
|
22 |
# 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
|
23 |
# 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
|
24 |
# 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
|
25 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
26 |
|
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
27 |
from __future__ import absolute_import |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
28 |
from __future__ import division |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
29 |
import wx |
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 |
from plcopen.structures import TestIdentifier, IEC_KEYWORDS |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
32 |
from graphics.GraphicCommons import FREEDRAWING_MODE |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
33 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
34 |
# ------------------------------------------------------------------------------- |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
35 |
# Dialog with preview for graphic block |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
36 |
# ------------------------------------------------------------------------------- |
1236
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): |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
40 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
41 |
Class that implements a generic dialog containing a preview panel for displaying |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
42 |
graphic created by dialog |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
43 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
44 |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
45 |
def __init__(self, parent, controller, tagname, title): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
46 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
47 |
Constructor |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
48 |
@param parent: Parent wx.Window of dialog for modal |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
49 |
@param controller: Reference to project controller |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
50 |
@param tagname: Tagname of project POU edited |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
51 |
@param title: Title of dialog frame |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
52 |
""" |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
53 |
wx.Dialog.__init__(self, parent, title=title) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
54 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
55 |
# Save reference to |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
56 |
self.Controller = controller |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
57 |
self.TagName = tagname |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
58 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
59 |
# Label for preview |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
60 |
self.PreviewLabel = wx.StaticText(self, label=_('Preview:')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
61 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
62 |
# Create Preview panel |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
63 |
self.Preview = wx.Panel(self, style=wx.SIMPLE_BORDER) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
64 |
self.Preview.SetBackgroundColour(wx.WHITE) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
65 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
66 |
# Add function to preview panel so that it answers to graphic elements |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
67 |
# like Viewer |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
68 |
setattr(self.Preview, "GetDrawingMode", lambda: FREEDRAWING_MODE) |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
69 |
setattr(self.Preview, "GetScaling", lambda: None) |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
70 |
setattr(self.Preview, "GetBlockType", controller.GetBlockType) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
71 |
setattr(self.Preview, "IsOfType", controller.IsOfType) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
72 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
73 |
# Bind paint event on Preview panel |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
74 |
self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
75 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
76 |
# Add default dialog buttons sizer |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
77 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
78 |
self.Bind(wx.EVT_BUTTON, self.OnOK, |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
79 |
self.ButtonSizer.GetAffirmativeButton()) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
80 |
|
1244 | 81 |
self.Element = None # Graphic element to display in preview |
82 |
self.MinElementSize = None # Graphic element minimal size |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
83 |
|
1244 | 84 |
# Variable containing the graphic element name when dialog is opened |
85 |
self.DefaultElementName = None |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
86 |
self.Fit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
87 |
|
1246 | 88 |
# List of variables defined in POU {var_name: (var_class, var_type),...} |
89 |
self.VariableList = {} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
90 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
91 |
def __del__(self): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
92 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
93 |
Destructor |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
94 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
95 |
# Remove reference to project controller |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
96 |
self.Controller = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
97 |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
98 |
def _init_sizers(self, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
99 |
main_rows, main_growable_row, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
100 |
left_rows, left_growable_row, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
101 |
right_rows, right_growable_row): |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
102 |
""" |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
103 |
Initialize common sizers |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
104 |
@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
|
105 |
@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
|
106 |
row is growable |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
107 |
@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
|
108 |
@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
|
109 |
if no row is growable |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
110 |
@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
|
111 |
@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
|
112 |
None if no row is growable |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
113 |
""" |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
114 |
# Create dialog main sizer |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
115 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
116 |
rows=main_rows, vgap=10) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
117 |
self.MainSizer.AddGrowableCol(0) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
118 |
if main_growable_row is not None: |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
119 |
self.MainSizer.AddGrowableRow(main_growable_row) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
120 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
121 |
# Create a sizer for dividing parameters in two columns |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
122 |
self.ColumnSizer = wx.BoxSizer(wx.HORIZONTAL) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
123 |
self.MainSizer.AddSizer(self.ColumnSizer, border=20, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
124 |
flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
125 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
126 |
# Create a sizer for left column |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
127 |
self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
128 |
rows=left_rows, vgap=5) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
129 |
self.LeftGridSizer.AddGrowableCol(0) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
130 |
if left_growable_row is not None: |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
131 |
self.LeftGridSizer.AddGrowableRow(left_growable_row) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
132 |
self.ColumnSizer.AddSizer(self.LeftGridSizer, 1, border=5, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
133 |
flag=wx.GROW | wx.RIGHT | wx.EXPAND) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
134 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
135 |
# Create a sizer for right column |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
136 |
self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
137 |
rows=right_rows, vgap=0) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
138 |
self.RightGridSizer.AddGrowableCol(0) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
139 |
if right_growable_row is not None: |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
140 |
self.RightGridSizer.AddGrowableRow(right_growable_row) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
141 |
self.ColumnSizer.AddSizer(self.RightGridSizer, 1, border=5, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
142 |
flag=wx.GROW | wx.LEFT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
143 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
144 |
self.SetSizer(self.MainSizer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
145 |
|
1244 | 146 |
def SetMinElementSize(self, size): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
147 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
148 |
Define minimal graphic element size |
1244 | 149 |
@param size: Tuple containing minimal size (width, height) |
150 |
""" |
|
151 |
self.MinElementSize = size |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
152 |
|
1249 | 153 |
def GetMinElementSize(self): |
154 |
""" |
|
155 |
Get minimal graphic element size |
|
156 |
@return: Tuple containing minimal size (width, height) or None if no |
|
157 |
element defined |
|
158 |
May be overridden by inherited classes |
|
159 |
""" |
|
160 |
if self.Element is None: |
|
161 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
162 |
|
1249 | 163 |
return self.Element.GetMinSize() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
164 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
165 |
def SetPreviewFont(self, font): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
166 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
167 |
Set font of Preview panel |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
168 |
@param font: wx.Font object containing font style |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
169 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
170 |
self.Preview.SetFont(font) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
171 |
|
1246 | 172 |
def RefreshVariableList(self): |
173 |
""" |
|
174 |
Extract list of variables defined in POU |
|
175 |
""" |
|
176 |
# Get list of variables defined in POU |
|
177 |
self.VariableList = { |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1311
diff
changeset
|
178 |
var.Name: (var.Class, var.Type) |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
179 |
for var in self.Controller.GetEditedElementInterfaceVars(self.TagName) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1311
diff
changeset
|
180 |
if var.Edit} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
181 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
182 |
# Add POU name to variable list if POU is a function |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
183 |
returntype = self.Controller.GetEditedElementInterfaceReturnType(self.TagName) |
1246 | 184 |
if returntype is not None: |
185 |
self.VariableList[ |
|
186 |
self.Controller.GetEditedElementName(self.TagName)] = \ |
|
187 |
("Output", returntype) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
188 |
|
1246 | 189 |
# Add POU name if POU is a transition |
190 |
words = self.TagName.split("::") |
|
191 |
if words[0] == "T": |
|
192 |
self.VariableList[words[2]] = ("Output", "BOOL") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
193 |
|
1244 | 194 |
def TestElementName(self, element_name): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
195 |
""" |
1245 | 196 |
Test displayed graphic element name |
1244 | 197 |
@param element_name: Graphic element name |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
198 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
199 |
# Variable containing error message format |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
200 |
message_format = None |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
201 |
# Get graphic element name in upper case |
1244 | 202 |
uppercase_element_name = element_name.upper() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
203 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
204 |
# Test if graphic element name is a valid identifier |
1244 | 205 |
if not TestIdentifier(element_name): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
206 |
message_format = _("\"%s\" is not a valid identifier!") |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
207 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
208 |
# Test that graphic element name isn't a keyword |
1244 | 209 |
elif uppercase_element_name in IEC_KEYWORDS: |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
210 |
message_format = _("\"%s\" is a keyword. It can't be used!") |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
211 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
212 |
# Test that graphic element name isn't a POU name |
1244 | 213 |
elif uppercase_element_name in self.Controller.GetProjectPouNames(): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
214 |
message_format = _("\"%s\" pou already exists!") |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
215 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
216 |
# 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
|
217 |
# or another graphic element |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
218 |
elif ((self.DefaultElementName is None or |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
219 |
self.DefaultElementName.upper() != uppercase_element_name) and |
1764
d5df428640ff
clean-up: fix PEP8 E502 the backslash is redundant between brackets
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
220 |
uppercase_element_name in self.Controller.GetEditedElementVariables(self.TagName)): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
221 |
message_format = _("\"%s\" element for this pou already exists!") |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
222 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
223 |
# If an error have been identify, show error message dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
224 |
if message_format is not None: |
1244 | 225 |
self.ShowErrorMessage(message_format % element_name) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
226 |
# Test failed |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
227 |
return False |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
228 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
229 |
# Test succeed |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
230 |
return True |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
231 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
232 |
def ShowErrorMessage(self, message): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
233 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
234 |
Show an error message dialog over this dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
235 |
@param message: Error message to display |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
236 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
237 |
dialog = wx.MessageDialog(self, message, |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
238 |
_("Error"), |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
239 |
wx.OK | wx.ICON_ERROR) |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
240 |
dialog.ShowModal() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
241 |
dialog.Destroy() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
242 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
243 |
def OnOK(self, event): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
244 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
245 |
Called when dialog OK button is pressed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
246 |
Need to be overridden by inherited classes to check that dialog values |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
247 |
are valid |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
248 |
@param event: wx.Event from OK button |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
249 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
250 |
# Close dialog |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
251 |
self.EndModal(wx.ID_OK) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
252 |
|
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
253 |
def RefreshPreview(self): |
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
254 |
"""Triggers EVT_PAINT event to refresh UI""" |
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
255 |
self.Refresh() |
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
256 |
|
2509
9c5f835b031e
Fix redraw problems in preview frames and debug panel
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2437
diff
changeset
|
257 |
def DrawPreview(self): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
258 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
259 |
Refresh preview panel of graphic element |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
260 |
May be overridden by inherited classes |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
261 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
262 |
# Init preview panel paint device context |
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
263 |
dc = wx.PaintDC(self.Preview) |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
264 |
dc.SetFont(self.Preview.GetFont()) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
265 |
dc.Clear() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
266 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
267 |
# Return immediately if no graphic element defined |
1244 | 268 |
if self.Element is None: |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
269 |
return |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
270 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
271 |
# Calculate block size according to graphic element min size due to its |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
272 |
# parameters and graphic element min size defined |
1249 | 273 |
min_width, min_height = self.GetMinElementSize() |
1244 | 274 |
width = max(self.MinElementSize[0], min_width) |
275 |
height = max(self.MinElementSize[1], min_height) |
|
276 |
self.Element.SetSize(width, height) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
277 |
|
1253
00b7d3c64c80
Fixed bug when centering element in Preview panel
Laurent Bessard
parents:
1252
diff
changeset
|
278 |
# 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
|
279 |
posx, posy = self.Element.GetPosition() |
1252 | 280 |
bbox = self.Element.GetBoundingBox() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
281 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
282 |
# Get Preview panel size |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
283 |
client_size = self.Preview.GetClientSize() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
284 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
285 |
# If graphic element is too big to be displayed in preview panel, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
286 |
# calculate preview panel scale so that graphic element fit inside |
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
287 |
k = 1.1 if (bbox.width * 1.1 > client_size.width or |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
288 |
bbox.height * 1.1 > client_size.height) \ |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
289 |
else 1.0 |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
290 |
scale = (max(bbox.width / client_size.width, |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
291 |
bbox.height / client_size.height) * k) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
292 |
dc.SetUserScale(1.0 / scale, 1.0 / scale) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
293 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
294 |
# Center graphic element in preview panel |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
295 |
x = int(client_size.width * scale - bbox.width) // 2 + posx - bbox.x |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
296 |
y = int(client_size.height * scale - bbox.height) // 2 + posy - bbox.y |
1244 | 297 |
self.Element.SetPosition(x, y) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
298 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
299 |
# Draw graphic element |
1244 | 300 |
self.Element.Draw(dc) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
301 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
302 |
def OnPaint(self, event): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
303 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
304 |
Called when Preview panel need to be redraw |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
305 |
@param event: wx.PaintEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
306 |
""" |
2509
9c5f835b031e
Fix redraw problems in preview frames and debug panel
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2437
diff
changeset
|
307 |
self.DrawPreview() |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
308 |
event.Skip() |