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