26 |
26 |
27 from __future__ import absolute_import |
27 from __future__ import absolute_import |
28 from __future__ import print_function |
28 from __future__ import print_function |
29 import os |
29 import os |
30 import sys |
30 import sys |
31 import tempfile |
|
32 import shutil |
31 import shutil |
33 import random |
|
34 import time |
32 import time |
35 from time import time as gettime |
33 from time import time as gettime |
36 from threading import Lock, Timer, currentThread |
34 from threading import Lock, Timer, currentThread |
37 |
35 |
38 from six.moves import cPickle, xrange |
36 from six.moves import cPickle, xrange |
45 from editors.EditorPanel import EditorPanel |
43 from editors.EditorPanel import EditorPanel |
46 from editors.Viewer import Viewer |
44 from editors.Viewer import Viewer |
47 from editors.TextViewer import TextViewer |
45 from editors.TextViewer import TextViewer |
48 from editors.ResourceEditor import ConfigurationEditor, ResourceEditor |
46 from editors.ResourceEditor import ConfigurationEditor, ResourceEditor |
49 from editors.DataTypeEditor import DataTypeEditor |
47 from editors.DataTypeEditor import DataTypeEditor |
50 from util import paths as paths |
48 from util.paths import Bpath |
51 from util.MiniTextControler import MiniTextControler |
49 from util.MiniTextControler import MiniTextControler |
52 from util.ProcessLogger import ProcessLogger |
|
53 from util.BitmapLibrary import GetBitmap |
50 from util.BitmapLibrary import GetBitmap |
54 from controls.LogViewer import LogViewer |
51 from controls.LogViewer import LogViewer |
55 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl |
52 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl |
56 from controls import EnhancedStatusBar as esb |
53 from controls import EnhancedStatusBar as esb |
57 from dialogs.AboutDialog import ShowAboutDialog |
54 from dialogs.AboutDialog import ShowAboutDialog |
82 PAGETITLES,\ |
79 PAGETITLES,\ |
83 IDEFrame, \ |
80 IDEFrame, \ |
84 EncodeFileSystemPath, \ |
81 EncodeFileSystemPath, \ |
85 DecodeFileSystemPath |
82 DecodeFileSystemPath |
86 |
83 |
87 |
84 from LocalRuntimeMixin import LocalRuntimeMixin |
88 beremiz_dir = paths.AbsDir(__file__) |
85 |
89 |
|
90 |
|
91 def Bpath(*args): |
|
92 return os.path.join(beremiz_dir, *args) |
|
93 |
86 |
94 def AppendMenu(parent, help, id, kind, text): |
87 def AppendMenu(parent, help, id, kind, text): |
95 return parent.Append(wx.MenuItem(helpString=help, id=id, kind=kind, text=text)) |
88 return parent.Append(wx.MenuItem(helpString=help, id=id, kind=kind, text=text)) |
96 |
89 |
97 MAX_RECENT_PROJECTS = 9 |
90 MAX_RECENT_PROJECTS = 9 |
238 |
231 |
239 |
232 |
240 ID_FILEMENURECENTPROJECTS = wx.NewId() |
233 ID_FILEMENURECENTPROJECTS = wx.NewId() |
241 |
234 |
242 |
235 |
243 class Beremiz(IDEFrame): |
236 class Beremiz(IDEFrame, LocalRuntimeMixin): |
244 |
237 |
245 def _init_utils(self): |
238 def _init_utils(self): |
246 self.ConfNodeMenu = wx.Menu(title='') |
239 self.ConfNodeMenu = wx.Menu(title='') |
247 self.RecentProjectsMenu = wx.Menu(title='') |
240 self.RecentProjectsMenu = wx.Menu(title='') |
248 self.TutorialsProjectsMenu = wx.Menu(title='') |
241 self.TutorialsProjectsMenu = wx.Menu(title='') |
449 # commands invoked by build process by default are |
442 # commands invoked by build process by default are |
450 # found here. |
443 # found here. |
451 os.environ["PATH"] = os.getcwd()+';'+os.environ["PATH"] |
444 os.environ["PATH"] = os.getcwd()+';'+os.environ["PATH"] |
452 |
445 |
453 def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True, logf=None): |
446 def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True, logf=None): |
|
447 LocalRuntimeMixin.__init__(self) |
|
448 |
454 # Add beremiz's icon in top left corner of the frame |
449 # Add beremiz's icon in top left corner of the frame |
455 self.icon = wx.Icon(Bpath("images", "brz.ico"), wx.BITMAP_TYPE_ICO) |
450 self.icon = wx.Icon(Bpath("images", "brz.ico"), wx.BITMAP_TYPE_ICO) |
456 self.__init_execute_path() |
451 self.__init_execute_path() |
457 |
452 |
458 IDEFrame.__init__(self, parent, debug) |
453 IDEFrame.__init__(self, parent, debug) |
459 self.Log = LogPseudoFile(self.LogConsole, self.SelectTab, logf) |
454 self.Log = LogPseudoFile(self.LogConsole, self.SelectTab, logf) |
460 |
|
461 self.local_runtime = None |
|
462 self.runtime_port = None |
|
463 self.local_runtime_tmpdir = None |
|
464 |
455 |
465 self.LastPanelSelected = None |
456 self.LastPanelSelected = None |
466 |
457 |
467 # Define Tree item icon list |
458 # Define Tree item icon list |
468 self.LocationImageList = wx.ImageList(16, 16) |
459 self.LocationImageList = wx.ImageList(16, 16) |
522 if self.CTR.ProjectTestModified(): |
513 if self.CTR.ProjectTestModified(): |
523 projectname = "~%s~" % projectname |
514 projectname = "~%s~" % projectname |
524 self.SetTitle("%s - %s" % (name, projectname)) |
515 self.SetTitle("%s - %s" % (name, projectname)) |
525 else: |
516 else: |
526 self.SetTitle(name) |
517 self.SetTitle(name) |
527 |
|
528 def StartLocalRuntime(self, taskbaricon=True): |
|
529 if (self.local_runtime is None) or (self.local_runtime.exitcode is not None): |
|
530 # create temporary directory for runtime working directory |
|
531 self.local_runtime_tmpdir = tempfile.mkdtemp() |
|
532 # choose an arbitrary random port for runtime |
|
533 self.runtime_port = int(random.random() * 1000) + 61131 |
|
534 self.Log.write(_("Starting local runtime...\n")) |
|
535 # launch local runtime |
|
536 self.local_runtime = ProcessLogger( |
|
537 self.Log, |
|
538 "\"%s\" \"%s\" -p %s -i localhost %s %s" % ( |
|
539 sys.executable, |
|
540 Bpath("Beremiz_service.py"), |
|
541 self.runtime_port, |
|
542 {False: "-x 0", True: "-x 1"}[taskbaricon], |
|
543 self.local_runtime_tmpdir), |
|
544 no_gui=False, |
|
545 timeout=500, keyword=self.local_runtime_tmpdir, |
|
546 cwd=self.local_runtime_tmpdir) |
|
547 self.local_runtime.spin() |
|
548 return self.runtime_port |
|
549 |
|
550 def KillLocalRuntime(self): |
|
551 if self.local_runtime is not None: |
|
552 # shutdown local runtime |
|
553 self.local_runtime.kill(gently=False) |
|
554 # clear temp dir |
|
555 shutil.rmtree(self.local_runtime_tmpdir) |
|
556 |
|
557 self.local_runtime = None |
|
558 |
518 |
559 def OnOpenWidgetInspector(self, evt): |
519 def OnOpenWidgetInspector(self, evt): |
560 # Activate the widget inspection tool |
520 # Activate the widget inspection tool |
561 from wx.lib.inspection import InspectionTool |
521 from wx.lib.inspection import InspectionTool |
562 if not InspectionTool().initialized: |
522 if not InspectionTool().initialized: |