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

Added option to delete custom games.

This commit is contained in:
Joe R 2021-07-29 17:35:09 -04:00
parent c9275edb26
commit 541b97b92f
4 changed files with 52 additions and 10 deletions

View file

@ -179,6 +179,7 @@ class PysolMenubar(PysolMenubarTk):
self.updateBookmarkMenuState()
self.setMenuState(ms.restart, "edit.restart")
self.setMenuState(ms.custom_game, "edit.editcurrentgame")
self.setMenuState(ms.custom_game, "edit.deletecurrentgame")
# Game menu
self.setMenuState(ms.deal, "game.dealcards")
self.setMenuState(ms.autodrop, "game.autodrop")

View file

@ -705,6 +705,11 @@ def registerGame(gameinfo):
return gameinfo
def hideGame(game):
game.gameinfo.si.game_type = GI.GT_HIDDEN
registerGame(game.gameinfo)
def loadGame(modname, filename, check_game=False):
# print "load game", modname, filename
GAME_DB.check_game = check_game

View file

@ -398,6 +398,9 @@ class PysolMenubarTkCommon:
menu.add_command(
label=n_("&Edit current game"),
command=self.mWizardEdit)
menu.add_command(
label=n_("&Delete current game"),
command=self.mWizardDelete)
menu = MfxMenu(self.menubar, label=n_("&Game"))
menu.add_command(
@ -932,7 +935,8 @@ class PysolMenubarTkCommon:
self.updateGamesMenu(submenu, games)
def _addSelectAllGameSubMenu(self, games, menu, command, variable):
menu = MfxMenu(menu, label=n_("&All games by name"))
if menu.name != "allgamesbyname":
menu = MfxMenu(menu, label=n_("&All games by name"))
n, d = 0, self.cb_max
i = 0
while True:
@ -1069,6 +1073,24 @@ class PysolMenubarTkCommon:
games.append(gi)
self.updateGamesMenu(submenu, games)
def updateCustomGamesMenu(self):
menu = self.menupath[".menubar.select.customgames"][2]
menu2 = self.menupath[".menubar.select.allgamesbyname"][2]
def select_func_visible(gi):
return gi.si.game_type != GI.GT_HIDDEN
def select_func_custom(gi):
return gi.si.game_type == GI.GT_CUSTOM
games = list(map(self.app.gdb.get,
self.app.gdb.getGamesIdSortedByName()))
games = list(filter(select_func_visible, games))
self.progress = False
self.updateGamesMenu(menu2, games)
games = list(filter(select_func_custom, games))
self.updateGamesMenu(menu, games)
def updateBookmarkMenuState(self):
state = self._getEnabledState
mp1 = self.menupath.get(".menubar.edit.setbookmark")
@ -1724,14 +1746,7 @@ Error while saving game.
return
if SELECT_GAME_MENU:
menu = self.menupath[".menubar.select.customgames"][2]
def select_func(gi):
return gi.si.game_type == GI.GT_CUSTOM
games = list(map(self.app.gdb.get,
self.app.gdb.getGamesIdSortedByName()))
games = list(filter(select_func, games))
self.updateGamesMenu(menu, games)
self.updateCustomGamesMenu()
self.tkopt.gameid.set(gameid)
self._mSelectGame(gameid, force=True)
@ -1746,6 +1761,21 @@ Error while saving game.
return
self.wizardDialog(edit=True)
def mWizardDelete(self, *event):
if self._cancelDrag(break_pause=False):
return
if not self.game.areYouSure(_("Delete game"),
_("Delete the game "
+ self.game.gameinfo.name + "?")):
return
from pysollib.wizardutil import delete_game
delete_game(self.game)
self.game.endGame()
self.game.quitGame(2)
if SELECT_GAME_MENU:
self.updateCustomGamesMenu()
def toolbarConfig(self, w, v):
if self._cancelDrag(break_pause=False):
return

View file

@ -23,7 +23,7 @@
import os
from pysollib.gamedb import GI, loadGame
from pysollib.gamedb import GI, loadGame, hideGame
from pysollib.layout import Layout
from pysollib.mygettext import _, n_
from pysollib.stack import AC_FoundationStack, \
@ -451,6 +451,12 @@ registerCustomGame(MyCustomGame)
return gameid
def delete_game(game):
hideGame(game)
fn = game.MODULE_FILENAME
os.remove(fn)
def reset_wizard(game):
for w in WizardWidgets:
if isinstance(w, six.string_types):