PLCOpenEditor.py
author Laurent Bessard
Sun, 03 Jun 2012 23:47:13 +0200
changeset 700 cf3db1775105
parent 699 649399ffdaf0
child 703 1a14560e10ed
permissions -rw-r--r--
Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     3
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     5
#based on the plcopen standard. 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     6
#
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     8
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     9
#See COPYING file for copyrights details.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    10
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5
f8652b073e84 GPL->LGPL
etisserant
parents: 4
diff changeset
    12
#modify it under the terms of the GNU General Public
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    15
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
    19
#General Public License for more details.
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    20
#
5
f8652b073e84 GPL->LGPL
etisserant
parents: 4
diff changeset
    21
#You should have received a copy of the GNU General Public
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    24
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    25
from datetime import datetime
120
add8e391e00c Adding support for wxAUI in wx 2.8
lbessard
parents: 118
diff changeset
    26
import wx, wx.grid
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
    27
import wx.aui
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    28
import os, re, platform, sys, time, traceback, getopt
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    29
import cPickle
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    30
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    31
CWD = os.path.split(os.path.realpath(__file__))[0]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    32
base_folder = os.path.split(CWD)[0]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    33
sys.path.append(base_folder)
682
4d437bc0ef3f refactoring
Edouard Tisserant
parents: 680
diff changeset
    34
from docutil import *
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    35
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    36
from types import TupleType
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    37
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    38
__version__ = "$Revision: 1.130 $"
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    39
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    40
if __name__ == '__main__':
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    41
    # Usage message displayed when help request or when error detected in 
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    42
    # command line
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    43
    def usage():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    44
        print "\nUsage of PLCOpenEditor.py :"
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    45
        print "\n   %s [Filepath]\n"%sys.argv[0]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    46
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    47
    # Parse options given to PLCOpenEditor in command line
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    48
    try:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    49
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    50
    except getopt.GetoptError:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    51
        # print help information and exit:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    52
        usage()
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    53
        sys.exit(2)
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    54
    
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    55
    # Extract if help has been requested
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    56
    for o, a in opts:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    57
        if o in ("-h", "--help"):
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    58
            usage()
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    59
            sys.exit()
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    60
    
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    61
    # Extract the optional filename to open
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    62
    fileOpen = None
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    63
    if len(args) > 1:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    64
        usage()
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    65
        sys.exit()
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    66
    elif len(args) == 1:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    67
        fileOpen = args[0]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    68
    
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    69
    # Create wxApp (Need to create App before internationalization because of
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    70
    # Windows) 
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    71
    app = wx.PySimpleApp()
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    72
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    73
# Import module for internationalization
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    74
import gettext
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    75
import __builtin__
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    76
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    77
# Get folder containing translation files
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    78
localedir = os.path.join(CWD,"locale")
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    79
# Get the default language
537
a31bf722aa82 Fix wire disappearing when wire tip and connector are not exactly at the same position fixed.
laurent
parents: 535
diff changeset
    80
langid = wx.LANGUAGE_DEFAULT
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    81
# Define translation domain (name of translation files)
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    82
domain = "PLCOpenEditor"
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    83
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    84
# Define locale for wx
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    85
loc = __builtin__.__dict__.get('loc', None)
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    86
if loc is None:
513
fb787f6cbe33 Adding support for disable language translation when default language not available in locale
laurent
parents: 512
diff changeset
    87
    test_loc = wx.Locale(langid)
fb787f6cbe33 Adding support for disable language translation when default language not available in locale
laurent
parents: 512
diff changeset
    88
    test_loc.AddCatalogLookupPathPrefix(localedir)
fb787f6cbe33 Adding support for disable language translation when default language not available in locale
laurent
parents: 512
diff changeset
    89
    if test_loc.AddCatalog(domain):
fb787f6cbe33 Adding support for disable language translation when default language not available in locale
laurent
parents: 512
diff changeset
    90
        loc = wx.Locale(langid)
fb787f6cbe33 Adding support for disable language translation when default language not available in locale
laurent
parents: 512
diff changeset
    91
    else:
fb787f6cbe33 Adding support for disable language translation when default language not available in locale
laurent
parents: 512
diff changeset
    92
        loc = wx.Locale(wx.LANGUAGE_ENGLISH)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    93
    __builtin__.__dict__['loc'] = loc
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    94
# Define location for searching translation files
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    95
loc.AddCatalogLookupPathPrefix(localedir)
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    96
# Define locale domain
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    97
loc.AddCatalog(domain)
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    98
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
    99
if __name__ == '__main__':
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   100
    __builtin__.__dict__['_'] = wx.GetTranslation
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   101
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   102
from SFCViewer import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   103
from LDViewer import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   104
from Viewer import *
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   105
from TextViewer import *
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents: 298
diff changeset
   106
from GraphicViewer import *
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   107
from RessourceEditor import *
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
   108
from DataTypeEditor import *
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   109
from PLCControler import *
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   110
from SearchResultPanel import SearchResultPanel
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   111
from controls import CustomGrid, CustomTable, CustomTree, LibraryPanel, PouInstanceVariablesPanel
700
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents: 699
diff changeset
   112
from dialogs import ProjectDialog
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   113
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   114
# Define PLCOpenEditor controls id
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   115
[ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK, 
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   116
 ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK, 
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   117
 ID_PLCOPENEDITORPROJECTTREE, ID_PLCOPENEDITORMAINSPLITTER, 
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   118
 ID_PLCOPENEDITORSECONDSPLITTER, ID_PLCOPENEDITORTHIRDSPLITTER, 
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   119
 ID_PLCOPENEDITORLIBRARYPANEL, ID_PLCOPENEDITORLIBRARYSEARCHCTRL, 
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   120
 ID_PLCOPENEDITORLIBRARYTREE, ID_PLCOPENEDITORLIBRARYCOMMENT, 
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   121
 ID_PLCOPENEDITORTABSOPENED, ID_PLCOPENEDITORTABSOPENED, 
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   122
 ID_PLCOPENEDITOREDITORMENUTOOLBAR, ID_PLCOPENEDITOREDITORTOOLBAR, 
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   123
 ID_PLCOPENEDITORPROJECTPANEL, 
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   124
] = [wx.NewId() for _init_ctrls in range(17)]
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   125
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   126
# Define PLCOpenEditor FileMenu extra items id
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   127
[ID_PLCOPENEDITORFILEMENUGENERATE, 
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   128
] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)]
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   129
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   130
# Define PLCOpenEditor EditMenu extra items id
350
f7958989e055 Adding support for Enable/Disable Undo/Redo
greg
parents: 347
diff changeset
   131
[ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, ID_PLCOPENEDITOREDITMENUADDDATATYPE, 
f7958989e055 Adding support for Enable/Disable Undo/Redo
greg
parents: 347
diff changeset
   132
 ID_PLCOPENEDITOREDITMENUADDFUNCTION, ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK, 
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   133
 ID_PLCOPENEDITOREDITMENUADDPROGRAM, ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   134
 ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   135
] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   136
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   137
# Define PLCOpenEditor DisplayMenu extra items id
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   138
[ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE, 
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   139
] = [wx.NewId() for _init_coll_DisplayMenu_Items in range(1)]
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   140
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   141
#-------------------------------------------------------------------------------
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   142
#                            EditorToolBar definitions
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   143
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   144
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   145
# Define PLCOpenEditor Toolbar items id
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   146
[ID_PLCOPENEDITOREDITORTOOLBARSELECTION, ID_PLCOPENEDITOREDITORTOOLBARCOMMENT,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   147
 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, ID_PLCOPENEDITOREDITORTOOLBARBLOCK,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   148
 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, ID_PLCOPENEDITOREDITORTOOLBARWIRE,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   149
 ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITOREDITORTOOLBARRUNG,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   150
 ID_PLCOPENEDITOREDITORTOOLBARCOIL, ID_PLCOPENEDITOREDITORTOOLBARCONTACT,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   151
 ID_PLCOPENEDITOREDITORTOOLBARBRANCH, ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   152
 ID_PLCOPENEDITOREDITORTOOLBARSTEP, ID_PLCOPENEDITOREDITORTOOLBARTRANSITION,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   153
 ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   154
 ID_PLCOPENEDITOREDITORTOOLBARJUMP, ID_PLCOPENEDITOREDITORTOOLBARMOTION, 
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   155
] = [wx.NewId() for _init_coll_DefaultEditorToolBar_Items in range(18)]
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   156
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   157
# Define behaviour of each Toolbar item according to current POU body type 
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   158
# Informations meaning are in this order:
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   159
#  - Item is toggled
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   160
#  - PLCOpenEditor mode where item is displayed (could be more then one)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   161
#  - Item id
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   162
#  - Item callback function name
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   163
#  - Item icon filename
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   164
#  - Item tooltip text
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   165
EditorToolBarItems = {
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   166
    "FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   167
              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
   168
              "move.png", _("Move the view")),
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
   169
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   170
              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   171
              "add_comment.png", _("Create a new comment")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   172
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   173
              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   174
              "add_variable.png", _("Create a new variable")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   175
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   176
              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   177
              "add_block.png", _("Create a new block")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   178
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   179
              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   180
              "add_connection.png", _("Create a new connection"))],
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
   181
    "LD"  : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   182
              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
   183
              "move.png", _("Move the view")),
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
   184
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   185
              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   186
              "add_comment.png", _("Create a new comment")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   187
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   188
              ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   189
              "add_powerrail.png", _("Create a new power rail")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   190
             (False, DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   191
              ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   192
              "add_rung.png", _("Create a new rung")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   193
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   194
              ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   195
              "add_coil.png", _("Create a new coil")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   196
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   197
              ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   198
              "add_contact.png", _("Create a new contact")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   199
             (False, DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   200
              ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   201
              "add_branch.png", _("Create a new branch")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   202
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   203
              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   204
              "add_variable.png", _("Create a new variable")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   205
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   206
              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   207
              "add_block.png", _("Create a new block")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   208
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   209
              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   210
              "add_connection.png", _("Create a new connection"))],
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
   211
    "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   212
              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
   213
              "move.png", _("Move the view")),
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
   214
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   215
              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   216
              "add_comment.png", _("Create a new comment")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   217
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   218
              ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   219
              "add_initial_step.png", _("Create a new initial step")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   220
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   221
              ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   222
              "add_step.png", _("Create a new step")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   223
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   224
              ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   225
              "add_transition.png", _("Create a new transition")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   226
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   227
              ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   228
              "add_action.png", _("Create a new action block")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   229
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   230
              ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   231
              "add_divergence.png", _("Create a new divergence")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   232
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   233
              ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   234
              "add_jump.png", _("Create a new jump")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   235
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   236
              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   237
              "add_variable.png", _("Create a new variable")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   238
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   239
              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   240
              "add_block.png", _("Create a new block")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   241
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   242
              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   243
              "add_connection.png", _("Create a new connection")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   244
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   245
              ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   246
              "add_powerrail.png", _("Create a new power rail")),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   247
             (True, FREEDRAWING_MODE, 
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   248
              ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   249
              "add_contact.png", _("Create a new contact"))],
82
119b62c73085 PLCOpenEditor SplitterWindow names changed
lbessard
parents: 80
diff changeset
   250
    "ST"  : [],
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   251
    "IL"  : [],
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   252
    "debug": [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   253
              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   254
              "move.png", _("Move the view"))],
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   255
}
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   256
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   257
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   258
#                               Helper Functions
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   259
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   260
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   261
# Compatibility function for wx versions < 2.6
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   262
def AppendMenu(parent, help, id, kind, text):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   263
    if wx.VERSION >= (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   264
        parent.Append(help=help, id=id, kind=kind, text=text)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   265
    else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   266
        parent.Append(helpString=help, id=id, kind=kind, item=text)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   267
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   268
[TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, 
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   269
 POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   270
] = range(10)
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   271
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   272
def GetShortcutKeyCallbackFunction(viewer_function):
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   273
    def ShortcutKeyFunction(self, event):
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   274
        control = self.FindFocus()
599
4bb7b132e15d Fixing standard functions library treectrl in library panel in order to make it similar on all platforms
laurent
parents: 587
diff changeset
   275
        if control is not None and control.GetName() in ["Viewer", "TextViewer"]:
699
649399ffdaf0 Fix bug with cut/copy/paste on PythonEditor
Laurent Bessard
parents: 695
diff changeset
   276
            getattr(control.ParentWindow, viewer_function)()
587
98445f90f45d Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 586
diff changeset
   277
        elif isinstance(control, wx.stc.StyledTextCtrl):
98445f90f45d Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 586
diff changeset
   278
            getattr(control, viewer_function)()
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   279
        elif isinstance(control, wx.TextCtrl):
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   280
            control.ProcessEvent(event)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   281
    return ShortcutKeyFunction
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   282
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   283
def GetDeleteElementFunction(remove_function, parent_type=None, check_function=None):
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   284
    def DeleteElementFunction(self, selected):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   285
        name = self.ProjectTree.GetItemText(selected)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   286
        if check_function is None or not check_function(self.Controler, name):
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   287
            if parent_type is not None:
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   288
                item_infos = self.ProjectTree.GetPyData(selected)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   289
                parent_name = item_infos["tagname"].split("::")[1]
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   290
                remove_function(self.Controler, parent_name, name)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   291
            else:
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   292
                remove_function(self.Controler, name)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   293
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   294
            self.ShowErrorMessage(_("\"%s\" is used by one or more POUs. It can't be removed!")%name)
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   295
    return DeleteElementFunction
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   296
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   297
if wx.Platform == '__WXMSW__':
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   298
    TAB_BORDER = 6
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   299
    NOTEBOOK_BORDER = 6
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   300
else:
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   301
    TAB_BORDER = 7
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   302
    NOTEBOOK_BORDER = 2
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   303
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   304
def SimplifyTabLayout(tabs, rect):
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   305
    for tab in tabs:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   306
        if tab["pos"][0] == rect.x:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   307
            others = [t for t in tabs if t != tab]
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   308
            others.sort(lambda x,y: cmp(x["pos"][0], y["pos"][0]))
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   309
            for other in others:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   310
                if (other["pos"][1] == tab["pos"][1] and 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   311
                    other["size"][1] == tab["size"][1] and
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   312
                    other["pos"][0] == tab["pos"][0] + tab["size"][0] + TAB_BORDER):
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   313
                    
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   314
                    tab["size"] = (tab["size"][0] + other["size"][0] + TAB_BORDER, tab["size"][1])
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   315
                    tab["pages"].extend(other["pages"])
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   316
                    tabs.remove(other)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   317
                    
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   318
                    if tab["size"][0] == rect.width:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   319
                        return True
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   320
                    
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   321
        elif tab["pos"][1] == rect.y:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   322
            others = [t for t in tabs if t != tab]
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   323
            others.sort(lambda x,y: cmp(x["pos"][1], y["pos"][1]))
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   324
            for other in others:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   325
                if (other["pos"][0] == tab["pos"][0] and 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   326
                    other["size"][0] == tab["size"][0] and
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   327
                    other["pos"][1] == tab["pos"][1] + tab["size"][1] + TAB_BORDER):
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   328
                    
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   329
                    tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + TAB_BORDER)
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   330
                    tab["pages"].extend(other["pages"])
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   331
                    tabs.remove(other)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   332
                    
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   333
                    if tab["size"][1] == rect.height:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   334
                        return True
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   335
    return False
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   336
    
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   337
def ComputeTabsLayout(tabs, rect):
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   338
    if len(tabs) == 0:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   339
        return tabs
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   340
    if len(tabs) == 1:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   341
        return tabs[0]
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   342
    split = None
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   343
    for idx, tab in enumerate(tabs):
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   344
        if len(tab["pages"]) == 0:
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   345
        	raise "Not possible"
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   346
        if tab["size"][0] == rect.width:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   347
            if tab["pos"][1] == rect.y:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   348
                split = (wx.TOP, float(tab["size"][1]) / float(rect.height))
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   349
                split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER, 
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   350
                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   351
            elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   352
                split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height))
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   353
                split_rect = wx.Rect(rect.x, rect.y, 
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   354
                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   355
            break
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   356
        elif tab["size"][1] == rect.height:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   357
            if tab["pos"][0] == rect.x:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   358
                split = (wx.LEFT, float(tab["size"][0]) / float(rect.width))
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   359
                split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y, 
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   360
                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   361
            elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   362
                split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width))
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   363
                split_rect = wx.Rect(rect.x, rect.y, 
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   364
                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   365
            break
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   366
    if split != None:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   367
        split_tab = tabs.pop(idx)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   368
        return {"split": split,
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   369
                "tab": split_tab, 
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   370
                "others": ComputeTabsLayout(tabs, split_rect)}
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   371
    else:
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   372
        if SimplifyTabLayout(tabs, rect):
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   373
            return ComputeTabsLayout(tabs, rect)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   374
    return tabs
401
d3f086b0da30 Bug with TabsImageList wrong image size definition fixed
laurent
parents: 397
diff changeset
   375
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   376
#-------------------------------------------------------------------------------
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   377
#                              IDEFrame Base Class
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   378
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   379
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   380
UNEDITABLE_NAMES_DICT = dict([(_(name), name) for name in UNEDITABLE_NAMES])
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   381
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   382
class IDEFrame(wx.Frame):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   383
    
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   384
    Starting = False
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   385
    
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
   386
    # Compatibility function for wx versions < 2.6
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   387
    if wx.VERSION < (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   388
        def Bind(self, event, function, id = None):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   389
            if id is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   390
                event(self, id, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   391
            else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   392
                event(self, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
   393
    
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   394
    def _init_coll_MenuBar_Menus(self, parent):
587
98445f90f45d Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 586
diff changeset
   395
        parent.Append(menu=self.FileMenu, title=_(u'&File'))
98445f90f45d Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 586
diff changeset
   396
        parent.Append(menu=self.EditMenu, title=_(u'&Edit'))
98445f90f45d Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 586
diff changeset
   397
        parent.Append(menu=self.DisplayMenu, title=_(u'&Display'))
98445f90f45d Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 586
diff changeset
   398
        parent.Append(menu=self.HelpMenu, title=_(u'&Help'))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   399
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   400
    def _init_coll_FileMenu_Items(self, parent):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   401
        pass
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   402
    
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   403
    def _init_coll_AddMenu_Items(self, parent, add_config=True):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   404
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDDATATYPE,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   405
              kind=wx.ITEM_NORMAL, text=_(u'&Data Type'))
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   406
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTION,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   407
              kind=wx.ITEM_NORMAL, text=_(u'&Function'))
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   408
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   409
              kind=wx.ITEM_NORMAL, text=_(u'Function &Block'))
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   410
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDPROGRAM,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   411
              kind=wx.ITEM_NORMAL, text=_(u'&Program'))
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   412
        if add_config:
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   413
            AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   414
                  kind=wx.ITEM_NORMAL, text=_(u'&Configuration'))
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   415
    
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   416
    def _init_coll_EditMenu_Items(self, parent):
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   417
        AppendMenu(parent, help='', id=wx.ID_UNDO,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   418
              kind=wx.ITEM_NORMAL, text=_(u'Undo\tCTRL+Z'))
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   419
        AppendMenu(parent, help='', id=wx.ID_REDO,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   420
              kind=wx.ITEM_NORMAL, text=_(u'Redo\tCTRL+Y'))
559
984c51d1bf6b Fix PrintPreview behavior
laurent
parents: 555
diff changeset
   421
        #AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO,
984c51d1bf6b Fix PrintPreview behavior
laurent
parents: 555
diff changeset
   422
        #      kind=wx.ITEM_CHECK, text=_(u'Enable Undo/Redo'))
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 559
diff changeset
   423
        enable_undo_redo = _(u'Enable Undo/Redo') # Keeping text in translations for possible menu reactivation
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   424
        parent.AppendSeparator()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   425
        AppendMenu(parent, help='', id=wx.ID_CUT,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   426
              kind=wx.ITEM_NORMAL, text=_(u'Cut\tCTRL+X'))
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   427
        AppendMenu(parent, help='', id=wx.ID_COPY,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   428
              kind=wx.ITEM_NORMAL, text=_(u'Copy\tCTRL+C'))
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   429
        AppendMenu(parent, help='', id=wx.ID_PASTE,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   430
              kind=wx.ITEM_NORMAL, text=_(u'Paste\tCTRL+V'))
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   431
        parent.AppendSeparator()
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   432
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT,
656
ff38b7250b64 Added a few shortcuts in menus
Edouard Tisserant
parents: 654
diff changeset
   433
              kind=wx.ITEM_NORMAL, text=_(u'Search in Project\tCTRL+F'))
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   434
        parent.AppendSeparator()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   435
        add_menu = wx.Menu(title='')
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   436
        self._init_coll_AddMenu_Items(add_menu)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   437
        parent.AppendMenu(wx.ID_ADD, _(u"&Add Element"), add_menu)
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   438
        AppendMenu(parent, help='', id=wx.ID_SELECTALL,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   439
              kind=wx.ITEM_NORMAL, text=_(u'Select All\tCTRL+A'))
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   440
        AppendMenu(parent, help='', id=wx.ID_DELETE,
656
ff38b7250b64 Added a few shortcuts in menus
Edouard Tisserant
parents: 654
diff changeset
   441
              kind=wx.ITEM_NORMAL, text=_(u'&Delete'))
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   442
        self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   443
        self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
