author | Edouard Tisserant |
Mon, 04 Jun 2012 18:50:08 +0200 | |
changeset 758 | 699a7bad5a8c |
parent 755 | 9f5dbd90e1e0 |
child 759 | 8f6ed225f4d8 |
child 760 | d38560559afb |
permissions | -rwxr-xr-x |
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 |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
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 | 25 |
|
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 | 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] |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
46 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
47 |
try: |
736 | 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 | 53 |
|
54 |
extensions=[] |
|
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 | 60 |
if o in ("-u", "--updatecheck"): |
61 |
updateinfo_url = a |
|
731 | 62 |
if o in ("-e", "--extend"): |
63 |
extensions.append(a) |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
64 |
|
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 |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
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() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
86 |
|
588 | 87 |
# popup splash |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
88 |
bmp = wx.Image(Bpath("images","splash.png")).ConvertToBitmap() |
588 | 89 |
#splash=AdvancedSplash(None, bitmap=bmp, style=wx.SPLASH_CENTRE_ON_SCREEN, timeout=4000) |
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 | 93 |
if updateinfo_url is not None: |
94 |
updateinfo = "Fetching %s" % updateinfo_url |
|
95 |
# warn for possible updates |
|
96 |
def updateinfoproc(): |
|
97 |
global updateinfo |
|
98 |
try : |
|
99 |
import urllib2 |
|
100 |
updateinfo = urllib2.urlopen(updateinfo_url,None).read() |
|
101 |
except : |
|
102 |
updateinfo = "update info unavailable." |
|
103 |
||
104 |
from threading import Thread |
|
105 |
splash.SetText(text=updateinfo) |
|
106 |
wx.Yield() |
|
107 |
updateinfoThread = Thread(target=updateinfoproc) |
|
108 |
updateinfoThread.start() |
|
109 |
updateinfoThread.join(2) |
|
110 |
splash.SetText(text=updateinfo) |
|
111 |
wx.Yield() |
|
112 |
||
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
113 |
# Import module for internationalization |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
114 |
import gettext |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
115 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
116 |
# Get folder containing translation files |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
117 |
localedir = os.path.join(CWD,"locale") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
118 |
# Get the default language |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
119 |
langid = wx.LANGUAGE_DEFAULT |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
120 |
# Define translation domain (name of translation files) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
121 |
domain = "Beremiz" |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
122 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
123 |
# Define locale for wx |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
124 |
loc = __builtin__.__dict__.get('loc', None) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
125 |
if loc is None: |
589
22e83880cdd9
Adding support for disable language translation when default language not available in locale
laurent
parents:
588
diff
changeset
|
126 |
test_loc = wx.Locale(langid) |
22e83880cdd9
Adding support for disable language translation when default language not available in locale
laurent
parents:
588
diff
changeset
|
127 |
test_loc.AddCatalogLookupPathPrefix(localedir) |
22e83880cdd9
Adding support for disable language translation when default language not available in locale
laurent
parents:
588
diff
changeset
|
128 |
if test_loc.AddCatalog(domain): |
22e83880cdd9
Adding support for disable language translation when default language not available in locale
laurent
parents:
588
diff
changeset
|
129 |
loc = wx.Locale(langid) |
22e83880cdd9
Adding support for disable language translation when default language not available in locale
laurent
parents:
588
diff
changeset
|
130 |
else: |
22e83880cdd9
Adding support for disable language translation when default language not available in locale
laurent
parents:
588
diff
changeset
|
131 |
loc = wx.Locale(wx.LANGUAGE_ENGLISH) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
132 |
__builtin__.__dict__['loc'] = loc |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
133 |
# Define location for searching translation files |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
134 |
loc.AddCatalogLookupPathPrefix(localedir) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
135 |
# Define locale domain |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
136 |
loc.AddCatalog(domain) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
137 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
138 |
def unicode_translation(message): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
139 |
return wx.GetTranslation(message).encode("utf-8") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
140 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
141 |
if __name__ == '__main__': |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
142 |
__builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
143 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
144 |
base_folder = os.path.split(sys.path[0])[0] |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
145 |
sys.path.append(base_folder) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
146 |
sys.path.append(os.path.join(base_folder, "plcopeneditor")) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
147 |
|
735
d9f4ecee761d
Fixed extension loading too late causing features to be ignored
Edouard Tisserant
parents:
734
diff
changeset
|
148 |
if __name__ == '__main__': |
d9f4ecee761d
Fixed extension loading too late causing features to be ignored
Edouard Tisserant
parents:
734
diff
changeset
|
149 |
# Load extensions |
d9f4ecee761d
Fixed extension loading too late causing features to be ignored
Edouard Tisserant
parents:
734
diff
changeset
|
150 |
for extfilename in extensions: |
d9f4ecee761d
Fixed extension loading too late causing features to be ignored
Edouard Tisserant
parents:
734
diff
changeset
|
151 |
sys.path.append(os.path.split(os.path.realpath(extfilename))[0]) |
737 | 152 |
execfile(extfilename, locals()) |
735
d9f4ecee761d
Fixed extension loading too late causing features to be ignored
Edouard Tisserant
parents:
734
diff
changeset
|
153 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
154 |
import wx.lib.buttons, wx.lib.statbmp |
724 | 155 |
from util.TextCtrlAutoComplete import TextCtrlAutoComplete |
156 |
import cPickle |
|
157 |
from util.BrowseValuesLibraryDialog import BrowseValuesLibraryDialog |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
158 |
import types, time, re, platform, time, traceback, commands |
738 | 159 |
from ProjectController import ProjectController, MATIEC_ERROR_MODEL, ITEM_CONFNODE |
730 | 160 |
from util.MiniTextControler import MiniTextControler |
726 | 161 |
from util.ProcessLogger import ProcessLogger |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
162 |
|
727 | 163 |
from docutil import OpenHtmlFrame |
731 | 164 |
from PLCOpenEditor import IDEFrame, AppendMenu, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES |
715
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
165 |
from PLCOpenEditor import EditorPanel, Viewer, TextViewer, GraphicViewer, ResourceEditor, ConfigurationEditor, DataTypeEditor |
738 | 166 |
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
167 |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
168 |
MAX_RECENT_PROJECTS = 10 |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
169 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
170 |
class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
171 |
""" Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
172 |
and accept image name as __init__ parameter, fail silently if file do not exist""" |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
173 |
def __init__(self, parent, ID, bitmapname, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
174 |
pos = wx.DefaultPosition, size = wx.DefaultSize, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
175 |
style = 0, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
176 |
name = "genstatbmp"): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
177 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
178 |
bitmappath = Bpath( "images", bitmapname) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
179 |
if os.path.isfile(bitmappath): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
180 |
bitmap = wx.Bitmap(bitmappath) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
181 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
182 |
bitmap = None |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
183 |
wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID, bitmap, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
184 |
pos, size, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
185 |
style, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
186 |
name) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
187 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
188 |
def OnPaint(self, event): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
189 |
dc = wx.PaintDC(self) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
190 |
colour = self.GetParent().GetBackgroundColour() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
191 |
dc.SetPen(wx.Pen(colour)) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
192 |
dc.SetBrush(wx.Brush(colour )) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
193 |
dc.DrawRectangle(0, 0, *dc.GetSizeTuple()) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
194 |
if self._bitmap: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
195 |
dc.DrawBitmap(self._bitmap, 0, 0, True) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
196 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
197 |
|
705
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
198 |
from threading import Lock,Timer,currentThread |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
199 |
MainThread = currentThread().ident |
686
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
200 |
REFRESH_PERIOD = 0.1 |
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
201 |
from time import time as gettime |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
202 |
class LogPseudoFile: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
203 |
""" Base class for file like objects to facilitate StdOut for the Shell.""" |
451 | 204 |
def __init__(self, output, risecall): |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
205 |
self.red_white = wx.TextAttr("RED", "WHITE") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
206 |
self.red_yellow = wx.TextAttr("RED", "YELLOW") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
207 |
self.black_white = wx.TextAttr("BLACK", "WHITE") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
208 |
self.default_style = None |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
209 |
self.output = output |
451 | 210 |
self.risecall = risecall |
446
1edde533db19
Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents:
439
diff
changeset
|
211 |
# to prevent rapid fire on rising log panel |
1edde533db19
Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents:
439
diff
changeset
|
212 |
self.rising_timer = 0 |
686
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
213 |
self.lock = Lock() |
705
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
214 |
self.YieldLock = Lock() |
686
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
215 |
self.RefreshLock = Lock() |
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
216 |
self.stack = [] |
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
217 |
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
|
218 |
self.LastRefreshTimer = None |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
219 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
220 |
def write(self, s, style = None): |
686
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
221 |
if self.lock.acquire(): |
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
222 |
self.stack.append((s,style)) |
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
223 |
self.lock.release() |
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
224 |
current_time = gettime() |
688
6324b40d82a5
Even more robust logger, up to the really last line that comes after the rush
Edouard Tisserant
parents:
687
diff
changeset
|
225 |
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
|
226 |
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
|
227 |
self.LastRefreshTimer=None |
686
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
228 |
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
|
229 |
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
|
230 |
else: |
705
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
231 |
self.LastRefreshTimer = Timer(REFRESH_PERIOD, 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
|
232 |
self.LastRefreshTimer.start() |
686
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
233 |
|
705
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
234 |
def _should_write(self): |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
235 |
wx.CallAfter(self._write) |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
236 |
if MainThread == currentThread().ident: |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
237 |
app = wx.GetApp() |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
238 |
if app is not None: |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
239 |
if self.YieldLock.acquire(0): |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
240 |
app.Yield() |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
241 |
self.YieldLock.release() |
a5977f64d4d9
More gentle use of app.Yield in ProcessLogger
Edouard Tisserant
parents:
704
diff
changeset
|
242 |
|
686
e4e1da75d411
More robust Logger, now resist to flooding.
Edouard Tisserant
parents:
683
diff
changeset
|
243 |
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
|
244 |
if self.output : |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
245 |
self.output.Freeze(); |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
246 |
self.lock.acquire() |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
247 |
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
|
248 |
if style is None : style=self.black_white |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
249 |
if self.default_style != style: |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
250 |
self.output.SetDefaultStyle(style) |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
251 |
self.default_style = style |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
252 |
self.output.AppendText(s) |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
253 |
self.output.ScrollLines(s.count('\n')+1) |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
254 |
self.stack = [] |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
255 |
self.lock.release() |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
256 |
self.output.ShowPosition(self.output.GetLastPosition()) |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
257 |
self.output.Thaw() |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
258 |
self.LastRefreshTime = gettime() |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
259 |
try: |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
260 |
self.RefreshLock.release() |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
261 |
except: |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
262 |
pass |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
263 |
newtime = time.time() |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
264 |
if newtime - self.rising_timer > 1: |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
265 |
self.risecall() |
166db2cb630b
Stripped dead code in bug report dialog.\nFixed error when log flooded while quitting
Edouard Tisserant
parents:
692
diff
changeset
|
266 |
self.rising_timer = newtime |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
267 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
268 |
def write_warning(self, s): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
269 |
self.write(s,self.red_white) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
270 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
271 |
def write_error(self, s): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
272 |
self.write(s,self.red_yellow) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
273 |
|
569
37af7286dd65
LPC program transfer more verbose, test code added in __main__ of LPCBootProto
Edouqrd Tisserant <edouard.tisserant@gmail.com>
parents:
550
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
278 |
def flush(self): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
279 |
self.output.SetValue("") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
280 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
281 |
def isatty(self): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
282 |
return false |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
283 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
284 |
[ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
285 |
ID_BEREMIZPLCCONFIG, ID_BEREMIZLOGCONSOLE, |
623
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
286 |
ID_BEREMIZINSPECTOR] = [wx.NewId() for _init_ctrls in range(5)] |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
287 |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
288 |
[ID_FILEMENURECENTPROJECTS, |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
289 |
] = [wx.NewId() for _init_ctrls in range(1)] |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
290 |
|
717 | 291 |
CONFNODEMENU_POSITION = 3 |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
292 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
293 |
class Beremiz(IDEFrame): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
294 |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
295 |
def _init_coll_MenuBar_Menus(self, parent): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
296 |
IDEFrame._init_coll_MenuBar_Menus(self, parent) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
297 |
|
717 | 298 |
parent.Insert(pos=CONFNODEMENU_POSITION, |
299 |
menu=self.ConfNodeMenu, title=_(u'&ConfNode')) |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
300 |
|
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
301 |
def _init_utils(self): |
717 | 302 |
self.ConfNodeMenu = wx.Menu(title='') |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
303 |
self.RecentProjectsMenu = wx.Menu(title='') |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
304 |
|
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
305 |
IDEFrame._init_utils(self) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
306 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
307 |
def _init_coll_FileMenu_Items(self, parent): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
308 |
AppendMenu(parent, help='', id=wx.ID_NEW, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
309 |
kind=wx.ITEM_NORMAL, text=_(u'New\tCTRL+N')) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
310 |
AppendMenu(parent, help='', id=wx.ID_OPEN, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
311 |
kind=wx.ITEM_NORMAL, text=_(u'Open\tCTRL+O')) |
702 | 312 |
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
|
313 |
parent.AppendSeparator() |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
314 |
AppendMenu(parent, help='', id=wx.ID_SAVE, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
315 |
kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S')) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
316 |
AppendMenu(parent, help='', id=wx.ID_SAVEAS, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
317 |
kind=wx.ITEM_NORMAL, text=_(u'Save as\tCTRL+SHIFT+S')) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
318 |
AppendMenu(parent, help='', id=wx.ID_CLOSE, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
319 |
kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W')) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
320 |
AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL, |
702 | 321 |
kind=wx.ITEM_NORMAL, text=_(u'Close Project\tCTRL+SHIFT+W')) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
322 |
parent.AppendSeparator() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
323 |
AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP, |
702 | 324 |
kind=wx.ITEM_NORMAL, text=_(u'Page Setup\tCTRL+ALT+P')) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
325 |
AppendMenu(parent, help='', id=wx.ID_PREVIEW, |
702 | 326 |
kind=wx.ITEM_NORMAL, text=_(u'Preview\tCTRL+SHIFT+P')) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
327 |
AppendMenu(parent, help='', id=wx.ID_PRINT, |
702 | 328 |
kind=wx.ITEM_NORMAL, text=_(u'Print\tCTRL+P')) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
329 |
parent.AppendSeparator() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
330 |
AppendMenu(parent, help='', id=wx.ID_EXIT, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
331 |
kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q')) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
332 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
333 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
334 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
335 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
336 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
337 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
338 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
339 |
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
340 |
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
341 |
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
342 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
343 |
|
708 | 344 |
self.AddToMenuToolBar([(wx.ID_NEW, "new.png", _(u'New'), None), |
345 |
(wx.ID_OPEN, "open.png", _(u'Open'), None), |
|
346 |
(wx.ID_SAVE, "save.png", _(u'Save'), None), |
|
347 |
(wx.ID_SAVEAS, "saveas.png", _(u'Save As...'), None), |
|
348 |
(wx.ID_PRINT, "print.png", _(u'Print'), None)]) |
|
706 | 349 |
|
738 | 350 |
def _init_coll_AddMenu_Items(self, parent): |
351 |
IDEFrame._init_coll_AddMenu_Items(self, parent, False) |
|
352 |
new_id = wx.NewId() |
|
353 |
AppendMenu(parent, help='', id=new_id, |
|
354 |
kind=wx.ITEM_NORMAL, text=_(u'&Resource')) |
|
355 |
for name, XSDClass, help in ProjectController.CTNChildrenTypes: |
|
356 |
new_id = wx.NewId() |
|
357 |
AppendMenu(parent, help='', id=new_id, |
|
358 |
kind=wx.ITEM_NORMAL, text=help) |
|
359 |
self.Bind(wx.EVT_MENU, self._GetAddConfNodeFunction(name), id=new_id) |
|
360 |
||
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
361 |
def _init_coll_HelpMenu_Items(self, parent): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
362 |
parent.Append(help='', id=wx.ID_ABOUT, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
363 |
kind=wx.ITEM_NORMAL, text=_(u'About')) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
364 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
365 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
366 |
def _init_ctrls(self, prnt): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
367 |
IDEFrame._init_ctrls(self, prnt) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
368 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
369 |
self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR) |
623
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
370 |
accels = [wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), ID_BEREMIZINSPECTOR)] |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
371 |
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
|
372 |
("Run", wx.WXK_F5), |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
373 |
("Transfer", wx.WXK_F6), |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
374 |
("Connect", wx.WXK_F7), |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
375 |
("Build", wx.WXK_F11)]: |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
376 |
def OnMethodGen(obj,meth): |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
377 |
def OnMethod(evt): |
717 | 378 |
if obj.CTR is not None: |
379 |
obj.CTR.CallMethod('_'+meth) |
|
738 | 380 |
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
|
381 |
return OnMethod |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
382 |
newid = wx.NewId() |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
383 |
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
|
384 |
accels += [wx.AcceleratorEntry(wx.ACCEL_NORMAL, shortcut,newid)] |
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
385 |
|
8cdb533c3c7a
A few new keyboard shortcuts : F4=stop, F5=run, F5=transfer, F7=connect
Edouard Tisserant
parents:
619
diff
changeset
|
386 |
self.SetAcceleratorTable(wx.AcceleratorTable(accels)) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
387 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
388 |
self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
389 |
name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0), |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
390 |
size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
391 |
self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick) |
715
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
392 |
self.MainTabs["LogConsole"] = (self.LogConsole, _("Log Console")) |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
393 |
self.BottomNoteBook.AddPage(*self.MainTabs["LogConsole"]) |
731 | 394 |
self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogConsole), wx.RIGHT) |
738 | 395 |
|
396 |
StatusToolBar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, |
|
397 |
wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER) |
|
398 |
StatusToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
|
399 |
StatusToolBar.Realize() |
|
400 |
self.Panes["StatusToolBar"] = StatusToolBar |
|
401 |
self.AUIManager.AddPane(StatusToolBar, wx.aui.AuiPaneInfo(). |
|
402 |
Name("StatusToolBar").Caption(_("Status ToolBar")). |
|
403 |
ToolbarPane().Top().Position(2). |
|
404 |
LeftDockable(False).RightDockable(False)) |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
405 |
|
738 | 406 |
self.AUIManager.Update() |
407 |
||
717 | 408 |
def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True): |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
409 |
IDEFrame.__init__(self, parent, debug) |
451 | 410 |
self.Log = LogPseudoFile(self.LogConsole,self.RiseLogConsole) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
411 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
412 |
self.local_runtime = None |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
413 |
self.runtime_port = None |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
414 |
self.local_runtime_tmpdir = None |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
415 |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
416 |
self.LastPanelSelected = None |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
417 |
|
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
|
418 |
# 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
|
419 |
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
|
420 |
self.LocationImageDict = {} |
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
|
421 |
|
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
|
422 |
# 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
|
423 |
for imgname, itemtype in [ |
717 | 424 |
("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
|
425 |
("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
|
426 |
("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
|
427 |
("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
|
428 |
("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
|
429 |
("VAR_LOCAL", LOCATION_VAR_MEMORY)]: |
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
|
430 |
self.LocationImageDict[itemtype]=self.LocationImageList.Add(wx.Bitmap(os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png'%imgname))) |
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
|
431 |
|
738 | 432 |
# Icons for other items |
433 |
for imgname, itemtype in [ |
|
434 |
("Extension", ITEM_CONFNODE)]: |
|
435 |
self.TreeImageDict[itemtype]=self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'images', '%s.png'%imgname))) |
|
436 |
||
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
|
437 |
# Add beremiz's icon in top left corner of the frame |
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
|
438 |
self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO)) |
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
|
439 |
|
715
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
440 |
if projectOpen is None and self.Config.HasEntry("currenteditedproject"): |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
441 |
projectOpen = str(self.Config.Read("currenteditedproject")) |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
442 |
if projectOpen == "": |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
443 |
projectOpen = None |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
444 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
445 |
if projectOpen is not None and os.path.isdir(projectOpen): |
725 | 446 |
self.CTR = ProjectController(self, self.Log) |
717 | 447 |
self.Controler = self.CTR |
448 |
result = self.CTR.LoadProject(projectOpen, buildpath) |
|
679
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
449 |
if not result: |
716
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
450 |
self.LibraryPanel.SetControler(self.Controler) |
738 | 451 |
self.ProjectTree.Enable(True) |
730 | 452 |
self.PouInstanceVariablesPanel.SetController(self.Controler) |
679
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
453 |
self.RefreshConfigRecentProjects(os.path.abspath(projectOpen)) |
730 | 454 |
self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
679
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
455 |
else: |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
456 |
self.ResetView() |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
457 |
self.ShowErrorMessage(result) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
458 |
else: |
717 | 459 |
self.CTR = ctr |
460 |
self.Controler = ctr |
|
461 |
if ctr is not None: |
|
716
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
462 |
self.LibraryPanel.SetControler(self.Controler) |
738 | 463 |
self.ProjectTree.Enable(True) |
730 | 464 |
self.PouInstanceVariablesPanel.SetController(self.Controler) |
465 |
self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
|
490 | 466 |
if self.EnableDebug: |
717 | 467 |
self.DebugVariablePanel.SetDataProducer(self.CTR) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
468 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
469 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
470 |
|
706 | 471 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
717 | 472 |
self.RefreshConfNodeMenu() |
755 | 473 |
self.RefreshAll() |
590 | 474 |
self.LogConsole.SetFocus() |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
475 |
|
446
1edde533db19
Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents:
439
diff
changeset
|
476 |
def RiseLogConsole(self): |
513
feb2acb04070
Split BottomNoteBook to make LogConsole always visible
laurent
parents:
509
diff
changeset
|
477 |
self.BottomNoteBook.SetSelection(self.BottomNoteBook.GetPageIndex(self.LogConsole)) |
446
1edde533db19
Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents:
439
diff
changeset
|
478 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
479 |
def RefreshTitle(self): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
480 |
name = _("Beremiz") |
717 | 481 |
if self.CTR is not None: |
482 |
projectname = self.CTR.GetProjectName() |
|
483 |
if self.CTR.ProjectTestModified(): |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
484 |
projectname = "~%s~" % projectname |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
485 |
self.SetTitle("%s - %s" % (name, projectname)) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
486 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
487 |
self.SetTitle(name) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
488 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
489 |
def StartLocalRuntime(self, taskbaricon = True): |
713
37dc330e96a2
Reflected recent changes in ProcessLogger changes in StartLocalRuntime
Edouard Tisserant
parents:
710
diff
changeset
|
490 |
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
|
491 |
# create temporary directory for runtime working directory |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
492 |
self.local_runtime_tmpdir = tempfile.mkdtemp() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
493 |
# choose an arbitrary random port for runtime |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
494 |
self.runtime_port = int(random.random() * 1000) + 61131 |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
495 |
# launch local runtime |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
496 |
self.local_runtime = ProcessLogger(self.Log, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
497 |
"\"%s\" \"%s\" -p %s -i localhost %s %s"%(sys.executable, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
498 |
Bpath("Beremiz_service.py"), |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
499 |
self.runtime_port, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
500 |
{False : "-x 0", True :"-x 1"}[taskbaricon], |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
501 |
self.local_runtime_tmpdir), |
704 | 502 |
no_gui=False, |
503 |
timeout=500, keyword = "working") |
|
504 |
self.local_runtime.spin() |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
505 |
return self.runtime_port |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
506 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
507 |
def KillLocalRuntime(self): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
508 |
if self.local_runtime is not None: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
509 |
# shutdown local runtime |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
510 |
self.local_runtime.kill(gently=False) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
511 |
# clear temp dir |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
512 |
shutil.rmtree(self.local_runtime_tmpdir) |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
513
diff
changeset
|
513 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
513
diff
changeset
|
514 |
self.local_runtime = None |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
515 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
516 |
def OnOpenWidgetInspector(self, evt): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
517 |
# Activate the widget inspection tool |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
518 |
from wx.lib.inspection import InspectionTool |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
519 |
if not InspectionTool().initialized: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
520 |
InspectionTool().Init() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
521 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
522 |
# Find a widget to be selected in the tree. Use either the |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
523 |
# one under the cursor, if any, or this frame. |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
524 |
wnd = wx.FindWindowAtPointer() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
525 |
if not wnd: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
526 |
wnd = self |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
527 |
InspectionTool().Show(wnd, True) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
528 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
529 |
def OnLogConsoleDClick(self, event): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
530 |
wx.CallAfter(self.SearchLineForError) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
531 |
event.Skip() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
532 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
533 |
def SearchLineForError(self): |
717 | 534 |
if self.CTR is not None: |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
535 |
text = self.LogConsole.GetRange(0, self.LogConsole.GetInsertionPoint()) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
536 |
line = self.LogConsole.GetLineText(len(text.splitlines()) - 1) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
537 |
result = MATIEC_ERROR_MODEL.match(line) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
538 |
if result is not None: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
539 |
first_line, first_column, last_line, last_column, error = result.groups() |
717 | 540 |
infos = self.CTR.ShowError(self.Log, |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
541 |
(int(first_line), int(first_column)), |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
542 |
(int(last_line), int(last_column))) |
429
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
543 |
|
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
544 |
## 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
|
545 |
# @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
|
546 |
def CheckSaveBeforeClosing(self, title=_("Close Project")): |
717 | 547 |
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
|
548 |
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
|
549 |
_("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
|
550 |
title, |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
551 |
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
|
552 |
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
|
553 |
dialog.Destroy() |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
554 |
if answer == wx.ID_YES: |
717 | 555 |
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
|
556 |
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
|
557 |
return False |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
558 |
return True |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
559 |
|
715
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
560 |
def GetTabInfos(self, tab): |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
561 |
if (isinstance(tab, EditorPanel) and |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
562 |
not isinstance(tab, (Viewer, |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
563 |
TextViewer, |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
564 |
GraphicViewer, |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
565 |
ResourceEditor, |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
566 |
ConfigurationEditor, |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
567 |
DataTypeEditor))): |
718 | 568 |
return ("confnode", tab.Controler.CTNFullName()) |
716
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
569 |
elif (isinstance(tab, TextViewer) and |
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
570 |
(tab.Controler is None or isinstance(tab.Controler, MiniTextControler))): |
717 | 571 |
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
|
572 |
else: |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
573 |
return IDEFrame.GetTabInfos(self, tab) |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
574 |
|
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
575 |
def LoadTab(self, notebook, page_infos): |
717 | 576 |
if page_infos[0] == "confnode": |
716
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
577 |
if page_infos[1] is None: |
717 | 578 |
confnode = self.CTR |
716
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
579 |
else: |
717 | 580 |
confnode = self.CTR.GetChildByName(page_infos[1]) |
581 |
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
|
582 |
else: |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
583 |
return IDEFrame.LoadTab(self, notebook, page_infos) |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
584 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
585 |
def OnCloseFrame(self, event): |
717 | 586 |
if self.CTR is None or self.CheckSaveBeforeClosing(_("Close Application")): |
587 |
if self.CTR is not None: |
|
588 |
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
|
589 |
self.KillLocalRuntime() |
598
6c919bc1551d
Adding support for saving frame size while closing and restore it at next launch
laurent
parents:
590
diff
changeset
|
590 |
|
715
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
591 |
self.SaveLastState() |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
592 |
|
717 | 593 |
if self.CTR is not None: |
594 |
project_path = os.path.realpath(self.CTR.GetProjectPath()) |
|
715
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
595 |
else: |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
596 |
project_path = "" |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
597 |
self.Config.Write("currenteditedproject", project_path) |
135566ab0807
Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents:
714
diff
changeset
|
598 |
self.Config.Flush() |
598
6c919bc1551d
Adding support for saving frame size while closing and restore it at next launch
laurent
parents:
590
diff
changeset
|
599 |
|
429
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
600 |
event.Skip() |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
601 |
else: |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
602 |
event.Veto() |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
603 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
604 |
def RefreshFileMenu(self): |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
605 |
self.RefreshRecentProjectsMenu() |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
606 |
|
706 | 607 |
MenuToolBar = self.Panes["MenuToolBar"] |
717 | 608 |
if self.CTR is not None: |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
609 |
selected = self.TabsOpened.GetSelection() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
610 |
if selected >= 0: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
611 |
graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
612 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
613 |
graphic_viewer = False |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
614 |
if self.TabsOpened.GetPageCount() > 0: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
615 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
616 |
if graphic_viewer: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
617 |
self.FileMenu.Enable(wx.ID_PREVIEW, True) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
618 |
self.FileMenu.Enable(wx.ID_PRINT, True) |
706 | 619 |
MenuToolBar.EnableTool(wx.ID_PRINT, True) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
620 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
621 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
622 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
706 | 623 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
624 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
625 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
626 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
627 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
706 | 628 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
629 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
717 | 630 |
project_modified = self.CTR.ProjectTestModified() |
706 | 631 |
self.FileMenu.Enable(wx.ID_SAVE, project_modified) |
632 |
MenuToolBar.EnableTool(wx.ID_SAVE, project_modified) |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
633 |
self.FileMenu.Enable(wx.ID_SAVEAS, True) |
706 | 634 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, True) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
635 |
self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
636 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
637 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
638 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
639 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
640 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
641 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
706 | 642 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
643 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
706 | 644 |
MenuToolBar.EnableTool(wx.ID_SAVE, False) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
645 |
self.FileMenu.Enable(wx.ID_SAVEAS, False) |
706 | 646 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, False) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
647 |
self.FileMenu.Enable(wx.ID_PROPERTIES, False) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
648 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
649 |
|
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
650 |
def RefreshRecentProjectsMenu(self): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
651 |
recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([])))) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
652 |
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
|
653 |
for idx, projectpath in enumerate(recent_projects): |
730 | 654 |
text = u'%d: %s' % (idx + 1, projectpath) |
655 |
||
656 |
if idx < self.RecentProjectsMenu.GetMenuItemCount(): |
|
657 |
item = self.RecentProjectsMenu.FindItemByPosition(idx) |
|
658 |
id = item.GetId() |
|
659 |
item.SetItemLabel(text) |
|
660 |
self.Disconnect(id, id, wx.EVT_BUTTON._getEvtType()) |
|
661 |
else: |
|
662 |
id = wx.NewId() |
|
663 |
AppendMenu(self.RecentProjectsMenu, help='', id=id, |
|
664 |
kind=wx.ITEM_NORMAL, text=text) |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
665 |
self.Bind(wx.EVT_MENU, self.GenerateOpenRecentProjectFunction(projectpath), id=id) |
730 | 666 |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
667 |
def GenerateOpenRecentProjectFunction(self, projectpath): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
668 |
def OpenRecentProject(event): |
717 | 669 |
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
|
670 |
return |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
671 |
|
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
672 |
self.OpenProject(projectpath) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
673 |
return OpenRecentProject |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
674 |
|
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
675 |
def GenerateMenuRecursive(self, items, menu): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
676 |
for kind, infos in items: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
677 |
if isinstance(kind, ListType): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
678 |
text, id = infos |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
679 |
submenu = wx.Menu('') |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
680 |
self.GenerateMenuRecursive(kind, submenu) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
681 |
menu.AppendMenu(id, text, submenu) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
682 |
elif kind == wx.ITEM_SEPARATOR: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
683 |
menu.AppendSeparator() |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
684 |
else: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
685 |
text, id, help, callback = infos |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
686 |
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
|
687 |
if callback is not None: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
688 |
self.Bind(wx.EVT_MENU, callback, id=id) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
689 |
|
738 | 690 |
def RefreshStatusToolBar(self): |
691 |
StatusToolBar = self.Panes["StatusToolBar"] |
|
692 |
StatusToolBar.ClearTools() |
|
693 |
||
694 |
if self.CTR is not None: |
|
695 |
||
696 |
for confnode_method in self.CTR.StatusMethods: |
|
697 |
if "method" in confnode_method and confnode_method.get("shown",True): |
|
698 |
id = wx.NewId() |
|
699 |
StatusToolBar.AddSimpleTool(id, |
|
700 |
wx.Bitmap(Bpath("images", "%s.png"%confnode_method.get("bitmap", "Unknown"))), |
|
701 |
confnode_method["tooltip"]) |
|
702 |
self.Bind(wx.EVT_MENU, self.GetMenuCallBackFunction(confnode_method["method"]), id=id) |
|
703 |
||
704 |
StatusToolBar.Realize() |
|
705 |
self.AUIManager.GetPane("StatusToolBar").BestSize(StatusToolBar.GetBestSize()).Show() |
|
706 |
else: |
|
707 |
self.AUIManager.GetPane("StatusToolBar").Hide() |
|
708 |
self.AUIManager.Update() |
|
709 |
||
717 | 710 |
def RefreshConfNodeMenu(self): |
711 |
if self.CTR is not None: |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
712 |
selected = self.TabsOpened.GetSelection() |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
713 |
if selected >= 0: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
714 |
panel = self.TabsOpened.GetPage(selected) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
715 |
else: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
716 |
panel = None |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
717 |
if panel != self.LastPanelSelected: |
717 | 718 |
for i in xrange(self.ConfNodeMenu.GetMenuItemCount()): |
719 |
item = self.ConfNodeMenu.FindItemByPosition(0) |
|
720 |
self.ConfNodeMenu.Delete(item.GetId()) |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
721 |
self.LastPanelSelected = panel |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
722 |
if panel is not None: |
717 | 723 |
items = panel.GetConfNodeMenuItems() |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
724 |
else: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
725 |
items = [] |
717 | 726 |
self.MenuBar.EnableTop(CONFNODEMENU_POSITION, len(items) > 0) |
727 |
self.GenerateMenuRecursive(items, self.ConfNodeMenu) |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
728 |
if panel is not None: |
717 | 729 |
panel.RefreshConfNodeMenu(self.ConfNodeMenu) |
730 |
else: |
|
731 |
self.MenuBar.EnableTop(CONFNODEMENU_POSITION, False) |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
732 |
self.MenuBar.UpdateMenus() |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
733 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
734 |
def RefreshAll(self): |
755 | 735 |
self.RefreshStatusToolBar() |
717 | 736 |
|
738 | 737 |
def _GetAddConfNodeFunction(self, name, confnode=None): |
717 | 738 |
def OnConfNodeMenu(event): |
739 |
wx.CallAfter(self.AddConfNode, name, confnode) |
|
740 |
return OnConfNodeMenu |
|
741 |
||
738 | 742 |
def GetMenuCallBackFunction(self, method): |
743 |
""" Generate the callbackfunc for a given CTR method""" |
|
744 |
def OnMenu(event): |
|
745 |
# Disable button to prevent re-entrant call |
|
746 |
event.GetEventObject().Disable() |
|
747 |
# Call |
|
748 |
getattr(self.CTR, method)() |
|
749 |
# Re-enable button |
|
750 |
event.GetEventObject().Enable() |
|
751 |
# Trigger refresh on Idle |
|
752 |
wx.CallAfter(self.RefreshStatusToolBar) |
|
753 |
return OnMenu |
|
754 |
||
755 |
def GetConfigEntry(self, entry_name, default): |
|
756 |
return cPickle.loads(str(self.Config.Read(entry_name, cPickle.dumps(default)))) |
|
757 |
||
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
758 |
def ResetView(self): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
759 |
IDEFrame.ResetView(self) |
717 | 760 |
self.ConfNodeInfos = {} |
761 |
if self.CTR is not None: |
|
762 |
self.CTR.CloseProject() |
|
763 |
self.CTR = None |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
764 |
self.Log.flush() |
490 | 765 |
if self.EnableDebug: |
766 |
self.DebugVariablePanel.SetDataProducer(None) |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
767 |
|
679
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
768 |
def RefreshConfigRecentProjects(self, projectpath): |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
769 |
recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([])))) |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
770 |
if projectpath in recent_projects: |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
771 |
recent_projects.remove(projectpath) |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
772 |
recent_projects.insert(0, projectpath) |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
773 |
self.Config.Write("RecentProjects", cPickle.dumps(recent_projects[:MAX_RECENT_PROJECTS])) |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
774 |
self.Config.Flush() |
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
775 |
|
743 | 776 |
def ResetPerspective(self): |
777 |
IDEFrame.ResetPerspective(self) |
|
778 |
self.RefreshStatusToolBar() |
|
779 |
||
780 |
def RestoreLastLayout(self): |
|
781 |
IDEFrame.RestoreLastLayout(self) |
|
782 |
self.RefreshStatusToolBar() |
|
783 |
||
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
784 |
def OnNewProjectMenu(self, event): |
717 | 785 |
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
|
786 |
return |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
787 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
788 |
if not self.Config.HasEntry("lastopenedfolder"): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
789 |
defaultpath = os.path.expanduser("~") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
790 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
791 |
defaultpath = self.Config.Read("lastopenedfolder") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
792 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
793 |
dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
794 |
if dialog.ShowModal() == wx.ID_OK: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
795 |
projectpath = dialog.GetPath() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
796 |
self.Config.Write("lastopenedfolder", os.path.dirname(projectpath)) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
797 |
self.Config.Flush() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
798 |
self.ResetView() |
725 | 799 |
ctr = ProjectController(self, self.Log) |
717 | 800 |
result = ctr.NewProject(projectpath) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
801 |
if not result: |
717 | 802 |
self.CTR = ctr |
803 |
self.Controler = self.CTR |
|
716
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
804 |
self.LibraryPanel.SetControler(self.Controler) |
738 | 805 |
self.ProjectTree.Enable(True) |
730 | 806 |
self.PouInstanceVariablesPanel.SetController(self.Controler) |
679
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
807 |
self.RefreshConfigRecentProjects(projectpath) |
490 | 808 |
if self.EnableDebug: |
717 | 809 |
self.DebugVariablePanel.SetDataProducer(self.CTR) |
730 | 810 |
self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
811 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
812 |
self.ResetView() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
813 |
self.ShowErrorMessage(result) |
755 | 814 |
self.RefreshAll() |
706 | 815 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
679
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
816 |
dialog.Destroy() |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
817 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
818 |
def OnOpenProjectMenu(self, event): |
717 | 819 |
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
|
820 |
return |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
821 |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
822 |
if not self.Config.HasEntry("lastopenedfolder"): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
823 |
defaultpath = os.path.expanduser("~") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
824 |
else: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
825 |
defaultpath = self.Config.Read("lastopenedfolder") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
826 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
827 |
dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
828 |
if dialog.ShowModal() == wx.ID_OK: |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
829 |
self.OpenProject(dialog.GetPath()) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
830 |
dialog.Destroy() |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
831 |
|
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
832 |
def OpenProject(self, projectpath): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
833 |
if os.path.isdir(projectpath): |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
834 |
self.Config.Write("lastopenedfolder", os.path.dirname(projectpath)) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
835 |
self.Config.Flush() |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
836 |
self.ResetView() |
725 | 837 |
self.CTR = ProjectController(self, self.Log) |
717 | 838 |
self.Controler = self.CTR |
839 |
result = self.CTR.LoadProject(projectpath) |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
840 |
if not result: |
716
180e4a7d945c
Adding search field for finding function or function block in library tree
laurent
parents:
715
diff
changeset
|
841 |
self.LibraryPanel.SetControler(self.Controler) |
738 | 842 |
self.ProjectTree.Enable(True) |
730 | 843 |
self.PouInstanceVariablesPanel.SetController(self.Controler) |
679
d72f3a42f440
Fix recent projects list not updated when creating new project
laurent
parents:
678
diff
changeset
|
844 |
self.RefreshConfigRecentProjects(projectpath) |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
845 |
if self.EnableDebug: |
717 | 846 |
self.DebugVariablePanel.SetDataProducer(self.CTR) |
743 | 847 |
self.LoadProjectLayout() |
730 | 848 |
self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
849 |
else: |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
850 |
self.ResetView() |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
851 |
self.ShowErrorMessage(result) |
755 | 852 |
self.RefreshAll() |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
853 |
else: |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
854 |
self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath) |
706 | 855 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
856 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
857 |
def OnCloseProjectMenu(self, event): |
717 | 858 |
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
|
859 |
return |
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
860 |
|
743 | 861 |
self.SaveProjectLayout() |
429
1a5471e81a93
Adding support for asking for saving while trying to close a modified project in any case
laurent
parents:
428
diff
changeset
|
862 |
self.ResetView() |
706 | 863 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
755 | 864 |
self.RefreshAll() |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
865 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
866 |
def OnSaveProjectMenu(self, event): |
717 | 867 |
if self.CTR is not None: |
868 |
self.CTR.SaveProject() |
|
636
35c59bfc54f2
Fixing refresh of notebook tab titles after project save
laurent
parents:
631
diff
changeset
|
869 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
870 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
871 |
def OnSaveProjectAsMenu(self, event): |
717 | 872 |
if self.CTR is not None: |
873 |
self.CTR.SaveProjectAs() |
|
636
35c59bfc54f2
Fixing refresh of notebook tab titles after project save
laurent
parents:
631
diff
changeset
|
874 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
875 |
event.Skip() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
876 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
877 |
def OnQuitMenu(self, event): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
878 |
self.Close() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
879 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
880 |
def OnAboutMenu(self, event): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
881 |
OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc","about.html"), wx.Size(550, 500)) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
882 |
|
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
883 |
def OnPouSelectedChanged(self, event): |
717 | 884 |
wx.CallAfter(self.RefreshConfNodeMenu) |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
885 |
IDEFrame.OnPouSelectedChanged(self, event) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
886 |
|
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
887 |
def OnPageClose(self, event): |
717 | 888 |
wx.CallAfter(self.RefreshConfNodeMenu) |
675
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
889 |
IDEFrame.OnPageClose(self, event) |
44b35c27e9ff
Adding support for quickly open recent projects in file menu
laurent
parents:
666
diff
changeset
|
890 |
|
738 | 891 |
def OnProjectTreeItemBeginEdit(self, event): |
892 |
selected = event.GetItem() |
|
747 | 893 |
if self.ProjectTree.GetPyData(selected)["type"] == ITEM_CONFNODE: |
738 | 894 |
event.Veto() |
895 |
else: |
|
896 |
IDEFrame.OnProjectTreeItemBeginEdit(self, event) |
|
897 |
||
898 |
def OnProjectTreeRightUp(self, event): |
|
899 |
if wx.Platform == '__WXMSW__': |
|
900 |
item = event.GetItem() |
|
901 |
else: |
|
902 |
item, flags = self.ProjectTree.HitTest(wx.Point(event.GetX(), event.GetY())) |
|
903 |
item_infos = self.ProjectTree.GetPyData(item) |
|
904 |
||
905 |
if item_infos["type"] == ITEM_CONFNODE: |
|
906 |
confnode_menu = wx.Menu(title='') |
|
907 |
||
908 |
confnode = item_infos["confnode"] |
|
909 |
if confnode is not None and len(confnode.CTNChildrenTypes) > 0: |
|
910 |
for name, XSDClass, help in confnode.CTNChildrenTypes: |
|
911 |
new_id = wx.NewId() |
|
912 |
confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=name) |
|
913 |
self.Bind(wx.EVT_MENU, self._GetAddConfNodeFunction(name, confnode), id=new_id) |
|
914 |
||
915 |
new_id = wx.NewId() |
|
916 |
AppendMenu(confnode_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Delete")) |
|
755 | 917 |
self.Bind(wx.EVT_MENU, self.GetDeleteMenuFunction(confnode), id=new_id) |
738 | 918 |
|
919 |
self.PopupMenu(confnode_menu) |
|
920 |
confnode_menu.Destroy() |
|
921 |
||
922 |
event.Skip() |
|
923 |
else: |
|
924 |
IDEFrame.OnProjectTreeRightUp(self, event) |
|
925 |
||
926 |
def OnProjectTreeItemActivated(self, event): |
|
927 |
selected = event.GetItem() |
|
928 |
name = self.ProjectTree.GetItemText(selected) |
|
929 |
item_infos = self.ProjectTree.GetPyData(selected) |
|
930 |
if item_infos["type"] == ITEM_CONFNODE: |
|
931 |
item_infos["confnode"]._OpenView() |
|
932 |
event.Skip() |
|
933 |
elif item_infos["type"] == ITEM_PROJECT: |
|
934 |
self.CTR._OpenView() |
|
935 |
else: |
|
936 |
IDEFrame.OnProjectTreeItemActivated(self, event) |
|
937 |
||
938 |
def SelectProjectTreeItem(self, tagname): |
|
939 |
if self.ProjectTree is not None: |
|
940 |
root = self.ProjectTree.GetRootItem() |
|
941 |
if root.IsOk(): |
|
942 |
words = tagname.split("::") |
|
943 |
if len(words) == 1: |
|
944 |
if tagname == "Project": |
|
945 |
self.SelectedItem = root |
|
946 |
self.ProjectTree.SelectItem(root) |
|
947 |
wx.CallAfter(self.ResetSelectedItem) |
|
948 |
else: |
|
949 |
return self.RecursiveProjectTreeItemSelection(root, |
|
950 |
[(word, ITEM_CONFNODE) for word in tagname.split(".")]) |
|
951 |
elif words[0] == "R": |
|
952 |
return self.RecursiveProjectTreeItemSelection(root, [(words[2], ITEM_RESOURCE)]) |
|
953 |
else: |
|
954 |
IDEFrame.SelectProjectTreeItem(self, tagname) |
|
955 |
||
755 | 956 |
def GetDeleteMenuFunction(self, confnode): |
957 |
def DeleteMenuFunction(event): |
|
717 | 958 |
wx.CallAfter(self.DeleteConfNode, confnode) |
755 | 959 |
return DeleteMenuFunction |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
960 |
|
738 | 961 |
def AddConfNode(self, ConfNodeType, confnode=None): |
717 | 962 |
if self.CTR.CheckProjectPathPerm(): |
963 |
dialog = wx.TextEntryDialog(self, _("Please enter a name for confnode:"), _("Add ConfNode"), "", wx.OK|wx.CANCEL) |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
964 |
if dialog.ShowModal() == wx.ID_OK: |
717 | 965 |
ConfNodeName = dialog.GetValue() |
738 | 966 |
if confnode is not None: |
967 |
confnode.CTNAddChild(ConfNodeName, ConfNodeType) |
|
968 |
else: |
|
969 |
self.CTR.CTNAddChild(ConfNodeName, ConfNodeType) |
|
970 |
self._Refresh(TITLE, FILEMENU, PROJECTTREE) |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
971 |
dialog.Destroy() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
972 |
|
717 | 973 |
def DeleteConfNode(self, confnode): |
974 |
if self.CTR.CheckProjectPathPerm(): |
|
975 |
dialog = wx.MessageDialog(self, _("Really delete confnode ?"), _("Remove confnode"), wx.YES_NO|wx.NO_DEFAULT) |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
976 |
if dialog.ShowModal() == wx.ID_YES: |
718 | 977 |
confnode.CTNRemove() |
717 | 978 |
del confnode |
738 | 979 |
self._Refresh(TITLE, FILEMENU, PROJECTTREE) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
980 |
dialog.Destroy() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
981 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
982 |
#------------------------------------------------------------------------------- |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
983 |
# Exception Handler |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
984 |
#------------------------------------------------------------------------------- |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
985 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
986 |
Max_Traceback_List_Size = 20 |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
987 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
988 |
def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
989 |
trcbck_lst = [] |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
990 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
734 | 991 |
trcbck = " " + str(i+1) + ". " |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
992 |
if line[0].find(os.getcwd()) == -1: |
734 | 993 |
trcbck += "file : " + str(line[0]) + ", " |
994 |
else: |
|
995 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
996 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
997 |
trcbck_lst.append(trcbck) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
998 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
999 |
# Allow clicking.... |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1000 |
cap = wx.Window_GetCapture() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1001 |
if cap: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1002 |
cap.ReleaseMouse() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1003 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1004 |
dlg = wx.SingleChoiceDialog(None, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1005 |
_(""" |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1006 |
An unhandled exception (bug) occured. Bug report saved at : |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1007 |
(%s) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1008 |
|
434 | 1009 |
Please be kind enough to send this file to: |
734 | 1010 |
beremiz-devel@lists.sourceforge.net |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1011 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1012 |
You should now restart Beremiz. |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1013 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1014 |
Traceback: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1015 |
""") % bug_report_path + |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1016 |
str(e_type) + " : " + str(e_value), |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1017 |
_("Error"), |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1018 |
trcbck_lst) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1019 |
try: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1020 |
res = (dlg.ShowModal() == wx.ID_OK) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1021 |
finally: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1022 |
dlg.Destroy() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1023 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1024 |
return res |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1025 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1026 |
def get_last_traceback(tb): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1027 |
while tb.tb_next: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1028 |
tb = tb.tb_next |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1029 |
return tb |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1030 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1031 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1032 |
def format_namespace(d, indent=' '): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1033 |
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
|
1034 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1035 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1036 |
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
|
1037 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1038 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1039 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1040 |
def handle_exception(e_type, e_value, e_traceback): |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1041 |
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
|
1042 |
last_tb = get_last_traceback(e_traceback) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1043 |
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
|
1044 |
if ex not in ignored_exceptions: |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1045 |
date = time.ctime() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1046 |
bug_report_path = path+os.sep+"bug_report_"+date.replace(':','-').replace(' ','_')+".txt" |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1047 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback,bug_report_path) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1048 |
if result: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1049 |
ignored_exceptions.append(ex) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1050 |
info = { |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1051 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1052 |
'app-version' : app_version, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1053 |
'wx-version' : wx.VERSION_STRING, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1054 |
'wx-platform' : wx.Platform, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1055 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1056 |
'platform' : platform.platform(), |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1057 |
'e-type' : e_type, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1058 |
'e-value' : e_value, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1059 |
'date' : date, |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1060 |
'cwd' : os.getcwd(), |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1061 |
} |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1062 |
if e_traceback: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1063 |
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
|
1064 |
last_tb = get_last_traceback(e_traceback) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1065 |
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
|
1066 |
info['locals'] = format_namespace(exception_locals) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1067 |
if 'self' in exception_locals: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1068 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1069 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1070 |
output = open(bug_report_path,'w') |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1071 |
lst = info.keys() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1072 |
lst.sort() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1073 |
for a in lst: |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1074 |
output.write(a+":\n"+str(info[a])+"\n\n") |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1075 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1076 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1077 |
sys.excepthook = handle_exception |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1078 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1079 |
if __name__ == '__main__': |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1080 |
# Install a exception handle for bug reports |
588 | 1081 |
AddExceptHook(os.getcwd(),updateinfo_url) |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1082 |
|
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1083 |
frame = Beremiz(None, projectOpen, buildpath) |
590 | 1084 |
splash.Close() |
428
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1085 |
frame.Show() |
ea09f33ce717
Update internationalization for new functionalities.
laurent
parents:
427
diff
changeset
|
1086 |
app.MainLoop() |