IDEFrame.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 20 Dec 2016 17:11:36 +0300
changeset 1610 31703a04789a
parent 1556 32e9d0ef30dc
child 1635 25e3bf6e193d
permissions -rw-r--r--
fix problem with SFC action/transition rename

Traceback (most recent call last):
File "/home/developer/WorkData/PLC/beremiz/beremiz/IDEFrame.py", line
1636, in OnProjectTreeItemEndEdit
elif new_name.upper() in [name.upper() for name in
self.Controler.GetProjectPouVariableNames(pou_name) if name !=
old_name]:
NameError: global name 'pou_name' is not defined
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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import os, sys
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import cPickle
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
from types import TupleType
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
import wx, wx.grid
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
import wx.aui
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
from editors.EditorPanel import EditorPanel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
from editors.SFCViewer import SFC_Viewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
from editors.LDViewer import LD_Viewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
from editors.TextViewer import TextViewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
from editors.Viewer import Viewer, ZOOM_FACTORS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
from editors.ResourceEditor import ConfigurationEditor, ResourceEditor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
from editors.DataTypeEditor import DataTypeEditor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
from PLCControler import *
1193
59c196884fec Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents: 1188
diff changeset
    40
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
    41
from controls.DebugVariablePanel import DebugVariablePanel
819
4424918efe8b Fix bug missing dialog import statements
laurent
parents: 814
diff changeset
    42
