84 kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S') |
85 kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S') |
85 AppendMenu(parent, help='', id=wx.ID_SAVEAS, |
86 AppendMenu(parent, help='', id=wx.ID_SAVEAS, |
86 kind=wx.ITEM_NORMAL, text=_(u'Save As...') + '\tCTRL+SHIFT+S') |
87 kind=wx.ITEM_NORMAL, text=_(u'Save As...') + '\tCTRL+SHIFT+S') |
87 AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATE, |
88 AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATE, |
88 kind=wx.ITEM_NORMAL, text=_(u'Generate Program') + '\tCTRL+G') |
89 kind=wx.ITEM_NORMAL, text=_(u'Generate Program') + '\tCTRL+G') |
|
90 AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATEAS, |
|
91 kind=wx.ITEM_NORMAL, text=_(u'Generate Program As...') + '\tCTRL+SHIFT+G') |
89 parent.AppendSeparator() |
92 parent.AppendSeparator() |
90 AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP, |
93 AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP, |
91 kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P') |
94 kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P') |
92 AppendMenu(parent, help='', id=wx.ID_PREVIEW, |
95 AppendMenu(parent, help='', id=wx.ID_PREVIEW, |
93 kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P') |
96 kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P') |
106 self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
109 self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
107 self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
110 self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
108 self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS) |
111 self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS) |
109 self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, |
112 self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, |
110 id=ID_PLCOPENEDITORFILEMENUGENERATE) |
113 id=ID_PLCOPENEDITORFILEMENUGENERATE) |
|
114 self.Bind(wx.EVT_MENU, self.OnGenerateProgramAsMenu, |
|
115 id=ID_PLCOPENEDITORFILEMENUGENERATEAS) |
111 self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
116 self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
112 self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
117 self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
113 self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
118 self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
114 self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
119 self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
115 self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
120 self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
232 self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
237 self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
233 self.FileMenu.Enable(wx.ID_SAVEAS, True) |
238 self.FileMenu.Enable(wx.ID_SAVEAS, True) |
234 MenuToolBar.EnableTool(wx.ID_SAVEAS, True) |
239 MenuToolBar.EnableTool(wx.ID_SAVEAS, True) |
235 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
240 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
236 MenuToolBar.EnableTool(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
241 MenuToolBar.EnableTool(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
|
242 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATEAS, True) |
237 else: |
243 else: |
238 self.FileMenu.Enable(wx.ID_CLOSE, False) |
244 self.FileMenu.Enable(wx.ID_CLOSE, False) |
239 self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
245 self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
240 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
246 self.FileMenu.Enable(wx.ID_PREVIEW, False) |
241 self.FileMenu.Enable(wx.ID_PRINT, False) |
247 self.FileMenu.Enable(wx.ID_PRINT, False) |
246 self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
252 self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
247 self.FileMenu.Enable(wx.ID_SAVEAS, False) |
253 self.FileMenu.Enable(wx.ID_SAVEAS, False) |
248 MenuToolBar.EnableTool(wx.ID_SAVEAS, False) |
254 MenuToolBar.EnableTool(wx.ID_SAVEAS, False) |
249 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
255 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
250 MenuToolBar.EnableTool(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
256 MenuToolBar.EnableTool(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
|
257 self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATEAS, False) |
251 |
258 |
252 def OnNewProjectMenu(self, event): |
259 def OnNewProjectMenu(self, event): |
253 if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
260 if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
254 return |
261 return |
255 dialog = ProjectDialog(self) |
262 dialog = ProjectDialog(self) |
306 |
313 |
307 def OnSaveProjectAsMenu(self, event): |
314 def OnSaveProjectAsMenu(self, event): |
308 self.SaveProjectAs() |
315 self.SaveProjectAs() |
309 |
316 |
310 def OnGenerateProgramMenu(self, event): |
317 def OnGenerateProgramMenu(self, event): |
|
318 result = self.Controler.GetProgramFilePath() |
|
319 if not result: |
|
320 self.GenerateProgramAs() |
|
321 else: |
|
322 self.GenerateProgram(result) |
|
323 |
|
324 def OnGenerateProgramAsMenu(self, event): |
|
325 self.GenerateProgramAs() |
|
326 |
|
327 def GenerateProgramAs(self): |
311 dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), os.path.basename(self.Controler.GetProgramFilePath()), _("ST files (*.st)|*.st|All files|*.*"), wx.SAVE | wx.CHANGE_DIR) |
328 dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), os.path.basename(self.Controler.GetProgramFilePath()), _("ST files (*.st)|*.st|All files|*.*"), wx.SAVE | wx.CHANGE_DIR) |
312 if dialog.ShowModal() == wx.ID_OK: |
329 if dialog.ShowModal() == wx.ID_OK: |
313 filepath = dialog.GetPath() |
330 self.GenerateProgram(dialog.GetPath()) |
314 message_text = "" |
331 dialog.Destroy() |
315 header, icon = _("Done"), wx.ICON_INFORMATION |
332 |
316 if os.path.isdir(os.path.dirname(filepath)): |
333 def GenerateProgram(self, filepath=None): |
317 _program, errors, warnings = self.Controler.GenerateProgram(filepath) |
334 message_text = "" |
318 message_text += "".join([_("warning: %s\n") % warning for warning in warnings]) |
335 header, icon = _("Done"), wx.ICON_INFORMATION |
319 if len(errors) > 0: |
336 if os.path.isdir(os.path.dirname(filepath)): |
320 message_text += "".join([_("error: %s\n") % error for error in errors]) |
337 _program, errors, warnings = self.Controler.GenerateProgram(filepath) |
321 message_text += _("Can't generate program to file %s!") % filepath |
338 message_text += "".join([_("warning: %s\n") % warning for warning in warnings]) |
322 header, icon = _("Error"), wx.ICON_ERROR |
339 if len(errors) > 0: |
323 else: |
340 message_text += "".join([_("error: %s\n") % error for error in errors]) |
324 message_text += _("Program was successfully generated!") |
341 message_text += _("Can't generate program to file %s!") % filepath |
|
342 header, icon = _("Error"), wx.ICON_ERROR |
325 else: |
343 else: |
326 message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath) |
344 message_text += _("Program was successfully generated!") |
327 header, icon = _("Error"), wx.ICON_ERROR |
345 else: |
328 message = wx.MessageDialog(self, message_text, header, wx.OK | icon) |
346 message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath) |
329 message.ShowModal() |
347 header, icon = _("Error"), wx.ICON_ERROR |
330 message.Destroy() |
348 message = wx.MessageDialog(self, message_text, header, wx.OK | icon) |
331 dialog.Destroy() |
349 message.ShowModal() |
|
350 message.Destroy() |
332 |
351 |
333 def OnPLCOpenEditorMenu(self, event): |
352 def OnPLCOpenEditorMenu(self, event): |
334 wx.MessageBox(_("No documentation available.\nComing soon.")) |
353 wx.MessageBox(_("No documentation available.\nComing soon.")) |
335 |
354 |
336 def OnPLCOpenMenu(self, event): |
355 def OnPLCOpenMenu(self, event): |