PLCOpenEditor.py
changeset 1734 750eeb7230a1
parent 1732 94ffe74e6895
child 1736 7e61baa047f0
equal deleted inserted replaced
1733:dea107dce0c4 1734:750eeb7230a1
    40 if __name__ == '__main__':
    40 if __name__ == '__main__':
    41     # Usage message displayed when help request or when error detected in
    41     # Usage message displayed when help request or when error detected in
    42     # command line
    42     # command line
    43     def usage():
    43     def usage():
    44         print "\nUsage of PLCOpenEditor.py :"
    44         print "\nUsage of PLCOpenEditor.py :"
    45         print "\n   %s [Filepath]\n"%sys.argv[0]
    45         print "\n   %s [Filepath]\n" % sys.argv[0]
    46 
    46 
    47     # Parse options given to PLCOpenEditor in command line
    47     # Parse options given to PLCOpenEditor in command line
    48     try:
    48     try:
    49         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
    49         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
    50     except getopt.GetoptError:
    50     except getopt.GetoptError:
   221             event.Veto()
   221             event.Veto()
   222 
   222 
   223     def RefreshTitle(self):
   223     def RefreshTitle(self):
   224         name = _("PLCOpenEditor")
   224         name = _("PLCOpenEditor")
   225         if self.Controler is not None:
   225         if self.Controler is not None:
   226             self.SetTitle("%s - %s"%(name, self.Controler.GetFilename()))
   226             self.SetTitle("%s - %s" % (name, self.Controler.GetFilename()))
   227         else:
   227         else:
   228             self.SetTitle(name)
   228             self.SetTitle(name)
   229 
   229 
   230 #-------------------------------------------------------------------------------
   230 #-------------------------------------------------------------------------------
   231 #                            File Menu Functions
   231 #                            File Menu Functions
   344             if os.path.isdir(os.path.dirname(filepath)):
   344             if os.path.isdir(os.path.dirname(filepath)):
   345                 program, errors, warnings = self.Controler.GenerateProgram(filepath)
   345                 program, errors, warnings = self.Controler.GenerateProgram(filepath)
   346                 message_text += "".join([_("warning: %s\n") % warning for warning in warnings])
   346                 message_text += "".join([_("warning: %s\n") % warning for warning in warnings])
   347                 if len(errors) > 0:
   347                 if len(errors) > 0:
   348                     message_text += "".join([_("error: %s\n") % error for error in errors])
   348                     message_text += "".join([_("error: %s\n") % error for error in errors])
   349                     message_text += _("Can't generate program to file %s!")%filepath
   349                     message_text += _("Can't generate program to file %s!") % filepath
   350                     header, icon = _("Error"), wx.ICON_ERROR
   350                     header, icon = _("Error"), wx.ICON_ERROR
   351                 else:
   351                 else:
   352                     message_text += _("Program was successfully generated!")
   352                     message_text += _("Program was successfully generated!")
   353             else:
   353             else:
   354                 message_text += _("\"%s\" is not a valid folder!")%os.path.dirname(filepath)
   354                 message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath)
   355                 header, icon = _("Error"), wx.ICON_ERROR
   355                 header, icon = _("Error"), wx.ICON_ERROR
   356             message = wx.MessageDialog(self, message_text, header, wx.OK|icon)
   356             message = wx.MessageDialog(self, message_text, header, wx.OK|icon)
   357             message.ShowModal()
   357             message.ShowModal()
   358             message.Destroy()
   358             message.Destroy()
   359         dialog.Destroy()
   359         dialog.Destroy()
   382     def SaveProjectAs(self):
   382     def SaveProjectAs(self):
   383         filepath = self.Controler.GetFilePath()
   383         filepath = self.Controler.GetFilePath()
   384         if filepath != "":
   384         if filepath != "":
   385             directory, filename = os.path.split(filepath)
   385             directory, filename = os.path.split(filepath)
   386         else:
   386         else:
   387             directory, filename = os.getcwd(), "%(projectName)s.xml"%self.Controler.GetProjectProperties()
   387             directory, filename = os.getcwd(), "%(projectName)s.xml" % self.Controler.GetProjectProperties()
   388         dialog = wx.FileDialog(self, _("Choose a file"), directory, filename,  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.SAVE|wx.OVERWRITE_PROMPT)
   388         dialog = wx.FileDialog(self, _("Choose a file"), directory, filename,  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.SAVE|wx.OVERWRITE_PROMPT)
   389         if dialog.ShowModal() == wx.ID_OK:
   389         if dialog.ShowModal() == wx.ID_OK:
   390             filepath = dialog.GetPath()
   390             filepath = dialog.GetPath()
   391             if os.path.isdir(os.path.dirname(filepath)):
   391             if os.path.isdir(os.path.dirname(filepath)):
   392                 result = self.Controler.SaveXMLFile(filepath)
   392                 result = self.Controler.SaveXMLFile(filepath)
   393                 if not result:
   393                 if not result:
   394                     self.ShowErrorMessage(_("Can't save project to file %s!")%filepath)
   394                     self.ShowErrorMessage(_("Can't save project to file %s!") % filepath)
   395             else:
   395             else:
   396                 self.ShowErrorMessage(_("\"%s\" is not a valid folder!")%os.path.dirname(filepath))
   396                 self.ShowErrorMessage(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath))
   397             self._Refresh(TITLE, FILEMENU, PAGETITLES)
   397             self._Refresh(TITLE, FILEMENU, PAGETITLES)
   398         dialog.Destroy()
   398         dialog.Destroy()
   399 
   399 
   400 #-------------------------------------------------------------------------------
   400 #-------------------------------------------------------------------------------
   401 #                               Exception Handler
   401 #                               Exception Handler