from dialogs import ProjectDialog, PouDialog, PouTransitionDialog, PouActionDialog, FindInPouDialog, SearchInProjectDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
from util.BitmapLibrary import GetBitmap
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
# Define PLCOpenEditor controls id
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    46
[ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    47
 ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    48
 ID_PLCOPENEDITORPROJECTTREE, ID_PLCOPENEDITORMAINSPLITTER,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    49
 ID_PLCOPENEDITORSECONDSPLITTER, ID_PLCOPENEDITORTHIRDSPLITTER,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    50
 ID_PLCOPENEDITORLIBRARYPANEL, ID_PLCOPENEDITORLIBRARYSEARCHCTRL,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    51
 ID_PLCOPENEDITORLIBRARYTREE, ID_PLCOPENEDITORLIBRARYCOMMENT,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    52
 ID_PLCOPENEDITORTABSOPENED, ID_PLCOPENEDITORTABSOPENED,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    53
 ID_PLCOPENEDITOREDITORMENUTOOLBAR, ID_PLCOPENEDITOREDITORTOOLBAR,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    54
 ID_PLCOPENEDITORPROJECTPANEL,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
] = [wx.NewId() for _init_ctrls in range(17)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
# Define PLCOpenEditor EditMenu extra items id
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    58
[ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, ID_PLCOPENEDITOREDITMENUADDDATATYPE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    59
 ID_PLCOPENEDITOREDITMENUADDFUNCTION, ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
 ID_PLCOPENEDITOREDITMENUADDPROGRAM, ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
 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
    62
 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
    63
] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
# Define PLCOpenEditor DisplayMenu extra items id
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    66
[ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
1530
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
    67
 ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
    68
] = [wx.NewId() for _init_coll_DisplayMenu_Items in range(2)]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
#                            EditorToolBar definitions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
# Define PLCOpenEditor Toolbar items id
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
[ID_PLCOPENEDITOREDITORTOOLBARSELECTION, ID_PLCOPENEDITOREDITORTOOLBARCOMMENT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, ID_PLCOPENEDITOREDITORTOOLBARBLOCK,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, ID_PLCOPENEDITOREDITORTOOLBARWIRE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
 ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITOREDITORTOOLBARRUNG,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
 ID_PLCOPENEDITOREDITORTOOLBARCOIL, ID_PLCOPENEDITOREDITORTOOLBARCONTACT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
 ID_PLCOPENEDITOREDITORTOOLBARBRANCH, ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
 ID_PLCOPENEDITOREDITORTOOLBARSTEP, ID_PLCOPENEDITOREDITORTOOLBARTRANSITION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
 ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE,
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    83
 ID_PLCOPENEDITOREDITORTOOLBARJUMP, ID_PLCOPENEDITOREDITORTOOLBARMOTION,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
] = [wx.NewId() for _init_coll_DefaultEditorToolBar_Items in range(18)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
    88
# Define behaviour of each Toolbar item according to current POU body type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
# Informations meaning are in this order:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
#  - Item is toggled
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
#  - PLCOpenEditor mode where item is displayed (could be more then one)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
#  - Item id
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
#  - Item callback function name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
#  - Item icon filename
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
#  - Item tooltip text
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
EditorToolBarItems = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
    "FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
              "move", _("Move the view")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
              "add_comment", _("Create a new comment")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
              "add_variable", _("Create a new variable")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
              "add_block", _("Create a new block")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   109
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   110
              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
              "add_connection", _("Create a new connection"))],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
    "LD"  : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
              "move", _("Move the view")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   115
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   116
              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
              "add_comment", _("Create a new comment")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   118
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   119
              ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
              "add_powerrail", _("Create a new power rail")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   121
             (False, DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   122
              ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
              "add_rung", _("Create a new rung")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   124
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   125
              ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
              "add_coil", _("Create a new coil")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   127
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   128
              ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
              "add_contact", _("Create a new contact")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   130
             (False, DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   131
              ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
              "add_branch", _("Create a new branch")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   133
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   134
              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
              "add_variable", _("Create a new variable")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   136
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   137
              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
              "add_block", _("Create a new block")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   139
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   140
              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
              "add_connection", _("Create a new connection"))],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
    "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
              "move", _("Move the view")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   145
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   146
              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
              "add_comment", _("Create a new comment")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   148
             (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   149
              ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
              "add_initial_step", _("Create a new initial step")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   151
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   152
              ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
              "add_step", _("Create a new step")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   154
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   155
              ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
              "add_transition", _("Create a new transition")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   157
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   158
              ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
              "add_action", _("Create a new action block")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   160
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   161
              ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
              "add_divergence", _("Create a new divergence")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   163
             (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   164
              ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
              "add_jump", _("Create a new jump")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   166
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   167
              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
              "add_variable", _("Create a new variable")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   169
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   170
              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
              "add_block", _("Create a new block")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   172
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   173
              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
              "add_connection", _("Create a new connection")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   175
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   176
              ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
              "add_powerrail", _("Create a new power rail")),
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   178
             (True, FREEDRAWING_MODE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   179
              ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
              "add_contact", _("Create a new contact"))],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
    "ST"  : [],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
    "IL"  : [],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
    "debug": [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
              "move", _("Move the view"))],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
}
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
#                               Helper Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
import base64
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
def EncodeFileSystemPath(path, use_base64=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
    path = path.encode(sys.getfilesystemencoding())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
    if use_base64:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
        return base64.encodestring(path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
    return path
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
def DecodeFileSystemPath(path, is_base64=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
    if is_base64:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
        path = base64.decodestring(path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
    return unicode(path, sys.getfilesystemencoding())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
# Compatibility function for wx versions < 2.6
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
def AppendMenu(parent, help, id, kind, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
    if wx.VERSION >= (2, 6, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
        parent.Append(help=help, id=id, kind=kind, text=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
        parent.Append(helpString=help, id=id, kind=kind, item=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   212
[TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
 POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
] = range(10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
def GetShortcutKeyCallbackFunction(viewer_function):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
    def ShortcutKeyFunction(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
        control = self.FindFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
        if control is not None and control.GetName() in ["Viewer", "TextViewer"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
            getattr(control.ParentWindow, viewer_function)()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
        elif isinstance(control, wx.stc.StyledTextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
            getattr(control, viewer_function)()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
        elif isinstance(control, wx.TextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
            control.ProcessEvent(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
    return ShortcutKeyFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
def GetDeleteElementFunction(remove_function, parent_type=None, check_function=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
    def DeleteElementFunction(self, selected):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
        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
   230
        if check_function is None or check_function(name):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
            if parent_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
                item_infos = self.ProjectTree.GetPyData(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
                parent_name = item_infos["tagname"].split("::")[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
                remove_function(self.Controler, parent_name, name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
                remove_function(self.Controler, name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
    return DeleteElementFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
if wx.Platform == '__WXMSW__':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
    TAB_BORDER = 6
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
    NOTEBOOK_BORDER = 6
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
    TAB_BORDER = 7
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
    NOTEBOOK_BORDER = 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
def SimplifyTabLayout(tabs, rect):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
    for tab in tabs:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
        if tab["pos"][0] == rect.x:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
            others = [t for t in tabs if t != tab]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
            others.sort(lambda x,y: cmp(x["pos"][0], y["pos"][0]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
            for other in others:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   252
                if (other["pos"][1] == tab["pos"][1] and
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
                    other["size"][1] == tab["size"][1] and
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
                    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
   255
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                    tab["size"] = (tab["size"][0] + other["size"][0] + TAB_BORDER, tab["size"][1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                    tab["pages"].extend(other["pages"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
                    tabs.remove(other)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   259
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
                    if tab["size"][0] == rect.width:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
                        return True
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   262
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
        elif tab["pos"][1] == rect.y:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
            others = [t for t in tabs if t != tab]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
            others.sort(lambda x,y: cmp(x["pos"][1], y["pos"][1]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
            for other in others:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   267
                if (other["pos"][0] == tab["pos"][0] and
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
                    other["size"][0] == tab["size"][0] and
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
                    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
   270
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
                    tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + TAB_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   272
                    tab["pages"].extend(other["pages"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   273
                    tabs.remove(other)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   274
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
                    if tab["size"][1] == rect.height:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
                        return True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
    return False
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   278
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
def ComputeTabsLayout(tabs, rect):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
    if len(tabs) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
        return tabs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
    if len(tabs) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
        return tabs[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
    split = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
    for idx, tab in enumerate(tabs):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
        if len(tab["pages"]) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
            raise ValueError, "Not possible"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
        if tab["size"][0] == rect.width:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
            if tab["pos"][1] == rect.y:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
                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
   291
                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
   292
                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
            elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
                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
   295
                split_rect = wx.Rect(rect.x, rect.y,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
            break
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
        elif tab["size"][1] == rect.height:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
            if tab["pos"][0] == rect.x:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
                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
   301
                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
   302
                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
            elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
                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
   305
                split_rect = wx.Rect(rect.x, rect.y,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
            break
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
    if split != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
        split_tab = tabs.pop(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
        return {"split": split,
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   311
                "tab": split_tab,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
                "others": ComputeTabsLayout(tabs, split_rect)}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
        if SimplifyTabLayout(tabs, rect):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
            return ComputeTabsLayout(tabs, rect)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
    return tabs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
#                              IDEFrame Base Class
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
UNEDITABLE_NAMES_DICT = dict([(_(name), name) for name in UNEDITABLE_NAMES])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
class IDEFrame(wx.Frame):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   325
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
    # Compatibility function for wx versions < 2.6
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
    if wx.VERSION < (2, 6, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
        def Bind(self, event, function, id = None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
            if id is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
                event(self, id, function)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
                event(self, function)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   333
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
    def _init_coll_MenuBar_Menus(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
        parent.Append(menu=self.FileMenu, title=_(u'&File'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
        parent.Append(menu=self.EditMenu, title=_(u'&Edit'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
        parent.Append(menu=self.DisplayMenu, title=_(u'&Display'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
        parent.Append(menu=self.HelpMenu, title=_(u'&Help'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
    def _init_coll_FileMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
        pass
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   342
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
    def _init_coll_AddMenu_Items(self, parent, add_config=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDDATATYPE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
              kind=wx.ITEM_NORMAL, text=_(u'&Data Type'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
              kind=wx.ITEM_NORMAL, text=_(u'&Function'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
              kind=wx.ITEM_NORMAL, text=_(u'Function &Block'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDPROGRAM,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
              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
   352
        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
   353
                  kind=wx.ITEM_NORMAL, text=_(u'&Resource'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
        if add_config:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
            AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
                  kind=wx.ITEM_NORMAL, text=_(u'&Configuration'))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   357
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
    def _init_coll_EditMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
        AppendMenu(parent, help='', id=wx.ID_UNDO,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   360
              kind=wx.ITEM_NORMAL, text=_(u'Undo') + '\tCTRL+Z')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
        AppendMenu(parent, help='', id=wx.ID_REDO,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
              kind=wx.ITEM_NORMAL, text=_(u'Redo') + '\tCTRL+Y')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
        #AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
        #      kind=wx.ITEM_CHECK, text=_(u'Enable Undo/Redo'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
        enable_undo_redo = _(u'Enable Undo/Redo') # Keeping text in translations for possible menu reactivation
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   366
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
        AppendMenu(parent, help='', id=wx.ID_CUT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
              kind=wx.ITEM_NORMAL, text=_(u'Cut') + '\tCTRL+X')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
        AppendMenu(parent, help='', id=wx.ID_COPY,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
              kind=wx.ITEM_NORMAL, text=_(u'Copy') + '\tCTRL+C')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
        AppendMenu(parent, help='', id=wx.ID_PASTE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
              kind=wx.ITEM_NORMAL, text=_(u'Paste') + '\tCTRL+V')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
        AppendMenu(parent, help='', id=wx.ID_FIND,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
              kind=wx.ITEM_NORMAL, text=_(u'Find') + '\tCTRL+F')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDNEXT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
              kind=wx.ITEM_NORMAL, text=_(u'Find Next') + '\tCTRL+K')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
              kind=wx.ITEM_NORMAL, text=_(u'Find Previous') + '\tCTRL+SHIFT+K')
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=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
              kind=wx.ITEM_NORMAL, text=_(u'Search in Project') + '\tCTRL+SHIFT+F')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
        add_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
        self._init_coll_AddMenu_Items(add_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
        parent.AppendMenu(wx.ID_ADD, _(u"&Add Element"), add_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
        AppendMenu(parent, help='', id=wx.ID_SELECTALL,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
              kind=wx.ITEM_NORMAL, text=_(u'Select All') + '\tCTRL+A')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
        AppendMenu(parent, help='', id=wx.ID_DELETE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
              kind=wx.ITEM_NORMAL, text=_(u'&Delete'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
        self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
        self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
        #self.Bind(wx.EVT_MENU, self.OnEnableUndoRedoMenu, id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
        self.Bind(wx.EVT_MENU, self.OnCutMenu, id=wx.ID_CUT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
        self.Bind(wx.EVT_MENU, self.OnCopyMenu, id=wx.ID_COPY)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
        self.Bind(wx.EVT_MENU, self.OnPasteMenu, id=wx.ID_PASTE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
        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
   398
        self.Bind(wx.EVT_MENU, self.OnFindNextMenu,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
              id=ID_PLCOPENEDITOREDITMENUFINDNEXT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   400
        self.Bind(wx.EVT_MENU, self.OnFindPreviousMenu,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
              id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   402
        self.Bind(wx.EVT_MENU, self.OnSearchInProjectMenu,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
              id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   404
        self.Bind(wx.EVT_MENU, self.OnSearchInProjectMenu,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
              id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
        self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
              id=ID_PLCOPENEDITOREDITMENUADDDATATYPE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("function"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
              id=ID_PLCOPENEDITOREDITMENUADDFUNCTION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("functionBlock"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
              id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   412
        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("program"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
              id=ID_PLCOPENEDITOREDITMENUADDPROGRAM)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   414
        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
   415
              id=ID_PLCOPENEDITOREDITMENUADDRESOURCE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   416
        self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
              id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
        self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
        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
   420
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
        self.AddToMenuToolBar([(wx.ID_UNDO, "undo", _(u'Undo'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
                               (wx.ID_REDO, "redo", _(u'Redo'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   423
                               None,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   424
                               (wx.ID_CUT, "cut", _(u'Cut'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
                               (wx.ID_COPY, "copy", _(u'Copy'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   426
                               (wx.ID_PASTE, "paste", _(u'Paste'), None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
                               None,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   428
                               (ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find", _(u'Search in Project'), None)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   429
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
    def _init_coll_DisplayMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   431
        AppendMenu(parent, help='', id=wx.ID_REFRESH,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
              kind=wx.ITEM_NORMAL, text=_(u'Refresh') + '\tCTRL+R')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
        if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   434
            AppendMenu(parent, help='', id=wx.ID_CLEAR,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
                  kind=wx.ITEM_NORMAL, text=_(u'Clear Errors') + '\tCTRL+K')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
        parent.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
        zoommenu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
        parent.AppendMenu(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   439
        for idx, value in enumerate(ZOOM_FACTORS):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   440
            new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   441
            AppendMenu(zoommenu, help='', id=new_id,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
                  kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
            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
   444
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
        parent.AppendSeparator()
1530
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
   446
        AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
   447
                   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
   448
        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
   449
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   450
        AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
              kind=wx.ITEM_NORMAL, text=_(u'Reset Perspective'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
        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
   453
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
        self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   455
        if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
            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
   457
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   458
    def _init_coll_HelpMenu_Items(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
        pass
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
    def _init_utils(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
        self.MenuBar = wx.MenuBar()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   463
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
        self.FileMenu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   465
        self.EditMenu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
        self.DisplayMenu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   467
        self.HelpMenu = wx.Menu(title='')
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   468
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   469
        self._init_coll_MenuBar_Menus(self.MenuBar)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
        self._init_coll_FileMenu_Items(self.FileMenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
        self._init_coll_EditMenu_Items(self.EditMenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   472
        self._init_coll_DisplayMenu_Items(self.DisplayMenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   473
        self._init_coll_HelpMenu_Items(self.HelpMenu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
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
   475
    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
   476
        if self.icon:
f03bc6c9c146 make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1480
diff changeset
   477
            self.SetIcon(self.icon)                            
f03bc6c9c146 make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1480
diff changeset
   478
        elif parent and parent.icon:
f03bc6c9c146 make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1480
diff changeset
   479
            self.SetIcon(parent.icon)                
f03bc6c9c146 make About and Find dialogs have the same icon as main Beremiz window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1480
diff changeset
   480
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
    def _init_ctrls(self, prnt):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   482
        wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name='IDEFrame',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
              parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
              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
   485
        self._init_icon(prnt)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
        self.SetClientSize(wx.Size(1000, 600))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
        self.Bind(wx.EVT_ACTIVATE, self.OnActivated)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   488
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
        self.TabsImageList = wx.ImageList(31, 16)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
        self.TabsImageListIndexes = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   491
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   492
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   493
        #                          Creating main structure
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   494
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   495
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   496
        self.AUIManager = wx.aui.AuiManager(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   497
        self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   498
        self.Panes = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   499
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
        self.LeftNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORLEFTNOTEBOOK,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   501
              style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   502
                    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
   503
        self.LeftNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   504
                self.OnAllowNotebookDnD)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   505
        self.AUIManager.AddPane(self.LeftNoteBook,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   506
              wx.aui.AuiPaneInfo().Name("ProjectPane").
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
              Left().Layer(1).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
              BestSize(wx.Size(300, 500)).CloseButton(False))
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.BottomNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORBOTTOMNOTEBOOK,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   511
              style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   512
                    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
   513
        self.BottomNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   514
                self.OnAllowNotebookDnD)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   515
        self.AUIManager.AddPane(self.BottomNoteBook,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
              wx.aui.AuiPaneInfo().Name("ResultPane").
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
              Bottom().Layer(0).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
              BestSize(wx.Size(800, 300)).CloseButton(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   519
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
        self.RightNoteBook = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORRIGHTNOTEBOOK,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
              style=wx.aui.AUI_NB_TOP|wx.aui.AUI_NB_TAB_SPLIT|wx.aui.AUI_NB_TAB_MOVE|
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
                    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
   523
        self.RightNoteBook.Bind(wx.aui.EVT_AUINOTEBOOK_ALLOW_DND,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
                self.OnAllowNotebookDnD)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   525
        self.AUIManager.AddPane(self.RightNoteBook,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
              wx.aui.AuiPaneInfo().Name("LibraryPane").
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   527
              Right().Layer(0).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
              BestSize(wx.Size(250, 400)).CloseButton(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   529
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   530
        self.TabsOpened = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORTABSOPENED,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
              style=wx.aui.AUI_NB_DEFAULT_STYLE|wx.aui.AUI_NB_WINDOWLIST_BUTTON)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   533
              self.OnPouSelectedChanging)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
              self.OnPouSelectedChanged)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   536
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
              self.OnPageClose)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
        self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_END_DRAG,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
              self.OnPageDragged)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   540
        self.AUIManager.AddPane(self.TabsOpened,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   541
              wx.aui.AuiPaneInfo().CentrePane().Name("TabsPane"))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   542
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   543
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   544
        #                    Creating PLCopen Project Types Tree
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   545
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   546
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
        self.MainTabs = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   548
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   549
        self.ProjectPanel = wx.SplitterWindow(id=ID_PLCOPENEDITORPROJECTPANEL,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   550
                  name='ProjectPanel', parent=self.LeftNoteBook, point=wx.Point(0, 0),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   551
                  size=wx.Size(0, 0), style=wx.SP_3D)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   552
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
        self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE,
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   554
                  name='ProjectTree', parent=self.ProjectPanel,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   555
                  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
   556
                  style=wx.SUNKEN_BORDER,
a2f9b44c17c9 Fixed bug ProjectTree items label can't be edited
Laurent Bessard
parents: 1165
diff changeset
   557
                  agwStyle=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.TR_EDIT_LABELS)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   558
        self.ProjectTree.SetBackgroundBitmap(GetBitmap("custom_tree_background"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
                                             wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
        add_menu = wx.Menu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
        self._init_coll_AddMenu_Items(add_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   562
        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
   563
        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
   564
              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
   565
        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
   566
        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
   567
              id=ID_PLCOPENEDITORPROJECTTREE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   568
        self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   569
              id=ID_PLCOPENEDITORPROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
        self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   571
              id=ID_PLCOPENEDITORPROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   572
        self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   573
              id=ID_PLCOPENEDITORPROJECTTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   574
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
              id=ID_PLCOPENEDITORPROJECTTREE)
1106
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
   576
        self.ProjectTree.Bind(wx.EVT_MOTION, self.OnProjectTreeMotion)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   577
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   579
        #        Creating PLCopen Project POU Instance Variables Panel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   581
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
        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
   583
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
        self.MainTabs["ProjectPanel"] = (self.ProjectPanel, _("Project"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   585
        self.LeftNoteBook.AddPage(*self.MainTabs["ProjectPanel"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   586
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   587
        self.ProjectPanel.SplitHorizontally(self.ProjectTree, self.PouInstanceVariablesPanel, 300)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   588
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   589
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   590
        #                            Creating Tool Bar
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   591
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   592
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
        MenuToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORMENUTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
                wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   595
        MenuToolBar.SetToolBitmapSize(wx.Size(25, 25))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
        MenuToolBar.Realize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   597
        self.Panes["MenuToolBar"] = MenuToolBar
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
        self.AUIManager.AddPane(MenuToolBar, wx.aui.AuiPaneInfo().
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   599
                  Name("MenuToolBar").Caption(_("Menu ToolBar")).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   600
                  ToolbarPane().Top().
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   601
                  LeftDockable(False).RightDockable(False))
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
        EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
                wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   605
        EditorToolBar.SetToolBitmapSize(wx.Size(25, 25))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   606
        EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
              GetBitmap("select"), wx.NullBitmap, _("Select an object"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
        EditorToolBar.Realize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   609
        self.Panes["EditorToolBar"] = EditorToolBar
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
        self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo().
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   611
                  Name("EditorToolBar").Caption(_("Editor ToolBar")).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   612
                  ToolbarPane().Top().Position(1).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
                  LeftDockable(False).RightDockable(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   614
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   615
        self.Bind(wx.EVT_MENU, self.OnSelectionTool,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   616
              id=ID_PLCOPENEDITOREDITORTOOLBARSELECTION)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   617
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   618
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   619
        #                            Creating Search Panel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   620
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   621
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   622
        self.SearchResultPanel = SearchResultPanel(self.BottomNoteBook, self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
        self.MainTabs["SearchResultPanel"] = (self.SearchResultPanel, _("Search"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
        self.BottomNoteBook.AddPage(*self.MainTabs["SearchResultPanel"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   625
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   626
        #-----------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   627
        #                            Creating Library Panel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   628
        #-----------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   629
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   630
        self.LibraryPanel = LibraryPanel(self, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   631
        self.MainTabs["LibraryPanel"] = (self.LibraryPanel, _("Library"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
        self.RightNoteBook.AddPage(*self.MainTabs["LibraryPanel"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   633
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   634
        self._init_utils()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   635
        self.SetMenuBar(self.MenuBar)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   636
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
        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
   638
            self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self.Controler, self)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   639
            self.MainTabs["DebugVariablePanel"] = (self.DebugVariablePanel, _("Debugger"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
            self.RightNoteBook.AddPage(*self.MainTabs["DebugVariablePanel"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   641
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
        self.AUIManager.Update()
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.FindDialog = FindInPouDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   645
        self.FindDialog.Hide()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   646
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
    ## Constructor of the PLCOpenEditor class.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   648
    #  @param parent The parent window.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
    #  @param controler The controler been used by PLCOpenEditor (default: None).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   650
    #  @param fileOpen The filepath to open if no controler defined (default: None).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
    #  @param debug The filepath to open if no controler defined (default: False).
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   652
    def __init__(self, parent, enable_debug = False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
        self.Controler = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
        self.Config = wx.ConfigBase.Get()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
        self.EnableDebug = enable_debug
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   656
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
        self._init_ctrls(parent)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   658
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   659
        # Define Tree item icon list
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
        self.TreeImageList = wx.ImageList(16, 16)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   661
        self.TreeImageDict = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   662
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   663
        # Icons for languages
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
        for language in LANGUAGES:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
            self.TreeImageDict[language] = self.TreeImageList.Add(GetBitmap(language))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   666
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   667
        # Icons for other items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   668
        for imgname, itemtype in [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   669
            #editables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   670
            ("PROJECT",        ITEM_PROJECT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   671
            #("POU",            ITEM_POU),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   672
            #("VARIABLE",       ITEM_VARIABLE),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   673
            ("TRANSITION",     ITEM_TRANSITION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   674
            ("ACTION",         ITEM_ACTION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   675
            ("CONFIGURATION",  ITEM_CONFIGURATION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   676
            ("RESOURCE",       ITEM_RESOURCE),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   677
            ("DATATYPE",       ITEM_DATATYPE),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   678
            # uneditables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   679
            ("DATATYPES",      ITEM_DATATYPES),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   680
            ("FUNCTION",       ITEM_FUNCTION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   681
            ("FUNCTIONBLOCK",  ITEM_FUNCTIONBLOCK),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   682
            ("PROGRAM",        ITEM_PROGRAM),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   683
            ("VAR_LOCAL",      ITEM_VAR_LOCAL),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
            ("VAR_LOCAL",      ITEM_VAR_GLOBAL),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
            ("VAR_LOCAL",      ITEM_VAR_EXTERNAL),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
            ("VAR_LOCAL",      ITEM_VAR_TEMP),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
            ("VAR_INPUT",      ITEM_VAR_INPUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
            ("VAR_OUTPUT",     ITEM_VAR_OUTPUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
            ("VAR_INOUT",      ITEM_VAR_INOUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   690
            ("TRANSITIONS",    ITEM_TRANSITIONS),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
            ("ACTIONS",        ITEM_ACTIONS),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
            ("CONFIGURATIONS", ITEM_CONFIGURATIONS),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
            ("RESOURCES",      ITEM_RESOURCES),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   694
            ("PROPERTIES",     ITEM_PROPERTIES)]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
            self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   696
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
        # Assign icon list to TreeCtrls
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
        self.ProjectTree.SetImageList(self.TreeImageList)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
        self.PouInstanceVariablesPanel.SetTreeImageList(self.TreeImageList)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   700
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
        self.CurrentEditorToolBar = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
        self.CurrentMenu = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
        self.SelectedItem = None
1106
843d181f73b4 Added tooltip in ProjectTree when mouse over POU
Laurent Bessard
parents: 1105
diff changeset
   704
        self.LastToolTipItem = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   705
        self.SearchParams = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
        self.Highlights = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   707
        self.DrawingMode = FREEDRAWING_MODE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   708
        #self.DrawingMode = DRIVENDRAWING_MODE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   709
        self.AuiTabCtrl = []
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   710
980
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   711
        # Save default perspective
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   712
        notebooks = {}
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   713
        for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   714
                                     (self.BottomNoteBook, "bottomnotebook"),
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   715
                                     (self.RightNoteBook, "rightnotebook")]:
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   716
            notebooks[entry_name] = self.SaveTabLayout(notebook)
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   717
        self.DefaultPerspective = {
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   718
            "perspective": self.AUIManager.SavePerspective(),
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   719
            "notebooks": notebooks,
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   720
        }
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   721
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   722
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   723
        # Initialize Printing configuring elements
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   724
        self.PrintData = wx.PrintData()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   725
        self.PrintData.SetPaperId(wx.PAPER_A4)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   726
        self.PrintData.SetPrintMode(wx.PRINT_MODE_PRINTER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
        self.PageSetupData = wx.PageSetupDialogData(self.PrintData)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
        self.PageSetupData.SetMarginTopLeft(wx.Point(10, 15))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   729
        self.PageSetupData.SetMarginBottomRight(wx.Point(10, 20))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   730
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   731
        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
   732
        self.SetDeleteFunctions()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   733
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   734
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
        self.FindDialog.Destroy()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   736
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
    def Show(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   738
        wx.Frame.Show(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
        wx.CallAfter(self.RestoreLastState)
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
    def OnActivated(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   742
        if event.GetActive():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   743
            wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   744
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   745
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   746
    def SelectTab(self, tab):
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   747
        for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   748
            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
   749
            if idx != wx.NOT_FOUND and idx != notebook.GetSelection():
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   750
                notebook.SetSelection(idx)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   751
                return
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 989
diff changeset
   752
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   753
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   754
#                Saving and restoring frame organization functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   755
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   756
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   757
    def GetTabInfos(self, tab):
980
c7ba67d01d65 Completely removed restore perspective and project layout process
Laurent Bessard
parents: 970
diff changeset
   758
        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
   759
            if page_ref == tab:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 980
diff changeset
   760
                return ("main", page_name)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   761
        return None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   762
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   763
    def SaveTabLayout(self, notebook):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   764
        tabs = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   765
        for child in notebook.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   766
            if isinstance(child, wx.aui.AuiTabCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   767
                if child.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   768
                    pos = child.GetPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
                    tab = {"pos": (pos.x, pos.y), "pages": []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   770
                    tab_size = child.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   771
                    for page_idx in xrange(child.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
                        page = child.GetWindowFromIdx(page_idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
                        if not tab.has_key("size"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   774
                            tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   775
                        tab_infos = self.GetTabInfos(page)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   776
                        if tab_infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   777
                            tab["pages"].append((tab_infos, page_idx == child.GetActivePage()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   778
                    tabs.append(tab)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   779
        tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   780
        size = notebook.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   781
        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
   782
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   783
    def LoadTab(self, notebook, page_infos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   784
        if page_infos[0] == "main":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   785
            infos = self.MainTabs.get(page_infos[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   786
            if infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   787
                page_ref, page_title = infos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   788
                notebook.AddPage(page_ref, page_title)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   789
                return notebook.GetPageIndex(page_ref)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   790
        elif page_infos[0] == "editor":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   791
            tagname = page_infos[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   792
            page_ref = self.EditProjectElement(self.Controler.GetElementType(tagname), tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
            if page_ref is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   794
                page_ref.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   795
                return notebook.GetPageIndex(page_ref)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   796
        elif page_infos[0] == "debug":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   797
            instance_path = page_infos[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   798
            instance_infos = self.Controler.GetInstanceInfos(instance_path, self.EnableDebug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   799
            if instance_infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   800
                return notebook.GetPageIndex(self.OpenDebugViewer(instance_infos["class"], instance_path, instance_infos["type"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   801
        return None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   802
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   803
    def LoadTabLayout(self, notebook, tabs, mode="all", first_index=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   804
        if isinstance(tabs, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   805
            if len(tabs) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   806
                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   807
            raise ValueError, "Not supported"
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   808
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   809
        if tabs.has_key("split"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   810
            self.LoadTabLayout(notebook, tabs["others"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   811
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   812
            split_dir, split_ratio = tabs["split"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   813
            first_index = self.LoadTabLayout(notebook, tabs["tab"], mode="first")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
            notebook.Split(first_index, split_dir)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   815
            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
   816
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   817
        elif mode == "first":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   818
            return self.LoadTab(notebook, tabs["pages"][0][0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   819
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   820
            selected = first_index
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   821
            if mode == "others":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   822
                add_tabs = tabs["pages"][1:]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   823
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   824
                add_tabs = tabs["pages"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   825
            for page_infos, page_selected in add_tabs:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
                page_idx = self.LoadTab(notebook, page_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   827
                if page_selected:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   828
                    selected = page_idx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   829
            if selected is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   830
                wx.CallAfter(notebook.SetSelection, selected)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   831
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   832
    def ResetPerspective(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   833
        if self.DefaultPerspective is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   834
            self.AUIManager.LoadPerspective(self.DefaultPerspective["perspective"])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   835
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   836
            for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   837
                for idx in xrange(notebook.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   838
                    notebook.RemovePage(0)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   839
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   840
            notebooks = self.DefaultPerspective["notebooks"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   841
            for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   842
                                         (self.BottomNoteBook, "bottomnotebook"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   843
                                         (self.RightNoteBook, "rightnotebook")]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   844
                self.LoadTabLayout(notebook, notebooks.get(entry_name))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   845
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   846
            self._Refresh(EDITORTOOLBAR)
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 RestoreLastState(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   849
        frame_size = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   850
        if self.Config.HasEntry("framesize"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   851
            frame_size = cPickle.loads(str(self.Config.Read("framesize")))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   852
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   853
        if frame_size is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   854
            self.Maximize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   855
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   856
            self.SetClientSize(frame_size)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   857
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   858
    def SaveLastState(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   859
        if not self.IsMaximized():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   860
            self.Config.Write("framesize", cPickle.dumps(self.GetClientSize()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   861
        elif self.Config.HasEntry("framesize"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   862
            self.Config.DeleteEntry("framesize")
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
        self.Config.Flush()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   865
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   866
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   867
#                               General Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   868
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   869
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   870
    def SetRefreshFunctions(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   871
        self.RefreshFunctions = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   872
            TITLE : self.RefreshTitle,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   873
            EDITORTOOLBAR : self.RefreshEditorToolBar,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   874
            FILEMENU : self.RefreshFileMenu,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   875
            EDITMENU : self.RefreshEditMenu,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   876
            DISPLAYMENU : self.RefreshDisplayMenu,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   877
            PROJECTTREE : self.RefreshProjectTree,
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   878
            POUINSTANCEVARIABLESPANEL : self.RefreshPouInstanceVariablesPanel,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   879
            LIBRARYTREE : self.RefreshLibraryPanel,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   880
            SCALING : self.RefreshScaling,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   881
            PAGETITLES: self.RefreshPageTitles}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   882
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   883
    ## Call PLCOpenEditor refresh functions.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   884
    #  @param elements List of elements to refresh.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   885
    def _Refresh(self, *elements):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   886
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   887
            for element in elements:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   888
                self.RefreshFunctions[element]()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   889
        except wx.PyDeadObjectError:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   890
            # ignore exceptions caused by refresh while quitting
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   891
            pass
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   892
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   893
    ## Callback function when AUINotebook Page closed with CloseButton
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   894
    #  @param event AUINotebook Event.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   895
    def OnPageClose(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   896
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   897
        if selected > -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   898
            window = self.TabsOpened.GetPage(selected)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   899
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   900
            if window.CheckSaveBeforeClosing():
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   901
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   902
                # Refresh all window elements that have changed
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   903
                wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   904
                wx.CallAfter(self.RefreshTabCtrlEvent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   905
                wx.CallAfter(self.CloseFindInPouDialog)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   906
                event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   907
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   908
                event.Veto()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   909
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   910
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1010
diff changeset
   911
    def GetCopyBuffer(self, primary_selection=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   912
        data = None
1028
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   913
        if primary_selection and wx.Platform == '__WXMSW__':
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   914
            return data
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   915
        else:
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   916
            wx.TheClipboard.UsePrimarySelection(primary_selection)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   917
        if wx.TheClipboard.Open():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   918
            dataobj = wx.TextDataObject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   919
            if wx.TheClipboard.GetData(dataobj):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   920
                data = dataobj.GetText()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   921
            wx.TheClipboard.Close()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   922
        return data
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   923
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1010
diff changeset
   924
    def SetCopyBuffer(self, text, primary_selection=False):
1028
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   925
        if primary_selection and wx.Platform == '__WXMSW__':
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   926
            return
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   927
        else:
0ddbc39c91ee Fixed bug with diagram copy
Laurent Bessard
parents: 1024
diff changeset
   928
            wx.TheClipboard.UsePrimarySelection(primary_selection)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   929
        if wx.TheClipboard.Open():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   930
            data = wx.TextDataObject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   931
            data.SetText(text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   932
            wx.TheClipboard.SetData(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   933
            wx.TheClipboard.Flush()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   934
            wx.TheClipboard.Close()
1087
16cc3c42e413 Fixed bug when closing Beremiz frame
Laurent Bessard
parents: 1028
diff changeset
   935
        self.RefreshEditMenu()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   936
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   937
    def GetDrawingMode(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   938
        return self.DrawingMode
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   939
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   940
    def RefreshScaling(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   941
        for i in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   942
            editor = self.TabsOpened.GetPage(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   943
            editor.RefreshScaling()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   944
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   945
    def EditProjectSettings(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   946
        old_values = self.Controler.GetProjectProperties()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   947
        dialog = ProjectDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   948
        dialog.SetValues(old_values)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   949
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   950
            new_values = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   951
            new_values["creationDateTime"] = old_values["creationDateTime"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   952
            if new_values != old_values:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   953
                self.Controler.SetProjectProperties(None, new_values)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   954
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   955
                              PROJECTTREE, POUINSTANCEVARIABLESPANEL, SCALING)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   956
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   957
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   958
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   959
#                            Notebook Unified Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   960
#-------------------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   961
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   962
    ## Function that add a tab in Notebook, calling refresh for tab DClick event
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   963
    # for wx.aui.AUINotebook.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   964
    #  @param window Panel to display in tab.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   965
    #  @param text title for the tab ctrl.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   966
    def AddPage(self, window, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   967
        self.TabsOpened.AddPage(window, text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   968
        self.RefreshTabCtrlEvent()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   969
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   970
    ## Function that add a tab in Notebook, calling refresh for tab DClick event
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   971
    # for wx.aui.AUINotebook.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   972
    #  @param window Panel to display in tab.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   973
    #  @param text title for the tab ctrl.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   974
    def DeletePage(self, window):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   975
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   976
            if self.TabsOpened.GetPage(idx) == window:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   977
                self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   978
                self.RefreshTabCtrlEvent()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   979
                return
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   980
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   981
    ## Function that fix difference in deleting all tabs between
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   982
    # wx.Notebook and wx.aui.AUINotebook.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   983
    def DeleteAllPages(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   984
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   985
            self.TabsOpened.DeletePage(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   986
        self.RefreshTabCtrlEvent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   987
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
   988
    ## Function that fix difference in setting picture on tab between
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   989
    # wx.Notebook and wx.aui.AUINotebook.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   990
    #  @param idx Tab index.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   991
    #  @param bitmap wx.Bitmap to define on tab.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   992
    #  @return True if operation succeeded
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   993
    def SetPageBitmap(self, idx, bitmap):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   994
        return self.TabsOpened.SetPageBitmap(idx, bitmap)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   995
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   996
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   997
#                         Dialog Message Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   998
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   999
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1000
    ## Function displaying an Error dialog in PLCOpenEditor.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1001
    #  @param message The message to display.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1002
    def ShowErrorMessage(self, message):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1003
        dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1004
        dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1005
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1006
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1007
    ## Function displaying an Error dialog in PLCOpenEditor.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1008
    #  @return False if closing cancelled.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1009
    def CheckSaveBeforeClosing(self, title=_("Close Project")):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1010
        if not self.Controler.ProjectIsSaved():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1011
            dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), title, wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1012
            answer = dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1013
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1014
            if answer == wx.ID_YES:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1015
                self.SaveProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1016
            elif answer == wx.ID_CANCEL:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1017
                return False
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1018
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1019
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1020
            window = self.TabsOpened.GetPage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1021
            if not window.CheckSaveBeforeClosing():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1022
                return False
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1023
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1024
        return True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1025
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1026
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1027
#                            File Menu Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1028
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1029
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1030
    def RefreshFileMenu(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1031
        pass
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1032
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1033
    def ResetView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1034
        self.DeleteAllPages()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1035
        self.ProjectTree.DeleteAllItems()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1036
        self.ProjectTree.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1037
        self.PouInstanceVariablesPanel.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1038
        self.LibraryPanel.ResetTree()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1039
        self.LibraryPanel.SetController(None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1040
        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
  1041
            self.DebugVariablePanel.ResetView()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1042
        self.Controler = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1043
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1044
    def OnCloseTabMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1045
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1046
        if selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1047
            self.TabsOpened.DeletePage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1048
            if self.TabsOpened.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1049
                new_index = min(selected, self.TabsOpened.GetPageCount() - 1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1050
                self.TabsOpened.SetSelection(new_index)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1051
        # Refresh all window elements that have changed
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1052
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1053
        self.RefreshTabCtrlEvent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1054
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1055
    def OnPageSetupMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1056
        dialog = wx.PageSetupDialog(self, self.PageSetupData)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1057
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1058
            self.PageSetupData = wx.PageSetupDialogData(dialog.GetPageSetupData())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1059
            self.PrintData = wx.PrintData(self.PageSetupData.GetPrintData())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1060
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1061
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1062
    def OnPreviewMenu(self, event):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1063
        selected = self.TabsOpened.GetSelection()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1064
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1065
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1066
            data = wx.PrintDialogData(self.PrintData)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1067
            properties = self.Controler.GetProjectProperties(window.IsDebugging())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1068
            page_size = map(int, properties["pageSize"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1069
            margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1070
            printout = GraphicPrintout(window, page_size, margins, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1071
            printout2 = GraphicPrintout(window, page_size, margins, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1072
            preview = wx.PrintPreview(printout, printout2, data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1073
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1074
            if preview.Ok():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1075
                preview_frame = wx.PreviewFrame(preview, self, _("Print preview"), style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1076
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1077
                preview_frame.Initialize()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1078
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1079
                preview_canvas = preview.GetCanvas()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1080
                preview_canvas.SetMinSize(preview_canvas.GetVirtualSize())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1081
                preview_frame.Fit()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1082
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1083
                preview_frame.Show(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1084
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1085
    def OnPrintMenu(self, event):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1086
        selected = self.TabsOpened.GetSelection()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1087
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1088
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1089
            dialog_data = wx.PrintDialogData(self.PrintData)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1090
            dialog_data.SetToPage(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1091
            properties = self.Controler.GetProjectProperties(window.IsDebugging())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1092
            page_size = map(int, properties["pageSize"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1093
            margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1094
            printer = wx.Printer(dialog_data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1095
            printout = GraphicPrintout(window, page_size, margins)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1096
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1097
            if not printer.Print(self, printout, True) and printer.GetLastError() != wx.PRINTER_CANCELLED:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1098
                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
  1099
            printout.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1100
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1101
    def OnPropertiesMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1102
        self.EditProjectSettings()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1103
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1104
    def OnQuitMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1105
        self.Close()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1106
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1107
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1108
#                            Edit Menu Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1109
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1110
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1111
    def RefreshEditMenu(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1112
        MenuToolBar = self.Panes["MenuToolBar"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1113
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1114
            selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1115
            if selected > -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1116
                window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1117
                undo, redo = window.GetBufferState()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1118
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1119
                undo, redo = self.Controler.GetBufferState()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1120
            self.EditMenu.Enable(wx.ID_UNDO, undo)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1121
            MenuToolBar.EnableTool(wx.ID_UNDO, undo)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1122
            self.EditMenu.Enable(wx.ID_REDO, redo)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1123
            MenuToolBar.EnableTool(wx.ID_REDO, redo)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1124
            #self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, True)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1125
            #self.EditMenu.Check(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1126
            #                self.Controler.IsProjectBufferEnabled())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1127
            self.EditMenu.Enable(wx.ID_FIND, selected > -1)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1128
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDNEXT,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1129
                  selected > -1 and self.SearchParams is not None)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1130
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1131
                  selected > -1 and self.SearchParams is not None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1132
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1133
            MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1134
            self.EditMenu.Enable(wx.ID_ADD, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1135
            self.EditMenu.Enable(wx.ID_DELETE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1136
            if self.TabsOpened.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1137
                self.EditMenu.Enable(wx.ID_CUT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1138
                MenuToolBar.EnableTool(wx.ID_CUT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1139
                self.EditMenu.Enable(wx.ID_COPY, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1140
                MenuToolBar.EnableTool(wx.ID_COPY, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1141
                if self.GetCopyBuffer() is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1142
                    self.EditMenu.Enable(wx.ID_PASTE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1143
                    MenuToolBar.EnableTool(wx.ID_PASTE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1144
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1145
                    self.EditMenu.Enable(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1146
                    MenuToolBar.EnableTool(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1147
                self.EditMenu.Enable(wx.ID_SELECTALL, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1148
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1149
                self.EditMenu.Enable(wx.ID_CUT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1150
                MenuToolBar.EnableTool(wx.ID_CUT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1151
                self.EditMenu.Enable(wx.ID_COPY, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1152
                MenuToolBar.EnableTool(wx.ID_COPY, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1153
                self.EditMenu.Enable(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1154
                MenuToolBar.EnableTool(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1155
                self.EditMenu.Enable(wx.ID_SELECTALL, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1156
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1157
            self.EditMenu.Enable(wx.ID_UNDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1158
            MenuToolBar.EnableTool(wx.ID_UNDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1159
            self.EditMenu.Enable(wx.ID_REDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1160
            MenuToolBar.EnableTool(wx.ID_REDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1161
            #self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1162
            self.EditMenu.Enable(wx.ID_CUT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1163
            MenuToolBar.EnableTool(wx.ID_CUT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1164
            self.EditMenu.Enable(wx.ID_COPY, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1165
            MenuToolBar.EnableTool(wx.ID_COPY, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1166
            self.EditMenu.Enable(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1167
            MenuToolBar.EnableTool(wx.ID_PASTE, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1168
            self.EditMenu.Enable(wx.ID_SELECTALL, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1169
            self.EditMenu.Enable(wx.ID_FIND, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1170
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDNEXT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1171
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUFINDPREVIOUS, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1172
            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1173
            MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1174
            self.EditMenu.Enable(wx.ID_ADD, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1175
            self.EditMenu.Enable(wx.ID_DELETE, False)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1176
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1177
    def CloseTabsWithoutModel(self, refresh=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1178
        idxs = range(self.TabsOpened.GetPageCount())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1179
        idxs.reverse()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1180
        for idx in idxs:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1181
            window = self.TabsOpened.GetPage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1182
            if window.HasNoModel():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1183
                self.TabsOpened.DeletePage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1184
        if refresh:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1185
            self.RefreshEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1186
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1187
    def OnUndoMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1188
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1189
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1190
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1191
            window.Undo()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1192
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1193
            self.Controler.LoadPrevious()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1194
        self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1195
                      SCALING, PAGETITLES)
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1196
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1197
    def OnRedoMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1198
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1199
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1200
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1201
            window.Redo()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1202
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1203
            self.Controler.LoadNext()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1204
        self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1205
                      SCALING, PAGETITLES)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1206
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1207
    def OnEnableUndoRedoMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1208
        self.Controler.EnableProjectBuffer(event.IsChecked())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1209
        self.RefreshEditMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1210
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1211
    OnCutMenu = GetShortcutKeyCallbackFunction("Cut")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1212
    OnCopyMenu = GetShortcutKeyCallbackFunction("Copy")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1213
    OnPasteMenu = GetShortcutKeyCallbackFunction("Paste")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1214
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1215
    def OnSelectAllMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1216
        control = self.FindFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1217
        if control is not None and control.GetName() == "Viewer":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1218
            control.Parent.SelectAll()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1219
        elif isinstance(control, wx.stc.StyledTextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1220
            control.SelectAll()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1221
        elif isinstance(control, wx.TextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1222
            control.SetSelection(0, control.GetLastPosition())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1223
        elif isinstance(control, wx.ComboBox):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1224
            control.SetMark(0, control.GetLastPosition() + 1)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1225
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
  1226
    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
  1227
        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
  1228
            ITEM_DATATYPE: GetDeleteElementFunction(
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1229
                    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
  1230
                    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
  1231
            ITEM_POU: GetDeleteElementFunction(
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1232
                    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
  1233
                    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
  1234
            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
  1235
                    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
  1236
            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
  1237
                    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
  1238
            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
  1239
                    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
  1240
            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
  1241
                    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
  1242
        }
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1243
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1244
    def OnDeleteMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1245
        window = self.FindFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1246
        if window == self.ProjectTree or window is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1247
            selected = self.ProjectTree.GetSelection()
1165
99972084890d Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents: 1164
diff changeset
  1248
            if selected is not None and selected.IsOk():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1249
                function = self.DeleteFunctions.get(self.ProjectTree.GetPyData(selected)["type"], None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1250
                if function is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1251
                    function(self, selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1252
                    self.CloseTabsWithoutModel()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1253
                    self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1254
                                  POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1255
        elif isinstance(window, (Viewer, TextViewer)):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1256
            event = wx.KeyEvent(wx.EVT_CHAR._getEvtType())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1257
            event.m_keyCode = wx.WXK_DELETE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1258
            window.ProcessEvent(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1259
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1260
    def OnFindMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1261
        if not self.FindDialog.IsShown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1262
            self.FindDialog.Show()
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1263
            self.FindDialog.FindPattern.SetFocus()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1264
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1265
    def CloseFindInPouDialog(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1266
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1267
        if selected == -1 and self.FindDialog.IsShown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1268
            self.FindDialog.Hide()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1269
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1270
    def OnFindNextMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1271
        self.FindInPou(1)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1272
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1273
    def OnFindPreviousMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1274
        self.FindInPou(-1)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1275
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1276
    def FindInPou(self, direction, search_params=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1277
        if search_params is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1278
            self.SearchParams = search_params
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1279
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1280
        if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1281
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1282
            window.Find(direction, self.SearchParams)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1283
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1284
    def OnSearchInProjectMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1285
        dialog = SearchInProjectDialog(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1286
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1287
            criteria = dialog.GetCriteria()
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1288
            if len(criteria) > 0:
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1289
                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
  1290
                self.ClearSearchResults()
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1530
diff changeset
  1291
                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
  1292
                self.SelectTab(self.SearchResultPanel)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1293
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1294
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1295
#                             Display Menu Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1296
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1297
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1298
    def RefreshDisplayMenu(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1299
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1300
            if self.TabsOpened.GetPageCount() > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1301
                self.DisplayMenu.Enable(wx.ID_REFRESH, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1302
                selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1303
                if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1304
                    window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1305
                    if isinstance(window, Viewer):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1306
                        self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1307
                        zoommenu = self.DisplayMenu.FindItemById(wx.ID_ZOOM_FIT).GetSubMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1308
                        zoomitem = zoommenu.FindItemByPosition(window.GetScale())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1309
                        zoomitem.Check(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1310
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1311
                        self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1312
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1313
                    self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1314
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1315
                self.DisplayMenu.Enable(wx.ID_REFRESH, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1316
                self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1317
            if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1318
                self.DisplayMenu.Enable(wx.ID_CLEAR, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1319
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1320
            self.DisplayMenu.Enable(wx.ID_REFRESH, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1321
            if self.EnableDebug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1322
                self.DisplayMenu.Enable(wx.ID_CLEAR, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1323
            self.DisplayMenu.Enable(wx.ID_ZOOM_FIT, False)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1324
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1325
    def OnRefreshMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1326
        self.RefreshEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1327
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1328
    def OnClearErrorsMenu(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1329
        self.ClearErrors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1330
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1331
    def GenerateZoomFunction(self, idx):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1332
        def ZoomFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1333
            selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1334
            if selected != -1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1335
                window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1336
                window.SetScale(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1337
                window.RefreshVisibleElements()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1338
                window.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1339
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1340
        return ZoomFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1341
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1342
    def OnResetPerspective(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1343
        self.ResetPerspective()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1344
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1345
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1346
#                      Project Editor Panels Management Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1347
#-------------------------------------------------------------------------------
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1348
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1349
    def OnPageDragged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1350
        wx.CallAfter(self.RefreshTabCtrlEvent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1351
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1352
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1353
    def OnAllowNotebookDnD(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1354
        event.Allow()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1355
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1356
    def RefreshTabCtrlEvent(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1357
        auitabctrl = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1358
        for child in self.TabsOpened.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1359
            if isinstance(child, wx.aui.AuiTabCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1360
                auitabctrl.append(child)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1361
                if child not in self.AuiTabCtrl:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1362
                    child.Bind(wx.EVT_LEFT_DCLICK, self.GetTabsOpenedDClickFunction(child))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1363
        self.AuiTabCtrl = auitabctrl
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1364
        if self.TabsOpened.GetPageCount() == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1365
            pane = self.AUIManager.GetPane(self.TabsOpened)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1366
            if pane.IsMaximized():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1367
                self.AUIManager.RestorePane(pane)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1368
            self.AUIManager.Update()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1369
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1370
    def EnsureTabVisible(self, tab):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1371
        notebook = tab.GetParent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1372
        notebook.SetSelection(notebook.GetPageIndex(tab))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1373
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1374
    def OnPouSelectedChanging(self, event):
989
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1375
        selected = self.TabsOpened.GetSelection()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1376
        if selected >= 0:
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1377
            window = self.TabsOpened.GetPage(selected)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1378
            if not window.IsDebugging():
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1379
                window.ResetBuffer()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1380
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1381
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1382
    def OnPouSelectedChanged(self, event):
989
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1383
        selected = self.TabsOpened.GetSelection()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1384
        if selected >= 0:
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1385
            window = self.TabsOpened.GetPage(selected)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1386
            tagname = window.GetTagName()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1387
            if not window.IsDebugging():
1158
193e6cd9010f Fixed bug tabs selected cyclically when drag'n dropping variable into Editor
Laurent Bessard
parents: 1129
diff changeset
  1388
                self.SelectProjectTreeItem(tagname)
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1222
diff changeset
  1389
                self.PouInstanceVariablesPanel.SetPouType(tagname)
989
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1390
                window.RefreshView()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1391
                self.EnsureTabVisible(self.LibraryPanel)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1392
            else:
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1393
                instance_path = window.GetInstancePath()
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1394
                if tagname == "":
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1395
                    instance_path = instance_path.rsplit(".", 1)[0]
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1396
                    tagname = self.Controler.GetPouInstanceTagName(instance_path, self.EnableDebug)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1397
                self.EnsureTabVisible(self.DebugVariablePanel)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1398
                wx.CallAfter(self.PouInstanceVariablesPanel.SetPouType, tagname, instance_path)
b24c11c93766 Fixed bug editors empty after being opened
Laurent Bessard
parents: 981
diff changeset
  1399
        wx.CallAfter(self._Refresh, FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1400
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1401
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1402
    def RefreshEditor(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1403
        selected = self.TabsOpened.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1404
        if selected >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1405
            window = self.TabsOpened.GetPage(selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1406
            tagname = window.GetTagName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1407
            if not window.IsDebugging():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1408
                self.SelectProjectTreeItem(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1409
                self.PouInstanceVariablesPanel.SetPouType(tagname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1410
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1411
                instance_path = window.GetInstancePath()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1412
                if tagname == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1413
                    instance_path = instance_path.rsplit(".", 1)[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1414
                    tagname = self.Controler.GetPouInstanceTagName(instance_path, self.EnableDebug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1415
                self.PouInstanceVariablesPanel.SetPouType(tagname, instance_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1416
            for child in self.TabsOpened.GetChildren():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1417
                if isinstance(child, wx.aui.AuiTabCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1418
                    active_page = child.GetActivePage()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1419
                    if active_page >= 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1420
                        window = child.GetWindowFromIdx(active_page)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1421
                        window.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1422
            self._Refresh(FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1423
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1424
    def RefreshEditorNames(self, old_tagname, new_tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1425
        for i in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1426
            editor = self.TabsOpened.GetPage(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1427
            if editor.GetTagName() == old_tagname:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1428
                editor.SetTagName(new_tagname)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1401
diff changeset
  1429
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1430
    def IsOpened(self, tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1431
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1432
            if self.TabsOpened.GetPage(idx).IsViewing(tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1433
                return idx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1434
        return None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1435
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1436
    def RefreshPageTitles(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1437
        for idx in xrange(self.TabsOpened.GetPageCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1438
            window = self.TabsOpened.GetPage(idx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1439
            icon = window.GetIcon()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1440
            if icon is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1441
                self.SetPageBitmap(idx, icon)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1442
            self.TabsOpened.SetPageText(idx, window.GetTitle())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1443
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1444
    def GetTabsOpenedDClickFunction(self, tabctrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1445
        def OnTabsOpenedDClick(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1446
            pos = event.GetPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1447
            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
  1448
                self.SwitchFullScrMode(event)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1449
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1450
        return OnTabsOpenedDClick
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1451
1530
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1452
    def SwitchFullScrMode(self,evt):
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1453
        pane = self.AUIManager.GetPane(self.TabsOpened)
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1454
        if pane.IsMaximized():
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1455
            self.AUIManager.RestorePane(pane)
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1456
        else:
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1457
            self.AUIManager.MaximizePane(pane)
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1458
        self.AUIManager.Update()
24d8e8c233bd Add hotkey (F12) for switching perspective.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1514
diff changeset
  1459
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1460
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1461
#                         Types Tree Management Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1462
#-------------------------------------------------------------------------------