changeset 714 | 131ea7f237b9 |
parent 712 | c11b54730a7b |
child 718 | 0183a66eddf9 |
713:95a0a427f3ef | 714:131ea7f237b9 |
---|---|
29 import cPickle |
29 import cPickle |
30 |
30 |
31 CWD = os.path.split(os.path.realpath(__file__))[0] |
31 CWD = os.path.split(os.path.realpath(__file__))[0] |
32 base_folder = os.path.split(CWD)[0] |
32 base_folder = os.path.split(CWD)[0] |
33 sys.path.append(base_folder) |
33 sys.path.append(base_folder) |
34 |
|
35 from utils.BitmapLibrary import AddBitmapFolder, GetBitmap |
|
36 AddBitmapFolder(os.path.join(CWD, "Images")) |
|
37 |
|
34 from docutil import * |
38 from docutil import * |
35 |
39 |
36 from types import TupleType |
40 from types import TupleType |
37 |
41 |
38 __version__ = "$Revision: 1.130 $" |
42 __version__ = "$Revision: 1.130 $" |
163 # - Item icon filename |
167 # - Item icon filename |
164 # - Item tooltip text |
168 # - Item tooltip text |
165 EditorToolBarItems = { |
169 EditorToolBarItems = { |
166 "FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
170 "FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
167 ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
171 ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
168 "move.png", _("Move the view")), |
172 "move", _("Move the view")), |
169 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
173 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
170 ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
174 ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
171 "add_comment.png", _("Create a new comment")), |
175 "add_comment", _("Create a new comment")), |
172 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
176 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
173 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
177 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
174 "add_variable.png", _("Create a new variable")), |
178 "add_variable", _("Create a new variable")), |
175 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
179 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
176 ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
180 ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
177 "add_block.png", _("Create a new block")), |
181 "add_block", _("Create a new block")), |
178 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
182 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
179 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
183 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
180 "add_connection.png", _("Create a new connection"))], |
184 "add_connection", _("Create a new connection"))], |
181 "LD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
185 "LD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
182 ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
186 ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
183 "move.png", _("Move the view")), |
187 "move", _("Move the view")), |
184 (True, FREEDRAWING_MODE, |
188 (True, FREEDRAWING_MODE, |
185 ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
189 ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
186 "add_comment.png", _("Create a new comment")), |
190 "add_comment", _("Create a new comment")), |
187 (True, FREEDRAWING_MODE, |
191 (True, FREEDRAWING_MODE, |
188 ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", |
192 ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", |
189 "add_powerrail.png", _("Create a new power rail")), |
193 "add_powerrail", _("Create a new power rail")), |
190 (False, DRIVENDRAWING_MODE, |
194 (False, DRIVENDRAWING_MODE, |
191 ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool", |
195 ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool", |
192 "add_rung.png", _("Create a new rung")), |
196 "add_rung", _("Create a new rung")), |
193 (True, FREEDRAWING_MODE, |
197 (True, FREEDRAWING_MODE, |
194 ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool", |
198 ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool", |
195 "add_coil.png", _("Create a new coil")), |
199 "add_coil", _("Create a new coil")), |
196 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
200 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
197 ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", |
201 ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", |
198 "add_contact.png", _("Create a new contact")), |
202 "add_contact", _("Create a new contact")), |
199 (False, DRIVENDRAWING_MODE, |
203 (False, DRIVENDRAWING_MODE, |
200 ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool", |
204 ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool", |
201 "add_branch.png", _("Create a new branch")), |
205 "add_branch", _("Create a new branch")), |
202 (True, FREEDRAWING_MODE, |
206 (True, FREEDRAWING_MODE, |
203 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
207 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
204 "add_variable.png", _("Create a new variable")), |
208 "add_variable", _("Create a new variable")), |
205 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
209 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
206 ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
210 ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
207 "add_block.png", _("Create a new block")), |
211 "add_block", _("Create a new block")), |
208 (True, FREEDRAWING_MODE, |
212 (True, FREEDRAWING_MODE, |
209 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
213 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
210 "add_connection.png", _("Create a new connection"))], |
214 "add_connection", _("Create a new connection"))], |
211 "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
215 "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
212 ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
216 ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
213 "move.png", _("Move the view")), |
217 "move", _("Move the view")), |
214 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
218 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
215 ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
219 ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", |
216 "add_comment.png", _("Create a new comment")), |
220 "add_comment", _("Create a new comment")), |
217 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
221 (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
218 ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool", |
222 ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool", |
219 "add_initial_step.png", _("Create a new initial step")), |
223 "add_initial_step", _("Create a new initial step")), |
220 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
224 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
221 ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool", |
225 ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool", |
222 "add_step.png", _("Create a new step")), |
226 "add_step", _("Create a new step")), |
223 (True, FREEDRAWING_MODE, |
227 (True, FREEDRAWING_MODE, |
224 ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool", |
228 ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool", |
225 "add_transition.png", _("Create a new transition")), |
229 "add_transition", _("Create a new transition")), |
226 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
230 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
227 ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", |
231 ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", |
228 "add_action.png", _("Create a new action block")), |
232 "add_action", _("Create a new action block")), |
229 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
233 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
230 ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool", |
234 ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool", |
231 "add_divergence.png", _("Create a new divergence")), |
235 "add_divergence", _("Create a new divergence")), |
232 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
236 (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
233 ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool", |
237 ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool", |
234 "add_jump.png", _("Create a new jump")), |
238 "add_jump", _("Create a new jump")), |
235 (True, FREEDRAWING_MODE, |
239 (True, FREEDRAWING_MODE, |
236 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
240 ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", |
237 "add_variable.png", _("Create a new variable")), |
241 "add_variable", _("Create a new variable")), |
238 (True, FREEDRAWING_MODE, |
242 (True, FREEDRAWING_MODE, |
239 ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
243 ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", |
240 "add_block.png", _("Create a new block")), |
244 "add_block", _("Create a new block")), |
241 (True, FREEDRAWING_MODE, |
245 (True, FREEDRAWING_MODE, |
242 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
246 ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", |
243 "add_connection.png", _("Create a new connection")), |
247 "add_connection", _("Create a new connection")), |
244 (True, FREEDRAWING_MODE, |
248 (True, FREEDRAWING_MODE, |
245 ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", |
249 ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", |
246 "add_powerrail.png", _("Create a new power rail")), |
250 "add_powerrail", _("Create a new power rail")), |
247 (True, FREEDRAWING_MODE, |
251 (True, FREEDRAWING_MODE, |
248 ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", |
252 ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", |
249 "add_contact.png", _("Create a new contact"))], |
253 "add_contact", _("Create a new contact"))], |
250 "ST" : [], |
254 "ST" : [], |
251 "IL" : [], |
255 "IL" : [], |
252 "debug": [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
256 "debug": [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, |
253 ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
257 ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool", |
254 "move.png", _("Move the view"))], |
258 "move", _("Move the view"))], |
255 } |
259 } |
256 |
260 |
257 #------------------------------------------------------------------------------- |
261 #------------------------------------------------------------------------------- |
258 # Helper Functions |
262 # Helper Functions |
259 #------------------------------------------------------------------------------- |
263 #------------------------------------------------------------------------------- |
458 self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, |
462 self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, |
459 id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION) |
463 id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION) |
460 self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL) |
464 self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL) |
461 self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE) |
465 self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE) |
462 |
466 |
463 self.AddToMenuToolBar([(wx.ID_UNDO, "undo.png", _(u'Undo'), None), |
467 self.AddToMenuToolBar([(wx.ID_UNDO, "undo", _(u'Undo'), None), |
464 (wx.ID_REDO, "redo.png", _(u'Redo'), None), |
468 (wx.ID_REDO, "redo", _(u'Redo'), None), |
465 None, |
469 None, |
466 (wx.ID_CUT, "cut.png", _(u'Cut'), None), |
470 (wx.ID_CUT, "cut", _(u'Cut'), None), |
467 (wx.ID_COPY, "copy.png", _(u'Copy'), None), |
471 (wx.ID_COPY, "copy", _(u'Copy'), None), |
468 (wx.ID_PASTE, "paste.png", _(u'Paste'), None), |
472 (wx.ID_PASTE, "paste", _(u'Paste'), None), |
469 None, |
473 None, |
470 (ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find.png", _(u'Search in Project'), None)]) |
474 (ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find", _(u'Search in Project'), None)]) |
471 |
475 |
472 def _init_coll_DisplayMenu_Items(self, parent): |
476 def _init_coll_DisplayMenu_Items(self, parent): |
473 AppendMenu(parent, help='', id=wx.ID_REFRESH, |
477 AppendMenu(parent, help='', id=wx.ID_REFRESH, |
474 kind=wx.ITEM_NORMAL, text=_(u'Refresh\tCTRL+R')) |
478 kind=wx.ITEM_NORMAL, text=_(u'Refresh\tCTRL+R')) |
475 if self.EnableDebug: |
479 if self.EnableDebug: |
584 |
588 |
585 self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE, |
589 self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE, |
586 name='ProjectTree', parent=self.ProjectPanel, |
590 name='ProjectTree', parent=self.ProjectPanel, |
587 pos=wx.Point(0, 0), size=wx.Size(0, 0), |
591 pos=wx.Point(0, 0), size=wx.Size(0, 0), |
588 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_EDIT_LABELS) |
592 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_EDIT_LABELS) |
589 self.ProjectTree.SetBackgroundBitmap(wx.Bitmap(os.path.join(CWD, 'Images', 'custom_tree_background.png')), |
593 self.ProjectTree.SetBackgroundBitmap(GetBitmap("custom_tree_background"), |
590 wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM) |
594 wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM) |
591 add_menu = wx.Menu() |
595 add_menu = wx.Menu() |
592 self._init_coll_AddMenu_Items(add_menu) |
596 self._init_coll_AddMenu_Items(add_menu) |
593 self.ProjectTree.SetAddMenu(add_menu) |
597 self.ProjectTree.SetAddMenu(add_menu) |
594 if wx.Platform == '__WXMSW__': |
598 if wx.Platform == '__WXMSW__': |
637 |
641 |
638 EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize, |
642 EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize, |
639 wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER) |
643 wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER) |
640 EditorToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
644 EditorToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
641 EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, |
645 EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, |
642 wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, _("Select an object")) |
646 GetBitmap("select"), wx.NullBitmap, _("Select an object")) |
643 EditorToolBar.Realize() |
647 EditorToolBar.Realize() |
644 self.Panes["EditorToolBar"] = EditorToolBar |
648 self.Panes["EditorToolBar"] = EditorToolBar |
645 self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo(). |
649 self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo(). |
646 Name("EditorToolBar").Caption(_("Editor ToolBar")). |
650 Name("EditorToolBar").Caption(_("Editor ToolBar")). |
647 ToolbarPane().Top().Position(1). |
651 ToolbarPane().Top().Position(1). |
668 |
672 |
669 self._init_utils() |
673 self._init_utils() |
670 self.SetMenuBar(self.MenuBar) |
674 self.SetMenuBar(self.MenuBar) |
671 |
675 |
672 if self.EnableDebug: |
676 if self.EnableDebug: |
673 self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self, self.Controler) |
677 self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self.Controler) |
674 self.MainTabs["DebugVariablePanel"] = (self.DebugVariablePanel, _("Debugger")) |
678 self.MainTabs["DebugVariablePanel"] = (self.DebugVariablePanel, _("Debugger")) |
675 self.RightNoteBook.AddPage(*self.MainTabs["DebugVariablePanel"]) |
679 self.RightNoteBook.AddPage(*self.MainTabs["DebugVariablePanel"]) |
676 |
680 |
677 self.AUIManager.Update() |
681 self.AUIManager.Update() |
678 |
682 |
692 self.TreeImageList = wx.ImageList(16, 16) |
696 self.TreeImageList = wx.ImageList(16, 16) |
693 self.TreeImageDict = {} |
697 self.TreeImageDict = {} |
694 |
698 |
695 # Icons for languages |
699 # Icons for languages |
696 for language in LANGUAGES: |
700 for language in LANGUAGES: |
697 self.TreeImageDict[language]=self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%language))) |
701 self.TreeImageDict[language] = self.TreeImageList.Add(GetBitmap(language)) |
698 |
702 |
699 # Icons for other items |
703 # Icons for other items |
700 for imgname, itemtype in [ |
704 for imgname, itemtype in [ |
701 #editables |
705 #editables |
702 ("PROJECT", ITEM_PROJECT), |
706 ("PROJECT", ITEM_PROJECT), |
722 ("TRANSITIONS", ITEM_TRANSITIONS), |
726 ("TRANSITIONS", ITEM_TRANSITIONS), |
723 ("ACTIONS", ITEM_ACTIONS), |
727 ("ACTIONS", ITEM_ACTIONS), |
724 ("CONFIGURATIONS", ITEM_CONFIGURATIONS), |
728 ("CONFIGURATIONS", ITEM_CONFIGURATIONS), |
725 ("RESOURCES", ITEM_RESOURCES), |
729 ("RESOURCES", ITEM_RESOURCES), |
726 ("PROPERTIES", ITEM_PROPERTIES)]: |
730 ("PROPERTIES", ITEM_PROPERTIES)]: |
727 self.TreeImageDict[itemtype]=self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%imgname))) |
731 self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname)) |
728 |
732 |
729 # Assign icon list to TreeCtrls |
733 # Assign icon list to TreeCtrls |
730 self.ProjectTree.SetImageList(self.TreeImageList) |
734 self.ProjectTree.SetImageList(self.TreeImageList) |
731 self.PouInstanceVariablesPanel.SetTreeImageList(self.TreeImageList) |
735 self.PouInstanceVariablesPanel.SetTreeImageList(self.TreeImageList) |
732 |
736 |
1086 dialog.Destroy() |
1090 dialog.Destroy() |
1087 |
1091 |
1088 #------------------------------------------------------------------------------- |
1092 #------------------------------------------------------------------------------- |
1089 # Notebook Unified Functions |
1093 # Notebook Unified Functions |
1090 #------------------------------------------------------------------------------- |
1094 #------------------------------------------------------------------------------- |
1091 |
|
1092 ## Function that generate bitmap for |
|
1093 # for wx.aui.AUINotebook. |
|
1094 # @param window Panel to display in tab. |
|
1095 # @param text title for the tab ctrl. |
|
1096 def GenerateBitmap(self, icon1_name, icon2_name = None): |
|
1097 # Find index of bitmap if already created |
|
1098 index = self.TabsImageListIndexes.get((icon1_name, icon2_name), None) |
|
1099 # Return index or bitmap if found |
|
1100 if index is not None: |
|
1101 return self.TabsImageList.GetBitmap(index) |
|
1102 if icon2_name is None: |
|
1103 # Bitmap with only one icon |
|
1104 bitmap = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name)) |
|
1105 else: |
|
1106 # Bitmap with two icon |
|
1107 icon1 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name)) |
|
1108 icon2 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon2_name)) |
|
1109 |
|
1110 # Calculate bitmap size |
|
1111 width = icon1.GetWidth() + icon2.GetWidth() - 1 |
|
1112 height = max(icon1.GetHeight(), icon2.GetHeight()) |
|
1113 # Create bitmap with both icons |
|
1114 bitmap = wx.EmptyBitmap(width, height) |
|
1115 dc = wx.MemoryDC() |
|
1116 dc.SelectObject(bitmap) |
|
1117 dc.Clear() |
|
1118 dc.DrawBitmap(icon1, 0, 0) |
|
1119 dc.DrawBitmap(icon2, icon1.GetWidth() - 1, 0) |
|
1120 dc.Destroy() |
|
1121 |
|
1122 # Store bitmap in ImageList |
|
1123 index = self.TabsImageList.Add(bitmap) |
|
1124 # Save bitmap index in ImageList in dictionary |
|
1125 self.TabsImageListIndexes[(icon1_name, icon2_name)] = index |
|
1126 return bitmap |
|
1127 |
1095 |
1128 ## Function that add a tab in Notebook, calling refresh for tab DClick event |
1096 ## Function that add a tab in Notebook, calling refresh for tab DClick event |
1129 # for wx.aui.AUINotebook. |
1097 # for wx.aui.AUINotebook. |
1130 # @param window Panel to display in tab. |
1098 # @param window Panel to display in tab. |
1131 # @param text title for the tab ctrl. |
1099 # @param text title for the tab ctrl. |
1194 self.DeleteAllPages() |
1162 self.DeleteAllPages() |
1195 self.ProjectTree.DeleteAllItems() |
1163 self.ProjectTree.DeleteAllItems() |
1196 self.ProjectTree.Enable(False) |
1164 self.ProjectTree.Enable(False) |
1197 self.PouInstanceVariablesPanel.ResetView() |
1165 self.PouInstanceVariablesPanel.ResetView() |
1198 self.LibraryPanel.ResetTree() |
1166 self.LibraryPanel.ResetTree() |
1199 self.LibraryPanel.SetControler(None) |
1167 self.LibraryPanel.SetController(None) |
1200 self.Controler = None |
1168 self.Controler = None |
1201 |
1169 |
1202 def OnCloseTabMenu(self, event): |
1170 def OnCloseTabMenu(self, event): |
1203 selected = self.TabsOpened.GetSelection() |
1171 selected = self.TabsOpened.GetSelection() |
1204 if selected >= 0: |
1172 if selected >= 0: |
1601 self.ProjectTree.SetItemBackgroundColour(root, highlight_colours[0]) |
1569 self.ProjectTree.SetItemBackgroundColour(root, highlight_colours[0]) |
1602 self.ProjectTree.SetItemTextColour(root, highlight_colours[1]) |
1570 self.ProjectTree.SetItemTextColour(root, highlight_colours[1]) |
1603 if infos["type"] == ITEM_POU: |
1571 if infos["type"] == ITEM_POU: |
1604 self.ProjectTree.SetItemImage(root, self.TreeImageDict[self.Controler.GetPouBodyType(infos["name"])]) |
1572 self.ProjectTree.SetItemImage(root, self.TreeImageDict[self.Controler.GetPouBodyType(infos["name"])]) |
1605 elif infos.has_key("icon") and infos["icon"] is not None: |
1573 elif infos.has_key("icon") and infos["icon"] is not None: |
1606 icon_path = infos["icon"] |
1574 icon_name = infos["icon"] |
1607 if not self.TreeImageDict.has_key(icon_path): |
1575 if not self.TreeImageDict.has_key(icon_name): |
1608 self.TreeImageDict[icon_path] = self.TreeImageList.Add(wx.Bitmap(icon_path)) |
1576 self.TreeImageDict[icon_name] = self.TreeImageList.Add(GetBitmap(icon_name)) |
1609 self.ProjectTree.SetItemImage(root, self.TreeImageDict[icon_path]) |
1577 self.ProjectTree.SetItemImage(root, self.TreeImageDict[icon_name]) |
1610 elif self.TreeImageDict.has_key(infos["type"]): |
1578 elif self.TreeImageDict.has_key(infos["type"]): |
1611 self.ProjectTree.SetItemImage(root, self.TreeImageDict[infos["type"]]) |
1579 self.ProjectTree.SetItemImage(root, self.TreeImageDict[infos["type"]]) |
1612 |
1580 |
1613 if wx.VERSION >= (2, 6, 0): |
1581 if wx.VERSION >= (2, 6, 0): |
1614 item, root_cookie = self.ProjectTree.GetFirstChild(root) |
1582 item, root_cookie = self.ProjectTree.GetFirstChild(root) |
1851 self._Refresh(FILEMENU, EDITMENU, EDITORTOOLBAR, PAGETITLES) |
1819 self._Refresh(FILEMENU, EDITMENU, EDITORTOOLBAR, PAGETITLES) |
1852 elif not onlyopened: |
1820 elif not onlyopened: |
1853 new_window = None |
1821 new_window = None |
1854 if element == ITEM_CONFIGURATION: |
1822 if element == ITEM_CONFIGURATION: |
1855 new_window = ConfigurationEditor(self.TabsOpened, tagname, self, self.Controler) |
1823 new_window = ConfigurationEditor(self.TabsOpened, tagname, self, self.Controler) |
1856 new_window.SetIcon(self.GenerateBitmap("CONFIGURATION")) |
1824 new_window.SetIcon(GetBitmap("CONFIGURATION")) |
1857 self.AddPage(new_window, "") |
1825 self.AddPage(new_window, "") |
1858 elif element == ITEM_RESOURCE: |
1826 elif element == ITEM_RESOURCE: |
1859 new_window = ResourceEditor(self.TabsOpened, tagname, self, self.Controler) |
1827 new_window = ResourceEditor(self.TabsOpened, tagname, self, self.Controler) |
1860 new_window.SetIcon(self.GenerateBitmap("RESOURCE")) |
1828 new_window.SetIcon(GetBitmap("RESOURCE")) |
1861 self.AddPage(new_window, "") |
1829 self.AddPage(new_window, "") |
1862 elif element in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
1830 elif element in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
1863 bodytype = self.Controler.GetEditedElementBodyType(tagname) |
1831 bodytype = self.Controler.GetEditedElementBodyType(tagname) |
1864 if bodytype == "FBD": |
1832 if bodytype == "FBD": |
1865 new_window = Viewer(self.TabsOpened, tagname, self, self.Controler) |
1833 new_window = Viewer(self.TabsOpened, tagname, self, self.Controler) |
1877 new_window.SetKeywords(IL_KEYWORDS) |
1845 new_window.SetKeywords(IL_KEYWORDS) |
1878 else: |
1846 else: |
1879 new_window.SetKeywords(ST_KEYWORDS) |
1847 new_window.SetKeywords(ST_KEYWORDS) |
1880 if element == ITEM_POU: |
1848 if element == ITEM_POU: |
1881 pou_type = self.Controler.GetEditedElementType(tagname)[1].upper() |
1849 pou_type = self.Controler.GetEditedElementType(tagname)[1].upper() |
1882 icon = self.GenerateBitmap(pou_type, bodytype) |
1850 icon = GetBitmap(pou_type, bodytype) |
1883 elif element == ITEM_TRANSITION: |
1851 elif element == ITEM_TRANSITION: |
1884 icon = self.GenerateBitmap("TRANSITION", bodytype) |
1852 icon = GetBitmap("TRANSITION", bodytype) |
1885 elif element == ITEM_ACTION: |
1853 elif element == ITEM_ACTION: |
1886 icon = self.GenerateBitmap("ACTION", bodytype) |
1854 icon = GetBitmap("ACTION", bodytype) |
1887 new_window.SetIcon(icon) |
1855 new_window.SetIcon(icon) |
1888 self.AddPage(new_window, "") |
1856 self.AddPage(new_window, "") |
1889 elif element == ITEM_DATATYPE: |
1857 elif element == ITEM_DATATYPE: |
1890 new_window = DataTypeEditor(self.TabsOpened, tagname, self, self.Controler) |
1858 new_window = DataTypeEditor(self.TabsOpened, tagname, self, self.Controler) |
1891 new_window.SetIcon(self.GenerateBitmap("DATATYPE")) |
1859 new_window.SetIcon(GetBitmap("DATATYPE")) |
1892 self.AddPage(new_window, "") |
1860 self.AddPage(new_window, "") |
1893 elif isinstance(element, EditorPanel): |
1861 elif isinstance(element, EditorPanel): |
1894 new_window = element |
1862 new_window = element |
1895 self.AddPage(element, "") |
1863 self.AddPage(element, "") |
1896 if new_window is not None: |
1864 if new_window is not None: |
2096 if state is not None: |
2064 if state is not None: |
2097 wx.CallAfter(new_window.SetState, state) |
2065 wx.CallAfter(new_window.SetState, state) |
2098 |
2066 |
2099 if instance_category in [ITEM_FUNCTIONBLOCK, ITEM_PROGRAM]: |
2067 if instance_category in [ITEM_FUNCTIONBLOCK, ITEM_PROGRAM]: |
2100 pou_type = self.Controler.GetEditedElementType(instance_type, True)[1].upper() |
2068 pou_type = self.Controler.GetEditedElementType(instance_type, True)[1].upper() |
2101 icon = self.GenerateBitmap(pou_type, bodytype) |
2069 icon = GetBitmap(pou_type, bodytype) |
2102 elif instance_category == ITEM_TRANSITION: |
2070 elif instance_category == ITEM_TRANSITION: |
2103 icon = self.GenerateBitmap("TRANSITION", bodytype) |
2071 icon = GetBitmap("TRANSITION", bodytype) |
2104 elif instance_category == ITEM_ACTION: |
2072 elif instance_category == ITEM_ACTION: |
2105 icon = self.GenerateBitmap("ACTION", bodytype) |
2073 icon = GetBitmap("ACTION", bodytype) |
2106 new_window.SetIcon(icon) |
2074 new_window.SetIcon(icon) |
2107 self.AddPage(new_window, "") |
2075 self.AddPage(new_window, "") |
2108 new_window.RefreshView() |
2076 new_window.RefreshView() |
2109 new_window.SetFocus() |
2077 new_window.SetFocus() |
2110 self.RefreshPageTitles() |
2078 self.RefreshPageTitles() |
2112 |
2080 |
2113 return None |
2081 return None |
2114 |
2082 |
2115 def OpenGraphicViewer(self, var_path): |
2083 def OpenGraphicViewer(self, var_path): |
2116 new_window = GraphicViewer(self.TabsOpened, self, self.Controler, var_path) |
2084 new_window = GraphicViewer(self.TabsOpened, self, self.Controler, var_path) |
2085 new_window.SetIcon(GetBitmap("GRAPH")) |
|
2117 self.AddPage(new_window, "") |
2086 self.AddPage(new_window, "") |
2118 new_window.RefreshView() |
2087 new_window.RefreshView() |
2119 new_window.SetFocus() |
2088 new_window.SetFocus() |
2120 self.RefreshPageTitles() |
2089 self.RefreshPageTitles() |
2121 return new_window |
2090 return new_window |
2165 for toolbar_item in items: |
2134 for toolbar_item in items: |
2166 if toolbar_item is None: |
2135 if toolbar_item is None: |
2167 MenuToolBar.AddSeparator() |
2136 MenuToolBar.AddSeparator() |
2168 else: |
2137 else: |
2169 id, bitmap, help, callback = toolbar_item |
2138 id, bitmap, help, callback = toolbar_item |
2170 MenuToolBar.AddSimpleTool(id=id, shortHelpString=help, bitmap=wx.Bitmap(os.path.join(CWD, 'Images', bitmap))) |
2139 MenuToolBar.AddSimpleTool(id=id, shortHelpString=help, bitmap=GetBitmap(bitmap)) |
2171 if callback is not None: |
2140 if callback is not None: |
2172 self.Bind(wx.EVT_TOOL, callback, id=id) |
2141 self.Bind(wx.EVT_TOOL, callback, id=id) |
2173 MenuToolBar.Realize() |
2142 MenuToolBar.Realize() |
2174 self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize()) |
2143 self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize()) |
2175 |
2144 |
2208 EditorToolBar = self.Panes["EditorToolBar"] |
2177 EditorToolBar = self.Panes["EditorToolBar"] |
2209 if EditorToolBar: |
2178 if EditorToolBar: |
2210 for radio, modes, id, method, picture, help in EditorToolBarItems[menu]: |
2179 for radio, modes, id, method, picture, help in EditorToolBarItems[menu]: |
2211 if modes & self.DrawingMode: |
2180 if modes & self.DrawingMode: |
2212 if radio or self.DrawingMode == FREEDRAWING_MODE: |
2181 if radio or self.DrawingMode == FREEDRAWING_MODE: |
2213 EditorToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), wx.NullBitmap, help) |
2182 EditorToolBar.AddRadioTool(id, GetBitmap(picture), wx.NullBitmap, help) |
2214 else: |
2183 else: |
2215 EditorToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), help) |
2184 EditorToolBar.AddSimpleTool(id, GetBitmap(picture), help) |
2216 self.Bind(wx.EVT_MENU, getattr(self, method), id=id) |
2185 self.Bind(wx.EVT_MENU, getattr(self, method), id=id) |
2217 self.CurrentEditorToolBar.append(id) |
2186 self.CurrentEditorToolBar.append(id) |
2218 EditorToolBar.Realize() |
2187 EditorToolBar.Realize() |
2219 self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize()) |
2188 self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize()) |
2220 self.AUIManager.GetPane("EditorToolBar").Show() |
2189 self.AUIManager.GetPane("EditorToolBar").Show() |
2665 self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
2634 self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
2666 self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
2635 self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
2667 self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
2636 self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
2668 self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
2637 self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
2669 |
2638 |
2670 self.AddToMenuToolBar([(wx.ID_NEW, "new.png", _(u'New'), None), |
2639 self.AddToMenuToolBar([(wx.ID_NEW, "new", _(u'New'), None), |
2671 (wx.ID_OPEN, "open.png", _(u'Open'), None), |
2640 (wx.ID_OPEN, "open", _(u'Open'), None), |
2672 (wx.ID_SAVE, "save.png", _(u'Save'), None), |
2641 (wx.ID_SAVE, "save", _(u'Save'), None), |
2673 (wx.ID_SAVEAS, "saveas.png", _(u'Save As...'), None), |
2642 (wx.ID_SAVEAS, "saveas", _(u'Save As...'), None), |
2674 (wx.ID_PRINT, "print.png", _(u'Print'), None)]) |
2643 (wx.ID_PRINT, "print", _(u'Print'), None)]) |
2675 |
2644 |
2676 def _init_coll_HelpMenu_Items(self, parent): |
2645 def _init_coll_HelpMenu_Items(self, parent): |
2677 AppendMenu(parent, help='', id=wx.ID_HELP, |
2646 AppendMenu(parent, help='', id=wx.ID_HELP, |
2678 kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor\tF1')) |
2647 kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor\tF1')) |
2679 #AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS, |
2648 #AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS, |
2701 # Create a new controller |
2670 # Create a new controller |
2702 controler = PLCControler() |
2671 controler = PLCControler() |
2703 result = controler.OpenXMLFile(fileOpen) |
2672 result = controler.OpenXMLFile(fileOpen) |
2704 if result is None: |
2673 if result is None: |
2705 self.Controler = controler |
2674 self.Controler = controler |
2706 self.LibraryPanel.SetControler(controler) |
2675 self.LibraryPanel.SetController(controler) |
2707 self.ProjectTree.Enable(True) |
2676 self.ProjectTree.Enable(True) |
2708 self.PouInstanceVariablesPanel.SetController(controler) |
2677 self.PouInstanceVariablesPanel.SetController(controler) |
2709 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
2678 self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
2710 |
2679 |
2711 # Define PLCOpenEditor icon |
2680 # Define PLCOpenEditor icon |
2712 self.SetIcon(wx.Icon(os.path.join(CWD,"Images", "poe.ico"),wx.BITMAP_TYPE_ICO)) |
2681 self.SetIcon(wx.Icon(os.path.join(CWD, "Images", "poe.ico"),wx.BITMAP_TYPE_ICO)) |
2713 |
2682 |
2714 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
2683 self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
2715 |
2684 |
2716 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
2685 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
2717 |
2686 |
2792 if dialog.ShowModal() == wx.ID_OK: |
2761 if dialog.ShowModal() == wx.ID_OK: |
2793 properties = dialog.GetValues() |
2762 properties = dialog.GetValues() |
2794 self.ResetView() |
2763 self.ResetView() |
2795 self.Controler = PLCControler() |
2764 self.Controler = PLCControler() |
2796 self.Controler.CreateNewProject(properties) |
2765 self.Controler.CreateNewProject(properties) |
2797 self.LibraryPanel.SetControler(self.Controler) |
2766 self.LibraryPanel.SetController(self.Controler) |
2798 self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, |
2767 self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, |
2799 LIBRARYTREE) |
2768 LIBRARYTREE) |
2800 |
2769 |
2801 def OnOpenProjectMenu(self, event): |
2770 def OnOpenProjectMenu(self, event): |
2802 if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
2771 if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
2818 self.ResetView() |
2787 self.ResetView() |
2819 controler = PLCControler() |
2788 controler = PLCControler() |
2820 result = controler.OpenXMLFile(filepath) |
2789 result = controler.OpenXMLFile(filepath) |
2821 if result is None: |
2790 if result is None: |
2822 self.Controler = controler |
2791 self.Controler = controler |
2823 self.LibraryPanel.SetControler(controler) |
2792 self.LibraryPanel.SetController(controler) |
2824 self.ProjectTree.Enable(True) |
2793 self.ProjectTree.Enable(True) |
2825 self.PouInstanceVariablesPanel.SetController(controler) |
2794 self.PouInstanceVariablesPanel.SetController(controler) |
2826 self.LoadProjectLayout() |
2795 self.LoadProjectLayout() |
2827 self._Refresh(PROJECTTREE, LIBRARYTREE) |
2796 self._Refresh(PROJECTTREE, LIBRARYTREE) |
2828 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
2797 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |