Beremiz.py
author mjsousa
Tue, 08 Jul 2014 18:01:33 +0100
changeset 1471 3eda8d8f622d
parent 1408 eb2aa27602b7
child 1441 826730e60407
permissions -rwxr-xr-x
merge
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
     1
#!/usr/bin/env python
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
     2
# -*- coding: utf-8 -*-
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
     3
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
     4
#This file is part of Beremiz, a Integrated Development Environment for
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
     5
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
     6
#
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
     8
#
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
     9
#See COPYING file for copyrights details.
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    10
#
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    11
#This library is free software; you can redistribute it and/or
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    12
#modify it under the terms of the GNU General Public
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    13
#License as published by the Free Software Foundation; either
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    15
#
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    16
#This library is distributed in the hope that it will be useful,
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    19
#General Public License for more details.
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    20
#
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    21
#You should have received a copy of the GNU General Public
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    22
#License along with this library; if not, write to the Free Software
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    24
588
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    25
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    26
updateinfo_url = None
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    27
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    28
import os, sys, getopt, wx
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
    29
import __builtin__
588
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    30
from wx.lib.agw.advancedsplash import AdvancedSplash
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    31
import tempfile
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    32
import shutil
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    33
import random
446
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 439
diff changeset
    34
import time
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
    35
from types import ListType
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    36
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    37
CWD = os.path.split(os.path.realpath(__file__))[0]
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    38
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    39
def Bpath(*args):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    40
    return os.path.join(CWD,*args)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    41
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    42
if __name__ == '__main__':
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    43
    def usage():
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    44
        print "\nUsage of Beremiz.py :"
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    45
        print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
    46
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    47
    try:
736
944e58c00ca5 Fixed argument parsing error
Edouard Tisserant
parents: 735
diff changeset
    48
        opts, args = getopt.getopt(sys.argv[1:], "hu:e:", ["help", "updatecheck=", "extend="])
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    49
    except getopt.GetoptError:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    50
        # print help information and exit:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    51
        usage()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    52
        sys.exit(2)
731
4fc681ed0c61 refecored library extension machanism
Edouard Tisserant
parents: 730
diff changeset
    53
4fc681ed0c61 refecored library extension machanism
Edouard Tisserant
parents: 730
diff changeset
    54
    extensions=[]
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
    55
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    56
    for o, a in opts:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    57
        if o in ("-h", "--help"):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    58
            usage()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    59
            sys.exit()
588
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    60
        if o in ("-u", "--updatecheck"):
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    61
            updateinfo_url = a
731
4fc681ed0c61 refecored library extension machanism
Edouard Tisserant
parents: 730
diff changeset
    62
        if o in ("-e", "--extend"):
4fc681ed0c61 refecored library extension machanism
Edouard Tisserant
parents: 730
diff changeset
    63
            extensions.append(a)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
    64
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    65
    if len(args) > 2:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    66
        usage()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    67
        sys.exit()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    68
    elif len(args) == 1:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    69
        projectOpen = args[0]
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    70
        buildpath = None
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    71
    elif len(args) == 2:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    72
        projectOpen = args[0]
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    73
        buildpath = args[1]
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    74
    else:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    75
        projectOpen = None
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    76
        buildpath = None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
    77
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 569
diff changeset
    78
    if os.path.exists("BEREMIZ_DEBUG"):
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
    79
        __builtin__.__dict__["BMZ_DBG"] = True
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 569
diff changeset
    80
    else :
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
    81
        __builtin__.__dict__["BMZ_DBG"] = False
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 569
diff changeset
    82
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 569
diff changeset
    83
    app = wx.PySimpleApp(redirect=BMZ_DBG)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    84
    app.SetAppName('beremiz')
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    85
    wx.InitAllImageHandlers()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
    86
588
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    87
    # popup splash
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
    88
    bmp = wx.Image(Bpath("images", "splash.png")).ConvertToBitmap()
588
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    89
    #splash=AdvancedSplash(None, bitmap=bmp, style=wx.SPLASH_CENTRE_ON_SCREEN, timeout=4000)
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    90
    splash=AdvancedSplash(None, bitmap=bmp)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    91
    wx.Yield()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
    92
588
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    93
    if updateinfo_url is not None:
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    94
        updateinfo = "Fetching %s" % updateinfo_url
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    95
        # warn for possible updates
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    96
        def updateinfoproc():
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    97
            global updateinfo
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    98
            try :
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
    99
                import urllib2
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   100
                updateinfo = urllib2.urlopen(updateinfo_url,None).read()
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   101
            except :
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   102
                updateinfo = "update info unavailable."
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   103
588
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   104
        from threading import Thread
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   105
        splash.SetText(text=updateinfo)
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   106
        wx.Yield()
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   107
        updateinfoThread = Thread(target=updateinfoproc)
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   108
        updateinfoThread.start()
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   109
        updateinfoThread.join(2)
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   110
        splash.SetText(text=updateinfo)
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   111
        wx.Yield()
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
   112
1388
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   113
    from util.misc import InstallLocalRessources
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   114
    InstallLocalRessources(CWD)
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   115
735
d9f4ecee761d Fixed extension loading too late causing features to be ignored
Edouard Tisserant
parents: 734
diff changeset
   116
    # Load extensions
d9f4ecee761d Fixed extension loading too late causing features to be ignored
Edouard Tisserant
parents: 734
diff changeset
   117
    for extfilename in extensions:
1393
e6c3908c925d Fixed import error when loading extensions
Edouard Tisserant
parents: 1388
diff changeset
   118
        from util.TranslationCatalogs import AddCatalog
e6c3908c925d Fixed import error when loading extensions
Edouard Tisserant
parents: 1388
diff changeset
   119
        from util.BitmapLibrary import AddBitmapFolder
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   120
        extension_folder = os.path.split(os.path.realpath(extfilename))[0]
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   121
        sys.path.append(extension_folder)
815
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents: 814
diff changeset
   122
        AddCatalog(os.path.join(extension_folder, "locale"))
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   123
        AddBitmapFolder(os.path.join(extension_folder, "images"))
737
7b421e080636 fixed typos
Edouard Tisserant
parents: 736
diff changeset
   124
        execfile(extfilename, locals())
735
d9f4ecee761d Fixed extension loading too late causing features to be ignored
Edouard Tisserant
parents: 734
diff changeset
   125
1388
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   126
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   127
import wx.lib.buttons, wx.lib.statbmp, wx.stc
724
e0630d262ac3 refactoring
Edouard Tisserant
parents: 722
diff changeset
   128
import cPickle
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   129
import types, time, re, platform, time, traceback, commands
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   130
727
3edd2f19bce2 refactoring
Edouard Tisserant
parents: 726
diff changeset
   131
from docutil import OpenHtmlFrame
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   132
from editors.EditorPanel import EditorPanel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   133
from editors.Viewer import Viewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   134
from editors.TextViewer import TextViewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   135
from editors.ResourceEditor import ConfigurationEditor, ResourceEditor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   136
from editors.DataTypeEditor import DataTypeEditor
807
17c97fec1164 Fix import order in Beremiz.py to prevent wrong translations in internationalization
laurent
parents: 801
diff changeset
   137
from util.MiniTextControler import MiniTextControler
17c97fec1164 Fix import order in Beremiz.py to prevent wrong translations in internationalization
laurent
parents: 801
diff changeset
   138
from util.ProcessLogger import ProcessLogger
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents: 973
diff changeset
   139
from controls.LogViewer import LogViewer
1091
5f612651d227 Fixed bug with margin cursor in StyledTextCtrl on Windows
Laurent Bessard
parents: 1090
diff changeset
   140
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   141
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   142
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE
1282
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   143
from ProjectController import ProjectController, GetAddMenuItems, MATIEC_ERROR_MODEL, ITEM_CONFNODE
807
17c97fec1164 Fix import order in Beremiz.py to prevent wrong translations in internationalization
laurent
parents: 801
diff changeset
   144
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   145
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   146
MAX_RECENT_PROJECTS = 10
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   147
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   148
if wx.Platform == '__WXMSW__':
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   149
    faces = {
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   150
        'mono' : 'Courier New',
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   151
        'size' : 8,
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   152
    }
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   153
else:
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   154
    faces = {
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   155
        'mono' : 'Courier',
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   156
        'size' : 10,
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   157
    }
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   158
705
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   159
from threading import Lock,Timer,currentThread
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   160
MainThread = currentThread().ident
686
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   161
REFRESH_PERIOD = 0.1
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   162
from time import time as gettime
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   163
class LogPseudoFile:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   164
    """ Base class for file like objects to facilitate StdOut for the Shell."""
451
73b3913b6d9c Fixed automatic console rising on w32
edouard
parents: 446
diff changeset
   165
    def __init__(self, output, risecall):
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   166
        self.red_white = 1
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   167
        self.red_yellow = 2
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   168
        self.black_white = wx.stc.STC_STYLE_DEFAULT
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   169
        self.output = output
451
73b3913b6d9c Fixed automatic console rising on w32
edouard
parents: 446
diff changeset
   170
        self.risecall = risecall
446
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 439
diff changeset
   171
        # to prevent rapid fire on rising log panel
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 439
diff changeset
   172
        self.rising_timer = 0
