BeremizIDE.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 17 Aug 2017 10:12:04 +0300
changeset 1761 8c98bad90b8d
parent 1760 ed2e2afb9573
child 1762 fcc406143e5b
permissions -rwxr-xr-x
clean-up: fix PEP8 E203 whitespace before ','
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
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    28
import sys
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    29
import tempfile
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    30
import shutil
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    31
import random
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    32
import time
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    33
import version
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    34
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1662
diff changeset
    35
import util.paths as paths
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    36
from types import ListType
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    37
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1662
diff changeset
    38
beremiz_dir = paths.AbsDir(__file__)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    39
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    40
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    41
def Bpath(*args):
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
    42
    return os.path.join(beremiz_dir, *args)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    43
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
    44
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    45
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
    46
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
    47
import wx.stc
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    48
import cPickle
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    49
import types
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    50
import time
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    51
import re
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    52
import platform
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    53
import time
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    54
import traceback
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    55
import commands
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    56
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    57
from docutil import OpenHtmlFrame
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    58
from editors.EditorPanel import EditorPanel
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    59
from editors.Viewer import Viewer
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    60
from editors.TextViewer import TextViewer
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    61
from editors.ResourceEditor import ConfigurationEditor, ResourceEditor
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    62
from editors.DataTypeEditor import DataTypeEditor
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    63
from util.MiniTextControler import MiniTextControler
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    64
from util.ProcessLogger import ProcessLogger
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    65
from controls.LogViewer import LogViewer
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    66
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    67
from controls import EnhancedStatusBar as esb
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    68
from dialogs.AboutDialog import ShowAboutDialog
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    69
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    70
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    71
from ProjectController import ProjectController, GetAddMenuItems, MATIEC_ERROR_MODEL, ITEM_CONFNODE
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    72
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    73
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    74
MAX_RECENT_PROJECTS = 9
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    75
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    76
if wx.Platform == '__WXMSW__':
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    77
    faces = {
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
    78
        'mono': 'Courier New',
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
    79
        'size': 8,
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    80
    }
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    81
else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    82
    faces = {
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
    83
        'mono': 'Courier',
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
    84
        'size': 10,
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    85
    }
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    86
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
    87
