mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Add "Export current layout".
A menu option in the tile (for now only that) menubar. TODO: the tile and tk directories contain *a lot* of duplicate code. One should extract base classes and abstract.
This commit is contained in:
parent
8a5b8de137
commit
b03ec17350
2 changed files with 42 additions and 4 deletions
|
@ -790,7 +790,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
|||
else:
|
||||
return False
|
||||
|
||||
def _calcBoard(self):
|
||||
def calcBoardString(self):
|
||||
game = self.game
|
||||
board = ''
|
||||
#
|
||||
|
@ -833,7 +833,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
|||
game_type = self.game_type
|
||||
progress = self.options['progress']
|
||||
|
||||
board = self._calcBoard()
|
||||
board = self.calcBoardString()
|
||||
#
|
||||
if DEBUG:
|
||||
print '--------------------\n', board, '--------------------'
|
||||
|
@ -989,7 +989,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
|||
class BlackHoleSolver_Hint(Base_Solver_Hint):
|
||||
BLACK_HOLE_SOLVER_COMMAND = 'black-hole-solve'
|
||||
|
||||
def _calcBoard(self):
|
||||
def calcBoardString(self):
|
||||
board = ''
|
||||
cards = self.game.s.foundations[0].cards
|
||||
s = '-'
|
||||
|
@ -1013,7 +1013,7 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
|||
game_type = self.game_type
|
||||
progress = self.options['progress']
|
||||
|
||||
board = self._calcBoard()
|
||||
board = self.calcBoardString()
|
||||
#
|
||||
if DEBUG:
|
||||
print '--------------------\n', board, '--------------------'
|
||||
|
|
|
@ -357,6 +357,7 @@ class PysolMenubarTk:
|
|||
menu.add_command(label=n_("&Open..."), command=self.mOpen, accelerator=m+"O")
|
||||
menu.add_command(label=n_("&Save"), command=self.mSave, accelerator=m+"S")
|
||||
menu.add_command(label=n_("Save &as..."), command=self.mSaveAs)
|
||||
menu.add_command(label=n_("E&xport current layout..."), command=self.mExportCurrentLayout)
|
||||
menu.add_separator()
|
||||
menu.add_command(label=n_("&Hold and quit"), command=self.mHoldAndQuit, accelerator=m+"X")
|
||||
if WIN_SYSTEM != "aqua":
|
||||
|
@ -1001,6 +1002,43 @@ class PysolMenubarTk:
|
|||
if os.path.isfile(filename):
|
||||
self.game.loadGame(filename)
|
||||
|
||||
def mExportCurrentLayout(self, *event):
|
||||
if self._cancelDrag(break_pause=False): return
|
||||
game = self.game
|
||||
if not self.menustate.save_as:
|
||||
return
|
||||
if not game.Solver_Class:
|
||||
d = MfxMessageDialog(self.top, title=_('Export game error'),
|
||||
text=_('''
|
||||
Unsupported game for export.
|
||||
'''),
|
||||
bitmap='error')
|
||||
return
|
||||
|
||||
filename = game.filename
|
||||
if not filename:
|
||||
filename = self.app.getGameSaveName(self.game.id)
|
||||
if os.name == "posix" or os.path.supports_unicode_filenames:
|
||||
filename += "-" + self.game.getGameNumber(format=0)
|
||||
else:
|
||||
filename += "-01"
|
||||
filename += ".board"
|
||||
idir, ifile = os.path.split(os.path.normpath(filename))
|
||||
if not idir:
|
||||
idir = self.app.dn.savegames
|
||||
##print self.game.filename, ifile
|
||||
d = tkFileDialog.SaveAs()
|
||||
filename = d.show(filetypes=self.FILETYPES,
|
||||
defaultextension=self.DEFAULTEXTENSION,
|
||||
initialdir=idir, initialfile=ifile)
|
||||
if filename:
|
||||
filename = os.path.normpath(filename)
|
||||
##filename = os.path.normcase(filename)
|
||||
with open(filename, 'w') as fh:
|
||||
game = self.game
|
||||
fh.write(game.Solver_Class(game, self).calcBoardString())
|
||||
self.updateMenus()
|
||||
|
||||
def mSaveAs(self, *event):
|
||||
if self._cancelDrag(break_pause=False): return
|
||||
if not self.menustate.save_as:
|
||||
|
|
Loading…
Add table
Reference in a new issue