686
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   173
        self.lock = Lock()
705
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   174
        self.YieldLock = Lock()
686
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   175
        self.RefreshLock = Lock()
881
68ac754a5a72 Fix bug with concurrent access to LastRefreshTimer in LogPseudoFile for Log Console
Laurent Bessard
parents: 875
diff changeset
   176
        self.TimerAccessLock = Lock()
686
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   177
        self.stack = []
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   178
        self.LastRefreshTime = gettime()
688
6324b40d82a5 Even more robust logger, up to the really last line that comes after the rush
Edouard Tisserant
parents: 687
diff changeset
   179
        self.LastRefreshTimer = None
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   180
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   181
    def write(self, s, style = None):
686
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   182
        if self.lock.acquire():
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   183
            self.stack.append((s,style))
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   184
            self.lock.release()
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   185
            current_time = gettime()
881
68ac754a5a72 Fix bug with concurrent access to LastRefreshTimer in LogPseudoFile for Log Console
Laurent Bessard
parents: 875
diff changeset
   186
            self.TimerAccessLock.acquire()
688
6324b40d82a5 Even more robust logger, up to the really last line that comes after the rush
Edouard Tisserant
parents: 687
diff changeset
   187
            if self.LastRefreshTimer:
6324b40d82a5 Even more robust logger, up to the really last line that comes after the rush
Edouard Tisserant
parents: 687
diff changeset
   188
                self.LastRefreshTimer.cancel()
6324b40d82a5 Even more robust logger, up to the really last line that comes after the rush
Edouard Tisserant
parents: 687
diff changeset
   189
                self.LastRefreshTimer=None
881
68ac754a5a72 Fix bug with concurrent access to LastRefreshTimer in LogPseudoFile for Log Console
Laurent Bessard
parents: 875
diff changeset
   190
            self.TimerAccessLock.release()
686
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   191
            if current_time - self.LastRefreshTime > REFRESH_PERIOD and self.RefreshLock.acquire(False):
705
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   192
                self._should_write()
688
6324b40d82a5 Even more robust logger, up to the really last line that comes after the rush
Edouard Tisserant
parents: 687
diff changeset
   193
            else:
881
68ac754a5a72 Fix bug with concurrent access to LastRefreshTimer in LogPseudoFile for Log Console
Laurent Bessard
parents: 875
diff changeset
   194
                self.TimerAccessLock.acquire()
875
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   195
                self.LastRefreshTimer = Timer(REFRESH_PERIOD, self._timer_expired)
688
6324b40d82a5 Even more robust logger, up to the really last line that comes after the rush
Edouard Tisserant
parents: 687
diff changeset
   196
                self.LastRefreshTimer.start()
881
68ac754a5a72 Fix bug with concurrent access to LastRefreshTimer in LogPseudoFile for Log Console
Laurent Bessard
parents: 875
diff changeset
   197
                self.TimerAccessLock.release()
686
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   198
875
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   199
    def _timer_expired(self):
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   200
        if self.RefreshLock.acquire(False):
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   201
            self._should_write()
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   202
        else:
881
68ac754a5a72 Fix bug with concurrent access to LastRefreshTimer in LogPseudoFile for Log Console
Laurent Bessard
parents: 875
diff changeset
   203
            self.TimerAccessLock.acquire()
875
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   204
            self.LastRefreshTimer = Timer(REFRESH_PERIOD, self._timer_expired)
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   205
            self.LastRefreshTimer.start()
881
68ac754a5a72 Fix bug with concurrent access to LastRefreshTimer in LogPseudoFile for Log Console
Laurent Bessard
parents: 875
diff changeset
   206
            self.TimerAccessLock.release()
875
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   207
705
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   208
    def _should_write(self):
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   209
        wx.CallAfter(self._write)
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   210
        if MainThread == currentThread().ident:
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   211
            app = wx.GetApp()
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   212
            if app is not None:
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   213
                if self.YieldLock.acquire(0):
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   214
                    app.Yield()
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   215
                    self.YieldLock.release()
a5977f64d4d9 More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents: 704
diff changeset
   216
686
e4e1da75d411 More robust Logger, now resist to flooding.
Edouard Tisserant
parents: 683
diff changeset
   217
    def _write(self):
701
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   218
        if self.output :
875
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 843
diff changeset
   219
            self.output.Freeze()
701
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   220
            self.lock.acquire()
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   221
            for s, style in self.stack:
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   222
                if style is None : style=self.black_white
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   223
                if style != self.black_white:
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   224
                    self.output.StartStyling(self.output.GetLength(), 0xff)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   225
1091
5f612651d227 Fixed bug with margin cursor in StyledTextCtrl on Windows
Laurent Bessard
parents: 1090
diff changeset
   226
                # Temporary deactivate read only mode on StyledTextCtrl for
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   227
                # adding text. It seems that text modifications, even
1091
5f612651d227 Fixed bug with margin cursor in StyledTextCtrl on Windows
Laurent Bessard
parents: 1090
diff changeset
   228
                # programmatically, are disabled in StyledTextCtrl when read
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   229
                # only is active
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   230
                self.output.SetReadOnly(False)
1091
5f612651d227 Fixed bug with margin cursor in StyledTextCtrl on Windows
Laurent Bessard
parents: 1090
diff changeset
   231
                self.output.AppendText(s)
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   232
                self.output.SetReadOnly(True)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   233
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   234
                if style != self.black_white:
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   235
                    self.output.SetStyling(len(s), style)
701
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   236
            self.stack = []
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   237
            self.lock.release()
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   238
            self.output.Thaw()
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   239
            self.LastRefreshTime = gettime()
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   240
            try:
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   241
                self.RefreshLock.release()
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   242
            except:
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   243
                pass
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   244
            newtime = time.time()
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   245
            if newtime - self.rising_timer > 1:
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   246
                self.risecall(self.output)
701
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
   247
            self.rising_timer = newtime
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   248
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   249
    def write_warning(self, s):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   250
        self.write(s,self.red_white)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   251
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   252
    def write_error(self, s):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   253
        self.write(s,self.red_yellow)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   254
569
37af7286dd65 LPC program transfer more verbose, test code added in __main__ of LPCBootProto
Edouqrd Tisserant <edouard.tisserant@gmail.com>
parents: 550
diff changeset
   255
    def writeyield(self, s):
37af7286dd65 LPC program transfer more verbose, test code added in __main__ of LPCBootProto
Edouqrd Tisserant <edouard.tisserant@gmail.com>
parents: 550
diff changeset
   256
        self.write(s)
37af7286dd65 LPC program transfer more verbose, test code added in __main__ of LPCBootProto
Edouqrd Tisserant <edouard.tisserant@gmail.com>
parents: 550
diff changeset
   257
        wx.GetApp().Yield()
37af7286dd65 LPC program transfer more verbose, test code added in __main__ of LPCBootProto
Edouqrd Tisserant <edouard.tisserant@gmail.com>
parents: 550
diff changeset
   258
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   259
    def flush(self):
1091
5f612651d227 Fixed bug with margin cursor in StyledTextCtrl on Windows
Laurent Bessard
parents: 1090
diff changeset
   260
        # Temporary deactivate read only mode on StyledTextCtrl for clearing
5f612651d227 Fixed bug with margin cursor in StyledTextCtrl on Windows
Laurent Bessard
parents: 1090
diff changeset
   261
        # text. It seems that text modifications, even programmatically, are
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   262
        # disabled in StyledTextCtrl when read only is active
1025
36e38d3c28b2 Fixed LogConsole not cleared when building several times
Laurent Bessard
parents: 1024
diff changeset
   263
        self.output.SetReadOnly(False)
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   264
        self.output.SetText("")
1025
36e38d3c28b2 Fixed LogConsole not cleared when building several times
Laurent Bessard
parents: 1024
diff changeset
   265
        self.output.SetReadOnly(True)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   266
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   267
    def isatty(self):
1269
e8e153a7c3bf Fix bug in atty function of LogPseudoFile
Laurent Bessard
parents: 1240
diff changeset
   268
        return False
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   269
1281
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1274
diff changeset
   270
