IDEFrame.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 17 Aug 2017 14:27:06 +0300
changeset 1763 bcc07ff2362c
parent 1762 fcc406143e5b
child 1765 ccf59c1f0b45
permissions -rwxr-xr-x
clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     1
#!/usr/bin/env python
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     2
# -*- coding: utf-8 -*-
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     3
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     6
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     8
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     9
# See COPYING file for copyrights details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    10
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    11
# This program is free software; you can redistribute it and/or
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    12
# modify it under the terms of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    13
# as published by the Free Software Foundation; either version 2
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    14
# of the License, or (at your option) any later version.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    15
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    16
# This program is distributed in the hope that it will be useful,
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    19
# GNU General Public License for more details.
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    20
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    21
# You should have received a copy of the GNU General Public License
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    22
# along with this program; if not, write to the Free Software
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    25
import os
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    26
import sys
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import cPickle
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
from types import TupleType
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    30
import wx
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    31
import wx.grid
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
import wx.aui
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
from editors.EditorPanel import EditorPanel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
from editors.SFCViewer import SFC_Viewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
from editors.LDViewer import LD_Viewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
from editors.TextViewer import TextViewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
from editors.Viewer import Viewer, ZOOM_FACTORS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
from editors.ResourceEditor import ConfigurationEditor, ResourceEditor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
from editors.DataTypeEditor import DataTypeEditor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
from PLCControler import *
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1188
diff changeset
    42
from controls import CustomTree, LibraryPanel, PouInstanceVariablesPanel, SearchResultPanel
1198
8b4e6bd0aa92 Separated old table debug variable panel and new graphic debug variable panel
Laurent Bessard
parents: 1193
diff changeset
    43
from controls.DebugVariablePanel import DebugVariablePanel
819
4424918efe8b Fix bug missing dialog import statements
laurent
parents: 814
diff changeset
    44
