1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
3 |
4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
4 # This file is part of Beremiz, a Integrated Development Environment for |
5 #based on the plcopen standard. |
5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
6 # |
6 # |
7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
8 # |
8 # |
9 #See COPYING file for copyrights details. |
9 # See COPYING file for copyrights details. |
10 # |
10 # |
11 #This library is free software; you can redistribute it and/or |
11 # This program is free software; you can redistribute it and/or |
12 #modify it under the terms of the GNU General Public |
12 # modify it under the terms of the GNU General Public License |
13 #License as published by the Free Software Foundation; either |
13 # as published by the Free Software Foundation; either version 2 |
14 #version 2.1 of the License, or (at your option) any later version. |
14 # of the License, or (at your option) any later version. |
15 # |
15 # |
16 #This library is distributed in the hope that it will be useful, |
16 # This program is distributed in the hope that it will be useful, |
17 #but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 #General Public License for more details. |
19 # GNU General Public License for more details. |
20 # |
20 # |
21 #You should have received a copy of the GNU General Public |
21 # You should have received a copy of the GNU General Public License |
22 #License along with this library; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 import wx |
25 import wx |
26 import os, sys, platform, time, traceback, getopt |
26 import os, sys, platform, time, traceback, getopt |
|
27 import version |
27 |
28 |
28 beremiz_dir = os.path.dirname(os.path.realpath(__file__)) |
29 beremiz_dir = os.path.dirname(os.path.realpath(__file__)) |
29 |
30 |
30 __version__ = "$Revision: 1.130 $" |
31 __version__ = "$Revision: 1.130 $" |
31 |
32 |
70 from IDEFrame import TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, PAGETITLES |
75 from IDEFrame import TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, PAGETITLES |
71 from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath |
76 from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath |
72 from editors.Viewer import Viewer |
77 from editors.Viewer import Viewer |
73 from PLCControler import PLCControler |
78 from PLCControler import PLCControler |
74 from dialogs import ProjectDialog |
79 from dialogs import ProjectDialog |
|
80 from dialogs.AboutDialog import ShowAboutDialog |
75 |
81 |
76 #------------------------------------------------------------------------------- |
82 #------------------------------------------------------------------------------- |
77 # PLCOpenEditor Main Class |
83 # PLCOpenEditor Main Class |
78 #------------------------------------------------------------------------------- |
84 #------------------------------------------------------------------------------- |
79 |
85 |
158 # @param parent The parent window. |
164 # @param parent The parent window. |
159 # @param controler The controler been used by PLCOpenEditor (default: None). |
165 # @param controler The controler been used by PLCOpenEditor (default: None). |
160 # @param fileOpen The filepath to open if no controler defined (default: None). |
166 # @param fileOpen The filepath to open if no controler defined (default: None). |
161 # @param debug The filepath to open if no controler defined (default: False). |
167 # @param debug The filepath to open if no controler defined (default: False). |
162 def __init__(self, parent, fileOpen = None): |
168 def __init__(self, parent, fileOpen = None): |
|
169 self.icon = wx.Icon(os.path.join(beremiz_dir, "images", "poe.ico"), wx.BITMAP_TYPE_ICO) |
163 IDEFrame.__init__(self, parent) |
170 IDEFrame.__init__(self, parent) |
164 |
171 |
165 result = None |
172 result = None |
166 |
173 |
167 # Open the filepath if defined |
174 # Open the filepath if defined |
176 self.ProjectTree.Enable(True) |
183 self.ProjectTree.Enable(True) |
177 self.PouInstanceVariablesPanel.SetController(controler) |
184 self.PouInstanceVariablesPanel.SetController(controler) |
178 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
185 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
179 |
186 |
180 # Define PLCOpenEditor icon |
187 # Define PLCOpenEditor icon |
181 self.SetIcon(wx.Icon(os.path.join(beremiz_dir, "images", "poe.ico"),wx.BITMAP_TYPE_ICO)) |
188 self.SetIcon(self.icon) |
182 |
189 |
183 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
190 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
184 |
191 |
185 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
192 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
186 |
193 |
187 if result is not None: |
194 if result is not None: |
188 self.ShowErrorMessage( |
195 (num, line) = result |
189 _("PLC syntax error at line %d:\n%s") % result) |
196 self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1 = num, a2 = line)) |
190 |
197 |
191 def OnCloseFrame(self, event): |
198 def OnCloseFrame(self, event): |
192 if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")): |
199 if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")): |
193 self.AUIManager.UnInit() |
200 self.AUIManager.UnInit() |
194 |
201 |
296 self._Refresh(PROJECTTREE, LIBRARYTREE) |
303 self._Refresh(PROJECTTREE, LIBRARYTREE) |
297 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
304 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
298 dialog.Destroy() |
305 dialog.Destroy() |
299 |
306 |
300 if result is not None: |
307 if result is not None: |
301 self.ShowErrorMessage( |
308 (num, line) = result |
302 _("PLC syntax error at line %d:\n%s") % result) |
309 self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1 = num, a2 = line)) |
303 |
310 |
304 def OnCloseProjectMenu(self, event): |
311 def OnCloseProjectMenu(self, event): |
305 if not self.CheckSaveBeforeClosing(): |
312 if not self.CheckSaveBeforeClosing(): |
306 return |
313 return |
307 self.ResetView() |
314 self.ResetView() |
341 |
348 |
342 def OnPLCOpenMenu(self, event): |
349 def OnPLCOpenMenu(self, event): |
343 open_pdf(os.path.join(beremiz_dir, "plcopen", "TC6_XML_V101.pdf")) |
350 open_pdf(os.path.join(beremiz_dir, "plcopen", "TC6_XML_V101.pdf")) |
344 |
351 |
345 def OnAboutMenu(self, event): |
352 def OnAboutMenu(self, event): |
346 OpenHtmlFrame(self,_("About PLCOpenEditor"), os.path.join(beremiz_dir, "doc", _("plcopen_about.html")), wx.Size(350, 350)) |
353 info = version.GetAboutDialogInfo() |
|
354 info.Name = "PLCOpenEditor" |
|
355 info.Description = _("PLCOpenEditor is part of Beremiz project.\n\n" |
|
356 "Beremiz is an ") + info.Description |
|
357 info.Icon = wx.Icon(os.path.join(beremiz_dir, "images", "aboutlogo.png"), wx.BITMAP_TYPE_PNG) |
|
358 ShowAboutDialog(self, info) |
347 |
359 |
348 def SaveProject(self): |
360 def SaveProject(self): |
349 result = self.Controler.SaveXMLFile() |
361 result = self.Controler.SaveXMLFile() |
350 if not result: |
362 if not result: |
351 self.SaveProjectAs() |
363 self.SaveProjectAs() |
392 if cap: |
404 if cap: |
393 cap.ReleaseMouse() |
405 cap.ReleaseMouse() |
394 |
406 |
395 dlg = wx.SingleChoiceDialog(None, |
407 dlg = wx.SingleChoiceDialog(None, |
396 _(""" |
408 _(""" |
397 An error has occurred. |
409 An unhandled exception (bug) occured. Bug report saved at : |
398 |
410 (%s) |
399 Click OK to save an error report. |
|
400 |
411 |
401 Please be kind enough to send this file to: |
412 Please be kind enough to send this file to: |
402 edouard.tisserant@gmail.com |
413 beremiz-devel@lists.sourceforge.net |
403 |
414 |
404 Error: |
415 You should now restart program. |
405 """) + |
416 |
406 str(e_type) + _(" : ") + str(e_value), |
417 Traceback: |
|
418 """) % bug_report_path + |
|
419 repr(e_type) + " : " + repr(e_value), |
407 _("Error"), |
420 _("Error"), |
408 trcbck_lst) |
421 trcbck_lst) |
409 try: |
422 try: |
410 res = (dlg.ShowModal() == wx.ID_OK) |
423 res = (dlg.ShowModal() == wx.ID_OK) |
411 finally: |
424 finally: |
470 |
483 |
471 #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
484 #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
472 sys.excepthook = handle_exception |
485 sys.excepthook = handle_exception |
473 |
486 |
474 if __name__ == '__main__': |
487 if __name__ == '__main__': |
475 wx.InitAllImageHandlers() |
488 if wx.VERSION < (3, 0, 0): |
|
489 wx.InitAllImageHandlers() |
476 |
490 |
477 # Install a exception handle for bug reports |
491 # Install a exception handle for bug reports |
478 AddExceptHook(os.getcwd(),__version__) |
492 AddExceptHook(os.getcwd(), version.app_version) |
479 |
493 |
480 frame = PLCOpenEditor(None, fileOpen=fileOpen) |
494 frame = PLCOpenEditor(None, fileOpen=fileOpen) |
481 |
495 |
482 frame.Show() |
496 frame.Show() |
483 app.MainLoop() |
497 app.MainLoop() |