ID_FILEMENURECENTPROJECTS = wx.NewId()
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   271
1388
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   272
from IDEFrame import TITLE,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   273
                     EDITORTOOLBAR,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   274
                     FILEMENU,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   275
                     EDITMENU,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   276
                     DISPLAYMENU,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   277
                     PROJECTTREE,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   278
                     POUINSTANCEVARIABLESPANEL,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   279
                     LIBRARYTREE,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   280
                     SCALING,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   281
                     PAGETITLES,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   282
                     IDEFrame, AppendMenu,\
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   283
                     EncodeFileSystemPath, DecodeFileSystemPath
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   284
from util.BitmapLibrary import GetBitmap
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 1364
diff changeset
   285
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   286
class Beremiz(IDEFrame):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   287
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   288
    def _init_utils(self):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   289
        self.ConfNodeMenu = wx.Menu(title='')
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   290
        self.RecentProjectsMenu = wx.Menu(title='')
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   291
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   292
        IDEFrame._init_utils(self)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   293
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   294
    def _init_coll_FileMenu_Items(self, parent):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   295
        AppendMenu(parent, help='', id=wx.ID_NEW,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   296
              kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N')
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   297
        AppendMenu(parent, help='', id=wx.ID_OPEN,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   298
              kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O')
702
01f5e6356859 Added a few shortcuts in menus
Edouard Tisserant
parents: 701
diff changeset
   299
        parent.AppendMenu(ID_FILEMENURECENTPROJECTS, _("&Recent Projects"), self.RecentProjectsMenu)
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   300
        parent.AppendSeparator()
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   301
        AppendMenu(parent, help='', id=wx.ID_SAVE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   302
              kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S')
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   303
        AppendMenu(parent, help='', id=wx.ID_SAVEAS,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   304
              kind=wx.ITEM_NORMAL, text=_(u'Save as') + '\tCTRL+SHIFT+S')
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   305
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   306
              kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W')
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   307
        AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   308
              kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W')
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   309
        parent.AppendSeparator()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   310
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   311
              kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P')
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   312
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   313
              kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P')
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   314
        AppendMenu(parent, help='', id=wx.ID_PRINT,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   315
              kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P')
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   316
        parent.AppendSeparator()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   317
        AppendMenu(parent, help='', id=wx.ID_EXIT,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   318
              kind=wx.ITEM_NORMAL, text=_(u'Quit') + '\tCTRL+Q')
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   319
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   320
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   321
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   322
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   323
        self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   324
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   325
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   326
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   327
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   328
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   329
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   330
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   331
        self.AddToMenuToolBar([(wx.ID_NEW, "new", _(u'New'), None),
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   332
                               (wx.ID_OPEN, "open", _(u'Open'), None),
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   333
                               (wx.ID_SAVE, "save", _(u'Save'), None),
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   334
                               (wx.ID_SAVEAS, "saveas", _(u'Save As...'), None),
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   335
                               (wx.ID_PRINT, "print", _(u'Print'), None)])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   336
1282
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   337
    def _RecursiveAddMenuItems(self, menu, items):
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   338
        for name, text, help, children in items:
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   339
            new_id = wx.NewId()
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   340
            if len(children) > 0:
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   341
                new_menu = wx.Menu(title='')
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   342
                menu.AppendMenu(new_id, text, new_menu)
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   343
                self._RecursiveAddMenuItems(new_menu, children)
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   344
            else:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   345
                AppendMenu(menu, help=help, id=new_id,
1282
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   346
                       kind=wx.ITEM_NORMAL, text=text)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   347
                self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name),
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   348
                          id=new_id)
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   349
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   350
    def _init_coll_AddMenu_Items(self, parent):
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   351
        IDEFrame._init_coll_AddMenu_Items(self, parent, False)
1282
f427352f9727 Added support for left panel add menu with multiple levels
laurent
parents: 1281
diff changeset
   352
        self._RecursiveAddMenuItems(parent, GetAddMenuItems())
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   353
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   354
    def _init_coll_HelpMenu_Items(self, parent):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   355
        parent.Append(help='', id=wx.ID_ABOUT,
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   356
              kind=wx.ITEM_NORMAL, text=_(u'About'))
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   357
        self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   358
1000
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   359
    def _init_coll_ConnectionStatusBar_Fields(self, parent):
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   360
        parent.SetFieldsCount(3)
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   361
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   362
        parent.SetStatusText(number=0, text='')
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   363
        parent.SetStatusText(number=1, text='')
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   364
        parent.SetStatusText(number=2, text='')
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   365
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   366
        parent.SetStatusWidths([-1, 300, 200])
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   367
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   368
    def _init_ctrls(self, prnt):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   369
        IDEFrame._init_ctrls(self, prnt)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   370
771
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   371
        self.EditMenuSize = self.EditMenu.GetMenuItemCount()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   372
1281
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1274
diff changeset
   373
        inspectorID = wx.NewId()
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1274
diff changeset
   374
        self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=inspectorID)
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1274
diff changeset
   375
        accels = [wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), inspectorID)]
623
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   376
        for method,shortcut in [("Stop",     wx.WXK_F4),
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   377
                                ("Run",      wx.WXK_F5),
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   378
                                ("Transfer", wx.WXK_F6),
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   379
                                ("Connect",  wx.WXK_F7),
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   380
                                ("Build",    wx.WXK_F11)]:
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   381
            def OnMethodGen(obj,meth):
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   382
                def OnMethod(evt):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   383
                    if obj.CTR is not None:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   384
                       obj.CTR.CallMethod('_'+meth)
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   385
                    wx.CallAfter(self.RefreshStatusToolBar)
623
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   386
                return OnMethod
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   387
            newid = wx.NewId()
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   388
            self.Bind(wx.EVT_MENU, OnMethodGen(self,method), id=newid)
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   389
            accels += [wx.AcceleratorEntry(wx.ACCEL_NORMAL, shortcut,newid)]
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   390
623
8cdb533c3c7a A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents: 619
diff changeset
   391
        self.SetAcceleratorTable(wx.AcceleratorTable(accels))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   392
1281
47131e3388f4 Various cleanup and optimization
Edouard Tisserant
parents: 1274
diff changeset
   393
        self.LogConsole = CustomStyledTextCtrl(
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   394
                  name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   395
                  size=wx.Size(0, 0))
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   396
        self.LogConsole.Bind(wx.EVT_SET_FOCUS, self.OnLogConsoleFocusChanged)
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   397
        self.LogConsole.Bind(wx.EVT_KILL_FOCUS, self.OnLogConsoleFocusChanged)
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   398
        self.LogConsole.Bind(wx.stc.EVT_STC_UPDATEUI, self.OnLogConsoleUpdateUI)
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   399
        self.LogConsole.SetReadOnly(True)
1007
025ac12cd0d2 Added automatic line wrapping to log console
Laurent Bessard
parents: 1000
diff changeset
   400
        self.LogConsole.SetWrapMode(wx.stc.STC_WRAP_CHAR)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   401
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   402
        # Define Log Console styles
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   403
        self.LogConsole.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   404
        self.LogConsole.StyleClearAll()
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   405
        self.LogConsole.StyleSetSpec(1, "face:%(mono)s,fore:#FF0000,size:%(size)d" % faces)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   406
        self.LogConsole.StyleSetSpec(2, "face:%(mono)s,fore:#FF0000,back:#FFFF00,size:%(size)d" % faces)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   407
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   408
        # Define Log Console markers
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   409
        self.LogConsole.SetMarginSensitive(1, True)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   410
        self.LogConsole.SetMarginType(1, wx.stc.STC_MARGIN_SYMBOL)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   411
        self.LogConsole.MarkerDefine(0, wx.stc.STC_MARK_CIRCLE, "BLACK", "RED")
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   412
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   413
        self.LogConsole.SetModEventMask(wx.stc.STC_MOD_INSERTTEXT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   414
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   415
        self.LogConsole.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnLogConsoleMarginClick)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   416
        self.LogConsole.Bind(wx.stc.EVT_STC_MODIFIED, self.OnLogConsoleModified)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   417
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 980
diff changeset
   418
        self.MainTabs["LogConsole"] = (self.LogConsole, _("Console"))
715
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   419
        self.BottomNoteBook.AddPage(*self.MainTabs["LogConsole"])
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   420
        #self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogConsole), wx.RIGHT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   421
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents: 973
diff changeset
   422
        self.LogViewer = LogViewer(self.BottomNoteBook, self)
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 980
diff changeset
   423
        self.MainTabs["LogViewer"] = (self.LogViewer, _("PLC Log"))
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents: 973
diff changeset
   424
        self.BottomNoteBook.AddPage(*self.MainTabs["LogViewer"])
994
0401295d9804 Inverted Console and LogViewer tabs in bottom Notebook
Laurent Bessard
parents: 986
diff changeset
   425
        #self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogViewer), wx.RIGHT)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   426
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   427
        StatusToolBar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   428
                wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   429
        StatusToolBar.SetToolBitmapSize(wx.Size(25, 25))
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   430
        StatusToolBar.Realize()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   431
        self.Panes["StatusToolBar"] = StatusToolBar
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   432
        self.AUIManager.AddPane(StatusToolBar, wx.aui.AuiPaneInfo().
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   433
                  Name("StatusToolBar").Caption(_("Status ToolBar")).
765
ef221ba41dec Add support for reorganizing toolbars when their size changed
laurent
parents: 762
diff changeset
   434
                  ToolbarPane().Top().Position(1).
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   435
                  LeftDockable(False).RightDockable(False))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   436
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   437
        self.AUIManager.Update()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   438
