author | Laurent Bessard |
Tue, 11 Jun 2013 09:03:35 +0200 | |
changeset 1243 | e77c95c4c7fc |
parent 1242 | ec2c415fc65e |
child 1244 | 336d515096b1 |
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 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
5 |
#based on the plcopen standard. |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
6 |
# |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
7 |
#Copyright (C) 2013: Edouard TISSERANT and Laurent BESSARD |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
8 |
# |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
9 |
#See COPYING file for copyrights details. |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
10 |
# |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
11 |
#This library is free software; you can redistribute it and/or |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
12 |
#modify it under the terms of the GNU General Public |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
13 |
#License as published by the Free Software Foundation; either |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
15 |
# |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
16 |
#This library is distributed in the hope that it will be useful, |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
19 |
#General Public License for more details. |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
20 |
# |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
21 |
#You should have received a copy of the GNU General Public |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
22 |
#License along with this library; if not, write to the Free Software |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
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): |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
40 |
|
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 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
78 |
self.Block = None # Graphic element to display in preview |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
79 |
self.MinBlockSize = None # Graphic element minimal size |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
80 |
self.DefaultBlockName = None # Graphic element name when opening dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
81 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
82 |
def __del__(self): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
83 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
84 |
Destructor |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
85 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
86 |
# Remove reference to project controller |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
87 |
self.Controller = None |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
88 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
89 |
def SetMinBlockSize(self, size): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
90 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
91 |
Define minimal graphic element size |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
92 |
@param size: wx.Size object containing minimal size |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
93 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
94 |
self.MinBlockSize = size |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
95 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
96 |
def SetPreviewFont(self, font): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
97 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
98 |
Set font of Preview panel |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
99 |
@param font: wx.Font object containing font style |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
100 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
101 |
self.Preview.SetFont(font) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
102 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
103 |
def TestBlockName(self, block_name): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
104 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
105 |
Text displayed graphic element name |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
106 |
@param block_name: Graphic element name |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
107 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
108 |
# Variable containing error message format |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
109 |
message_format = None |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
110 |
# Get graphic element name in upper case |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
111 |
uppercase_block_name = block_name.upper() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
112 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
113 |
# Test if graphic element name is a valid identifier |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
114 |
if not TestIdentifier(block_name): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
115 |
message_format = _("\"%s\" is not a valid identifier!") |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
116 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
117 |
# Test that graphic element name isn't a keyword |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
118 |
elif uppercase_block_name in IEC_KEYWORDS: |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
119 |
message_format = _("\"%s\" is a keyword. It can't be used!") |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
120 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
121 |
# Test that graphic element name isn't a POU name |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
122 |
elif uppercase_block_name in self.Controller.GetProjectPouNames(): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
123 |
message_format = _("\"%s\" pou already exists!") |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
124 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
125 |
# 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
|
126 |
# or another graphic element |
1237
0c8b8ef9559b
Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1236
diff
changeset
|
127 |
elif ((self.DefaultBlockName is None or |
0c8b8ef9559b
Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1236
diff
changeset
|
128 |
self.DefaultBlockName.upper() != uppercase_block_name) and |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
129 |
uppercase_block_name in self.Controller.GetEditedElementVariables( |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
130 |
self.TagName)): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
131 |
message_format = _("\"%s\" element for this pou already exists!") |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
132 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
133 |
# If an error have been identify, show error message dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
134 |
if message_format is not None: |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
135 |
self.ShowErrorMessage(message_format % block_name) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
136 |
# Test failed |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
137 |
return False |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
138 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
139 |
# Test succeed |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
140 |
return True |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
141 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
142 |
def ShowErrorMessage(self, message): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
143 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
144 |
Show an error message dialog over this dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
145 |
@param message: Error message to display |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
146 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
147 |
dialog = wx.MessageDialog(self, message, |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
148 |
_("Error"), |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
149 |
wx.OK|wx.ICON_ERROR) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
150 |
dialog.ShowModal() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
151 |
dialog.Destroy() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
152 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
153 |
def OnOK(self, event): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
154 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
155 |
Called when dialog OK button is pressed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
156 |
Need to be overridden by inherited classes to check that dialog values |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
157 |
are valid |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
158 |
@param event: wx.Event from OK button |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
159 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
160 |
# Close dialog |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
161 |
self.EndModal(wx.ID_OK) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
162 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
163 |
def RefreshPreview(self): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
164 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
165 |
Refresh preview panel of graphic element |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
166 |
May be overridden by inherited classes |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
167 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
168 |
# Init preview panel paint device context |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
169 |
dc = wx.ClientDC(self.Preview) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
170 |
dc.SetFont(self.Preview.GetFont()) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
171 |
dc.Clear() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
172 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
173 |
# Return immediately if no graphic element defined |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
174 |
if self.Block is None: |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
175 |
return |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
176 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
177 |
# Calculate block size according to graphic element min size due to its |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
178 |
# parameters and graphic element min size defined |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
179 |
min_width, min_height = self.Block.GetMinSize() |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
180 |
width = max(self.MinBlockSize[0], min_width) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
181 |
height = max(self.MinBlockSize[1], min_height) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
182 |
self.Block.SetSize(width, height) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
183 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
184 |
# Get Preview panel size |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
185 |
client_size = self.Preview.GetClientSize() |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
186 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
187 |
# If graphic element is too big to be displayed in preview panel, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
188 |
# calculate preview panel scale so that graphic element fit inside |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
189 |
scale = (max(float(width) / client_size.width, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
190 |
float(height) / client_size.height) * 1.2 |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
191 |
if width * 1.2 > client_size.width or |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
192 |
height * 1.2 > client_size.height |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
193 |
else 1.0) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
194 |
dc.SetUserScale(1.0 / scale, 1.0 / scale) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
195 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
196 |
# Center graphic element in preview panel |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
197 |
x = int(client_size.width * scale - width) / 2 |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
198 |
y = int(client_size.height * scale - height) / 2 |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
199 |
self.Block.SetPosition(x, y) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
200 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
201 |
# Draw graphic element |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
202 |
self.Block.Draw(dc) |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
203 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
204 |
def OnPaint(self, event): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
205 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
206 |
Called when Preview panel need to be redraw |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
207 |
@param event: wx.PaintEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1241
diff
changeset
|
208 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
209 |
self.RefreshPreview() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
210 |
event.Skip() |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
diff
changeset
|
211 |