svghmi/svghmi.py
branchsvghmi
changeset 3112 bd20f9112014
parent 3108 079419e7228d
child 3113 18133b90196e
equal deleted inserted replaced
3111:5d9ae04ee50f 3112:bd20f9112014
    28 from util.ProcessLogger import ProcessLogger
    28 from util.ProcessLogger import ProcessLogger
    29 from runtime.typemapping import DebugTypesSize
    29 from runtime.typemapping import DebugTypesSize
    30 import targets
    30 import targets
    31 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
    31 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
    32 from XSLTransform import XSLTransform
    32 from XSLTransform import XSLTransform
    33 from svghmi.i18n import POTWriter, POReader
    33 from svghmi.i18n import POTWriter, POReader, open_pofile
    34 
    34 
    35 HMI_TYPES_DESC = {
    35 HMI_TYPES_DESC = {
    36     "HMI_NODE":{},
    36     "HMI_NODE":{},
    37     "HMI_STRING":{},
    37     "HMI_STRING":{},
    38     "HMI_INT":{},
    38     "HMI_INT":{},
   453             "name":    _("Import SVG"),
   453             "name":    _("Import SVG"),
   454             "tooltip": _("Import SVG"),
   454             "tooltip": _("Import SVG"),
   455             "method":   "_ImportSVG"
   455             "method":   "_ImportSVG"
   456         },
   456         },
   457         {
   457         {
   458             "bitmap":    "ImportSVG",  # should be something different
   458             "bitmap":    "EditSVG",  # should be something different
   459             "name":    _("Inkscape"),
   459             "name":    _("Inkscape"),
   460             "tooltip": _("Edit HMI"),
   460             "tooltip": _("Edit HMI"),
   461             "method":   "_StartInkscape"
   461             "method":   "_StartInkscape"
   462         },
   462         },
   463 
   463         {
   464         # TODO : Launch POEdit button for new languqge (opens POT)
   464             "bitmap":    "OpenPOT",  # should be something different
   465 
   465             "name":    _("New lang"),
   466         # TODO : Launch POEdit button for existing languqge (opens one of existing PO)
   466             "tooltip": _("Open non translated message catalog (POT) to start new language"),
       
   467             "method":   "_OpenPOT"
       
   468         },
       
   469 
       
   470         {
       
   471             "bitmap":    "EditPO",  # should be something different
       
   472             "name":    _("Edit lang"),
       
   473             "tooltip": _("Edit existing message catalog (PO) for specific language"),
       
   474             "method":   "_EditPO"
       
   475         },
   467 
   476 
   468         # TODO : HMITree button
   477         # TODO : HMITree button
   469         #        - can drag'n'drop variabes to Inkscape
   478         #        - can drag'n'drop variabes to Inkscape
   470 
       
   471     ]
   479     ]
   472 
   480 
   473     def _getSVGpath(self, project_path=None):
   481     def _getSVGpath(self, project_path=None):
   474         if project_path is None:
   482         if project_path is None:
   475             project_path = self.CTNPath()
   483             project_path = self.CTNPath()
   482 
   490 
   483     def OnCTNSave(self, from_project_path=None):
   491     def OnCTNSave(self, from_project_path=None):
   484         if from_project_path is not None:
   492         if from_project_path is not None:
   485             shutil.copyfile(self._getSVGpath(from_project_path),
   493             shutil.copyfile(self._getSVGpath(from_project_path),
   486                             self._getSVGpath())
   494                             self._getSVGpath())
       
   495             shutil.copyfile(self._getPOTpath(from_project_path),
       
   496                             self._getPOTpath())
       
   497             # XXX TODO copy .PO files
   487         return True
   498         return True
   488 
   499 
   489     def GetSVGGeometry(self):
   500     def GetSVGGeometry(self):
   490         # invoke inskscape -S, csv-parse output, produce elements
   501         # invoke inskscape -S, csv-parse output, produce elements
   491         InkscapeGeomColumns = ["Id", "x", "y", "w", "h"]
   502         InkscapeGeomColumns = ["Id", "x", "y", "w", "h"]
   520 
   531 
   521     def GetTranslations(self, _context, msgs):
   532     def GetTranslations(self, _context, msgs):
   522 
   533 
   523         w = POTWriter()
   534         w = POTWriter()
   524         w.ImportMessages(msgs)
   535         w.ImportMessages(msgs)
   525         # XXX get POT path
   536 
   526         # XXX save POT file
   537         with open(self._getPOTpath(), 'w') as POT_file:
       
   538             w.write(POT_file)
   527 
   539 
   528         # XXX scan existing PO files 
   540         # XXX scan existing PO files 
   529         # XXX read PO files
   541         # XXX read PO files
   530 
   542 
   531         r = POReader()
   543         r = POReader()
   676                                       _("Open POEdit"),
   688                                       _("Open POEdit"),
   677                                       wx.YES_NO | wx.ICON_QUESTION)
   689                                       wx.YES_NO | wx.ICON_QUESTION)
   678             open_poedit = dialog.ShowModal() == wx.ID_YES
   690             open_poedit = dialog.ShowModal() == wx.ID_YES
   679             dialog.Destroy()
   691             dialog.Destroy()
   680         if open_poedit:
   692         if open_poedit:
   681             # XXX TODO
   693             open_pofile(POFile)
   682             pass
   694 
   683 
   695     def _EditPO(self):
   684     def _EditTranslation(self):
       
   685         """ Select a specific translation and edit it with POEdit """
   696         """ Select a specific translation and edit it with POEdit """
   686         pass
   697         project_path = self.CTNPath()
   687 
   698         dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a PO file"), project_path, "",  _("PO files (*.po)|*.po"), wx.OPEN)
   688     def _EditNewTranslation(self):
   699         if dialog.ShowModal() == wx.ID_OK:
       
   700             POFile = dialog.GetPath()
       
   701             if os.path.isfile(POFile):
       
   702                 if os.path.dirname(POFile) == project_path:
       
   703                     self._StartPOEdit(POFile)
       
   704                 else:
       
   705                     self.GetCTRoot().logger.write_error(_("PO file misplaced: %s is not in %s\n") % (POFile,project_path))
       
   706             else:
       
   707                 self.GetCTRoot().logger.write_error(_("PO file do not exist: %s\n") % POFile)
       
   708         dialog.Destroy()
       
   709 
       
   710     def _OpenPOT(self):
   689         """ Start POEdit with untouched empty catalog """
   711         """ Start POEdit with untouched empty catalog """
   690         POFile = self._getPOTpath()
   712         POFile = self._getPOTpath()
   691         self._StartPOEdit(POFile)
   713         self._StartPOEdit(POFile)
   692 
   714 
   693     def CTNGlobalInstances(self):
   715     def CTNGlobalInstances(self):