1000
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   439
        self.ConnectionStatusBar = wx.StatusBar(self, style=wx.ST_SIZEGRIP)
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   440
        self._init_coll_ConnectionStatusBar_Fields(self.ConnectionStatusBar)
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   441
        self.SetStatusBar(self.ConnectionStatusBar)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   442
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   443
    def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True):
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   444
        IDEFrame.__init__(self, parent, debug)
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   445
        self.Log = LogPseudoFile(self.LogConsole,self.SelectTab)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   446
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   447
        self.local_runtime = None
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   448
        self.runtime_port = None
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   449
        self.local_runtime_tmpdir = None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   450
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   451
        self.LastPanelSelected = None
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   452
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   453
        # Define Tree item icon list
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   454
        self.LocationImageList = wx.ImageList(16, 16)
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   455
        self.LocationImageDict = {}
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   456
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   457
        # Icons for location items
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   458
        for imgname, itemtype in [
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   459
            ("CONFIGURATION", LOCATION_CONFNODE),
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   460
            ("RESOURCE",      LOCATION_MODULE),
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   461
            ("PROGRAM",       LOCATION_GROUP),
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   462
            ("VAR_INPUT",     LOCATION_VAR_INPUT),
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   463
            ("VAR_OUTPUT",    LOCATION_VAR_OUTPUT),
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   464
            ("VAR_LOCAL",     LOCATION_VAR_MEMORY)]:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   465
            self.LocationImageDict[itemtype] = self.LocationImageList.Add(GetBitmap(imgname))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   466
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   467
        # Icons for other items
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   468
        for imgname, itemtype in [
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   469
            ("Extension", ITEM_CONFNODE)]:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   470
            self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   471
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 636
diff changeset
   472
        # Add beremiz's icon in top left corner of the frame
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   473
        self.SetIcon(wx.Icon(Bpath("images", "brz.ico"), wx.BITMAP_TYPE_ICO))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   474
788
3cec473bef94 Fixing bug with filesystem encoding on Windows
laurent
parents: 784
diff changeset
   475
        if projectOpen is not None:
3cec473bef94 Fixing bug with filesystem encoding on Windows
laurent
parents: 784
diff changeset
   476
            projectOpen = DecodeFileSystemPath(projectOpen, False)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   477
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   478
        if projectOpen is not None and os.path.isdir(projectOpen):
725
31dade089db5 refactoring
Edouard Tisserant
parents: 724
diff changeset
   479
            self.CTR = ProjectController(self, self.Log)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   480
            self.Controler = self.CTR
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   481
            result = self.CTR.LoadProject(projectOpen, buildpath)
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   482
            if not result:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   483
                self.LibraryPanel.SetController(self.Controler)
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   484
                self.ProjectTree.Enable(True)
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   485
                self.PouInstanceVariablesPanel.SetController(self.Controler)
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   486
                self.RefreshConfigRecentProjects(os.path.abspath(projectOpen))
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   487
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   488
            else:
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   489
                self.ResetView()
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   490
                self.ShowErrorMessage(result)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   491
        else:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   492
            self.CTR = ctr
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   493
            self.Controler = ctr
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   494
            if ctr is not None:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   495
                self.LibraryPanel.SetController(self.Controler)
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   496
                self.ProjectTree.Enable(True)
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   497
                self.PouInstanceVariablesPanel.SetController(self.Controler)
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   498
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
490
898648a09e13 One issue on SetDataProducer not handled fixed
laurent
parents: 466
diff changeset
   499
        if self.EnableDebug:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   500
            self.DebugVariablePanel.SetDataProducer(self.CTR)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   501
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   502
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   503
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   504
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
755
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
   505
        self.RefreshAll()
590
d3fb687dd0b9 Added build shortcut
Edouard Tisserant
parents: 589
diff changeset
   506
        self.LogConsole.SetFocus()
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   507
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   508
    def RefreshTitle(self):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   509
        name = _("Beremiz")
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   510
        if self.CTR is not None:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   511
            projectname = self.CTR.GetProjectName()
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   512
            if self.CTR.ProjectTestModified():
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   513
                projectname = "~%s~" % projectname
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   514
            self.SetTitle("%s - %s" % (name, projectname))
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   515
        else:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   516
            self.SetTitle(name)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   517
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   518
    def StartLocalRuntime(self, taskbaricon = True):
713
37dc330e96a2 Reflected recent changes in ProcessLogger changes in StartLocalRuntime
Edouard Tisserant
parents: 710
diff changeset
   519
        if (self.local_runtime is None) or (self.local_runtime.exitcode is not None):
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   520
            # create temporary directory for runtime working directory
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   521
            self.local_runtime_tmpdir = tempfile.mkdtemp()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   522
            # choose an arbitrary random port for runtime
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   523
            self.runtime_port = int(random.random() * 1000) + 61131
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   524
            # launch local runtime
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   525
            self.local_runtime = ProcessLogger(self.Log,
958
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   526
                "\"%s\" \"%s\" -p %s -i localhost %s %s"%(
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   527
                    sys.executable,
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   528
                    Bpath("Beremiz_service.py"),
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   529
                    self.runtime_port,
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   530
                    {False : "-x 0", True :"-x 1"}[taskbaricon],
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   531
                    self.local_runtime_tmpdir),
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   532
                no_gui=False,
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   533
                timeout=500, keyword = "working",
511bf048b8b7 Added CWD to ProcessLogger, and make sure local runtime have CWD setup correctly
Edouard Tisserant
parents: 918
diff changeset
   534
                cwd = self.local_runtime_tmpdir)
704
5993b16fe2d0 More stable ProcessLogger.spin()
Edouard Tisserant
parents: 703
diff changeset
   535
            self.local_runtime.spin()
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   536
        return self.runtime_port
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   537
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   538
    def KillLocalRuntime(self):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   539
        if self.local_runtime is not None:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   540
            # shutdown local runtime
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   541
            self.local_runtime.kill(gently=False)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   542
            # clear temp dir
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   543
            shutil.rmtree(self.local_runtime_tmpdir)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   544
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 513
diff changeset
   545
            self.local_runtime = None
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   546
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   547
    def OnOpenWidgetInspector(self, evt):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   548
        # Activate the widget inspection tool
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   549
        from wx.lib.inspection import InspectionTool
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   550
        if not InspectionTool().initialized:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   551
            InspectionTool().Init()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   552
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   553
        # Find a widget to be selected in the tree.  Use either the
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   554
        # one under the cursor, if any, or this frame.
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   555
        wnd = wx.FindWindowAtPointer()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   556
        if not wnd:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   557
            wnd = self
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   558
        InspectionTool().Show(wnd, True)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   559
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   560
    def OnLogConsoleFocusChanged(self, event):