from threading import Lock, Timer, currentThread
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    88
MainThread = currentThread().ident
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    89
REFRESH_PERIOD = 0.1
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    90
from time import time as gettime
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    91
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    92
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    93
class LogPseudoFile:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    94
    """ Base class for file like objects to facilitate StdOut for the Shell."""
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    95
    def __init__(self, output, risecall):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    96
        self.red_white = 1
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    97
        self.red_yellow = 2
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    98
        self.black_white = wx.stc.STC_STYLE_DEFAULT
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    99
        self.output = output
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   100
        self.risecall = risecall
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   101
        # to prevent rapid fire on rising log panel
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   102
        self.rising_timer = 0
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   103
        self.lock = Lock()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   104
        self.YieldLock = Lock()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   105
        self.RefreshLock = Lock()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   106
        self.TimerAccessLock = Lock()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   107
        self.stack = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   108
        self.LastRefreshTime = gettime()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   109
        self.LastRefreshTimer = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   110
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   111
    def write(self, s, style=None):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   112
        if self.lock.acquire():
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   113
            self.stack.append((s, style))
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   114
            self.lock.release()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   115
            current_time = gettime()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   116
            self.TimerAccessLock.acquire()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   117
            if self.LastRefreshTimer:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   118
                self.LastRefreshTimer.cancel()
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   119
                self.LastRefreshTimer = None
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   120
            self.TimerAccessLock.release()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   121
            if current_time - self.LastRefreshTime > REFRESH_PERIOD and self.RefreshLock.acquire(False):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   122
                self._should_write()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   123
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   124
                self.TimerAccessLock.acquire()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   125
                self.LastRefreshTimer = Timer(REFRESH_PERIOD, self._timer_expired)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   126
                self.LastRefreshTimer.start()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   127
                self.TimerAccessLock.release()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   128
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   129
    def _timer_expired(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   130
        if self.RefreshLock.acquire(False):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   131
            self._should_write()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   132
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   133
            self.TimerAccessLock.acquire()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   134
            self.LastRefreshTimer = Timer(REFRESH_PERIOD, self._timer_expired)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   135
            self.LastRefreshTimer.start()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   136
            self.TimerAccessLock.release()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   137
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   138
    def _should_write(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   139
        wx.CallAfter(self._write)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   140
        if MainThread == currentThread().ident:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   141
            app = wx.GetApp()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   142
            if app is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   143
                if self.YieldLock.acquire(0):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   144
                    app.Yield()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   145
                    self.YieldLock.release()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   146
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   147
    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
   148
        if self.output:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   149
            self.output.Freeze()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   150
            self.lock.acquire()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   151
            for s, style in self.stack:
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1751
diff changeset
   152
                if style is None:
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1751
diff changeset
   153
                    style = self.black_white
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   154
                if style != self.black_white:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   155
                    self.output.StartStyling(self.output.GetLength(), 0xff)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   156
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   157
                # Temporary deactivate read only mode on StyledTextCtrl for
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   158
                # adding text. It seems that text modifications, even
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   159
                # programmatically, are disabled in StyledTextCtrl when read
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   160
                # only is active
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   161
                start_pos = self.output.GetLength()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   162
                self.output.SetReadOnly(False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   163
                self.output.AppendText(s)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   164
                self.output.SetReadOnly(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   165
                text_len = self.output.GetLength() - start_pos
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   166
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   167
                if style != self.black_white:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   168
                    self.output.SetStyling(text_len, style)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   169
            self.stack = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   170
            self.lock.release()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   171
            self.output.Thaw()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   172
            self.LastRefreshTime = gettime()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   173
            try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   174
                self.RefreshLock.release()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   175
            except:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   176
                pass
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   177
            newtime = time.time()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   178
            if newtime - self.rising_timer > 1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   179
                self.risecall(self.output)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   180
            self.rising_timer = newtime
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   181
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   182
    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
   183
        self.write(s, self.red_white)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   184
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   185
    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
   186
        self.write(s, self.red_yellow)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   187
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   188
    def writeyield(self, s):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   189
        self.write(s)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   190
        wx.GetApp().Yield()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   191
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   192
    def flush(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   193
        # 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
   194
        # 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
   195
        # disabled in StyledTextCtrl when read only is active
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   196
        self.output.SetReadOnly(False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   197
        self.output.SetText("")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   198
        self.output.SetReadOnly(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   199
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   200
    def isatty(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   201
        return False
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   202
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
   203
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   204
ID_FILEMENURECENTPROJECTS = wx.NewId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   205
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   206
from IDEFrame import TITLE,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   207
                     EDITORTOOLBAR,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   208
                     FILEMENU,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   209
                     EDITMENU,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   210
                     DISPLAYMENU,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   211
                     PROJECTTREE,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   212
                     POUINSTANCEVARIABLESPANEL,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   213
                     LIBRARYTREE,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   214
                     SCALING,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   215
                     PAGETITLES,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   216
                     IDEFrame, AppendMenu,\
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   217
                     EncodeFileSystemPath, DecodeFileSystemPath
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   218
from util.BitmapLibrary import GetBitmap
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   219
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   220
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   221
class Beremiz(IDEFrame):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   222
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   223
    def _init_utils(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   224
        self.ConfNodeMenu = wx.Menu(title='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   225
        self.RecentProjectsMenu = wx.Menu(title='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   226
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   227
        IDEFrame._init_utils(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   228
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   229
    def _init_coll_FileMenu_Items(self, parent):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   230
        AppendMenu(parent, help='', id=wx.ID_NEW,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   231
              kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   232
        AppendMenu(parent, help='', id=wx.ID_OPEN,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   233
              kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   234
        parent.AppendMenu(ID_FILEMENURECENTPROJECTS, _("&Recent Projects"), self.RecentProjectsMenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   235
        parent.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   236
        AppendMenu(parent, help='', id=wx.ID_SAVE,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   237
              kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   238
        AppendMenu(parent, help='', id=wx.ID_SAVEAS,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   239
              kind=wx.ITEM_NORMAL, text=_(u'Save as') + '\tCTRL+SHIFT+S')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   240
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   241
              kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   242
        AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   243
              kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   244
        parent.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   245
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   246
              kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   247
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   248
              kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   249
        AppendMenu(parent, help='', id=wx.ID_PRINT,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   250
              kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   251
        parent.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   252
        AppendMenu(parent, help='', id=wx.ID_EXIT,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   253
              kind=wx.ITEM_NORMAL, text=_(u'Quit') + '\tCTRL+Q')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   254
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   255
        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
   256
        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
   257
        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
   258
        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
   259
        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
   260
        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
   261
        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
   262
        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
   263
        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
   264
        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
   265
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   266
        self.AddToMenuToolBar([(wx.ID_NEW, "new", _(u'New'), None),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   267
                               (wx.ID_OPEN, "open", _(u'Open'), None),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   268
                               (wx.ID_SAVE, "save", _(u'Save'), None),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   269
                               (wx.ID_SAVEAS, "saveas", _(u'Save As...'), None),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   270
                               (wx.ID_PRINT, "print", _(u'Print'), None)])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   271
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   272
    def _RecursiveAddMenuItems(self, menu, items):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   273
        for name, text, help, children in items:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   274
            new_id = wx.NewId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   275
            if len(children) > 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   276
                new_menu = wx.Menu(title='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   277
                menu.AppendMenu(new_id, text, new_menu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   278
                self._RecursiveAddMenuItems(new_menu, children)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   279
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   280
                AppendMenu(menu, help=help, id=new_id,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   281
                       kind=wx.ITEM_NORMAL, text=text)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   282
                self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   283
                          id=new_id)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   284
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   285
    def _init_coll_AddMenu_Items(self, parent):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   286
        IDEFrame._init_coll_AddMenu_Items(self, parent, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   287
        self._RecursiveAddMenuItems(parent, GetAddMenuItems())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   288
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   289
    def _init_coll_HelpMenu_Items(self, parent):
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   290
        handler = lambda event: {
1692
9cb4d1392baf add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1684
diff changeset
   291
            wx.MessageBox(version.GetCommunityHelpMsg(), _(u'Community support'), wx.OK | wx.ICON_INFORMATION)
9cb4d1392baf add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1684
diff changeset
   292
        }
9cb4d1392baf add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1684
diff changeset
   293
        id = wx.NewId()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1721
diff changeset
   294
        parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
1692
9cb4d1392baf add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1684
diff changeset
   295
        self.Bind(wx.EVT_MENU, handler, id=id)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1721
diff changeset
   296
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   297
        parent.Append(help='', id=wx.ID_ABOUT,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   298
              kind=wx.ITEM_NORMAL, text=_(u'About'))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   299
        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
   300
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   301
    def _init_coll_ConnectionStatusBar_Fields(self, parent):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   302
        parent.SetFieldsCount(3)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   303
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   304
        parent.SetStatusText(number=0, text='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   305
        parent.SetStatusText(number=1, text='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   306
        parent.SetStatusText(number=2, text='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   307
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   308
        parent.SetStatusWidths([-1, 300, 200])
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 _init_ctrls(self, prnt):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   311
        IDEFrame._init_ctrls(self, prnt)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   312
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   313
        self.EditMenuSize = self.EditMenu.GetMenuItemCount()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   314
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   315
        inspectorID = wx.NewId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   316
        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
   317
        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
   318
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   319
        keyID = wx.NewId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   320
        self.Bind(wx.EVT_MENU, self.SwitchFullScrMode, id=keyID)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   321
        accels += [wx.AcceleratorEntry(wx.ACCEL_NORMAL, wx.WXK_F12, keyID)]
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   322
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   323
        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
   324
                                 ("Run",      wx.WXK_F5),
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   325
                                 ("Transfer", wx.WXK_F6),
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   326
                                 ("Connect",  wx.WXK_F7),
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   327
                                 ("Build",    wx.WXK_F11)]:
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   328
            def OnMethodGen(obj, meth):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   329
                def OnMethod(evt):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   330
                    if obj.CTR is not None:
1757
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   331
                        obj.CTR.CallMethod('_'+meth)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   332
                    wx.CallAfter(self.RefreshStatusToolBar)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   333
                return OnMethod
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   334
            newid = wx.NewId()
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   335
            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
   336
            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
   337
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   338
        self.SetAcceleratorTable(wx.AcceleratorTable(accels))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   339
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   340
        self.LogConsole = CustomStyledTextCtrl(
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   341
                  name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   342
                  size=wx.Size(0, 0))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   343
        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
   344
        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
   345
        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
   346
        self.LogConsole.SetReadOnly(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   347
        self.LogConsole.SetWrapMode(wx.stc.STC_WRAP_CHAR)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   348
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   349
        # Define Log Console styles
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   350
        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
   351
        self.LogConsole.StyleClearAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   352
        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
   353
        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
   354
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   355
        # Define Log Console markers
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   356
        self.LogConsole.SetMarginSensitive(1, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   357
        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
   358
        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
   359
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   360
        self.LogConsole.SetModEventMask(wx.stc.STC_MOD_INSERTTEXT)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   361
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   362
        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
   363
        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
   364
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   365
        self.MainTabs["LogConsole"] = (self.LogConsole, _("Console"))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   366
        self.BottomNoteBook.AddPage(*self.MainTabs["LogConsole"])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   367
        #self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogConsole), wx.RIGHT)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   368
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   369
        self.LogViewer = LogViewer(self.BottomNoteBook, self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   370
        self.MainTabs["LogViewer"] = (self.LogViewer, _("PLC Log"))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   371
        self.BottomNoteBook.AddPage(*self.MainTabs["LogViewer"])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   372
        #self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogViewer), wx.RIGHT)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   373
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   374
        StatusToolBar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   375
                wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   376
        StatusToolBar.SetToolBitmapSize(wx.Size(25, 25))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   377
        StatusToolBar.Realize()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   378
        self.Panes["StatusToolBar"] = StatusToolBar
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   379
        self.AUIManager.AddPane(StatusToolBar, wx.aui.AuiPaneInfo().
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   380
                  Name("StatusToolBar").Caption(_("Status ToolBar")).
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   381
                  ToolbarPane().Top().Position(1).
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   382
                  LeftDockable(False).RightDockable(False))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   383
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   384
        self.AUIManager.Update()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   385
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   386
        self.ConnectionStatusBar = esb.EnhancedStatusBar(self, style=wx.ST_SIZEGRIP)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   387
        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
   388
        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
   389
        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
   390
        self.ProgressStatusBar.Hide()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   391
        self.SetStatusBar(self.ConnectionStatusBar)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   392
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   393
    def __init_execute_path(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   394
        if os.name == 'nt':
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   395
            # on windows, desktop shortcut launches Beremiz.py
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   396
            # with working dir set to mingw/bin.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   397
            # 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
   398
            # commands invoked by build process by default are
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   399
            # found here.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   400
            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
   401
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   402
    def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   403
        # 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
   404
        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
   405
        self.__init_execute_path()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1721
diff changeset
   406
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   407
        IDEFrame.__init__(self, parent, debug)
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   408
        self.Log = LogPseudoFile(self.LogConsole, self.SelectTab)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   409
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   410
        self.local_runtime = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   411
        self.runtime_port = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   412
        self.local_runtime_tmpdir = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   413
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   414
        self.LastPanelSelected = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   415
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   416
        # Define Tree item icon list
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   417
        self.LocationImageList = wx.ImageList(16, 16)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   418
        self.LocationImageDict = {}
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   419
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   420
        # Icons for location items
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   421
        for imgname, itemtype in [
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   422
            ("CONFIGURATION", LOCATION_CONFNODE),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   423
            ("RESOURCE",      LOCATION_MODULE),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   424
            ("PROGRAM",       LOCATION_GROUP),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   425
            ("VAR_INPUT",     LOCATION_VAR_INPUT),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   426
            ("VAR_OUTPUT",    LOCATION_VAR_OUTPUT),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   427
            ("VAR_LOCAL",     LOCATION_VAR_MEMORY)]:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   428
            self.LocationImageDict[itemtype] = self.LocationImageList.Add(GetBitmap(imgname))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   429
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   430
        # Icons for other items
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   431
        for imgname, itemtype in [
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   432
            ("Extension", ITEM_CONFNODE)]:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   433
            self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   434
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   435
        if projectOpen is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   436
            projectOpen = DecodeFileSystemPath(projectOpen, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   437
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   438
        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
   439
            self.CTR = ProjectController(self, self.Log)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   440
            self.Controler = self.CTR
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   441
            result, err = self.CTR.LoadProject(projectOpen, buildpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   442
            if not result:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   443
                self.LibraryPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   444
                self.ProjectTree.Enable(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   445
                self.PouInstanceVariablesPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   446
                self.RefreshConfigRecentProjects(os.path.abspath(projectOpen))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   447
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   448
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   449
                self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   450
                self.ShowErrorMessage(result)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   451
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   452
            self.CTR = ctr
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   453
            self.Controler = ctr
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   454
            if ctr is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   455
                self.LibraryPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   456
                self.ProjectTree.Enable(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   457
                self.PouInstanceVariablesPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   458
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   459
        if self.EnableDebug:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   460
            self.DebugVariablePanel.SetDataProducer(self.CTR)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   461
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   462
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   463
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   464
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   465
        self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   466
        self.LogConsole.SetFocus()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   467
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   468
    def RefreshTitle(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   469
        name = _("Beremiz")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   470
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   471
            projectname = self.CTR.GetProjectName()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   472
            if self.CTR.ProjectTestModified():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   473
                projectname = "~%s~" % projectname
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   474
            self.SetTitle("%s - %s" % (name, projectname))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   475
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   476
            self.SetTitle(name)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   477
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   478
    def StartLocalRuntime(self, taskbaricon=True):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   479
        if (self.local_runtime is None) or (self.local_runtime.exitcode is not None):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   480
            # create temporary directory for runtime working directory
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   481
            self.local_runtime_tmpdir = tempfile.mkdtemp()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   482
            # choose an arbitrary random port for runtime
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   483
            self.runtime_port = int(random.random() * 1000) + 61131
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   484
            # launch local runtime
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   485
            self.local_runtime = ProcessLogger(self.Log,
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   486
                "\"%s\" \"%s\" -p %s -i localhost %s %s" % (
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   487
                    sys.executable,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   488
                    Bpath("Beremiz_service.py"),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   489
                    self.runtime_port,
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   490
                    {False: "-x 0", True: "-x 1"}[taskbaricon],
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   491
                    self.local_runtime_tmpdir),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   492
                no_gui=False,
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   493
                timeout=500, keyword=self.local_runtime_tmpdir,
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   494
                cwd=self.local_runtime_tmpdir)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   495
            self.local_runtime.spin()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   496
        return self.runtime_port
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   497
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   498
    def KillLocalRuntime(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   499
        if self.local_runtime is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   500
            # shutdown local runtime
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   501
            self.local_runtime.kill(gently=False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   502
            # clear temp dir
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   503
            shutil.rmtree(self.local_runtime_tmpdir)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   504
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   505
            self.local_runtime = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   506
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   507
    def OnOpenWidgetInspector(self, evt):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   508
        # Activate the widget inspection tool
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   509
        from wx.lib.inspection import InspectionTool
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   510
        if not InspectionTool().initialized:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   511
            InspectionTool().Init()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   512
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   513
        # 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
   514
        # 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
   515
        wnd = wx.FindWindowAtPointer()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   516
        if not wnd:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   517
            wnd = self
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   518
        InspectionTool().Show(wnd, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   519
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   520
    def OnLogConsoleFocusChanged(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   521
        self.RefreshEditMenu()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   522
        event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   523
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   524
    def OnLogConsoleUpdateUI(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   525
        self.SetCopyBuffer(self.LogConsole.GetSelectedText(), True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   526
        event.Skip()
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
    def OnLogConsoleMarginClick(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   529
        line_idx = self.LogConsole.LineFromPosition(event.GetPosition())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   530
        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
   531
        event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   532
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   533
    def OnLogConsoleModified(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   534
        line_idx = self.LogConsole.LineFromPosition(event.GetPosition())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   535
        line = self.LogConsole.GetLine(line_idx)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   536
        if line:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   537
            result = MATIEC_ERROR_MODEL.match(line)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   538
            if result is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   539
                self.LogConsole.MarkerAdd(line_idx, 0)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   540
        event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   541
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   542
    def SearchLineForError(self, line):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   543
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   544
            result = MATIEC_ERROR_MODEL.match(line)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   545
            if result is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   546
                first_line, first_column, last_line, last_column, error = result.groups()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   547
                infos = self.CTR.ShowError(self.Log,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   548
                                                  (int(first_line), int(first_column)),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   549
                                                  (int(last_line), int(last_column)))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   550
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   551
    ## Function displaying an Error dialog in PLCOpenEditor.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   552
    #  @return False if closing cancelled.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   553
    def CheckSaveBeforeClosing(self, title=_("Close Project")):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   554
        if self.CTR.ProjectTestModified():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   555
            dialog = wx.MessageDialog(self,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   556
                                      _("There are changes, do you want to save?"),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   557
                                      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
   558
                                      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
   559
            answer = dialog.ShowModal()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   560
            dialog.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   561
            if answer == wx.ID_YES:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   562
                self.CTR.SaveProject()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   563
            elif answer == wx.ID_CANCEL:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   564
                return False
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   565
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   566
        for idx in xrange(self.TabsOpened.GetPageCount()):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   567
            window = self.TabsOpened.GetPage(idx)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   568
            if not window.CheckSaveBeforeClosing():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   569
                return False
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   570
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   571
        return True
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   572
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   573
    def GetTabInfos(self, tab):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   574
        if (isinstance(tab, EditorPanel) and
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   575
            not isinstance(tab, (Viewer,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   576
                                 TextViewer,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   577
                                 ResourceEditor,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   578
                                 ConfigurationEditor,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   579
                                 DataTypeEditor))):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   580
            return ("confnode", tab.Controler.CTNFullName(), tab.GetTagName())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   581
        elif (isinstance(tab, TextViewer) and
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   582
              (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
   583
            return ("confnode", None, tab.GetInstancePath())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   584
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   585
            return IDEFrame.GetTabInfos(self, tab)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   586
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   587
    def LoadTab(self, notebook, page_infos):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   588
        if page_infos[0] == "confnode":
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   589
            if page_infos[1] is None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   590
                confnode = self.CTR
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   591
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   592
                confnode = self.CTR.GetChildByName(page_infos[1])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   593
            return notebook.GetPageIndex(confnode._OpenView(*page_infos[2:]))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   594
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   595
            return IDEFrame.LoadTab(self, notebook, page_infos)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   596
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   597
    # Strange hack required by WAMP connector, using twisted.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   598
    # 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
   599
    # since it cannot be restarted
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   600
    ToDoBeforeQuit = []
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1750
diff changeset
   601
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   602
    def AddToDoBeforeQuit(self, Thing):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   603
        self.ToDoBeforeQuit.append(Thing)
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 OnCloseFrame(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   606
        for evt_type in [wx.EVT_SET_FOCUS,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   607
                         wx.EVT_KILL_FOCUS,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   608
                         wx.stc.EVT_STC_UPDATEUI]:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   609
            self.LogConsole.Unbind(evt_type)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   610
        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
   611
            if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   612
                self.CTR.KillDebugThread()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   613
            self.KillLocalRuntime()
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
            self.SaveLastState()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   616
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   617
            for Thing in self.ToDoBeforeQuit:
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   618
                Thing()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   619
            self.ToDoBeforeQuit = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   620
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   621
            event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   622
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   623
            event.Veto()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   624
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   625
    def RefreshFileMenu(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   626
        self.RefreshRecentProjectsMenu()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   627
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   628
        MenuToolBar = self.Panes["MenuToolBar"]
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   629
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   630
            selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   631
            if selected >= 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   632
                window = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   633
                viewer_is_modified = window.IsModified()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   634
                is_viewer = isinstance(window, Viewer)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   635
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   636
                viewer_is_modified = is_viewer = False
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   637
            if self.TabsOpened.GetPageCount() > 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   638
                self.FileMenu.Enable(wx.ID_CLOSE, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   639
                if is_viewer:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   640
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   641
                    self.FileMenu.Enable(wx.ID_PRINT, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   642
                    MenuToolBar.EnableTool(wx.ID_PRINT, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   643
                else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   644
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   645
                    self.FileMenu.Enable(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   646
                    MenuToolBar.EnableTool(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   647
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   648
                self.FileMenu.Enable(wx.ID_CLOSE, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   649
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   650
                self.FileMenu.Enable(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   651
                MenuToolBar.EnableTool(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   652
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   653
            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
   654
            self.FileMenu.Enable(wx.ID_SAVE, project_modified)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   655
            MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   656
            self.FileMenu.Enable(wx.ID_SAVEAS, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   657
            MenuToolBar.EnableTool(wx.ID_SAVEAS, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   658
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   659
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   660
            self.FileMenu.Enable(wx.ID_CLOSE, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   661
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   662
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   663
            self.FileMenu.Enable(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   664
            MenuToolBar.EnableTool(wx.ID_PRINT, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   665
            self.FileMenu.Enable(wx.ID_SAVE, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   666
            MenuToolBar.EnableTool(wx.ID_SAVE, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   667
            self.FileMenu.Enable(wx.ID_SAVEAS, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   668
            MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   669
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   670
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   671
    def RefreshRecentProjectsMenu(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   672
        try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   673
            recent_projects = map(DecodeFileSystemPath,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   674
                                  self.GetConfigEntry("RecentProjects", []))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   675
        except:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   676
            recent_projects = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   677
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   678
        while self.RecentProjectsMenu.GetMenuItemCount() > len(recent_projects):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   679
            item = self.RecentProjectsMenu.FindItemByPosition(0)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   680
            self.RecentProjectsMenu.RemoveItem(item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   681
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   682
        self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   683
        for idx, projectpath in enumerate(recent_projects):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   684
            text = u'&%d: %s' % (idx + 1, projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   685
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   686
            if idx < self.RecentProjectsMenu.GetMenuItemCount():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   687
                item = self.RecentProjectsMenu.FindItemByPosition(idx)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   688
                id = item.GetId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   689
                item.SetItemLabel(text)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   690
                self.Disconnect(id, id, wx.EVT_BUTTON._getEvtType())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   691
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   692
                id = wx.NewId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   693
                AppendMenu(self.RecentProjectsMenu, help='', id=id,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   694
                           kind=wx.ITEM_NORMAL, text=text)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   695
            self.Bind(wx.EVT_MENU, self.GenerateOpenRecentProjectFunction(projectpath), id=id)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   696
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   697
    def GenerateOpenRecentProjectFunction(self, projectpath):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   698
        def OpenRecentProject(event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   699
            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
   700
                return
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   701
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   702
            self.OpenProject(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   703
        return OpenRecentProject
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   704
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   705
    def GenerateMenuRecursive(self, items, menu):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   706
        for kind, infos in items:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   707
            if isinstance(kind, ListType):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   708
                text, id = infos
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   709
                submenu = wx.Menu('')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   710
                self.GenerateMenuRecursive(kind, submenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   711
                menu.AppendMenu(id, text, submenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   712
            elif kind == wx.ITEM_SEPARATOR:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   713
                menu.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   714
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   715
                text, id, help, callback = infos
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   716
                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
   717
                if callback is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   718
                    self.Bind(wx.EVT_MENU, callback, id=id)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   719
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   720
    def RefreshEditorToolBar(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   721
        IDEFrame.RefreshEditorToolBar(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   722
        self.AUIManager.GetPane("EditorToolBar").Position(2)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   723
        self.AUIManager.GetPane("StatusToolBar").Position(1)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   724
        self.AUIManager.Update()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   725
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   726
    def RefreshStatusToolBar(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   727
        StatusToolBar = self.Panes["StatusToolBar"]
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   728
        StatusToolBar.ClearTools()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   729
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   730
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   731
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   732
            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
   733
                if "method" in confnode_method and confnode_method.get("shown", True):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   734
                    id = wx.NewId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   735
                    StatusToolBar.AddSimpleTool(id,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   736
                        GetBitmap(confnode_method.get("bitmap", "Unknown")),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   737
                        confnode_method["tooltip"])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   738
                    self.Bind(wx.EVT_MENU, self.GetMenuCallBackFunction(confnode_method["method"]), 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
            StatusToolBar.Realize()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   741
            self.AUIManager.GetPane("StatusToolBar").BestSize(StatusToolBar.GetBestSize()).Show()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   742
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   743
            self.AUIManager.GetPane("StatusToolBar").Hide()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   744
        self.AUIManager.GetPane("EditorToolBar").Position(2)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   745
        self.AUIManager.GetPane("StatusToolBar").Position(1)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   746
        self.AUIManager.Update()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   747
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   748
    def RefreshEditMenu(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   749
        IDEFrame.RefreshEditMenu(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   750
        if self.FindFocus() == self.LogConsole:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   751
            self.EditMenu.Enable(wx.ID_COPY, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   752
            self.Panes["MenuToolBar"].EnableTool(wx.ID_COPY, True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   753
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   754
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   755
            selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   756
            if selected >= 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   757
                panel = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   758
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   759
                panel = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   760
            if panel != self.LastPanelSelected:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   761
                for i in xrange(self.EditMenuSize, self.EditMenu.GetMenuItemCount()):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   762
                    item = self.EditMenu.FindItemByPosition(self.EditMenuSize)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   763
                    if item is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   764
                        if item.IsSeparator():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   765
                            self.EditMenu.RemoveItem(item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   766
                        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   767
                            self.EditMenu.Delete(item.GetId())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   768
                self.LastPanelSelected = panel
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   769
                if panel is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   770
                    items = panel.GetConfNodeMenuItems()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   771
                else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   772
                    items = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   773
                if len(items) > 0:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   774
                    self.EditMenu.AppendSeparator()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   775
                    self.GenerateMenuRecursive(items, self.EditMenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   776
            if panel is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   777
                panel.RefreshConfNodeMenu(self.EditMenu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   778
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   779
            for i in xrange(self.EditMenuSize, self.EditMenu.GetMenuItemCount()):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   780
                item = self.EditMenu.FindItemByPosition(i)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   781
                if item is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   782
                    if item.IsSeparator():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   783
                        self.EditMenu.RemoveItem(item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   784
                    else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   785
                        self.EditMenu.Delete(item.GetId())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   786
            self.LastPanelSelected = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   787
        self.MenuBar.UpdateMenus()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   788
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   789
    def RefreshAll(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   790
        self.RefreshStatusToolBar()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   791
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   792
    def GetMenuCallBackFunction(self, method):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   793
        """ Generate the callbackfunc for a given CTR method"""
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   794
        def OnMenu(event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   795
            # Disable button to prevent re-entrant call
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   796
            event.GetEventObject().Disable()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   797
            # Call
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   798
            getattr(self.CTR, method)()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   799
            # Re-enable button
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   800
            event.GetEventObject().Enable()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   801
        return OnMenu
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   802
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   803
    def GetConfigEntry(self, entry_name, default):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   804
        return cPickle.loads(str(self.Config.Read(entry_name, cPickle.dumps(default))))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   805
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   806
    def ResetConnectionStatusBar(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   807
        for field in xrange(self.ConnectionStatusBar.GetFieldsCount()):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   808
            self.ConnectionStatusBar.SetStatusText('', field)
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 ResetView(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   811
        IDEFrame.ResetView(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   812
        self.ConfNodeInfos = {}
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   813
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   814
            self.CTR.CloseProject()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   815
        self.CTR = None
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   816
        self.Log.flush()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   817
        if self.EnableDebug:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   818
            self.DebugVariablePanel.SetDataProducer(None)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   819
            self.ResetConnectionStatusBar()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   820
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   821
    def RefreshConfigRecentProjects(self, projectpath, err=False):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   822
        try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   823
            recent_projects = map(DecodeFileSystemPath,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   824
                                  self.GetConfigEntry("RecentProjects", []))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   825
        except:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   826
            recent_projects = []
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   827
        if projectpath in recent_projects:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   828
            recent_projects.remove(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   829
        if not err:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   830
            recent_projects.insert(0, projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   831
        self.Config.Write("RecentProjects", cPickle.dumps(
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   832
            map(EncodeFileSystemPath, recent_projects[:MAX_RECENT_PROJECTS])))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   833
        self.Config.Flush()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   834
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   835
    def ResetPerspective(self):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   836
        IDEFrame.ResetPerspective(self)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   837
        self.RefreshStatusToolBar()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   838
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   839
    def OnNewProjectMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   840
        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
   841
            return
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
        try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   844
            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   845
        except:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   846
            defaultpath = os.path.expanduser("~")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   847
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1737
diff changeset
   848
        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
   849
        if dialog.ShowModal() == wx.ID_OK:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   850
            projectpath = dialog.GetPath()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   851
            self.Config.Write("lastopenedfolder",
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   852
                              EncodeFileSystemPath(os.path.dirname(projectpath)))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   853
            self.Config.Flush()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   854
            self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   855
            ctr = ProjectController(self, self.Log)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   856
            result = ctr.NewProject(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   857
            if not result:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   858
                self.CTR = ctr
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   859
                self.Controler = self.CTR
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   860
                self.LibraryPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   861
                self.ProjectTree.Enable(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   862
                self.PouInstanceVariablesPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   863
                self.RefreshConfigRecentProjects(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   864
                if self.EnableDebug:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   865
                    self.DebugVariablePanel.SetDataProducer(self.CTR)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   866
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
1708
24416137cda7 add dialog "add program", that appears after creating new project
Surkov Sergey <surkovsv93@gmail.com>
parents: 1692
diff changeset
   867
                IDEFrame.OnAddNewProject(self, event)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   868
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   869
                self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   870
                self.ShowErrorMessage(result)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   871
            self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   872
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   873
        dialog.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   874
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   875
    def OnOpenProjectMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   876
        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
   877
            return
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   878
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   879
        try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   880
            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   881
        except:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   882
            defaultpath = os.path.expanduser("~")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   883
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   884
        dialog = wx.DirDialog(self, _("Choose a project"), defaultpath, style=wx.DEFAULT_DIALOG_STYLE |
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   885
                                                                               wx.RESIZE_BORDER)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   886
        if dialog.ShowModal() == wx.ID_OK:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   887
            self.OpenProject(dialog.GetPath())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   888
        dialog.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   889
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   890
    def OpenProject(self, projectpath):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   891
        if os.path.isdir(projectpath):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   892
            self.Config.Write("lastopenedfolder",
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   893
                              EncodeFileSystemPath(os.path.dirname(projectpath)))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   894
            self.Config.Flush()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   895
            self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   896
            self.CTR = ProjectController(self, self.Log)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   897
            self.Controler = self.CTR
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   898
            result, err = self.CTR.LoadProject(projectpath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   899
            if not result:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   900
                self.LibraryPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   901
                self.ProjectTree.Enable(True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   902
                self.PouInstanceVariablesPanel.SetController(self.Controler)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   903
                if self.EnableDebug:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   904
                    self.DebugVariablePanel.SetDataProducer(self.CTR)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   905
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   906
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   907
                self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   908
                self.ShowErrorMessage(result)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   909
            self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   910
            self.SearchResultPanel.ResetSearchResults()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   911
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   912
            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
   913
            err = True
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   914
        self.RefreshConfigRecentProjects(projectpath, err)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   915
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   916
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   917
    def OnCloseProjectMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   918
        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
   919
            return
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   920
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   921
        self.ResetView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   922
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   923
        self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   924
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   925
    def OnSaveProjectMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   926
        selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   927
        if selected != -1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   928
            window = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   929
            window.Save()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   930
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   931
            self.CTR.SaveProject()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   932
            self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   933
            self._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   934
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   935
    def OnSaveProjectAsMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   936
        selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   937
        if selected != -1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   938
            window = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   939
            window.SaveAs()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   940
        if self.CTR is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   941
            self.CTR.SaveProjectAs()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   942
            self.RefreshAll()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   943
            self.RefreshConfigRecentProjects(self.CTR.ProjectPath)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   944
            self._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES)
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
    def OnQuitMenu(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   947
        self.Close()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   948
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   949
    def OnAboutMenu(self, event):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1721
diff changeset
   950
        info = version.GetAboutDialogInfo()
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   951
        ShowAboutDialog(self, info)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   952
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   953
    def OnProjectTreeItemBeginEdit(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   954
        selected = event.GetItem()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   955
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_CONFNODE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   956
            event.Veto()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   957
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   958
            IDEFrame.OnProjectTreeItemBeginEdit(self, event)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   959
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   960
    def OnProjectTreeRightUp(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   961
        item = event.GetItem()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   962
        item_infos = self.ProjectTree.GetPyData(item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   963
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   964
        if item_infos["type"] == ITEM_CONFNODE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   965
            confnode_menu = wx.Menu(title='')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   966
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   967
            confnode = item_infos["confnode"]
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   968
            if confnode is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   969
                menu_items = confnode.GetContextualMenuItems()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   970
                if menu_items is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   971
                    for text, help, callback in menu_items:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   972
                        new_id = wx.NewId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   973
                        confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=text)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   974
                        self.Bind(wx.EVT_MENU, callback, id=new_id)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   975
                else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   976
                    for name, XSDClass, help 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
   977
                        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
   978
                                or len(confnode.Children[name]) < XSDClass.CTNMaxCount:
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
   979
                            new_id = wx.NewId()
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
   980
                            confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Add") + " " + 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
   981
                            self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name, confnode), id=new_id)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   982
            new_id = wx.NewId()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   983
            AppendMenu(confnode_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Delete"))
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   984
            self.Bind(wx.EVT_MENU, self.GetDeleteMenuFunction(confnode), id=new_id)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   985
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   986
            self.PopupMenu(confnode_menu)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   987
            confnode_menu.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   988
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   989
            event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   990
        elif item_infos["type"] == ITEM_RESOURCE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   991
            # prevent last resource to be delted
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   992
            parent = self.ProjectTree.GetItemParent(item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   993
            parent_name = self.ProjectTree.GetItemText(parent)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   994
            if parent_name == _("Resources"):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   995
                IDEFrame.OnProjectTreeRightUp(self, event)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   996
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
   997
            IDEFrame.OnProjectTreeRightUp(self, event)
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 OnProjectTreeItemActivated(self, event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1000
        selected = event.GetItem()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1001
        name = self.ProjectTree.GetItemText(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1002
        item_infos = self.ProjectTree.GetPyData(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1003
        if item_infos["type"] == ITEM_CONFNODE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1004
            item_infos["confnode"]._OpenView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1005
            event.Skip()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1006
        elif item_infos["type"] == ITEM_PROJECT:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1007
            self.CTR._OpenView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1008
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1009
            IDEFrame.OnProjectTreeItemActivated(self, event)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1010
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1011
    def ProjectTreeItemSelect(self, select_item):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1012
        if select_item is not None and select_item.IsOk():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1013
            name = self.ProjectTree.GetItemText(select_item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1014
            item_infos = self.ProjectTree.GetPyData(select_item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1015
            if item_infos["type"] == ITEM_CONFNODE:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1016
                item_infos["confnode"]._OpenView(onlyopened=True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1017
            elif item_infos["type"] == ITEM_PROJECT:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1018
                self.CTR._OpenView(onlyopened=True)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1019
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1020
                IDEFrame.ProjectTreeItemSelect(self, select_item)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1021
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1022
    def SelectProjectTreeItem(self, tagname):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1023
        if self.ProjectTree is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1024
            root = self.ProjectTree.GetRootItem()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1025
            if root.IsOk():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1026
                words = tagname.split("::")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1027
                if len(words) == 1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1028
                    if tagname == "Project":
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1029
                        self.SelectedItem = root
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1030
                        self.ProjectTree.SelectItem(root)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1031
                        self.ResetSelectedItem()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1032
                    else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1033
                        return self.RecursiveProjectTreeItemSelection(root,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1034
                              [(word, ITEM_CONFNODE) for word in tagname.split(".")])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1035
                elif words[0] == "R":
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1036
                    return self.RecursiveProjectTreeItemSelection(root, [(words[2], ITEM_RESOURCE)])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1037
                elif not os.path.exists(words[0]):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1038
                    IDEFrame.SelectProjectTreeItem(self, tagname)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1039
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1040
    def GetAddConfNodeFunction(self, name, confnode=None):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1041
        def AddConfNodeMenuFunction(event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1042
            wx.CallAfter(self.AddConfNode, name, confnode)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1043
        return AddConfNodeMenuFunction
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1044
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1045
    def GetDeleteMenuFunction(self, confnode):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1046
        def DeleteMenuFunction(event):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1047
            wx.CallAfter(self.DeleteConfNode, confnode)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1048
        return DeleteMenuFunction
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1049
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1050
    def AddConfNode(self, ConfNodeType, confnode=None):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1051
        if self.CTR.CheckProjectPathPerm():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1052
            ConfNodeName = "%s_0" % ConfNodeType
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1053
            if confnode is not None:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1054
                confnode.CTNAddChild(ConfNodeName, ConfNodeType)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1055
            else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1056
                self.CTR.CTNAddChild(ConfNodeName, ConfNodeType)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1057
            self._Refresh(TITLE, FILEMENU, PROJECTTREE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1058
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1059
    def DeleteConfNode(self, confnode):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1060
        if self.CTR.CheckProjectPathPerm():
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1061
            dialog = wx.MessageDialog(self,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1062
                _("Really delete node '%s'?") % confnode.CTNName(),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1063
                _("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
  1064
                wx.YES_NO | wx.NO_DEFAULT)
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1065
            if dialog.ShowModal() == wx.ID_YES:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1066
                confnode.CTNRemove()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1067
                del confnode
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1068
                self._Refresh(TITLE, FILEMENU, PROJECTTREE)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1069
            dialog.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1070
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1071
#-------------------------------------------------------------------------------
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1072
#                        Highlights showing functions
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1073
#-------------------------------------------------------------------------------
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1074
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1075
    def ShowHighlight(self, infos, start, end, highlight_type):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1076
        config_name = self.Controler.GetProjectMainConfigurationName()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1077
        if config_name is not None and infos[0] == self.Controler.ComputeConfigurationName(config_name):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1078
            self.CTR._OpenView()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1079
            selected = self.TabsOpened.GetSelection()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1080
            if selected != -1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1081
                viewer = self.TabsOpened.GetPage(selected)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1082
                viewer.AddHighlight(infos[1:], start, end, highlight_type)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1083
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1084
            IDEFrame.ShowHighlight(self, infos, start, end, highlight_type)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1085
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
  1086
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1087
#-------------------------------------------------------------------------------
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1088
#                               Exception Handler
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1089
#-------------------------------------------------------------------------------
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1090
import threading
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1091
import traceback
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1092
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1093
Max_Traceback_List_Size = 20
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1094
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
  1095
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1096
def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1097
    trcbck_lst = []
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
  1098
    for i, line in enumerate(traceback.extract_tb(e_tb)):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1099
        trcbck = " " + str(i+1) + ". "
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1100
        if line[0].find(os.getcwd()) == -1:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1101
            trcbck += "file : " + str(line[0]) + ",   "
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1102
        else:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1103
            trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1104
        trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1105
        trcbck_lst.append(trcbck)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1106
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1107
    # Allow clicking....
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1108
    cap = wx.Window_GetCapture()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1109
    if cap:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1110
        cap.ReleaseMouse()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1111
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1112
    dlg = wx.SingleChoiceDialog(None,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1113
        _("""
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1114
An unhandled exception (bug) occured. Bug report saved at :
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1115
(%s)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1116
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1117
Please be kind enough to send this file to:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1118
beremiz-devel@lists.sourceforge.net
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1119
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1120
You should now restart program.
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1121
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1122
Traceback:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1123
""") % bug_report_path +
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1124
        repr(e_type) + " : " + repr(e_value),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1125
        _("Error"),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1126
        trcbck_lst)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1127
    try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1128
        res = (dlg.ShowModal() == wx.ID_OK)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1129
    finally:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1130
        dlg.Destroy()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1131
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1132
    return res
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1133
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
  1134
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1135
def get_last_traceback(tb):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1136
    while tb.tb_next:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1137
        tb = tb.tb_next
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1138
    return tb
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1139
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1140
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1141
def format_namespace(d, indent='    '):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1142
    return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1143
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1144
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
  1145
ignored_exceptions = []  # a problem with a line in a module is only reported once per session
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
  1146
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
  1147
1760
ed2e2afb9573 clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1757
diff changeset
  1148
def AddExceptHook(path, app_version='[No version]'):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1149
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
  1150
    def save_bug_report(e_type, e_value, e_traceback, bug_report_path, date):
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1151
        info = {
1760
ed2e2afb9573 clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1757
diff changeset
  1152
            'app-title': wx.GetApp().GetAppName(),
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1153
            'app-version': app_version,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1154
            'wx-version': wx.VERSION_STRING,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1155
            'wx-platform': wx.Platform,
1760
ed2e2afb9573 clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1757
diff changeset
  1156
            'python-version': platform.python_version(),
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1157
            'platform': platform.platform(),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1158
            'e-type': e_type,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1159
            'e-value': e_value,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1160
            'date': date,
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1161
            'cwd': os.getcwd(),
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1162
        }
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1163
        if e_traceback:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1164
            info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1165
            last_tb = get_last_traceback(e_traceback)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1166
            exception_locals = last_tb.tb_frame.f_locals  # the locals at the level of the stack trace where the exception actually occurred
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1167
            info['locals'] = format_namespace(exception_locals)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1168
            if 'self' in exception_locals:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1169
                try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1170
                    info['self'] = format_namespace(exception_locals['self'].__dict__)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1171
                except:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1172
                    pass
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1173
        if not os.path.exists(path):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1174
            os.mkdir(path)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1175
        output = open(bug_report_path, 'w')
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1176
        lst = info.keys()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1177
        lst.sort()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1178
        for a in lst:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1179
            output.write(a + ":\n" + str(info[a]) + "\n\n")
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1180
        output.close()
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1181
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1182
    def handle_exception(e_type, e_value, e_traceback):
1737
a39c2918c015 clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
  1183
        traceback.print_exception(e_type, e_value, e_traceback)  # this is very helpful when there's an exception in the rest of this func
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1184
        last_tb = get_last_traceback(e_traceback)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1185
        ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1186
        if ex not in ignored_exceptions:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1187
            ignored_exceptions.append(ex)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1188
            date = time.ctime()
1718
703ddaf48b00 change structure of filename for bug reports in Beremiz and
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1708
diff changeset
  1189
            bug_report_path = path + os.sep + "bug_report_" + time.strftime("%Y_%m_%d__%H-%M-%S") + ".txt"
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1190
            save_bug_report(e_type, e_value, e_traceback, bug_report_path, date)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1191
            Display_Exception_Dialog(e_type, e_value, e_traceback, bug_report_path)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1192
    #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1193
    sys.excepthook = handle_exception
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1194
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1195
    init_old = threading.Thread.__init__
1750
acf02488f37f clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
  1196
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1197
    def init(self, *args, **kwargs):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1198
        init_old(self, *args, **kwargs)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1199
        run_old = self.run
1750
acf02488f37f clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
  1200
1662
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1201
        def run_with_except_hook(*args, **kw):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1202
            try:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1203
                run_old(*args, **kw)
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1204
            except (KeyboardInterrupt, SystemExit):
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1205
                raise
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1206
            except:
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1207
                sys.excepthook(*sys.exc_info())
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1208
        self.run = run_with_except_hook
8816f7316d9c rename Beremiz.py to BeremizIDE.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
  1209
    threading.Thread.__init__ = init