from dialogs import ProjectDialog, PouDialog, PouTransitionDialog, PouActionDialog, FindInPouDialog, SearchInProjectDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
# Define PLCOpenEditor controls id
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    48
[ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    49
 ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    50
 ID_PLCOPENEDITORPROJECTTREE, ID_PLCOPENEDITORMAINSPLITTER,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    51
 ID_PLCOPENEDITORSECONDSPLITTER, ID_PLCOPENEDITORTHIRDSPLITTER,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    52
 ID_PLCOPENEDITORLIBRARYPANEL, ID_PLCOPENEDITORLIBRARYSEARCHCTRL,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    53
 ID_PLCOPENEDITORLIBRARYTREE, ID_PLCOPENEDITORLIBRARYCOMMENT,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    54
 ID_PLCOPENEDITORTABSOPENED, ID_PLCOPENEDITORTABSOPENED,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    55
 ID_PLCOPENEDITOREDITORMENUTOOLBAR, ID_PLCOPENEDITOREDITORTOOLBAR,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    56
 ID_PLCOPENEDITORPROJECTPANEL,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
] = [wx.NewId() for _init_ctrls in range(17)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
# Define PLCOpenEditor EditMenu extra items id
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    60
[ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, ID_PLCOPENEDITOREDITMENUADDDATATYPE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    61
 ID_PLCOPENEDITOREDITMENUADDFUNCTION, ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
 ID_PLCOPENEDITOREDITMENUADDPROGRAM, ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
 ID_PLCOPENEDITOREDITMENUFINDNEXT, ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1364
diff changeset
    64
 ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, ID_PLCOPENEDITOREDITMENUADDRESOURCE
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1364
diff changeset
    65
] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
# Define PLCOpenEditor DisplayMenu extra items id
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    68
[ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
1530
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
    69
 ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
    70
] = [wx.NewId() for _init_coll_DisplayMenu_Items in range(2)]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
#                            EditorToolBar definitions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
# Define PLCOpenEditor Toolbar items id
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
[ID_PLCOPENEDITOREDITORTOOLBARSELECTION, ID_PLCOPENEDITOREDITORTOOLBARCOMMENT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, ID_PLCOPENEDITOREDITORTOOLBARBLOCK,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, ID_PLCOPENEDITOREDITORTOOLBARWIRE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
 ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITOREDITORTOOLBARRUNG,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
 ID_PLCOPENEDITOREDITORTOOLBARCOIL, ID_PLCOPENEDITOREDITORTOOLBARCONTACT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
 ID_PLCOPENEDITOREDITORTOOLBARBRANCH, ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
 ID_PLCOPENEDITOREDITORTOOLBARSTEP, ID_PLCOPENEDITOREDITORTOOLBARTRANSITION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
 ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE,
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    85
 ID_PLCOPENEDITOREDITORTOOLBARJUMP, ID_PLCOPENEDITOREDITORTOOLBARMOTION,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
] = [wx.NewId() for _init_coll_DefaultEditorToolBar_Items in range(18)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    89
# Define behaviour of each Toolbar item according to current POU body type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
# Informations meaning are in this order:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
#  - Item is toggled
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
#  - PLCOpenEditor mode where item is displayed (could be more then one)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
#  - Item id
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
#  - Item callback function name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
#  - Item icon filename
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
#  - Item tooltip text
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
EditorToolBarItems = {
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
    98
    "FBD":   [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
    99
               ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   100
               "move", _("Move the view")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   101
              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   102
               ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   103
               "add_comment", _("Create a new comment")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   104
              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   105
               ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   106
               "add_variable", _("Create a new variable")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   107
              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   108
               ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   109
               "add_block", _("Create a new block")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   110
              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   111
               ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   112
               "add_connection", _("Create a new connection"))],
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   113
    "LD":    [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   114
               ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   115
               "move", _("Move the view")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   116
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   117
               ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   118
               "add_comment", _("Create a new comment")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   119
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   120
               ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   121
               "add_powerrail", _("Create a new power rail")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   122
              (False, DRIVENDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   123
               ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   124
               "add_rung", _("Create a new rung")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   125
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   126
               ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   127
               "add_coil", _("Create a new coil")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   128
              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   129
               ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   130
               "add_contact", _("Create a new contact")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   131
              (False, DRIVENDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   132
               ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   133
               "add_branch", _("Create a new branch")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   134
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   135
               ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   136
               "add_variable", _("Create a new variable")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   137
              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   138
               ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   139
               "add_block", _("Create a new block")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   140
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   141
               ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   142
               "add_connection", _("Create a new connection"))],
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   143
    "SFC":   [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   144
               ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   145
               "move", _("Move the view")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   146
              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   147
               ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   148
               "add_comment", _("Create a new comment")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   149
              (True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   150
               ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   151
               "add_initial_step", _("Create a new initial step")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   152
              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   153
               ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   154
               "add_step", _("Create a new step")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   155
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   156
               ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   157
               "add_transition", _("Create a new transition")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   158
              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   159
               ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   160
               "add_action", _("Create a new action block")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   161
              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   162
               ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   163
               "add_divergence", _("Create a new divergence")),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   164
              (False, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   165
               ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   166
               "add_jump", _("Create a new jump")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   167
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   168
               ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   169
               "add_variable", _("Create a new variable")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   170
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   171
               ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   172
               "add_block", _("Create a new block")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   173
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   174
               ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   175
               "add_connection", _("Create a new connection")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   176
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   177
               ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   178
               "add_powerrail", _("Create a new power rail")),
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   179
              (True, FREEDRAWING_MODE,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   180
               ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   181
               "add_contact", _("Create a new contact"))],
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   182
    "ST":    [],
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   183
    "IL":    [],
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   184
    "debug": [(True, FREEDRAWING_MODE | DRIVENDRAWING_MODE,
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   185
               ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   186
               "move", _("Move the view"))],
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
#                               Helper Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
import base64
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   195
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
def EncodeFileSystemPath(path, use_base64=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
    path = path.encode(sys.getfilesystemencoding())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
    if use_base64:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
        return base64.encodestring(path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
    return path
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   202
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
def DecodeFileSystemPath(path, is_base64=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
    if is_base64:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
        path = base64.decodestring(path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
    return unicode(path, sys.getfilesystemencoding())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   208
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
def AppendMenu(parent, help, id, kind, text):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   210
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   211
    Compatibility function for wx versions < 2.6
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   212
    """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
    if wx.VERSION >= (2, 6, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
        parent.Append(help=help, id=id, kind=kind, text=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
        parent.Append(helpString=help, id=id, kind=kind, item=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   218
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   219
[TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
 POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
] = range(10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   223
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
def GetShortcutKeyCallbackFunction(viewer_function):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
    def ShortcutKeyFunction(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
        control = self.FindFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
        if control is not None and control.GetName() in ["Viewer", "TextViewer"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
            getattr(control.ParentWindow, viewer_function)()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
        elif isinstance(control, wx.stc.StyledTextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
            getattr(control, viewer_function)()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
        elif isinstance(control, wx.TextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
            control.ProcessEvent(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
    return ShortcutKeyFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   235
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
def GetDeleteElementFunction(remove_function, parent_type=None, check_function=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
    def DeleteElementFunction(self, selected):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
        name = self.ProjectTree.GetItemText(selected)
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
   239
        if check_function is None or check_function(name):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
            if parent_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
                item_infos = self.ProjectTree.GetPyData(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
                parent_name = item_infos["tagname"].split("::")[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
                remove_function(self.Controler, parent_name, name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
                remove_function(self.Controler, name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
    return DeleteElementFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   248
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
if wx.Platform == '__WXMSW__':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
    TAB_BORDER = 6
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
    NOTEBOOK_BORDER = 6
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
    TAB_BORDER = 7
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
    NOTEBOOK_BORDER = 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   256
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
def SimplifyTabLayout(tabs, rect):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
    for tab in tabs:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
        if tab["pos"][0] == rect.x:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
            others = [t for t in tabs if t != tab]
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   261
            others.sort(lambda x, y: cmp(x["pos"][0], y["pos"][0]))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
            for other in others:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   263
                if (other["pos"][1] == tab["pos"][1] and
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
                    other["size"][1] == tab["size"][1] and
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
                    other["pos"][0] == tab["pos"][0] + tab["size"][0] + TAB_BORDER):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   266
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
                    tab["size"] = (tab["size"][0] + other["size"][0] + TAB_BORDER, tab["size"][1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
                    tab["pages"].extend(other["pages"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
                    tabs.remove(other)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   270
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
                    if tab["size"][0] == rect.width:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   272
                        return True
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   273
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   274
        elif tab["pos"][1] == rect.y:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
            others = [t for t in tabs if t != tab]
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   276
            others.sort(lambda x, y: cmp(x["pos"][1], y["pos"][1]))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
            for other in others:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   278
                if (other["pos"][0] == tab["pos"][0] and
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
                    other["size"][0] == tab["size"][0] and
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
                    other["pos"][1] == tab["pos"][1] + tab["size"][1] + TAB_BORDER):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   281
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
                    tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + TAB_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
                    tab["pages"].extend(other["pages"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
                    tabs.remove(other)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   285
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
                    if tab["size"][1] == rect.height:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
                        return True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
    return False
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   289
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   290
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
def ComputeTabsLayout(tabs, rect):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
    if len(tabs) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
        return tabs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
    if len(tabs) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
        return tabs[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
    split = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
    for idx, tab in enumerate(tabs):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
        if len(tab["pages"]) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
            raise ValueError, "Not possible"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
        if tab["size"][0] == rect.width:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
            if tab["pos"][1] == rect.y:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
                split = (wx.TOP, float(tab["size"][1]) / float(rect.height))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   303
                split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
            elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
                split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   307
                split_rect = wx.Rect(rect.x, rect.y,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
            break
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
        elif tab["size"][1] == rect.height:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
            if tab["pos"][0] == rect.x:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
                split = (wx.LEFT, float(tab["size"][0]) / float(rect.width))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   313
                split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
            elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
                split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   317
                split_rect = wx.Rect(rect.x, rect.y,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
            break
1743
c3c3d1318130 clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   320
    if split is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
        split_tab = tabs.pop(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
        return {"split": split,
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   323
                "tab": split_tab,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
                "others": ComputeTabsLayout(tabs, split_rect)}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
        if SimplifyTabLayout(tabs, rect):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
            return ComputeTabsLayout(tabs, rect)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
    return tabs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
#                              IDEFrame Base Class
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   334
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
UNEDITABLE_NAMES_DICT = dict([(_(name), name) for name in UNEDITABLE_NAMES])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   337
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
class IDEFrame(wx.Frame):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   339
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
    # Compatibility function for wx versions < 2.6
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
    if wx.VERSION < (2, 6, 0):
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   342
        def Bind(self, event, function, id=None):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
            if id is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
                event(self, id, function)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
                event(self, function)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   347
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
    def _init_coll_MenuBar_Menus(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
        parent.Append(menu=self.FileMenu, title=_(u'&File'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
        parent.Append(menu=self.EditMenu, title=_(u'&Edit'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
        parent.Append(menu=self.DisplayMenu, title=_(u'&Display'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
        parent.Append(menu=self.HelpMenu, title=_(u'&Help'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
    def _init_coll_FileMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
        pass
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   356
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
    def _init_coll_AddMenu_Items(self, parent, add_config=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDDATATYPE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
              kind=wx.ITEM_NORMAL, text=_(u'&Data Type'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   360
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
              kind=wx.ITEM_NORMAL, text=_(u'&Function'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
              kind=wx.ITEM_NORMAL, text=_(u'Function &Block'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDPROGRAM,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
              kind=wx.ITEM_NORMAL, text=_(u'&Program'))
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1364
diff changeset
   366
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDRESOURCE,
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1364
diff changeset
   367
                  kind=wx.ITEM_NORMAL, text=_(u'&Resource'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
        if add_config:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
            AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
                  kind=wx.ITEM_NORMAL, text=_(u'&Configuration'))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   371
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
    def _init_coll_EditMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
        AppendMenu(parent, help='', id=wx.ID_UNDO,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
              kind=wx.ITEM_NORMAL, text=_(u'Undo') + '\tCTRL+Z')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
        AppendMenu(parent, help='', id=wx.ID_REDO,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
              kind=wx.ITEM_NORMAL, text=_(u'Redo') + '\tCTRL+Y')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
        #AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
        #      kind=wx.ITEM_CHECK, text=_(u'Enable Undo/Redo'))
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   379
        enable_undo_redo = _(u'Enable Undo/Redo')  # Keeping text in translations for possible menu reactivation
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
        AppendMenu(parent, help='', id=wx.ID_CUT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
              kind=wx.ITEM_NORMAL, text=_(u'Cut') + '\tCTRL+X')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
        AppendMenu(parent, help='', id=wx.ID_COPY,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
              kind=wx.ITEM_NORMAL, text=_(u'Copy') + '\tCTRL+C')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
        AppendMenu(parent, help='', id=wx.ID_PASTE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
              kind=wx.ITEM_NORMAL, text=_(u'Paste') + '\tCTRL+V')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
        AppendMenu(parent, help='', id=wx.ID_FIND,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
              kind=wx.ITEM_NORMAL, text=_(u'Find') + '\tCTRL+F')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDNEXT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
              kind=wx.ITEM_NORMAL, text=_(u'Find Next') + '\tCTRL+K')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
              kind=wx.ITEM_NORMAL, text=_(u'Find Previous') + '\tCTRL+SHIFT+K')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
              kind=wx.ITEM_NORMAL, text=_(u'Search in Project') + '\tCTRL+SHIFT+F')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
        add_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
        self._init_coll_AddMenu_Items(add_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
        parent.AppendMenu(wx.ID_ADD, _(u"&Add Element"), add_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
        AppendMenu(parent, help='', id=wx.ID_SELECTALL,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
              kind=wx.ITEM_NORMAL, text=_(u'Select All') + '\tCTRL+A')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
        AppendMenu(parent, help='', id=wx.ID_DELETE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
              kind=wx.ITEM_NORMAL, text=_(u'&Delete'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
        self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
        self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
        #self.Bind(wx.EVT_MENU, self.OnEnableUndoRedoMenu, id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
        self.Bind(wx.EVT_MENU, self.OnCutMenu, id=wx.ID_CUT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
        self.Bind(wx.EVT_MENU, self.OnCopyMenu, id=wx.ID_COPY)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
        self.Bind(wx.EVT_MENU, self.OnPasteMenu, id=wx.ID_PASTE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
        self.Bind(wx.EVT_MENU, self.OnFindMenu, id=wx.ID_FIND)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   412
        self.Bind(wx.EVT_MENU, self.OnFindNextMenu,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
              id=ID_PLCOPENEDITOREDITMENUFINDNEXT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   414
        self.Bind(wx.EVT_MENU, self.OnFindPreviousMenu,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
              id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   416
        self.Bind(wx.EVT_MENU, self.OnSearchInProjectMenu,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
              id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   418
        self.Bind(wx.EVT_MENU, self.OnSearchInProjectMenu,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
              id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
        self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
              id=ID_PLCOPENEDITOREDITMENUADDDATATYPE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("function"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   423
              id=ID_PLCOPENEDITOREDITMENUADDFUNCTION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   424
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("functionBlock"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
              id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   426
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("program"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
              id=ID_PLCOPENEDITOREDITMENUADDPROGRAM)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   428
        self.Bind(wx.EVT_MENU, self.AddResourceMenu,
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1364
diff changeset
   429
              id=ID_PLCOPENEDITOREDITMENUADDRESOURCE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
        self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   431
              id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
        self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
        self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   434
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
        self.AddToMenuToolBar([(wx.ID_UNDO, "undo", _(u'Undo'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
                               (wx.ID_REDO, "redo", _(u'Redo'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
                               None,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
                               (wx.ID_CUT, "cut", _(u'Cut'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   439
                               (wx.ID_COPY, "copy", _(u'Copy'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   440
                               (wx.ID_PASTE, "paste", _(u'Paste'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   441
                               None,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
                               (ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find", _(u'Search in Project'), None)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   444
    def _init_coll_DisplayMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
        AppendMenu(parent, help='', id=wx.ID_REFRESH,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
              kind=wx.ITEM_NORMAL, text=_(u'Refresh') + '\tCTRL+R')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   447
        if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   448
            AppendMenu(parent, help='', id=wx.ID_CLEAR,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   449
                  kind=wx.ITEM_NORMAL, text=_(u'Clear Errors') + '\tCTRL+K')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   450
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
        zoommenu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
        parent.AppendMenu(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
        for idx, value in enumerate(ZOOM_FACTORS):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
            new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   455
            AppendMenu(zoommenu, help='', id=new_id,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
                  kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
            self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   458
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
        parent.AppendSeparator()
1530
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
   460
        AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
   461
                   kind=wx.ITEM_NORMAL, text=_(u'Switch perspective') + '\tF12')
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
   462
        self.Bind(wx.EVT_MENU, self.SwitchFullScrMode, id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE)
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
   463
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
        AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   465
              kind=wx.ITEM_NORMAL, text=_(u'Reset Perspective'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
        self.Bind(wx.EVT_MENU, self.OnResetPerspective, id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   467
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   468
        self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   469
        if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
            self.Bind(wx.EVT_MENU, self.OnClearErrorsMenu, id=wx.ID_CLEAR)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   471
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   472
    def _init_coll_HelpMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   473
        pass
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   475
    def _init_utils(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   476
        self.MenuBar = wx.MenuBar()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   477
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   478
        self.FileMenu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   479
        self.EditMenu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   480
        self.DisplayMenu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
        self.HelpMenu = wx.Menu(title='')
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   482
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
        self._init_coll_MenuBar_Menus(self.MenuBar)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
        self._init_coll_FileMenu_Items(self.FileMenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   485
        self._init_coll_EditMenu_Items(self.EditMenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
        self._init_coll_DisplayMenu_Items(self.DisplayMenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
        self._init_coll_HelpMenu_Items(self.HelpMenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   488
1490
f03bc6c9c146 make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1480
diff changeset
   489
    def _init_icon(self, parent):
f03bc6c9c146 make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1480
diff changeset
   490
        if self.icon:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1710
diff changeset
   491
            self.SetIcon(self.icon)
1490
f03bc6c9c146 make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1480
diff changeset
   492
        elif parent and parent.icon:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1710
diff changeset
   493
            self.SetIcon(parent.icon)
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1710
diff changeset
   494
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
    def _init_ctrls(self, prnt):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   496
        wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name='IDEFrame',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   497
              parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   498
              style=wx.DEFAULT_FRAME_STYLE)
1490
f03bc6c9c146 make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1480
diff changeset
   499
        self._init_icon(prnt)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
        self.SetClientSize(wx.Size(1000, 600))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   501
        self.Bind(wx.EVT_ACTIVATE, self.OnActivated)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   502
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   503
        self.TabsImageList = wx.ImageList(31, 16)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   504
        self.TabsImageListIndexes = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   505
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   506
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
        #                          Creating main structure
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   509
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   510
        self.AUIManager = wx.aui.AuiManager(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   511
        self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   512
        self.Panes = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   513
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   514
        self.LeftNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORLEFTNOTEBOOK,
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   515
              style=wx.aui.AUI_NB_TOP | wx.aui.AUI_NB_TAB_SPLIT | wx.aui.AUI_NB_TAB_MOVE |
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   516
                    wx.aui.AUI_NB_SCROLL_BUTTONS | wx.aui.AUI_NB_TAB_EXTERNAL_MOVE)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   517
        self.LeftNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
                self.OnAllowNotebookDnD)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   519
        self.AUIManager.AddPane(self.LeftNoteBook,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
              wx.aui.AuiPaneInfo().Name("ProjectPane").
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
              Left().Layer(1).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
              BestSize(wx.Size(300, 500)).CloseButton(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   523
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
        self.BottomNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORBOTTOMNOTEBOOK,
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   525
              style=wx.aui.AUI_NB_TOP | wx.aui.AUI_NB_TAB_SPLIT | wx.aui.AUI_NB_TAB_MOVE |
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   526
                    wx.aui.AUI_NB_SCROLL_BUTTONS | wx.aui.AUI_NB_TAB_EXTERNAL_MOVE)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   527
        self.BottomNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
                self.OnAllowNotebookDnD)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   529
        self.AUIManager.AddPane(self.BottomNoteBook,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   530
              wx.aui.AuiPaneInfo().Name("ResultPane").
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
              Bottom().Layer(0).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
              BestSize(wx.Size(800, 300)).CloseButton(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   533
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
        self.RightNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORRIGHTNOTEBOOK,
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   535
              style=wx.aui.AUI_NB_TOP | wx.aui.AUI_NB_TAB_SPLIT | wx.aui.AUI_NB_TAB_MOVE |
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   536
                    wx.aui.AUI_NB_SCROLL_BUTTONS | wx.aui.AUI_NB_TAB_EXTERNAL_MOVE)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   537
        self.RightNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
                self.OnAllowNotebookDnD)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   539
        self.AUIManager.AddPane(self.RightNoteBook,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   540
              wx.aui.AuiPaneInfo().Name("LibraryPane").
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   541
              Right().Layer(0).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   542
              BestSize(wx.Size(250, 400)).CloseButton(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   543
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   544
        self.TabsOpened = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORTABSOPENED,
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   545
              style=wx.aui.AUI_NB_DEFAULT_STYLE | wx.aui.AUI_NB_WINDOWLIST_BUTTON)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   546
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
              self.OnPouSelectedChanging)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   548
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   549
              self.OnPouSelectedChanged)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   550
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   551
              self.OnPageClose)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   552
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_END_DRAG,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
              self.OnPageDragged)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   554
        self.AUIManager.AddPane(self.TabsOpened,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   555
              wx.aui.AuiPaneInfo().CentrePane().Name("TabsPane"))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   556
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   557
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   558
        #                    Creating PLCopen Project Types Tree
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   560
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
        self.MainTabs = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   562
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   563
        self.ProjectPanel = wx.SplitterWindow(id=ID_PLCOPENEDITORPROJECTPANEL,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   564
                  name='ProjectPanel', parent=self.LeftNoteBook, point=wx.Point(0, 0),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
                  size=wx.Size(0, 0), style=wx.SP_3D)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   566
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   567
        self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE,
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   568
                  name='ProjectTree', parent=self.ProjectPanel,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   569
                  pos=wx.Point(0, 0), size=wx.Size(0, 0),
1167
a2f9b44c17c9 Fixed bug ProjectTree items label can't be edited
Laurent Bessard
parents: 1165
diff changeset
   570
                  style=wx.SUNKEN_BORDER,
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   571
                  agwStyle=wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.TR_EDIT_LABELS)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   572
        self.ProjectTree.SetBackgroundBitmap(GetBitmap("custom_tree_background"),
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   573
                                             wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   574
        add_menu = wx.Menu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
        self._init_coll_AddMenu_Items(add_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
        self.ProjectTree.SetAddMenu(add_menu)
1240
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1233
diff changeset
   577
        self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnProjectTreeRightUp,
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1233
diff changeset
   578
              id=ID_PLCOPENEDITORPROJECTTREE)
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1233
diff changeset
   579
        self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp)
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1233
diff changeset
   580
        self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging,
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1233
diff changeset
   581
              id=ID_PLCOPENEDITORPROJECTTREE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
        self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   583
              id=ID_PLCOPENEDITORPROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
        self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   585
              id=ID_PLCOPENEDITORPROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   586
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   587
              id=ID_PLCOPENEDITORPROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   588
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   589
              id=ID_PLCOPENEDITORPROJECTTREE)
1106
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
   590
        self.ProjectTree.Bind(wx.EVT_MOTION, self.OnProjectTreeMotion)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   591
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
        #        Creating PLCopen Project POU Instance Variables Panel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   595
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
        self.PouInstanceVariablesPanel = PouInstanceVariablesPanel(self.ProjectPanel, self, self.Controler, self.EnableDebug)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   597
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
        self.MainTabs["ProjectPanel"] = (self.ProjectPanel, _("Project"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   599
        self.LeftNoteBook.AddPage(*self.MainTabs["ProjectPanel"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   600
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   601
        self.ProjectPanel.SplitHorizontally(self.ProjectTree, self.PouInstanceVariablesPanel, 300)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   602
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   603
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
        #                            Creating Tool Bar
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   605
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   606
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
        MenuToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORMENUTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
                wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   609
        MenuToolBar.SetToolBitmapSize(wx.Size(25, 25))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
        MenuToolBar.Realize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   611
        self.Panes["MenuToolBar"] = MenuToolBar
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   612
        self.AUIManager.AddPane(MenuToolBar, wx.aui.AuiPaneInfo().
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
                  Name("MenuToolBar").Caption(_("Menu ToolBar")).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   614
                  ToolbarPane().Top().
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   615
                  LeftDockable(False).RightDockable(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   616
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   617
        EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   618
                wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   619
        EditorToolBar.SetToolBitmapSize(wx.Size(25, 25))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   620
        EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   621
              GetBitmap("select"), wx.NullBitmap, _("Select an object"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   622
        EditorToolBar.Realize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
        self.Panes["EditorToolBar"] = EditorToolBar
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
        self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo().
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   625
                  Name("EditorToolBar").Caption(_("Editor ToolBar")).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   626
                  ToolbarPane().Top().Position(1).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   627
                  LeftDockable(False).RightDockable(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   628
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   629
        self.Bind(wx.EVT_MENU, self.OnSelectionTool,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   630
              id=ID_PLCOPENEDITOREDITORTOOLBARSELECTION)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   631
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   633
        #                            Creating Search Panel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   634
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   635
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   636
        self.SearchResultPanel = SearchResultPanel(self.BottomNoteBook, self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
        self.MainTabs["SearchResultPanel"] = (self.SearchResultPanel, _("Search"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   638
        self.BottomNoteBook.AddPage(*self.MainTabs["SearchResultPanel"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   639
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   641
        #                            Creating Library Panel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   643
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   644
        self.LibraryPanel = LibraryPanel(self, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   645
        self.MainTabs["LibraryPanel"] = (self.LibraryPanel, _("Library"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   646
        self.RightNoteBook.AddPage(*self.MainTabs["LibraryPanel"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   647
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   648
        self._init_utils()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
        self.SetMenuBar(self.MenuBar)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   650
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
        if self.EnableDebug:
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 897
diff changeset
   652
            self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self.Controler, self)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
            self.MainTabs["DebugVariablePanel"] = (self.DebugVariablePanel, _("Debugger"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
            self.RightNoteBook.AddPage(*self.MainTabs["DebugVariablePanel"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   655
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   656
        self.AUIManager.Update()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   657
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
    ## Constructor of the PLCOpenEditor class.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   659
    #  @param parent The parent window.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
    #  @param controler The controler been used by PLCOpenEditor (default: None).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   661
    #  @param fileOpen The filepath to open if no controler defined (default: None).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
    #  @param debug The filepath to open if no controler defined (default: False).
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   663
    def __init__(self, parent, enable_debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
        self.Controler = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
        self.Config = wx.ConfigBase.Get()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   666
        self.EnableDebug = enable_debug
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   667
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   668
        self._init_ctrls(parent)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   669
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   670
        # Define Tree item icon list
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   671
        self.TreeImageList = wx.ImageList(16, 16)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   672
        self.TreeImageDict = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   673
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   674
        # Icons for languages
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   675
        for language in LANGUAGES:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   676
            self.TreeImageDict[language] = self.TreeImageList.Add(GetBitmap(language))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   677
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   678
        # Icons for other items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   679
        for imgname, itemtype in [
1733
dea107dce0c4 clean-up: fix some PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   680
            # editables
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   681
            ("PROJECT",        ITEM_PROJECT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   682
            #("POU",            ITEM_POU),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   683
            #("VARIABLE",       ITEM_VARIABLE),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
            ("TRANSITION",     ITEM_TRANSITION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
            ("ACTION",         ITEM_ACTION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
            ("CONFIGURATION",  ITEM_CONFIGURATION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
            ("RESOURCE",       ITEM_RESOURCE),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
            ("DATATYPE",       ITEM_DATATYPE),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
            # uneditables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   690
            ("DATATYPES",      ITEM_DATATYPES),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
            ("FUNCTION",       ITEM_FUNCTION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
            ("FUNCTIONBLOCK",  ITEM_FUNCTIONBLOCK),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
            ("PROGRAM",        ITEM_PROGRAM),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   694
            ("VAR_LOCAL",      ITEM_VAR_LOCAL),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
            ("VAR_LOCAL",      ITEM_VAR_GLOBAL),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   696
            ("VAR_LOCAL",      ITEM_VAR_EXTERNAL),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
            ("VAR_LOCAL",      ITEM_VAR_TEMP),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
            ("VAR_INPUT",      ITEM_VAR_INPUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
            ("VAR_OUTPUT",     ITEM_VAR_OUTPUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
            ("VAR_INOUT",      ITEM_VAR_INOUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
            ("TRANSITIONS",    ITEM_TRANSITIONS),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
            ("ACTIONS",        ITEM_ACTIONS),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
            ("CONFIGURATIONS", ITEM_CONFIGURATIONS),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   704
            ("RESOURCES",      ITEM_RESOURCES),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   705
            ("PROPERTIES",     ITEM_PROPERTIES)]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
            self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   707
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   708
        # Assign icon list to TreeCtrls
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   709
        self.ProjectTree.SetImageList(self.TreeImageList)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   710
        self.PouInstanceVariablesPanel.SetTreeImageList(self.TreeImageList)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   711
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   712
        self.CurrentEditorToolBar = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
        self.CurrentMenu = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   714
        self.SelectedItem = None
1106
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
   715
        self.LastToolTipItem = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   716
        self.SearchParams = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
        self.Highlights = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
        self.DrawingMode = FREEDRAWING_MODE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   719
        #self.DrawingMode = DRIVENDRAWING_MODE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   720
        self.AuiTabCtrl = []
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   721
980
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   722
        # Save default perspective
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   723
        notebooks = {}
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   724
        for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   725
                                     (self.BottomNoteBook, "bottomnotebook"),
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   726
                                     (self.RightNoteBook, "rightnotebook")]:
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   727
            notebooks[entry_name] = self.SaveTabLayout(notebook)
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   728
        self.DefaultPerspective = {
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   729
            "perspective": self.AUIManager.SavePerspective(),
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   730
            "notebooks": notebooks,
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   731
        }
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   732
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   733
        # Initialize Printing configuring elements
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   734
        self.PrintData = wx.PrintData()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
        self.PrintData.SetPaperId(wx.PAPER_A4)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   736
        self.PrintData.SetPrintMode(wx.PRINT_MODE_PRINTER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
        self.PageSetupData = wx.PageSetupDialogData(self.PrintData)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   738
        self.PageSetupData.SetMarginTopLeft(wx.Point(10, 15))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
        self.PageSetupData.SetMarginBottomRight(wx.Point(10, 20))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   740
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   741
        self.SetRefreshFunctions()
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
   742
        self.SetDeleteFunctions()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   743
1700
df50e13a94d6 fix problem with hidden FindInPou dialog with wxPython 3.0 on Windows
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1635
diff changeset
   744
        wx.CallAfter(self.InitFindDialog)
df50e13a94d6 fix problem with hidden FindInPou dialog with wxPython 3.0 on Windows
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1635
diff changeset
   745
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   746
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   747
        self.FindDialog.Destroy()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   748
1700
df50e13a94d6 fix problem with hidden FindInPou dialog with wxPython 3.0 on Windows
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1635
diff changeset
   749
    def InitFindDialog(self):
df50e13a94d6 fix problem with hidden FindInPou dialog with wxPython 3.0 on Windows
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1635
diff changeset
   750
        self.FindDialog = FindInPouDialog(self)
df50e13a94d6 fix problem with hidden FindInPou dialog with wxPython 3.0 on Windows
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1635
diff changeset
   751
        self.FindDialog.Hide()
df50e13a94d6 fix problem with hidden FindInPou dialog with wxPython 3.0 on Windows
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1635
diff changeset
   752
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   753
    def Show(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   754
        wx.Frame.Show(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   755
        wx.CallAfter(self.RestoreLastState)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   756
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   757
    def OnActivated(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   758
        if event.GetActive():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   759
            wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   760
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   761
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   762
    def SelectTab(self, tab):
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   763
        for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   764
            idx = notebook.GetPageIndex(tab)
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1010
diff changeset
   765
            if idx != wx.NOT_FOUND and idx != notebook.GetSelection():
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   766
                notebook.SetSelection(idx)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   767
                return
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   768
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   770
#                Saving and restoring frame organization functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   771
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
    def GetTabInfos(self, tab):
980
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   774
        for page_name, (page_ref, page_title) in self.MainTabs.iteritems():
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 980
diff changeset
   775
            if page_ref == tab:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 980
diff changeset
   776
                return ("main", page_name)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   777
        return None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   778
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   779
    def SaveTabLayout(self, notebook):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   780
        tabs = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   781
        for child in notebook.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   782
            if isinstance(child, wx.aui.AuiTabCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   783
                if child.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   784
                    pos = child.GetPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   785
                    tab = {"pos": (pos.x, pos.y), "pages": []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   786
                    tab_size = child.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   787
                    for page_idx in xrange(child.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   788
                        page = child.GetWindowFromIdx(page_idx)
1763
bcc07ff2362c clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   789
                        if not "size" in tab:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   790
                            tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   791
                        tab_infos = self.GetTabInfos(page)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   792
                        if tab_infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
                            tab["pages"].append((tab_infos, page_idx == child.GetActivePage()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   794
                    tabs.append(tab)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   795
        tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   796
        size = notebook.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   797
        return ComputeTabsLayout(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   798
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   799
    def LoadTab(self, notebook, page_infos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   800
        if page_infos[0] == "main":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   801
            infos = self.MainTabs.get(page_infos[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   802
            if infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   803
                page_ref, page_title = infos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   804
                notebook.AddPage(page_ref, page_title)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   805
                return notebook.GetPageIndex(page_ref)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   806
        elif page_infos[0] == "editor":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   807
            tagname = page_infos[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   808
            page_ref = self.EditProjectElement(self.Controler.GetElementType(tagname), tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   809
            if page_ref is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   810
                page_ref.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   811
                return notebook.GetPageIndex(page_ref)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   812
        elif page_infos[0] == "debug":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   813
            instance_path = page_infos[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
            instance_infos = self.Controler.GetInstanceInfos(instance_path, self.EnableDebug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   815
            if instance_infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   816
                return notebook.GetPageIndex(self.OpenDebugViewer(instance_infos["class"], instance_path, instance_infos["type"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   817
        return None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   818
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   819
    def LoadTabLayout(self, notebook, tabs, mode="all", first_index=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   820
        if isinstance(tabs, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   821
            if len(tabs) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   822
                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   823
            raise ValueError, "Not supported"
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   824
1763
bcc07ff2362c clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   825
        if "split" in tabs:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
            self.LoadTabLayout(notebook, tabs["others"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   827
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   828
            split_dir, split_ratio = tabs["split"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   829
            first_index = self.LoadTabLayout(notebook, tabs["tab"], mode="first")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   830
            notebook.Split(first_index, split_dir)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   831
            self.LoadTabLayout(notebook, tabs["tab"], mode="others", first_index=first_index)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   832
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   833
        elif mode == "first":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   834
            return self.LoadTab(notebook, tabs["pages"][0][0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   835
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   836
            selected = first_index
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   837
            if mode == "others":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   838
                add_tabs = tabs["pages"][1:]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   839
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   840
                add_tabs = tabs["pages"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   841
            for page_infos, page_selected in add_tabs:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   842
                page_idx = self.LoadTab(notebook, page_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   843
                if page_selected:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   844
                    selected = page_idx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   845
            if selected is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   846
                wx.CallAfter(notebook.SetSelection, selected)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   847
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   848
    def ResetPerspective(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   849
        if self.DefaultPerspective is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   850
            self.AUIManager.LoadPerspective(self.DefaultPerspective["perspective"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   851
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   852
            for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   853
                for idx in xrange(notebook.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   854
                    notebook.RemovePage(0)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   855
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   856
            notebooks = self.DefaultPerspective["notebooks"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   857
            for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   858
                                         (self.BottomNoteBook, "bottomnotebook"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   859
                                         (self.RightNoteBook, "rightnotebook")]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   860
                self.LoadTabLayout(notebook, notebooks.get(entry_name))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   861
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   862
            self._Refresh(EDITORTOOLBAR)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   863
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   864
    def RestoreLastState(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   865
        frame_size = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   866
        if self.Config.HasEntry("framesize"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   867
            frame_size = cPickle.loads(str(self.Config.Read("framesize")))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   868
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   869
        if frame_size is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   870
            self.Maximize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   871
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   872
            self.SetClientSize(frame_size)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   873
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   874
    def SaveLastState(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   875
        if not self.IsMaximized():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   876
            self.Config.Write("framesize", cPickle.dumps(self.GetClientSize()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   877
        elif self.Config.HasEntry("framesize"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   878
            self.Config.DeleteEntry("framesize")
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   879
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   880
        self.Config.Flush()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   881
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   882
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   883
#                               General Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   884
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   885
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   886
    def SetRefreshFunctions(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   887
        self.RefreshFunctions = {
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   888
            TITLE: self.RefreshTitle,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   889
            EDITORTOOLBAR: self.RefreshEditorToolBar,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   890
            FILEMENU: self.RefreshFileMenu,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   891
            EDITMENU: self.RefreshEditMenu,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   892
            DISPLAYMENU: self.RefreshDisplayMenu,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   893
            PROJECTTREE: self.RefreshProjectTree,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   894
            POUINSTANCEVARIABLESPANEL: self.RefreshPouInstanceVariablesPanel,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   895
            LIBRARYTREE: self.RefreshLibraryPanel,
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   896
            SCALING: self.RefreshScaling,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   897
            PAGETITLES: self.RefreshPageTitles}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   898
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   899
    ## Call PLCOpenEditor refresh functions.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   900
    #  @param elements List of elements to refresh.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   901
    def _Refresh(self, *elements):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   902
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   903
            for element in elements:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   904
                self.RefreshFunctions[element]()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   905
        except wx.PyDeadObjectError:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   906
            # ignore exceptions caused by refresh while quitting
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   907
            pass
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   908
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   909
    ## Callback function when AUINotebook Page closed with CloseButton
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   910
    #  @param event AUINotebook Event.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   911
    def OnPageClose(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   912
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   913
        if selected > -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   914
            window = self.TabsOpened.GetPage(selected)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   915
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   916
            if window.CheckSaveBeforeClosing():
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   917
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   918
                # Refresh all window elements that have changed
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   919
                wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   920
                wx.CallAfter(self.RefreshTabCtrlEvent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   921
                wx.CallAfter(self.CloseFindInPouDialog)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   922
                event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   923
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   924
                event.Veto()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   925
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1010
diff changeset
   926
    def GetCopyBuffer(self, primary_selection=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   927
        data = None
1028
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   928
        if primary_selection and wx.Platform == '__WXMSW__':
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   929
            return data
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   930
        else:
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   931
            wx.TheClipboard.UsePrimarySelection(primary_selection)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   932
        if wx.TheClipboard.Open():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   933
            dataobj = wx.TextDataObject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   934
            if wx.TheClipboard.GetData(dataobj):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   935
                data = dataobj.GetText()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   936
            wx.TheClipboard.Close()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   937
        return data
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   938
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1010
diff changeset
   939
    def SetCopyBuffer(self, text, primary_selection=False):
1028
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   940
        if primary_selection and wx.Platform == '__WXMSW__':
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   941
            return
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   942
        else:
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   943
            wx.TheClipboard.UsePrimarySelection(primary_selection)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   944
        if wx.TheClipboard.Open():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   945
            data = wx.TextDataObject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   946
            data.SetText(text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   947
            wx.TheClipboard.SetData(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   948
            wx.TheClipboard.Flush()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   949
            wx.TheClipboard.Close()
1087
16cc3c42e413 Fixed bug when closing Beremiz frame
Laurent Bessard
parents: 1028
diff changeset
   950
        self.RefreshEditMenu()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   951
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   952
    def GetDrawingMode(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   953
        return self.DrawingMode
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   954
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   955
    def RefreshScaling(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   956
        for i in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   957
            editor = self.TabsOpened.GetPage(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   958
            editor.RefreshScaling()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   959
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   960
    def EditProjectSettings(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   961
        old_values = self.Controler.GetProjectProperties()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   962
        dialog = ProjectDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   963
        dialog.SetValues(old_values)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   964
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   965
            new_values = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   966
            new_values["creationDateTime"] = old_values["creationDateTime"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   967
            if new_values != old_values:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   968
                self.Controler.SetProjectProperties(None, new_values)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   969
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   970
                              PROJECTTREE, POUINSTANCEVARIABLESPANEL, SCALING)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   971
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   972
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   973
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   974
#                            Notebook Unified Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   975
#-------------------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   976
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   977
    ## Function that add a tab in Notebook, calling refresh for tab DClick event
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   978
    # for wx.aui.AUINotebook.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   979
    #  @param window Panel to display in tab.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   980
    #  @param text title for the tab ctrl.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   981
    def AddPage(self, window, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   982
        self.TabsOpened.AddPage(window, text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   983
        self.RefreshTabCtrlEvent()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   984
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   985
    ## Function that add a tab in Notebook, calling refresh for tab DClick event
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   986
    # for wx.aui.AUINotebook.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   987
    #  @param window Panel to display in tab.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   988
    #  @param text title for the tab ctrl.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   989
    def DeletePage(self, window):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   990
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   991
            if self.TabsOpened.GetPage(idx) == window:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   992
                self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   993
                self.RefreshTabCtrlEvent()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   994
                return
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   995
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   996
    ## Function that fix difference in deleting all tabs between
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   997
    # wx.Notebook and wx.aui.AUINotebook.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   998
    def DeleteAllPages(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   999
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1000
            self.TabsOpened.DeletePage(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1001
        self.RefreshTabCtrlEvent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1002
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1003
    ## Function that fix difference in setting picture on tab between
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1004
    # wx.Notebook and wx.aui.AUINotebook.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1005
    #  @param idx Tab index.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1006
    #  @param bitmap wx.Bitmap to define on tab.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1007
    #  @return True if operation succeeded
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1008
    def SetPageBitmap(self, idx, bitmap):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1009
        return self.TabsOpened.SetPageBitmap(idx, bitmap)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1010
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1011
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1012
#                         Dialog Message Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1013
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1014
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1015
    ## Function displaying an Error dialog in PLCOpenEditor.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1016
    #  @param message The message to display.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1017
    def ShowErrorMessage(self, message):
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1018
        dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1019
        dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1020
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1021
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1022
    ## Function displaying an Error dialog in PLCOpenEditor.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1023
    #  @return False if closing cancelled.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1024
    def CheckSaveBeforeClosing(self, title=_("Close Project")):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1025
        if not self.Controler.ProjectIsSaved():
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1026
            dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), title, wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1027
            answer = dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1028
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1029
            if answer == wx.ID_YES:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1030
                self.SaveProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1031
            elif answer == wx.ID_CANCEL:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1032
                return False
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1033
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1034
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1035
            window = self.TabsOpened.GetPage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1036
            if not window.CheckSaveBeforeClosing():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1037
                return False
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1038
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1039
        return True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1040
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1041
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1042
#                            File Menu Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1043
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1044
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1045
    def RefreshFileMenu(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1046
        pass
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1047
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1048
    def ResetView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1049
        self.DeleteAllPages()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1050
        self.ProjectTree.DeleteAllItems()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1051
        self.ProjectTree.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1052
        self.PouInstanceVariablesPanel.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1053
        self.LibraryPanel.ResetTree()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1054
        self.LibraryPanel.SetController(None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1055
        if self.EnableDebug:
916
697d8b77d716 Improved matplotlib graphic debug panel implementation, adding force, release, split and delete graph buttons, replacing data grid by adding panel displaying non-numeric data between graphs
Laurent Bessard
parents: 909
diff changeset
  1056
            self.DebugVariablePanel.ResetView()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1057
        self.Controler = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1058
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1059
    def OnCloseTabMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1060
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1061
        if selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1062
            self.TabsOpened.DeletePage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1063
            if self.TabsOpened.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1064
                new_index = min(selected, self.TabsOpened.GetPageCount() - 1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1065
                self.TabsOpened.SetSelection(new_index)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1066
        # Refresh all window elements that have changed
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1067
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1068
        self.RefreshTabCtrlEvent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1069
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1070
    def OnPageSetupMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1071
        dialog = wx.PageSetupDialog(self, self.PageSetupData)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1072
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1073
            self.PageSetupData = wx.PageSetupDialogData(dialog.GetPageSetupData())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1074
            self.PrintData = wx.PrintData(self.PageSetupData.GetPrintData())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1075
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1076
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1077
    def OnPreviewMenu(self, event):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1078
        selected = self.TabsOpened.GetSelection()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1079
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1080
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1081
            data = wx.PrintDialogData(self.PrintData)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1082
            properties = self.Controler.GetProjectProperties(window.IsDebugging())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1083
            page_size = map(int, properties["pageSize"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1084
            margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1085
            printout = GraphicPrintout(window, page_size, margins, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1086
            printout2 = GraphicPrintout(window, page_size, margins, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1087
            preview = wx.PrintPreview(printout, printout2, data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1088
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1089
            if preview.Ok():
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1090
                preview_frame = wx.PreviewFrame(preview, self, _("Print preview"), style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1091
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1092
                preview_frame.Initialize()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1093
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1094
                preview_canvas = preview.GetCanvas()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1095
                preview_canvas.SetMinSize(preview_canvas.GetVirtualSize())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1096
                preview_frame.Fit()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1097
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1098
                preview_frame.Show(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1099
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1100
    def OnPrintMenu(self, event):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1101
        selected = self.TabsOpened.GetSelection()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1102
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1103
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1104
            dialog_data = wx.PrintDialogData(self.PrintData)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1105
            dialog_data.SetToPage(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1106
            properties = self.Controler.GetProjectProperties(window.IsDebugging())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1107
            page_size = map(int, properties["pageSize"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1108
            margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1109
            printer = wx.Printer(dialog_data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1110
            printout = GraphicPrintout(window, page_size, margins)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1111
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1112
            if not printer.Print(self, printout, True) and printer.GetLastError() != wx.PRINTER_CANCELLED:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1113
                self.ShowErrorMessage(_("There was a problem printing.\nPerhaps your current printer is not set correctly?"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1114
            printout.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1115
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1116
    def OnPropertiesMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1117
        self.EditProjectSettings()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1118
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1119
    def OnQuitMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1120
        self.Close()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1121
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1122
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1123
#                            Edit Menu Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1124
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1125
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1126
    def RefreshEditMenu(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1127
        MenuToolBar = self.Panes["MenuToolBar"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1128
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1129
            selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1130
            if selected > -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1131
                window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1132
                undo, redo = window.GetBufferState()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1133
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1134
                undo, redo = self.Controler.GetBufferState()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1135
            self.EditMenu.Enable(wx.ID_UNDO, undo)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1136
            MenuToolBar.EnableTool(wx.ID_UNDO, undo)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1137
            self.EditMenu.Enable(wx.ID_REDO, redo)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1138
            MenuToolBar.EnableTool(wx.ID_REDO, redo)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1139
            #self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, True)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1140
            #self.EditMenu.Check(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1141
            #                self.Controler.IsProjectBufferEnabled())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1142
            self.EditMenu.Enable(wx.ID_FIND, selected > -1)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1143
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDNEXT,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1144
                  selected > -1 and self.SearchParams is not None)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1145
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1146
                  selected > -1 and self.SearchParams is not None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1147
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1148
            MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1149
            self.EditMenu.Enable(wx.ID_ADD, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1150
            self.EditMenu.Enable(wx.ID_DELETE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1151
            if self.TabsOpened.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1152
                self.EditMenu.Enable(wx.ID_CUT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1153
                MenuToolBar.EnableTool(wx.ID_CUT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1154
                self.EditMenu.Enable(wx.ID_COPY, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1155
                MenuToolBar.EnableTool(wx.ID_COPY, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1156
                if self.GetCopyBuffer() is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1157
                    self.EditMenu.Enable(wx.ID_PASTE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1158
                    MenuToolBar.EnableTool(wx.ID_PASTE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1159
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1160
                    self.EditMenu.Enable(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1161
                    MenuToolBar.EnableTool(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1162
                self.EditMenu.Enable(wx.ID_SELECTALL, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1163
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1164
                self.EditMenu.Enable(wx.ID_CUT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1165
                MenuToolBar.EnableTool(wx.ID_CUT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1166
                self.EditMenu.Enable(wx.ID_COPY, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1167
                MenuToolBar.EnableTool(wx.ID_COPY, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1168
                self.EditMenu.Enable(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1169
                MenuToolBar.EnableTool(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1170
                self.EditMenu.Enable(wx.ID_SELECTALL, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1171
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1172
            self.EditMenu.Enable(wx.ID_UNDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1173
            MenuToolBar.EnableTool(wx.ID_UNDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1174
            self.EditMenu.Enable(wx.ID_REDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1175
            MenuToolBar.EnableTool(wx.ID_REDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1176
            #self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1177
            self.EditMenu.Enable(wx.ID_CUT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1178
            MenuToolBar.EnableTool(wx.ID_CUT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1179
            self.EditMenu.Enable(wx.ID_COPY, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1180
            MenuToolBar.EnableTool(wx.ID_COPY, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1181
            self.EditMenu.Enable(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1182
            MenuToolBar.EnableTool(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1183
            self.EditMenu.Enable(wx.ID_SELECTALL, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1184
            self.EditMenu.Enable(wx.ID_FIND, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1185
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDNEXT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1186
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDPREVIOUS, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1187
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1188
            MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1189
            self.EditMenu.Enable(wx.ID_ADD, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1190
            self.EditMenu.Enable(wx.ID_DELETE, False)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1191
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1192
    def CloseTabsWithoutModel(self, refresh=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1193
        idxs = range(self.TabsOpened.GetPageCount())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1194
        idxs.reverse()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1195
        for idx in idxs:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1196
            window = self.TabsOpened.GetPage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1197
            if window.HasNoModel():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1198
                self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1199
        if refresh:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1200
            self.RefreshEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1201
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1202
    def OnUndoMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1203
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1204
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1205
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1206
            window.Undo()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1207
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1208
            self.Controler.LoadPrevious()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1209
        self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1210
                      SCALING, PAGETITLES)
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1211
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1212
    def OnRedoMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1213
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1214
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1215
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1216
            window.Redo()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1217
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1218
            self.Controler.LoadNext()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1219
        self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1220
                      SCALING, PAGETITLES)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1221
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1222
    def OnEnableUndoRedoMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1223
        self.Controler.EnableProjectBuffer(event.IsChecked())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1224
        self.RefreshEditMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1225
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1226
    OnCutMenu = GetShortcutKeyCallbackFunction("Cut")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1227
    OnCopyMenu = GetShortcutKeyCallbackFunction("Copy")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1228
    OnPasteMenu = GetShortcutKeyCallbackFunction("Paste")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1229
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1230
    def OnSelectAllMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1231
        control = self.FindFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1232
        if control is not None and control.GetName() == "Viewer":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1233
            control.Parent.SelectAll()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1234
        elif isinstance(control, wx.stc.StyledTextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1235
            control.SelectAll()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1236
        elif isinstance(control, wx.TextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1237
            control.SetSelection(0, control.GetLastPosition())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1238
        elif isinstance(control, wx.ComboBox):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1239
            control.SetMark(0, control.GetLastPosition() + 1)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1240
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1241
    def SetDeleteFunctions(self):
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1242
        self.DeleteFunctions = {
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1243
            ITEM_DATATYPE: GetDeleteElementFunction(
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1244
                    PLCControler.ProjectRemoveDataType,
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1245
                    check_function=self.CheckDataTypeIsUsedBeforeDeletion),
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1246
            ITEM_POU: GetDeleteElementFunction(
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1247
                    PLCControler.ProjectRemovePou,
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1248
                    check_function=self.CheckPouIsUsedBeforeDeletion),
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1249
            ITEM_TRANSITION: GetDeleteElementFunction(
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1250
                    PLCControler.ProjectRemovePouTransition, ITEM_POU),
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1251
            ITEM_ACTION: GetDeleteElementFunction(
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1252
                    PLCControler.ProjectRemovePouAction, ITEM_POU),
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1253
            ITEM_CONFIGURATION: GetDeleteElementFunction(
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1254
                    PLCControler.ProjectRemoveConfiguration),
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1255
            ITEM_RESOURCE: GetDeleteElementFunction(
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1256
                    PLCControler.ProjectRemoveConfigurationResource, ITEM_CONFIGURATION)
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  1257
        }
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1258
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1259
    def OnDeleteMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1260
        window = self.FindFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1261
        if window == self.ProjectTree or window is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1262
            selected = self.ProjectTree.GetSelection()
1165
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1263
            if selected is not None and selected.IsOk():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1264
                function = self.DeleteFunctions.get(self.ProjectTree.GetPyData(selected)["type"], None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1265
                if function is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1266
                    function(self, selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1267
                    self.CloseTabsWithoutModel()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1268
                    self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1269
                                  POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1270
        elif isinstance(window, (Viewer, TextViewer)):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1271
            event = wx.KeyEvent(wx.EVT_CHAR._getEvtType())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1272
            event.m_keyCode = wx.WXK_DELETE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1273
            window.ProcessEvent(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1274
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1275
    def OnFindMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1276
        if not self.FindDialog.IsShown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1277
            self.FindDialog.Show()
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1278
            self.FindDialog.FindPattern.SetFocus()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1279
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1280
    def CloseFindInPouDialog(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1281
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1282
        if selected == -1 and self.FindDialog.IsShown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1283
            self.FindDialog.Hide()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1284
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1285
    def OnFindNextMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1286
        self.FindInPou(1)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1287
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1288
    def OnFindPreviousMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1289
        self.FindInPou(-1)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1290
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1291
    def FindInPou(self, direction, search_params=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1292
        if search_params is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1293
            self.SearchParams = search_params
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1294
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1295
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1296
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1297
            window.Find(direction, self.SearchParams)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1298
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1299
    def OnSearchInProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1300
        dialog = SearchInProjectDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1301
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1302
            criteria = dialog.GetCriteria()
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1303
            if len(criteria) > 0:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1304
                result = self.Controler.SearchInProject(criteria)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1305
                self.ClearSearchResults()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1306
                self.SearchResultPanel.SetSearchResults(criteria, result)
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1307
                self.SelectTab(self.SearchResultPanel)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1308
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1309
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1310
#                             Display Menu Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1311
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1312
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1313
    def RefreshDisplayMenu(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1314
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1315
            if self.TabsOpened.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1316
                self.DisplayMenu.Enable(wx.ID_REFRESH, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1317
                selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1318
                if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1319
                    window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1320
                    if isinstance(window, Viewer):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1321
                        self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1322
                        zoommenu = self.DisplayMenu.FindItemById(wx.ID_ZOOM_FIT).GetSubMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1323
                        zoomitem = zoommenu.FindItemByPosition(window.GetScale())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1324
                        zoomitem.Check(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1325
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1326
                        self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1327
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1328
                    self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1329
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1330
                self.DisplayMenu.Enable(wx.ID_REFRESH, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1331
                self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1332
            if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1333
                self.DisplayMenu.Enable(wx.ID_CLEAR, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1334
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1335
            self.DisplayMenu.Enable(wx.ID_REFRESH, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1336
            if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1337
                self.DisplayMenu.Enable(wx.ID_CLEAR, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1338
            self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1339
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1340
    def OnRefreshMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1341
        self.RefreshEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1342
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1343
    def OnClearErrorsMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1344
        self.ClearErrors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1345
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1346
    def GenerateZoomFunction(self, idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1347
        def ZoomFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1348
            selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1349
            if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1350
                window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1351
                window.SetScale(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1352
                window.RefreshVisibleElements()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1353
                window.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1354
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1355
        return ZoomFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1356
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1357
    def OnResetPerspective(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1358
        self.ResetPerspective()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1359
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1360
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1361
#                      Project Editor Panels Management Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1362
#-------------------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1363
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1364
    def OnPageDragged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1365
        wx.CallAfter(self.RefreshTabCtrlEvent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1366
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1367
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1368
    def OnAllowNotebookDnD(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1369
        event.Allow()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1370
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1371
    def RefreshTabCtrlEvent(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1372
        auitabctrl = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1373
        for child in self.TabsOpened.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1374
            if isinstance(child, wx.aui.AuiTabCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1375
                auitabctrl.append(child)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1376
                if child not in self.AuiTabCtrl:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1377
                    child.Bind(wx.EVT_LEFT_DCLICK, self.GetTabsOpenedDClickFunction(child))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1378
        self.AuiTabCtrl = auitabctrl
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1379
        if self.TabsOpened.GetPageCount() == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1380
            pane = self.AUIManager.GetPane(self.TabsOpened)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1381
            if pane.IsMaximized():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1382
                self.AUIManager.RestorePane(pane)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1383
            self.AUIManager.Update()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1384
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1385
    def EnsureTabVisible(self, tab):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1386
        notebook = tab.GetParent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1387
        notebook.SetSelection(notebook.GetPageIndex(tab))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1388
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1389
    def OnPouSelectedChanging(self, event):
989
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1390
        selected = self.TabsOpened.GetSelection()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1391
        if selected >= 0:
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1392
            window = self.TabsOpened.GetPage(selected)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1393
            if not window.IsDebugging():
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1394
                window.ResetBuffer()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1395
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1396
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1397
    def OnPouSelectedChanged(self, event):
989
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1398
        selected = self.TabsOpened.GetSelection()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1399
        if selected >= 0:
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1400
            window = self.TabsOpened.GetPage(selected)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1401
            tagname = window.GetTagName()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1402
            if not window.IsDebugging():
1158
193e6cd9010f Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents: 1129
diff changeset
  1403
                self.SelectProjectTreeItem(tagname)
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
  1404
                self.PouInstanceVariablesPanel.SetPouType(tagname)
989
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1405
                window.RefreshView()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1406
                self.EnsureTabVisible(self.LibraryPanel)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1407
            else:
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1408
                instance_path = window.GetInstancePath()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1409
                if tagname == "":
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1410
                    instance_path = instance_path.rsplit(".", 1)[0]
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1411
                    tagname = self.Controler.GetPouInstanceTagName(instance_path, self.EnableDebug)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1412
                self.EnsureTabVisible(self.DebugVariablePanel)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1413
                wx.CallAfter(self.PouInstanceVariablesPanel.SetPouType, tagname, instance_path)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1414
        wx.CallAfter(self._Refresh, FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1415
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1416
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1417
    def RefreshEditor(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1418
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1419
        if selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1420
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1421
            tagname = window.GetTagName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1422
            if not window.IsDebugging():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1423
                self.SelectProjectTreeItem(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1424
                self.PouInstanceVariablesPanel.SetPouType(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1425
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1426
                instance_path = window.GetInstancePath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1427
                if tagname == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1428
                    instance_path = instance_path.rsplit(".", 1)[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1429
                    tagname = self.Controler.GetPouInstanceTagName(instance_path, self.EnableDebug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1430
                self.PouInstanceVariablesPanel.SetPouType(tagname, instance_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1431
            for child in self.TabsOpened.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1432
                if isinstance(child, wx.aui.AuiTabCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1433
                    active_page = child.GetActivePage()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1434
                    if active_page >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1435
                        window = child.GetWindowFromIdx(active_page)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1436
                        window.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1437
            self._Refresh(FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1438
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1439
    def RefreshEditorNames(self, old_tagname, new_tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1440
        for i in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1441
            editor = self.TabsOpened.GetPage(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1442
            if editor.GetTagName() == old_tagname:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1443
                editor.SetTagName(new_tagname)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1444
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1445
    def IsOpened(self, tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1446
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1447
            if self.TabsOpened.GetPage(idx).IsViewing(tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1448
                return idx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1449
        return None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1450
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1451
    def RefreshPageTitles(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1452
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1453
            window = self.TabsOpened.GetPage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1454
            icon = window.GetIcon()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1455
            if icon is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1456
                self.SetPageBitmap(idx, icon)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1457
            self.TabsOpened.SetPageText(idx, window.GetTitle())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1458
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1459
    def GetTabsOpenedDClickFunction(self, tabctrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1460
        def OnTabsOpenedDClick(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1461
            pos = event.GetPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1462
            if tabctrl.TabHitTest(pos.x, pos.y, None):
1530
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1463
                self.SwitchFullScrMode(event)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1464
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1465
        return OnTabsOpenedDClick
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1466
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
  1467
    def SwitchFullScrMode(self, evt):
1530
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1468
        pane = self.AUIManager.GetPane(self.TabsOpened)
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1469
        if pane.IsMaximized():
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1470
            self.AUIManager.RestorePane(pane)
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1471
        else:
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1472
            self.AUIManager.MaximizePane(pane)
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1473
        self.AUIManager.Update()
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1474
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1475
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1476
#                         Types Tree Management Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1477
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1478
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1479
    def RefreshProjectTree(self):
1105
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1480
        # Extract current selected item tagname
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1481
        selected = self.ProjectTree.GetSelection()
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1482
        if selected is not None and selected.IsOk():
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1483
            item_infos = self.ProjectTree.GetPyData(selected)
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1484
            tagname = item_infos.get("tagname", None)
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1485
        else:
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1486
            tagname = None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1487
1105
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1488
        # Refresh treectrl items according to project infos
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1489
        infos = self.Controler.GetProjectInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1490
        root = self.ProjectTree.GetRootItem()
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1491
        if root is None or not root.IsOk():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1492
            root = self.ProjectTree.AddRoot(infos["name"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1493
        self.GenerateProjectTreeBranch(root, infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1494
        self.ProjectTree.Expand(root)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1495
1105
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1496
        # Select new item corresponding to previous selected item
f0e5b475a074 Fixed bug when modifying ConfTreeNode IEC Channel
Laurent Bessard
parents: 1089
diff changeset
  1497
        if tagname is not None:
1158
193e6cd9010f Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents: 1129
diff changeset
  1498
            self.SelectProjectTreeItem(tagname)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1499
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1500
    def GenerateProjectTreeBranch(self, root, infos, item_alone=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1501
        to_delete = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1502
        item_name = infos["name"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1503
        if infos["type"] in ITEMS_UNEDITABLE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1504
            if len(infos["values"]) == 1:
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1505
                return self.GenerateProjectTreeBranch(root, infos["values"][0], True)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1506
            item_name = _(item_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1507
        self.ProjectTree.SetItemText(root, item_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1508
        self.ProjectTree.SetPyData(root, infos)
1635
25e3bf6e193d change white background for project tree element to transparent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1610
diff changeset
  1509
        highlight_colours = self.Highlights.get(infos.get("tagname", None), (wx.Colour(255, 255, 255, 0), wx.BLACK))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1510
        self.ProjectTree.SetItemTextColour(root, highlight_colours[1])
1188
63afb5833bd8 Fixed bug two icons displayed for POU category item in Project Tree when adding a second POU
Laurent Bessard
parents: 1176
diff changeset
  1511
        self.ProjectTree.SetItemExtraImage(root, None)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1512
        if infos["type"] == ITEM_POU:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1513
            self.ProjectTree.SetItemImage(root,
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1514
                self.TreeImageDict[self.Controler.GetPouBodyType(infos["name"])])
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1515
            if item_alone:
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1516
                self.ProjectTree.SetItemExtraImage(root, self.Controler.GetPouType(infos["name"]))
1763
bcc07ff2362c clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
  1517
        elif "icon" in infos and infos["icon"] is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1518
            icon_name = infos["icon"]
1763
bcc07ff2362c clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
  1519
            if not icon_name in self.TreeImageDict:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1520
                self.TreeImageDict[icon_name] = self.TreeImageList.Add(GetBitmap(icon_name))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1521
            self.ProjectTree.SetItemImage(root, self.TreeImageDict[icon_name])
1763
bcc07ff2362c clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
  1522
        elif infos["type"] in self.TreeImageDict:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1523
            self.ProjectTree.SetItemImage(root, self.TreeImageDict[infos["type"]])
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1524
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1525
        item, root_cookie = self.ProjectTree.GetFirstChild(root)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1526
        for values in infos["values"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1527
            if values["type"] not in ITEMS_UNEDITABLE or len(values["values"]) > 0:
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1528
                if item is None or not item.IsOk():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1529
                    item = self.ProjectTree.AppendItem(root, "")
1165
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1530
                    item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1531
                self.GenerateProjectTreeBranch(item, values)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1532
                item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1533
        while item is not None and item.IsOk():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1534
            to_delete.append(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1535
            item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1536
        for item in to_delete:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1537
            self.ProjectTree.Delete(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1538
1165
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1539
    TagNamePartsItemTypes = {
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1540
        "D": [ITEM_DATATYPE],
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1541
        "P": [ITEM_POU],
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1542
        "T": [ITEM_POU, ITEM_TRANSITION],
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1543
        "A": [ITEM_POU, ITEM_ACTION],
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1544
        "C": [ITEM_CONFIGURATION],
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1545
        "R": [ITEM_CONFIGURATION, ITEM_RESOURCE]}
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1546
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1547
    def SelectProjectTreeItem(self, tagname):
1158
193e6cd9010f Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents: 1129
diff changeset
  1548
        result = False
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1549
        if self.ProjectTree is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1550
            root = self.ProjectTree.GetRootItem()
1165
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1551
            if root is not None and root.IsOk():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1552
                words = tagname.split("::")
1165
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1553
                result = self.RecursiveProjectTreeItemSelection(root,
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1554
                    zip(words[1:], self.TagNamePartsItemTypes.get(words[0], [])))
1158
193e6cd9010f Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents: 1129
diff changeset
  1555
        return result
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1556
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1557
    def RecursiveProjectTreeItemSelection(self, root, items):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1558
        found = False
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1559
        item, root_cookie = self.ProjectTree.GetFirstChild(root)
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1560
        while item is not None and item.IsOk() and not found:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1561
            item_infos = self.ProjectTree.GetPyData(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1562
            if (item_infos["name"].split(":")[-1].strip(), item_infos["type"]) == items[0]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1563
                if len(items) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1564
                    self.SelectedItem = item
1158
193e6cd9010f Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents: 1129
diff changeset
  1565
                    self.ProjectTree.SelectItem(item)
193e6cd9010f Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents: 1129
diff changeset
  1566
                    self.ResetSelectedItem()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1567
                    return True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1568
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1569
                    found = self.RecursiveProjectTreeItemSelection(item, items[1:])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1570
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1571
                found = self.RecursiveProjectTreeItemSelection(item, items)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1572
            item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1573
        return found
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1574
1243
e77c95c4c7fc Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents: 1240
diff changeset
  1575
    def ResetSelectedItem(self):
e77c95c4c7fc Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents: 1240
diff changeset
  1576
        self.SelectedItem = None
e77c95c4c7fc Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents: 1240
diff changeset
  1577
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1578
    def OnProjectTreeBeginDrag(self, event):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1579
        selected_item = (self.SelectedItem
1243
e77c95c4c7fc Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents: 1240
diff changeset
  1580
                         if self.SelectedItem is not None
e77c95c4c7fc Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents: 1240
diff changeset
  1581
                         else event.GetItem())
e77c95c4c7fc Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents: 1240
diff changeset
  1582
        if selected_item.IsOk() and self.ProjectTree.GetPyData(selected_item)["type"] == ITEM_POU:
e77c95c4c7fc Fixed bug when drag'n dropping POU from project tree and POU is selected
Laurent Bessard
parents: 1240
diff changeset
  1583
            block_name = self.ProjectTree.GetItemText(selected_item)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1584
            block_type = self.Controler.GetPouType(block_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1585
            if block_type != "program":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1586
                data = wx.TextDataObject(str((block_name, block_type, "")))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1587
                dragSource = wx.DropSource(self.ProjectTree)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1588
                dragSource.SetData(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1589
                dragSource.DoDragDrop()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1590
            self.ResetSelectedItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1591
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1592
    def OnProjectTreeItemBeginEdit(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1593
        selected = event.GetItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1594
        if self.ProjectTree.GetPyData(selected)["type"] in ITEMS_UNEDITABLE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1595
            event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1596
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1597
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1598
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1599
    def OnProjectTreeItemEndEdit(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1600
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1601
        abort = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1602
        new_name = event.GetLabel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1603
        if new_name != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1604
            if not TestIdentifier(new_name):
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1605
                message = _("\"%s\" is not a valid identifier!") % new_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1606
            elif new_name.upper() in IEC_KEYWORDS:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1607
                message = _("\"%s\" is a keyword. It can't be used!") % new_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1608
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1609
                item = event.GetItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1610
                old_name = self.ProjectTree.GetItemText(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1611
                item_infos = self.ProjectTree.GetPyData(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1612
                if item_infos["type"] == ITEM_PROJECT:
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1613
                    self.Controler.SetProjectProperties(name=new_name)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1614
                elif item_infos["type"] == ITEM_DATATYPE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1615
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectDataTypeNames() if name != old_name]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1616
                        message = _("\"%s\" data type already exists!") % new_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1617
                        abort = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1618
                    if not abort:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1619
                        self.Controler.ChangeDataTypeName(old_name, new_name)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1620
                        self.RefreshEditorNames(self.Controler.ComputeDataTypeName(old_name),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1621
                                                self.Controler.ComputeDataTypeName(new_name))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1622
                        self.RefreshPageTitles()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1623
                elif item_infos["type"] == ITEM_POU:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1624
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames() if name != old_name]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1625
                        message = _("\"%s\" pou already exists!") % new_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1626
                        abort = True
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1167
diff changeset
  1627
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames()]:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1628
                        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)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1629
                        if messageDialog.ShowModal() == wx.ID_NO:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1630
                            abort = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1631
                        messageDialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1632
                    if not abort:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1633
                        self.Controler.ChangePouName(old_name, new_name)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1634
                        self.RefreshEditorNames(self.Controler.ComputePouName(old_name),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1635
                                                self.Controler.ComputePouName(new_name))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1636
                        self.RefreshLibraryPanel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1637
                        self.RefreshPageTitles()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1638
                elif item_infos["type"] == ITEM_TRANSITION:
1610
31703a04789a fix problem with SFC action/transition rename
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1556
diff changeset
  1639
                    pou_item = self.ProjectTree.GetItemParent(event.GetItem())
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1710
diff changeset
  1640
                    pou_name = self.ProjectTree.GetItemText(pou_item)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1641
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1642
                        message = _("A POU named \"%s\" already exists!") % new_name
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1167
diff changeset
  1643
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames(pou_name) if name != old_name]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1644
                        message = _("A variable with \"%s\" as name already exists in this pou!") % new_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1645
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1646
                        words = item_infos["tagname"].split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1647
                        self.Controler.ChangePouTransitionName(words[1], old_name, new_name)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1648
                        self.RefreshEditorNames(self.Controler.ComputePouTransitionName(words[1], old_name),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1649
                                                self.Controler.ComputePouTransitionName(words[1], new_name))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1650
                        self.RefreshPageTitles()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1651
                elif item_infos["type"] == ITEM_ACTION:
1610
31703a04789a fix problem with SFC action/transition rename
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1556
diff changeset
  1652
                    pou_item = self.ProjectTree.GetItemParent(event.GetItem())
31703a04789a fix problem with SFC action/transition rename
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1556
diff changeset
  1653
                    pou_name = self.ProjectTree.GetItemText(pou_item)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1654
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1655
                        message = _("A POU named \"%s\" already exists!") % new_name
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1167
diff changeset
  1656
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames(pou_name) if name != old_name]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1657
                        message = _("A variable with \"%s\" as name already exists in this pou!") % new_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1658
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1659
                        words = item_infos["tagname"].split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1660
                        self.Controler.ChangePouActionName(words[1], old_name, new_name)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1661
                        self.RefreshEditorNames(self.Controler.ComputePouActionName(words[1], old_name),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1662
                                                self.Controler.ComputePouActionName(words[1], new_name))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1663
                        self.RefreshPageTitles()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1664
                elif item_infos["type"] == ITEM_CONFIGURATION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1665
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames() if name != old_name]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1666
                        message = _("\"%s\" config already exists!") % new_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1667
                        abort = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1668
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1669
                        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)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1670
                        if messageDialog.ShowModal() == wx.ID_NO:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1671
                            abort = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1672
                        messageDialog.Destroy()
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1167
diff changeset
  1673
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames()]:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1674
                        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)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1675
                        if messageDialog.ShowModal() == wx.ID_NO:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1676
                            abort = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1677
                        messageDialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1678
                    if not abort:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1679
                        self.Controler.ChangeConfigurationName(old_name, new_name)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1680
                        self.RefreshEditorNames(self.Controler.ComputeConfigurationName(old_name),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1681
                                                self.Controler.ComputeConfigurationName(new_name))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1682
                        self.RefreshPageTitles()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1683
                elif item_infos["type"] == ITEM_RESOURCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1684
                    if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames()]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1733
diff changeset
  1685
                        message = _("\"%s\" config already exists!") % new_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1686
                        abort = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1687
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1688
                        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)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1689
                        if messageDialog.ShowModal() == wx.ID_NO:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1690
                            abort = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1691
                        messageDialog.Destroy()
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1167
diff changeset
  1692
                    elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariableNames()]:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1693
                        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)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1694
                        if messageDialog.ShowModal() == wx.ID_NO:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1695
                            abort = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1696
                        messageDialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1697
                    if not abort:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1698
                        words = item_infos["tagname"].split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1699
                        self.Controler.ChangeConfigurationResourceName(words[1], old_name, new_name)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1700
                        self.RefreshEditorNames(self.Controler.ComputeConfigurationResourceName(words[1], old_name),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1701
                                                self.Controler.ComputeConfigurationResourceName(words[1], new_name))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1702
                        self.RefreshPageTitles()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1703
            if message or abort:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1704
                if message:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1705
                    self.ShowErrorMessage(message)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1706
                event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1707
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1708
                wx.CallAfter(self.RefreshProjectTree)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1709
                self.RefreshEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1710
                self._Refresh(TITLE, FILEMENU, EDITMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1711
                event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1712
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1713
    def OnProjectTreeItemActivated(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1714
        selected = event.GetItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1715
        name = self.ProjectTree.GetItemText(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1716
        item_infos = self.ProjectTree.GetPyData(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1717
        if item_infos["type"] == ITEM_PROJECT:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1718
            self.EditProjectSettings()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1719
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1720
            if item_infos["type"] in [ITEM_DATATYPE, ITEM_POU,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1721
                                    ITEM_CONFIGURATION, ITEM_RESOURCE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1722
                                    ITEM_TRANSITION, ITEM_ACTION]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1723
                self.EditProjectElement(item_infos["type"], item_infos["tagname"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1724
            event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1725
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1726
    def ProjectTreeItemSelect(self, select_item):
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1727
        if select_item is not None and select_item.IsOk():
1112
ff3fcad17b47 Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents: 1106
diff changeset
  1728
            name = self.ProjectTree.GetItemText(select_item)
ff3fcad17b47 Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents: 1106
diff changeset
  1729
            item_infos = self.ProjectTree.GetPyData(select_item)
ff3fcad17b47 Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents: 1106
diff changeset
  1730
            if item_infos["type"] in [ITEM_DATATYPE, ITEM_POU,
ff3fcad17b47 Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents: 1106
diff changeset
  1731
                                      ITEM_CONFIGURATION, ITEM_RESOURCE,
ff3fcad17b47 Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents: 1106
diff changeset
  1732
                                      ITEM_TRANSITION, ITEM_ACTION]:
ff3fcad17b47 Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents: 1106
diff changeset
  1733
                self.EditProjectElement(item_infos["type"], item_infos["tagname"], True)
ff3fcad17b47 Fixed bug when selecting item in ProjectTree on Linux
Laurent Bessard
parents: 1106
diff changeset
  1734
                self.PouInstanceVariablesPanel.SetPouType(item_infos["tagname"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1735
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1736
    def OnProjectTreeLeftUp(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1737
        if self.SelectedItem is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1738
            self.ProjectTree.SelectItem(self.SelectedItem)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1739
            self.ProjectTreeItemSelect(self.SelectedItem)
1240
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1233
diff changeset
  1740
            self.ResetSelectedItem()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1741
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1742
1106
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1743
    def OnProjectTreeMotion(self, event):
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1744
        if not event.Dragging():
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1745
            pt = wx.Point(event.GetX(), event.GetY())
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1746
            item, flags = self.ProjectTree.HitTest(pt)
1164
8fd44bc05aae Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents: 1159
diff changeset
  1747
            if item is not None and item.IsOk() and flags & wx.TREE_HITTEST_ONITEMLABEL:
1106
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1748
                item_infos = self.ProjectTree.GetPyData(item)
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1749
                if item != self.LastToolTipItem and self.LastToolTipItem is not None:
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1750
                    self.ProjectTree.SetToolTip(None)
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1751
                    self.LastToolTipItem = None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1752
                if (self.LastToolTipItem != item and
1106
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1753
                    item_infos["type"] in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]):
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1754
                    bodytype = self.Controler.GetEditedElementBodyType(
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1755
                            item_infos["tagname"])
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1756
                    if item_infos["type"] == ITEM_POU:
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1757
                        block_type = {
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1758
                            "program": _("Program"),
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1759
                            "functionBlock": _("Function Block"),
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1760
                            "function": _("Function")
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1761
                        }[self.Controler.GetPouType(item_infos["name"])]
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1762
                    elif item_infos["type"] == ITEM_TRANSITION:
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1763
                        block_type = "Transition"
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1764
                    else:
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1765
                        block_type = "Action"
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1766
                    self.LastToolTipItem = item
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1767
                    wx.CallAfter(self.ProjectTree.SetToolTipString,
1106
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1768
                        "%s : %s : %s" % (
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1769
                            block_type, bodytype, item_infos["name"]))
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1770
            elif self.LastToolTipItem is not None:
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1771
                self.ProjectTree.SetToolTip(None)
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1772
                self.LastToolTipItem = None
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
  1773
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1774
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1775
    def OnProjectTreeItemChanging(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1776
        if self.ProjectTree.GetPyData(event.GetItem())["type"] not in ITEMS_UNEDITABLE and self.SelectedItem is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1777
            self.SelectedItem = event.GetItem()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1778
            event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1779
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1780
            event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1781
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1782
    def EditProjectElement(self, element, tagname, onlyopened=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1783
        openedidx = self.IsOpened(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1784
        if openedidx is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1785
            old_selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1786
            if old_selected != openedidx:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1787
                if old_selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1788
                    self.TabsOpened.GetPage(old_selected).ResetBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1789
                self.TabsOpened.SetSelection(openedidx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1790
            self._Refresh(FILEMENU, EDITMENU, EDITORTOOLBAR, PAGETITLES)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1791
        elif not onlyopened:
870
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1792
            if isinstance(element, EditorPanel):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1793
                new_window = element
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1794
                self.AddPage(element, "")
870
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1795
            elif self.Controler.GetEditedElement(tagname) is not None:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1796
                new_window = None
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1797
                if element == ITEM_CONFIGURATION:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1798
                    new_window = ConfigurationEditor(self.TabsOpened, tagname, self, self.Controler)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1799
                    new_window.SetIcon(GetBitmap("CONFIGURATION"))
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1800
                    self.AddPage(new_window, "")
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1801
                elif element == ITEM_RESOURCE:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1802
                    new_window = ResourceEditor(self.TabsOpened, tagname, self, self.Controler)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1803
                    new_window.SetIcon(GetBitmap("RESOURCE"))
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1804
                    self.AddPage(new_window, "")
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1805
                elif element in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1806
                    bodytype = self.Controler.GetEditedElementBodyType(tagname)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1807
                    if bodytype == "FBD":
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1808
                        new_window = Viewer(self.TabsOpened, tagname, self, self.Controler)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1809
                        new_window.RefreshScaling(False)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1810
                    elif bodytype == "LD":
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1811
                        new_window = LD_Viewer(self.TabsOpened, tagname, self, self.Controler)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1812
                        new_window.RefreshScaling(False)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1813
                    elif bodytype == "SFC":
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1814
                        new_window = SFC_Viewer(self.TabsOpened, tagname, self, self.Controler)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1815
                        new_window.RefreshScaling(False)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1816
                    else:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1817
                        new_window = TextViewer(self.TabsOpened, tagname, self, self.Controler)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1818
                        new_window.SetTextSyntax(bodytype)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1819
                        if bodytype == "IL":
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1820
                            new_window.SetKeywords(IL_KEYWORDS)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1821
                        else:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1822
                            new_window.SetKeywords(ST_KEYWORDS)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1823
                    if element == ITEM_POU:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1824
                        pou_type = self.Controler.GetEditedElementType(tagname)[1].upper()
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1825
                        icon = GetBitmap(pou_type, bodytype)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1826
                    elif element == ITEM_TRANSITION:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1827
                        icon = GetBitmap("TRANSITION", bodytype)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1828
                    elif element == ITEM_ACTION:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1829
                        icon = GetBitmap("ACTION", bodytype)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1830
                    new_window.SetIcon(icon)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1831
                    self.AddPage(new_window, "")
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1832
                elif element == ITEM_DATATYPE:
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1833
                    new_window = DataTypeEditor(self.TabsOpened, tagname, self, self.Controler)
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1834
                    new_window.SetIcon(GetBitmap("DATATYPE"))
61b32521442e Fix bug in RestoreLayout when previously opened tab no more exist in project
Laurent Bessard
parents: 849
diff changeset
  1835
                    self.AddPage(new_window, "")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1836
            if new_window is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1837
                openedidx = self.IsOpened(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1838
                old_selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1839
                if old_selected != openedidx:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1840
                    if old_selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1841
                        self.TabsOpened.GetPage(old_selected).ResetBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1842
                for i in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1843
                    window = self.TabsOpened.GetPage(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1844
                    if window == new_window:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1845
                        self.TabsOpened.SetSelection(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1846
                        window.SetFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1847
                self.RefreshPageTitles()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1848
            return new_window
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1849
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1850
    def OnProjectTreeRightUp(self, event):
1240
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1233
diff changeset
  1851
        item = event.GetItem()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1852
        self.ProjectTree.SelectItem(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1853
        self.ProjectTreeItemSelect(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1854
        name = self.ProjectTree.GetItemText(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1855
        item_infos = self.ProjectTree.GetPyData(item)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1856
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1857
        menu = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1858
        if item_infos["type"] in ITEMS_UNEDITABLE + [ITEM_PROJECT]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1859
            if item_infos["type"] == ITEM_PROJECT:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1860
                name = "Project"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1861
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1862
                name = UNEDITABLE_NAMES_DICT[name]
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1863
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1864
            if name == "Data Types":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1865
                menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1866
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1867
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add DataType"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1868
                self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1869
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1870
            elif name in ["Functions", "Function Blocks", "Programs", "Project"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1871
                menu = wx.Menu(title='')
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1872
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1873
                if name != "Project":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1874
                    new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1875
                    AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add POU"))
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
  1876
                    self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction({"Functions": "function", "Function Blocks": "functionBlock", "Programs": "program"}[name]), id=new_id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1877
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1878
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1879
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Paste POU"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1880
                self.Bind(wx.EVT_MENU, self.OnPastePou, id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1881
                if self.GetCopyBuffer() is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1882
                    menu.Enable(new_id, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1883
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1884
            elif name == "Configurations":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1885
                menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1886
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1887
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Configuration"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1888
                self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1889
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1890
            elif name == "Transitions":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1891
                menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1892
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1893
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Transition"))
1010
44c3cafef436 Fixed typo in IDEFrame OnProjectTreeRightUp method
Laurent Bessard
parents: 999
diff changeset
  1894
                parent = self.ProjectTree.GetItemParent(item)
44c3cafef436 Fixed typo in IDEFrame OnProjectTreeRightUp method
Laurent Bessard
parents: 999
diff changeset
  1895
                parent_type = self.ProjectTree.GetPyData(parent)["type"]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1896
                while parent_type != ITEM_POU:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1897
                    parent = self.ProjectTree.GetItemParent(parent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1898
                    parent_type = self.ProjectTree.GetPyData(parent)["type"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1899
                self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(self.ProjectTree.GetItemText(parent)), id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1900
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1901
            elif name == "Actions":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1902
                menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1903
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1904
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Action"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1905
                parent = self.ProjectTree.GetItemParent(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1906
                parent_type = self.ProjectTree.GetPyData(parent)["type"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1907
                while parent_type != ITEM_POU:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1908
                    parent = self.ProjectTree.GetItemParent(parent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1909
                    parent_type = self.ProjectTree.GetPyData(parent)["type"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1910
                self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(self.ProjectTree.GetItemText(parent)), id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1911
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1912
            elif name == "Resources":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1913
                menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1914
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1915
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Resource"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1916
                parent = self.ProjectTree.GetItemParent(item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1917
                parent_type = self.ProjectTree.GetPyData(parent)["type"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1918
                while parent_type not in [ITEM_CONFIGURATION, ITEM_PROJECT]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1919
                    parent = self.ProjectTree.GetItemParent(parent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1920
                    parent_type = self.ProjectTree.GetPyData(parent)["type"]
1024
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1921
                parent_name = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1922
                if parent_type == ITEM_PROJECT:
1024
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1923
                    config_names = self.Controler.GetProjectConfigNames()
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1924
                    if len(config_names) > 0:
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1925
                        parent_name = config_names[0]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1926
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1927
                    parent_name = self.ProjectTree.GetItemText(parent)
1024
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1928
                if parent_name is not None:
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1929
                    self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(parent_name), id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1930
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1931
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1932
            if item_infos["type"] == ITEM_POU:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1933
                menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1934
                if self.Controler.GetPouBodyType(name) == "SFC":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1935
                    new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1936
                    AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Transition"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1937
                    self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(name), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1938
                    new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1939
                    AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Action"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1940
                    self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(name), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1941
                    menu.AppendSeparator()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1942
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1943
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1944
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Copy POU"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1945
                self.Bind(wx.EVT_MENU, self.OnCopyPou, id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1946
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1947
                pou_type = self.Controler.GetPouType(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1948
                if pou_type in ["function", "functionBlock"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1949
                    change_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1950
                    if pou_type == "function":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1951
                        new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1952
                        AppendMenu(change_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Function Block"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1953
                        self.Bind(wx.EVT_MENU, self.GenerateChangePouTypeFunction(name, "functionBlock"), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1954
                    new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1955
                    AppendMenu(change_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Program"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1956
                    self.Bind(wx.EVT_MENU, self.GenerateChangePouTypeFunction(name, "program"), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1957
                    menu.AppendMenu(wx.NewId(), _("Change POU Type To"), change_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1958
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1959
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Rename"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1960
                self.Bind(wx.EVT_MENU, self.OnRenamePouMenu, id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1961
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1962
            elif item_infos["type"] == ITEM_CONFIGURATION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1963
                menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1964
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1965
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add Resource"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1966
                self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(name), id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1967
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1968
            elif item_infos["type"] in [ITEM_DATATYPE, ITEM_TRANSITION, ITEM_ACTION, ITEM_RESOURCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1969
                menu = wx.Menu(title='')
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1970
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1971
            if menu is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1972
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1973
                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Delete"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1974
                self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1975
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1976
        if menu is not None:
1480
79e54c5dead5 fix issue, then it wasn't possible to remove functional blocks from
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1408
diff changeset
  1977
            self.FindFocus().PopupMenu(menu)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1978
            menu.Destroy()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1979
1240
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1233
diff changeset
  1980
        self.ResetSelectedItem()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1981
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1982
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1983
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1984
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1985
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1986
#                         Instances Tree Management Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1987
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1988
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1989
    def GetTreeImage(self, var_class):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1990
        return self.TreeImageDict[var_class]
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1991
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1992
    def RefreshPouInstanceVariablesPanel(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1993
        self.PouInstanceVariablesPanel.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1994
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1995
    def OpenDebugViewer(self, instance_category, instance_path, instance_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1996
        openedidx = self.IsOpened(instance_path)
930
4be515ac635e Improved matplotlib graphic debug panel implementation
Laurent Bessard
parents: 916
diff changeset
  1997
        new_window = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1998
        if openedidx is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1999
            old_selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2000
            if old_selected != openedidx:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2001
                if old_selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2002
                    self.TabsOpened.GetPage(old_selected).ResetBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2003
                self.TabsOpened.SetSelection(openedidx)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2004
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2005
        elif instance_category in ITEMS_VARIABLE:
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 885
diff changeset
  2006
            if self.Controler.IsNumType(instance_type, True):
1364
e9e17d3b2849 Remove old debug panels and viewers not using matplotlib
Laurent Bessard
parents: 1362
diff changeset
  2007
                self.AddDebugVariable(instance_path, True)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2008
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2009
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2010
            bodytype = self.Controler.GetEditedElementBodyType(instance_type, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2011
            if bodytype == "FBD":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2012
                new_window = Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2013
                new_window.RefreshScaling(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2014
            elif bodytype == "LD":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2015
                new_window = LD_Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2016
                new_window.RefreshScaling(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2017
            elif bodytype == "SFC":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2018
                new_window = SFC_Viewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2019
                new_window.RefreshScaling(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2020
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2021
                new_window = TextViewer(self.TabsOpened, instance_type, self, self.Controler, True, instance_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2022
                new_window.SetTextSyntax(bodytype)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2023
                if bodytype == "IL":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2024
                    new_window.SetKeywords(IL_KEYWORDS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2025
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2026
                    new_window.SetKeywords(ST_KEYWORDS)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2027
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2028
            if new_window is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2029
                if instance_category in [ITEM_FUNCTIONBLOCK, ITEM_PROGRAM]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2030
                    pou_type = self.Controler.GetEditedElementType(instance_type, True)[1].upper()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2031
                    icon = GetBitmap(pou_type, bodytype)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2032
                elif instance_category == ITEM_TRANSITION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2033
                    icon = GetBitmap("TRANSITION", bodytype)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2034
                elif instance_category == ITEM_ACTION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2035
                    icon = GetBitmap("ACTION", bodytype)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2036
885
fc91d3718b74 Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents: 870
diff changeset
  2037
        if new_window is not None:
fc91d3718b74 Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents: 870
diff changeset
  2038
            new_window.SetIcon(icon)
fc91d3718b74 Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents: 870
diff changeset
  2039
            self.AddPage(new_window, "")
fc91d3718b74 Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents: 870
diff changeset
  2040
            new_window.RefreshView()
fc91d3718b74 Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents: 870
diff changeset
  2041
            new_window.SetFocus()
fc91d3718b74 Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents: 870
diff changeset
  2042
            self.RefreshPageTitles()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2043
        return new_window
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2044
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2045
    def ResetGraphicViewers(self):
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 885
diff changeset
  2046
        if self.EnableDebug:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 885
diff changeset
  2047
            self.DebugVariablePanel.ResetGraphicsValues()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2048
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2049
    def CloseObsoleteDebugTabs(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2050
        if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2051
            idxs = range(self.TabsOpened.GetPageCount())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2052
            idxs.reverse()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2053
            for idx in idxs:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2054
                editor = self.TabsOpened.GetPage(idx)
1364
e9e17d3b2849 Remove old debug panels and viewers not using matplotlib
Laurent Bessard
parents: 1362
diff changeset
  2055
                if isinstance(editor, Viewer) and editor.IsDebugging():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2056
                    instance_infos = self.Controler.GetInstanceInfos(editor.GetInstancePath(), self.EnableDebug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2057
                    if instance_infos is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2058
                        self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2059
                    else:
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1171
diff changeset
  2060
                        editor.SubscribeAllDataConsumers()
1710
953ceea2573e fix bug with TextViewer instance in debug mode, appears after transferring new program on PLC
Surkov Sergey <surkovsv93@gmail.com>
parents: 1708
diff changeset
  2061
                elif editor.IsDebugging() and hasattr(editor, 'SubscribeAllDataConsumers'):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1171
diff changeset
  2062
                    editor.SubscribeAllDataConsumers()
1207
fb9799a0c0f7 Rewrite DebugVariableTablePanel
Laurent Bessard
parents: 1202
diff changeset
  2063
            self.DebugVariablePanel.SubscribeAllDataConsumers()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2064
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1207
diff changeset
  2065
    def AddDebugVariable(self, iec_path, force=False, graph=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2066
        if self.EnableDebug:
1214
2ef048b5383c Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents: 1207
diff changeset
  2067
            self.DebugVariablePanel.InsertValue(iec_path, force=force, graph=graph)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2068
            self.EnsureTabVisible(self.DebugVariablePanel)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2069
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2070
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2071
#                         Library Panel Management Function
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2072
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2073
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2074
    def RefreshLibraryPanel(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2075
        self.LibraryPanel.RefreshTree()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2076
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2077
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2078
#                          ToolBars Management Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2079
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2080
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2081
    def AddToMenuToolBar(self, items):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2082
        MenuToolBar = self.Panes["MenuToolBar"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2083
        if MenuToolBar.GetToolsCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2084
            MenuToolBar.AddSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2085
        for toolbar_item in items:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2086
            if toolbar_item is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2087
                MenuToolBar.AddSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2088
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2089
                id, bitmap, help, callback = toolbar_item
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2090
                MenuToolBar.AddSimpleTool(id=id, shortHelpString=help, bitmap=GetBitmap(bitmap))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2091
                if callback is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2092
                    self.Bind(wx.EVT_TOOL, callback, id=id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2093
        MenuToolBar.Realize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2094
        self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2095
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2096
    def ResetEditorToolBar(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2097
        EditorToolBar = self.Panes["EditorToolBar"]
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2098
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2099
        for item in self.CurrentEditorToolBar:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2100
            if wx.VERSION >= (2, 6, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2101
                self.Unbind(wx.EVT_MENU, id=item)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2102
            else:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2103
                self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED)
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2104
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2105
            if EditorToolBar:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2106
                EditorToolBar.DeleteTool(item)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2107
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2108
        if EditorToolBar:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2109
            EditorToolBar.Realize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2110
            self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2111
            self.AUIManager.GetPane("EditorToolBar").Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2112
            self.AUIManager.Update()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2113
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2114
    def RefreshEditorToolBar(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2115
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2116
        menu = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2117
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2118
            window = self.TabsOpened.GetPage(selected)
1364
e9e17d3b2849 Remove old debug panels and viewers not using matplotlib
Laurent Bessard
parents: 1362
diff changeset
  2119
            if isinstance(window, (Viewer, TextViewer)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2120
                if not window.IsDebugging():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2121
                    menu = self.Controler.GetEditedElementBodyType(window.GetTagName())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2122
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2123
                    menu = "debug"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2124
        if menu is not None and menu != self.CurrentMenu:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2125
            self.ResetEditorToolBar()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2126
            self.CurrentMenu = menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2127
            self.CurrentEditorToolBar = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2128
            EditorToolBar = self.Panes["EditorToolBar"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2129
            if EditorToolBar:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2130
                for radio, modes, id, method, picture, help in EditorToolBarItems[menu]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2131
                    if modes & self.DrawingMode:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2132
                        if radio or self.DrawingMode == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2133
                            EditorToolBar.AddRadioTool(id, GetBitmap(picture), wx.NullBitmap, help)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2134
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2135
                            EditorToolBar.AddSimpleTool(id, GetBitmap(picture), help)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2136
                        self.Bind(wx.EVT_MENU, getattr(self, method), id=id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2137
                        self.CurrentEditorToolBar.append(id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2138
                EditorToolBar.Realize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2139
                self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2140
                self.AUIManager.GetPane("EditorToolBar").Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2141
                self.AUIManager.Update()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2142
        elif menu is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2143
            self.ResetEditorToolBar()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2144
            self.CurrentMenu = menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2145
        self.ResetCurrentMode()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2146
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2147
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2148
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2149
#                           EditorToolBar Items Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2150
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2151
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2152
    def ResetCurrentMode(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2153
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2154
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2155
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2156
            window.SetMode(MODE_SELECTION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2157
        EditorToolBar = self.Panes["EditorToolBar"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2158
        if EditorToolBar:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2159
            EditorToolBar.ToggleTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2160
            EditorToolBar.ToggleTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, True)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2161
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2162
    def ResetToolToggle(self, id):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2163
        tool = self.Panes["EditorToolBar"].FindById(id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2164
        tool.SetToggle(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2165
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2166
    def OnSelectionTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2167
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2168
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2169
            self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2170
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2171
    def OnMotionTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2172
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2173
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2174
            self.TabsOpened.GetPage(selected).SetMode(MODE_MOTION)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2175
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2176
    def OnCommentTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2177
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCOMMENT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2178
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2179
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2180
            self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2181
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2182
    def OnVariableTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2183
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARVARIABLE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2184
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2185
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2186
            self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2187
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2188
    def OnBlockTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2189
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARBLOCK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2190
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2191
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2192
            self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2193
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2194
    def OnConnectionTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2195
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCONNECTION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2196
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2197
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2198
            self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2199
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2200
    def OnPowerRailTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2201
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2202
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2203
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2204
            self.TabsOpened.GetPage(selected).SetMode(MODE_POWERRAIL)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2205
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2206
    def OnRungTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2207
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2208
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2209
            self.TabsOpened.GetPage(selected).AddLadderRung()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2210
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2211
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2212
    def OnCoilTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2213
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCOIL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2214
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2215
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2216
            self.TabsOpened.GetPage(selected).SetMode(MODE_COIL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2217
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2218
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2219
    def OnContactTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2220
        if self.DrawingMode == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2221
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCONTACT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2222
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2223
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2224
            if self.DrawingMode == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2225
                self.TabsOpened.GetPage(selected).SetMode(MODE_CONTACT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2226
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2227
                self.TabsOpened.GetPage(selected).AddLadderContact()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2228
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2229
    def OnBranchTool(self, event):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2230
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2231
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2232
            self.TabsOpened.GetPage(selected).AddLadderBranch()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2233
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2234
    def OnInitialStepTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2235
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2236
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2237
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2238
            self.TabsOpened.GetPage(selected).SetMode(MODE_INITIALSTEP)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2239
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2240
    def OnStepTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2241
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2242
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARSTEP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2243
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2244
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2245
            if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2246
                self.TabsOpened.GetPage(selected).SetMode(MODE_STEP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2247
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2248
                self.TabsOpened.GetPage(selected).AddStep()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2249
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2250
    def OnActionBlockTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2251
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2252
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2253
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2254
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2255
            if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2256
                self.TabsOpened.GetPage(selected).SetMode(MODE_ACTION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2257
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2258
                self.TabsOpened.GetPage(selected).AddStepAction()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2259
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2260
    def OnTransitionTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2261
        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARTRANSITION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2262
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2263
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2264
            self.TabsOpened.GetPage(selected).SetMode(MODE_TRANSITION)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2265
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2266
    def OnDivergenceTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2267
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2268
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2269
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2270
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2271
            if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2272
                self.TabsOpened.GetPage(selected).SetMode(MODE_DIVERGENCE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2273
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2274
                self.TabsOpened.GetPage(selected).AddDivergence()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2275
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2276
    def OnJumpTool(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2277
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2278
            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARJUMP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2279
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2280
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2281
            if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2282
                self.TabsOpened.GetPage(selected).SetMode(MODE_JUMP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2283
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2284
                self.TabsOpened.GetPage(selected).AddJump()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2285
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2286
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2287
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2288
#                         Add Project Elements Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2289
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2290
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2291
    def OnAddNewProject(self, event):
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2292
        # Asks user to create main program after creating new project
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2293
        AddProgramDialog = self.GenerateAddPouFunction('program', True)
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2294
        # Checks that user created main program
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2295
        if AddProgramDialog(event):
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2296
            self.Controler.SetProjectDefaultConfiguration()
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2297
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2298
    def OnAddDataTypeMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2299
        tagname = self.Controler.ProjectAddDataType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2300
        if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2301
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2302
            self.EditProjectElement(ITEM_DATATYPE, tagname)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2303
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  2304
    def GenerateAddPouFunction(self, pou_type, type_readonly=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2305
        def OnAddPouMenu(event):
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2306
            dialog = PouDialog(self, pou_type, type_readonly)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2307
            dialog.SetPouNames(self.Controler.GetProjectPouNames())
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1167
diff changeset
  2308
            dialog.SetPouElementNames(self.Controler.GetProjectPouVariableNames())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2309
            dialog.SetValues({"pouName": self.Controler.GenerateNewName(None, None, "%s%%d" % pou_type)})
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2310
            pou_created = False
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2311
            if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2312
                values = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2313
                tagname = self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2314
                if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2315
                    self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2316
                    self.EditProjectElement(ITEM_POU, tagname)
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2317
                    dialog.Destroy()
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2318
                    pou_created = True
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2319
            dialog.Destroy()
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1700
diff changeset
  2320
            return pou_created
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2321
        return OnAddPouMenu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2322
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2323
    def GenerateAddTransitionFunction(self, pou_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2324
        def OnAddTransitionMenu(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2325
            dialog = PouTransitionDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2326
            dialog.SetPouNames(self.Controler.GetProjectPouNames())
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1167
diff changeset
  2327
            dialog.SetPouElementNames(self.Controler.GetProjectPouVariableNames(pou_name))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2328
            dialog.SetValues({"transitionName": self.Controler.GenerateNewName(None, None, "transition%d")})
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2329
            if dialog.ShowModal() == wx.ID_OK:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2330
                values = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2331
                tagname = self.Controler.ProjectAddPouTransition(pou_name, values["transitionName"], values["language"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2332
                if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2333
                    self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2334
                    self.EditProjectElement(ITEM_TRANSITION, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2335
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2336
        return OnAddTransitionMenu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2337
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2338
    def GenerateAddActionFunction(self, pou_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2339
        def OnAddActionMenu(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2340
            dialog = PouActionDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2341
            dialog.SetPouNames(self.Controler.GetProjectPouNames())
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1167
diff changeset
  2342
            dialog.SetPouElementNames(self.Controler.GetProjectPouVariableNames(pou_name))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2343
            dialog.SetValues({"actionName": self.Controler.GenerateNewName(None, None, "action%d")})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2344
            if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2345
                values = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2346
                tagname = self.Controler.ProjectAddPouAction(pou_name, values["actionName"], values["language"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2347
                if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2348
                    self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2349
                    self.EditProjectElement(ITEM_ACTION, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2350
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2351
        return OnAddActionMenu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2352
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2353
    def OnAddConfigurationMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2354
        tagname = self.Controler.ProjectAddConfiguration()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2355
        if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2356
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2357
            self.EditProjectElement(ITEM_CONFIGURATION, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2358
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2359
    def AddResourceMenu(self, event):
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2360
        config_names = self.Controler.GetProjectConfigNames()
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2361
        if len(config_names) > 0:
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2362
            tagname = self.Controler.ProjectAddConfigurationResource(config_names[0])
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2363
            if tagname is not None:
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2364
                self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2365
                self.EditProjectElement(ITEM_RESOURCE, tagname)
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2366
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2367
    def GenerateAddResourceFunction(self, config_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2368
        def OnAddResourceMenu(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2369
            tagname = self.Controler.ProjectAddConfigurationResource(config_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2370
            if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2371
                self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2372
                self.EditProjectElement(ITEM_RESOURCE, tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2373
        return OnAddResourceMenu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2374
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2375
    def GenerateChangePouTypeFunction(self, name, new_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2376
        def OnChangePouTypeMenu(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2377
            selected = self.ProjectTree.GetSelection()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2378
            if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2379
                self.Controler.ProjectChangePouType(name, new_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2380
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2381
        return OnChangePouTypeMenu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2382
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2383
    def OnCopyPou(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2384
        selected = self.ProjectTree.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2385
        pou_name = self.ProjectTree.GetItemText(selected)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2386
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2387
        pou_xml = self.Controler.GetPouXml(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2388
        if pou_xml is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2389
            self.SetCopyBuffer(pou_xml)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2390
            self._Refresh(EDITMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2391
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2392
    def OnPastePou(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2393
        selected = self.ProjectTree.GetSelection()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2394
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2395
        if self.ProjectTree.GetPyData(selected)["type"] != ITEM_PROJECT:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2396
            pou_type = self.ProjectTree.GetItemText(selected)
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
  2397
            pou_type = UNEDITABLE_NAMES_DICT[pou_type]  # one of 'Functions', 'Function Blocks' or 'Programs'
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2398
            pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2399
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2400
            pou_type = None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2401
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2402
        pou_xml = self.GetCopyBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2403
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2404
        result = self.Controler.PastePou(pou_type, pou_xml)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2405
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2406
        if not isinstance(result, TupleType):
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2407
            self.ShowErrorMessage(result)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2408
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2409
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2410
            self.EditProjectElement(ITEM_POU, result[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2411
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2412
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2413
#                        Remove Project Elements Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2414
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2415
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2416
    def CheckElementIsUsedBeforeDeletion(self, check_function, title, name):
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2417
        if not check_function(name):
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2418
            return True
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2419
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2420
        dialog = wx.MessageDialog(self,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2421
            _("\"%s\" is used by one or more POUs. Do you wish to continue?") % name,
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  2422
            title, wx.YES_NO | wx.ICON_QUESTION)
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2423
        answer = dialog.ShowModal()
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2424
        dialog.Destroy()
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2425
        return answer == wx.ID_YES
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2426
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2427
    def CheckDataTypeIsUsedBeforeDeletion(self, name):
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2428
        return self.CheckElementIsUsedBeforeDeletion(
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2429
            self.Controler.DataTypeIsUsed,
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2430
            _("Remove Datatype"), name)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2431
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2432
    def CheckPouIsUsedBeforeDeletion(self, name):
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2433
        return self.CheckElementIsUsedBeforeDeletion(
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2434
            self.Controler.PouIsUsed,
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2435
            _("Remove Pou"), name)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2436
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2437
    def OnRemoveDataTypeMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2438
        selected = self.ProjectTree.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2439
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_DATATYPE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2440
            name = self.ProjectTree.GetItemText(selected)
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2441
            if self.CheckDataTypeIsUsedBeforeDeletion(name):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2442
                self.Controler.ProjectRemoveDataType(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2443
                tagname = self.Controler.ComputeDataTypeName(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2444
                idx = self.IsOpened(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2445
                if idx is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2446
                    self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2447
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2448
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2449
    def OnRenamePouMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2450
        selected = self.ProjectTree.GetSelection()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2451
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2452
            wx.CallAfter(self.ProjectTree.EditLabel, selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2453
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2454
    def OnRemovePouMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2455
        selected = self.ProjectTree.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2456
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_POU:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2457
            name = self.ProjectTree.GetItemText(selected)
1129
189b49723f9f Removed restriction on deletion of a POU or DataType already used, replaced by a dialog asking user to confirm
Laurent Bessard
parents: 1112
diff changeset
  2458
            if self.CheckPouIsUsedBeforeDeletion(name):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2459
                self.Controler.ProjectRemovePou(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2460
                tagname = self.Controler.ComputePouName(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2461
                idx = self.IsOpened(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2462
                if idx is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2463
                    self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2464
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2465
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2466
    def OnRemoveTransitionMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2467
        selected = self.ProjectTree.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2468
        item_infos = self.ProjectTree.GetPyData(selected)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2469
        if item_infos["type"] == ITEM_TRANSITION:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2470
            transition = self.ProjectTree.GetItemText(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2471
            pou_name = item_infos["tagname"].split("::")[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2472
            self.Controler.ProjectRemovePouTransition(pou_name, transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2473
            tagname = self.Controler.ComputePouTransitionName(pou_name, transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2474
            idx = self.IsOpened(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2475
            if idx is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2476
                self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2477
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2478
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2479
    def OnRemoveActionMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2480
        selected = self.ProjectTree.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2481
        item_infos = self.ProjectTree.GetPyData(selected)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2482
        if item_infos["type"] == ITEM_ACTION:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2483
            action = self.ProjectTree.GetItemText(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2484
            pou_name = item_infos["tagname"].split("::")[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2485
            self.Controler.ProjectRemovePouAction(pou_name, action)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2486
            tagname = self.Controler.ComputePouActionName(pou_name, action)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2487
            idx = self.IsOpened(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2488
            if idx is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2489
                self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2490
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2491
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2492
    def OnRemoveConfigurationMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2493
        selected = self.ProjectTree.GetSelection()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2494
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_CONFIGURATION:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2495
            name = self.ProjectTree.GetItemText(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2496
            self.Controler.ProjectRemoveConfiguration(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2497
            tagname = self.Controler.ComputeConfigurationName(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2498
            idx = self.IsOpened(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2499
            if idx is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2500
                self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2501
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2502
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2503
    def OnRemoveResourceMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2504
        selected = self.ProjectTree.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2505
        item_infos = self.ProjectTree.GetPyData(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2506
        if item_infos["type"] == ITEM_RESOURCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2507
            resource = self.ProjectTree.GetItemText(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2508
            config_name = item_infos["tagname"].split("::")[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2509
            self.Controler.ProjectRemoveConfigurationResource(config_name, resource)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2510
            tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2511
            idx = self.IsOpened(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2512
            if idx is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2513
                self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2514
            self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2515
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2516
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2517
#                        Highlights showing functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2518
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2519
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2520
    def ShowHighlight(self, infos, start, end, highlight_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2521
        self.SelectProjectTreeItem(infos[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2522
        if infos[1] == "name":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2523
            self.Highlights[infos[0]] = highlight_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2524
            self.RefreshProjectTree()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2525
            self.ProjectTree.Unselect()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2526
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2527
            self.EditProjectElement(self.Controler.GetElementType(infos[0]), infos[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2528
            selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2529
            if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2530
                viewer = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2531
                viewer.AddHighlight(infos[1:], start, end, highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2532
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2533
    def ShowError(self, infos, start, end):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2534
        self.ShowHighlight(infos, start, end, ERROR_HIGHLIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2535
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2536
    def ShowSearchResult(self, infos, start, end):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2537
        self.ShowHighlight(infos, start, end, SEARCH_RESULT_HIGHLIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2538
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2539
    def ClearHighlights(self, highlight_type=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2540
        if highlight_type is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2541
            self.Highlights = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2542
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2543
            self.Highlights = dict([(name, highlight) for name, highlight in self.Highlights.iteritems() if highlight != highlight_type])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2544
        self.RefreshProjectTree()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2545
        for i in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2546
            viewer = self.TabsOpened.GetPage(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2547
            viewer.ClearHighlights(highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2548
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2549
    def ClearErrors(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2550
        self.ClearHighlights(ERROR_HIGHLIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2551
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2552
    def ClearSearchResults(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  2553
        self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT)
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2554
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2555
#-------------------------------------------------------------------------------
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2556
#                               Viewer Printout
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2557
#-------------------------------------------------------------------------------
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2558
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
  2559
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
  2560
def UPPER_DIV(x, y):
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
  2561
    return (x / y) + {True: 0, False: 1}[(x % y) == 0]
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2562
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
  2563
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2564
class GraphicPrintout(wx.Printout):
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  2565
    def __init__(self, viewer, page_size, margins, preview=False):
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2566
        wx.Printout.__init__(self)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2567
        self.Viewer = viewer
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2568
        self.PageSize = page_size
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2569
        if self.PageSize[0] == 0 or self.PageSize[1] == 0:
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2570
            self.PageSize = (1050, 1485)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2571
        self.Preview = preview
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2572
        self.Margins = margins
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2573
        self.FontSize = 5
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2574
        self.TextMargin = 3
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2575
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2576
        maxx, maxy = viewer.GetMaxSize()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2577
        self.PageGrid = (UPPER_DIV(maxx, self.PageSize[0]),
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2578
                         UPPER_DIV(maxy, self.PageSize[1]))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2579
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2580
    def GetPageNumber(self):
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2581
        return self.PageGrid[0] * self.PageGrid[1]
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2582
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2583
    def HasPage(self, page):
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2584
        return page <= self.GetPageNumber()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2585
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2586
    def GetPageInfo(self):
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2587
        page_number = self.GetPageNumber()
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2588
        return (1, page_number, 1, page_number)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2589
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2590
    def OnBeginDocument(self, startPage, endPage):
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2591
        dc = self.GetDC()
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2592
        if not self.Preview and isinstance(dc, wx.PostScriptDC):
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2593
            dc.SetResolution(720)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2594
        super(GraphicPrintout, self).OnBeginDocument(startPage, endPage)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2595
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2596
    def OnPrintPage(self, page):
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2597
        dc = self.GetDC()
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2598
        dc.SetUserScale(1.0, 1.0)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2599
        dc.SetDeviceOrigin(0, 0)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2600
        dc.printing = not self.Preview
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2601
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2602
        # Get the size of the DC in pixels
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2603
        ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2604
        ppiScreenX, ppiScreenY = self.GetPPIScreen()
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2605
        pw, ph = self.GetPageSizePixels()
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2606
        dw, dh = dc.GetSizeTuple()
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2607
        Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2608
        Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2609
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2610
        fontsize = self.FontSize * Yscale
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2611
        text_margin = self.TextMargin * Yscale
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2612
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2613
        margin_left = self.Margins[0].x * Xscale
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2614
        margin_top = self.Margins[0].y * Yscale
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2615
        area_width = dw - self.Margins[1].x * Xscale - margin_left
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2616
        area_height = dh - self.Margins[1].y * Yscale - margin_top
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2617
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2618
        dc.SetPen(MiterPen(wx.BLACK))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2619
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2620
        dc.DrawRectangle(margin_left, margin_top, area_width, area_height)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2621
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2622
        dc.SetFont(wx.Font(fontsize, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2623
        dc.SetTextForeground(wx.BLACK)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2624
        block_name = " - ".join(self.Viewer.GetTagName().split("::")[1:])
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2625
        text_width, text_height = dc.GetTextExtent(block_name)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2626
        dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2627
        dc.DrawText(_("Page: %d") % page, margin_left, margin_top + area_height + self.TextMargin)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2628
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2629
        # Calculate the position on the DC for centering the graphic
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2630
        posX = area_width * ((page - 1) % self.PageGrid[0])
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2631
        posY = area_height * ((page - 1) / self.PageGrid[0])
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2632
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2633
        scaleX = float(area_width) / float(self.PageSize[0])
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2634
        scaleY = float(area_height) / float(self.PageSize[1])
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2635
        scale = min(scaleX, scaleY)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2636
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2637
        # Set the scale and origin
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2638
        dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2639
        dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale)
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2640
        dc.SetUserScale(scale, scale)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2641
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2642
        #-------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2643
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2644
        self.Viewer.DoDrawing(dc, True)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  2645
838
06db7d4edbe6 Fix bug with Print functionality
laurent
parents: 819
diff changeset
  2646
        return True