Пример #1
0
 def mEditGameComment(self, *args):
     if self._cancelDrag(break_pause=False):
         return
     game, gi = self.game, self.game.gameinfo
     kw = {'game': gi.name, 'id': game.getGameNumber(format=1)}
     cc = _("Comments for %(game)s %(id)s:\n\n") % kw
     c = game.gsaveinfo.comment or cc
     d = EditTextDialog(game.top, _("Comments for %(id)s") % kw, text=c)
     if d.status == 0 and d.button == 0:
         text = d.text
         if text.strip() == cc.strip():
             game.gsaveinfo.comment = ""
         else:
             game.gsaveinfo.comment = d.text
             # save to file
             fn = os.path.join(self.app.dn.config, "comments.txt")
             fn = os.path.normpath(fn)
             if not text.endswith(os.linesep):
                 text += os.linesep
             enc = locale.getpreferredencoding()
             try:
                 open(fn, 'a').write(text.encode(enc, 'replace'))
             except Exception as err:
                 d = MfxExceptionDialog(
                     self.top, err, text=_("Error while writing to file"))
             else:
                 d = MfxMessageDialog(
                     self.top,
                     title=_("%s Info") % TITLE,
                     bitmap="info",
                     text=_("Comments were appended to\n\n%(filename)s") %
                     {'filename': fn})
     self._setCommentMenu(bool(game.gsaveinfo.comment))
Пример #2
0
 def mEditGameComment(self, *args):
     if self._cancelDrag(break_pause=False): return
     game, gi = self.game, self.game.gameinfo
     t = " " + game.getGameNumber(format=1)
     cc = _("Comments for %s:\n\n") % (gi.name + t)
     c = game.gsaveinfo.comment or cc
     d = EditTextDialog(game.top, _("Comments for ") + t, text=c)
     if d.status == 0 and d.button == 0:
         text = d.text
         if text.strip() == cc.strip():
             game.gsaveinfo.comment = ""
         else:
             game.gsaveinfo.comment = d.text
             # save to file
             fn = os.path.join(self.app.dn.config, "comments.txt")
             fn = os.path.normpath(fn)
             if not text.endswith(os.linesep):
                 text += os.linesep
             enc = locale.getpreferredencoding()
             try:
                 fd = open(fn, 'a')
                 fd.write(text.encode(enc, 'replace'))
             except Exception, err:
                 d = MfxExceptionDialog(
                     self.top, err, text=_("Error while writing to file"))
             else:
                 if fd: fd.close()
                 d = MfxMessageDialog(
                     self.top,
                     title=TITLE + _(" Info"),
                     bitmap="info",
                     text=_("Comments were appended to\n\n") + fn)