562
0ce12552cf36 Fix bug on Windows after removing "Enable Undo/Redo" menu item
laurent
parents: 560
diff changeset
   444
        #self.Bind(wx.EVT_MENU, self.OnEnableUndoRedoMenu, id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO)
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   445
        self.Bind(wx.EVT_MENU, self.OnCutMenu, id=wx.ID_CUT)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   446
        self.Bind(wx.EVT_MENU, self.OnCopyMenu, id=wx.ID_COPY)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   447
        self.Bind(wx.EVT_MENU, self.OnPasteMenu, id=wx.ID_PASTE)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   448
        self.Bind(wx.EVT_MENU, self.OnSearchInProjectMenu, 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   449
              id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT)
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   450
        self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu,
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   451
              id=ID_PLCOPENEDITOREDITMENUADDDATATYPE)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   452
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("function"),
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   453
              id=ID_PLCOPENEDITOREDITMENUADDFUNCTION)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   454
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("functionBlock"),
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   455
              id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   456
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("program"),
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   457
              id=ID_PLCOPENEDITOREDITMENUADDPROGRAM)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   458
        self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu,
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   459
              id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   460
        self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   461
        self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   462
        
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   463
        self.AddToMenuToolBar([(wx.ID_UNDO, "undo.png", _(u'Undo'), None),
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   464
                               (wx.ID_REDO, "redo.png", _(u'Redo'), None),
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   465
                               None,
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   466
                               (wx.ID_CUT, "cut.png", _(u'Cut'), None),
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   467
                               (wx.ID_COPY, "copy.png", _(u'Copy'), None),
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   468
                               (wx.ID_PASTE, "paste.png", _(u'Paste'), None),
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   469
                               None,
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   470
                               (ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find.png", _(u'Search in Project'), None)])
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   471
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   472
    def _init_coll_DisplayMenu_Items(self, parent):
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   473
        AppendMenu(parent, help='', id=wx.ID_REFRESH,
569
4ce166451816 Changed F5 shortcut to CTRL+R for refresh
Edouard Tisserant
parents: 563
diff changeset
   474
              kind=wx.ITEM_NORMAL, text=_(u'Refresh\tCTRL+R'))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   475
        if self.EnableDebug:
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   476
            AppendMenu(parent, help='', id=wx.ID_CLEAR,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   477
                  kind=wx.ITEM_NORMAL, text=_(u'Clear Errors\tCTRL+K'))
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   478
        parent.AppendSeparator()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   479
        zoommenu = wx.Menu(title='')
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
   480
        parent.AppendMenu(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   481
        for idx, value in enumerate(ZOOM_FACTORS):
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   482
            new_id = wx.NewId()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   483
            AppendMenu(zoommenu, help='', id=new_id,
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   484
                  kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   485
            self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), id=new_id)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   486
        
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   487
        parent.AppendSeparator()
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   488
        AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   489
              kind=wx.ITEM_NORMAL, text=_(u'Reset Perspective'))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   490
        self.Bind(wx.EVT_MENU, self.OnResetPerspective, id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   491
        
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   492
        self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   493
        if self.EnableDebug:
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   494
            self.Bind(wx.EVT_MENU, self.OnClearErrorsMenu, id=wx.ID_CLEAR)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   495
            
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   496
    def _init_coll_HelpMenu_Items(self, parent):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   497
        pass
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   498
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   499
    def _init_utils(self):
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   500
        self.MenuBar = wx.MenuBar()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   501
220
127d1323e5e0 Added File menu, even in non-solo mode.
etisserant
parents: 219
diff changeset
   502
        self.FileMenu = wx.Menu(title='')
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   503
        self.EditMenu = wx.Menu(title='')
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   504
        self.DisplayMenu = wx.Menu(title='')
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   505
        self.HelpMenu = wx.Menu(title='')
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
   506
        
185
fdc8a59b02bd Adding icon to menus
lbessard
parents: 184
diff changeset
   507
        self._init_coll_MenuBar_Menus(self.MenuBar)
220
127d1323e5e0 Added File menu, even in non-solo mode.
etisserant
parents: 219
diff changeset
   508
        self._init_coll_FileMenu_Items(self.FileMenu)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   509
        self._init_coll_EditMenu_Items(self.EditMenu)
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   510
        self._init_coll_DisplayMenu_Items(self.DisplayMenu)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   511
        self._init_coll_HelpMenu_Items(self.HelpMenu)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   512
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
    def _init_ctrls(self, prnt):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   514
        wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name='IDEFrame',
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   515
              parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600),
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   516
              style=wx.DEFAULT_FRAME_STYLE)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   517
        self.SetClientSize(wx.Size(1000, 600))
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   518
        self.Bind(wx.EVT_ACTIVATE, self.OnActivated)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   519
        self.Bind(wx.EVT_SIZE, self.OnResize)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   520
        
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   521
        self.TabsImageList = wx.ImageList(31, 16)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   522
        self.TabsImageListIndexes = {}
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   523
        
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   524
        #-----------------------------------------------------------------------
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   525
        #                          Creating main structure
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   526
        #-----------------------------------------------------------------------
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   527
        
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   528
        self.AUIManager = wx.aui.AuiManager(self)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   529
        self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   530
        self.Panes = {}
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   531
        
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   532
        self.LeftNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORLEFTNOTEBOOK,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   533
              style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE|
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   534
                    wx.aui.AUI_NB_SCROLL_BUTTONS|wx.aui.AUI_NB_TAB_EXTERNAL_MOVE)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   535
        self.LeftNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   536
                self.OnAllowNotebookDnD)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   537
        self.AUIManager.AddPane(self.LeftNoteBook, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   538
              wx.aui.AuiPaneInfo().Name("ProjectPane").
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   539
              Left().Layer(1).
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   540
              BestSize(wx.Size(300, 500)).CloseButton(False))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   541
        
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   542
        self.BottomNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORBOTTOMNOTEBOOK,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   543
              style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE|
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   544
                    wx.aui.AUI_NB_SCROLL_BUTTONS|wx.aui.AUI_NB_TAB_EXTERNAL_MOVE)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   545
        self.BottomNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   546
                self.OnAllowNotebookDnD)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   547
        self.AUIManager.AddPane(self.BottomNoteBook, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   548
              wx.aui.AuiPaneInfo().Name("ResultPane").
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   549
              Bottom().Layer(0).
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   550
              BestSize(wx.Size(800, 300)).CloseButton(False))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   551
        
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   552
        self.RightNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORRIGHTNOTEBOOK,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   553
              style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE|
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   554
                    wx.aui.AUI_NB_SCROLL_BUTTONS|wx.aui.AUI_NB_TAB_EXTERNAL_MOVE)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   555
        self.RightNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   556
                self.OnAllowNotebookDnD)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   557
        self.AUIManager.AddPane(self.RightNoteBook, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   558
              wx.aui.AuiPaneInfo().Name("LibraryPane").
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   559
              Right().Layer(0).
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   560
              BestSize(wx.Size(250, 400)).CloseButton(False))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   561
        
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   562
        self.TabsOpened = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORTABSOPENED, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   563
              style=wx.aui.AUI_NB_DEFAULT_STYLE|wx.aui.AUI_NB_WINDOWLIST_BUTTON)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   564
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   565
                self.OnPouSelectedChanging)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   566
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   567
                self.OnPouSelectedChanged)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   568
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   569
                self.OnPageClose)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   570
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_END_DRAG,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   571
                self.OnPageDragged)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   572
        self.AUIManager.AddPane(self.TabsOpened, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   573
              wx.aui.AuiPaneInfo().CentrePane().Name("TabsPane"))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   574
        
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   575
        #-----------------------------------------------------------------------
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   576
        #                    Creating PLCopen Project Types Tree
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   577
        #-----------------------------------------------------------------------
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   578
        
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   579
        self.MainTabs = {}
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   580
        
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   581
        self.ProjectPanel = wx.SplitterWindow(id=ID_PLCOPENEDITORPROJECTPANEL,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   582
                  name='ProjectPanel', parent=self.LeftNoteBook, point=wx.Point(0, 0),
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   583
                  size=wx.Size(0, 0), style=wx.SP_3D)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   584
        
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   585
        self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   586
                  name='ProjectTree', parent=self.ProjectPanel, 
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   587
                  pos=wx.Point(0, 0), size=wx.Size(0, 0),
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   588
                  style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_EDIT_LABELS)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   589
        self.ProjectTree.SetBackgroundBitmap(wx.Bitmap(os.path.join(CWD, 'Images', 'custom_tree_background.png')),
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   590
											 wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   591
        add_menu = wx.Menu()
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   592
        self._init_coll_AddMenu_Items(add_menu)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   593
        self.ProjectTree.SetAddMenu(add_menu)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   594
        if wx.Platform == '__WXMSW__':
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   595
            self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnProjectTreeRightUp,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   596
                  id=ID_PLCOPENEDITORPROJECTTREE)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   597
            self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   598
                  id=ID_PLCOPENEDITORPROJECTTREE)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   599
        else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   600
            if wx.VERSION >= (2, 6, 0):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   601
                self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   602
                self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 245
diff changeset
   603
            else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   604
                wx.EVT_RIGHT_UP(self.ProjectTree, self.OnProjectTreeRightUp)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   605
                wx.EVT_LEFT_UP(self.ProjectTree, self.OnProjectTreeLeftUp)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   606
            self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   607
                  id=ID_PLCOPENEDITORPROJECTTREE)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   608
        self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   609
              id=ID_PLCOPENEDITORPROJECTTREE)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   610
        self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   611
              id=ID_PLCOPENEDITORPROJECTTREE)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   612
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   613
              id=ID_PLCOPENEDITORPROJECTTREE)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   614
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   615
              id=ID_PLCOPENEDITORPROJECTTREE)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   616
        
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   617
        #-----------------------------------------------------------------------
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   618
        #        Creating PLCopen Project POU Instance Variables Panel
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   619
        #-----------------------------------------------------------------------
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   620
        
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   621
        self.PouInstanceVariablesPanel = PouInstanceVariablesPanel(self.ProjectPanel, self, self.Controler, self.EnableDebug)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   622
        
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   623
        self.MainTabs["ProjectPanel"] = (self.ProjectPanel, _("Project"))
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   624
        self.LeftNoteBook.AddPage(*self.MainTabs["ProjectPanel"])
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   625
        
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   626
        self.ProjectPanel.SplitHorizontally(self.ProjectTree, self.PouInstanceVariablesPanel, 300)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   627
        
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   628
        #-----------------------------------------------------------------------
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   629
        #                            Creating Tool Bar
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   630
        #-----------------------------------------------------------------------
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   631
        
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   632
        MenuToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORMENUTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   633
                wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   634
        MenuToolBar.SetToolBitmapSize(wx.Size(25, 25))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   635
        MenuToolBar.Realize()
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   636
        self.Panes["MenuToolBar"] = MenuToolBar
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   637
        self.AUIManager.AddPane(MenuToolBar, wx.aui.AuiPaneInfo().
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   638
                  Name("MenuToolBar").Caption(_("Menu ToolBar")).
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   639
                  ToolbarPane().Top().
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   640
                  LeftDockable(False).RightDockable(False))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   641
        
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   642
        EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   643
                wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   644
        EditorToolBar.SetToolBitmapSize(wx.Size(25, 25))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   645
        EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, 
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   646
              wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, _("Select an object"))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   647
        EditorToolBar.Realize()
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   648
        self.Panes["EditorToolBar"] = EditorToolBar
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   649
        self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo().
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   650
                  Name("EditorToolBar").Caption(_("Editor ToolBar")).
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   651
                  ToolbarPane().Top().Position(1).
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   652
                  LeftDockable(False).RightDockable(False))
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
   653
            
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   654
        self.Bind(wx.EVT_MENU, self.OnSelectionTool, 
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   655
              id=ID_PLCOPENEDITOREDITORTOOLBARSELECTION)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   656
        
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   657
        #-----------------------------------------------------------------------
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   658
        #                            Creating Search Panel
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   659
        #-----------------------------------------------------------------------
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   660
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   661
        self.SearchResultPanel = SearchResultPanel(self.BottomNoteBook, self)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   662
        self.MainTabs["SearchResultPanel"] = (self.SearchResultPanel, _("Search"))
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   663
        self.BottomNoteBook.AddPage(*self.MainTabs["SearchResultPanel"])
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   664
        
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   665
        #-----------------------------------------------------------------------
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   666
        #                            Creating Library Panel
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   667
        #-----------------------------------------------------------------------
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   668
        
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   669
        self.LibraryPanel = LibraryPanel(self, True)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   670
        self.MainTabs["LibraryPanel"] = (self.LibraryPanel, _("Library"))
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   671
        self.RightNoteBook.AddPage(*self.MainTabs["LibraryPanel"])
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   672
                
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   673
        self._init_utils()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   674
        self.SetMenuBar(self.MenuBar)
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   675
                
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   676
        if self.EnableDebug:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   677
            self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self.Controler)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   678
            self.MainTabs["DebugVariablePanel"] = (self.DebugVariablePanel, _("Debugger"))
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   679
            self.RightNoteBook.AddPage(*self.MainTabs["DebugVariablePanel"])
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   680
        
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   681
        self.AUIManager.Update()
241
64e584348a5b Bug on Windows with LibraryTree fixed
lbessard
parents: 240
diff changeset
   682
    
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   683
    ## Constructor of the PLCOpenEditor class.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   684
    #  @param parent The parent window.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   685
    #  @param controler The controler been used by PLCOpenEditor (default: None).
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   686
    #  @param fileOpen The filepath to open if no controler defined (default: None).
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   687
    #  @param debug The filepath to open if no controler defined (default: False).
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   688
    def __init__(self, parent, enable_debug = False):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   689
        self.Controler = None
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   690
        self.Config = wx.ConfigBase.Get()
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   691
        self.EnableDebug = enable_debug
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
   692
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   693
        self._init_ctrls(parent)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   694
        
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   695
        # Define Tree item icon list
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   696
        self.TreeImageList = wx.ImageList(16, 16)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   697
        self.TreeImageDict = {}
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   698
        
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   699
        # Icons for languages
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   700
        for language in LANGUAGES:
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   701
            self.TreeImageDict[language]=self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%language)))
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   702
            
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   703
        # Icons for other items
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   704
        for imgname, itemtype in [
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   705
            #editables
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   706
            ("PROJECT",        ITEM_PROJECT),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   707
            #("POU",            ITEM_POU),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   708
            #("VARIABLE",       ITEM_VARIABLE),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   709
            ("TRANSITION",     ITEM_TRANSITION),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   710
            ("ACTION",         ITEM_ACTION),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   711
            ("CONFIGURATION",  ITEM_CONFIGURATION),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   712
            ("RESOURCE",       ITEM_RESOURCE),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   713
            ("DATATYPE",       ITEM_DATATYPE),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   714
            # uneditables
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   715
            ("DATATYPES",      ITEM_DATATYPES),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   716
            ("FUNCTION",       ITEM_FUNCTION),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   717
            ("FUNCTIONBLOCK",  ITEM_FUNCTIONBLOCK),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   718
            ("PROGRAM",        ITEM_PROGRAM),
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   719
            ("VAR_LOCAL",      ITEM_VAR_LOCAL),
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   720
            ("VAR_LOCAL",      ITEM_VAR_GLOBAL),
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   721
            ("VAR_LOCAL",      ITEM_VAR_EXTERNAL),
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   722
            ("VAR_LOCAL",      ITEM_VAR_TEMP),
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   723
            ("VAR_INPUT",      ITEM_VAR_INPUT),
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   724
            ("VAR_OUTPUT",     ITEM_VAR_OUTPUT),
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   725
            ("VAR_INOUT",      ITEM_VAR_INOUT),
184
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   726
            ("TRANSITIONS",    ITEM_TRANSITIONS),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   727
            ("ACTIONS",        ITEM_ACTIONS),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   728
            ("CONFIGURATIONS", ITEM_CONFIGURATIONS),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   729
            ("RESOURCES",      ITEM_RESOURCES),
d3e6484ebe85 changed the way icons are loaded for both toolbars and treectrl. Now, non editable items have different pyData.
etisserant
parents: 183
diff changeset
   730
            ("PROPERTIES",     ITEM_PROPERTIES)]:
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   731
            self.TreeImageDict[itemtype]=self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%imgname)))
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   732
        
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   733
        # Assign icon list to TreeCtrls
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   734
        self.ProjectTree.SetImageList(self.TreeImageList)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   735
        self.PouInstanceVariablesPanel.SetTreeImageList(self.TreeImageList)
9
b29105e29081 Adding test on step names in SFC Editor
lbessard
parents: 8
diff changeset
   736
        
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   737
        self.CurrentEditorToolBar = []
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
   738
        self.CurrentMenu = None
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
   739
        self.SelectedItem = None
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
   740
        self.Highlights = {}
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   741
        self.DrawingMode = FREEDRAWING_MODE
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   742
        #self.DrawingMode = DRIVENDRAWING_MODE
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   743
        self.AuiTabCtrl = []
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   744
        self.DefaultPerspective = None
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   745
        
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   746
        # Initialize Printing configuring elements
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
   747
        self.PrintData = wx.PrintData()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
   748
        self.PrintData.SetPaperId(wx.PAPER_A4)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
   749
        self.PrintData.SetPrintMode(wx.PRINT_MODE_PRINTER)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
   750
        self.PageSetupData = wx.PageSetupDialogData(self.PrintData)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
   751
        self.PageSetupData.SetMarginTopLeft(wx.Point(10, 15))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
   752
        self.PageSetupData.SetMarginBottomRight(wx.Point(10, 20))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
   753
        
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
   754
        self.SetRefreshFunctions()
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   755
    
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   756
    def ResetStarting(self):
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   757
		self.Starting = False
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   758
    
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   759
    def Show(self):
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   760
        wx.Frame.Show(self)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   761
        wx.CallAfter(self.RestoreLastState)
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   762
    
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   763
    def OnActivated(self, event):
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   764
        if event.GetActive():
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   765
            wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
   766
        event.Skip()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   767
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   768
#-------------------------------------------------------------------------------
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   769
#                Saving and restoring frame organization functions
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   770
#-------------------------------------------------------------------------------
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   771
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   772
    def OnResize(self, event):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   773
        if self.Starting:
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   774
            self.RestoreLastLayout()
680
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   775
            if wx.Platform == '__WXMSW__':
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   776
                wx.CallAfter(self.ResetStarting)
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   777
            else:
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   778
                self.ResetStarting()
b693147fb2c3 Fixing bugs with latest changesets on Windows
laurent
parents: 678
diff changeset
   779
            wx.CallAfter(self.RefreshEditor)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   780
        event.Skip()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   781
    
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   782
    def GetProjectConfiguration(self):
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   783
        projects = {}
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   784
        try:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   785
            if self.Config.HasEntry("projects"):
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   786
                projects = cPickle.loads(str(self.Config.Read("projects")))
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   787
        except:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   788
            pass
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   789
        
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   790
        return projects.get(os.path.realpath(self.Controler.GetFilePath()), {})
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   791
    
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   792
    def SavePageState(self, page):
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   793
        state = page.GetState()
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   794
        if state is not None:
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   795
            if self.Config.HasEntry("projects"):
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   796
                projects = cPickle.loads(str(self.Config.Read("projects")))
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   797
            else:
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   798
                projects = {}
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   799
            
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   800
            project_infos = projects.setdefault(os.path.realpath(self.Controler.GetFilePath()), {})
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   801
            editors_state = project_infos.setdefault("editors_state", {})
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   802
            
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   803
            if page.IsDebugging():
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   804
                editors_state[page.GetInstancePath()] = state
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   805
            else:
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   806
                editors_state[page.GetTagName()] = state
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   807
            
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   808
            self.Config.Write("projects", cPickle.dumps(projects))
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   809
            self.Config.Flush()
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   810
    
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   811
    def GetTabInfos(self, tab):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   812
        if isinstance(tab, EditorPanel):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   813
            if tab.IsDebugging():
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   814
                return ("debug", tab.GetInstancePath())
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   815
            else:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   816
                return ("editor", tab.GetTagName())
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   817
        else:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   818
            for page_name, (page_ref, page_title) in self.MainTabs.iteritems():
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   819
                if page_ref == tab:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   820
                    return ("main", page_name)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   821
        return None
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   822
    
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   823
    def SaveTabLayout(self, notebook):
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   824
        tabs = []
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   825
        for child in notebook.GetChildren():
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   826
            if isinstance(child, wx.aui.AuiTabCtrl):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   827
                pos = child.GetPosition()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   828
                tab = {"pos": (pos.x, pos.y), "pages": []}
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   829
                tab_size = child.GetSize()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   830
                for page_idx in xrange(child.GetPageCount()):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   831
                    page = child.GetWindowFromIdx(page_idx)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   832
                    if not tab.has_key("size"):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   833
                        tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1])
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   834
                    tab_infos = self.GetTabInfos(page)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   835
                    if tab_infos is not None:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   836
                        tab["pages"].append((tab_infos, page_idx == child.GetActivePage()))
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   837
                tabs.append(tab)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   838
        tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   839
        size = notebook.GetSize()
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   840
        return ComputeTabsLayout(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER))
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   841
    
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   842
    def LoadTab(self, notebook, page_infos):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   843
        if page_infos[0] == "main":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   844
            infos = self.MainTabs.get(page_infos[1])
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   845
            if infos is not None:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   846
                page_ref, page_title = infos
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   847
                notebook.AddPage(page_ref, page_title)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   848
                return notebook.GetPageIndex(page_ref)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   849
        elif page_infos[0] == "editor":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   850
            tagname = page_infos[1]
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   851
            page_ref = self.EditProjectElement(self.Controler.GetElementType(tagname), tagname)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   852
            if page_ref is not None:
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   853
                page_ref.RefreshView()
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   854
                return notebook.GetPageIndex(page_ref)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   855
        elif page_infos[0] == "debug":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   856
            instance_path = page_infos[1]
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
   857
            instance_infos = self.Controler.GetInstanceInfos(instance_path, self.EnableDebug)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   858
            if instance_infos is not None:
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
   859
                return notebook.GetPageIndex(self.OpenDebugViewer(instance_infos["class"], instance_path, instance_infos["type"]))
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   860
        return None
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   861
            
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   862
    def LoadTabLayout(self, notebook, tabs, mode="all", first_index=None):
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   863
        if isinstance(tabs, ListType):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   864
            if len(tabs) == 0:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   865
                return
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   866
            raise ValueError, "Not supported"
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   867
        
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   868
        if tabs.has_key("split"):
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   869
            self.LoadTabLayout(notebook, tabs["others"])
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   870
            
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   871
            split_dir, split_ratio = tabs["split"]
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   872
            first_index = self.LoadTabLayout(notebook, tabs["tab"], mode="first")
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   873
            notebook.Split(first_index, split_dir)
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   874
            self.LoadTabLayout(notebook, tabs["tab"], mode="others", first_index=first_index)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   875
            
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   876
        elif mode == "first":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   877
            return self.LoadTab(notebook, tabs["pages"][0][0])
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   878
        else:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   879
            selected = first_index
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   880
            if mode == "others":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   881
                add_tabs = tabs["pages"][1:]
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   882
            else:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   883
                add_tabs = tabs["pages"]
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   884
            for page_infos, page_selected in add_tabs:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   885
                page_idx = self.LoadTab(notebook, page_infos)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   886
                if page_selected:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   887
                    selected = page_idx
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   888
            if selected is not None:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   889
                wx.CallAfter(notebook.SetSelection, selected)
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   890
    
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   891
    def ResetPerspective(self):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   892
    	if self.DefaultPerspective is not None:
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   893
            self.AUIManager.LoadPerspective(self.DefaultPerspective["perspective"])
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   894
        
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   895
            for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   896
                for idx in xrange(notebook.GetPageCount()):
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   897
                    notebook.RemovePage(0)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   898
                        
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   899
            notebooks = self.DefaultPerspective["notebooks"]
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   900
            for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   901
                                         (self.BottomNoteBook, "bottomnotebook"),
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   902
                                         (self.RightNoteBook, "rightnotebook")]:
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   903
                self.LoadTabLayout(notebook, notebooks.get(entry_name))
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   904
    
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   905
    def RestoreLastState(self):
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   906
        frame_size = None
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   907
        if self.Config.HasEntry("framesize"):
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   908
            frame_size = cPickle.loads(str(self.Config.Read("framesize")))
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   909
        
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   910
        self.Starting = True
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   911
        if frame_size is None:
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   912
            self.Maximize()
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   913
        else:
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   914
            self.SetClientSize(frame_size)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   915
        
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   916
    def RestoreLastLayout(self):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   917
        notebooks = {}
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   918
        for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   919
                                     (self.BottomNoteBook, "bottomnotebook"),
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   920
                                     (self.RightNoteBook, "rightnotebook")]:
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   921
            notebooks[entry_name] = self.SaveTabLayout(notebook)
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   922
        self.DefaultPerspective = {
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   923
            "perspective": self.AUIManager.SavePerspective(),
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   924
            "notebooks": notebooks,
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   925
        }
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   926
        
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   927
        try:
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   928
            if self.Config.HasEntry("perspective"):
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   929
                self.AUIManager.LoadPerspective(str(self.Config.Read("perspective")))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   930
        
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   931
            if self.Config.HasEntry("notebooks"):
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   932
                notebooks = cPickle.loads(str(self.Config.Read("notebooks")))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   933
                
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   934
                for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   935
                    for idx in xrange(notebook.GetPageCount()):
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   936
                        notebook.RemovePage(0)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   937
                        
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   938
                for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   939
                                             (self.BottomNoteBook, "bottomnotebook"),
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   940
                                             (self.RightNoteBook, "rightnotebook")]:
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   941
                    self.LoadTabLayout(notebook, notebooks.get(entry_name))
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   942
        except:
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   943
            self.ResetPerspective()
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   944
        
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   945
        self.LoadProjectLayout()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   946
    
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   947
    def SaveLastState(self):
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   948
        if not self.IsMaximized():
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   949
            self.Config.Write("framesize", cPickle.dumps(self.GetClientSize()))
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   950
        elif self.Config.HasEntry("framesize"):
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   951
            self.Config.DeleteEntry("framesize")
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   952
        
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   953
        notebooks = {}
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   954
        for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   955
                                     (self.BottomNoteBook, "bottomnotebook"),
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   956
                                     (self.RightNoteBook, "rightnotebook")]:
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   957
            notebooks[entry_name] = self.SaveTabLayout(notebook)
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   958
        self.Config.Write("notebooks", cPickle.dumps(notebooks))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   959
        
695
8848ffb7ae2a Adding support for preventing perspective to be saved with tabs maximized
Laurent Bessard
parents: 691
diff changeset
   960
        pane = self.AUIManager.GetPane(self.TabsOpened)
8848ffb7ae2a Adding support for preventing perspective to be saved with tabs maximized
Laurent Bessard
parents: 691
diff changeset
   961
        if pane.IsMaximized():
