BeremizIDE.py
author Edouard Tisserant <edouard@beremiz.fr>
Fri, 11 Oct 2024 10:34:15 +0200
changeset 4026 a3cf9f635952
parent 3909 c29a95aebfbf
permissions -rw-r--r--
SVGHMI: add ForEach widget example
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     3
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     6
#
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     8
# Copyright (C) 2016: Andrey Skvortsov <andrej.skvortzov@gmail.com>
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     9
#
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    10
# See COPYING file for copyrights details.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    11
#
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    12
# This program is free software; you can redistribute it and/or
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    13
# modify it under the terms of the GNU General Public License
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    14
# as published by the Free Software Foundation; either version 2
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    15
# of the License, or (at your option) any later version.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    16
#
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    17
# This program is distributed in the hope that it will be useful,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    20
# GNU General Public License for more details.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    21
#
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    22
# You should have received a copy of the GNU General Public License
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    23
# along with this program; if not, write to the Free Software
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    25
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    26
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    27
import os
3758
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
    28
import pickle
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    29
import sys
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    30
import shutil
1834
cd42b426028b fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    31
import time
3712
cea2005bf2c9 IDE: When receiving SIGTERM signal, kill runtime befor bailing out without saving.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3588
diff changeset
    32
import signal
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    33
from time import time as gettime
3833
73a44957c381 IDE: fix py3/wxpy4 related deprecation warnings
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3789
diff changeset
    34
from threading import Lock, Timer, current_thread
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    35
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    36
import wx.lib.buttons
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    37
import wx.lib.statbmp
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    38
import wx.stc
3570
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
    39
import wx.adv
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    40
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    41
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1831
diff changeset
    42
import version
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    43
from editors.EditorPanel import EditorPanel
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    44
from editors.Viewer import Viewer
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    45
from editors.TextViewer import TextViewer
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    46
from editors.ResourceEditor import ConfigurationEditor, ResourceEditor
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    47
from editors.DataTypeEditor import DataTypeEditor
3906
f831ff63ca6e IDE: display contents of revisions.txt (put there by installer builder script) in About Dialog.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3833
diff changeset
    48
from util.paths import Bpath, ThirdPartyPath
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    49
from util.MiniTextControler import MiniTextControler
1834
cd42b426028b fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    50
from util.BitmapLibrary import GetBitmap
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    51
from controls.LogViewer import LogViewer
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    52
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    53
from controls import EnhancedStatusBar as esb
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    54
from dialogs.AboutDialog import ShowAboutDialog
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
1948
b9a3f771aaab Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents: 1933
diff changeset
    56
from plcopen.types_enums import \
b9a3f771aaab Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents: 1933
diff changeset
    57
    ComputeConfigurationName, \
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
    58
    LOCATION_CONFNODE, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    59
    LOCATION_MODULE, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    60
    LOCATION_GROUP, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    61
    LOCATION_VAR_INPUT, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    62
    LOCATION_VAR_OUTPUT, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    63
    LOCATION_VAR_MEMORY, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    64
    ITEM_PROJECT, \
1948
b9a3f771aaab Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents: 1933
diff changeset
    65
    ITEM_RESOURCE, \
b9a3f771aaab Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents: 1933
diff changeset
    66
    ITEM_CONFNODE
b9a3f771aaab Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents: 1933
diff changeset
    67
b9a3f771aaab Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents: 1933
diff changeset
    68
from ProjectController import ProjectController, GetAddMenuItems, MATIEC_ERROR_MODEL
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    69
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
    70
from IDEFrame import \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    71
    TITLE,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    72
    EDITORTOOLBAR,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    73
    FILEMENU,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    74
    EDITMENU,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    75
    DISPLAYMENU,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    76
    PROJECTTREE,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    77
    POUINSTANCEVARIABLESPANEL,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    78
    LIBRARYTREE,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    79
    PAGETITLES,\
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    80
    IDEFrame, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    81
    EncodeFileSystemPath, \
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    82
    DecodeFileSystemPath
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    83
3501
fa291393aac7 Added preliminary CLI. Supports building a project, transfering and running on PLC.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3445
diff changeset
    84
from LocalRuntimeMixin import LocalRuntimeMixin
fa291393aac7 Added preliminary CLI. Supports building a project, transfering and running on PLC.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3445
diff changeset
    85
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
    86
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: 2735
diff changeset
    87
def AppendMenu(parent, help, id, kind, text):
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: 2740
diff changeset
    88
    return parent.Append(wx.MenuItem(helpString=help, id=id, kind=kind, text=text))
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    89
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    90
MAX_RECENT_PROJECTS = 9
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    91
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
    92
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    93
if wx.Platform == '__WXMSW__':
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    94
    faces = {
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
    95
        'mono': 'Courier New',
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
    96
        'size': 8,
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    97
    }
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    98
else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    99
    faces = {
2704
4ba3bdc7d71f Fix unmatched "Courier" font for monospace fonts on latest ubuntu 20.04. Selected "FreeMono" instead, present since at least 18.04
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2624
diff changeset
   100
        'mono': 'FreeMono',
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   101
        'size': 10,
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   102
    }
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   103
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
   104
3833
73a44957c381 IDE: fix py3/wxpy4 related deprecation warnings
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3789
diff changeset
   105
MainThread = current_thread().ident
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   106
REFRESH_PERIOD = 0.1
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   107
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   108
1831
56b48961cc68 fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1829
diff changeset
   109
class LogPseudoFile(object):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   110
    """ Base class for file like objects to facilitate StdOut for the Shell."""
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3405
diff changeset
   111
    def __init__(self, output, risecall, logf):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   112
        self.red_white = 1
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   113
        self.red_yellow = 2
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   114
        self.black_white = wx.stc.STC_STYLE_DEFAULT
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   115
        self.output = output
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   116
        self.risecall = risecall
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   117
        # to prevent rapid fire on rising log panel
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   118
        self.rising_timer = 0
2728
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   119
        self.StackLock = Lock()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   120
        self.YieldLock = Lock()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   121
        self.RefreshLock = Lock()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   122
        self.TimerAccessLock = Lock()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   123
        self.stack = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   124
        self.LastRefreshTime = gettime()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   125
        self.LastRefreshTimer = None
2730
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   126
        self.refreshPending = False
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3405
diff changeset
   127
        self.logf = logf
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   128
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   129
    def write(self, s, style=None):
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3405
diff changeset
   130
        if self.logf is not None:
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3405
diff changeset
   131
            self.logf.write(s)
3437
ce366d67a5b7 Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3424
diff changeset
   132
            self.logf.flush()
2728
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   133
        self.StackLock.acquire()
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   134
        self.stack.append((s, style))
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   135
        self.StackLock.release()
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   136
        current_time = gettime()
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   137
        with self.TimerAccessLock:
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   138
            if self.LastRefreshTimer is not None:
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   139
                self.LastRefreshTimer.cancel()
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   140
                self.LastRefreshTimer = None
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   141
        elapsed = current_time - self.LastRefreshTime
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   142
        if elapsed > REFRESH_PERIOD:
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   143
            self._should_write()
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   144
        else:
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   145
            with self.TimerAccessLock:
2728
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   146
                if self.LastRefreshTimer is None:
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   147
                    self.LastRefreshTimer = Timer(REFRESH_PERIOD - elapsed, self._timer_expired)
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   148
                    self.LastRefreshTimer.start()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   149
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   150
    def _timer_expired(self):
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   151
        self._should_write()
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   152
        with self.TimerAccessLock:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   153
            self.LastRefreshTimer = None
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   154
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   155
    def _should_write(self):
3833
73a44957c381 IDE: fix py3/wxpy4 related deprecation warnings
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3789
diff changeset
   156
        if MainThread == current_thread().ident:
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   157
            app = wx.GetApp()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   158
            if app is not None:
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   159
                self._write()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   160
                if self.YieldLock.acquire(0):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   161
                    app.Yield()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   162
                    self.YieldLock.release()
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   163
        else:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   164
            with self.RefreshLock:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   165
                if not self.refreshPending:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   166
                    self.refreshPending = True
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   167
                    wx.CallAfter(self._write)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   168
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   169
    def _write(self):
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   170
        if self.output:
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   171
            with self.RefreshLock:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   172
                self.output.Freeze()