1087
16cc3c42e413 Fixed bug when closing Beremiz frame
Laurent Bessard
parents: 1067
diff changeset
   561
        self.RefreshEditMenu()
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   562
        event.Skip()
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   563
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   564
    def OnLogConsoleUpdateUI(self, event):
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   565
        self.SetCopyBuffer(self.LogConsole.GetSelectedText(), True)
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   566
        event.Skip()
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   567
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   568
    def OnLogConsoleMarginClick(self, event):
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   569
        line_idx = self.LogConsole.LineFromPosition(event.GetPosition())
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   570
        wx.CallAfter(self.SearchLineForError, self.LogConsole.GetLine(line_idx))
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   571
        event.Skip()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   572
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   573
    def OnLogConsoleModified(self, event):
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   574
        line_idx = self.LogConsole.LineFromPosition(event.GetPosition())
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   575
        line = self.LogConsole.GetLine(line_idx)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   576
        if line:
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   577
            result = MATIEC_ERROR_MODEL.match(line)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   578
            if result is not None:
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   579
                self.LogConsole.MarkerAdd(line_idx, 0)
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   580
        event.Skip()
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   581
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 994
diff changeset
   582
    def SearchLineForError(self, line):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   583
        if self.CTR is not None:
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   584
            result = MATIEC_ERROR_MODEL.match(line)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   585
            if result is not None:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   586
                first_line, first_column, last_line, last_column, error = result.groups()
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   587
                infos = self.CTR.ShowError(self.Log,
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   588
                                                  (int(first_line), int(first_column)),
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   589
                                                  (int(last_line), int(last_column)))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   590
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   591
    ## Function displaying an Error dialog in PLCOpenEditor.
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   592
    #  @return False if closing cancelled.
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   593
    def CheckSaveBeforeClosing(self, title=_("Close Project")):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   594
        if self.CTR.ProjectTestModified():
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   595
            dialog = wx.MessageDialog(self,
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   596
                                      _("There are changes, do you want to save?"),
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   597
                                      title,
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   598
                                      wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   599
            answer = dialog.ShowModal()
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   600
            dialog.Destroy()
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   601
            if answer == wx.ID_YES:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   602
                self.CTR.SaveProject()
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   603
            elif answer == wx.ID_CANCEL:
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   604
                return False
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   605
797
61280a7d9ff2 Adding support for checking that tab content is saved before closing it
laurent
parents: 793
diff changeset
   606
        for idx in xrange(self.TabsOpened.GetPageCount()):
61280a7d9ff2 Adding support for checking that tab content is saved before closing it
laurent
parents: 793
diff changeset
   607
            window = self.TabsOpened.GetPage(idx)
61280a7d9ff2 Adding support for checking that tab content is saved before closing it
laurent
parents: 793
diff changeset
   608
            if not window.CheckSaveBeforeClosing():
61280a7d9ff2 Adding support for checking that tab content is saved before closing it
laurent
parents: 793
diff changeset
   609
                return False
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   610
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   611
        return True
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   612
715
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   613
    def GetTabInfos(self, tab):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   614
        if (isinstance(tab, EditorPanel) and
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   615
            not isinstance(tab, (Viewer,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   616
                                 TextViewer,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   617
                                 ResourceEditor,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   618
                                 ConfigurationEditor,
715
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   619
                                 DataTypeEditor))):
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents: 781
diff changeset
   620
            return ("confnode", tab.Controler.CTNFullName(), tab.GetTagName())
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   621
        elif (isinstance(tab, TextViewer) and
716
180e4a7d945c Adding search field for finding function or function block in library tree
laurent
parents: 715
diff changeset
   622
              (tab.Controler is None or isinstance(tab.Controler, MiniTextControler))):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   623
            return ("confnode", None, tab.GetInstancePath())
715
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   624
        else:
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   625
            return IDEFrame.GetTabInfos(self, tab)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   626
715
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   627
    def LoadTab(self, notebook, page_infos):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   628
        if page_infos[0] == "confnode":
716
180e4a7d945c Adding search field for finding function or function block in library tree
laurent
parents: 715
diff changeset
   629
            if page_infos[1] is None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   630
                confnode = self.CTR
716
180e4a7d945c Adding search field for finding function or function block in library tree
laurent
parents: 715
diff changeset
   631
            else:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   632
                confnode = self.CTR.GetChildByName(page_infos[1])
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   633
            return notebook.GetPageIndex(confnode._OpenView(*page_infos[2:]))
715
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   634
        else:
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   635
            return IDEFrame.LoadTab(self, notebook, page_infos)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   636
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   637
    def OnCloseFrame(self, event):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   638
        for evt_type in [wx.EVT_SET_FOCUS,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   639
                         wx.EVT_KILL_FOCUS,
1090
f4d08cea7774 Fixed bug when closing Beremiz frame
Laurent Bessard
parents: 1088
diff changeset
   640
                         wx.stc.EVT_STC_UPDATEUI]:
f4d08cea7774 Fixed bug when closing Beremiz frame
Laurent Bessard
parents: 1088
diff changeset
   641
            self.LogConsole.Unbind(evt_type)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   642
        if self.CTR is None or self.CheckSaveBeforeClosing(_("Close Application")):
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   643
            if self.CTR is not None:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   644
                self.CTR.KillDebugThread()
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   645
            self.KillLocalRuntime()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   646
715
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 714
diff changeset
   647
            self.SaveLastState()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   648
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   649
            event.Skip()
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   650
        else:
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   651
            event.Veto()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   652
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   653
    def RefreshFileMenu(self):
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   654
        self.RefreshRecentProjectsMenu()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   655
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   656
        MenuToolBar = self.Panes["MenuToolBar"]
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   657
        if self.CTR is not None:
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   658
            selected = self.TabsOpened.GetSelection()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   659
            if selected >= 0:
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   660
                window = self.TabsOpened.GetPage(selected)
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   661
                viewer_is_modified = window.IsModified()
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   662
                is_viewer = isinstance(window, Viewer)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   663
            else:
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   664
                viewer_is_modified = is_viewer = False
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   665
            if self.TabsOpened.GetPageCount() > 0:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   666
                self.FileMenu.Enable(wx.ID_CLOSE, True)
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   667
                if is_viewer:
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   668
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   669
                    self.FileMenu.Enable(wx.ID_PRINT, True)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   670
                    MenuToolBar.EnableTool(wx.ID_PRINT, True)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   671
                else:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   672
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   673
                    self.FileMenu.Enable(wx.ID_PRINT, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   674
                    MenuToolBar.EnableTool(wx.ID_PRINT, False)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   675
            else:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   676
                self.FileMenu.Enable(wx.ID_CLOSE, False)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   677
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   678
                self.FileMenu.Enable(wx.ID_PRINT, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   679
                MenuToolBar.EnableTool(wx.ID_PRINT, False)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   680
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   681
            project_modified = self.CTR.ProjectTestModified() or viewer_is_modified
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   682
            self.FileMenu.Enable(wx.ID_SAVE, project_modified)
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   683
            MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   684
            self.FileMenu.Enable(wx.ID_SAVEAS, True)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   685
            MenuToolBar.EnableTool(wx.ID_SAVEAS, True)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   686
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   687
        else:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   688
            self.FileMenu.Enable(wx.ID_CLOSE, False)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   689
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   690
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   691
            self.FileMenu.Enable(wx.ID_PRINT, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   692
            MenuToolBar.EnableTool(wx.ID_PRINT, False)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   693
            self.FileMenu.Enable(wx.ID_SAVE, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   694
            MenuToolBar.EnableTool(wx.ID_SAVE, False)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   695
            self.FileMenu.Enable(wx.ID_SAVEAS, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   696
            MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   697
            self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   698
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   699
    def RefreshRecentProjectsMenu(self):
793
1b24b970a816 Fixing bug while loading recent projects open path with old configurations
laurent
parents: 790
diff changeset
   700
        try:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   701
            recent_projects = map(DecodeFileSystemPath,
793
1b24b970a816 Fixing bug while loading recent projects open path with old configurations
laurent
parents: 790
diff changeset
   702
                                  self.GetConfigEntry("RecentProjects", []))
1b24b970a816 Fixing bug while loading recent projects open path with old configurations
laurent
parents: 790
diff changeset
   703
        except:
1b24b970a816 Fixing bug while loading recent projects open path with old configurations
laurent
parents: 790
diff changeset
   704
            recent_projects = []
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   705
        self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   706
        for idx, projectpath in enumerate(recent_projects):
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   707
            text = u'%d: %s' % (idx + 1, projectpath)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   708
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   709
            if idx < self.RecentProjectsMenu.GetMenuItemCount():
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   710
                item = self.RecentProjectsMenu.FindItemByPosition(idx)
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   711
                id = item.GetId()
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   712
                item.SetItemLabel(text)
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   713
                self.Disconnect(id, id, wx.EVT_BUTTON._getEvtType())
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   714
            else:
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   715
                id = wx.NewId()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   716
                AppendMenu(self.RecentProjectsMenu, help='', id=id,
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   717
                           kind=wx.ITEM_NORMAL, text=text)
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   718
            self.Bind(wx.EVT_MENU, self.GenerateOpenRecentProjectFunction(projectpath), id=id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   719
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   720
    def GenerateOpenRecentProjectFunction(self, projectpath):
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   721
        def OpenRecentProject(event):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   722
            if self.CTR is not None and not self.CheckSaveBeforeClosing():
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   723
                return
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   724
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   725
            self.OpenProject(projectpath)
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   726
        return OpenRecentProject
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   727
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   728
    def GenerateMenuRecursive(self, items, menu):
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   729
        for kind, infos in items:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   730
            if isinstance(kind, ListType):
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   731
                text, id = infos
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   732
                submenu = wx.Menu('')
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   733
                self.GenerateMenuRecursive(kind, submenu)
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   734
                menu.AppendMenu(id, text, submenu)
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   735
            elif kind == wx.ITEM_SEPARATOR:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   736
                menu.AppendSeparator()
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   737
            else:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   738
                text, id, help, callback = infos
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   739
                AppendMenu(menu, help='', id=id, kind=kind, text=text)
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   740
                if callback is not None:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   741
                    self.Bind(wx.EVT_MENU, callback, id=id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   742
766
42c0062655a7 Fix bug in reorganization of toolbars after refreshing them
laurent
parents: 765
diff changeset
   743
    def RefreshEditorToolBar(self):
42c0062655a7 Fix bug in reorganization of toolbars after refreshing them
laurent
parents: 765
diff changeset
   744
        IDEFrame.RefreshEditorToolBar(self)
42c0062655a7 Fix bug in reorganization of toolbars after refreshing them
laurent
parents: 765
diff changeset
   745
        self.AUIManager.GetPane("EditorToolBar").Position(2)
42c0062655a7 Fix bug in reorganization of toolbars after refreshing them
laurent
parents: 765
diff changeset
   746
        self.AUIManager.GetPane("StatusToolBar").Position(1)
42c0062655a7 Fix bug in reorganization of toolbars after refreshing them
laurent
parents: 765
diff changeset
   747
        self.AUIManager.Update()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   748
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   749
    def RefreshStatusToolBar(self):
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   750
        StatusToolBar = self.Panes["StatusToolBar"]
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   751
        StatusToolBar.ClearTools()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   752
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   753
        if self.CTR is not None:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   754
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   755
            for confnode_method in self.CTR.StatusMethods:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   756
                if "method" in confnode_method and confnode_method.get("shown",True):
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   757
                    id = wx.NewId()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   758
                    StatusToolBar.AddSimpleTool(id,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   759
                        GetBitmap(confnode_method.get("bitmap", "Unknown")),
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   760
                        confnode_method["tooltip"])
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   761
                    self.Bind(wx.EVT_MENU, self.GetMenuCallBackFunction(confnode_method["method"]), id=id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   762
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   763
            StatusToolBar.Realize()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   764
            self.AUIManager.GetPane("StatusToolBar").BestSize(StatusToolBar.GetBestSize()).Show()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   765
        else:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   766
            self.AUIManager.GetPane("StatusToolBar").Hide()
766
42c0062655a7 Fix bug in reorganization of toolbars after refreshing them
laurent
parents: 765
diff changeset
   767
        self.AUIManager.GetPane("EditorToolBar").Position(2)
765
ef221ba41dec Add support for reorganizing toolbars when their size changed
laurent
parents: 762
diff changeset
   768
        self.AUIManager.GetPane("StatusToolBar").Position(1)
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   769
        self.AUIManager.Update()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   770
771
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   771
    def RefreshEditMenu(self):
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   772
        IDEFrame.RefreshEditMenu(self)
1015
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   773
        if self.FindFocus() == self.LogConsole:
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   774
            self.EditMenu.Enable(wx.ID_COPY, True)
50bb7cc12a84 Fixed LogConsole: set read only, enabled copy selected text with CTRL+C and primary selection
Laurent Bessard
parents: 1007
diff changeset
   775
            self.Panes["MenuToolBar"].EnableTool(wx.ID_COPY, True)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   776
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   777
        if self.CTR is not None:
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   778
            selected = self.TabsOpened.GetSelection()
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   779
            if selected >= 0:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   780
                panel = self.TabsOpened.GetPage(selected)
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   781
            else:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   782
                panel = None
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   783
            if panel != self.LastPanelSelected:
771
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   784
                for i in xrange(self.EditMenuSize, self.EditMenu.GetMenuItemCount()):
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   785
                    item = self.EditMenu.FindItemByPosition(self.EditMenuSize)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   786
                    if item is not None:
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   787
                        if item.IsSeparator():
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   788
                            self.EditMenu.RemoveItem(item)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   789
                        else:
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   790
                            self.EditMenu.Delete(item.GetId())
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   791
                self.LastPanelSelected = panel
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   792
                if panel is not None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   793
                    items = panel.GetConfNodeMenuItems()
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   794
                else:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   795
                    items = []
771
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   796
                if len(items) > 0:
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   797
                    self.EditMenu.AppendSeparator()
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   798
                    self.GenerateMenuRecursive(items, self.EditMenu)
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   799
            if panel is not None:
771
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   800
                panel.RefreshConfNodeMenu(self.EditMenu)
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   801
        else:
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   802
            for i in xrange(self.EditMenuSize, self.EditMenu.GetMenuItemCount()):
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   803
                item = self.EditMenu.FindItemByPosition(i)
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   804
                if item is not None:
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   805
                    if item.IsSeparator():
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   806
                        self.EditMenu.RemoveItem(item)
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   807
                    else:
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   808
                        self.EditMenu.Delete(item.GetId())
771
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 766
diff changeset
   809
            self.LastPanelSelected = None
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   810
        self.MenuBar.UpdateMenus()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   811
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   812
    def RefreshAll(self):
755
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
   813
        self.RefreshStatusToolBar()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   814
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   815
    def GetMenuCallBackFunction(self, method):
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   816
        """ Generate the callbackfunc for a given CTR method"""
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   817
        def OnMenu(event):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   818
            # Disable button to prevent re-entrant call
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   819
            event.GetEventObject().Disable()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   820
            # Call
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   821
            getattr(self.CTR, method)()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   822
            # Re-enable button
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   823
            event.GetEventObject().Enable()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   824
        return OnMenu
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   825
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   826
    def GetConfigEntry(self, entry_name, default):
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   827
        return cPickle.loads(str(self.Config.Read(entry_name, cPickle.dumps(default))))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   828
1000
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   829
    def ResetConnectionStatusBar(self):
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   830
        for field in xrange(self.ConnectionStatusBar.GetFieldsCount()):
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   831
            self.ConnectionStatusBar.SetStatusText('', field)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   832
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   833
    def ResetView(self):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   834
        IDEFrame.ResetView(self)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   835
        self.ConfNodeInfos = {}
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   836
        if self.CTR is not None:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   837
            self.CTR.CloseProject()
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   838
        self.CTR = None
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   839
        self.Log.flush()
490
898648a09e13 One issue on SetDataProducer not handled fixed
laurent
parents: 466
diff changeset
   840
        if self.EnableDebug:
898648a09e13 One issue on SetDataProducer not handled fixed
laurent
parents: 466
diff changeset
   841
            self.DebugVariablePanel.SetDataProducer(None)
1000
d19af9341d28 Added support for StatusBar
Laurent Bessard
parents: 999
diff changeset
   842
            self.ResetConnectionStatusBar()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   843
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   844
    def RefreshConfigRecentProjects(self, projectpath):
793
1b24b970a816 Fixing bug while loading recent projects open path with old configurations
laurent
parents: 790
diff changeset
   845
        try:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   846
            recent_projects = map(DecodeFileSystemPath,
793
1b24b970a816 Fixing bug while loading recent projects open path with old configurations
laurent
parents: 790
diff changeset
   847
                                  self.GetConfigEntry("RecentProjects", []))
1b24b970a816 Fixing bug while loading recent projects open path with old configurations
laurent
parents: 790
diff changeset
   848
        except:
1b24b970a816 Fixing bug while loading recent projects open path with old configurations
laurent
parents: 790
diff changeset
   849
            recent_projects = []
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   850
        if projectpath in recent_projects:
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   851
            recent_projects.remove(projectpath)
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   852
        recent_projects.insert(0, projectpath)
788
3cec473bef94 Fixing bug with filesystem encoding on Windows
laurent
parents: 784
diff changeset
   853
        self.Config.Write("RecentProjects", cPickle.dumps(
3cec473bef94 Fixing bug with filesystem encoding on Windows
laurent
parents: 784
diff changeset
   854
            map(EncodeFileSystemPath, recent_projects[:MAX_RECENT_PROJECTS])))
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   855
        self.Config.Flush()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   856
743
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 739
diff changeset
   857
    def ResetPerspective(self):
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 739
diff changeset
   858
        IDEFrame.ResetPerspective(self)
4645a3a398ad Fix bugs with ConfigTreeNode
laurent
parents: 739
diff changeset
   859
        self.RefreshStatusToolBar()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   860
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   861
    def OnNewProjectMenu(self, event):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   862
        if self.CTR is not None and not self.CheckSaveBeforeClosing():
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   863
            return
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   864
790
52d3a084d2b2 Adding secure extraction of last edited project path to avoid crash if path is not well formatted
laurent
parents: 788
diff changeset
   865
        try:
52d3a084d2b2 Adding secure extraction of last edited project path to avoid crash if path is not well formatted
laurent
parents: 788
diff changeset
   866
            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
52d3a084d2b2 Adding secure extraction of last edited project path to avoid crash if path is not well formatted
laurent
parents: 788
diff changeset
   867
        except:
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   868
            defaultpath = os.path.expanduser("~")
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   869
833
3f997fb22928 Fix confnode new name format that generates an error with frame class name in wxGlade extension
laurent
parents: 815
diff changeset
   870
        dialog = wx.DirDialog(self , _("Choose a project"), defaultpath)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   871
        if dialog.ShowModal() == wx.ID_OK:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   872
            projectpath = dialog.GetPath()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   873
            self.Config.Write("lastopenedfolder",
788
3cec473bef94 Fixing bug with filesystem encoding on Windows
laurent
parents: 784
diff changeset
   874
                              EncodeFileSystemPath(os.path.dirname(projectpath)))
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   875
            self.Config.Flush()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   876
            self.ResetView()
725
31dade089db5 refactoring
Edouard Tisserant
parents: 724
diff changeset
   877
            ctr = ProjectController(self, self.Log)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   878
            result = ctr.NewProject(projectpath)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   879
            if not result:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   880
                self.CTR = ctr
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   881
                self.Controler = self.CTR
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   882
                self.LibraryPanel.SetController(self.Controler)
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   883
                self.ProjectTree.Enable(True)
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   884
                self.PouInstanceVariablesPanel.SetController(self.Controler)
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   885
                self.RefreshConfigRecentProjects(projectpath)
490
898648a09e13 One issue on SetDataProducer not handled fixed
laurent
parents: 466
diff changeset
   886
                if self.EnableDebug:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   887
                    self.DebugVariablePanel.SetDataProducer(self.CTR)
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   888
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   889
            else:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   890
                self.ResetView()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   891
                self.ShowErrorMessage(result)
755
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
   892
            self.RefreshAll()
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   893
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   894
        dialog.Destroy()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   895
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   896
    def OnOpenProjectMenu(self, event):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   897
        if self.CTR is not None and not self.CheckSaveBeforeClosing():
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   898
            return
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   899
790
52d3a084d2b2 Adding secure extraction of last edited project path to avoid crash if path is not well formatted
laurent
parents: 788
diff changeset
   900
        try:
52d3a084d2b2 Adding secure extraction of last edited project path to avoid crash if path is not well formatted
laurent
parents: 788
diff changeset
   901
            defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder"))
52d3a084d2b2 Adding secure extraction of last edited project path to avoid crash if path is not well formatted
laurent
parents: 788
diff changeset
   902
        except:
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   903
            defaultpath = os.path.expanduser("~")
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   904
833
3f997fb22928 Fix confnode new name format that generates an error with frame class name in wxGlade extension
laurent
parents: 815
diff changeset
   905
        dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, style=wx.DEFAULT_DIALOG_STYLE|
3f997fb22928 Fix confnode new name format that generates an error with frame class name in wxGlade extension
laurent
parents: 815
diff changeset
   906
                                                                               wx.RESIZE_BORDER)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   907
        if dialog.ShowModal() == wx.ID_OK:
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   908
            self.OpenProject(dialog.GetPath())
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   909
        dialog.Destroy()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   910
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   911
    def OpenProject(self, projectpath):
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   912
        if os.path.isdir(projectpath):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   913
            self.Config.Write("lastopenedfolder",
788
3cec473bef94 Fixing bug with filesystem encoding on Windows
laurent
parents: 784
diff changeset
   914
                              EncodeFileSystemPath(os.path.dirname(projectpath)))
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   915
            self.Config.Flush()
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   916
            self.ResetView()
725
31dade089db5 refactoring
Edouard Tisserant
parents: 724
diff changeset
   917
            self.CTR = ProjectController(self, self.Log)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   918
            self.Controler = self.CTR
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   919
            result = self.CTR.LoadProject(projectpath)
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   920
            if not result:
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   921
                self.LibraryPanel.SetController(self.Controler)
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   922
                self.ProjectTree.Enable(True)
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   923
                self.PouInstanceVariablesPanel.SetController(self.Controler)
679
d72f3a42f440 Fix recent projects list not updated when creating new project
laurent
parents: 678
diff changeset
   924
                self.RefreshConfigRecentProjects(projectpath)
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   925
                if self.EnableDebug:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   926
                    self.DebugVariablePanel.SetDataProducer(self.CTR)
730
4480b7da6bea refactoring
laurent
parents: 727
diff changeset
   927
                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   928
            else:
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   929
                self.ResetView()
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   930
                self.ShowErrorMessage(result)
755
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
   931
            self.RefreshAll()
675
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   932
        else:
44b35c27e9ff Adding support for quickly open recent projects in file menu
laurent
parents: 666
diff changeset
   933
            self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   934
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   935
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   936
    def OnCloseProjectMenu(self, event):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   937
        if self.CTR is not None and not self.CheckSaveBeforeClosing():
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   938
            return
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   939
429
1a5471e81a93 Adding support for asking for saving while trying to close a modified project in any case
laurent
parents: 428
diff changeset
   940
        self.ResetView()
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 703
diff changeset
   941
        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
755
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
   942
        self.RefreshAll()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   943
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   944
    def OnSaveProjectMenu(self, event):
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   945
        selected = self.TabsOpened.GetSelection()
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   946
        if selected != -1:
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   947
            window = self.TabsOpened.GetPage(selected)
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   948
            window.Save()
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   949
        if self.CTR is not None:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   950
            self.CTR.SaveProject()
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   951
            self.RefreshAll()
636
35c59bfc54f2 Fixing refresh of notebook tab titles after project save
laurent
parents: 631
diff changeset
   952
            self._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   953
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   954
    def OnSaveProjectAsMenu(self, event):
784
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   955
        selected = self.TabsOpened.GetSelection()
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   956
        if selected != -1:
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   957
            window = self.TabsOpened.GetPage(selected)
a1d970365e41 Adding support for beremiz extensions to define custom file editors for project files
laurent
parents: 782
diff changeset
   958
            window.SaveAs()
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   959
        if self.CTR is not None:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
   960
            self.CTR.SaveProjectAs()
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 771
diff changeset
   961
            self.RefreshAll()
636
35c59bfc54f2 Fixing refresh of notebook tab titles after project save
laurent
parents: 631
diff changeset
   962
            self._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   963
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   964
    def OnQuitMenu(self, event):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   965
        self.Close()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   966
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
   967
    def OnAboutMenu(self, event):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 807
diff changeset
   968
        OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc", "about.html"), wx.Size(550, 500))
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   969
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   970
    def OnProjectTreeItemBeginEdit(self, event):
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   971
        selected = event.GetItem()
747
e7fca1f93de1 Fix bug when begin editing item in project tree
laurent
parents: 743
diff changeset
   972
        if self.ProjectTree.GetPyData(selected)["type"] == ITEM_CONFNODE:
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   973
            event.Veto()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   974
        else:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   975
            IDEFrame.OnProjectTreeItemBeginEdit(self, event)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   976
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   977
    def OnProjectTreeRightUp(self, event):
1240
ceaf9b4c0f86 Fixed bug when drag'n dropping POU from project tree, POU editor is selected if open
Laurent Bessard
parents: 1211
diff changeset
   978
        item = event.GetItem()
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   979
        item_infos = self.ProjectTree.GetPyData(item)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   980
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   981
        if item_infos["type"] == ITEM_CONFNODE:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   982
            confnode_menu = wx.Menu(title='')
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
   983
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   984
            confnode = item_infos["confnode"]
967
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   985
            if confnode is not None:
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   986
                menu_items = confnode.GetContextualMenuItems()
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   987
                if menu_items is not None:
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   988
                    for text, help, callback in menu_items:
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   989
                        new_id = wx.NewId()
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   990
                        confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=text)
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   991
                        self.Bind(wx.EVT_MENU, callback, id=new_id)
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   992
                else:
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   993
                    for name, XSDClass, help in confnode.CTNChildrenTypes:
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   994
                        new_id = wx.NewId()
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   995
                        confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Add") + " " + name)
8a339cd61cb4 Added support for extension custom contextual add menu
Laurent Bessard
parents: 958
diff changeset
   996
                        self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name, confnode), id=new_id)
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   997
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   998
            new_id = wx.NewId()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
   999
            AppendMenu(confnode_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Delete"))
755
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
  1000
            self.Bind(wx.EVT_MENU, self.GetDeleteMenuFunction(confnode), id=new_id)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1001
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1002
            self.PopupMenu(confnode_menu)
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1003
            confnode_menu.Destroy()
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1004
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1005
            event.Skip()
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1393
diff changeset
  1006
        elif item_infos["type"] == ITEM_RESOURCE:
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1393
diff changeset
  1007
            # prevent last resource to be delted
1024
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1008
            parent = self.ProjectTree.GetItemParent(item)
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1009
            parent_name = self.ProjectTree.GetItemText(parent)
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1393
diff changeset
  1010
            if parent_name == _("Resources"):
1024
626de4ff4bdc Fixed resource editing, removing definition of more than one resource and deletion of last resource defined
Laurent Bessard
parents: 1019
diff changeset
  1011
                IDEFrame.OnProjectTreeRightUp(self, event)
1038
1923a69482f8 Fixed bug when right click on ProjectTree project item
Laurent Bessard
parents: 1025
diff changeset
  1012
        else:
1923a69482f8 Fixed bug when right click on ProjectTree project item
Laurent Bessard
parents: 1025
diff changeset
  1013
            IDEFrame.OnProjectTreeRightUp(self, event)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1014
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1015
    def OnProjectTreeItemActivated(self, event):
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1016
        selected = event.GetItem()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1017
        name = self.ProjectTree.GetItemText(selected)
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1018
        item_infos = self.ProjectTree.GetPyData(selected)
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1019
        if item_infos["type"] == ITEM_CONFNODE:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1020
            item_infos["confnode"]._OpenView()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1021
            event.Skip()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1022
        elif item_infos["type"] == ITEM_PROJECT:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1023
            self.CTR._OpenView()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1024
        else:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1025
            IDEFrame.OnProjectTreeItemActivated(self, event)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1026
782
6f0e10085df9 Adding support for file explorer for project files
laurent
parents: 781
diff changeset
  1027
    def ProjectTreeItemSelect(self, select_item):
1272
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1028
        if select_item is not None and select_item.IsOk():
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1029
            name = self.ProjectTree.GetItemText(select_item)
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1030
            item_infos = self.ProjectTree.GetPyData(select_item)
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1031
            if item_infos["type"] == ITEM_CONFNODE:
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1032
                item_infos["confnode"]._OpenView(onlyopened=True)
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1033
            elif item_infos["type"] == ITEM_PROJECT:
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1034
                self.CTR._OpenView(onlyopened=True)
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1035
            else:
0086cbee609b Fixed bug when open editor while Build is working
Laurent Bessard
parents: 1269
diff changeset
  1036
                IDEFrame.ProjectTreeItemSelect(self, select_item)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1037
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1038
    def SelectProjectTreeItem(self, tagname):
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1039
        if self.ProjectTree is not None:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1040
            root = self.ProjectTree.GetRootItem()
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1041
            if root.IsOk():
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1042
                words = tagname.split("::")
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1043
                if len(words) == 1:
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1044
                    if tagname == "Project":
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1045
                        self.SelectedItem = root
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1046
                        self.ProjectTree.SelectItem(root)
1269
e8e153a7c3bf Fix bug in atty function of LogPseudoFile
Laurent Bessard
parents: 1240
diff changeset
  1047
                        self.ResetSelectedItem()
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1048
                    else:
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1049
                        return self.RecursiveProjectTreeItemSelection(root,
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1050
                              [(word, ITEM_CONFNODE) for word in tagname.split(".")])
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1051
                elif words[0] == "R":
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1052
                    return self.RecursiveProjectTreeItemSelection(root, [(words[2], ITEM_RESOURCE)])
1274
6b38acbe1fd0 Fix bug when opening specific file editor
Laurent Bessard
parents: 1272
diff changeset
  1053
                elif not os.path.exists(words[0]):
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1054
                    IDEFrame.SelectProjectTreeItem(self, tagname)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1055
760
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1056
    def GetAddConfNodeFunction(self, name, confnode=None):
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1057
        def AddConfNodeMenuFunction(event):
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1058
            wx.CallAfter(self.AddConfNode, name, confnode)
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1059
        return AddConfNodeMenuFunction
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1060
755
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
  1061
    def GetDeleteMenuFunction(self, confnode):
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
  1062
        def DeleteMenuFunction(event):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
  1063
            wx.CallAfter(self.DeleteConfNode, confnode)
755
9f5dbd90e1e0 Removing code related to Topology panel
laurent
parents: 749
diff changeset
  1064
        return DeleteMenuFunction
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1065
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1066
    def AddConfNode(self, ConfNodeType, confnode=None):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
  1067
        if self.CTR.CheckProjectPathPerm():
833
3f997fb22928 Fix confnode new name format that generates an error with frame class name in wxGlade extension
laurent
parents: 815
diff changeset
  1068
            ConfNodeName = "%s_0" % ConfNodeType
760
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1069
            if confnode is not None:
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1070
                confnode.CTNAddChild(ConfNodeName, ConfNodeType)
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1071
            else:
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1072
                self.CTR.CTNAddChild(ConfNodeName, ConfNodeType)
d38560559afb Replacing dialog asking for a name when adding confnode to project by automatically generated name
laurent
parents: 755
diff changeset
  1073
            self._Refresh(TITLE, FILEMENU, PROJECTTREE)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1074
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
  1075
    def DeleteConfNode(self, confnode):
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
  1076
        if self.CTR.CheckProjectPathPerm():
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1077
            dialog = wx.MessageDialog(self,
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1078
                _("Really delete node '%s'?") % confnode.CTNName(),
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1079
                _("Remove %s node") % confnode.CTNType,
801
435e49e80832 Update list of messages to be translated for internationalization and french translations
laurent
parents: 799
diff changeset
  1080
                wx.YES_NO|wx.NO_DEFAULT)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1081
            if dialog.ShowModal() == wx.ID_YES:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1082
                confnode.CTNRemove()
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 716
diff changeset
  1083
                del confnode
738
413946c04c87 refactoring
laurent
parents: 737
diff changeset
  1084
                self._Refresh(TITLE, FILEMENU, PROJECTTREE)
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1085
            dialog.Destroy()
900
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1086
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1087
#-------------------------------------------------------------------------------
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1088
#                        Highlights showing functions
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1089
#-------------------------------------------------------------------------------
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1090
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1091
    def ShowHighlight(self, infos, start, end, highlight_type):
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1092
        config_name = self.Controler.GetProjectMainConfigurationName()
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1093
        if config_name is not None and infos[0] == self.Controler.ComputeConfigurationName(config_name):
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1094
            self.CTR._OpenView()
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1095
            selected = self.TabsOpened.GetSelection()
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1096
            if selected != -1:
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1097
                viewer = self.TabsOpened.GetPage(selected)
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1098
                viewer.AddHighlight(infos[1:], start, end, highlight_type)
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1099
        else:
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1100
            IDEFrame.ShowHighlight(self, infos, start, end, highlight_type)
3e78925125e1 Fix bug main configuration variables not displayed in lower left panel when project root element is selected
Laurent Bessard
parents: 881
diff changeset
  1101
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1102
#-------------------------------------------------------------------------------
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1103
#                               Exception Handler
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1104
#-------------------------------------------------------------------------------
1067
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1105
import threading, traceback
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1106
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1107
Max_Traceback_List_Size = 20
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1108
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1109
def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1110
    trcbck_lst = []
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1111
    for i,line in enumerate(traceback.extract_tb(e_tb)):
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 731
diff changeset
  1112
        trcbck = " " + str(i+1) + ". "
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1113
        if line[0].find(os.getcwd()) == -1:
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 731
diff changeset
  1114
            trcbck += "file : " + str(line[0]) + ",   "
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 731
diff changeset
  1115
        else:
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 731
diff changeset
  1116
            trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 731
diff changeset
  1117
        trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1118
        trcbck_lst.append(trcbck)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1119
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1120
    # Allow clicking....
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1121
    cap = wx.Window_GetCapture()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1122
    if cap:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1123
        cap.ReleaseMouse()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1124
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1125
    dlg = wx.SingleChoiceDialog(None,
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1126
        _("""
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1127
An unhandled exception (bug) occured. Bug report saved at :
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1128
(%s)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1129
434
092060fd8afb Replace \"lolitech\" contact by \"edouard\" contact
greg
parents: 429
diff changeset
  1130
Please be kind enough to send this file to:
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 731
diff changeset
  1131
beremiz-devel@lists.sourceforge.net
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1132
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1133
You should now restart Beremiz.
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1134
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1135
Traceback:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1136
""") % bug_report_path +
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1137
        repr(e_type) + " : " + repr(e_value),
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1138
        _("Error"),
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1139
        trcbck_lst)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1140
    try:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1141
        res = (dlg.ShowModal() == wx.ID_OK)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1142
    finally:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1143
        dlg.Destroy()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1144
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1145
    return res
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1146
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1147
def get_last_traceback(tb):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1148
    while tb.tb_next:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1149
        tb = tb.tb_next
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1150
    return tb
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1151
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1152
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1153
def format_namespace(d, indent='    '):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1154
    return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1155
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1156
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1157
ignored_exceptions = [] # a problem with a line in a module is only reported once per session
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1158
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1159
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1160
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1161
    def handle_exception(e_type, e_value, e_traceback):
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1162
        traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1163
        last_tb = get_last_traceback(e_traceback)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1164
        ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
701
166db2cb630b Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents: 692
diff changeset
  1165
        if ex not in ignored_exceptions:
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1166
            date = time.ctime()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1167
            bug_report_path = path+os.sep+"bug_report_"+date.replace(':','-').replace(' ','_')+".txt"
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1168
            result = Display_Exception_Dialog(e_type,e_value,e_traceback,bug_report_path)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1169
            if result:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1170
                ignored_exceptions.append(ex)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1171
                info = {
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1172
                    'app-title' : wx.GetApp().GetAppName(), # app_title
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1173
                    'app-version' : app_version,
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1174
                    'wx-version' : wx.VERSION_STRING,
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1175
                    'wx-platform' : wx.Platform,
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1176
                    'python-version' : platform.python_version(), #sys.version.split()[0],
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1177
                    'platform' : platform.platform(),
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1178
                    'e-type' : e_type,
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1179
                    'e-value' : e_value,
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1180
                    'date' : date,
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1181
                    'cwd' : os.getcwd(),
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1182
                    }
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1183
                if e_traceback:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1184
                    info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1185
                    last_tb = get_last_traceback(e_traceback)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1186
                    exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1187
                    info['locals'] = format_namespace(exception_locals)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1188
                    if 'self' in exception_locals:
1404
d4a6c9287e97 Fixed Exception dialog crash when original exception contains unicode
Edouard Tisserant
parents: 1401
diff changeset
  1189
                        try :
d4a6c9287e97 Fixed Exception dialog crash when original exception contains unicode
Edouard Tisserant
parents: 1401
diff changeset
  1190
                            info['self'] = format_namespace(exception_locals['self'].__dict__)
d4a6c9287e97 Fixed Exception dialog crash when original exception contains unicode
Edouard Tisserant
parents: 1401
diff changeset
  1191
                        except :
d4a6c9287e97 Fixed Exception dialog crash when original exception contains unicode
Edouard Tisserant
parents: 1401
diff changeset
  1192
                            pass
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1193
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1194
                output = open(bug_report_path,'w')
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1195
                lst = info.keys()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1196
                lst.sort()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1197
                for a in lst:
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1198
                    output.write(a+":\n"+str(info[a])+"\n\n")
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1199
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1200
    #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1201
    sys.excepthook = handle_exception
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1202
1067
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1203
    init_old = threading.Thread.__init__
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1204
    def init(self, *args, **kwargs):
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1205
        init_old(self, *args, **kwargs)
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1206
        run_old = self.run
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1207
        def run_with_except_hook(*args, **kw):
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1208
            try:
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1209
                run_old(*args, **kw)
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1210
            except (KeyboardInterrupt, SystemExit):
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1211
                raise
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1212
            except:
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1213
                sys.excepthook(*sys.exc_info())
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1214
        self.run = run_with_except_hook
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1215
    threading.Thread.__init__ = init
4f460c1dffb5 Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents: 1061
diff changeset
  1216
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1217
if __name__ == '__main__':
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1218
    # Install a exception handle for bug reports
588
aa5a08d20ba1 spring 2011 - 1.01 bugfix release
Edouard Tisserant
parents: 571
diff changeset
  1219
    AddExceptHook(os.getcwd(),updateinfo_url)
1408
eb2aa27602b7 Fixed launch of PLCopenEditor, broken since 611fded24ce4.
Edouard Tisserant
parents: 1404
diff changeset
  1220
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1221
    frame = Beremiz(None, projectOpen, buildpath)
1211
e3f805ba74ca Fixed bug when launching Beremiz with a wrong project path
Laurent Bessard
parents: 1091
diff changeset
  1222
    if splash:
e3f805ba74ca Fixed bug when launching Beremiz with a wrong project path
Laurent Bessard
parents: 1091
diff changeset
  1223
        splash.Close()
428
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1224
    frame.Show()
ea09f33ce717 Update internationalization for new functionalities.
laurent
parents: 427
diff changeset
  1225
    app.MainLoop()