8848ffb7ae2a Adding support for preventing perspective to be saved with tabs maximized
Laurent Bessard
parents: 691
diff changeset
   962
            self.AUIManager.RestorePane(pane)
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   963
        self.Config.Write("perspective", self.AUIManager.SavePerspective())
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   964
    
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   965
        self.SaveProjectLayout()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   966
        
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   967
        for i in xrange(self.TabsOpened.GetPageCount()):
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   968
            self.SavePageState(self.TabsOpened.GetPage(i))
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   969
        
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
   970
        self.Config.Flush()
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
   971
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   972
    def SaveProjectLayout(self):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   973
        if self.Controler is not None:
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   974
            tabs = []
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   975
            
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   976
            projects = {}
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   977
            try:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   978
             	if self.Config.HasEntry("projects"):
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   979
                	projects = cPickle.loads(str(self.Config.Read("projects")))
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   980
            except:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   981
            	pass
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   982
            
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
   983
            project_infos = projects.setdefault(os.path.realpath(self.Controler.GetFilePath()), {})
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   984
            project_infos["tabs"] = self.SaveTabLayout(self.TabsOpened)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   985
            if self.EnableDebug:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   986
                project_infos["debug_vars"] = self.DebugVariablePanel.GetDebugVariables()
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   987
            
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   988
            self.Config.Write("projects", cPickle.dumps(projects))
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   989
            self.Config.Flush()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
   990
    
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   991
    def LoadProjectLayout(self):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
   992
        if self.Controler is not None:
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   993
            project = self.GetProjectConfiguration()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   994
		    
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   995
            try:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   996
                if project.has_key("tabs"):
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
   997
                    self.LoadTabLayout(self.TabsOpened, project["tabs"])
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   998
            except:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
   999
            	self.DeleteAllPages()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1000
            	
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1001
            if self.EnableDebug:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1002
            	try:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1003
                    for variable in project.get("debug_vars", []):
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1004
                        self.DebugVariablePanel.InsertValue(variable, force=True)
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1005
            	except:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1006
            		self.DebugVariablePanel.ResetGrid()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1007
            
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1008
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1009
#                               General Functions
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1010
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1011
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1012
    def SetRefreshFunctions(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1013
        self.RefreshFunctions = {
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1014
            TITLE : self.RefreshTitle,
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1015
            EDITORTOOLBAR : self.RefreshEditorToolBar,
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1016
            FILEMENU : self.RefreshFileMenu,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1017
            EDITMENU : self.RefreshEditMenu,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1018
            DISPLAYMENU : self.RefreshDisplayMenu,
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1019
            PROJECTTREE : self.RefreshProjectTree,
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1020
            POUINSTANCEVARIABLESPANEL : self.RefreshPouInstanceVariablesPanel, 
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1021
            LIBRARYTREE : self.RefreshLibraryPanel,
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1022
            SCALING : self.RefreshScaling,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1023
            PAGETITLES: self.RefreshPageTitles}
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1024
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1025
    ## Call PLCOpenEditor refresh functions.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1026
    #  @param elements List of elements to refresh.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1027
    def _Refresh(self, *elements):
683
37882f34f9cb fixed on quit exception dialog
Edouard Tisserant
parents: 682
diff changeset
  1028
        try:
37882f34f9cb fixed on quit exception dialog
Edouard Tisserant
parents: 682
diff changeset
  1029
            for element in elements:
37882f34f9cb fixed on quit exception dialog
Edouard Tisserant
parents: 682
diff changeset
  1030
                self.RefreshFunctions[element]()
37882f34f9cb fixed on quit exception dialog
Edouard Tisserant
parents: 682
diff changeset
  1031
        except wx.PyDeadObjectError:
37882f34f9cb fixed on quit exception dialog
Edouard Tisserant
parents: 682
diff changeset
  1032
            # ignore exceptions caused by refresh while quitting
37882f34f9cb fixed on quit exception dialog
Edouard Tisserant
parents: 682
diff changeset
  1033
            pass
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1034
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1035
    ## Callback function when AUINotebook Page closed with CloseButton
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1036
    #  @param event AUINotebook Event.
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1037
    def OnPageClose(self, event):
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1038
        selected = self.TabsOpened.GetSelection()
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1039
        if selected > -1:
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1040
            self.SavePageState(self.TabsOpened.GetPage(selected))
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1041
        
624
efedc9d06a59 Fix bug in refreshing menu after tab selection changed
laurent
parents: 618
diff changeset
  1042
        # Refresh all window elements that have changed
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1043
        wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1044
        wx.CallAfter(self.RefreshTabCtrlEvent)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1045
        event.Skip()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1046
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  1047
    def GetCopyBuffer(self):
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1048
        data = None
402
281fd35e7a7b Adding test for avoiding Clipboard multiple opening
laurent
parents: 401
diff changeset
  1049
        if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1050
            dataobj = wx.TextDataObject()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1051
            if wx.TheClipboard.GetData(dataobj):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1052
                data = dataobj.GetText()
403
2160fd6d83ed Adding test for avoiding closing Clipboard when not opened
laurent
parents: 402
diff changeset
  1053
        if wx.TheClipboard.IsOpened():
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1054
            wx.TheClipboard.Close()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1055
        return data
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1056
        
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1057
    def SetCopyBuffer(self, text):
402
281fd35e7a7b Adding test for avoiding Clipboard multiple opening
laurent
parents: 401
diff changeset
  1058
        if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1059
            data = wx.TextDataObject()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1060
            data.SetText(text)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1061
            wx.TheClipboard.SetData(data)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1062
            wx.TheClipboard.Flush()
403
2160fd6d83ed Adding test for avoiding closing Clipboard when not opened
laurent
parents: 402
diff changeset
  1063
        if wx.TheClipboard.IsOpened():
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 372
diff changeset
  1064
            wx.TheClipboard.Close()
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  1065
        self.RefreshEditMenu()
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  1066
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1067
    def GetDrawingMode(self):
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1068
        return self.DrawingMode
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1069
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1070
    def RefreshScaling(self):
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1071
        for i in xrange(self.TabsOpened.GetPageCount()):
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1072
            editor = self.TabsOpened.GetPage(i)
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1073
            editor.RefreshScaling()
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1074
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1075
    def EditProjectSettings(self):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1076
        old_values = self.Controler.GetProjectProperties()
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1077
        dialog = ProjectDialog(self)
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1078
        dialog.SetValues(old_values)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  1079
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1080
            new_values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1081
            new_values["creationDateTime"] = old_values["creationDateTime"]
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1082
            if new_values != old_values:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1083
                self.Controler.SetProjectProperties(None, new_values)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1084
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1085
                              PROJECTTREE, POUINSTANCEVARIABLESPANEL, SCALING)
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1086
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1087
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1088
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1089
#                            Notebook Unified Functions
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1090
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1091
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1092
    ## Function that generate bitmap for
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1093
    # for wx.aui.AUINotebook.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1094
    #  @param window Panel to display in tab.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1095
    #  @param text title for the tab ctrl.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1096
    def GenerateBitmap(self, icon1_name, icon2_name = None):
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1097
        # Find index of bitmap if already created
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1098
        index = self.TabsImageListIndexes.get((icon1_name, icon2_name), None)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1099
        # Return index or bitmap if found
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1100
        if index is not None:
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1101
            return self.TabsImageList.GetBitmap(index)
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1102
        if icon2_name is None:
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1103
            # Bitmap with only one icon
401
d3f086b0da30 Bug with TabsImageList wrong image size definition fixed
laurent
parents: 397
diff changeset
  1104
            bitmap = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name))
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1105
        else:
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1106
            # Bitmap with two icon
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1107
            icon1 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name))
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1108
            icon2 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon2_name))
401
d3f086b0da30 Bug with TabsImageList wrong image size definition fixed
laurent
parents: 397
diff changeset
  1109
            
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1110
            # Calculate bitmap size
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1111
            width = icon1.GetWidth() + icon2.GetWidth() - 1
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1112
            height = max(icon1.GetHeight(), icon2.GetHeight())
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1113
            # Create bitmap with both icons
401
d3f086b0da30 Bug with TabsImageList wrong image size definition fixed
laurent
parents: 397
diff changeset
  1114
            bitmap = wx.EmptyBitmap(width, height)
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1115
            dc = wx.MemoryDC()
401
d3f086b0da30 Bug with TabsImageList wrong image size definition fixed
laurent
parents: 397
diff changeset
  1116
            dc.SelectObject(bitmap)
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1117
            dc.Clear()
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1118
            dc.DrawBitmap(icon1, 0, 0)
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 275
diff changeset
  1119
            dc.DrawBitmap(icon2, icon1.GetWidth() - 1, 0)
401
d3f086b0da30 Bug with TabsImageList wrong image size definition fixed
laurent
parents: 397
diff changeset
  1120
            dc.Destroy()
d3f086b0da30 Bug with TabsImageList wrong image size definition fixed
laurent
parents: 397
diff changeset
  1121
            
397
ea47ebbe23b7 Bug with tabs images on Windows fixed
laurent
parents: 396
diff changeset
  1122
            # Store bitmap in ImageList
401
d3f086b0da30 Bug with TabsImageList wrong image size definition fixed
laurent
parents: 397
diff changeset
  1123
            index = self.TabsImageList.Add(bitmap)
397
ea47ebbe23b7 Bug with tabs images on Windows fixed
laurent
parents: 396
diff changeset
  1124
            # Save bitmap index in ImageList in dictionary
ea47ebbe23b7 Bug with tabs images on Windows fixed
laurent
parents: 396
diff changeset
  1125
            self.TabsImageListIndexes[(icon1_name, icon2_name)] = index
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1126
        return bitmap
337
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  1127
    
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1128
    ## Function that add a tab in Notebook, calling refresh for tab DClick event
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1129
    # for wx.aui.AUINotebook.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1130
    #  @param window Panel to display in tab.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1131
    #  @param text title for the tab ctrl.
337
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  1132
    def AddPage(self, window, text):
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  1133
        self.TabsOpened.AddPage(window, text)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1134
        self.RefreshTabCtrlEvent()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1135
    
611
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1136
    ## Function that add a tab in Notebook, calling refresh for tab DClick event
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1137
    # for wx.aui.AUINotebook.
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1138
    #  @param window Panel to display in tab.
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1139
    #  @param text title for the tab ctrl.
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1140
    def DeletePage(self, window):
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1141
        for idx in xrange(self.TabsOpened.GetPageCount()):
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1142
            if self.TabsOpened.GetPage(idx) == window:
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1143
                self.TabsOpened.DeletePage(idx)
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1144
                self.RefreshTabCtrlEvent()
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1145
                return 
9d24fa46523f Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 606
diff changeset
  1146
        
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1147
    ## Function that fix difference in deleting all tabs between 
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1148
    # wx.Notebook and wx.aui.AUINotebook.
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1149
    def DeleteAllPages(self):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1150
        for idx in xrange(self.TabsOpened.GetPageCount()):
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1151
            self.TabsOpened.DeletePage(0)
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1152
        self.RefreshTabCtrlEvent()
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1153
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1154
    ## Function that fix difference in setting picture on tab between 
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1155
    # wx.Notebook and wx.aui.AUINotebook.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1156
    #  @param idx Tab index.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1157
    #  @param bitmap wx.Bitmap to define on tab.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1158
    #  @return True if operation succeeded
203
76c407fb33fe Adding icons on viewers tabs
lbessard
parents: 190
diff changeset
  1159
    def SetPageBitmap(self, idx, bitmap):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1160
        return self.TabsOpened.SetPageBitmap(idx, bitmap)
203
76c407fb33fe Adding icons on viewers tabs
lbessard
parents: 190
diff changeset
  1161
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1162
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1163
#                         Dialog Message Functions
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1164
#-------------------------------------------------------------------------------
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1165
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1166
    ## Function displaying an Error dialog in PLCOpenEditor.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1167
    #  @param message The message to display.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1168
    def ShowErrorMessage(self, message):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1169
        dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1170
        dialog.ShowModal()
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1171
        dialog.Destroy()
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1172
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1173
    ## Function displaying an Error dialog in PLCOpenEditor.
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1174
    #  @return False if closing cancelled.
450
b31d1dfb407b Fix messages on DialogBox title while asking for project saving when closing project
laurent
parents: 447
diff changeset
  1175
    def CheckSaveBeforeClosing(self, title=_("Close Project")):
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1176
        if not self.Controler.ProjectIsSaved():
450
b31d1dfb407b Fix messages on DialogBox title while asking for project saving when closing project
laurent
parents: 447
diff changeset
  1177
            dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), title, wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 55
diff changeset
  1178
            answer = dialog.ShowModal()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 55
diff changeset
  1179
            dialog.Destroy()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  1180
            if answer == wx.ID_YES:
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 55
diff changeset
  1181
                self.SaveProject()
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1182
            elif answer == wx.ID_CANCEL:
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1183
                return False
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1184
        return True
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1185
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1186
#-------------------------------------------------------------------------------
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1187
#                            File Menu Functions
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1188
#-------------------------------------------------------------------------------
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1189
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1190
    def RefreshFileMenu(self):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1191
        pass
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1192
411
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
  1193
    def ResetView(self):
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
  1194
        self.DeleteAllPages()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1195
        self.ProjectTree.DeleteAllItems()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1196
        self.ProjectTree.Enable(False)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1197
        self.PouInstanceVariablesPanel.ResetView()
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1198
        self.LibraryPanel.ResetTree()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1199
        self.LibraryPanel.SetControler(None)
411
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
  1200
        self.Controler = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1201
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1202
    def OnCloseTabMenu(self, event):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1203
        selected = self.TabsOpened.GetSelection()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1204
        if selected >= 0:
294
4a36f2ec8967 Two bugs fixed:
lbessard
parents: 292
diff changeset
  1205
            self.TabsOpened.DeletePage(selected)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1206
            if self.TabsOpened.GetPageCount() > 0:
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1207
                new_index = min(selected, self.TabsOpened.GetPageCount() - 1)
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1208
                self.TabsOpened.SetSelection(new_index)
478
dc403c47af54 Adding colour to graphic element that showing forced values
laurent
parents: 474
diff changeset
  1209
        # Refresh all window elements that have changed
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1210
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
478
dc403c47af54 Adding colour to graphic element that showing forced values
laurent
parents: 474
diff changeset
  1211
        self.RefreshTabCtrlEvent()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1212
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1213
    def OnPageSetupMenu(self, event):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1214
        dialog = wx.PageSetupDialog(self, self.PageSetupData)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1215
        if dialog.ShowModal() == wx.ID_OK:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1216
            self.PageSetupData = wx.PageSetupDialogData(dialog.GetPageSetupData())
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1217
            self.PrintData = wx.PrintData(self.PageSetupData.GetPrintData())
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1218
        dialog.Destroy()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1219
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1220
    def OnPreviewMenu(self, event):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1221
        selected = self.TabsOpened.GetSelection()        
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1222
        if selected != -1:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1223
            window = self.TabsOpened.GetPage(selected)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1224
            data = wx.PrintDialogData(self.PrintData)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1225
            properties = self.Controler.GetProjectProperties(window.IsDebugging())
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1226
            page_size = map(int, properties["pageSize"])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1227
            margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1228
            printout = GraphicPrintout(window, page_size, margins, True)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1229
            printout2 = GraphicPrintout(window, page_size, margins, True)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1230
            preview = wx.PrintPreview(printout, printout2, data)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1231
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1232
            if preview.Ok():
559
984c51d1bf6b Fix PrintPreview behavior
laurent
parents: 555
diff changeset
  1233
                preview_frame = wx.PreviewFrame(preview, self, _("Print preview"), style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1234
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1235
                preview_frame.Initialize()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1236
                
559
984c51d1bf6b Fix PrintPreview behavior
laurent
parents: 555
diff changeset
  1237
                preview_canvas = preview.GetCanvas()
984c51d1bf6b Fix PrintPreview behavior
laurent
parents: 555
diff changeset
  1238
                preview_canvas.SetMinSize(preview_canvas.GetVirtualSize())
984c51d1bf6b Fix PrintPreview behavior
laurent
parents: 555
diff changeset
  1239
                preview_frame.Fit()
984c51d1bf6b Fix PrintPreview behavior
laurent
parents: 555
diff changeset
  1240
                
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1241
                preview_frame.Show(True)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1242
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1243
    def OnPrintMenu(self, event):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1244
        selected = self.TabsOpened.GetSelection()        
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1245
        if selected != -1:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1246
            window = self.TabsOpened.GetPage(selected)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1247
            dialog_data = wx.PrintDialogData(self.PrintData)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1248
            dialog_data.SetToPage(1)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1249
            properties = self.Controler.GetProjectProperties(window.IsDebugging())
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1250
            page_size = map(int, properties["pageSize"])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1251
            margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1252
            printer = wx.Printer(dialog_data)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1253
            printout = GraphicPrintout(window, page_size, margins)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1254
            
559
984c51d1bf6b Fix PrintPreview behavior
laurent
parents: 555
diff changeset
  1255
            if not printer.Print(self, printout, True) and printer.GetLastError() != wx.PRINTER_CANCELLED:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1256
                self.ShowErrorMessage(_("There was a problem printing.\nPerhaps your current printer is not set correctly?"))
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1257
            printout.Destroy()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  1258
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1259
    def OnPropertiesMenu(self, event):
690
a32548167224 Fix bug with Properties menu entry
laurent
parents: 689
diff changeset
  1260
        self.EditProjectSettings()
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
  1261
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1262
    def OnQuitMenu(self, event):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1263
        self.Close()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1264
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1265
#-------------------------------------------------------------------------------
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1266
#                            Edit Menu Functions
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1267
#-------------------------------------------------------------------------------
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1268
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1269
    def RefreshEditMenu(self):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1270
        MenuToolBar = self.Panes["MenuToolBar"]
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1271
        if self.Controler is not None:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1272
            selected = self.TabsOpened.GetSelection()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1273
            if selected > -1:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1274
                window = self.TabsOpened.GetPage(selected)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1275
                undo, redo = window.GetBufferState()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1276
            else:
613
c487c54c1cfe Fixing bug conflict on tab selection between POU editor and Debug window of an instance of this same POU on Windows
laurent
parents: 611
diff changeset
  1277
                undo, redo = self.Controler.GetBufferState()
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1278
            self.EditMenu.Enable(wx.ID_UNDO, undo)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1279
            MenuToolBar.EnableTool(wx.ID_UNDO, undo)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1280
            self.EditMenu.Enable(wx.ID_REDO, redo)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1281
            MenuToolBar.EnableTool(wx.ID_REDO, redo)
562
0ce12552cf36 Fix bug on Windows after removing "Enable Undo/Redo" menu item
laurent
parents: 560
diff changeset
  1282
            #self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, True)
0ce12552cf36 Fix bug on Windows after removing "Enable Undo/Redo" menu item
laurent
parents: 560
diff changeset
  1283
            #self.EditMenu.Check(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, 
0ce12552cf36 Fix bug on Windows after removing "Enable Undo/Redo" menu item
laurent
parents: 560
diff changeset
  1284
            #                self.Controler.IsProjectBufferEnabled())
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1285
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, True)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1286
            MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, True)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1287
            self.EditMenu.Enable(wx.ID_ADD, True)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1288
            self.EditMenu.Enable(wx.ID_DELETE, True)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1289
            if self.TabsOpened.GetPageCount() > 0:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1290
                self.EditMenu.Enable(wx.ID_CUT, True)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1291
                MenuToolBar.EnableTool(wx.ID_CUT, True)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1292
                self.EditMenu.Enable(wx.ID_COPY, True)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1293
                MenuToolBar.EnableTool(wx.ID_COPY, True)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1294
                if self.GetCopyBuffer() is not None:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1295
                    self.EditMenu.Enable(wx.ID_PASTE, True)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1296
                    MenuToolBar.EnableTool(wx.ID_PASTE, True)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1297
                else:
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1298
                    self.EditMenu.Enable(wx.ID_PASTE, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1299
                    MenuToolBar.EnableTool(wx.ID_PASTE, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1300
                self.EditMenu.Enable(wx.ID_SELECTALL, True)
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1301
            else:
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1302
                self.EditMenu.Enable(wx.ID_CUT, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1303
                MenuToolBar.EnableTool(wx.ID_CUT, False)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1304
                self.EditMenu.Enable(wx.ID_COPY, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1305
                MenuToolBar.EnableTool(wx.ID_COPY, False)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1306
                self.EditMenu.Enable(wx.ID_PASTE, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1307
                MenuToolBar.EnableTool(wx.ID_PASTE, False)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1308
                self.EditMenu.Enable(wx.ID_SELECTALL, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1309
        else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1310
            self.EditMenu.Enable(wx.ID_UNDO, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1311
            MenuToolBar.EnableTool(wx.ID_UNDO, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1312
            self.EditMenu.Enable(wx.ID_REDO, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1313
            MenuToolBar.EnableTool(wx.ID_REDO, False)
562
0ce12552cf36 Fix bug on Windows after removing "Enable Undo/Redo" menu item
laurent
parents: 560
diff changeset
  1314
            #self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1315
            self.EditMenu.Enable(wx.ID_CUT, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1316
            MenuToolBar.EnableTool(wx.ID_CUT, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1317
            self.EditMenu.Enable(wx.ID_COPY, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1318
            MenuToolBar.EnableTool(wx.ID_COPY, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1319
            self.EditMenu.Enable(wx.ID_PASTE, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1320
            MenuToolBar.EnableTool(wx.ID_PASTE, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1321
            self.EditMenu.Enable(wx.ID_SELECTALL, False)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1322
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1323
            MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1324
            self.EditMenu.Enable(wx.ID_ADD, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1325
            self.EditMenu.Enable(wx.ID_DELETE, False)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1326
    
654
f8445d00613d Fix bug when undo just after creating a new project element
laurent
parents: 651
diff changeset
  1327
    def CloseTabsWithoutModel(self, refresh=True):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1328
        idxs = range(self.TabsOpened.GetPageCount())
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1329
        idxs.reverse()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1330
        for idx in idxs:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1331
            window = self.TabsOpened.GetPage(idx)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1332
            if window.HasNoModel():
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1333
                self.TabsOpened.DeletePage(idx)
654
f8445d00613d Fix bug when undo just after creating a new project element
laurent
parents: 651
diff changeset
  1334
        if refresh:
f8445d00613d Fix bug when undo just after creating a new project element
laurent
parents: 651
diff changeset
  1335
            self.RefreshEditor()
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1336
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1337
    def OnUndoMenu(self, event):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1338
        selected = self.TabsOpened.GetSelection()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1339
        if selected != -1:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1340
            window = self.TabsOpened.GetPage(selected)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1341
            window.Undo()
613
c487c54c1cfe Fixing bug conflict on tab selection between POU editor and Debug window of an instance of this same POU on Windows
laurent
parents: 611
diff changeset
  1342
        else:
c487c54c1cfe Fixing bug conflict on tab selection between POU editor and Debug window of an instance of this same POU on Windows
laurent
parents: 611
diff changeset
  1343
            self.Controler.LoadPrevious()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1344
        self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, 
613
c487c54c1cfe Fixing bug conflict on tab selection between POU editor and Debug window of an instance of this same POU on Windows
laurent
parents: 611
diff changeset
  1345
                      SCALING, PAGETITLES)    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1346
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1347
    def OnRedoMenu(self, event):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1348
        selected = self.TabsOpened.GetSelection()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1349
        if selected != -1:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1350
            window = self.TabsOpened.GetPage(selected)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1351
            window.Redo()
613
c487c54c1cfe Fixing bug conflict on tab selection between POU editor and Debug window of an instance of this same POU on Windows
laurent
parents: 611
diff changeset
  1352
        else:
c487c54c1cfe Fixing bug conflict on tab selection between POU editor and Debug window of an instance of this same POU on Windows
laurent
parents: 611
diff changeset
  1353
            self.Controler.LoadNext()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1354
        self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, 
613
c487c54c1cfe Fixing bug conflict on tab selection between POU editor and Debug window of an instance of this same POU on Windows
laurent
parents: 611
diff changeset
  1355
                      SCALING, PAGETITLES)
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1356
    
350
f7958989e055 Adding support for Enable/Disable Undo/Redo
greg
parents: 347
diff changeset
  1357
    def OnEnableUndoRedoMenu(self, event):
f7958989e055 Adding support for Enable/Disable Undo/Redo
greg
parents: 347
diff changeset
  1358
        self.Controler.EnableProjectBuffer(event.IsChecked())
f7958989e055 Adding support for Enable/Disable Undo/Redo
greg
parents: 347
diff changeset
  1359
        self.RefreshEditMenu()
f7958989e055 Adding support for Enable/Disable Undo/Redo
greg
parents: 347
diff changeset
  1360
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1361
    OnCutMenu = GetShortcutKeyCallbackFunction("Cut")
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1362
    OnCopyMenu = GetShortcutKeyCallbackFunction("Copy")
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1363
    OnPasteMenu = GetShortcutKeyCallbackFunction("Paste")
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1364
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1365
    def OnSelectAllMenu(self, event):
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1366
        control = self.FindFocus()
599
4bb7b132e15d Fixing standard functions library treectrl in library panel in order to make it similar on all platforms
laurent
parents: 587
diff changeset
  1367
        if control is not None and control.GetName() == "Viewer":
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1368
            control.Parent.SelectAll()
587
98445f90f45d Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 586
diff changeset
  1369
        elif isinstance(control, wx.stc.StyledTextCtrl):
98445f90f45d Fixing bug preventing copy/cut/paste using shortcuts on CFileEditor text editors
laurent
parents: 586
diff changeset
  1370
            control.SelectAll()
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1371
        elif isinstance(control, wx.TextCtrl):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1372
            control.SetSelection(0, control.GetLastPosition())
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1373
        elif isinstance(control, wx.ComboBox):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  1374
            control.SetMark(0, control.GetLastPosition() + 1)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1375
    
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1376
    DeleteFunctions = {
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1377
        ITEM_DATATYPE: GetDeleteElementFunction(PLCControler.ProjectRemoveDataType, check_function=PLCControler.DataTypeIsUsed),
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1378
        ITEM_POU: GetDeleteElementFunction(PLCControler.ProjectRemovePou, check_function=PLCControler.PouIsUsed),
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1379
        ITEM_TRANSITION: GetDeleteElementFunction(PLCControler.ProjectRemovePouTransition, ITEM_POU),
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1380
        ITEM_ACTION: GetDeleteElementFunction(PLCControler.ProjectRemovePouAction, ITEM_POU),
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1381
        ITEM_CONFIGURATION: GetDeleteElementFunction(PLCControler.ProjectRemoveConfiguration),
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1382
        ITEM_RESOURCE: GetDeleteElementFunction(PLCControler.ProjectRemoveConfigurationResource, ITEM_CONFIGURATION)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1383
    }
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1384
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1385
    def OnDeleteMenu(self, event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1386
        window = self.FindFocus()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1387
        if window == self.ProjectTree or window is None:
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1388
            selected = self.ProjectTree.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1389
            if selected.IsOk():
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1390
                function = self.DeleteFunctions.get(self.ProjectTree.GetPyData(selected)["type"], None)
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1391
                if function is not None:
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1392
                    function(self, selected)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1393
                    self.CloseTabsWithoutModel()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1394
                    self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, 
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1395
                                  POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1396
        elif isinstance(window, (Viewer, TextViewer)):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1397
            event = wx.KeyEvent(wx.EVT_CHAR._getEvtType())
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1398
            event.m_keyCode = wx.WXK_DELETE
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1399
            window.ProcessEvent(event)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1400
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1401
    def OnSearchInProjectMenu(self, event):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1402
        dialog = SearchInProjectDialog(self)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1403
        if dialog.ShowModal() == wx.ID_OK:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1404
            criteria = dialog.GetCriteria()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1405
            result = self.Controler.SearchInProject(criteria)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1406
            self.ClearSearchResults()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1407
            self.SearchResultPanel.SetSearchResults(criteria, result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1408
            self.BottomNoteBook.SetSelection(self.BottomNoteBook.GetPageIndex(self.SearchResultPanel))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1409
            
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1410
#-------------------------------------------------------------------------------
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1411
#                             Display Menu Functions
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1412
#-------------------------------------------------------------------------------
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1413
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1414
    def RefreshDisplayMenu(self):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1415
        if self.Controler is not None:
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1416
            if self.TabsOpened.GetPageCount() > 0:
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1417
                self.DisplayMenu.Enable(wx.ID_REFRESH, True)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1418
                selected = self.TabsOpened.GetSelection()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1419
                if selected != -1:
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1420
                    window = self.TabsOpened.GetPage(selected)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1421
                    if isinstance(window, Viewer):
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1422
                        self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, True)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1423
                        zoommenu = self.DisplayMenu.FindItemById(wx.ID_ZOOM_FIT).GetSubMenu()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1424
                        zoomitem = zoommenu.FindItemByPosition(window.GetScale())
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1425
                        zoomitem.Check(True)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1426
                    else:
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1427
                        self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1428
                else:
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1429
                    self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1430
            else:
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1431
                self.DisplayMenu.Enable(wx.ID_REFRESH, False)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1432
                self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1433
            if self.EnableDebug:
352
5cd60f7e510c fixed some bugs:
greg
parents: 350
diff changeset
  1434
                self.DisplayMenu.Enable(wx.ID_CLEAR, True)
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1435
        else:
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1436
            self.DisplayMenu.Enable(wx.ID_REFRESH, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1437
            if self.EnableDebug:
352
5cd60f7e510c fixed some bugs:
greg
parents: 350
diff changeset
  1438
                self.DisplayMenu.Enable(wx.ID_CLEAR, False)
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1439
            self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1440
        
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1441
    def OnRefreshMenu(self, event):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1442
        self.RefreshEditor()
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1443
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1444
    def OnClearErrorsMenu(self, event):
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1445
        self.ClearErrors()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1446
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1447
    def GenerateZoomFunction(self, idx):
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1448
        def ZoomFunction(event):
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1449
            selected = self.TabsOpened.GetSelection()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1450
            if selected != -1:
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1451
                window = self.TabsOpened.GetPage(selected)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1452
                window.SetScale(idx)
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  1453
                window.RefreshVisibleElements()
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  1454
                window.RefreshScrollBars()
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1455
            event.Skip()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1456
        return ZoomFunction
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1457
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1458
    def OnResetPerspective(self, event):
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1459
        self.ResetPerspective()
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1460
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1461
#-------------------------------------------------------------------------------
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1462
#                      Project Editor Panels Management Functions
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1463
#-------------------------------------------------------------------------------
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1464
    
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1465
    def OnPageDragged(self, event):
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1466
        wx.CallAfter(self.RefreshTabCtrlEvent)
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1467
        event.Skip()
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1468
    
618
6e48943e821e Adding support for Drag'n dropping panels between notebooks
laurent
parents: 613
diff changeset
  1469
    def OnAllowNotebookDnD(self, event):
6e48943e821e Adding support for Drag'n dropping panels between notebooks
laurent
parents: 613
diff changeset
  1470
        event.Allow()
6e48943e821e Adding support for Drag'n dropping panels between notebooks
laurent
parents: 613
diff changeset
  1471
    
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1472
    def RefreshTabCtrlEvent(self):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1473
        auitabctrl = []
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1474
        for child in self.TabsOpened.GetChildren():
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1475
            if isinstance(child, wx.aui.AuiTabCtrl):
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1476
                auitabctrl.append(child)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1477
                if child not in self.AuiTabCtrl:
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1478
                    child.Bind(wx.EVT_LEFT_DCLICK, self.GetTabsOpenedDClickFunction(child))
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1479
        self.AuiTabCtrl = auitabctrl
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1480
        if self.TabsOpened.GetPageCount() == 0:
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1481
            pane = self.AUIManager.GetPane(self.TabsOpened)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1482
            if pane.IsMaximized():
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1483
                self.AUIManager.RestorePane(pane)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1484
            self.AUIManager.Update()
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1485
    
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1486
    def EnsureTabVisible(self, tab):
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1487
        notebook = tab.GetParent()
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1488
        notebook.SetSelection(notebook.GetPageIndex(tab))
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1489
    
631
e4dd5bf1f1db Fix segmentation fault happening when changing POU tab selection
laurent
parents: 625
diff changeset
  1490
    def OnPouSelectedChanging(self, event):
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1491
        if not self.Starting:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1492
            selected = self.TabsOpened.GetSelection()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1493
            if selected >= 0:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1494
                window = self.TabsOpened.GetPage(selected)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1495
                if not window.IsDebugging():
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1496
                    window.ResetBuffer()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1497
        event.Skip()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1498
    
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1499
    def OnPouSelectedChanged(self, event):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1500
        if not self.Starting:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1501
            selected = self.TabsOpened.GetSelection()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1502
            if selected >= 0:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1503
                window = self.TabsOpened.GetPage(selected)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1504
                tagname = window.GetTagName()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1505
                if not window.IsDebugging():
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1506
                    wx.CallAfter(self.SelectProjectTreeItem, tagname)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1507
                    wx.CallAfter(self.PouInstanceVariablesPanel.SetPouType, tagname)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1508
                    window.RefreshView()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1509
                    self.EnsureTabVisible(self.LibraryPanel)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1510
                else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1511
                    instance_path = window.GetInstancePath()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1512
                    if tagname == "":
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1513
                        instance_path = instance_path.rsplit(".", 1)[0]
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1514
                        tagname = self.Controler.GetPouInstanceTagName(instance_path, self.EnableDebug)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1515
                    self.EnsureTabVisible(self.DebugVariablePanel)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1516
                    wx.CallAfter(self.PouInstanceVariablesPanel.SetPouType, tagname, instance_path)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1517
            wx.CallAfter(self._Refresh, FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1518
        event.Skip()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1519
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1520
    def RefreshEditor(self):
631
e4dd5bf1f1db Fix segmentation fault happening when changing POU tab selection
laurent
parents: 625
diff changeset
  1521
        selected = self.TabsOpened.GetSelection()
e4dd5bf1f1db Fix segmentation fault happening when changing POU tab selection
laurent
parents: 625
diff changeset
  1522
        if selected >= 0:
e4dd5bf1f1db Fix segmentation fault happening when changing POU tab selection
laurent
parents: 625
diff changeset
  1523
            window = self.TabsOpened.GetPage(selected)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1524
            if not window.IsDebugging():
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1525
                self.SelectProjectTreeItem(window.GetTagName())
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1526
            else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1527
                self.PouInstanceVariablesPanel.SetPouType(window.GetTagName(), window.GetInstancePath())
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1528
            for child in self.TabsOpened.GetChildren():
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1529
                if isinstance(child, wx.aui.AuiTabCtrl):
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1530
                    active_page = child.GetActivePage()
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1531
                    if active_page >= 0:
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1532
                        window = child.GetWindowFromIdx(active_page)
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  1533
                        window.RefreshView()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1534
            self._Refresh(FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1535
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1536
    def RefreshEditorNames(self, old_tagname, new_tagname):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1537
        for i in xrange(self.TabsOpened.GetPageCount()):
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1538
            editor = self.TabsOpened.GetPage(i)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1539
            if editor.GetTagName() == old_tagname:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1540
                editor.SetTagName(new_tagname)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1541
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1542
    def IsOpened(self, tagname):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1543
        for idx in xrange(self.TabsOpened.GetPageCount()):
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1544
            if self.TabsOpened.GetPage(idx).IsViewing(tagname):
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1545
                return idx
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1546
        return None
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1547
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1548
    def RefreshPageTitles(self):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1549
        for idx in xrange(self.TabsOpened.GetPageCount()):
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1550
            window = self.TabsOpened.GetPage(idx)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1551
            icon = window.GetIcon()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1552
            if icon is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1553
                self.SetPageBitmap(idx, icon)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1554
            self.TabsOpened.SetPageText(idx, window.GetTitle())
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1555
335
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1556
    def GetTabsOpenedDClickFunction(self, tabctrl):
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1557
        def OnTabsOpenedDClick(event):
335
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1558
            pos = event.GetPosition()
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1559
            if tabctrl.TabHitTest(pos.x, pos.y, None):
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1560
                pane = self.AUIManager.GetPane(self.TabsOpened)
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1561
                if pane.IsMaximized():
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1562
                    self.AUIManager.RestorePane(pane)
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1563
                else:
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1564
                    self.AUIManager.MaximizePane(pane)
c2c6db53a04f Fix bug with maximize on TabCtrl DoubleClick.
lbessard
parents: 332
diff changeset
  1565
                self.AUIManager.Update()
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1566
            event.Skip()
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 324
diff changeset
  1567
        return OnTabsOpenedDClick
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1568
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1569
#-------------------------------------------------------------------------------
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  1570
#                         Types Tree Management Functions
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1571
#-------------------------------------------------------------------------------
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1572
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1573
    def RefreshProjectTree(self):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1574
        infos = self.Controler.GetProjectInfos()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1575
        root = self.ProjectTree.GetRootItem()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1576
        if not root.IsOk():
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1577
            root = self.ProjectTree.AddRoot(infos["name"])
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1578
        self.GenerateProjectTreeBranch(root, infos)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1579
        self.ProjectTree.Expand(root)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1580
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1581
    def ResetSelectedItem(self):
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1582
        self.SelectedItem = None
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1583
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1584
    def GenerateProjectTreeBranch(self, root, infos):
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1585
        to_delete = []
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1586
        item_name = infos["name"]
512
07a7989f58e4 Fix unwanted translations in TypesTree
laurent
parents: 503
diff changeset
  1587
        if infos["type"] in ITEMS_UNEDITABLE:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1588
        	if len(infos["values"]) == 1:
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1589
        		return self.GenerateProjectTreeBranch(root, infos["values"][0])
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1590
        	item_name = _(item_name)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1591
        self.ProjectTree.SetItemText(root, item_name)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1592
        self.ProjectTree.SetPyData(root, infos)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  1593
        highlight_colours = self.Highlights.get(infos.get("tagname", None), (wx.WHITE, wx.BLACK))
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1594
        self.ProjectTree.SetItemBackgroundColour(root, highlight_colours[0])
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1595
        self.ProjectTree.SetItemTextColour(root, highlight_colours[1])
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1596
        if infos["type"] == ITEM_POU:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1597
            self.ProjectTree.SetItemImage(root, self.TreeImageDict[self.Controler.GetPouBodyType(infos["name"])])
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1598
        elif infos.has_key("icon") and infos["icon"] is not None:
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1599
            icon_path = infos["icon"]
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1600
            if not self.TreeImageDict.has_key(icon_path):
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1601
                self.TreeImageDict[icon_path] = self.TreeImageList.Add(wx.Bitmap(icon_path))
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1602
            self.ProjectTree.SetItemImage(root, self.TreeImageDict[icon_path])
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1603
        elif self.TreeImageDict.has_key(infos["type"]):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1604
            self.ProjectTree.SetItemImage(root, self.TreeImageDict[infos["type"]])      
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1605
        
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1606
        if wx.VERSION >= (2, 6, 0):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1607
            item, root_cookie = self.ProjectTree.GetFirstChild(root)
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1608
        else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1609
            item, root_cookie = self.ProjectTree.GetFirstChild(root, 0)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1610
        for values in infos["values"]:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1611
            if values["type"] not in ITEMS_UNEDITABLE or len(values["values"]) > 0:
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1612
                if not item.IsOk():
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1613
                    item = self.ProjectTree.AppendItem(root, "")
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1614
                    if wx.Platform != '__WXMSW__':
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1615
                        item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1616
                self.GenerateProjectTreeBranch(item, values)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1617
                item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1618
        while item.IsOk():
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1619
            to_delete.append(item)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1620
            item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1621
        for item in to_delete:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1622
            self.ProjectTree.Delete(item)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1623
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1624
    def SelectProjectTreeItem(self, tagname):
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1625
        if self.ProjectTree is not None:
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1626
            root = self.ProjectTree.GetRootItem()
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1627
            if root.IsOk():
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1628
                words = tagname.split("::")
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1629
                if words[0] == "D":
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1630
                    return self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_DATATYPE)])
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1631
                elif words[0] == "P":
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1632
                    return self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_POU)])
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1633
                elif words[0] == "T":
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1634
                    return self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_POU), (words[2], ITEM_TRANSITION)])
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1635
                elif words[0] == "A":
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1636
                    return self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_POU), (words[2], ITEM_ACTION)])
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1637
                elif words[0] == "C":
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1638
                    return self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_CONFIGURATION)])
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1639
                elif words[0] == "R":
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1640
                    return self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_CONFIGURATION), (words[2], ITEM_RESOURCE)])
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 223
diff changeset
  1641
        return False
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 223
diff changeset
  1642
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1643
    def RecursiveProjectTreeItemSelection(self, root, items):
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1644
        found = False
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1645
        if wx.VERSION >= (2, 6, 0):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1646
            item, root_cookie = self.ProjectTree.GetFirstChild(root)
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1647
        else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1648
            item, root_cookie = self.ProjectTree.GetFirstChild(root, 0)
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1649
        while item.IsOk() and not found:
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1650
            item_infos = self.ProjectTree.GetPyData(item)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1651
            if (item_infos["name"].split(":")[-1].strip(), item_infos["type"]) == items[0]:
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1652
                if len(items) == 1:
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1653
                    self.SelectedItem = item
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1654
                    self.ProjectTree.SelectItem(item)