2728
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   173
                self.output.AnnotationClearAll()
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   174
                self.StackLock.acquire()
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   175
                for s, style in self.stack:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   176
                    if style is None:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   177
                        style = self.black_white
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   178
                    if style != self.black_white:
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: 2740
diff changeset
   179
                        self.output.StartStyling(self.output.GetLength())
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   180
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   181
                    # Temporary deactivate read only mode on StyledTextCtrl for
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   182
                    # adding text. It seems that text modifications, even
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   183
                    # programmatically, are disabled in StyledTextCtrl when read
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   184
                    # only is active
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   185
                    start_pos = self.output.GetLength()
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   186
                    self.output.SetReadOnly(False)
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   187
                    self.output.AppendText(s)
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   188
                    self.output.SetReadOnly(True)
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   189
                    text_len = self.output.GetLength() - start_pos
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   190
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   191
                    if style != self.black_white:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   192
                        self.output.SetStyling(text_len, style)
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   193
                self.stack = []
2728
10d8ca7a3d31 IDE: Log: Cosmetic changes, refactoring
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2726
diff changeset
   194
                self.StackLock.release()
2731
c6a55270d468 IDE: Fix logging of external process execution time so that it is visible on windows as well.
Edouard Tisserant
parents: 2730
diff changeset
   195
                self.output.ScrollToEnd()
2726
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   196
                self.output.Thaw()
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   197
                self.LastRefreshTime = gettime()
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   198
                newtime = time.time()
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   199
                if newtime - self.rising_timer > 1:
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   200
                    self.risecall(self.output)
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   201
                self.rising_timer = newtime
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   202
                self.refreshPending = False
