Skip to content

Commit

Permalink
Add "Export current layout".
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shlomif committed Feb 13, 2016
1 parent 8a5b8de commit b03ec17
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pysollib/hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def _determineIfSolverState(self, line):
else:
return False

def _calcBoard(self):
def calcBoardString(self):
game = self.game
board = ''
#
Expand Down Expand Up @@ -833,7 +833,7 @@ def computeHints(self):
game_type = self.game_type
progress = self.options['progress']

board = self._calcBoard()
board = self.calcBoardString()
#
if DEBUG:
print '--------------------\n', board, '--------------------'
Expand Down Expand Up @@ -989,7 +989,7 @@ def computeHints(self):
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 = '-'
Expand All @@ -1013,7 +1013,7 @@ def computeHints(self):
game_type = self.game_type
progress = self.options['progress']

board = self._calcBoard()
board = self.calcBoardString()
#
if DEBUG:
print '--------------------\n', board, '--------------------'
Expand Down
38 changes: 38 additions & 0 deletions pysollib/tile/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def _createMenubar(self):
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":
Expand Down Expand Up @@ -1001,6 +1002,43 @@ def mOpen(self, *event):
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:
Expand Down

0 comments on commit b03ec17

Please sign in to comment.