635
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1655
                    wx.CallAfter(self.ResetSelectedItem)
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1656
                    return True
dbcb8e2d2730 Fix bug while using 'Close project' menu and a few POUs are opened
laurent
parents: 631
diff changeset
  1657
                else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1658
                    found = self.RecursiveProjectTreeItemSelection(item, items[1:])
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1659
            else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1660
                found = self.RecursiveProjectTreeItemSelection(item, items)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1661
            item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1662
        return found
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1663
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1664
    def OnProjectTreeBeginDrag(self, event):
131
bc534997aecc Bug on Project Tree with Windows fixed
lbessard
parents: 129
diff changeset
  1665
        if wx.Platform == '__WXMSW__':
134
6715fd958477 Bug on Drag and Drop fixed
lbessard
parents: 133
diff changeset
  1666
            self.SelectedItem = event.GetItem()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1667
        if self.SelectedItem is not None and self.ProjectTree.GetPyData(self.SelectedItem)["type"] == ITEM_POU:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1668
            block_name = self.ProjectTree.GetItemText(self.SelectedItem)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1669
            block_type = self.Controler.GetPouType(block_name)
53
4988262d03e3 *** empty log message ***
lbessard
parents: 52
diff changeset
  1670
            if block_type != "program":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  1671
                data = wx.TextDataObject(str((block_name, block_type, "")))
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1672
                dragSource = wx.DropSource(self.ProjectTree)
53
4988262d03e3 *** empty log message ***
lbessard
parents: 52
diff changeset
  1673
                dragSource.SetData(data)
4988262d03e3 *** empty log message ***
lbessard
parents: 52
diff changeset
  1674
                dragSource.DoDragDrop()
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1675
            self.ResetSelectedItem()
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
  1676
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1677
    def OnProjectTreeItemBeginEdit(self, event):
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1678
        selected = event.GetItem()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1679
        if self.ProjectTree.GetPyData(selected)["type"] in ITEMS_UNEDITABLE:
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1680
            event.Veto()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1681
        else:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1682
            event.Skip()
107
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1683
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1684
    def OnProjectTreeItemEndEdit(self, event):
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1685
        message = None
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1686
        abort = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1687
        new_name = event.GetLabel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1688
        if new_name != "":
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1689
            if not TestIdentifier(new_name):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1690
                message = _("\"%s\" is not a valid identifier!")%new_name
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1691
            elif new_name.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1692
                message = _("\"%s\" is a keyword. It can't be used!")%new_name
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1693
            else:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1694
                item = event.GetItem()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1695
                old_name = self.ProjectTree.GetItemText(item)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1696
                item_infos = self.ProjectTree.GetPyData(item)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1697
                if item_infos["type"] == ITEM_PROJECT:
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 55
diff changeset
  1698
                    self.Controler.SetProjectProperties(name = new_name)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1699
                elif item_infos["type"] == ITEM_DATATYPE:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1700
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectDataTypeNames() if name != old_name]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1701
                        message = _("\"%s\" data type already exists!")%new_name
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  1702
                        abort = True
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  1703
                    if not abort:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  1704
                        self.Controler.ChangeDataTypeName(old_name, new_name)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1705
                        self.RefreshEditorNames(self.Controler.ComputeDataTypeName(old_name), 
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1706
                                                self.Controler.ComputeDataTypeName(new_name))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  1707
                        self.RefreshPageTitles()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1708
                elif item_infos["type"] == ITEM_POU:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1709
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames() if name != old_name]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1710
                        message = _("\"%s\" pou already exists!")%new_name
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1711
                        abort = True
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1712
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  1713
                        messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  1714
                        if messageDialog.ShowModal() == wx.ID_NO:
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1715
                            abort = True
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1716
                        messageDialog.Destroy()
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1717
                    if not abort:
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1718
                        self.Controler.ChangePouName(old_name, new_name)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1719
                        self.RefreshEditorNames(self.Controler.ComputePouName(old_name), 
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1720
                                                self.Controler.ComputePouName(new_name))
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  1721
                        self.RefreshLibraryPanel()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1722
                        self.RefreshPageTitles()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1723
                elif item_infos["type"] == ITEM_TRANSITION:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1724
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  1725
                        message = _("A POU named \"%s\" already exists!")%new_name
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1726
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name) if name != old_name]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1727
                        message = _("A variable with \"%s\" as name already exists in this pou!")%new_name
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1728
                    else:
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1729
                        words = item_infos["tagname"].split("::")
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1730
                        self.Controler.ChangePouTransitionName(words[1], old_name, new_name)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1731
                        self.RefreshEditorNames(self.Controler.ComputePouTransitionName(words[1], old_name), 
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1732
                                                self.Controler.ComputePouTransitionName(words[1], new_name))
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1733
                        self.RefreshPageTitles()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1734
                elif item_infos["type"] == ITEM_ACTION:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1735
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  1736
                        message = _("A POU named \"%s\" already exists!")%new_name
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1737
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name) if name != old_name]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1738
                        message = _("A variable with \"%s\" as name already exists in this pou!")%new_name
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1739
                    else:
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1740
                        words = item_infos["tagname"].split("::")
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1741
                        self.Controler.ChangePouActionName(words[1], old_name, new_name)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1742
                        self.RefreshEditorNames(self.Controler.ComputePouActionName(words[1], old_name), 
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1743
                                                self.Controler.ComputePouActionName(words[1], new_name))
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1744
                        self.RefreshPageTitles()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1745
                elif item_infos["type"] == ITEM_CONFIGURATION:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1746
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames() if name != old_name]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1747
                        message = _("\"%s\" config already exists!")%new_name
