98 return wx.GetTranslation(message).encode("utf-8") |
97 return wx.GetTranslation(message).encode("utf-8") |
99 |
98 |
100 if __name__ == '__main__': |
99 if __name__ == '__main__': |
101 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
100 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
102 |
101 |
|
102 #Quick hack to be able to find Beremiz IEC tools. Should be config params. |
|
103 base_folder = os.path.split(sys.path[0])[0] |
|
104 sys.path.append(base_folder) |
|
105 sys.path.append(os.path.join(base_folder, "plcopeneditor")) |
|
106 sys.path.append(os.path.join(base_folder, "docutils")) |
|
107 |
103 import wx.lib.buttons, wx.lib.statbmp |
108 import wx.lib.buttons, wx.lib.statbmp |
104 import TextCtrlAutoComplete, cPickle |
109 import TextCtrlAutoComplete, cPickle |
105 import types, time, re, platform, time, traceback, commands |
110 import types, time, re, platform, time, traceback, commands |
106 from plugger import PluginsRoot, MATIEC_ERROR_MODEL |
111 from plugger import PluginsRoot, MATIEC_ERROR_MODEL |
107 from wxPopen import ProcessLogger |
112 from wxPopen import ProcessLogger |
108 |
113 |
109 base_folder = os.path.split(sys.path[0])[0] |
|
110 sys.path.append(base_folder) |
|
111 from docutils import * |
114 from docutils import * |
|
115 from PLCOpenEditor import IDEFrame, Viewer, AppendMenu, TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE, SCALING |
112 |
116 |
113 SCROLLBAR_UNIT = 10 |
117 SCROLLBAR_UNIT = 10 |
114 WINDOW_COLOUR = wx.Colour(240,240,240) |
118 WINDOW_COLOUR = wx.Colour(240,240,240) |
115 TITLE_COLOUR = wx.Colour(200,200,220) |
119 TITLE_COLOUR = wx.Colour(200,200,220) |
116 CHANGED_TITLE_COLOUR = wx.Colour(220,200,220) |
120 CHANGED_TITLE_COLOUR = wx.Colour(220,200,220) |
277 |
281 |
278 [ID_BEREMIZRUNMENUBUILD, ID_BEREMIZRUNMENUSIMULATE, |
282 [ID_BEREMIZRUNMENUBUILD, ID_BEREMIZRUNMENUSIMULATE, |
279 ID_BEREMIZRUNMENURUN, ID_BEREMIZRUNMENUSAVELOG, |
283 ID_BEREMIZRUNMENURUN, ID_BEREMIZRUNMENUSAVELOG, |
280 ] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] |
284 ] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] |
281 |
285 |
282 class Beremiz(wx.Frame): |
286 class Beremiz(IDEFrame): |
283 |
287 |
284 def _init_coll_FileMenu_Items(self, parent): |
288 def _init_coll_FileMenu_Items(self, parent): |
285 parent.Append(help='', id=wx.ID_NEW, |
289 AppendMenu(parent, help='', id=wx.ID_NEW, |
286 kind=wx.ITEM_NORMAL, text=_(u'New\tCTRL+N')) |
290 kind=wx.ITEM_NORMAL, text=_(u'New\tCTRL+N')) |
287 parent.Append(help='', id=wx.ID_OPEN, |
291 AppendMenu(parent, help='', id=wx.ID_OPEN, |
288 kind=wx.ITEM_NORMAL, text=_(u'Open\tCTRL+O')) |
292 kind=wx.ITEM_NORMAL, text=_(u'Open\tCTRL+O')) |
289 parent.Append(help='', id=wx.ID_SAVE, |
293 AppendMenu(parent, help='', id=wx.ID_SAVE, |
290 kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S')) |
294 kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S')) |
291 parent.Append(help='', id=wx.ID_CLOSE_ALL, |
295 AppendMenu(parent, help='', id=wx.ID_CLOSE, |
|
296 kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W')) |
|
297 AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL, |
292 kind=wx.ITEM_NORMAL, text=_(u'Close Project')) |
298 kind=wx.ITEM_NORMAL, text=_(u'Close Project')) |
293 parent.AppendSeparator() |
299 parent.AppendSeparator() |
294 parent.Append(help='', id=wx.ID_PROPERTIES, |
300 AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP, |
|
301 kind=wx.ITEM_NORMAL, text=_(u'Page Setup')) |
|
302 AppendMenu(parent, help='', id=wx.ID_PREVIEW, |
|
303 kind=wx.ITEM_NORMAL, text=_(u'Preview')) |
|
304 AppendMenu(parent, help='', id=wx.ID_PRINT, |
|
305 kind=wx.ITEM_NORMAL, text=_(u'Print')) |
|
306 parent.AppendSeparator() |
|
307 AppendMenu(parent, help='', id=wx.ID_PROPERTIES, |
295 kind=wx.ITEM_NORMAL, text=_(u'Properties')) |
308 kind=wx.ITEM_NORMAL, text=_(u'Properties')) |
296 parent.AppendSeparator() |
309 parent.AppendSeparator() |
297 parent.Append(help='', id=wx.ID_EXIT, |
310 AppendMenu(parent, help='', id=wx.ID_EXIT, |
298 kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q')) |
311 kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q')) |
|
312 |
299 self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
313 self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
300 self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
314 self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
301 self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
315 self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
|
316 self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE) |
302 self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
317 self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
|
318 self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
|
319 self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
|
320 self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
303 self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
321 self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
304 self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
322 self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
305 |
|
306 def _init_coll_EditMenu_Items(self, parent): |
|
307 parent.Append(help='', id=wx.ID_EDIT, |
|
308 kind=wx.ITEM_NORMAL, text=_(u'Edit PLC\tCTRL+R')) |
|
309 parent.AppendSeparator() |
|
310 parent.Append(help='', id=wx.ID_ADD, |
|
311 kind=wx.ITEM_NORMAL, text=_(u'Add Plugin')) |
|
312 parent.Append(help='', id=wx.ID_DELETE, |
|
313 kind=wx.ITEM_NORMAL, text=_(u'Delete Plugin')) |
|
314 self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, id=wx.ID_EDIT) |
|
315 self.Bind(wx.EVT_MENU, self.OnAddMenu, id=wx.ID_ADD) |
|
316 self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE) |
|
317 |
|
318 def _init_coll_RunMenu_Items(self, parent): |
|
319 parent.Append(help='', id=ID_BEREMIZRUNMENUBUILD, |
|
320 kind=wx.ITEM_NORMAL, text=_(u'Build\tCTRL+R')) |
|
321 parent.AppendSeparator() |
|
322 parent.Append(help='', id=ID_BEREMIZRUNMENUSIMULATE, |
|
323 kind=wx.ITEM_NORMAL, text=_(u'Simulate')) |
|
324 parent.Append(help='', id=ID_BEREMIZRUNMENURUN, |
|
325 kind=wx.ITEM_NORMAL, text=_(u'Run')) |
|
326 parent.AppendSeparator() |
|
327 parent.Append(help='', id=ID_BEREMIZRUNMENUSAVELOG, |
|
328 kind=wx.ITEM_NORMAL, text=_(u'Save Log')) |
|
329 self.Bind(wx.EVT_MENU, self.OnBuildMenu, |
|
330 id=ID_BEREMIZRUNMENUBUILD) |
|
331 self.Bind(wx.EVT_MENU, self.OnSimulateMenu, |
|
332 id=ID_BEREMIZRUNMENUSIMULATE) |
|
333 self.Bind(wx.EVT_MENU, self.OnRunMenu, |
|
334 id=ID_BEREMIZRUNMENURUN) |
|
335 self.Bind(wx.EVT_MENU, self.OnSaveLogMenu, |
|
336 id=ID_BEREMIZRUNMENUSAVELOG) |
|
337 |
323 |
338 def _init_coll_HelpMenu_Items(self, parent): |
324 def _init_coll_HelpMenu_Items(self, parent): |
339 parent.Append(help='', id=wx.ID_HELP, |
325 parent.Append(help='', id=wx.ID_HELP, |
340 kind=wx.ITEM_NORMAL, text=_(u'Beremiz\tF1')) |
326 kind=wx.ITEM_NORMAL, text=_(u'Beremiz\tF1')) |
341 parent.Append(help='', id=wx.ID_ABOUT, |
327 parent.Append(help='', id=wx.ID_ABOUT, |
342 kind=wx.ITEM_NORMAL, text=_(u'About')) |
328 kind=wx.ITEM_NORMAL, text=_(u'About')) |
343 self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP) |
329 self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP) |
344 self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
330 self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
345 |
331 |
346 def _init_coll_MenuBar_Menus(self, parent): |
|
347 parent.Append(menu=self.FileMenu, title=_(u'File')) |
|
348 #parent.Append(menu=self.EditMenu, title=u'Edit') |
|
349 #parent.Append(menu=self.RunMenu, title=u'Run') |
|
350 parent.Append(menu=self.HelpMenu, title=_(u'Help')) |
|
351 |
|
352 def _init_utils(self): |
|
353 self.MenuBar = wx.MenuBar() |
|
354 self.FileMenu = wx.Menu(title=u'') |
|
355 #self.EditMenu = wx.Menu(title=u'') |
|
356 #self.RunMenu = wx.Menu(title=u'') |
|
357 self.HelpMenu = wx.Menu(title=u'') |
|
358 |
|
359 self._init_coll_MenuBar_Menus(self.MenuBar) |
|
360 self._init_coll_FileMenu_Items(self.FileMenu) |
|
361 #self._init_coll_EditMenu_Items(self.EditMenu) |
|
362 #self._init_coll_RunMenu_Items(self.RunMenu) |
|
363 self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
364 |
|
365 def _init_coll_PLCConfigMainSizer_Items(self, parent): |
332 def _init_coll_PLCConfigMainSizer_Items(self, parent): |
366 parent.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
333 parent.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
367 parent.AddSizer(self.PluginTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT) |
334 parent.AddSizer(self.PluginTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT) |
368 |
335 |
369 def _init_coll_PLCConfigMainSizer_Growables(self, parent): |
336 def _init_coll_PLCConfigMainSizer_Growables(self, parent): |
385 self._init_coll_PluginTreeSizer_Growables(self.PluginTreeSizer) |
352 self._init_coll_PluginTreeSizer_Growables(self.PluginTreeSizer) |
386 |
353 |
387 self.PLCConfig.SetSizer(self.PLCConfigMainSizer) |
354 self.PLCConfig.SetSizer(self.PLCConfigMainSizer) |
388 |
355 |
389 def _init_ctrls(self, prnt): |
356 def _init_ctrls(self, prnt): |
390 wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz', |
357 IDEFrame._init_ctrls(self, prnt) |
391 parent=prnt, pos=wx.Point(0, 0), size=wx.Size(1000, 600), |
358 |
392 style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=_(u'Beremiz')) |
|
393 self._init_utils() |
|
394 self.SetClientSize(wx.Size(1000, 600)) |
|
395 self.SetMenuBar(self.MenuBar) |
|
396 self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated) |
|
397 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
|
398 |
|
399 self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR) |
359 self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR) |
400 accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), ID_BEREMIZINSPECTOR)]) |
360 accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), ID_BEREMIZINSPECTOR)]) |
401 self.SetAcceleratorTable(accel) |
361 self.SetAcceleratorTable(accel) |
402 |
362 |
403 if wx.VERSION < (2, 8, 0): |
|
404 self.MainSplitter = wx.SplitterWindow(id=ID_BEREMIZMAINSPLITTER, |
|
405 name='MainSplitter', parent=self, point=wx.Point(0, 0), |
|
406 size=wx.Size(0, 0), style=wx.SP_3D) |
|
407 self.MainSplitter.SetNeedUpdating(True) |
|
408 self.MainSplitter.SetMinimumPaneSize(1) |
|
409 |
|
410 parent = self.MainSplitter |
|
411 else: |
|
412 parent = self |
|
413 |
|
414 self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG, |
363 self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG, |
415 name='PLCConfig', parent=parent, pos=wx.Point(0, 0), |
364 name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0), |
416 size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL) |
365 size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL) |
417 self.PLCConfig.SetBackgroundColour(wx.WHITE) |
366 self.PLCConfig.SetBackgroundColour(wx.WHITE) |
418 self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
367 self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
419 self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
368 self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
|
369 self.LeftNoteBook.AddPage(self.PLCConfig, _("Topology")) |
420 |
370 |
421 self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
371 self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
422 name='LogConsole', parent=parent, pos=wx.Point(0, 0), |
372 name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0), |
423 size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) |
373 size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) |
424 self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick) |
374 self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick) |
425 |
375 self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console")) |
426 if wx.VERSION < (2, 8, 0): |
376 |
427 self.MainSplitter.SplitHorizontally(self.PLCConfig, self.LogConsole, -250) |
377 self._init_beremiz_sizers() |
428 else: |
378 |
429 self.AUIManager = wx.aui.AuiManager(self) |
379 def __init__(self, parent, projectOpen, buildpath, debug=True): |
430 self.AUIManager.SetDockSizeConstraint(0.5, 0.5) |
380 IDEFrame.__init__(self, parent, debug) |
431 |
381 self.Config = wx.ConfigBase.Get() |
432 self.AUIManager.AddPane(self.PLCConfig, wx.aui.AuiPaneInfo().CenterPane()) |
|
433 |
|
434 self.AUIManager.AddPane(self.LogConsole, wx.aui.AuiPaneInfo(). |
|
435 Caption(_("Log Console")).Bottom().Layer(1). |
|
436 BestSize(wx.Size(800, 200)).CloseButton(False)) |
|
437 |
|
438 self.AUIManager.Update() |
|
439 |
|
440 self._init_sizers() |
|
441 |
|
442 def __init__(self, parent, projectOpen, buildpath): |
|
443 self._init_ctrls(parent) |
|
444 |
382 |
445 self.Log = LogPseudoFile(self.LogConsole) |
383 self.Log = LogPseudoFile(self.LogConsole) |
446 |
384 |
447 self.local_runtime = None |
385 self.local_runtime = None |
448 self.runtime_port = None |
386 self.runtime_port = None |
449 self.local_runtime_tmpdir = None |
387 self.local_runtime_tmpdir = None |
450 |
388 |
451 # Add beremiz's icon in top left corner of the frame |
|
452 self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO)) |
|
453 |
|
454 self.DisableEvents = False |
389 self.DisableEvents = False |
455 |
390 |
456 self.PluginInfos = {} |
391 self.PluginInfos = {} |
457 |
392 |
458 if projectOpen: |
393 if projectOpen: |
459 self.PluginRoot = PluginsRoot(self, self.Log) |
394 self.PluginRoot = PluginsRoot(self, self.Log) |
|
395 self.Controler = self.PluginRoot |
460 self.PluginRoot.LoadProject(projectOpen, buildpath) |
396 self.PluginRoot.LoadProject(projectOpen, buildpath) |
|
397 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE) |
461 self.RefreshAll() |
398 self.RefreshAll() |
462 else: |
399 else: |
463 self.PluginRoot = None |
400 self.PluginRoot = None |
464 |
401 self.Controler = None |
465 self.RefreshMainMenu() |
402 |
|
403 # Add beremiz's icon in top left corner of the frame |
|
404 self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO)) |
|
405 |
|
406 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
|
407 |
|
408 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
|
409 |
|
410 def RefreshTitle(self): |
|
411 name = _("Beremiz") |
|
412 if self.PluginRoot is not None: |
|
413 self.SetTitle("%s - %s"%(name, self.PluginRoot.GetProjectName())) |
|
414 else: |
|
415 self.SetTitle(name) |
466 |
416 |
467 def StartLocalRuntime(self, taskbaricon = True): |
417 def StartLocalRuntime(self, taskbaricon = True): |
468 if self.local_runtime is None or self.local_runtime.finished: |
418 if self.local_runtime is None or self.local_runtime.finished: |
469 # create temporary directory for runtime working directory |
419 # create temporary directory for runtime working directory |
470 self.local_runtime_tmpdir = tempfile.mkdtemp() |
420 self.local_runtime_tmpdir = tempfile.mkdtemp() |
542 def OnMoveWindow(self, event): |
492 def OnMoveWindow(self, event): |
543 self.GetBestSize() |
493 self.GetBestSize() |
544 self.RefreshScrollBars() |
494 self.RefreshScrollBars() |
545 event.Skip() |
495 event.Skip() |
546 |
496 |
547 def OnFrameActivated(self, event): |
|
548 if not event.GetActive() and self.PluginRoot is not None: |
|
549 self.PluginRoot.RefreshPluginsBlockLists() |
|
550 |
|
551 def OnPanelLeftDown(self, event): |
497 def OnPanelLeftDown(self, event): |
552 focused = self.FindFocus() |
498 focused = self.FindFocus() |
553 if isinstance(focused, TextCtrlAutoComplete.TextCtrlAutoComplete): |
499 if isinstance(focused, TextCtrlAutoComplete.TextCtrlAutoComplete): |
554 focused._showDropDown(False) |
500 focused._showDropDown(False) |
555 event.Skip() |
501 event.Skip() |
556 |
502 |
557 def RefreshMainMenu(self): |
503 def RefreshFileMenu(self): |
558 if self.PluginRoot is not None: |
504 if self.PluginRoot is not None: |
559 ## self.MenuBar.EnableTop(1, True) |
505 selected = self.TabsOpened.GetSelection() |
560 ## self.MenuBar.EnableTop(2, True) |
506 if selected >= 0: |
|
507 graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
|
508 else: |
|
509 graphic_viewer = False |
|
510 if self.TabsOpened.GetPageCount() > 0: |
|
511 self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
512 if graphic_viewer: |
|
513 self.FileMenu.Enable(wx.ID_PREVIEW, True) |
|
514 self.FileMenu.Enable(wx.ID_PRINT, True) |
|
515 else: |
|
516 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
517 self.FileMenu.Enable(wx.ID_PRINT, False) |
|
518 else: |
|
519 self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
520 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
521 self.FileMenu.Enable(wx.ID_PRINT, False) |
|
522 self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
561 self.FileMenu.Enable(wx.ID_SAVE, True) |
523 self.FileMenu.Enable(wx.ID_SAVE, True) |
|
524 self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
562 self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
525 self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
563 self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
526 self.FileMenu.Enable(wx.ID_SAVEAS, True) |
564 else: |
527 else: |
565 ## self.MenuBar.EnableTop(1, False) |
528 self.FileMenu.Enable(wx.ID_CLOSE, False) |
566 ## self.MenuBar.EnableTop(2, False) |
529 self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
|
530 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
531 self.FileMenu.Enable(wx.ID_PRINT, False) |
567 self.FileMenu.Enable(wx.ID_SAVE, False) |
532 self.FileMenu.Enable(wx.ID_SAVE, False) |
|
533 self.FileMenu.Enable(wx.ID_PROPERTIES, False) |
568 self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
534 self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
569 self.FileMenu.Enable(wx.ID_PROPERTIES, False) |
535 self.FileMenu.Enable(wx.ID_SAVEAS, False) |
570 |
536 |
571 def RefreshScrollBars(self): |
537 def RefreshScrollBars(self): |
572 xstart, ystart = self.PLCConfig.GetViewStart() |
538 xstart, ystart = self.PLCConfig.GetViewStart() |
573 window_size = self.PLCConfig.GetClientSize() |
539 window_size = self.PLCConfig.GetClientSize() |
574 sizer = self.PLCConfig.GetSizer() |
540 sizer = self.PLCConfig.GetSizer() |
1239 textctrl.ChangeValue(str(element_infos["value"])) |
1205 textctrl.ChangeValue(str(element_infos["value"])) |
1240 textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path)) |
1206 textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path)) |
1241 first = False |
1207 first = False |
1242 |
1208 |
1243 def OnNewProjectMenu(self, event): |
1209 def OnNewProjectMenu(self, event): |
1244 if not config.HasEntry("lastopenedfolder"): |
1210 if not self.Config.HasEntry("lastopenedfolder"): |
1245 defaultpath = os.path.expanduser("~") |
1211 defaultpath = os.path.expanduser("~") |
1246 else: |
1212 else: |
1247 defaultpath = config.Read("lastopenedfolder") |
1213 defaultpath = self.Config.Read("lastopenedfolder") |
1248 |
1214 |
1249 dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) |
1215 dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) |
1250 if dialog.ShowModal() == wx.ID_OK: |
1216 if dialog.ShowModal() == wx.ID_OK: |
1251 projectpath = dialog.GetPath() |
1217 projectpath = dialog.GetPath() |
1252 dialog.Destroy() |
1218 dialog.Destroy() |
1253 config.Write("lastopenedfolder", os.path.dirname(projectpath)) |
1219 self.Config.Write("lastopenedfolder", os.path.dirname(projectpath)) |
1254 config.Flush() |
1220 self.Config.Flush() |
1255 self.PluginInfos = {} |
1221 self.PluginInfos = {} |
1256 if self.PluginRoot is not None: |
|
1257 self.PluginRoot.CloseProject() |
|
1258 self.PluginRoot = PluginsRoot(self, self.Log) |
1222 self.PluginRoot = PluginsRoot(self, self.Log) |
1259 res = self.PluginRoot.NewProject(projectpath) |
1223 self.Controler = self.PluginRoot |
1260 if not res : |
1224 result = self.PluginRoot.NewProject(projectpath) |
|
1225 if not result: |
|
1226 self.DebugVariablePanel.SetDataProducer(self.PluginRoot) |
|
1227 self._Refresh(TITLE, FILEMENU, EDITMENU, TYPESTREE, INSTANCESTREE, |
|
1228 LIBRARYTREE) |
1261 self.RefreshAll() |
1229 self.RefreshAll() |
1262 self.RefreshMainMenu() |
|
1263 else: |
1230 else: |
1264 message = wx.MessageDialog(self, res, _("ERROR"), wx.OK|wx.ICON_ERROR) |
1231 self.ShowErrorMessage(result) |
1265 message.ShowModal() |
|
1266 message.Destroy() |
|
1267 event.Skip() |
1232 event.Skip() |
1268 |
1233 |
1269 def OnOpenProjectMenu(self, event): |
1234 def OnOpenProjectMenu(self, event): |
1270 if not config.HasEntry("lastopenedfolder"): |
1235 if not self.Config.HasEntry("lastopenedfolder"): |
1271 defaultpath = os.path.expanduser("~") |
1236 defaultpath = os.path.expanduser("~") |
1272 else: |
1237 else: |
1273 defaultpath = config.Read("lastopenedfolder") |
1238 defaultpath = self.Config.Read("lastopenedfolder") |
1274 |
1239 |
1275 dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) |
1240 dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) |
1276 if dialog.ShowModal() == wx.ID_OK: |
1241 if dialog.ShowModal() == wx.ID_OK: |
1277 projectpath = dialog.GetPath() |
1242 projectpath = dialog.GetPath() |
1278 if os.path.isdir(projectpath): |
1243 if os.path.isdir(projectpath): |
1279 config.Write("lastopenedfolder", os.path.dirname(projectpath)) |
1244 self.Config.Write("lastopenedfolder", os.path.dirname(projectpath)) |
1280 config.Flush() |
1245 self.Config.Flush() |
1281 self.PluginInfos = {} |
1246 self.PluginInfos = {} |
1282 if self.PluginRoot is not None: |
|
1283 self.PluginRoot.CloseProject() |
|
1284 self.PluginRoot = PluginsRoot(self, self.Log) |
1247 self.PluginRoot = PluginsRoot(self, self.Log) |
|
1248 self.Controler = self.PluginRoot |
1285 result = self.PluginRoot.LoadProject(projectpath) |
1249 result = self.PluginRoot.LoadProject(projectpath) |
1286 if not result: |
1250 if not result: |
|
1251 self.DebugVariablePanel.SetDataProducer(self.PluginRoot) |
|
1252 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE) |
1287 self.RefreshAll() |
1253 self.RefreshAll() |
1288 self.RefreshMainMenu() |
|
1289 else: |
1254 else: |
1290 message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
1255 self.ShowErrorMessage(result) |
1291 message.ShowModal() |
|
1292 message.Destroy() |
|
1293 else: |
1256 else: |
1294 message = wx.MessageDialog(self, _("\"%s\" folder is not a valid Beremiz project\n")%projectpath, _("Error"), wx.OK|wx.ICON_ERROR) |
1257 self.ShowErrorMessage(_("\"%s\" folder is not a valid Beremiz project\n") % projectpath) |
1295 message.ShowModal() |
1258 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU) |
1296 message.Destroy() |
|
1297 dialog.Destroy() |
1259 dialog.Destroy() |
1298 event.Skip() |
1260 event.Skip() |
1299 |
1261 |
1300 def OnCloseProjectMenu(self, event): |
1262 def OnCloseProjectMenu(self, event): |
1301 if self.PluginRoot is not None: |
1263 if self.PluginRoot is not None: |
1309 if answer == wx.ID_YES: |
1271 if answer == wx.ID_YES: |
1310 self.PluginRoot.SaveProject() |
1272 self.PluginRoot.SaveProject() |
1311 elif answer == wx.ID_CANCEL: |
1273 elif answer == wx.ID_CANCEL: |
1312 return |
1274 return |
1313 self.PluginInfos = {} |
1275 self.PluginInfos = {} |
1314 self.PluginRoot.CloseProject() |
|
1315 self.PluginRoot = None |
1276 self.PluginRoot = None |
1316 self.Log.flush() |
1277 self.Log.flush() |
|
1278 self.DeleteAllPages() |
|
1279 self.VariablePanelIndexer.RemoveAllPanels() |
|
1280 self.TypesTree.DeleteAllItems() |
|
1281 self.InstancesTree.DeleteAllItems() |
|
1282 self.LibraryTree.DeleteAllItems() |
|
1283 self.Controler = None |
|
1284 self.DebugVariablePanel.SetDataProducer(None) |
|
1285 self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU) |
1317 self.RefreshAll() |
1286 self.RefreshAll() |
1318 self.RefreshMainMenu() |
|
1319 event.Skip() |
1287 event.Skip() |
1320 |
1288 |
1321 def OnSaveProjectMenu(self, event): |
1289 def OnSaveProjectMenu(self, event): |
1322 if self.PluginRoot is not None: |
1290 if self.PluginRoot is not None: |
1323 self.PluginRoot.SaveProject() |
1291 self.PluginRoot.SaveProject() |
1324 self.RefreshAll() |
1292 self.RefreshAll() |
|
1293 self.RefreshTitle() |
1325 event.Skip() |
1294 event.Skip() |
1326 |
1295 |
1327 def OnPropertiesMenu(self, event): |
1296 def OnPropertiesMenu(self, event): |
1328 event.Skip() |
1297 event.Skip() |
1329 |
1298 |
1330 def OnQuitMenu(self, event): |
1299 def OnQuitMenu(self, event): |
1331 self.Close() |
1300 self.Close() |
1332 event.Skip() |
1301 event.Skip() |
1333 |
1302 |
1334 def OnEditPLCMenu(self, event): |
|
1335 self.EditPLC() |
|
1336 event.Skip() |
|
1337 |
|
1338 def OnAddMenu(self, event): |
|
1339 self.AddPlugin() |
|
1340 event.Skip() |
|
1341 |
|
1342 def OnDeleteMenu(self, event): |
|
1343 self.DeletePlugin() |
|
1344 event.Skip() |
|
1345 |
|
1346 def OnBuildMenu(self, event): |
|
1347 #self.BuildAutom() |
|
1348 event.Skip() |
|
1349 |
|
1350 def OnSimulateMenu(self, event): |
|
1351 event.Skip() |
|
1352 |
|
1353 def OnRunMenu(self, event): |
|
1354 event.Skip() |
|
1355 |
|
1356 def OnSaveLogMenu(self, event): |
|
1357 event.Skip() |
|
1358 |
|
1359 def OnBeremizMenu(self, event): |
1303 def OnBeremizMenu(self, event): |
1360 open_pdf(Bpath( "doc", "manual_beremiz.pdf")) |
1304 open_pdf(Bpath( "doc", "manual_beremiz.pdf")) |
1361 event.Skip() |
1305 event.Skip() |
1362 |
1306 |
1363 def OnAboutMenu(self, event): |
1307 def OnAboutMenu(self, event): |
1364 OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc","about.html"), wx.Size(550, 500)) |
1308 OpenHtmlFrame(self,_("About Beremiz"), Bpath("doc","about.html"), wx.Size(550, 500)) |
1365 event.Skip() |
|
1366 |
|
1367 def OnAddButton(self, event): |
|
1368 PluginType = self.PluginChilds.GetStringSelection() |
|
1369 if PluginType != "": |
|
1370 self.AddPlugin(PluginType) |
|
1371 event.Skip() |
|
1372 |
|
1373 def OnDeleteButton(self, event): |
|
1374 self.DeletePlugin() |
|
1375 event.Skip() |
1309 event.Skip() |
1376 |
1310 |
1377 def GetAddButtonFunction(self, plugin, window): |
1311 def GetAddButtonFunction(self, plugin, window): |
1378 def AddButtonFunction(event): |
1312 def AddButtonFunction(event): |
1379 if plugin and len(plugin.PlugChildsTypes) > 0: |
1313 if plugin and len(plugin.PlugChildsTypes) > 0: |