1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Fix error saving comments to the comments.txt file

This commit is contained in:
Joe R 2024-11-24 16:04:21 -05:00
parent 86d92c2636
commit 61eb1f0361
5 changed files with 7 additions and 23 deletions

View file

@ -21,7 +21,6 @@
# #
# ---------------------------------------------------------------------------## # ---------------------------------------------------------------------------##
import locale
import os import os
from pysollib.gamedb import GI from pysollib.gamedb import GI
@ -566,20 +565,17 @@ class PysolMenubar(PysolMenubarTk):
fn = os.path.normpath(fn) fn = os.path.normpath(fn)
if not text.endswith(os.linesep): if not text.endswith(os.linesep):
text += os.linesep text += os.linesep
enc = locale.getpreferredencoding()
try: try:
with open(fn, 'at') as fh: with open(fn, 'at') as fh:
fh.write(text.encode(enc, 'replace')) fh.write(d.text)
except Exception as err: except Exception as err:
d = MfxExceptionDialog( MfxExceptionDialog(
self.top, err, self.top, err, text=_("Error while writing to file"))
text=_("Error while writing to file"))
else: else:
d = MfxMessageDialog( MfxMessageDialog(
self.top, title=_("%s Info") % TITLE, bitmap="info", self.top, title=_("%s Info") % TITLE, bitmap="info",
text=_("Comments were appended to\n\n%(filename)s") text=_("Comments were appended to\n\n%(filename)s")
% {'filename': fn}) % {'filename': fn})
self._setCommentMenu(bool(game.gsaveinfo.comment))
# #
# Game menu - statistics # Game menu - statistics

View file

@ -781,7 +781,7 @@ class Game(object):
def getGameNumber(self, format): def getGameNumber(self, format):
s = self.random.getSeedAsStr() s = self.random.getSeedAsStr()
if format: if format:
return "# " + s return "#" + s
return s return s
# this is called from within createGame() # this is called from within createGame()

View file

@ -2059,9 +2059,6 @@ class PysolMenubarTk:
# LB: not used # LB: not used
return return
def _setCommentMenu(self, v):
return
def _setPauseMenu(self, v): def _setPauseMenu(self, v):
self.tkopt.pause.value = v self.tkopt.pause.value = v

View file

@ -762,10 +762,6 @@ class PysolMenubarTk:
def updateAll(self, *event): def updateAll(self, *event):
self.app.canvas.updateAll() self.app.canvas.updateAll()
def _setCommentMenu(self, v):
# FIXME
pass
def _setPauseMenu(self, v): def _setPauseMenu(self, v):
# FIXME # FIXME
pass pass

View file

@ -291,7 +291,6 @@ class PysolMenubarTkCommon:
self.tkopt = Struct( self.tkopt = Struct(
gameid=tkinter.IntVar(), gameid=tkinter.IntVar(),
gameid_popular=tkinter.IntVar(), gameid_popular=tkinter.IntVar(),
comment=tkinter.BooleanVar(),
autofaceup=tkinter.BooleanVar(), autofaceup=tkinter.BooleanVar(),
autodrop=tkinter.BooleanVar(), autodrop=tkinter.BooleanVar(),
autodeal=tkinter.BooleanVar(), autodeal=tkinter.BooleanVar(),
@ -438,7 +437,6 @@ class PysolMenubarTkCommon:
tkopt = self.tkopt tkopt = self.tkopt
tkopt.gameid.set(game.id) tkopt.gameid.set(game.id)
tkopt.gameid_popular.set(game.id) tkopt.gameid_popular.set(game.id)
tkopt.comment.set(bool(game.gsaveinfo.comment))
tkopt.pause.set(self.game.pause) tkopt.pause.set(self.game.pause)
if game.canFindCard(): if game.canFindCard():
self._connect_game_find_card_dialog(game) self._connect_game_find_card_dialog(game)
@ -621,8 +619,8 @@ class PysolMenubarTkCommon:
label=n_("Log..."), label=n_("Log..."),
command=lambda: self.mPlayerStats(mode=103)) command=lambda: self.mPlayerStats(mode=103))
menu.add_separator() menu.add_separator()
menu.add_checkbutton( menu.add_command(
label=n_("&Comments..."), variable=self.tkopt.comment, label=n_("&Comments..."),
command=self.mEditGameComment) command=self.mEditGameComment)
menu = MfxMenu(self.menubar, label=n_("&Assist")) menu = MfxMenu(self.menubar, label=n_("&Assist"))
@ -1400,9 +1398,6 @@ class PysolMenubarTkCommon:
w = getattr(self.app.toolbar, path + "_button") w = getattr(self.app.toolbar, path + "_button")
w["state"] = s w["state"] = s
def _setCommentMenu(self, v):
self.tkopt.comment.set(v)
def _setPauseMenu(self, v): def _setPauseMenu(self, v):
self.tkopt.pause.set(v) self.tkopt.pause.set(v)