107
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1748
                        abort = True
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1749
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  1750
                        messageDialog = wx.MessageDialog(self, _("There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
107
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1751
                        if messageDialog.ShowModal() == wx.ID_NO:
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1752
                            abort = True
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1753
                        messageDialog.Destroy()
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1754
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  1755
                        messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
107
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1756
                        if messageDialog.ShowModal() == wx.ID_NO:
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1757
                            abort = True
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1758
                        messageDialog.Destroy()
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1759
                    if not abort:
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1760
                        self.Controler.ChangeConfigurationName(old_name, new_name)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1761
                        self.RefreshEditorNames(self.Controler.ComputeConfigurationName(old_name), 
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1762
                                                self.Controler.ComputeConfigurationName(new_name))
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1763
                        self.RefreshPageTitles()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1764
                elif item_infos["type"] == ITEM_RESOURCE:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1765
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames()]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1766
                        message = _("\"%s\" config already exists!")%new_name
107
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1767
                        abort = True
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1768
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  1769
                        messageDialog = wx.MessageDialog(self, _("There is a POU named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
107
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1770
                        if messageDialog.ShowModal() == wx.ID_NO:
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1771
                            abort = True
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1772
                        messageDialog.Destroy()
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1773
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  1774
                        messageDialog = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%new_name, _("Error"), wx.YES_NO|wx.ICON_QUESTION)
107
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1775
                        if messageDialog.ShowModal() == wx.ID_NO:
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1776
                            abort = True
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1777
                        messageDialog.Destroy()
255eada20688 Lots of bug fixed
lbessard
parents: 102
diff changeset
  1778
                    if not abort:
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1779
                        words = item_infos["tagname"].split("::")
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1780
                        self.Controler.ChangeConfigurationResourceName(words[1], old_name, new_name)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1781
                        self.RefreshEditorNames(self.Controler.ComputeConfigurationResourceName(words[1], old_name), 
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1782
                                                self.Controler.ComputeConfigurationResourceName(words[1], new_name))
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1783
                        self.RefreshPageTitles()
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1784
            if message or abort:
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1785
                if message:
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1786
                    self.ShowErrorMessage(message)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1787
                item = event.GetItem()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1788
                wx.CallAfter(self.ProjectTree.EditLabel, item)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1789
                event.Veto()
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1790
            else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1791
                wx.CallAfter(self.RefreshProjectTree)
350
f7958989e055 Adding support for Enable/Disable Undo/Redo
greg
parents: 347
diff changeset
  1792
                self.RefreshEditor()
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  1793
                self._Refresh(TITLE, FILEMENU, EDITMENU)
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  1794
                event.Skip()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1795
    
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1796
    def OnProjectTreeItemActivated(self, event):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1797
        selected = event.GetItem()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1798
        name = self.ProjectTree.GetItemText(selected)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1799
        item_infos = self.ProjectTree.GetPyData(selected)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1800
        if item_infos["type"] == ITEM_PROJECT:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1801
            self.EditProjectSettings()
700
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents: 699
diff changeset
  1802
        else:
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents: 699
diff changeset
  1803
            if item_infos["type"] in [ITEM_DATATYPE, ITEM_POU,
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1804
                                    ITEM_CONFIGURATION, ITEM_RESOURCE,
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1805
                                    ITEM_TRANSITION, ITEM_ACTION]:
700
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents: 699
diff changeset
  1806
                self.EditProjectElement(item_infos["type"], item_infos["tagname"])
cf3db1775105 Separating ProjectDialog from PLCOpenEditor for integration of panel into Beremiz project window
Laurent Bessard
parents: 699
diff changeset
  1807
            event.Skip()
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1808
    
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1809
    def ProjectTreeItemSelect(self, select_item):
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1810
        name = self.ProjectTree.GetItemText(select_item)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1811
        item_infos = self.ProjectTree.GetPyData(select_item)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1812
        if item_infos["type"] in [ITEM_DATATYPE, ITEM_POU,
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1813
                                  ITEM_CONFIGURATION, ITEM_RESOURCE,
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1814
                                  ITEM_TRANSITION, ITEM_ACTION]:
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1815
            self.EditProjectElement(item_infos["type"], item_infos["tagname"], True)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1816
            self.PouInstanceVariablesPanel.SetPouType(item_infos["tagname"])
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1817
        
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1818
    def OnProjectTreeLeftUp(self, event):
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1819
        if self.SelectedItem is not None:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1820
            self.ProjectTree.SelectItem(self.SelectedItem)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1821
            self.ProjectTreeItemSelect(self.SelectedItem)
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1822
            wx.CallAfter(self.ResetSelectedItem)
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1823
        event.Skip()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1824
    
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1825
    def OnProjectTreeItemSelected(self, event):
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1826
        self.ProjectTreeItemSelect(event.GetItem())
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1827
        event.Skip()
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1828
    
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1829
    def OnProjectTreeItemChanging(self, event):
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1830
        if self.ProjectTree.GetPyData(event.GetItem())["type"] not in ITEMS_UNEDITABLE and self.SelectedItem is None:
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1831
            self.SelectedItem = event.GetItem()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1832
            event.Veto()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1833
        else:
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1834
            event.Skip()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1835
    
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1836
    def EditProjectElement(self, element, tagname, onlyopened = False):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1837
        openedidx = self.IsOpened(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1838
        if openedidx is not None:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1839
            old_selected = self.TabsOpened.GetSelection()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1840
            if old_selected != openedidx:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1841
                if old_selected >= 0:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1842
                    self.TabsOpened.GetPage(old_selected).ResetBuffer()
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1843
                self.TabsOpened.SetSelection(openedidx)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  1844
            self._Refresh(FILEMENU, EDITMENU, EDITORTOOLBAR, PAGETITLES)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  1845
        elif not onlyopened:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1846
            new_window = None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1847
            if element == ITEM_CONFIGURATION:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1848
                new_window = ConfigurationEditor(self.TabsOpened, tagname, self, self.Controler)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1849
                new_window.SetIcon(self.GenerateBitmap("CONFIGURATION"))
337
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  1850
                self.AddPage(new_window, "")
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1851
            elif element == ITEM_RESOURCE:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1852
                new_window = ResourceEditor(self.TabsOpened, tagname, self, self.Controler)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1853
                new_window.SetIcon(self.GenerateBitmap("RESOURCE"))
337
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  1854
                self.AddPage(new_window, "")
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1855
            elif element in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  1856
                bodytype = self.Controler.GetEditedElementBodyType(tagname)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1857
                if bodytype == "FBD":
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1858
                    new_window = Viewer(self.TabsOpened, tagname, self, self.Controler)
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1859
                    new_window.RefreshScaling(False)
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1860
                elif bodytype == "LD":
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1861
                    new_window = LD_Viewer(self.TabsOpened, tagname, self, self.Controler)
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1862
                    new_window.RefreshScaling(False)
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1863
                elif bodytype == "SFC":
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1864
                    new_window = SFC_Viewer(self.TabsOpened, tagname, self, self.Controler)
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1865
                    new_window.RefreshScaling(False)
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1866
                else:
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1867
                    new_window = TextViewer(self.TabsOpened, tagname, self, self.Controler)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 245
diff changeset
  1868
                    new_window.SetTextSyntax(bodytype)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1869
                    if bodytype == "IL":
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1870
                        new_window.SetKeywords(IL_KEYWORDS)
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1871
                    else:
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1872
                        new_window.SetKeywords(ST_KEYWORDS)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1873
                if element == ITEM_POU:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1874
                    pou_type = self.Controler.GetEditedElementType(tagname)[1].upper()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1875
                    icon = self.GenerateBitmap(pou_type, bodytype)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1876
                elif element == ITEM_TRANSITION:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1877
                    icon = self.GenerateBitmap("TRANSITION", bodytype)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1878
                elif element == ITEM_ACTION:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1879
                    icon = self.GenerateBitmap("ACTION", bodytype)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1880
                new_window.SetIcon(icon)
337
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  1881
                self.AddPage(new_window, "")
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1882
            elif element == ITEM_DATATYPE:
451
20464365086e Bug while trying to open DataTypeEditor fixed
laurent
parents: 450
diff changeset
  1883
                new_window = DataTypeEditor(self.TabsOpened, tagname, self, self.Controler)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1884
                new_window.SetIcon(self.GenerateBitmap("DATATYPE"))
337
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  1885
                self.AddPage(new_window, "")
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1886
            elif isinstance(element, EditorPanel):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1887
                new_window = element
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1888
                self.AddPage(element, "")
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1889
            if new_window is not None:
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1890
                project_infos = self.GetProjectConfiguration()
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1891
                if project_infos.has_key("editors_state"):
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1892
                    state = project_infos["editors_state"].get(tagname)
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1893
                    if state is not None:
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1894
                        wx.CallAfter(new_window.SetState, state)
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  1895
                
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1896
                openedidx = self.IsOpened(tagname)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1897
                old_selected = self.TabsOpened.GetSelection()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1898
                if old_selected != openedidx:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1899
                    if old_selected >= 0:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1900
                        self.TabsOpened.GetPage(old_selected).ResetBuffer()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1901
                for i in xrange(self.TabsOpened.GetPageCount()):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1902
                    window = self.TabsOpened.GetPage(i)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1903
                    if window == new_window:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1904
                        self.TabsOpened.SetSelection(i)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1905
                        window.SetFocus()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  1906
                self.RefreshPageTitles()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  1907
            return new_window
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1908
    
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1909
    def OnProjectTreeRightUp(self, event):
159
76b2facf14a2 Bug on TreeCtrl right click on Windows fixed
lbessard
parents: 145
diff changeset
  1910
        if wx.Platform == '__WXMSW__':
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1911
            item = event.GetItem()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1912
        else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1913
            item, flags = self.ProjectTree.HitTest(wx.Point(event.GetX(), event.GetY()))
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1914
        self.ProjectTree.SelectItem(item)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1915
        self.ProjectTreeItemSelect(item)
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1916
        name = self.ProjectTree.GetItemText(item)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1917
        item_infos = self.ProjectTree.GetPyData(item)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1918
        
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1919
        menu = None
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1920
        if item_infos["type"] in ITEMS_UNEDITABLE:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1921
            name = UNEDITABLE_NAMES_DICT[name]
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1922
            
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1923
            if name == "Data Types":
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1924
                menu = wx.Menu(title='')
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1925
                new_id = wx.NewId()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1926
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add DataType"))
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1927
                self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, id=new_id)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1928
            
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1929
            elif name in ["Functions", "Function Blocks", "Programs"]:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1930
                menu = wx.Menu(title='')
428
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  1931
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1932
                new_id = wx.NewId()
447
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  1933
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add POU"))
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1934
                self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction({"Functions" : "function", "Function Blocks" : "functionBlock", "Programs" : "program"}[name]), id=new_id)
428
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  1935
447
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  1936
                new_id = wx.NewId()
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  1937
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Paste POU"))
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  1938
                self.Bind(wx.EVT_MENU, self.OnPastePou, id=new_id)
428
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  1939
                if self.GetCopyBuffer() is None:
447
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  1940
                    menu.Enable(new_id, False)
428
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  1941
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1942
            elif name == "Configurations":
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1943
                menu = wx.Menu(title='')
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1944
                new_id = wx.NewId()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1945
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Configuration"))
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1946
                self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, id=new_id)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1947
            
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1948
            elif name == "Transitions":
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1949
                menu = wx.Menu(title='')
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1950
                new_id = wx.NewId()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1951
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Transition"))
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1952
                parent = self.ProjectTree.GetItemParent(item)["type"]
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1953
                parent_type = self.ProjectTree.GetPyData(parent)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1954
                while parent_type != ITEM_POU:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1955
                    parent = self.ProjectTree.GetItemParent(parent)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1956
                    parent_type = self.ProjectTree.GetPyData(parent)["type"]
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1957
                self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(self.ProjectTree.GetItemText(parent)), id=new_id)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1958
            
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1959
            elif name == "Actions":
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1960
                menu = wx.Menu(title='')
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1961
                new_id = wx.NewId()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1962
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Action"))
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1963
                parent = self.ProjectTree.GetItemParent(item)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1964
                parent_type = self.ProjectTree.GetPyData(parent)["type"]
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1965
                while parent_type != ITEM_POU:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1966
                    parent = self.ProjectTree.GetItemParent(parent)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1967
                    parent_type = self.ProjectTree.GetPyData(parent)["type"]
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1968
                self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(self.ProjectTree.GetItemText(parent)), id=new_id)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1969
            
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1970
            elif name == "Resources":
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1971
                menu = wx.Menu(title='')
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  1972
                new_id = wx.NewId()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  1973
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Resource"))
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1974
                parent = self.ProjectTree.GetItemParent(item)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1975
                parent_type = self.ProjectTree.GetPyData(parent)["type"]
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1976
                while parent_type not in [ITEM_CONFIGURATION, ITEM_PROJECT]:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  1977
                    parent = self.ProjectTree.GetItemParent(parent)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1978
                    parent_type = self.ProjectTree.GetPyData(parent)["type"]
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1979
                if parent_type == ITEM_PROJECT:
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1980
                    parent_name = None
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1981
                else:
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1982
                    parent_name = self.ProjectTree.GetItemText(parent)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1983
                self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(parent_name), id=new_id)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1984
            
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1985
        else:
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  1986
            if item_infos["type"] == ITEM_POU:
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1987
                menu = wx.Menu(title='')
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1988
                if self.Controler.GetPouBodyType(name) == "SFC":
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1989
                    new_id = wx.NewId()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1990
                    AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Transition"))
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1991
                    self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(name), id=new_id)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1992
                    new_id = wx.NewId()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1993
                    AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Action"))
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1994
                    self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(name), id=new_id)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1995
                    menu.AppendSeparator()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1996
    
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1997
                new_id = wx.NewId()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1998
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Copy POU"))
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  1999
                self.Bind(wx.EVT_MENU, self.OnCopyPou, id=new_id)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2000
    
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2001
                pou_type = self.Controler.GetPouType(name)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2002
                if pou_type in ["function", "functionBlock"]:
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2003
                    change_menu = wx.Menu(title='')
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2004
                    if pou_type == "function":
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2005
                        new_id = wx.NewId()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2006
                        AppendMenu(change_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Function Block"))
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2007
                        self.Bind(wx.EVT_MENU, self.GenerateChangePouTypeFunction(name, "functionBlock"), id=new_id)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2008
                    new_id = wx.NewId()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2009
                    AppendMenu(change_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Program"))
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2010
                    self.Bind(wx.EVT_MENU, self.GenerateChangePouTypeFunction(name, "program"), id=new_id)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2011
                    menu.AppendMenu(wx.NewId(), _("Change POU Type To"), change_menu)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2012
                new_id = wx.NewId()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2013
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Rename"))
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2014
                self.Bind(wx.EVT_MENU, self.OnRenamePouMenu, id=new_id)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2015
            
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2016
            elif item_infos["type"] == ITEM_CONFIGURATION:
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2017
                menu = wx.Menu(title='')
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2018
                new_id = wx.NewId()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2019
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Resource"))
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2020
                self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(name), id=new_id)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2021
            
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2022
            elif item_infos["type"] in [ITEM_DATATYPE, ITEM_TRANSITION, ITEM_ACTION, ITEM_RESOURCE]:
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2023
                menu = wx.Menu(title='')
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2024
                
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2025
            if menu is not None:
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2026
                new_id = wx.NewId()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2027
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Delete"))
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2028
                self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=new_id)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2029
        
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2030
        if menu is not None:
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2031
            self.PopupMenu(menu)
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2032
            menu.Destroy()
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2033
        
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2034
        event.Skip()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2035
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2036
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2037
#-------------------------------------------------------------------------------
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2038
#                         Instances Tree Management Functions
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2039
#-------------------------------------------------------------------------------
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2040
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2041
    def GetTreeImage(self, var_class):
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2042
        return self.TreeImageDict[var_class]
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2043
    
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2044
    def RefreshPouInstanceVariablesPanel(self):
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2045
        self.PouInstanceVariablesPanel.RefreshView()
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  2046
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2047
    def OpenDebugViewer(self, instance_category, instance_path, instance_type):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2048
        openedidx = self.IsOpened(instance_path)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2049
        if openedidx is not None:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2050
            old_selected = self.TabsOpened.GetSelection()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2051
            if old_selected != openedidx:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2052
                if old_selected >= 0:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2053
                    self.TabsOpened.GetPage(old_selected).ResetBuffer()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2054
                self.TabsOpened.SetSelection(openedidx)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2055
        
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2056
        elif instance_category in ITEMS_VARIABLE:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2057
            if self.Controler.IsOfType(instance_type, "ANY_NUM", True) or\
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2058
               self.Controler.IsOfType(instance_type, "ANY_BIT", True):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2059
                
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2060
                return self.OpenGraphicViewer(instance_path)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2061
        
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2062
        else:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2063
            bodytype = self.Controler.GetEditedElementBodyType(instance_type, True)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2064
            new_window = None
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2065
            if bodytype == "FBD":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2066
                new_window = Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2067
                new_window.RefreshScaling(False)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2068
            elif bodytype == "LD":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2069
                new_window = LD_Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2070
                new_window.RefreshScaling(False)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2071
            elif bodytype == "SFC":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2072
                new_window = SFC_Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2073
                new_window.RefreshScaling(False)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2074
            else:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2075
                new_window = TextViewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2076
                new_window.SetTextSyntax(bodytype)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2077
                if bodytype == "IL":
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2078
                    new_window.SetKeywords(IL_KEYWORDS)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2079
                else:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2080
                    new_window.SetKeywords(ST_KEYWORDS)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2081
            if new_window is not None:
675
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  2082
                project_infos = self.GetProjectConfiguration()
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  2083
                if project_infos.has_key("editors_state"):
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  2084
                    state = project_infos["editors_state"].get(instance_path)
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  2085
                    if state is not None:
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  2086
                        wx.CallAfter(new_window.SetState, state)
0ea836add01f Adding support for saving and restoring zoom and position of editors through closing and opening tab of the same POU or POU instance
laurent
parents: 673
diff changeset
  2087
                
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2088
                if instance_category in [ITEM_FUNCTIONBLOCK, ITEM_PROGRAM]:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2089
                    pou_type = self.Controler.GetEditedElementType(instance_type, True)[1].upper()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2090
                    icon = self.GenerateBitmap(pou_type, bodytype)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2091
                elif instance_category == ITEM_TRANSITION:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2092
                    icon = self.GenerateBitmap("TRANSITION", bodytype)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2093
                elif instance_category == ITEM_ACTION:
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2094
                    icon = self.GenerateBitmap("ACTION", bodytype)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2095
                new_window.SetIcon(icon)
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2096
                self.AddPage(new_window, "")
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2097
                new_window.RefreshView()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2098
                new_window.SetFocus()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2099
                self.RefreshPageTitles()
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2100
            return new_window
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2101
        
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2102
        return None
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2103
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  2104
    def OpenGraphicViewer(self, var_path):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  2105
        new_window = GraphicViewer(self.TabsOpened, self, self.Controler, var_path)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  2106
        self.AddPage(new_window, "")
648
95d165193770 Fix bug in GraphicViewer when changing range while no data received
laurent
parents: 647
diff changeset
  2107
        new_window.RefreshView()
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  2108
        new_window.SetFocus()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  2109
        self.RefreshPageTitles()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2110
        return new_window
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents: 298
diff changeset
  2111
337
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  2112
    def ResetGraphicViewers(self):
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  2113
        for i in xrange(self.TabsOpened.GetPageCount()):
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  2114
            editor = self.TabsOpened.GetPage(i)
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  2115
            if isinstance(editor, GraphicViewer):
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  2116
                editor.ResetView()
388a00b05b6b Bug with maximize on Tab Double Click fixed
lbessard
parents: 335
diff changeset
  2117
647
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  2118
    def CloseObsoleteDebugTabs(self):
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  2119
        if self.EnableDebug:
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  2120
            idxs = range(self.TabsOpened.GetPageCount())
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  2121
            idxs.reverse()
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  2122
            for idx in idxs:
647
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  2123
                editor = self.TabsOpened.GetPage(idx)
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  2124
                if editor.IsDebugging():
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2125
                    instance_infos = self.Controler.GetInstanceInfos(editor.GetInstancePath(), self.EnableDebug)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2126
                    if instance_infos is None:
647
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  2127
                        self.TabsOpened.DeletePage(idx)
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  2128
                    elif isinstance(editor, GraphicViewer):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2129
                        editor.ResetView(True)
647
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  2130
                    else:
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  2131
                        editor.RefreshView()
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  2132
            self.DebugVariablePanel.UnregisterObsoleteData()
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  2133
    
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2134
    def AddDebugVariable(self, iec_path, force=False):
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  2135
        if self.EnableDebug:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2136
            self.DebugVariablePanel.InsertValue(iec_path, force=force)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2137
            self.EnsureTabVisible(self.DebugVariablePanel)
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  2138
            
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2139
#-------------------------------------------------------------------------------
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  2140
#                         Library Panel Management Function
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  2141
#-------------------------------------------------------------------------------
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  2142
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  2143
    def RefreshLibraryPanel(self):
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  2144
        self.LibraryPanel.RefreshTree()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  2145
        
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2146
#-------------------------------------------------------------------------------
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2147
#                          ToolBars Management Functions
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2148
#-------------------------------------------------------------------------------
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2149
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2150
    def AddToMenuToolBar(self, items):
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2151
        MenuToolBar = self.Panes["MenuToolBar"]
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2152
        if MenuToolBar.GetToolsCount() > 0:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2153
            MenuToolBar.AddSeparator()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2154
        for toolbar_item in items:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2155
            if toolbar_item is None:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2156
                MenuToolBar.AddSeparator()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2157
            else:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2158
                id, bitmap, help, callback = toolbar_item
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2159
                MenuToolBar.AddSimpleTool(id=id, shortHelpString=help, bitmap=wx.Bitmap(os.path.join(CWD, 'Images', bitmap)))
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2160
                if callback is not None:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2161
                    self.Bind(wx.EVT_TOOL, callback, id=id)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2162
        MenuToolBar.Realize()
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2163
        self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize())
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2164
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2165
    def ResetEditorToolBar(self):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2166
        EditorToolBar = self.Panes["EditorToolBar"]
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2167
        
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2168
        for item in self.CurrentEditorToolBar:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2169
            if wx.VERSION >= (2, 6, 0):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2170
                self.Unbind(wx.EVT_MENU, id=item)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2171
            else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2172
                self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) 
599
4bb7b132e15d Fixing standard functions library treectrl in library panel in order to make it similar on all platforms
laurent
parents: 587
diff changeset
  2173
        
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2174
            if EditorToolBar:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2175
                EditorToolBar.DeleteTool(item)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2176
        
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2177
        if EditorToolBar:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2178
            EditorToolBar.Realize()
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2179
            self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize())
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2180
            self.AUIManager.Update()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 245
diff changeset
  2181
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2182
    def RefreshEditorToolBar(self):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2183
        selected = self.TabsOpened.GetSelection()
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2184
        menu = None
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2185
        if selected != -1:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2186
            window = self.TabsOpened.GetPage(selected)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2187
            if not window.IsDebugging():
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2188
                menu = self.Controler.GetEditedElementBodyType(window.GetTagName())
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2189
            else:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2190
                menu = "debug"
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2191
        if menu is not None and menu != self.CurrentMenu:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2192
            self.ResetEditorToolBar()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2193
            self.CurrentMenu = menu
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2194
            self.CurrentEditorToolBar = []
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2195
            EditorToolBar = self.Panes["EditorToolBar"]
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2196
            if EditorToolBar:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2197
                for radio, modes, id, method, picture, help in EditorToolBarItems[menu]:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2198
                    if modes & self.DrawingMode:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2199
                        if radio or self.DrawingMode == FREEDRAWING_MODE:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2200
                            EditorToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), wx.NullBitmap, help)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2201
                        else:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2202
                            EditorToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), help)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2203
                        self.Bind(wx.EVT_MENU, getattr(self, method), id=id)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2204
                        self.CurrentEditorToolBar.append(id)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2205
                EditorToolBar.Realize()
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2206
                self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize())
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2207
                self.AUIManager.Update()
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2208
        elif not menu:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2209
            self.ResetEditorToolBar()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2210
            self.CurrentMenu = menu
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2211
        self.ResetCurrentMode()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2212
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2213
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2214
#-------------------------------------------------------------------------------
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2215
#                           EditorToolBar Items Functions
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2216
#-------------------------------------------------------------------------------
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2217
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2218
    def ResetCurrentMode(self):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2219
        selected = self.TabsOpened.GetSelection()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2220
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2221
            window = self.TabsOpened.GetPage(selected)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2222
            window.SetMode(MODE_SELECTION)
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2223
        EditorToolBar = self.Panes["EditorToolBar"]
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2224
        if EditorToolBar:
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2225
            EditorToolBar.ToggleTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, False)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2226
            EditorToolBar.ToggleTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, True)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2227
        
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2228
    def ResetToolToggle(self, id):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2229
        tool = self.Panes["EditorToolBar"].FindById(id)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2230
        tool.SetToggle(False)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2231
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2232
    def OnSelectionTool(self, event):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2233
        selected = self.TabsOpened.GetSelection()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 55
diff changeset
  2234
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2235
            self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION)
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2236
    
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2237
    def OnMotionTool(self, event):
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2238
        selected = self.TabsOpened.GetSelection()
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2239
        if selected != -1:
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2240
            self.TabsOpened.GetPage(selected).SetMode(MODE_MOTION)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2241
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2242
    def OnCommentTool(self, event):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2243
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCOMMENT)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2244
        selected = self.TabsOpened.GetSelection()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 55
diff changeset
  2245
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2246
            self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2247
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2248
    def OnVariableTool(self, event):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2249
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARVARIABLE)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2250
        selected = self.TabsOpened.GetSelection()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2251
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2252
            self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2253
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2254
    def OnBlockTool(self, event):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2255
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARBLOCK)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2256
        selected = self.TabsOpened.GetSelection()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2257
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2258
            self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2259
        
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2260
    def OnConnectionTool(self, event):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2261
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCONNECTION)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2262
        selected = self.TabsOpened.GetSelection()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2263
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2264
            self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION)
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2265
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2266
    def OnPowerRailTool(self, event):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2267
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2268
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2269
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2270
            self.TabsOpened.GetPage(selected).SetMode(MODE_POWERRAIL)
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2271
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2272
    def OnRungTool(self, event):
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2273
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2274
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2275
            self.TabsOpened.GetPage(selected).AddLadderRung()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2276
        event.Skip()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2277
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2278
    def OnCoilTool(self, event):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2279
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCOIL)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2280
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2281
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2282
            self.TabsOpened.GetPage(selected).SetMode(MODE_COIL)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2283
        event.Skip()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2284
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2285
    def OnContactTool(self, event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2286
        if self.DrawingMode == FREEDRAWING_MODE:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2287
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCONTACT)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2288
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2289
        if selected != -1:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2290
            if self.DrawingMode == FREEDRAWING_MODE:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2291
                self.TabsOpened.GetPage(selected).SetMode(MODE_CONTACT)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2292
            else:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2293
                self.TabsOpened.GetPage(selected).AddLadderContact()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2294
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2295
    def OnBranchTool(self, event): 
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2296
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2297
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2298
            self.TabsOpened.GetPage(selected).AddLadderBranch()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2299
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2300
    def OnInitialStepTool(self, event):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2301
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2302
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2303
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2304
            self.TabsOpened.GetPage(selected).SetMode(MODE_INITIALSTEP)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2305
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2306
    def OnStepTool(self, event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2307
        if self.GetDrawingMode() == FREEDRAWING_MODE:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2308
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARSTEP)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2309
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2310
        if selected != -1:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2311
            if self.GetDrawingMode() == FREEDRAWING_MODE:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2312
                self.TabsOpened.GetPage(selected).SetMode(MODE_STEP)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2313
            else:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2314
                self.TabsOpened.GetPage(selected).AddStep()
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2315
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2316
    def OnActionBlockTool(self, event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2317
        if self.GetDrawingMode() == FREEDRAWING_MODE:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2318
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2319
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2320
        if selected != -1:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2321
            if self.GetDrawingMode() == FREEDRAWING_MODE:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2322
                self.TabsOpened.GetPage(selected).SetMode(MODE_ACTION)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2323
            else:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2324
                self.TabsOpened.GetPage(selected).AddStepAction()
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2325
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2326
    def OnTransitionTool(self, event):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2327
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARTRANSITION)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2328
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2329
        if selected != -1:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2330
            self.TabsOpened.GetPage(selected).SetMode(MODE_TRANSITION)
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2331
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2332
    def OnDivergenceTool(self, event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2333
        if self.GetDrawingMode() == FREEDRAWING_MODE:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2334
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2335
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2336
        if selected != -1:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2337
            if self.GetDrawingMode() == FREEDRAWING_MODE:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2338
                self.TabsOpened.GetPage(selected).SetMode(MODE_DIVERGENCE)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2339
            else:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2340
                self.TabsOpened.GetPage(selected).AddDivergence()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2341
    
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2342
    def OnJumpTool(self, event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2343
        if self.GetDrawingMode() == FREEDRAWING_MODE:
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2344
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARJUMP)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2345
        selected = self.TabsOpened.GetSelection()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2346
        if selected != -1:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2347
            if self.GetDrawingMode() == FREEDRAWING_MODE:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2348
                self.TabsOpened.GetPage(selected).SetMode(MODE_JUMP)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2349
            else:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2350
                self.TabsOpened.GetPage(selected).AddJump()
575
a7c706b9492e Adding hand tool icon in Toolbar for moving the view
laurent
parents: 571
diff changeset
  2351
    
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2352
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2353
#-------------------------------------------------------------------------------
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2354
#                         Add Project Elements Functions
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2355
#-------------------------------------------------------------------------------
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2356
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2357
    def OnAddDataTypeMenu(self, event):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2358
        dialog = DataTypeDialog(self, _("Add a new data type"), _("Please enter data type name"), "", wx.OK|wx.CANCEL)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2359
        dialog.SetDataTypeNames(self.Controler.GetProjectDataTypeNames())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2360
        if dialog.ShowModal() == wx.ID_OK:
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2361
            tagname = self.Controler.ProjectAddDataType(dialog.GetValue())
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2362
            if tagname is not None:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2363
                self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2364
                self.EditProjectElement(ITEM_DATATYPE, tagname)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2365
        dialog.Destroy()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2366
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2367
    def GenerateAddPouFunction(self, pou_type):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2368
        def OnAddPouMenu(event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2369
            dialog = PouDialog(self, pou_type)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2370
            dialog.SetPouNames(self.Controler.GetProjectPouNames())
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2371
            dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2372
            if dialog.ShowModal() == wx.ID_OK:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2373
                values = dialog.GetValues()
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2374
                tagname = self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2375
                if tagname is not None:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2376
                    self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2377
                    self.EditProjectElement(ITEM_POU, tagname)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2378
            dialog.Destroy()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2379
        return OnAddPouMenu
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2380
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2381
    def GenerateAddTransitionFunction(self, pou_name):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2382
        def OnAddTransitionMenu(event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2383
            dialog = PouTransitionDialog(self)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2384
            dialog.SetPouNames(self.Controler.GetProjectPouNames())
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2385
            dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name))
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2386
            if dialog.ShowModal() == wx.ID_OK: 
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2387
                values = dialog.GetValues()
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2388
                tagname = self.Controler.ProjectAddPouTransition(pou_name, values["transitionName"], values["language"])
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2389
                if tagname is not None:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2390
                    self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2391
                    self.EditProjectElement(ITEM_TRANSITION, tagname)
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2392
            dialog.Destroy()
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2393
        return OnAddTransitionMenu
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2394
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2395
    def GenerateAddActionFunction(self, pou_name):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2396
        def OnAddActionMenu(event):
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2397
            dialog = PouActionDialog(self)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2398
            dialog.SetPouNames(self.Controler.GetProjectPouNames())
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2399
            dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name))
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2400
            if dialog.ShowModal() == wx.ID_OK:
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2401
                values = dialog.GetValues()
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2402
                tagname = self.Controler.ProjectAddPouAction(pou_name, values["actionName"], values["language"])
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2403
                if tagname is not None:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2404
                    self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2405
                    self.EditProjectElement(ITEM_ACTION, tagname)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2406
            dialog.Destroy()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2407
        return OnAddActionMenu
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2408
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2409
    def OnAddConfigurationMenu(self, event):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2410
        dialog = ConfigurationNameDialog(self, _("Please enter configuration name"), _("Add new configuration"))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2411
        dialog.SetPouNames(self.Controler.GetProjectPouNames())
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2412
        dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2413
        if dialog.ShowModal() == wx.ID_OK:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2414
            value = dialog.GetValue()
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2415
            tagname = self.Controler.ProjectAddConfiguration(value)
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2416
            if tagname is not None:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2417
                self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2418
                self.EditProjectElement(ITEM_CONFIGURATION, tagname)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2419
        dialog.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2420
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2421
    def GenerateAddResourceFunction(self, config_name):