c465414017a2 IDE: Fixed log console that was not updating line by line smoothly when building.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2704
diff changeset
   203
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   204
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   205
    def write_warning(self, s):
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   206
        self.write(s, self.red_white)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   207
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   208
    def write_error(self, s):
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   209
        self.write(s, self.red_yellow)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   210
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   211
    def flush(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   212
        # Temporary deactivate read only mode on StyledTextCtrl for clearing
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   213
        # text. It seems that text modifications, even programmatically, are
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   214
        # disabled in StyledTextCtrl when read only is active
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   215
        self.output.SetReadOnly(False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   216
        self.output.SetText("")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   217
        self.output.SetReadOnly(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   218
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   219
    def isatty(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   220
        return False
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   221
2730
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   222
    def progress(self, text):
2740
610801fe1b88 IDE: Log: Prevent crash when display progress on empty log.
Edouard Tisserant
parents: 2737
diff changeset
   223
        l = max(self.output.GetLineCount()-2, 0)
2730
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   224
        self.output.AnnotationSetText(l, text)
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   225
        self.output.AnnotationSetVisible(wx.stc.STC_ANNOTATION_BOXED)
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   226
        self.output.AnnotationSetStyle(l, self.black_white)
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   227
        if self.YieldLock.acquire(0):
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   228
            app = wx.GetApp()
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   229
            app.Yield()
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   230
            self.YieldLock.release()
ce21ce181fdb IDE: Process Logging : Add annotation in log so that user can see build is still alive and how long external process takes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2728
diff changeset
   231
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
   232
3766
f99def63cdd8 Update to wx.NewIdRef()
GP Orcullo <kinsamanka@gmail.com>
parents: 3758
diff changeset
   233
ID_FILEMENURECENTPROJECTS = wx.NewIdRef()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   234
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   235
3501
fa291393aac7 Added preliminary CLI. Supports building a project, transfering and running on PLC.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3445
diff changeset
   236
class Beremiz(IDEFrame, LocalRuntimeMixin):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   237
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   238
    def _init_utils(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   239
        self.ConfNodeMenu = wx.Menu(title='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   240
        self.RecentProjectsMenu = wx.Menu(title='')
3351
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   241
        self.TutorialsProjectsMenu = wx.Menu(title='')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   242
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   243
        IDEFrame._init_utils(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   244
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   245
    def _init_coll_FileMenu_Items(self, parent):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   246
        AppendMenu(parent, help='', id=wx.ID_NEW,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   247
                   kind=wx.ITEM_NORMAL, text=_('New') + '\tCTRL+N')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   248
        AppendMenu(parent, help='', id=wx.ID_OPEN,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   249
                   kind=wx.ITEM_NORMAL, text=_('Open') + '\tCTRL+O')
3833
73a44957c381 IDE: fix py3/wxpy4 related deprecation warnings
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3789
diff changeset
   250
        self.RecentProjectsMenuItem = parent.AppendSubMenu(self.RecentProjectsMenu, _("&Recent Projects"))
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   251
        parent.AppendSeparator()
3833
73a44957c381 IDE: fix py3/wxpy4 related deprecation warnings
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3789
diff changeset
   252
        parent.AppendSubMenu(self.TutorialsProjectsMenu, _("&Tutorials and Examples"))
3351
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   253
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   254
        exemples_dir = Bpath("exemples")
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   255
        project_list = sorted(os.listdir(exemples_dir))
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   256
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   257
        for idx, dirname  in enumerate(project_list):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   258
            text = '&%d: %s' % (idx + 1, dirname)
3351
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   259
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   260
            item = self.TutorialsProjectsMenu.Append(wx.ID_ANY, text, '')
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   261
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   262
            projectpath = os.path.join(exemples_dir, dirname)
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   263
3390
6532d7a1a3b5 IDE: Tutorial/Example menu was broken : path of project being open was the same for all menu entries.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3368
diff changeset
   264
            def OpenExemple(event, projectpath=projectpath):
3351
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   265
                if self.CTR is not None and not self.CheckSaveBeforeClosing():
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   266
                    return
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   267
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   268
                self.OpenProject(projectpath)
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   269
                if not self.CTR.CheckProjectPathPerm():
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   270
                    self.ResetView()
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   271
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   272
            self.Bind(wx.EVT_MENU, OpenExemple, item)
88dbdebd10fc IDE: Add a "Tutorials and Examples" sub menu to "File" menu to directly open projects in /exemples directory. Move 'python' and 'first_steps' projecvts from /tests to /exemple
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3350
diff changeset
   273
        parent.AppendSeparator()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   274
        AppendMenu(parent, help='', id=wx.ID_SAVE,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   275
                   kind=wx.ITEM_NORMAL, text=_('Save') + '\tCTRL+S')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   276
        AppendMenu(parent, help='', id=wx.ID_SAVEAS,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   277
                   kind=wx.ITEM_NORMAL, text=_('Save as') + '\tCTRL+SHIFT+S')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   278
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   279
                   kind=wx.ITEM_NORMAL, text=_('Close Tab') + '\tCTRL+W')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   280
        AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   281
                   kind=wx.ITEM_NORMAL, text=_('Close Project') + '\tCTRL+SHIFT+W')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   282
        parent.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   283
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   284
                   kind=wx.ITEM_NORMAL, text=_('Page Setup') + '\tCTRL+ALT+P')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   285
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   286
                   kind=wx.ITEM_NORMAL, text=_('Preview') + '\tCTRL+SHIFT+P')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   287
        AppendMenu(parent, help='', id=wx.ID_PRINT,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   288
                   kind=wx.ITEM_NORMAL, text=_('Print') + '\tCTRL+P')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   289
        parent.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   290
        AppendMenu(parent, help='', id=wx.ID_EXIT,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   291
                   kind=wx.ITEM_NORMAL, text=_('Quit') + '\tCTRL+Q')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   292
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   293
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   294
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   295
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   296
        self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   297
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   298
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   299
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   300
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   301
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   302
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   303
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   304
        self.AddToMenuToolBar([(wx.ID_NEW, "new", _('New'), None),
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   305
                               (wx.ID_OPEN, "open", _('Open'), None),
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   306
                               (wx.ID_SAVE, "save", _('Save'), None),
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   307
                               (wx.ID_SAVEAS, "saveas", _('Save As...'), None),
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   308
                               (wx.ID_PRINT, "print", _('Print'), None)])
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   309
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   310
    def _RecursiveAddMenuItems(self, menu, items):
2569
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
   311
        for name, text, helpstr, children in items:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   312
            if len(children) > 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   313
                new_menu = 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: 2740
diff changeset
   314
                menu.AppendSubMenu(new_menu, text)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   315
                self._RecursiveAddMenuItems(new_menu, children)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   316
            else:
3336
3860a6ad6998 IDE: fix wxpython4 sequel : project "add" menu was having no extension entry visible.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3318
diff changeset
   317
                item = menu.Append(wx.MenuItem(text=text, helpString=helpstr, kind=wx.ITEM_NORMAL, id=wx.ID_ANY))
2569
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
   318
                self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name), item)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   319
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   320
    def _init_coll_AddMenu_Items(self, parent):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   321
        IDEFrame._init_coll_AddMenu_Items(self, parent, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   322
        self._RecursiveAddMenuItems(parent, GetAddMenuItems())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   323
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   324
    def _init_coll_HelpMenu_Items(self, parent):
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   325
        def handler(event):
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   326
            return wx.MessageBox(
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   327
                version.GetCommunityHelpMsg(),
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   328
                _('Community support'),
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   329
                wx.OK | wx.ICON_INFORMATION)
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
   330
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   331
        item = parent.Append(wx.ID_ANY, _('Community support'), '')
2569
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
   332
        self.Bind(wx.EVT_MENU, handler, item)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1721
diff changeset
   333
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: 2740
diff changeset
   334
        parent.Append(wx.MenuItem(helpString='', id=wx.ID_ABOUT,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   335
                      kind=wx.ITEM_NORMAL, text=_('About')))
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   336
        self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   337
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   338
    def _init_coll_ConnectionStatusBar_Fields(self, parent):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   339
        parent.SetFieldsCount(3)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   340
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: 2740
diff changeset
   341
        parent.SetStatusText(i=0, text='')
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: 2740
diff changeset
   342
        parent.SetStatusText(i=1, text='')
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: 2740
diff changeset
   343
        parent.SetStatusText(i=2, text='')
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   344
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   345
        parent.SetStatusWidths([-1, 300, 200])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   346
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   347
    def _init_ctrls(self, prnt):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   348
        IDEFrame._init_ctrls(self, prnt)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   349
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   350
        self.EditMenuSize = self.EditMenu.GetMenuItemCount()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   351
3766
f99def63cdd8 Update to wx.NewIdRef()
GP Orcullo <kinsamanka@gmail.com>
parents: 3758
diff changeset
   352
        inspectorID = wx.NewIdRef()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   353
        self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=inspectorID)
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   354
        accels = [wx.AcceleratorEntry(wx.ACCEL_CTRL | wx.ACCEL_ALT, ord('I'), inspectorID)]
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   355
3445
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   356
        self.methodLock = Lock()
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   357
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   358
        for method, shortcut in [("Stop",     wx.WXK_F4),
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   359
                                 ("Run",      wx.WXK_F5),
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   360
                                 ("Transfer", wx.WXK_F6),
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   361
                                 ("Connect",  wx.WXK_F7),
2735
732d112dd902 IDE: Add a shortcut to project "Clean" action : F9
Edouard Tisserant
parents: 2731
diff changeset
   362
                                 ("Clean",    wx.WXK_F9),
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   363
                                 ("Build",    wx.WXK_F11)]:
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   364
            def OnMethodGen(obj, meth):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   365
                def OnMethod(evt):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   366
                    if obj.CTR is not None:
3445
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   367
                        if obj.methodLock.acquire(False):
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   368
                            obj.CTR.CallMethod('_'+meth)
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   369
                            obj.methodLock.release()
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   370
                            wx.CallAfter(obj.RefreshStatusToolBar)
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   371
                        else:
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   372
                            # Postpone call if one of method already running
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   373
                            # can happen because of long method using log, 
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   374
                            # itself calling wx.Yield
83545348403e IDE: Postpone execution of keyboard shortcut commands when given while previous command is still being executed, to prevent CTR/builder jamming.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   375
                            wx.CallLater(50, OnMethod, evt)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   376
                return OnMethod
3766
f99def63cdd8 Update to wx.NewIdRef()
GP Orcullo <kinsamanka@gmail.com>
parents: 3758
diff changeset
   377
            newid = wx.NewIdRef()
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   378
            self.Bind(wx.EVT_MENU, OnMethodGen(self, method), id=newid)
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   379
            accels += [wx.AcceleratorEntry(wx.ACCEL_NORMAL, shortcut, newid)]
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   380
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   381
        self.SetAcceleratorTable(wx.AcceleratorTable(accels))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   382
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   383
        self.LogConsole = CustomStyledTextCtrl(
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   384
            name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   385
            size=wx.Size(0, 0))
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   386
        self.LogConsole.Bind(wx.EVT_SET_FOCUS, self.OnLogConsoleFocusChanged)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   387
        self.LogConsole.Bind(wx.EVT_KILL_FOCUS, self.OnLogConsoleFocusChanged)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   388
        self.LogConsole.Bind(wx.stc.EVT_STC_UPDATEUI, self.OnLogConsoleUpdateUI)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   389
        self.LogConsole.SetReadOnly(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   390
        self.LogConsole.SetWrapMode(wx.stc.STC_WRAP_CHAR)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   391
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   392
        # Define Log Console styles
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   393
        self.LogConsole.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   394
        self.LogConsole.StyleClearAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   395
        self.LogConsole.StyleSetSpec(1, "face:%(mono)s,fore:#FF0000,size:%(size)d" % faces)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   396
        self.LogConsole.StyleSetSpec(2, "face:%(mono)s,fore:#FF0000,back:#FFFF00,size:%(size)d" % faces)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   397
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   398
        # Define Log Console markers
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   399
        self.LogConsole.SetMarginSensitive(1, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   400
        self.LogConsole.SetMarginType(1, wx.stc.STC_MARGIN_SYMBOL)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   401
        self.LogConsole.MarkerDefine(0, wx.stc.STC_MARK_CIRCLE, "BLACK", "RED")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   402
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   403
        self.LogConsole.SetModEventMask(wx.stc.STC_MOD_INSERTTEXT)
3424
7db96e011fe7 Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3423
diff changeset
   404
        self.LogConsole.SetCaretPeriod(0)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   405
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   406
        self.LogConsole.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnLogConsoleMarginClick)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   407
        self.LogConsole.Bind(wx.stc.EVT_STC_MODIFIED, self.OnLogConsoleModified)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   408
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   409
        self.MainTabs["LogConsole"] = (self.LogConsole, _("Console"))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   410
        self.BottomNoteBook.AddPage(*self.MainTabs["LogConsole"])
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   411
        # self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogConsole), wx.RIGHT)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   412
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   413
        self.LogViewer = LogViewer(self.BottomNoteBook, self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   414
        self.MainTabs["LogViewer"] = (self.LogViewer, _("PLC Log"))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   415
        self.BottomNoteBook.AddPage(*self.MainTabs["LogViewer"])
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
   416
        # self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogViewer), wx.RIGHT)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   417
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   418
        StatusToolBar = wx.ToolBar(self, -1, 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: 3586
diff changeset
   419
                                   wx.TB_FLAT | wx.TB_HORIZONTAL | wx.NO_BORDER)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   420
        StatusToolBar.SetToolBitmapSize(wx.Size(25, 25))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   421
        StatusToolBar.Realize()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   422
        self.Panes["StatusToolBar"] = StatusToolBar
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   423
        self.AUIManager.AddPane(StatusToolBar, wx.aui.AuiPaneInfo().
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   424
                                Name("StatusToolBar").Caption(_("Status ToolBar")).
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   425
                                ToolbarPane().Top().Position(1).
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   426
                                LeftDockable(False).RightDockable(False))
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   427
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   428
        self.AUIManager.Update()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   429
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: 2740
diff changeset
   430
        self.ConnectionStatusBar = esb.EnhancedStatusBar(self, style=wx.STB_SIZEGRIP)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   431
        self._init_coll_ConnectionStatusBar_Fields(self.ConnectionStatusBar)
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   432
        self.ProgressStatusBar = wx.Gauge(self.ConnectionStatusBar, -1, range=100)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1721
diff changeset
   433
        self.ConnectionStatusBar.AddWidget(self.ProgressStatusBar, esb.ESB_EXACT_FIT, esb.ESB_EXACT_FIT, 2)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   434
        self.ProgressStatusBar.Hide()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   435
        self.SetStatusBar(self.ConnectionStatusBar)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   436
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   437
    def __init_execute_path(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   438
        if os.name == 'nt':
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   439
            # on windows, desktop shortcut launches Beremiz.py
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   440
            # with working dir set to mingw/bin.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   441
            # then we prefix CWD to PATH in order to ensure that
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   442
            # commands invoked by build process by default are
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   443
            # found here.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   444
            os.environ["PATH"] = os.getcwd()+';'+os.environ["PATH"]
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1721
diff changeset
   445
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3405
diff changeset
   446
    def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True, logf=None):
3501
fa291393aac7 Added preliminary CLI. Supports building a project, transfering and running on PLC.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3445
diff changeset
   447
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   448
        # Add beremiz's icon in top left corner of the frame
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   449
        self.icon = wx.Icon(Bpath("images", "brz.ico"), wx.BITMAP_TYPE_ICO)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   450
        self.__init_execute_path()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1721
diff changeset
   451
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   452
        IDEFrame.__init__(self, parent, debug)
3423
84afcc0ebadd IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3405
diff changeset
   453
        self.Log = LogPseudoFile(self.LogConsole, self.SelectTab, logf)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   454
3502
a35bf9c585cf Fix typos breaking IDE
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3501
diff changeset
   455
        LocalRuntimeMixin.__init__(self, self.Log)
a35bf9c585cf Fix typos breaking IDE
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3501
diff changeset
   456
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   457
        self.LastPanelSelected = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   458
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   459
        # Define Tree item icon list
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   460
        self.LocationImageList = wx.ImageList(16, 16)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   461
        self.LocationImageDict = {}
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   462
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   463
        # Icons for location items
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   464
        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: 1762
diff changeset
   465
                ("CONFIGURATION", LOCATION_CONFNODE),
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   466
                ("RESOURCE",      LOCATION_MODULE),
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   467
                ("PROGRAM",       LOCATION_GROUP),
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   468
                ("VAR_INPUT",     LOCATION_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: 1762
diff changeset
   469
                ("VAR_OUTPUT",    LOCATION_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: 1762
diff changeset
   470
                ("VAR_LOCAL",     LOCATION_VAR_MEMORY)]:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   471
            self.LocationImageDict[itemtype] = self.LocationImageList.Add(GetBitmap(imgname))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   472
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   473
        # Icons for other items
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   474
        for imgname, itemtype in [
1769
4665ba25a0ba clean-up: fix PEP8 E125 continuation line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   475
                ("Extension", ITEM_CONFNODE)]:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   476
            self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   477
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   478
        if projectOpen is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   479
            projectOpen = DecodeFileSystemPath(projectOpen, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   480
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   481
        if projectOpen is not None and os.path.isdir(projectOpen):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   482
            self.CTR = ProjectController(self, self.Log)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   483
            self.Controler = self.CTR
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   484
            result, _err = self.CTR.LoadProject(projectOpen, buildpath)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   485
            if not result:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   486
                self.LibraryPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   487
                self.ProjectTree.Enable(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   488
                self.PouInstanceVariablesPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   489
                self.RefreshConfigRecentProjects(os.path.abspath(projectOpen))
1933
cef288644088 Factorized duplicated code
Edouard Tisserant
parents: 1927
diff changeset
   490
                self.RefreshAfterLoad()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   491
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   492
                self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   493
                self.ShowErrorMessage(result)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   494
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   495
            self.CTR = ctr
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   496
            self.Controler = ctr
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   497
            if ctr is not None:
1933
cef288644088 Factorized duplicated code
Edouard Tisserant
parents: 1927
diff changeset
   498
                ctr.SetAppFrame(self, self.Log)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   499
                self.LibraryPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   500
                self.ProjectTree.Enable(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   501
                self.PouInstanceVariablesPanel.SetController(self.Controler)
1933
cef288644088 Factorized duplicated code
Edouard Tisserant
parents: 1927
diff changeset
   502
                self.RefreshAfterLoad()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   503
        if self.EnableDebug:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   504
            self.DebugVariablePanel.SetDataProducer(self.CTR)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   505
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   506
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   507
        self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   508
        self.LogConsole.SetFocus()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   509
3712
cea2005bf2c9 IDE: When receiving SIGTERM signal, kill runtime befor bailing out without saving.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3588
diff changeset
   510
        signal.signal(signal.SIGTERM,self.signalTERM_handler)
cea2005bf2c9 IDE: When receiving SIGTERM signal, kill runtime befor bailing out without saving.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3588
diff changeset
   511
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   512
    def RefreshTitle(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   513
        name = _("Beremiz")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   514
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   515
            projectname = self.CTR.GetProjectName()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   516
            if self.CTR.ProjectTestModified():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   517
                projectname = "~%s~" % projectname
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   518
            self.SetTitle("%s - %s" % (name, projectname))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   519
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   520
            self.SetTitle(name)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   521
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   522
    def OnOpenWidgetInspector(self, evt):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   523
        # Activate the widget inspection tool
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   524
        from wx.lib.inspection import InspectionTool
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   525
        if not InspectionTool().initialized:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   526
            InspectionTool().Init()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   527
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   528
        # Find a widget to be selected in the tree.  Use either the
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   529
        # one under the cursor, if any, or this frame.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   530
        wnd = wx.FindWindowAtPointer()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   531
        if not wnd:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   532
            wnd = self
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   533
        InspectionTool().Show(wnd, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   534
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   535
    def OnLogConsoleFocusChanged(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   536
        self.RefreshEditMenu()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   537
        event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   538
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   539
    def OnLogConsoleUpdateUI(self, event):
3564
d2ca25a2d5d9 IDE: fix primary buffer selection being reset on each write to console on X11.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3502
diff changeset
   540
        if event.GetUpdated()==wx.stc.STC_UPDATE_SELECTION:
d2ca25a2d5d9 IDE: fix primary buffer selection being reset on each write to console on X11.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3502
diff changeset
   541
            self.SetCopyBuffer(self.LogConsole.GetSelectedText(), True)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   542
        event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   543
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   544
    def OnLogConsoleMarginClick(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   545
        line_idx = self.LogConsole.LineFromPosition(event.GetPosition())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   546
        wx.CallAfter(self.SearchLineForError, self.LogConsole.GetLine(line_idx))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   547
        event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   548
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   549
    def OnLogConsoleModified(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   550
        line_idx = self.LogConsole.LineFromPosition(event.GetPosition())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   551
        line = self.LogConsole.GetLine(line_idx)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   552
        if line:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   553
            result = MATIEC_ERROR_MODEL.match(line)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   554
            if result is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   555
                self.LogConsole.MarkerAdd(line_idx, 0)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   556
        event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   557
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   558
    def SearchLineForError(self, line):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   559
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   560
            result = MATIEC_ERROR_MODEL.match(line)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   561
            if result is not None:
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   562
                first_line, first_column, last_line, last_column, _error = result.groups()
1846
14b40afccd69 remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   563
                self.CTR.ShowError(self.Log,
14b40afccd69 remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   564
                                   (int(first_line), int(first_column)),
14b40afccd69 remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   565
                                   (int(last_line),  int(last_column)))
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   566
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   567
    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: 1780
diff changeset
   568
        """Function displaying an Error dialog in PLCOpenEditor.
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   569
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   570
        :returns: False if closing cancelled.
b112bfdde5cc clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   571
        """
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   572
        if self.CTR.ProjectTestModified():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   573
            dialog = wx.MessageDialog(self,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   574
                                      _("There are changes, do you want to save?"),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   575
                                      title,
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   576
                                      wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   577
            answer = dialog.ShowModal()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   578
            dialog.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   579
            if answer == wx.ID_YES:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   580
                self.CTR.SaveProject()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   581
            elif answer == wx.ID_CANCEL:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   582
                return False
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   583
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   584
        for idx in range(self.TabsOpened.GetPageCount()):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   585
            window = self.TabsOpened.GetPage(idx)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   586
            if not window.CheckSaveBeforeClosing():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   587
                return False
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   588
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   589
        return True
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   590
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   591
    def GetTabInfos(self, tab):
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   592
        if isinstance(tab, EditorPanel) and \
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   593
           not isinstance(tab, (Viewer,
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   594
                                TextViewer,
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   595
                                ResourceEditor,
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   596
                                ConfigurationEditor,
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
   597
                                DataTypeEditor)):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   598
            return ("confnode", tab.Controler.CTNFullName(), tab.GetTagName())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   599
        elif (isinstance(tab, TextViewer) and
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   600
              (tab.Controler is None or isinstance(tab.Controler, MiniTextControler))):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   601
            return ("confnode", None, tab.GetInstancePath())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   602
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   603
            return IDEFrame.GetTabInfos(self, tab)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   604
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   605
    def LoadTab(self, notebook, page_infos):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   606
        if page_infos[0] == "confnode":
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   607
            if page_infos[1] is None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   608
                confnode = self.CTR
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   609
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   610
                confnode = self.CTR.GetChildByName(page_infos[1])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   611
            return notebook.GetPageIndex(confnode._OpenView(*page_infos[2:]))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   612
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   613
            return IDEFrame.LoadTab(self, notebook, page_infos)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   614
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   615
    # Strange hack required by WAMP connector, using twisted.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   616
    # Twisted reactor needs to be stopped only before quit,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   617
    # since it cannot be restarted
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   618
    ToDoBeforeQuit = []
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1750
diff changeset
   619
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   620
    def AddToDoBeforeQuit(self, Thing):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   621
        self.ToDoBeforeQuit.append(Thing)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   622
2483
6a7f92b84855 Split IDE's frame OnCloseFrame() into TryCloseFrame() and OnCloseFrame(), to help further customization
Edouard Tisserant
parents: 2459
diff changeset
   623
    def TryCloseFrame(self):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   624
        if self.CTR is None or self.CheckSaveBeforeClosing(_("Close Application")):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   625
            if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   626
                self.CTR.KillDebugThread()
3348
cfac764413dd IDE/windows: Avoid exception on quit caused by runtime being killed without disconnecting.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2740
diff changeset
   627
                self.CTR._Disconnect()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   628
            self.KillLocalRuntime()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   629
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   630
            self.SaveLastState()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   631
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   632
            for Thing in self.ToDoBeforeQuit:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   633
                Thing()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   634
            self.ToDoBeforeQuit = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   635
2483
6a7f92b84855 Split IDE's frame OnCloseFrame() into TryCloseFrame() and OnCloseFrame(), to help further customization
Edouard Tisserant
parents: 2459
diff changeset
   636
            return True
6a7f92b84855 Split IDE's frame OnCloseFrame() into TryCloseFrame() and OnCloseFrame(), to help further customization
Edouard Tisserant
parents: 2459
diff changeset
   637
        return False
6a7f92b84855 Split IDE's frame OnCloseFrame() into TryCloseFrame() and OnCloseFrame(), to help further customization
Edouard Tisserant
parents: 2459
diff changeset
   638
6a7f92b84855 Split IDE's frame OnCloseFrame() into TryCloseFrame() and OnCloseFrame(), to help further customization
Edouard Tisserant
parents: 2459
diff changeset
   639
    def OnCloseFrame(self, event):
6a7f92b84855 Split IDE's frame OnCloseFrame() into TryCloseFrame() and OnCloseFrame(), to help further customization
Edouard Tisserant
parents: 2459
diff changeset
   640
        if self.TryCloseFrame():
2624
570cf07c3fd1 Fix exception on exit in some case, sequel of an earlier cleanup commit I couldn't find back. Disconnecting the event is apparently the way to go. https://wiki.wxpython.org/Surviving%20with%20wxEVT%20KILL%20FOCUS%20under%20Microsoft%20Windows
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2571
diff changeset
   641
            self.LogConsole.Disconnect(-1, -1, wx.wxEVT_KILL_FOCUS)
3350
0d86fd9691ec WxPython 3.x -> 4.x : removed exception on stdout when closing at IDE frame
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3348
diff changeset
   642
            super(Beremiz, self).OnCloseFrame(event)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   643
            event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   644
        else:
2483
6a7f92b84855 Split IDE's frame OnCloseFrame() into TryCloseFrame() and OnCloseFrame(), to help further customization
Edouard Tisserant
parents: 2459
diff changeset
   645
            # prevent event to continue, i.e. cancel closing
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   646
            event.Veto()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   647
3712
cea2005bf2c9 IDE: When receiving SIGTERM signal, kill runtime befor bailing out without saving.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3588
diff changeset
   648
    def signalTERM_handler(self, sig, frame):
cea2005bf2c9 IDE: When receiving SIGTERM signal, kill runtime befor bailing out without saving.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3588
diff changeset
   649
        print ("Signal TERM caught: kill local runtime and quit, no save")
cea2005bf2c9 IDE: When receiving SIGTERM signal, kill runtime befor bailing out without saving.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3588
diff changeset
   650
        self.KillLocalRuntime()
cea2005bf2c9 IDE: When receiving SIGTERM signal, kill runtime befor bailing out without saving.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3588
diff changeset
   651
        sys.exit()
cea2005bf2c9 IDE: When receiving SIGTERM signal, kill runtime befor bailing out without saving.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3588
diff changeset
   652
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   653
    def RefreshFileMenu(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   654
        self.RefreshRecentProjectsMenu()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   655
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   656
        MenuToolBar = self.Panes["MenuToolBar"]
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   657
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   658
            selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   659
            if selected >= 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   660
                window = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   661
                viewer_is_modified = window.IsModified()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   662
                is_viewer = isinstance(window, Viewer)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   663
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   664
                viewer_is_modified = is_viewer = False
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   665
            if self.TabsOpened.GetPageCount() > 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   666
                self.FileMenu.Enable(wx.ID_CLOSE, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   667
                if is_viewer:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   668
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   669
                    self.FileMenu.Enable(wx.ID_PRINT, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   670
                    MenuToolBar.EnableTool(wx.ID_PRINT, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   671
                else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   672
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   673
                    self.FileMenu.Enable(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   674
                    MenuToolBar.EnableTool(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   675
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   676
                self.FileMenu.Enable(wx.ID_CLOSE, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   677
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   678
                self.FileMenu.Enable(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   679
                MenuToolBar.EnableTool(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   680
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   681
            project_modified = self.CTR.ProjectTestModified() or viewer_is_modified
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   682
            self.FileMenu.Enable(wx.ID_SAVE, project_modified)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   683
            MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   684
            self.FileMenu.Enable(wx.ID_SAVEAS, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   685
            MenuToolBar.EnableTool(wx.ID_SAVEAS, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   686
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   687
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   688
            self.FileMenu.Enable(wx.ID_CLOSE, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   689
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   690
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   691
            self.FileMenu.Enable(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   692
            MenuToolBar.EnableTool(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   693
            self.FileMenu.Enable(wx.ID_SAVE, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   694
            MenuToolBar.EnableTool(wx.ID_SAVE, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   695
            self.FileMenu.Enable(wx.ID_SAVEAS, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   696
            MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   697
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   698
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   699
    def RefreshRecentProjectsMenu(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   700
        try:
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   701
            recent_projects = list(map(DecodeFileSystemPath,
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   702
                                  self.GetConfigEntry("RecentProjects", [])))
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1769
diff changeset
   703
        except Exception:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   704
            recent_projects = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   705
2571
d968d586ad16 Fixed RecentProjectMenu in BeremizIDE.py broken by untested changes in wx.NewID_abuse_fix.
Edouard Tisserant
parents: 2569
diff changeset
   706
        while self.RecentProjectsMenu.GetMenuItemCount() > 0:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   707
            item = self.RecentProjectsMenu.FindItemByPosition(0)
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: 2740
diff changeset
   708
            self.RecentProjectsMenu.Remove(item)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   709
3833
73a44957c381 IDE: fix py3/wxpy4 related deprecation warnings
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3789
diff changeset
   710
        self.RecentProjectsMenuItem.Enable(len(recent_projects) > 0)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   711
        for idx, projectpath in enumerate(recent_projects):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   712
            text = '&%d: %s' % (idx + 1, projectpath)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   713
2571
d968d586ad16 Fixed RecentProjectMenu in BeremizIDE.py broken by untested changes in wx.NewID_abuse_fix.
Edouard Tisserant
parents: 2569
diff changeset
   714
            item = self.RecentProjectsMenu.Append(wx.ID_ANY, text, '')
2569
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
   715
            self.Bind(wx.EVT_MENU, self.GenerateOpenRecentProjectFunction(projectpath), item)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   716
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   717
    def GenerateOpenRecentProjectFunction(self, projectpath):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   718
        def OpenRecentProject(event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   719
            if self.CTR is not None and not self.CheckSaveBeforeClosing():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   720
                return
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   721
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   722
            self.OpenProject(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   723
        return OpenRecentProject
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   724
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   725
    def GenerateMenuRecursive(self, items, menu):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   726
        for kind, infos in items:
2450
5024c19ca8f0 python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2432
diff changeset
   727
            if isinstance(kind, list):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   728
                text, id = infos
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   729
                submenu = wx.Menu('')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   730
                self.GenerateMenuRecursive(kind, submenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   731
                menu.AppendMenu(id, text, submenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   732
            elif kind == wx.ITEM_SEPARATOR:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   733
                menu.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   734
            else:
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   735
                text, id, _help, callback = infos
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   736
                AppendMenu(menu, help='', id=id, kind=kind, text=text)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   737
                if callback is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   738
                    self.Bind(wx.EVT_MENU, callback, id=id)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   739
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   740
    def RefreshEditorToolBar(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   741
        IDEFrame.RefreshEditorToolBar(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   742
        self.AUIManager.GetPane("EditorToolBar").Position(2)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   743
        self.AUIManager.GetPane("StatusToolBar").Position(1)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   744
        self.AUIManager.Update()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   745
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   746
    def RefreshStatusToolBar(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   747
        StatusToolBar = self.Panes["StatusToolBar"]
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   748
        StatusToolBar.ClearTools()
2255
f6a0508fa473 Fix problem with decreasing size of StatusToolBar when tools are removed from toolbar.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2243
diff changeset
   749
        StatusToolBar.SetMinSize(StatusToolBar.GetToolBitmapSize())
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   750
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   751
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   752
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   753
            for confnode_method in self.CTR.StatusMethods:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   754
                if "method" in confnode_method and confnode_method.get("shown", True):
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: 2740
diff changeset
   755
                    tool = StatusToolBar.AddTool(
3588
412090a6b3a7 IDE: Fix tooltip not being shown anymore on any toolbars since switch to wxPython4.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3586
diff changeset
   756
                        wx.ID_ANY, confnode_method["name"],
412090a6b3a7 IDE: Fix tooltip not being shown anymore on any toolbars since switch to wxPython4.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3586
diff changeset
   757
                        GetBitmap(confnode_method.get("bitmap", "Unknown")),
412090a6b3a7 IDE: Fix tooltip not being shown anymore on any toolbars since switch to wxPython4.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3586
diff changeset
   758
                        confnode_method["tooltip"])
2566
66a3c64c8dd0 More wx.NewID abuse removal. This one was apparently silently unbinding toolbar butons when running out of mew wx IDs.
Edouard Tisserant
parents: 2551
diff changeset
   759
                    self.Bind(wx.EVT_MENU, self.GetMenuCallBackFunction(confnode_method["method"]), tool)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   760
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   761
            StatusToolBar.Realize()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   762
            self.AUIManager.GetPane("StatusToolBar").BestSize(StatusToolBar.GetBestSize()).Show()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   763
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   764
            self.AUIManager.GetPane("StatusToolBar").Hide()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   765
        self.AUIManager.GetPane("EditorToolBar").Position(2)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   766
        self.AUIManager.GetPane("StatusToolBar").Position(1)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   767
        self.AUIManager.Update()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   768
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   769
    def RefreshEditMenu(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   770
        IDEFrame.RefreshEditMenu(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   771
        if self.FindFocus() == self.LogConsole:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   772
            self.EditMenu.Enable(wx.ID_COPY, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   773
            self.Panes["MenuToolBar"].EnableTool(wx.ID_COPY, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   774
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   775
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   776
            selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   777
            if selected >= 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   778
                panel = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   779
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   780
                panel = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   781
            if panel != self.LastPanelSelected:
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   782
                for i in range(self.EditMenuSize, self.EditMenu.GetMenuItemCount()):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   783
                    item = self.EditMenu.FindItemByPosition(self.EditMenuSize)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   784
                    if item is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   785
                        if item.IsSeparator():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   786
                            self.EditMenu.RemoveItem(item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   787
                        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   788
                            self.EditMenu.Delete(item.GetId())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   789
                self.LastPanelSelected = panel
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   790
                if panel is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   791
                    items = panel.GetConfNodeMenuItems()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   792
                else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   793
                    items = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   794
                if len(items) > 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   795
                    self.EditMenu.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   796
                    self.GenerateMenuRecursive(items, self.EditMenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   797
            if panel is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   798
                panel.RefreshConfNodeMenu(self.EditMenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   799
        else:
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   800
            for i in range(self.EditMenuSize, self.EditMenu.GetMenuItemCount()):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   801
                item = self.EditMenu.FindItemByPosition(i)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   802
                if item is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   803
                    if item.IsSeparator():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   804
                        self.EditMenu.RemoveItem(item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   805
                    else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   806
                        self.EditMenu.Delete(item.GetId())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   807
            self.LastPanelSelected = None
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: 2740
diff changeset
   808
        self.MenuBar.Refresh()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   809
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   810
    def RefreshAll(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   811
        self.RefreshStatusToolBar()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   812
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   813
    def GetMenuCallBackFunction(self, method):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   814
        """ Generate the callbackfunc for a given CTR method"""
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   815
        def OnMenu(event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   816
            # Disable button to prevent re-entrant call
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   817
            event.GetEventObject().Disable()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   818
            # Call
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   819
            getattr(self.CTR, method)()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   820
            # Re-enable button
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   821
            event.GetEventObject().Enable()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   822
        return OnMenu
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   823
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   824
    def GetConfigEntry(self, entry_name, default):
3758
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   825
        return pickle.loads(self.Config.Read(entry_name,
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   826
                                             pickle.dumps(default,
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   827
                                                          0).decode()).encode())
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   828
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   829
    def ResetConnectionStatusBar(self):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   830
        for field in range(self.ConnectionStatusBar.GetFieldsCount()):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   831
            self.ConnectionStatusBar.SetStatusText('', field)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   832
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   833
    def ResetView(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   834
        IDEFrame.ResetView(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   835
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   836
            self.CTR.CloseProject()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   837
        self.CTR = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   838
        self.Log.flush()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   839
        if self.EnableDebug:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   840
            self.DebugVariablePanel.SetDataProducer(None)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   841
            self.ResetConnectionStatusBar()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   842
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   843
    def RefreshConfigRecentProjects(self, projectpath, err=False):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   844
        try:
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   845
            recent_projects = list(map(DecodeFileSystemPath,
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3712
diff changeset
   846
                                  self.GetConfigEntry("RecentProjects", [])))
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1769
diff changeset
   847
        except Exception:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   848
            recent_projects = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   849
        if projectpath in recent_projects:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   850
            recent_projects.remove(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   851
        if not err:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   852
            recent_projects.insert(0, projectpath)
3758
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   853
        self.Config.Write("RecentProjects",
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   854
                          pickle.dumps(
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   855
                              list(map(EncodeFileSystemPath,
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   856
                                       recent_projects[:MAX_RECENT_PROJECTS])),
bc71b19b45ff switch to pickle from cPickle
GP Orcullo <kinsamanka@gmail.com>
parents: 3755
diff changeset
   857
                              0))
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   858
        self.Config.Flush()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   859
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   860
    def ResetPerspective(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   861
        IDEFrame.ResetPerspective(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   862
        self.RefreshStatusToolBar()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   863
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   864
    def OnNewProjectMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   865
        if self.CTR is not None and not self.CheckSaveBeforeClosing():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   866
            return
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   867
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   868
        try:
3755
ca814b175391 fix string encoding
GP Orcullo <kinsamanka@gmail.com>
parents: 3752
diff changeset
   869
            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder").encode())
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1769
diff changeset
   870
        except Exception:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   871
            defaultpath = os.path.expanduser("~")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   872
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   873
        dialog = wx.DirDialog(self, _("Choose an empty directory for new project"), defaultpath)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   874
        if dialog.ShowModal() == wx.ID_OK:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   875
            projectpath = dialog.GetPath()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   876
            self.Config.Write("lastopenedfolder",
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   877
                              EncodeFileSystemPath(os.path.dirname(projectpath)))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   878
            self.Config.Flush()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   879
            self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   880
            ctr = ProjectController(self, self.Log)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   881
            result = ctr.NewProject(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   882
            if not result:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   883
                self.CTR = ctr
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   884
                self.Controler = self.CTR
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   885
                self.LibraryPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   886
                self.ProjectTree.Enable(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   887
                self.PouInstanceVariablesPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   888
                self.RefreshConfigRecentProjects(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   889
                if self.EnableDebug:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   890
                    self.DebugVariablePanel.SetDataProducer(self.CTR)
1933
cef288644088 Factorized duplicated code
Edouard Tisserant
parents: 1927
diff changeset
   891
                self.RefreshAfterLoad()
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1692
diff changeset
   892
                IDEFrame.OnAddNewProject(self, event)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   893
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   894
                self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   895
                self.ShowErrorMessage(result)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   896
            self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   897
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   898
        dialog.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   899
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   900
    def OnOpenProjectMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   901
        if self.CTR is not None and not self.CheckSaveBeforeClosing():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   902
            return
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   903
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   904
        try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   905
            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1769
diff changeset
   906
        except Exception:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   907
            defaultpath = os.path.expanduser("~")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   908
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   909
        dialog = wx.DirDialog(self, _("Choose a project"), defaultpath,
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   910
                              style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   911
        if dialog.ShowModal() == wx.ID_OK:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   912
            self.OpenProject(dialog.GetPath())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   913
        dialog.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   914
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   915
    def OpenProject(self, projectpath):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   916
        if os.path.isdir(projectpath):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   917
            self.Config.Write("lastopenedfolder",
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   918
                              EncodeFileSystemPath(os.path.dirname(projectpath)))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   919
            self.Config.Flush()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   920
            self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   921
            self.CTR = ProjectController(self, self.Log)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   922
            self.Controler = self.CTR
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   923
            result, err = self.CTR.LoadProject(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   924
            if not result:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   925
                self.LibraryPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   926
                self.ProjectTree.Enable(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   927
                self.PouInstanceVariablesPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   928
                if self.EnableDebug:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   929
                    self.DebugVariablePanel.SetDataProducer(self.CTR)
1933
cef288644088 Factorized duplicated code
Edouard Tisserant
parents: 1927
diff changeset
   930
                self.RefreshAfterLoad()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   931
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   932
                self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   933
                self.ShowErrorMessage(result)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   934
            self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   935
            self.SearchResultPanel.ResetSearchResults()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   936
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   937
            self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   938
            err = True
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   939
        self.RefreshConfigRecentProjects(projectpath, err)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   940
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   941
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   942
    def OnCloseProjectMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   943
        if self.CTR is not None and not self.CheckSaveBeforeClosing():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   944
            return
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   945
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   946
        self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   947
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   948
        self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   949
1933
cef288644088 Factorized duplicated code
Edouard Tisserant
parents: 1927
diff changeset
   950
    def RefreshAfterLoad(self):
cef288644088 Factorized duplicated code
Edouard Tisserant
parents: 1927
diff changeset
   951
        self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
cef288644088 Factorized duplicated code
Edouard Tisserant
parents: 1927
diff changeset
   952
1927
5def24850a28 Factorized some repeated refresh code into a method, to allow customisation.
Edouard Tisserant
parents: 1925
diff changeset
   953
    def RefreshAfterSave(self):
5def24850a28 Factorized some repeated refresh code into a method, to allow customisation.
Edouard Tisserant
parents: 1925
diff changeset
   954
        self.RefreshAll()
5def24850a28 Factorized some repeated refresh code into a method, to allow customisation.
Edouard Tisserant
parents: 1925
diff changeset
   955
        self._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES)
5def24850a28 Factorized some repeated refresh code into a method, to allow customisation.
Edouard Tisserant
parents: 1925
diff changeset
   956
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   957
    def OnSaveProjectMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   958
        selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   959
        if selected != -1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   960
            window = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   961
            window.Save()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   962
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   963
            self.CTR.SaveProject()
1927
5def24850a28 Factorized some repeated refresh code into a method, to allow customisation.
Edouard Tisserant
parents: 1925
diff changeset
   964
            self.RefreshAfterSave()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   965
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   966
    def OnSaveProjectAsMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   967
        selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   968
        if selected != -1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   969
            window = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   970
            window.SaveAs()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   971
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   972
            self.CTR.SaveProjectAs()
1927
5def24850a28 Factorized some repeated refresh code into a method, to allow customisation.
Edouard Tisserant
parents: 1925
diff changeset
   973
            self.RefreshAfterSave()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   974
            self.RefreshConfigRecentProjects(self.CTR.ProjectPath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   975
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   976
    def OnQuitMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   977
        self.Close()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   978
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   979
    def OnAboutMenu(self, event):
3570
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
   980
        info = wx.adv.AboutDialogInfo()
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
   981
        info = version.GetAboutDialogInfo(info)
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
   982
        info.Name = "Beremiz"
3909
c29a95aebfbf Shows AboutDialog even if revisions.tx is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3906
diff changeset
   983
        try:
c29a95aebfbf Shows AboutDialog even if revisions.tx is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3906
diff changeset
   984
            with open(ThirdPartyPath("revisions.txt")) as f:
c29a95aebfbf Shows AboutDialog even if revisions.tx is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3906
diff changeset
   985
                revisions=f.read()
c29a95aebfbf Shows AboutDialog even if revisions.tx is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3906
diff changeset
   986
        except Exception as e:
c29a95aebfbf Shows AboutDialog even if revisions.tx is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3906
diff changeset
   987
            revisions="Can't load revisions.txt: "+str(e)
c29a95aebfbf Shows AboutDialog even if revisions.tx is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3906
diff changeset
   988
        finally:
3906
f831ff63ca6e IDE: display contents of revisions.txt (put there by installer builder script) in About Dialog.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3833
diff changeset
   989
            info.SetVersion(info.GetVersion(), longVersion=revisions)
f831ff63ca6e IDE: display contents of revisions.txt (put there by installer builder script) in About Dialog.
Edouard Tisserant <edouard@beremiz.fr>
parents: 3833
diff changeset
   990
3570
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
   991
        info.Description = _("Open Source framework for automation, "
3586
cbc6a6ccd52e IDE: Fixed About dialog exception on Windows, and typo in about dialog's content.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3570
diff changeset
   992
            "implementing IEC 61131 IDE with constantly growing set of extensions "
3570
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
   993
            "and flexible PLC runtime.")
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
   994
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
   995
        info.Icon = wx.Icon(Bpath("images", "about_brz_logo.png"), wx.BITMAP_TYPE_PNG)
eb915a9fdcb0 IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3564
diff changeset
   996
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   997
        ShowAboutDialog(self, info)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   998
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   999
    def OnProjectTreeItemBeginEdit(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1000
        selected = event.GetItem()
3789
8def429216ca fix wxPyDeprecationWarnings
GP Orcullo <kinsamanka@gmail.com>
parents: 3766
diff changeset
  1001
        if self.ProjectTree.GetItemData(selected)["type"] == ITEM_CONFNODE:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1002
            event.Veto()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1003
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1004
            IDEFrame.OnProjectTreeItemBeginEdit(self, event)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1005
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1006
    def OnProjectTreeRightUp(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1007
        item = event.GetItem()
3789
8def429216ca fix wxPyDeprecationWarnings
GP Orcullo <kinsamanka@gmail.com>
parents: 3766
diff changeset
  1008
        item_infos = self.ProjectTree.GetItemData(item)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1009
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1010
        if item_infos["type"] == ITEM_CONFNODE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1011
            confnode_menu = wx.Menu(title='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1012
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1013
            confnode = item_infos["confnode"]
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1014
            if confnode is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1015
                menu_items = confnode.GetContextualMenuItems()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1016
                if menu_items is not None:
2569
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
  1017
                    for text, helpstr, callback in menu_items:
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
  1018
                        item = confnode_menu.Append(wx.ID_ANY, text, helpstr)
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
  1019
                        self.Bind(wx.EVT_MENU, callback, item)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1020
                else:
2569
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
  1021
                    for name, XSDClass, helpstr in confnode.CTNChildrenTypes:
1684
1447424a7029 remove child node from add child node menu, if max count of the same type nodes reached
Surkov Sergey <surkovsv93@gmail.com>
parents: 1680
diff changeset
  1022
                        if not hasattr(XSDClass, 'CTNMaxCount') or not confnode.Children.get(name) \
1447424a7029 remove child node from add child node menu, if max count of the same type nodes reached
Surkov Sergey <surkovsv93@gmail.com>
parents: 1680
diff changeset
  1023
                                or len(confnode.Children[name]) < XSDClass.CTNMaxCount:
2569
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
  1024
                            item = confnode_menu.Append(wx.ID_ANY, _("Add") + " " + name, helpstr)
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
  1025
                            self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name, confnode), item)
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
  1026
            item = confnode_menu.Append(wx.ID_ANY, _("Delete"))
4f4d778c9376 More wx.NewID abuse removal. This time BeremizIDE.py was cleaned.
Edouard Tisserant
parents: 2566
diff changeset
  1027
            self.Bind(wx.EVT_MENU, self.GetDeleteMenuFunction(confnode), item)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1028
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1029
            self.PopupMenu(confnode_menu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1030
            confnode_menu.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1031
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1032
            event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1033
        elif item_infos["type"] == ITEM_RESOURCE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1034
            # prevent last resource to be delted
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1035
            parent = self.ProjectTree.GetItemParent(item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1036
            parent_name = self.ProjectTree.GetItemText(parent)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1037
            if parent_name == _("Resources"):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1038
                IDEFrame.OnProjectTreeRightUp(self, event)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1039
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1040
            IDEFrame.OnProjectTreeRightUp(self, event)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1041
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1042
    def OnProjectTreeItemActivated(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1043
        selected = event.GetItem()
3789
8def429216ca fix wxPyDeprecationWarnings
GP Orcullo <kinsamanka@gmail.com>
parents: 3766
diff changeset
  1044
        item_infos = self.ProjectTree.GetItemData(selected)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1045
        if item_infos["type"] == ITEM_CONFNODE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1046
            item_infos["confnode"]._OpenView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1047
            event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1048
        elif item_infos["type"] == ITEM_PROJECT:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1049
            self.CTR._OpenView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1050
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1051
            IDEFrame.OnProjectTreeItemActivated(self, event)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1052
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1053
    def ProjectTreeItemSelect(self, select_item):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1054
        if select_item is not None and select_item.IsOk():
3789
8def429216ca fix wxPyDeprecationWarnings
GP Orcullo <kinsamanka@gmail.com>
parents: 3766
diff changeset
  1055
            item_infos = self.ProjectTree.GetItemData(select_item)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1056
            if item_infos["type"] == ITEM_CONFNODE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1057
                item_infos["confnode"]._OpenView(onlyopened=True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1058
            elif item_infos["type"] == ITEM_PROJECT:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1059
                self.CTR._OpenView(onlyopened=True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1060
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1061
                IDEFrame.ProjectTreeItemSelect(self, select_item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1062
2524
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2485
diff changeset
  1063
    def GetProjectElementWindow(self, element, tagname):
2551
245644bfcd24 Make spaghetti-code-quality great again.
Edouard Tisserant
parents: 2529
diff changeset
  1064
        is_a_CTN_tagname = len(tagname.split("::")) == 1
2524
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2485
diff changeset
  1065
        if is_a_CTN_tagname:
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2485
diff changeset
  1066
            confnode = self.CTR.GetChildByName(tagname)
2551
245644bfcd24 Make spaghetti-code-quality great again.
Edouard Tisserant
parents: 2529
diff changeset
  1067
            return confnode.GetView()
245644bfcd24 Make spaghetti-code-quality great again.
Edouard Tisserant
parents: 2529
diff changeset
  1068
        else:
2524
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2485
diff changeset
  1069
            return IDEFrame.GetProjectElementWindow(self, element, tagname)
c80b0d864475 WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents: 2485
diff changeset
  1070
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1071
    def SelectProjectTreeItem(self, tagname):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1072
        if self.ProjectTree is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1073
            root = self.ProjectTree.GetRootItem()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1074
            if root.IsOk():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1075
                words = tagname.split("::")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1076
                if len(words) == 1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1077
                    if tagname == "Project":
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1078
                        self.SelectedItem = root
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1079
                        self.ProjectTree.SelectItem(root)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1080
                        self.ResetSelectedItem()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1081
                    else:
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
  1082
                        return self.RecursiveProjectTreeItemSelection(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
  1083
                            root,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
  1084
                            [(word, ITEM_CONFNODE) for word in tagname.split(".")])
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1085
                elif words[0] == "R":
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1086
                    return self.RecursiveProjectTreeItemSelection(root, [(words[2], ITEM_RESOURCE)])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1087
                elif not os.path.exists(words[0]):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1088
                    IDEFrame.SelectProjectTreeItem(self, tagname)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1089
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1090
    def GetAddConfNodeFunction(self, name, confnode=None):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1091
        def AddConfNodeMenuFunction(event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1092
            wx.CallAfter(self.AddConfNode, name, confnode)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1093
        return AddConfNodeMenuFunction
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1094
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1095
    def GetDeleteMenuFunction(self, confnode):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1096
        def DeleteMenuFunction(event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1097
            wx.CallAfter(self.DeleteConfNode, confnode)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1098
        return DeleteMenuFunction
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1099
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1100
    def AddConfNode(self, ConfNodeType, confnode=None):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1101
        if self.CTR.CheckProjectPathPerm():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1102
            ConfNodeName = "%s_0" % ConfNodeType
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1103
            if confnode is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1104
                confnode.CTNAddChild(ConfNodeName, ConfNodeType)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1105
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1106
                self.CTR.CTNAddChild(ConfNodeName, ConfNodeType)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1107
            self._Refresh(TITLE, FILEMENU, PROJECTTREE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1108
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1109
    def DeleteConfNode(self, confnode):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1110
        if self.CTR.CheckProjectPathPerm():
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
  1111
            dialog = wx.MessageDialog(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
  1112
                self,
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1113
                _("Really delete node '%s'?") % confnode.CTNName(),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1114
                _("Remove %s node") % confnode.CTNType,
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
  1115
                wx.YES_NO | wx.NO_DEFAULT)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1116
            if dialog.ShowModal() == wx.ID_YES:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1117
                confnode.CTNRemove()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1118
                del confnode
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1119
                self._Refresh(TITLE, FILEMENU, PROJECTTREE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1120
            dialog.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1121
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
  1122
# -------------------------------------------------------------------------------
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1123
#                        Highlights showing functions
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1781
diff changeset
  1124
# -------------------------------------------------------------------------------
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1125
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1126
    def ShowHighlight(self, infos, start, end, highlight_type):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1127
        config_name = self.Controler.GetProjectMainConfigurationName()
1948
b9a3f771aaab Moved some definitions away from controller class, and adaped references them through all code.
Edouard Tisserant
parents: 1933
diff changeset
  1128
        if config_name is not None and infos[0] == ComputeConfigurationName(config_name):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1129
            self.CTR._OpenView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1130
            selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1131
            if selected != -1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1132
                viewer = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1133
                viewer.AddHighlight(infos[1:], start, end, highlight_type)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1134
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1135
            IDEFrame.ShowHighlight(self, infos, start, end, highlight_type)