dialogs/ConnectionDialog.py
author Laurent Bessard
Sun, 08 Jul 2012 17:48:38 +0200
changeset 722 8c098eb05498
parent 714 131ea7f237b9
permissions -rw-r--r--
Fix bug with graphic viewer and zoom
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     3
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     5
#based on the plcopen standard. 
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     6
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     8
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     9
#See COPYING file for copyrights details.
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    10
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    15
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    19
#General Public License for more details.
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    20
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    24
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    25
import wx
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    26
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    27
from graphics import *
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    28
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    29
#-------------------------------------------------------------------------------
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    30
#                          Create New Connection Dialog
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    31
#-------------------------------------------------------------------------------
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    32
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    33
class ConnectionDialog(wx.Dialog):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    34
    
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    35
    def __init__(self, parent, controller):
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    36
        wx.Dialog.__init__(self, parent,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    37
              size=wx.Size(350, 220), title=_('Connection Properties'))
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    38
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    39
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    40
        main_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    41
        main_sizer.AddGrowableRow(0)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    42
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    43
        column_sizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    44
        main_sizer.AddSizer(column_sizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    45
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    46
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    47
        left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    48
        left_gridsizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    49
        column_sizer.AddSizer(left_gridsizer, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    50
              flag=wx.GROW|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    51
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    52
        type_label = wx.StaticText(self, label=_('Type:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    53
        left_gridsizer.AddWindow(type_label, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    54
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    55
        self.ConnectorRadioButton = wx.RadioButton(self, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    56
              label=_('Connector'), style=wx.RB_GROUP)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    57
        self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.ConnectorRadioButton)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    58
        self.ConnectorRadioButton.SetValue(True)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    59
        left_gridsizer.AddWindow(self.ConnectorRadioButton, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    60
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    61
        self.ConnectionRadioButton = wx.RadioButton(self, label=_('Continuation'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    62
        self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.ConnectionRadioButton)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    63
        left_gridsizer.AddWindow(self.ConnectionRadioButton, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    64
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    65
        name_label = wx.StaticText(self, label=_('Name:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    66
        left_gridsizer.AddWindow(name_label, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    67
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    68
        self.ConnectionName = wx.TextCtrl(self)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    69
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.ConnectionName)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    70
        left_gridsizer.AddWindow(self.ConnectionName, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    71
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    72
        right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    73
        right_gridsizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    74
        right_gridsizer.AddGrowableRow(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    75
        column_sizer.AddSizer(right_gridsizer, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    76
              flag=wx.GROW|wx.LEFT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    77
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    78
        preview_label = wx.StaticText(self, label=_('Preview:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    79
        right_gridsizer.AddWindow(preview_label, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    80
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    81
        self.Preview = wx.Panel(self, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    82
              style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    83
        self.Preview.SetBackgroundColour(wx.Colour(255,255,255))
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    84
        setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    85
        setattr(self.Preview, "GetScaling", lambda:None)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    86
        setattr(self.Preview, "IsOfType", controller.IsOfType)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    87
        self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    88
        right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 534
diff changeset
    89
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    90
        button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    91
        self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    92
        main_sizer.AddSizer(button_sizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    93
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 534
diff changeset
    94
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    95
        self.SetSizer(main_sizer)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    96
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    97
        self.Connection = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    98
        self.MinConnectionSize = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    99
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   100
        self.PouNames = []
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   101
        self.PouElementNames = []
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 534
diff changeset
   102
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   103
        self.ConnectorRadioButton.SetFocus()
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   104
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   105
    def SetPreviewFont(self, font):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   106
        self.Preview.SetFont(font)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   107
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   108
    def SetMinConnectionSize(self, size):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   109
        self.MinConnectionSize = size
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   110
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   111
    def SetValues(self, values):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   112
        for name, value in values.items():
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   113
            if name == "type":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   114
                if value == CONNECTOR:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   115
                    self.ConnectorRadioButton.SetValue(True)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   116
                elif value == CONTINUATION:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   117
                    self.ConnectionRadioButton.SetValue(True)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   118
            elif name == "name":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   119
                self.ConnectionName.SetValue(value)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   120
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   121
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   122
    def GetValues(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   123
        values = {}
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   124
        if self.ConnectorRadioButton.GetValue():
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   125
            values["type"] = CONNECTOR
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   126
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   127
            values["type"] = CONTINUATION
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   128
        values["name"] = self.ConnectionName.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   129
        values["width"], values["height"] = self.Connection.GetSize()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   130
        return values
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   131
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   132
    def SetPouNames(self, pou_names):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   133
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   134
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   135
    def SetPouElementNames(self, element_names):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   136
        self.PouElementNames = [element_name.upper() for element_name in element_names]
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 534
diff changeset
   137
    
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   138
    def OnOK(self, event):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   139
        message = None
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   140
        connection_name = self.ConnectionName.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   141
        if connection_name == "":
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   142
            message = _("Form isn't complete. Name must be filled!")
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   143
        elif not TestIdentifier(connection_name):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   144
            message = _("\"%s\" is not a valid identifier!") % connection_name
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   145
        elif connection_name.upper() in IEC_KEYWORDS:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   146
            message = _("\"%s\" is a keyword. It can't be used!") % connection_name
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   147
        elif connection_name.upper() in self.PouNames:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   148
            message = _("\"%s\" pou already exists!") % connection_name
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   149
        elif connection_name.upper() in self.PouElementNames:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   150
            message = _("\"%s\" element for this pou already exists!") % connection_name
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   151
        if message is not None:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   152
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   153
            dialog.ShowModal()
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   154
            dialog.Destroy()
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   155
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   156
            self.EndModal(wx.ID_OK)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   157
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   158
    def OnTypeChanged(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   159
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   160
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   161
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   162
    def OnNameChanged(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   163
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   164
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   165
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   166
    def RefreshPreview(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   167
        dc = wx.ClientDC(self.Preview)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   168
        dc.SetFont(self.Preview.GetFont())
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   169
        dc.Clear()
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   170
        if self.ConnectorRadioButton.GetValue():
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   171
            self.Connection = FBD_Connector(self.Preview, CONNECTOR, self.ConnectionName.GetValue())
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   172
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   173
            self.Connection = FBD_Connector(self.Preview, CONTINUATION, self.ConnectionName.GetValue())
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   174
        width, height = self.MinConnectionSize
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   175
        min_width, min_height = self.Connection.GetMinSize()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   176
        width, height = max(min_width, width), max(min_height, height)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   177
        self.Connection.SetSize(width, height)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   178
        clientsize = self.Preview.GetClientSize()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   179
        x = (clientsize.width - width) / 2
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   180
        y = (clientsize.height - height) / 2
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   181
        self.Connection.SetPosition(x, y)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   182
        self.Connection.Draw(dc)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   183
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   184
    def OnPaint(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   185
        self.RefreshPreview()
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   186
        event.Skip()