177
a3f6670949ba fixed bug when add resource
greg
parents: 176
diff changeset
  2422
        def OnAddResourceMenu(event):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2423
            dialog = ResourceNameDialog(self, _("Please enter resource name"), _("Add new resource"))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2424
            dialog.SetPouNames(self.Controler.GetProjectPouNames())
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2425
            dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2426
            if dialog.ShowModal() == wx.ID_OK:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2427
                value = dialog.GetValue()
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2428
                tagname = self.Controler.ProjectAddConfigurationResource(config_name, value)
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2429
                if tagname is not None:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2430
                    self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
555
b6f9d08fd69f Adding support for opening newly created project element
laurent
parents: 540
diff changeset
  2431
                    self.EditProjectElement(ITEM_RESOURCE, tagname)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2432
            dialog.Destroy()
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2433
        return OnAddResourceMenu
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2434
275
acf474a94136 Adding support for upgrading pou types
lbessard
parents: 274
diff changeset
  2435
    def GenerateChangePouTypeFunction(self, name, new_type):
acf474a94136 Adding support for upgrading pou types
lbessard
parents: 274
diff changeset
  2436
        def OnChangePouTypeMenu(event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2437
            selected = self.ProjectTree.GetSelection()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2438
            if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU: 
275
acf474a94136 Adding support for upgrading pou types
lbessard
parents: 274
diff changeset
  2439
                self.Controler.ProjectChangePouType(name, new_type)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2440
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
275
acf474a94136 Adding support for upgrading pou types
lbessard
parents: 274
diff changeset
  2441
        return OnChangePouTypeMenu
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2442
428
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2443
    def OnCopyPou(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2444
        selected = self.ProjectTree.GetSelection()
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2445
        pou_name = self.ProjectTree.GetItemText(selected)
447
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  2446
        
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  2447
        pou_xml = self.Controler.GetPouXml(pou_name)
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  2448
        if pou_xml is not None:
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  2449
            self.SetCopyBuffer(pou_xml)
6083dcecd2c5 Remove 'Create Pou From' option. Fix somme issues with Copy/Paste POU.
laurent
parents: 445
diff changeset
  2450
            self._Refresh(EDITMENU)
428
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2451
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2452
    def OnPastePou(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2453
        selected = self.ProjectTree.GetSelection()
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2454
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2455
        pou_type = self.ProjectTree.GetItemText(selected)
428
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2456
        pou_type = UNEDITABLE_NAMES_DICT[pou_type] # one of 'Functions', 'Function Blocks' or 'Programs'
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2457
        pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type]
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2458
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2459
        pou_xml = self.GetCopyBuffer()
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2460
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2461
        result = self.Controler.PastePou(pou_type, pou_xml)
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2462
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2463
        if result is not None:
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2464
            message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2465
            message.ShowModal()
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2466
            message.Destroy()
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2467
        else:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2468
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
428
3b19c34bac04 copy & paste for POUs
b.taylor@willowglen.ca
parents: 427
diff changeset
  2469
275
acf474a94136 Adding support for upgrading pou types
lbessard
parents: 274
diff changeset
  2470
#-------------------------------------------------------------------------------
acf474a94136 Adding support for upgrading pou types
lbessard
parents: 274
diff changeset
  2471
#                        Remove Project Elements Functions
acf474a94136 Adding support for upgrading pou types
lbessard
parents: 274
diff changeset
  2472
#-------------------------------------------------------------------------------
acf474a94136 Adding support for upgrading pou types
lbessard
parents: 274
diff changeset
  2473
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2474
    def OnRemoveDataTypeMenu(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2475
        selected = self.ProjectTree.GetSelection()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2476
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_DATATYPE:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2477
            name = self.ProjectTree.GetItemText(selected)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2478
            if not self.Controler.DataTypeIsUsed(name):
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2479
                self.Controler.ProjectRemoveDataType(name)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2480
                tagname = self.Controler.ComputeDataTypeName(name)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  2481
                idx = self.IsOpened(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 120
diff changeset
  2482
                if idx is not None:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2483
                    self.TabsOpened.DeletePage(idx)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2484
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2485
            else:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2486
                self.ShowErrorMessage(_("\"%s\" is used by one or more POUs. It can't be removed!"))
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2487
311
3e22e53878b8 Adding Rename item in TypesTree contextual menu
lbessard
parents: 309
diff changeset
  2488
    def OnRenamePouMenu(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2489
        selected = self.ProjectTree.GetSelection()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2490
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU: 
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2491
            wx.CallAfter(self.ProjectTree.EditLabel, selected)
311
3e22e53878b8 Adding Rename item in TypesTree contextual menu
lbessard
parents: 309
diff changeset
  2492
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2493
    def OnRemovePouMenu(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2494
        selected = self.ProjectTree.GetSelection()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2495
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2496
            name = self.ProjectTree.GetItemText(selected)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2497
            if not self.Controler.PouIsUsed(name):
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2498
                self.Controler.ProjectRemovePou(name)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2499
                tagname = self.Controler.ComputePouName(name)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2500
                idx = self.IsOpened(tagname)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2501
                if idx is not None:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2502
                    self.TabsOpened.DeletePage(idx)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2503
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2504
            else:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2505
                self.ShowErrorMessage(_("\"%s\" is used by one or more POUs. It can't be removed!"))
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2506
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2507
    def OnRemoveTransitionMenu(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2508
        selected = self.ProjectTree.GetSelection()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2509
        item_infos = self.ProjectTree.GetPyData(selected)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2510
        if item_infos["type"] == ITEM_TRANSITION: 
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2511
            transition = self.ProjectTree.GetItemText(selected)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2512
            pou_name = item_infos["tagname"].split("::")[1]
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2513
            self.Controler.ProjectRemovePouTransition(pou_name, transition)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2514
            tagname = self.Controler.ComputePouTransitionName(pou_name, transition)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2515
            idx = self.IsOpened(tagname)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2516
            if idx is not None:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2517
                self.TabsOpened.DeletePage(idx)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2518
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2519
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2520
    def OnRemoveActionMenu(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2521
        selected = self.ProjectTree.GetSelection()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2522
        item_infos = self.ProjectTree.GetPyData(selected)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2523
        if item_infos["type"] == ITEM_ACTION: 
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2524
            action = self.ProjectTree.GetItemText(selected)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2525
            pou_name = item_infos["tagname"].split("::")[1]
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2526
            self.Controler.ProjectRemovePouAction(pou_name, action)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2527
            tagname = self.Controler.ComputePouActionName(pou_name, action)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2528
            idx = self.IsOpened(tagname)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2529
            if idx is not None:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2530
                self.TabsOpened.DeletePage(idx)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2531
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2532
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2533
    def OnRemoveConfigurationMenu(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2534
        selected = self.ProjectTree.GetSelection()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2535
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_CONFIGURATION: 
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2536
            name = self.ProjectTree.GetItemText(selected)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2537
            self.Controler.ProjectRemoveConfiguration(name)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2538
            tagname = self.Controler.ComputeConfigurationName(name)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2539
            idx = self.IsOpened(tagname)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2540
            if idx is not None:
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2541
                self.TabsOpened.DeletePage(idx)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2542
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2543
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2544
    def OnRemoveResourceMenu(self, event):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2545
        selected = self.ProjectTree.GetSelection()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2546
        item_infos = self.ProjectTree.GetPyData(selected)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2547
        if item_infos["type"] == ITEM_RESOURCE:
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2548
            resource = self.ProjectTree.GetItemText(selected)
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2549
            config_name = item_infos["tagname"].split("::")[1]
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2550
            self.Controler.ProjectRemoveConfigurationResource(config_name, resource)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2551
            tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2552
            idx = self.IsOpened(tagname)
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  2553
            if idx is not None:
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2554
                self.TabsOpened.DeletePage(idx)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2555
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
190
f37abf3ee358 added to helpmenu : about + plcopen + plcopeneditor
greg
parents: 186
diff changeset
  2556
    
f37abf3ee358 added to helpmenu : about + plcopen + plcopeneditor
greg
parents: 186
diff changeset
  2557
    def OnPLCOpenEditorMenu(self, event):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2558
        wx.MessageBox(_("No documentation available.\nComing soon."))
190
f37abf3ee358 added to helpmenu : about + plcopen + plcopeneditor
greg
parents: 186
diff changeset
  2559
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2560
    def OnPLCOpenMenu(self, event):
190
f37abf3ee358 added to helpmenu : about + plcopen + plcopeneditor
greg
parents: 186
diff changeset
  2561
        open_pdf(os.path.join(CWD, "plcopen", "TC6_XML_V101.pdf"))
f37abf3ee358 added to helpmenu : about + plcopen + plcopeneditor
greg
parents: 186
diff changeset
  2562
    
f37abf3ee358 added to helpmenu : about + plcopen + plcopeneditor
greg
parents: 186
diff changeset
  2563
    def OnAboutMenu(self, event):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2564
        OpenHtmlFrame(self,_("About PLCOpenEditor"), os.path.join(CWD, "doc","about.html"), wx.Size(350, 350))
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 223
diff changeset
  2565
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 223
diff changeset
  2566
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 223
diff changeset
  2567
#-------------------------------------------------------------------------------
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2568
#                        Highlights showing functions
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2569
#-------------------------------------------------------------------------------
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2570
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2571
    def ShowHighlight(self, infos, start, end, highlight_type):
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2572
        self.SelectProjectTreeItem(infos[0])
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 223
diff changeset
  2573
        if infos[1] == "name":
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2574
            self.Highlights[infos[0]] = highlight_type
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2575
            self.RefreshProjectTree()
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2576
            self.ProjectTree.Unselect()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 223
diff changeset
  2577
        else:
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2578
            self.EditProjectElement(self.Controler.GetElementType(infos[0]), infos[0])
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  2579
            selected = self.TabsOpened.GetSelection()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  2580
            if selected != -1:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  2581
                viewer = self.TabsOpened.GetPage(selected)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  2582
                viewer.AddHighlight(infos[1:], start, end, highlight_type)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2583
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2584
    def ShowError(self, infos, start, end):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2585
        self.ShowHighlight(infos, start, end, ERROR_HIGHLIGHT)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2586
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2587
    def ShowSearchResult(self, infos, start, end):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2588
        self.ShowHighlight(infos, start, end, SEARCH_RESULT_HIGHLIGHT)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2589
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2590
    def ClearHighlights(self, highlight_type=None):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2591
        if highlight_type is None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2592
            self.Highlights = {}
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2593
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2594
            self.Highlights = dict([(name, highlight) for name, highlight in self.Highlights.iteritems() if highlight != highlight_type])
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2595
        self.RefreshProjectTree()
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2596
        for i in xrange(self.TabsOpened.GetPageCount()):
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  2597
            viewer = self.TabsOpened.GetPage(i)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2598
            viewer.ClearHighlights(highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2599
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2600
    def ClearErrors(self):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2601
        self.ClearHighlights(ERROR_HIGHLIGHT)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2602
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2603
    def ClearSearchResults(self):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 563
diff changeset
  2604
        self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT)
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  2605
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2606
#-------------------------------------------------------------------------------
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2607
#                            PLCOpenEditor Main Class
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2608
#-------------------------------------------------------------------------------
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2609
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2610
class PLCOpenEditor(IDEFrame):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2611
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2612
    # Compatibility function for wx versions < 2.6
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2613
    if wx.VERSION < (2, 6, 0):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2614
        def Bind(self, event, function, id = None):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2615
            if id is not None:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2616
                event(self, id, function)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2617
            else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2618
                event(self, function)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2619
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2620
    def _init_coll_FileMenu_Items(self, parent):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2621
        AppendMenu(parent, help='', id=wx.ID_NEW,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2622
              kind=wx.ITEM_NORMAL, text=_(u'New\tCTRL+N'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2623
        AppendMenu(parent, help='', id=wx.ID_OPEN,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2624
              kind=wx.ITEM_NORMAL, text=_(u'Open\tCTRL+O'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2625
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2626
              kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2627
        AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
656
ff38b7250b64 Added a few shortcuts in menus
Edouard Tisserant
parents: 654
diff changeset
  2628
              kind=wx.ITEM_NORMAL, text=_(u'Close Project\tCTRL+SHIFT+W'))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2629
        parent.AppendSeparator()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2630
        AppendMenu(parent, help='', id=wx.ID_SAVE,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2631
              kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2632
        AppendMenu(parent, help='', id=wx.ID_SAVEAS,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2633
              kind=wx.ITEM_NORMAL, text=_(u'Save As...\tCTRL+SHIFT+S'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2634
        AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATE,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2635
              kind=wx.ITEM_NORMAL, text=_(u'Generate Program\tCTRL+G'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2636
        parent.AppendSeparator()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2637
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
656
ff38b7250b64 Added a few shortcuts in menus
Edouard Tisserant
parents: 654
diff changeset
  2638
              kind=wx.ITEM_NORMAL, text=_(u'Page Setup\tCTRL+ALT+P'))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2639
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
656
ff38b7250b64 Added a few shortcuts in menus
Edouard Tisserant
parents: 654
diff changeset
  2640
              kind=wx.ITEM_NORMAL, text=_(u'Preview\tCTRL+SHIFT+P'))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2641
        AppendMenu(parent, help='', id=wx.ID_PRINT,
656
ff38b7250b64 Added a few shortcuts in menus
Edouard Tisserant
parents: 654
diff changeset
  2642
              kind=wx.ITEM_NORMAL, text=_(u'Print\tCTRL+P'))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2643
        parent.AppendSeparator()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2644
        AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
656
ff38b7250b64 Added a few shortcuts in menus
Edouard Tisserant
parents: 654
diff changeset
  2645
              kind=wx.ITEM_NORMAL, text=_(u'&Properties'))
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2646
        parent.AppendSeparator()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2647
        AppendMenu(parent, help='', id=wx.ID_EXIT,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2648
              kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2649
        
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2650
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2651
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2652
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2653
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2654
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2655
        self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2656
        self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2657
              id=ID_PLCOPENEDITORFILEMENUGENERATE)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2658
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2659
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2660
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2661
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2662
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2663
        
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2664
        self.AddToMenuToolBar([(wx.ID_NEW, "new.png", _(u'New'), None),
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2665
                               (wx.ID_OPEN, "open.png", _(u'Open'), None),
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2666
                               (wx.ID_SAVE, "save.png", _(u'Save'), None),
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2667
                               (wx.ID_SAVEAS, "saveas.png", _(u'Save As...'), None),
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  2668
                               (wx.ID_PRINT, "print.png", _(u'Print'), None)])
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2669
            
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2670
    def _init_coll_HelpMenu_Items(self, parent):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2671
        AppendMenu(parent, help='', id=wx.ID_HELP, 
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2672
            kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor\tF1'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2673
        #AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2674
        #      kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2')
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2675
        #AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2676
        #      kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3')
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2677
        AppendMenu(parent, help='', id=wx.ID_ABOUT,
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2678
            kind=wx.ITEM_NORMAL, text=_(u'About'))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2679
        self.Bind(wx.EVT_MENU, self.OnPLCOpenEditorMenu, id=wx.ID_HELP)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2680
        #self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, id=wx.ID_HELP_CONTENTS)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2681
        self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2682
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2683
    ## Constructor of the PLCOpenEditor class.
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2684
    #  @param parent The parent window.
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2685
    #  @param controler The controler been used by PLCOpenEditor (default: None).
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2686
    #  @param fileOpen The filepath to open if no controler defined (default: None).
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2687
    #  @param debug The filepath to open if no controler defined (default: False).
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2688
    def __init__(self, parent, fileOpen = None):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2689
        IDEFrame.__init__(self, parent)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2690
        
500
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2691
        result = None
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2692
        
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2693
        # Open the filepath if defined
438
eebcf66f2d5a Bug when opening unknown file at starting fixed
laurent
parents: 434
diff changeset
  2694
        if fileOpen is not None and os.path.isfile(fileOpen):
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2695
            # Create a new controller
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2696
            controler = PLCControler()
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2697
            result = controler.OpenXMLFile(fileOpen)
500
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2698
            if result is None:
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2699
                self.Controler = controler
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2700
            	self.LibraryPanel.SetControler(controler)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2701
                self.ProjectTree.Enable(True)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2702
                self.PouInstanceVariablesPanel.SetController(controler)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2703
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2704
        
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2705
        # Define PLCOpenEditor icon
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2706
        self.SetIcon(wx.Icon(os.path.join(CWD,"Images", "poe.ico"),wx.BITMAP_TYPE_ICO))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2707
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2708
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2709
        
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2710
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
500
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2711
        
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2712
        if result is not None:
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2713
            self.ShowErrorMessage(result)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2714
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2715
    def OnCloseFrame(self, event):
450
b31d1dfb407b Fix messages on DialogBox title while asking for project saving when closing project
laurent
parents: 447
diff changeset
  2716
        if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")):
685
ecd2226716d8 Removed references to old wx without AUI
Edouard Tisserant
parents: 684
diff changeset
  2717
            self.AUIManager.UnInit()
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
  2718
            
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  2719
            self.SaveLastState()
535
08f32198e932 Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 534
diff changeset
  2720
            
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2721
            event.Skip()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2722
        else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2723
            event.Veto()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2724
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2725
    def RefreshTitle(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2726
        name = _("PLCOpenEditor")
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2727
        if self.Controler is not None:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2728
            self.SetTitle("%s - %s"%(name, self.Controler.GetFilename()))
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2729
        else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2730
            self.SetTitle(name)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2731
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2732
#-------------------------------------------------------------------------------
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2733
#                            File Menu Functions
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2734
#-------------------------------------------------------------------------------
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2735
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2736
    def RefreshFileMenu(self):
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2737
        MenuToolBar = self.Panes["MenuToolBar"]
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2738
        if self.Controler is not None:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2739
            selected = self.TabsOpened.GetSelection()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2740
            if selected >= 0:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2741
                graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2742
            else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2743
                graphic_viewer = False
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2744
            if self.TabsOpened.GetPageCount() > 0:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2745
                self.FileMenu.Enable(wx.ID_CLOSE, True)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2746
                if graphic_viewer:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2747
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2748
                    self.FileMenu.Enable(wx.ID_PRINT, True)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2749
                    MenuToolBar.EnableTool(wx.ID_PRINT, True)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2750
                else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2751
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2752
                    self.FileMenu.Enable(wx.ID_PRINT, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2753
                    MenuToolBar.EnableTool(wx.ID_PRINT, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2754
            else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2755
                self.FileMenu.Enable(wx.ID_CLOSE, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2756
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2757
                self.FileMenu.Enable(wx.ID_PRINT, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2758
                MenuToolBar.EnableTool(wx.ID_PRINT, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2759
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2760
            project_modified = not self.Controler.ProjectIsSaved()
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2761
            self.FileMenu.Enable(wx.ID_SAVE, project_modified)
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2762
            MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2763
            self.FileMenu.Enable(wx.ID_PROPERTIES, True)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2764
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2765
            self.FileMenu.Enable(wx.ID_SAVEAS, True)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2766
            MenuToolBar.EnableTool(wx.ID_SAVEAS, True)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2767
            self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2768
        else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2769
            self.FileMenu.Enable(wx.ID_CLOSE, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2770
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2771
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2772
            self.FileMenu.Enable(wx.ID_PRINT, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2773
            MenuToolBar.EnableTool(wx.ID_PRINT, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2774
            self.FileMenu.Enable(wx.ID_SAVE, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2775
            MenuToolBar.EnableTool(wx.ID_SAVE, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2776
            self.FileMenu.Enable(wx.ID_PROPERTIES, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2777
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2778
            self.FileMenu.Enable(wx.ID_SAVEAS, False)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2779
            MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2780
            self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2781
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2782
    def OnNewProjectMenu(self, event):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2783
        if self.Controler is not None and not self.CheckSaveBeforeClosing():
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2784
            return
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2785
        dialog = ProjectDialog(self)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2786
        if dialog.ShowModal() == wx.ID_OK:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2787
            properties = dialog.GetValues()
411
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
  2788
            self.ResetView()
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2789
            self.Controler = PLCControler()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2790
            self.Controler.CreateNewProject(properties)
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 675
diff changeset
  2791
            self.LibraryPanel.SetControler(self.Controler)
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2792
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, 
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2793
                          LIBRARYTREE)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2794
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2795
    def OnOpenProjectMenu(self, event):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2796
        if self.Controler is not None and not self.CheckSaveBeforeClosing():
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2797
            return
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2798
        filepath = ""
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2799
        if self.Controler is not None:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2800
            filepath = self.Controler.GetFilePath()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2801
        if filepath != "":
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2802
            directory = os.path.dirname(filepath)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2803
        else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2804
            directory = os.getcwd()
500
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2805
        
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2806
        result = None
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2807
        
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2808
        dialog = wx.FileDialog(self, _("Choose a file"), directory, "",  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2809
        if dialog.ShowModal() == wx.ID_OK:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2810
            filepath = dialog.GetPath()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2811
            if os.path.isfile(filepath):
411
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
  2812
                self.ResetView()
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2813
                controler = PLCControler()
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2814
                result = controler.OpenXMLFile(filepath)
500
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2815
                if result is None:
687
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2816
                    self.Controler = controler
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2817
                    self.LibraryPanel.SetControler(controler)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2818
                    self.ProjectTree.Enable(True)
629680fb0582 refactoring
laurent
parents: 685
diff changeset
  2819
                    self.PouInstanceVariablesPanel.SetController(controler)
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
  2820
                    self.LoadProjectLayout()
684
f10449b18dbe refactoring
laurent
parents: 683
diff changeset
  2821
                    self._Refresh(PROJECTTREE, LIBRARYTREE)
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2822
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2823
        dialog.Destroy()
500
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2824
        
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2825
        if result is not None:
b3499ff87178 Adding message dialog for PLCOpen XML syntax errors.
laurent
parents: 498
diff changeset
  2826
            self.ShowErrorMessage(result)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2827
    
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2828
    def OnCloseProjectMenu(self, event):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2829
        if not self.CheckSaveBeforeClosing():
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2830
            return
691
361389f3ad2b Fixing semantics
laurent
parents: 690
diff changeset
  2831
        self.SaveProjectLayout()
411
9ab97d517ae8 Many bugs on PLCOpenEditor integration fixed
laurent
parents: 407
diff changeset
  2832
        self.ResetView()
660
30c0371ac086 Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
laurent
parents: 656
diff changeset
  2833
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2834
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2835
    def OnSaveProjectMenu(self, event):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2836
        self.SaveProject()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2837
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2838
    def OnSaveProjectAsMenu(self, event):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2839
        self.SaveProjectAs()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2840
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2841
    def OnGenerateProgramMenu(self, event):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2842
        dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), self.Controler.GetProgramFilePath(),  _("ST files (*.st)|*.st|All files|*.*"), wx.SAVE|wx.CHANGE_DIR)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2843
        if dialog.ShowModal() == wx.ID_OK:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2844
            filepath = dialog.GetPath()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2845
            message_text = ""
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2846
            header, icon = _("Done"), wx.ICON_INFORMATION
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2847
            if os.path.isdir(os.path.dirname(filepath)):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2848
                program, errors, warnings = self.Controler.GenerateProgram(filepath)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2849
                message_text += "".join([_("warning: %s\n") for warning in warnings])
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2850
                if len(errors) > 0:
540
82fa901a2160 Fix bug when displaying errors when generating textual program in standalone mode
laurent
parents: 538
diff changeset
  2851
                    message_text += "".join([_("error: %s\n") for error in errors])
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2852
                    message_text += _("Can't generate program to file %s!")%filepath
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2853
                    header, icon = _("Error"), wx.ICON_ERROR
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2854
                else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2855
                    message_text += _("Program was successfully generated!")
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2856
            else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2857
                message_text += _("\"%s\" is not a valid folder!")%os.path.dirname(filepath)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2858
                header, icon = _("Error"), wx.ICON_ERROR
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2859
            message = wx.MessageDialog(self, message_text, header, wx.OK|icon)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2860
            message.ShowModal()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2861
            message.Destroy()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2862
        dialog.Destroy()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2863
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2864
    def SaveProject(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2865
        result = self.Controler.SaveXMLFile()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2866
        if not result:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2867
            self.SaveProjectAs()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2868
        else:
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  2869
            self._Refresh(TITLE, FILEMENU, PAGETITLES)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  2870
        
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2871
    def SaveProjectAs(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2872
        filepath = self.Controler.GetFilePath()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2873
        if filepath != "":
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2874
            directory, filename = os.path.split(filepath)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2875
        else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2876
            directory, filename = os.getcwd(), "%(projectName)s.xml"%self.Controler.GetProjectProperties()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2877
        dialog = wx.FileDialog(self, _("Choose a file"), directory, filename,  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.SAVE|wx.OVERWRITE_PROMPT)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2878
        if dialog.ShowModal() == wx.ID_OK:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2879
            filepath = dialog.GetPath()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2880
            if os.path.isdir(os.path.dirname(filepath)):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2881
                result = self.Controler.SaveXMLFile(filepath)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2882
                if not result:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2883
                    self.ShowErrorMessage(_("Can't save project to file %s!")%filepath)
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2884
            else:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2885
                self.ShowErrorMessage(_("\"%s\" is not a valid folder!")%os.path.dirname(filepath))
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
  2886
            self._Refresh(TITLE, FILEMENU, PAGETITLES)
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  2887
        dialog.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2888
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2889
#-------------------------------------------------------------------------------
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2890
#                          Edit Step Name Dialog
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2891
#-------------------------------------------------------------------------------
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2892
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2893
class DataTypeDialog(wx.TextEntryDialog):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2894
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2895
    if wx.VERSION < (2, 6, 0):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2896
        def Bind(self, event, function, id = None):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2897
            if id is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2898
                event(self, id, function)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2899
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2900
                event(self, function)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2901
    
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2902
    def __init__(self, parent, message, caption = _("Please enter text"), defaultValue = "", 
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2903
                       style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2904
        wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2905
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2906
        self.DataTypeNames = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2907
        if wx.VERSION >= (2, 8, 0):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2908
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2909
        elif wx.VERSION >= (2, 6, 0):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2910
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2911
        else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2912
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2913
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2914
    def OnOK(self, event):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2915
        datatype_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2916
        if datatype_name == "":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2917
            message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2918
            message.ShowModal()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2919
            message.Destroy()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2920
        elif not TestIdentifier(datatype_name):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2921
            message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%datatype_name, _("Error"), wx.OK|wx.ICON_ERROR)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2922
            message.ShowModal()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2923
            message.Destroy()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2924
        elif datatype_name.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2925
            message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%datatype_name, _("Error"), wx.OK|wx.ICON_ERROR)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2926
            message.ShowModal()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2927
            message.Destroy()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2928
        elif datatype_name.upper() in self.DataTypeNames:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2929
            message = wx.MessageDialog(self, _("\"%s\" data type already exists!")%datatype_name, _("Error"), wx.OK|wx.ICON_ERROR)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2930
            message.ShowModal()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2931
            message.Destroy()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2932
        else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2933
            self.EndModal(wx.ID_OK)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2934
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2935
    def SetDataTypeNames(self, datatype_names):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2936
        self.DataTypeNames = [datatype_name.upper() for datatype_name in datatype_names]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2937
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2938
    def GetValue(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2939
        return self.GetSizer().GetItem(1).GetWindow().GetValue()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2940
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 122
diff changeset
  2941
#-------------------------------------------------------------------------------
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2942
#                            Create Pou Dialog
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2943
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2944
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2945
[ID_POUDIALOG, ID_POUDIALOGPOUNAME, 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2946
 ID_POUDIALOGPOUTYPE, ID_POUDIALOGLANGUAGE, ID_POUDIALOGSTATICTEXT1,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2947
 ID_POUDIALOGSTATICTEXT2, ID_POUDIALOGSTATICTEXT3, 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2948
] = [wx.NewId() for _init_ctrls in range(7)]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2949
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2950
def GetPouTypes():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2951
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2952
    return [_("function"), _("functionBlock"), _("program")]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2953
POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()])
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2954
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2955
def GetPouLanguages():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2956
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2957
    return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2958
POU_LANGUAGES_DICT = dict([(_(language), language) for language in GetPouLanguages()])
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2959
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2960
class PouDialog(wx.Dialog):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  2961
    if wx.VERSION < (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  2962
        def Bind(self, event, function, id = None):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  2963
            if id is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  2964
                event(self, id, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  2965
            else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  2966
                event(self, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  2967
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2968
    def _init_coll_flexGridSizer1_Items(self, parent):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2969
        parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2970
        parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2971
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2972
    def _init_coll_flexGridSizer1_Growables(self, parent):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2973
        parent.AddGrowableCol(0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2974
        parent.AddGrowableRow(0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2975
    
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2976
    def _init_coll_MainSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2977
        parent.AddWindow(self.staticText1, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2978
        parent.AddWindow(self.PouName, 0, border=0, flag=wx.GROW)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2979
        parent.AddWindow(self.staticText2, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2980
        parent.AddWindow(self.PouType, 0, border=0, flag=wx.GROW)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2981
        parent.AddWindow(self.staticText3, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2982
        parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2983
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2984
    def _init_coll_MainSizer_Growables(self, parent):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2985
        parent.AddGrowableCol(1)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2986
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2987
    def _init_sizers(self):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2988
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  2989
        self.MainSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2990
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2991
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2992
        self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2993
        self._init_coll_MainSizer_Items(self.MainSizer)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2994
        self._init_coll_MainSizer_Growables(self.MainSizer)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2995
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2996
        self.SetSizer(self.flexGridSizer1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2997
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2998
    def _init_ctrls(self, prnt):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  2999
        wx.Dialog.__init__(self, id=ID_POUDIALOG,
534
d506a353b3d3 Fix dialogs positions to stay on the same screen than parent frame
laurent
parents: 518
diff changeset
  3000
              name='PouDialog', parent=prnt,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3001
              size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3002
              title=_('Create a new POU'))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3003
        self.SetClientSize(wx.Size(300, 200))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3004
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3005
        self.staticText1 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT1,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3006
              label=_('POU Name:'), name='staticText1', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3007
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3008
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3009
        self.PouName = wx.TextCtrl(id=ID_POUDIALOGPOUNAME,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3010
              name='POUName', parent=self, pos=wx.Point(0, 0), 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3011
              size=wx.Size(0, 24), style=0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3012
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3013
        self.staticText2 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT2,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3014
              label=_('POU Type:'), name='staticText2', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3015
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3016
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 301
diff changeset
  3017
        self.PouType = wx.ComboBox(id=ID_POUDIALOGPOUTYPE,
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3018
              name='POUType', parent=self, pos=wx.Point(0, 0),
346
66fce4b3f7e2 Fix ComboBox height for display in ubuntu
lbessard
parents: 341
diff changeset
  3019
              size=wx.Size(0, 28), style=wx.CB_READONLY)
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 301
diff changeset
  3020
        self.Bind(wx.EVT_COMBOBOX, self.OnTypeChanged, id=ID_POUDIALOGPOUTYPE)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3021
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3022
        self.staticText3 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT3,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3023
              label=_('Language:'), name='staticText3', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3024
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3025
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 301
diff changeset
  3026
        self.Language = wx.ComboBox(id=ID_POUDIALOGLANGUAGE,
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3027
              name='Language', parent=self, pos=wx.Point(0, 0),
346
66fce4b3f7e2 Fix ComboBox height for display in ubuntu
lbessard
parents: 341
diff changeset
  3028
              size=wx.Size(0, 28), style=wx.CB_READONLY)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3029
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3030
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3031
        self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3032
            
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3033
        self._init_sizers()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3034
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  3035
    def __init__(self, parent, pou_type = None):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3036
        self._init_ctrls(parent)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3037
        
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3038
        for option in GetPouTypes():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3039
            self.PouType.Append(_(option))
163
e4949f54c5d6 Changing ProjectTree contextual menu and EditMenu
lbessard
parents: 159
diff changeset
  3040
        if pou_type is not None:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3041
            self.PouType.SetStringSelection(_(pou_type))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3042
        self.RefreshLanguage()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3043
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  3044
        self.PouNames = []
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3045
        self.PouElementNames = []
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
  3046
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3047
    def OnOK(self, event):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3048
        error = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3049
        pou_name = self.PouName.GetValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3050
        if pou_name == "":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3051
            error.append(_("POU Name"))
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3052
        if self.PouType.GetSelection() == -1:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3053
            error.append(_("POU Type"))
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3054
        if self.Language.GetSelection() == -1:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3055
            error.append(_("Language"))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3056
        if len(error) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3057
            text = ""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3058
            for i, item in enumerate(error):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3059
                if i == 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3060
                    text += item
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3061
                elif i == len(error) - 1:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3062
                    text += _(" and %s")%item
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3063
                else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3064
                    text += _(", %s")%item 
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3065
            message = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3066
            message.ShowModal()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3067
            message.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3068
        elif not TestIdentifier(pou_name):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3069
            message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%pou_name, _("Error"), wx.OK|wx.ICON_ERROR)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3070
            message.ShowModal()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3071
            message.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3072
        elif pou_name.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3073
            message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%pou_name, _("Error"), wx.OK|wx.ICON_ERROR)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3074
            message.ShowModal()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3075
            message.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3076
        elif pou_name.upper() in self.PouNames:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3077
            message = wx.MessageDialog(self, _("\"%s\" pou already exists!")%pou_name, _("Error"), wx.OK|wx.ICON_ERROR)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3078
            message.ShowModal()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3079
            message.Destroy()
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3080
        elif pou_name.upper() in self.PouElementNames:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3081
            message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%pou_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3082
            result = message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3083
            message.Destroy()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3084
            if result == wx.ID_YES:
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3085
                self.EndModal(wx.ID_OK)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3086
        else:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3087
            self.EndModal(wx.ID_OK)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3088
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3089
    def RefreshLanguage(self):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3090
        selection = POU_LANGUAGES_DICT.get(self.Language.GetStringSelection(), "")
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3091
        self.Language.Clear()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3092
        for language in GetPouLanguages():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3093
            if language != "SFC" or POU_TYPES_DICT[self.PouType.GetStringSelection()] != "function":
677
8f1f6022b3d3 Fix bug in create POU dialog
laurent
parents: 676
diff changeset
  3094
                self.Language.Append(_(language))
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3095
        if self.Language.FindString(_(selection)) != wx.NOT_FOUND:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3096
            self.Language.SetStringSelection(_(selection))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3097
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3098
    def OnTypeChanged(self, event):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3099
        self.RefreshLanguage()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3100
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3101
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3102
    def SetPouNames(self, pou_names):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3103
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3104
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3105
    def SetPouElementNames(self, element_names):
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3106
        self.PouElementNames = [element_name.upper() for element_name in element_names]
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3107
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3108
    def SetValues(self, values):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3109
        for item, value in values.items():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3110
            if item == "pouName":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3111
                self.PouName.SetValue(value)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3112
            elif item == "pouType":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3113
                self.PouType.SetStringSelection(_(value))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3114
            elif item == "language":
677
8f1f6022b3d3 Fix bug in create POU dialog
laurent
parents: 676
diff changeset
  3115
                self.Language.SetStringSelection(_(value))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3116
                
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3117
    def GetValues(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3118
        values = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3119
        values["pouName"] = self.PouName.GetValue()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3120
        values["pouType"] = POU_TYPES_DICT[self.PouType.GetStringSelection()]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3121
        values["language"] = POU_LANGUAGES_DICT[self.Language.GetStringSelection()]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3122
        return values
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3123
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3124
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3125
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3126
#                          Create Pou Transition Dialog
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3127
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3128
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3129
[ID_POUTRANSITIONDIALOG, ID_POUTRANSITIONDIALOGTRANSITIONNAME, 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3130
 ID_POUTRANSITIONDIALOGLANGUAGE, ID_POUTRANSITIONDIALOGSTATICTEXT1, 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3131
 ID_POUTRANSITIONDIALOGSTATICTEXT2,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3132
] = [wx.NewId() for _init_ctrls in range(5)]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3133
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3134
def GetTransitionLanguages():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3135
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3136
    return [_("IL"), _("ST"), _("LD"), _("FBD")]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3137
TRANSITION_LANGUAGES_DICT = dict([(_(language), language) for language in GetTransitionLanguages()])
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3138
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3139
class PouTransitionDialog(wx.Dialog):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3140
    if wx.VERSION < (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3141
        def Bind(self, event, function, id = None):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3142
            if id is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3143
                event(self, id, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3144
            else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3145
                event(self, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3146
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3147
    def _init_coll_flexGridSizer1_Items(self, parent):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3148
        parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3149
        parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3150
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3151
    def _init_coll_flexGridSizer1_Growables(self, parent):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3152
        parent.AddGrowableCol(0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3153
        parent.AddGrowableRow(0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3154
    
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3155
    def _init_coll_MainSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3156
        parent.AddWindow(self.staticText1, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3157
        parent.AddWindow(self.TransitionName, 0, border=0, flag=wx.GROW)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3158
        parent.AddWindow(self.staticText2, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3159
        parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3160
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3161
    def _init_coll_MainSizer_Growables(self, parent):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3162
        parent.AddGrowableCol(1)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3163
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3164
    def _init_sizers(self):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3165
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3166
        self.MainSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=15)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3167
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3168
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3169
        self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3170
        self._init_coll_MainSizer_Items(self.MainSizer)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3171
        self._init_coll_MainSizer_Growables(self.MainSizer)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3172
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3173
        self.SetSizer(self.flexGridSizer1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3174
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3175
    def _init_ctrls(self, prnt):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3176
        wx.Dialog.__init__(self, id=ID_POUTRANSITIONDIALOG,
534
d506a353b3d3 Fix dialogs positions to stay on the same screen than parent frame
laurent
parents: 518
diff changeset
  3177
              name='PouTransitionDialog', parent=prnt,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3178
              size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3179
              title=_('Create a new transition'))
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  3180
        self.SetClientSize(wx.Size(350, 160))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3181
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3182
        self.staticText1 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT1,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3183
              label=_('Transition Name:'), name='staticText1', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3184
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3185
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3186
        self.TransitionName = wx.TextCtrl(id=ID_POUTRANSITIONDIALOGTRANSITIONNAME,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3187
              name='TransitionName', parent=self, pos=wx.Point(0, 0),
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3188
              size=wx.Size(0, 24), style=0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3189
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3190
        self.staticText2 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT2,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3191
              label=_('Language:'), name='staticText2', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3192
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3193
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 301
diff changeset
  3194
        self.Language = wx.ComboBox(id=ID_POUTRANSITIONDIALOGLANGUAGE,
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3195
              name='Language', parent=self, pos=wx.Point(0, 0),
346
66fce4b3f7e2 Fix ComboBox height for display in ubuntu
lbessard
parents: 341
diff changeset
  3196
              size=wx.Size(0, 28), style=wx.CB_READONLY)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3197
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3198
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3199
        self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3200
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3201
        self._init_sizers()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3202
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3203
    def __init__(self, parent):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3204
        self._init_ctrls(parent)
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  3205
        
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3206
        for language in GetTransitionLanguages():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3207
            self.Language.Append(_(language))
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3208
            
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3209
        self.PouNames = []
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3210
        self.PouElementNames = []
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3211
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3212
    def OnOK(self, event):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3213
        error = []
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3214
        transition_name = self.TransitionName.GetValue()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3215
        if self.TransitionName.GetValue() == "":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3216
            error.append(_("Transition Name"))
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3217
        if self.Language.GetSelection() == -1:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3218
            error.append(_("Language"))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3219
        if len(error) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3220
            text = ""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3221
            for i, item in enumerate(error):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3222
                if i == 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3223
                    text += item
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3224
                elif i == len(error) - 1:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3225
                    text += _(" and %s")%item
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3226
                else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3227
                    text += _(", %s")%item 
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3228
            message = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3229
            message.ShowModal()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3230
            message.Destroy()
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3231
        elif not TestIdentifier(transition_name):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3232
            message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3233
            message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3234
            message.Destroy()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3235
        elif transition_name.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3236
            message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3237
            message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3238
            message.Destroy()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3239
        elif transition_name.upper() in self.PouNames:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3240
            message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3241
            message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3242
            message.Destroy()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3243
        elif transition_name.upper() in self.PouElementNames:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3244
            message = wx.MessageDialog(self, _("\"%s\" element for this pou already exists!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3245
            message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3246
            message.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3247
        else:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3248
            self.EndModal(wx.ID_OK)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3249
    
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3250
    def SetPouNames(self, pou_names):
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3251
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3252
    
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3253
    def SetPouElementNames(self, pou_names):
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3254
        self.PouElementNames = [pou_name.upper() for pou_name in pou_names]
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3255
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3256
    def SetValues(self, values):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3257
        for item, value in values.items():
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  3258
            if item == "transitionName":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3259
                self.TransitionName.SetValue(value)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3260
            elif item == "language":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3261
                self.Language.SetSelection(_(value))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3262
                
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3263
    def GetValues(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3264
        values = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3265
        values["transitionName"] = self.TransitionName.GetValue()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3266
        values["language"] = TRANSITION_LANGUAGES_DICT[self.Language.GetStringSelection()]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3267
        return values
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3268
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3269
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3270
#                          Create Pou Action Dialog
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3271
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3272
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3273
[ID_POUACTIONDIALOG, ID_POUACTIONDIALOGACTIONNAME, 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3274
 ID_POUACTIONDIALOGLANGUAGE, ID_POUACTIONDIALOGSTATICTEXT1, 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3275
 ID_POUACTIONDIALOGSTATICTEXT2, 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3276
] = [wx.NewId() for _init_ctrls in range(5)]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3277
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3278
def GetActionLanguages():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3279
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3280
    return [_("IL"), _("ST"), _("LD"), _("FBD")]
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3281
ACTION_LANGUAGES_DICT = dict([(_(language), language) for language in GetActionLanguages()])
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3282
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3283
class PouActionDialog(wx.Dialog):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3284
    if wx.VERSION < (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3285
        def Bind(self, event, function, id = None):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3286
            if id is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3287
                event(self, id, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3288
            else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3289
                event(self, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3290
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3291
    def _init_coll_flexGridSizer1_Items(self, parent):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3292
        parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3293
        parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3294
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3295
    def _init_coll_flexGridSizer1_Growables(self, parent):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3296
        parent.AddGrowableCol(0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3297
        parent.AddGrowableRow(0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3298
    
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3299
    def _init_coll_MainSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3300
        parent.AddWindow(self.staticText1, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3301
        parent.AddWindow(self.ActionName, 0, border=0, flag=wx.GROW)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3302
        parent.AddWindow(self.staticText2, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3303
        parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3304
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3305
    def _init_coll_MainSizer_Growables(self, parent):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3306
        parent.AddGrowableCol(1)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3307
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3308
    def _init_sizers(self):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3309
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3310
        self.MainSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=15)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3311
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3312
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3313
        self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3314
        self._init_coll_MainSizer_Items(self.MainSizer)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3315
        self._init_coll_MainSizer_Growables(self.MainSizer)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3316
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3317
        self.SetSizer(self.flexGridSizer1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3318
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3319
    def _init_ctrls(self, prnt):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3320
        wx.Dialog.__init__(self, id=ID_POUACTIONDIALOG,
534
d506a353b3d3 Fix dialogs positions to stay on the same screen than parent frame
laurent
parents: 518
diff changeset
  3321
              name='PouActionDialog', parent=prnt,
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3322
              size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3323
              title=_('Create a new action'))
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  3324
        self.SetClientSize(wx.Size(320, 160))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3325
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3326
        self.staticText1 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT1,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3327
              label=_('Action Name:'), name='staticText1', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3328
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3329
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3330
        self.ActionName = wx.TextCtrl(id=ID_POUACTIONDIALOGACTIONNAME,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3331
              name='ActionName', parent=self, pos=wx.Point(0, 0),
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3332
              size=wx.Size(0, 24), style=0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3333
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3334
        self.staticText2 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT2,
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3335
              label=_('Language:'), name='staticText2', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3336
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3337
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 301
diff changeset
  3338
        self.Language = wx.ComboBox(id=ID_POUACTIONDIALOGLANGUAGE,
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3339
              name='Language', parent=self, pos=wx.Point(0, 0),
346
66fce4b3f7e2 Fix ComboBox height for display in ubuntu
lbessard
parents: 341
diff changeset
  3340
              size=wx.Size(0, 28), style=wx.CB_READONLY)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3341
        
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3342
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3343
        self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3344
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3345
        self._init_sizers()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3346
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3347
    def __init__(self, parent):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3348
        self._init_ctrls(parent)
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  3349
        
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3350
        for option in GetActionLanguages():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3351
            self.Language.Append(_(option))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3352
        
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3353
        self.PouNames = []
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3354
        self.PouElementNames = []
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3355
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3356
    def OnOK(self, event):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3357
        error = []
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3358
        action_name = self.ActionName.GetValue()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3359
        if action_name == "":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3360
            error.append(_("Action Name"))
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3361
        if self.Language.GetSelection() == -1:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3362
            error.append(_("Language"))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3363
        if len(error) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3364
            text = ""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3365
            for i, item in enumerate(error):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3366
                if i == 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3367
                    text += item
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3368
                elif i == len(error) - 1:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3369
                    text += _(" and %s")%item
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3370
                else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3371
                    text += _(", %s")%item 
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3372
            message = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3373
            message.ShowModal()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3374
            message.Destroy()
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3375
        elif not TestIdentifier(action_name):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3376
            message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3377
            message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3378
            message.Destroy()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3379
        elif action_name.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3380
            message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3381
            message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3382
            message.Destroy()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3383
        elif action_name.upper() in self.PouNames:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3384
            message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3385
            message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3386
            message.Destroy()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3387
        elif action_name.upper() in self.PouElementNames:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3388
            message = wx.MessageDialog(self, _("\"%s\" element for this pou already exists!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3389
            message.ShowModal()
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3390
            message.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3391
        else:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  3392
            self.EndModal(wx.ID_OK)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3393
    
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3394
    def SetPouNames(self, pou_names):
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3395
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3396
        
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3397
    def SetPouElementNames(self, element_names):
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3398
        self.PouElementNames = [element_name.upper() for element_name in element_names]
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
  3399
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3400
    def SetValues(self, values):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3401
        for item, value in values.items():
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  3402
            if item == "actionName":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3403
                self.ActionName.SetValue(value)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3404
            elif item == "language":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3405
                self.Language.SetStringSelection(_(value))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3406
                
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3407
    def GetValues(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3408
        values = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3409
        values["actionName"] = self.ActionName.GetValue()
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3410
        values["language"] = ACTION_LANGUAGES_DICT[self.Language.GetStringSelection()]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3411
        return values
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3412
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3413
#-------------------------------------------------------------------------------
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3414
#                          Configuration Name Dialog
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3415
#-------------------------------------------------------------------------------
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3416
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3417
class ConfigurationNameDialog(wx.TextEntryDialog):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3418
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3419
    if wx.VERSION < (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3420
        def Bind(self, event, function, id = None):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3421
            if id is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3422
                event(self, id, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3423
            else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3424
                event(self, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3425
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3426
    def __init__(self, parent, message, caption = _("Please enter configuration name"), defaultValue = "", 
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3427
                       style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3428
        wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3429
        
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3430
        self.PouNames = []
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3431
        self.PouElementNames = []
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3432
        
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3433
        if wx.VERSION >= (2, 8, 0):
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3434
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3435
        elif wx.VERSION >= (2, 6, 0):
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3436
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3437
        else:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3438
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3439
    
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3440
    def OnOK(self, event):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3441
        config_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3442
        if config_name == "":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3443
            message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3444
            message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3445
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3446
        elif not TestIdentifier(config_name):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3447
            message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%config_name, _("Error"), wx.OK|wx.ICON_ERROR)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3448
            message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3449
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3450
        elif config_name.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3451
            message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%config_name, _("Error"), wx.OK|wx.ICON_ERROR)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3452
            message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3453
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3454
        elif config_name.upper() in self.PouNames:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3455
            message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%config_name, _("Error"), wx.OK|wx.ICON_ERROR)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3456
            message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3457
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3458
        elif config_name.upper() in self.PouElementNames:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3459
            message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%config_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3460
            result = message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3461
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3462
            if result == wx.ID_YES:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3463
                self.EndModal(wx.ID_OK)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3464
        else:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3465
            self.EndModal(wx.ID_OK)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3466
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3467
    def SetPouNames(self, pou_names):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3468
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3469
    
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3470
    def SetPouElementNames(self, pou_names):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3471
        self.PouElementNames = [pou_name.upper() for pou_name in pou_names]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3472
    
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3473
    def GetValue(self):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3474
        return self.GetSizer().GetItem(1).GetWindow().GetValue()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3475
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3476
#-------------------------------------------------------------------------------
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3477
#                          Resource Name Dialog
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3478
#-------------------------------------------------------------------------------
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3479
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3480
class ResourceNameDialog(wx.TextEntryDialog):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3481
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3482
    if wx.VERSION < (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3483
        def Bind(self, event, function, id = None):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3484
            if id is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3485
                event(self, id, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3486
            else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3487
                event(self, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 108
diff changeset
  3488
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3489
    def __init__(self, parent, message, caption = _("Please enter resource name"), defaultValue = "", 
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3490
                       style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3491
        wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3492
        
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3493
        self.PouNames = []
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3494
        self.PouElementNames = []
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3495
        
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3496
        if wx.VERSION >= (2, 8, 0):
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3497
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3498
        elif wx.VERSION >= (2, 6, 0):
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3499
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3500
        else:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3501
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 138
diff changeset
  3502
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3503
    def OnOK(self, event):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3504
        resource_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3505
        if resource_name == "":
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3506
            message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3507
            message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3508
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3509
        elif not TestIdentifier(resource_name):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3510
            message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%resource_name, _("Error"), wx.OK|wx.ICON_ERROR)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3511
            message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3512
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3513
        elif resource_name.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3514
            message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%resource_name, _("Error"), wx.OK|wx.ICON_ERROR)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3515
            message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3516
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3517
        elif resource_name.upper() in self.PouNames:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3518
            message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%resource_name, _("Error"), wx.OK|wx.ICON_ERROR)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3519
            message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3520
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3521
        elif resource_name.upper() in self.PouElementNames:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3522
            message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%resource_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3523
            result = message.ShowModal()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3524
            message.Destroy()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3525
            if result == wx.ID_YES:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3526
                self.EndModal(wx.ID_OK)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3527
        else:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3528
            self.EndModal(wx.ID_OK)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3529
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3530
    def SetPouNames(self, pou_names):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3531
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3532
    
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3533
    def SetPouElementNames(self, pou_names):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3534
        self.PouElementNames = [pou_name.upper() for pou_name in pou_names]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3535
    
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3536
    def GetValue(self):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3537
        return self.GetSizer().GetItem(1).GetWindow().GetValue()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3538
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  3539
#-------------------------------------------------------------------------------
390
020420ad8914 Adding comments and code improvements
laurent
parents: 384
diff changeset
  3540
#                            Debug Variables Panel
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3541
#-------------------------------------------------------------------------------
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3542
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3543
def GetDebugVariablesTableColnames():
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3544
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3545
    return [_("Variable"), _("Value")]
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3546
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3547
class VariableTableItem(DebugDataConsumer):
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3548
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3549
    def __init__(self, parent, variable, value):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3550
        DebugDataConsumer.__init__(self)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3551
        self.Parent = parent
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3552
        self.Variable = variable
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3553
        self.Value = value
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3554
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3555
    def __del__(self):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3556
        self.Parent = None
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3557
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3558
    def SetVariable(self, variable):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3559
        if self.Parent and self.Variable != variable:
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3560
            self.Variable = variable
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3561
            self.Parent.RefreshGrid()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3562
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3563
    def GetVariable(self):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3564
        return self.Variable
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3565
    
478
dc403c47af54 Adding colour to graphic element that showing forced values
laurent
parents: 474
diff changeset
  3566
    def SetForced(self, forced):
dc403c47af54 Adding colour to graphic element that showing forced values
laurent
parents: 474
diff changeset
  3567
        if self.Forced != forced:
dc403c47af54 Adding colour to graphic element that showing forced values
laurent
parents: 474
diff changeset
  3568
            self.Forced = forced
dc403c47af54 Adding colour to graphic element that showing forced values
laurent
parents: 474
diff changeset
  3569
            self.Parent.HasNewData = True
dc403c47af54 Adding colour to graphic element that showing forced values
laurent
parents: 474
diff changeset
  3570
    
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3571
    def SetValue(self, value):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3572
        if self.Value != value:
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3573
            self.Value = value
372
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 366
diff changeset
  3574
            self.Parent.HasNewData = True
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 366
diff changeset
  3575
            
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3576
    def GetValue(self):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3577
        return self.Value
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3578
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 599
diff changeset
  3579
class DebugVariableTable(CustomTable):
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 599
diff changeset
  3580
    
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3581
    def GetValue(self, row, col):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3582
        if row < self.GetNumberRows():
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3583
            return self.GetValueByName(row, self.GetColLabelValue(col, False))
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3584
        return ""
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3585
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3586
    def SetValue(self, row, col, value):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3587
        if col < len(self.colnames):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3588
            self.SetValueByName(row, self.GetColLabelValue(col, False), value)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3589
            
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3590
    def GetValueByName(self, row, colname):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3591
        if row < self.GetNumberRows():
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3592
            if colname == "Variable":
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3593
                return self.data[row].GetVariable()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3594
            elif colname == "Value":
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3595
                return self.data[row].GetValue()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3596
        return ""
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3597
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3598
    def SetValueByName(self, row, colname, value):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3599
        if row < self.GetNumberRows():
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3600
            if colname == "Variable":
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3601
                self.data[row].SetVariable(value)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3602
            elif colname == "Value":
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3603
                self.data[row].SetValue(value)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3604
    
472
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3605
    def IsForced(self, row):
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3606
        if row < self.GetNumberRows():
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3607
            return self.data[row].IsForced()
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3608
        return False
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3609
    
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3610
    def _updateColAttrs(self, grid):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3611
        """
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3612
        wx.grid.Grid -> update the column attributes to add the
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3613
        appropriate renderer given the column name.
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3614
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3615
        Otherwise default to the default renderer.
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3616
        """
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3617
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3618
        for row in range(self.GetNumberRows()):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3619
            for col in range(self.GetNumberCols()):
473
9ee851841d28 Adding value colour change in DebugVariablePanel when variable is forced
laurent
parents: 472
diff changeset
  3620
                if self.GetColLabelValue(col, False) == "Value":
9ee851841d28 Adding value colour change in DebugVariablePanel when variable is forced
laurent
parents: 472
diff changeset
  3621
                    if self.IsForced(row):
478
dc403c47af54 Adding colour to graphic element that showing forced values
laurent
parents: 474
diff changeset
  3622
                        grid.SetCellTextColour(row, col, wx.BLUE)
473
9ee851841d28 Adding value colour change in DebugVariablePanel when variable is forced
laurent
parents: 472
diff changeset
  3623
                    else:
474
a07115f79c27 Bug on changing variable value text colour fixed
laurent
parents: 473
diff changeset
  3624
                        grid.SetCellTextColour(row, col, wx.BLACK)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3625
                grid.SetReadOnly(row, col, True)
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 599
diff changeset
  3626
            self.ResizeRow(grid, row)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3627
                
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3628
    def AppendItem(self, data):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3629
        self.data.append(data)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3630
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3631
    def InsertItem(self, idx, data):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3632
        self.data.insert(idx, data)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3633
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3634
    def RemoveItem(self, idx):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3635
        self.data.pop(idx)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3636
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3637
    def MoveItem(self, idx, new_idx):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3638
        self.data.insert(new_idx, self.data.pop(idx))
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3639
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3640
    def GetItem(self, idx):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3641
        return self.data[idx]
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3642
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 599
diff changeset
  3643
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3644
class DebugVariableDropTarget(wx.TextDropTarget):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3645
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3646
    def __init__(self, parent):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3647
        wx.TextDropTarget.__init__(self)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3648
        self.ParentWindow = parent
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3649
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3650
    def OnDropText(self, x, y, data):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3651
        x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3652
        row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3653
        if row == wx.NOT_FOUND:
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3654
            row = self.ParentWindow.Table.GetNumberRows()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3655
        message = None
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3656
        try:
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3657
            values = eval(data)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3658
        except:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3659
            message = _("Invalid value \"%s\" for debug variable")%data
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3660
            values = None
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3661
        if not isinstance(values, TupleType):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3662
            message = _("Invalid value \"%s\" for debug variable")%data
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3663
            values = None
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3664
        if values is not None and values[1] == "debug":
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  3665
            self.ParentWindow.InsertValue(values[0], row)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3666
        if message is not None:
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3667
            wx.CallAfter(self.ShowMessage, message)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3668
            
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3669
    def ShowMessage(self, message):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3670
        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3671
        message.ShowModal()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3672
        message.Destroy()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3673
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3674
[ID_DEBUGVARIABLEPANEL, ID_DEBUGVARIABLEPANELVARIABLESGRID, 
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3675
 ID_DEBUGVARIABLEPANELUPBUTTON, ID_DEBUGVARIABLEPANELDOWNBUTTON, 
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3676
 ID_DEBUGVARIABLEPANELDELETEBUTTON,
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3677
] = [wx.NewId() for _init_ctrls in range(5)]
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3678
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3679
class DebugVariablePanel(wx.Panel, DebugViewer):
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3680
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3681
    if wx.VERSION < (2, 6, 0):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3682
        def Bind(self, event, function, id = None):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3683
            if id is not None:
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3684
                event(self, id, function)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3685
            else:
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3686
                event(self, function)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3687
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3688
    def _init_coll_MainSizer_Items(self, parent):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3689
        parent.AddSizer(self.ButtonPanelSizer, 0, border=5, flag=wx.ALIGN_RIGHT|wx.ALL)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3690
        parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3691
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3692
    def _init_coll_MainSizer_Growables(self, parent):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3693
        parent.AddGrowableCol(0)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3694
        parent.AddGrowableRow(1)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3695
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3696
    def _init_coll_ButtonPanelSizer_Items(self, parent):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3697
        parent.AddWindow(self.UpButton, 0, border=5, flag=wx.RIGHT)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3698
        parent.AddWindow(self.DownButton, 0, border=5, flag=wx.RIGHT)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3699
        parent.AddWindow(self.DeleteButton, 0, border=0, flag=0)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3700
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3701
    def _init_sizers(self):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3702
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3703
        self.ButtonPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3704
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3705
        self._init_coll_MainSizer_Items(self.MainSizer)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3706
        self._init_coll_MainSizer_Growables(self.MainSizer)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3707
        self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3708
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3709
        self.SetSizer(self.MainSizer)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3710
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3711
    def _init_ctrls(self, prnt):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3712
        wx.Panel.__init__(self, id=ID_DEBUGVARIABLEPANEL,
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3713
              name='DebugVariablePanel', parent=prnt, pos=wx.Point(0, 0),
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3714
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3715
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3716
        self.VariablesGrid = CustomGrid(id=ID_DEBUGVARIABLEPANELVARIABLESGRID,
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3717
              name='VariablesGrid', parent=self, pos=wx.Point(0, 0), 
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3718
              size=wx.Size(0, 150), style=wx.VSCROLL)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3719
        self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self))
497
3db9ffa8d816 Disable buttons in DebugVariablePanel when they aren't useful
laurent
parents: 490
diff changeset
  3720
        if wx.VERSION >= (2, 6, 0):
3db9ffa8d816 Disable buttons in DebugVariablePanel when they aren't useful
laurent
parents: 490
diff changeset
  3721
            self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnVariablesGridCellRightClick)
3db9ffa8d816 Disable buttons in DebugVariablePanel when they aren't useful
laurent
parents: 490
diff changeset
  3722
        else:
3db9ffa8d816 Disable buttons in DebugVariablePanel when they aren't useful
laurent
parents: 490
diff changeset
  3723
            wx.grid.EVT_GRID_CELL_RIGHT_CLICK(self.VariablesGrid, self.OnVariablesGridCellRightClick)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3724
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3725
        self.UpButton = wx.Button(id=ID_DEBUGVARIABLEPANELUPBUTTON, label='^',
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3726
              name='UpButton', parent=self, pos=wx.Point(0, 0),
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3727
              size=wx.Size(32, 32), style=0)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3728
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3729
        self.DownButton = wx.Button(id=ID_DEBUGVARIABLEPANELDOWNBUTTON, label='v',
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3730
              name='DownButton', parent=self, pos=wx.Point(0, 0),
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3731
              size=wx.Size(32, 32), style=0)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3732
        
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3733
        self.DeleteButton = wx.Button(id=ID_DEBUGVARIABLEPANELDELETEBUTTON, label=_('Delete'),
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3734
              name='DeleteButton', parent=self, pos=wx.Point(0, 0),
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  3735
              size=wx.DefaultSize, style=0)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3736
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3737
        self._init_sizers()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3738
    
415
d3d8f8f0b678 controler (PLCControler) and debug data producer (PluginsRoot) are no longer the same thing
b.taylor@willowglen.ca
parents: 412
diff changeset
  3739
    def __init__(self, parent, producer):
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3740
        self._init_ctrls(parent)
415
d3d8f8f0b678 controler (PLCControler) and debug data producer (PluginsRoot) are no longer the same thing
b.taylor@willowglen.ca
parents: 412
diff changeset
  3741
        DebugViewer.__init__(self, producer, True)
372
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 366
diff changeset
  3742
        self.HasNewData = False
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3743
        
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3744
        self.Table = DebugVariableTable(self, [], GetDebugVariablesTableColnames())
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3745
        self.VariablesGrid.SetTable(self.Table)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3746
        self.VariablesGrid.SetButtons({"Delete": self.DeleteButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3747
                                       "Up": self.UpButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3748
                                       "Down": self.DownButton})
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3749
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3750
        def _AddVariable(new_row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3751
            return self.VariablesGrid.GetGridCursorRow()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3752
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3753
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3754
        def _DeleteVariable(row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3755
            item = self.Table.GetItem(row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3756
            self.RemoveDataConsumer(item)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3757
            self.Table.RemoveItem(row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3758
            self.RefreshGrid()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3759
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3760
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3761
        def _MoveVariable(row, move):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3762
            new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1))
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3763
            if new_row != row:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3764
                self.Table.MoveItem(row, new_row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3765
                self.RefreshGrid()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3766
            return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3767
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3768
        
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3769
        self.VariablesGrid.SetRowLabelSize(0)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3770
        
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3771
        for col in range(self.Table.GetNumberCols()):
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3772
            attr = wx.grid.GridCellAttr()
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3773
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3774
            self.VariablesGrid.SetColAttr(col, attr)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3775
            self.VariablesGrid.SetColSize(col, 100)
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3776
        
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3777
        self.Table.ResetView(self.VariablesGrid)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3778
        self.VariablesGrid.RefreshButtons()
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3779
    
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3780
    def RefreshNewData(self):
372
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 366
diff changeset
  3781
        if self.HasNewData:
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 366
diff changeset
  3782
            self.HasNewData = False
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 366
diff changeset
  3783
            self.RefreshGrid()
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 366
diff changeset
  3784
        DebugViewer.RefreshNewData(self)
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3785
    
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3786
    def RefreshGrid(self):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3787
        self.Freeze()
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3788
        self.Table.ResetView(self.VariablesGrid)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3789
        self.VariablesGrid.RefreshButtons()
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3790
        self.Thaw()
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3791
    
647
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  3792
    def UnregisterObsoleteData(self):
651
34c1fa1a89a9 Fix bug variables in Debug Variable List unregistered even if they still exist in transfered program
laurent
parents: 648
diff changeset
  3793
        items = [(idx, item) for idx, item in enumerate(self.Table.GetData())]
34c1fa1a89a9 Fix bug variables in Debug Variable List unregistered even if they still exist in transfered program
laurent
parents: 648
diff changeset
  3794
        items.reverse()
34c1fa1a89a9 Fix bug variables in Debug Variable List unregistered even if they still exist in transfered program
laurent
parents: 648
diff changeset
  3795
        for idx, item in items:
688
188906a7368c Fixed bug when registering debugged variables after transferring new PLC
laurent
parents: 680
diff changeset
  3796
            iec_path = item.GetVariable().upper()
188906a7368c Fixed bug when registering debugged variables after transferring new PLC
laurent
parents: 680
diff changeset
  3797
            if self.GetDataType(iec_path) is None:
647
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  3798
                self.RemoveDataConsumer(item)
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  3799
                self.Table.RemoveItem(idx)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  3800
            else:
688
188906a7368c Fixed bug when registering debugged variables after transferring new PLC
laurent
parents: 680
diff changeset
  3801
                self.AddDataConsumer(iec_path, item)
647
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  3802
        self.Freeze()
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  3803
        self.Table.ResetView(self.VariablesGrid)
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  3804
        self.VariablesGrid.RefreshButtons()
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  3805
        self.Thaw()
2d53c653d8d2 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 638
diff changeset
  3806
    
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  3807
    def ResetGrid(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  3808
        self.DeleteDataConsumers()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  3809
        self.Table.Empty()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  3810
        self.Freeze()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  3811
        self.Table.ResetView(self.VariablesGrid)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3812
        self.VariablesGrid.RefreshButtons()
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  3813
        self.Thaw()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 403
diff changeset
  3814
    
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  3815
    def GetForceVariableMenuFunction(self, iec_path, item):
472
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3816
        iec_type = self.GetDataType(iec_path)
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3817
        def ForceVariableFunction(event):
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3818
            if iec_type is not None:
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  3819
                dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
472
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3820
                if dialog.ShowModal() == wx.ID_OK:
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3821
                    self.ForceDataValue(iec_path, dialog.GetValue())
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3822
        return ForceVariableFunction
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3823
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3824
    def GetReleaseVariableMenuFunction(self, iec_path):
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3825
        def ReleaseVariableFunction(event):
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3826
            self.ReleaseDataValue(iec_path)
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3827
        return ReleaseVariableFunction
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3828
    
497
3db9ffa8d816 Disable buttons in DebugVariablePanel when they aren't useful
laurent
parents: 490
diff changeset
  3829
    def OnVariablesGridCellRightClick(self, event):
472
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3830
        row, col = event.GetRow(), event.GetCol()
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3831
        if self.Table.GetColLabelValue(col, False) == "Value":
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3832
            iec_path = self.Table.GetValueByName(row, "Variable").upper()
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3833
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3834
            menu = wx.Menu(title='')
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3835
            new_id = wx.NewId()
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3836
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  3837
            self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.Table.GetItem(row)), id=new_id)
472
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3838
            new_id = wx.NewId()
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3839
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3840
            self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3841
            if self.Table.IsForced(row):
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3842
                menu.Enable(new_id, True)
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3843
            else:
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3844
                menu.Enable(new_id, False)
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3845
            self.PopupMenu(menu)
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 660
diff changeset
  3846
            menu.Destroy()
472
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3847
        event.Skip()
fecd4f6c01ed Adding support for forcing PLC variable in DebugVariablePanel
laurent
parents: 456
diff changeset
  3848
    
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  3849
    def InsertValue(self, iec_path, idx = None, force=False):
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  3850
        if idx is None:
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 478
diff changeset
  3851
            idx = self.Table.GetNumberRows()
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3852
        for item in self.Table.GetData():
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3853
            if iec_path == item.GetVariable():
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3854
                return
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3855
        item = VariableTableItem(self, iec_path, "")
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 359
diff changeset
  3856
        result = self.AddDataConsumer(iec_path.upper(), item)
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  3857
        if result is not None or force:
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3858
            self.Table.InsertItem(idx, item)
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3859
            self.RefreshGrid()
673
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  3860
        
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  3861
    def GetDebugVariables(self):
b686f0081e2b Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 666
diff changeset
  3862
        return [item.GetVariable() for item in self.Table.GetData()]
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 575
diff changeset
  3863
        
341
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3864
#-------------------------------------------------------------------------------
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3865
#                               Viewer Printout
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3866
#-------------------------------------------------------------------------------
88030497e29e Bug with AUINotebook double click
lbessard
parents: 337
diff changeset
  3867
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3868
UPPER_DIV = lambda x, y: (x / y) + {True : 0, False : 1}[(x % y) == 0]
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3869
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3870
class GraphicPrintout(wx.Printout):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3871
    def __init__(self, viewer, page_size, margins, preview = False):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3872
        wx.Printout.__init__(self)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3873
        self.Viewer = viewer
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3874
        self.PageSize = page_size
221
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3875
        if self.PageSize[0] == 0 or self.PageSize[1] == 0:
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3876
            self.PageSize = (1050, 1485)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3877
        self.Preview = preview
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3878
        self.Margins = margins
221
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3879
        self.FontSize = 5
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3880
        self.TextMargin = 3
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3881
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3882
        maxx, maxy = viewer.GetMaxSize()
221
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3883
        self.PageGrid = (UPPER_DIV(maxx, self.PageSize[0]), 
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3884
                         UPPER_DIV(maxy, self.PageSize[1]))
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3885
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3886
    def GetPageNumber(self):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3887
        return self.PageGrid[0] * self.PageGrid[1]
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3888
    
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3889
    def HasPage(self, page):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3890
        return page <= self.GetPageNumber()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3891
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3892
    def GetPageInfo(self):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3893
        page_number = self.GetPageNumber()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3894
        return (1, page_number, 1, page_number)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3895
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3896
    def OnBeginDocument(self, startPage, endPage):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3897
        dc = self.GetDC()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3898
        if not self.Preview and isinstance(dc, wx.PostScriptDC):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3899
            dc.SetResolution(720)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3900
        super(GraphicPrintout, self).OnBeginDocument(startPage, endPage)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3901
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3902
    def OnPrintPage(self, page):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3903
        dc = self.GetDC()
221
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3904
        dc.SetUserScale(1.0, 1.0)
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3905
        dc.SetDeviceOrigin(0, 0)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3906
        dc.printing = not self.Preview
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3907
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3908
        # Get the size of the DC in pixels
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3909
        ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3910
        ppiScreenX, ppiScreenY = self.GetPPIScreen()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3911
        pw, ph = self.GetPageSizePixels()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3912
        dw, dh = dc.GetSizeTuple()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3913
        Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3914
        Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3915
        
221
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3916
        fontsize = self.FontSize * Yscale
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3917
        text_margin = self.TextMargin * Yscale
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3918
        
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3919
        margin_left = self.Margins[0].x * Xscale
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3920
        margin_top = self.Margins[0].y * Yscale
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3921
        area_width = dw - self.Margins[1].x * Xscale - margin_left
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3922
        area_height = dh - self.Margins[1].y * Yscale - margin_top
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3923
        
563
3f92a5e18804 - Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents: 562
diff changeset
  3924
        dc.SetPen(MiterPen(wx.BLACK))
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3925
        dc.SetBrush(wx.TRANSPARENT_BRUSH)    
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3926
        dc.DrawRectangle(margin_left, margin_top, area_width, area_height)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3927
        
221
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3928
        dc.SetFont(wx.Font(fontsize, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3929
        dc.SetTextForeground(wx.BLACK)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3930
        block_name = " - ".join(self.Viewer.GetTagName().split("::")[1:])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3931
        text_width, text_height = dc.GetTextExtent(block_name)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3932
        dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin)
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3933
        dc.DrawText(_("Page: %d") % page, margin_left, margin_top + area_height + self.TextMargin)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3934
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3935
        # Calculate the position on the DC for centering the graphic
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3936
        posX = area_width * ((page - 1) % self.PageGrid[0])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3937
        posY = area_height * ((page - 1) / self.PageGrid[0])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3938
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3939
        scaleX = float(area_width) / float(self.PageSize[0])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3940
        scaleY = float(area_height) / float(self.PageSize[1])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3941
        scale = min(scaleX, scaleY)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3942
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3943
        # Set the scale and origin
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3944
        dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top)
221
25f2b4924347 Bugs with printing fixed
lbessard
parents: 220
diff changeset
  3945
        dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3946
        dc.SetUserScale(scale, scale)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3947
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3948
        #-------------------------------------------
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3949
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3950
        self.Viewer.DoDrawing(dc, True)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3951
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3952
        return True
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 212
diff changeset
  3953
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3954
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3955
#                               Exception Handler
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3956
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3957
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3958
Max_Traceback_List_Size = 20
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3959
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3960
def Display_Exception_Dialog(e_type,e_value,e_tb):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3961
    trcbck_lst = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3962
    for i,line in enumerate(traceback.extract_tb(e_tb)):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3963
        trcbck = " " + str(i+1) + _(". ")
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3964
        if line[0].find(os.getcwd()) == -1:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3965
            trcbck += _("file : ") + str(line[0]) + _(",   ")
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3966
        else:
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3967
            trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(",   ")
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3968
        trcbck += _("line : ") + str(line[1]) + _(",   ") + _("function : ") + str(line[2])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3969
        trcbck_lst.append(trcbck)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3970
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3971
    # Allow clicking....
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3972
    cap = wx.Window_GetCapture()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3973
    if cap:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3974
        cap.ReleaseMouse()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3975
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3976
    dlg = wx.SingleChoiceDialog(None, 
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3977
        _("""
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3978
An error has occurred.
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3979
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 423
diff changeset
  3980
Click OK to save an error report.
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3981
454
762497a95b7a Replace \"lolitech\" contact by \"edouard\" contact
greg
parents: 447
diff changeset
  3982
Please be kind enough to send this file to:
762497a95b7a Replace \"lolitech\" contact by \"edouard\" contact
greg
parents: 447
diff changeset
  3983
edouard.tisserant@gmail.com
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3984
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3985
Error:
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3986
""") +
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3987
        str(e_type) + _(" : ") + str(e_value), 
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3988
        _("Error"),
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3989
        trcbck_lst)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3990
    try:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3991
        res = (dlg.ShowModal() == wx.ID_OK)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3992
    finally:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3993
        dlg.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3994
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3995
    return res
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3996
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3997
def Display_Error_Dialog(e_value):
391
07447ee3538e Adding support for internationalization
laurent
parents: 390
diff changeset
  3998
    message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK|wx.ICON_ERROR)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  3999
    message.ShowModal()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4000
    message.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4001
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4002
def get_last_traceback(tb):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4003
    while tb.tb_next:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4004
        tb = tb.tb_next
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4005
    return tb
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4006
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4007
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4008
def format_namespace(d, indent='    '):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4009
    return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4010
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4011
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4012
ignored_exceptions = [] # a problem with a line in a module is only reported once per session
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4013
65
cb6bed0720f0 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 64
diff changeset
  4014
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4015
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4016
    def handle_exception(e_type, e_value, e_traceback):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4017
        traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4018
        last_tb = get_last_traceback(e_traceback)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4019
        ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4020
        if str(e_value).startswith("!!!"):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4021
            Display_Error_Dialog(e_value)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4022
        elif ex not in ignored_exceptions:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4023
            result = Display_Exception_Dialog(e_type,e_value,e_traceback)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4024
            if result:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4025
                ignored_exceptions.append(ex)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4026
                info = {
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4027
                    'app-title' : wx.GetApp().GetAppName(), # app_title
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4028
                    'app-version' : app_version,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4029
                    'wx-version' : wx.VERSION_STRING,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4030
                    'wx-platform' : wx.Platform,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4031
                    'python-version' : platform.python_version(), #sys.version.split()[0],
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4032
                    'platform' : platform.platform(),
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4033
                    'e-type' : e_type,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4034
                    'e-value' : e_value,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4035
                    'date' : time.ctime(),
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4036
                    'cwd' : os.getcwd(),
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4037
                    }
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4038
                if e_traceback:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4039
                    info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4040
                    last_tb = get_last_traceback(e_traceback)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4041
                    exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4042
                    info['locals'] = format_namespace(exception_locals)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4043
                    if 'self' in exception_locals:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4044
                        info['self'] = format_namespace(exception_locals['self'].__dict__)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4045
                
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4046
                output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4047
                lst = info.keys()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4048
                lst.sort()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4049
                for a in lst:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4050
                    output.write(a+":\n"+str(info[a])+"\n\n")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4051
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4052
    #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4053
    sys.excepthook = handle_exception
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4054
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4055
if __name__ == '__main__':
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
  4056
    wx.InitAllImageHandlers()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4057
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4058
    # Install a exception handle for bug reports
65
cb6bed0720f0 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 64
diff changeset
  4059
    AddExceptHook(os.getcwd(),__version__)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4060
    
92
76d5001393df Adding support for refreshing PLCOpenEditor block list
lbessard
parents: 90
diff changeset
  4061
    frame = PLCOpenEditor(None, fileOpen=fileOpen)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4062
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4063
    frame.Show()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4064
    app.MainLoop()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  4065