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

added settings for offsets of cards; bugfixes

git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@277 efabe8c0-fbe8-4139-b769-b5e6d273206e
This commit is contained in:
skomoroh 2012-06-05 18:37:12 +00:00
parent ee53b7320d
commit cbd51240c5
9 changed files with 150 additions and 78 deletions

View file

@ -43,13 +43,13 @@ pot:
done
mo:
for loc in ru ru_RU de de_AT de_BE de_DE de_LU de_CH pl pl_PL; do \
for loc in ru ru_RU de de_AT de_BE de_DE de_LU de_CH pl pl_PL it it_IT; do \
test -d locale/$${loc}/LC_MESSAGES || mkdir -p locale/$${loc}/LC_MESSAGES; \
done
for lang in ru pl; do \
msgcat po/$${lang}_games.po po/$${lang}_pysol.po > po/$${lang}.po 2>/dev/null; \
for lang in ru pl it; do \
msgcat --use-first po/$${lang}_games.po po/$${lang}_pysol.po > po/$${lang}.po 2>/dev/null; \
done
for lang in ru de pl; do \
for lang in ru de pl it; do \
msgfmt -o locale/$${lang}/LC_MESSAGES/pysol.mo po/$${lang}.po; \
done
cp -f locale/ru/LC_MESSAGES/pysol.mo locale/ru_RU/LC_MESSAGES/pysol.mo
@ -57,3 +57,4 @@ mo:
cp -f locale/de/LC_MESSAGES/pysol.mo locale/$${dir}/LC_MESSAGES/pysol.mo; \
done
cp -f locale/pl/LC_MESSAGES/pysol.mo locale/pl_PL/LC_MESSAGES/pysol.mo
cp -f locale/it/LC_MESSAGES/pysol.mo locale/it_IT/LC_MESSAGES/pysol.mo

View file

@ -1011,27 +1011,39 @@ Please select a %s type %s.
self.loadCardset(cs, id=id)
return 1
def __selectCardsetDialog(self, t):
key = self.cardset.index
def selectCardset(self, title, key):
d = SelectCardsetDialogWithPreview(
self.top, title=_("Please select a %s type %s") % (t[0], CARDSET),
app=self, manager=self.cardset_manager, key=key,
strings=(None, _("&OK"), _("&Cancel")), default=1)
if d.status != 0 or d.button != 1:
return None
self.top, title=title, app=self,
manager=self.cardset_manager, key=key)
cs = self.cardset_manager.get(d.key)
changed = (self.opt.scale_x,
self.opt.scale_y,
self.opt.auto_scale,
self.opt.preserve_aspect_ratio) != d.scale_values
if cs is None:
if d.status != 0 or d.button != 0 or d.key < 0 or cs is None:
return None
if d.key == key and not changed:
changed = False
if USE_PIL:
if (self.opt.scale_x, self.opt.scale_y,
self.opt.auto_scale, self.opt.preserve_aspect_ratio) != \
d.scale_values or \
(cs.CARD_XOFFSET, cs.CARD_YOFFSET) != d.cardset_values:
changed = True
if d.key == self.cardset.index and not changed:
return None
(self.opt.scale_x,
self.opt.scale_y,
self.opt.auto_scale,
self.opt.preserve_aspect_ratio) = d.scale_values
if USE_PIL:
(self.opt.scale_x,
self.opt.scale_y,
self.opt.auto_scale,
self.opt.preserve_aspect_ratio) = d.scale_values
if not self.opt.auto_scale:
self.images.resize(self.opt.scale_x, self.opt.scale_y)
if d.cardset_values:
cs.CARD_XOFFSET, cs.CARD_YOFFSET = d.cardset_values
self.opt.offsets[cs.ident] = d.cardset_values
self.images.setOffsets()
return cs
def __selectCardsetDialog(self, t):
cs = self.selectCardset(
_("Please select a %s type %s") % (t[0], CARDSET),
self.cardset.index)
return cs
@ -1381,6 +1393,9 @@ Please select a %s type %s.
else:
cs.backnames.insert(0, back)
cs.backindex = 0
# set offsets from options.cfg
if cs.ident in self.opt.offsets:
cs.CARD_XOFFSET, cs.CARD_YOFFSET = self.opt.offsets[cs.ident]
##if cs.type != 1: print cs.type, cs.name
return 1

View file

@ -342,8 +342,23 @@ class Images:
self._bottom = self._bottom_positive
self._letter = self._letter_positive
def setOffsets(self):
cs = self.cs
if cs is None:
return
r = self.reduced
if r > 1:
self.CARD_XOFFSET = max(10/r, cs.CARD_XOFFSET)
self.CARD_YOFFSET = max(10/r, cs.CARD_YOFFSET)
else:
self.CARD_XOFFSET = cs.CARD_XOFFSET
self.CARD_YOFFSET = cs.CARD_YOFFSET
self.SHADOW_XOFFSET = cs.SHADOW_XOFFSET
self.SHADOW_YOFFSET = cs.SHADOW_YOFFSET
self.CARD_DX, self.CARD_DY = cs.CARD_DX, cs.CARD_DY
def _setSize(self, xf=1, yf=1):
#print 'Images._setSize', xf, yf
#print 'image._setSize', xf, yf
self._xfactor = xf
self._yfactor = yf
cs = self.cs
@ -352,17 +367,9 @@ class Images:
r = self.reduced
xf = float(xf)/r
yf = float(yf)/r
# copy from cardset
# from cardset
self.CARDW, self.CARDH = int(cs.CARDW*xf), int(cs.CARDH*yf)
if r > 1:
self.CARD_XOFFSET = max(10/r, int(cs.CARD_XOFFSET*xf))
self.CARD_YOFFSET = max(10/r, int(cs.CARD_YOFFSET*yf))
else:
self.CARD_XOFFSET = int(cs.CARD_XOFFSET*xf)
self.CARD_YOFFSET = int(cs.CARD_YOFFSET*yf)
self.SHADOW_XOFFSET = int(cs.SHADOW_XOFFSET*xf)
self.SHADOW_YOFFSET = int(cs.SHADOW_YOFFSET*yf)
self.CARD_DX, self.CARD_DY = int(cs.CARD_DX*xf), int(cs.CARD_DY*yf)
self.setOffsets()
def getSize(self):
return (int(self.CARDW * self._xfactor),
@ -375,12 +382,14 @@ class Images:
int(self.CARD_DY * self._yfactor))
def resize(self, xf, yf):
#print 'Images.resize:', xf, yf, self._card[0].width()
#print 'Images.resize:', xf, yf, self._card[0].width(), self.CARDW
if self._xfactor == xf and self._yfactor == yf:
#print 'no resize'
return
self._xfactor = xf
self._yfactor = yf
#???self._setSize(xf, yf)
self.setOffsets()
# cards
cards = []
for c in self._card:

View file

@ -166,7 +166,7 @@ def init():
if os.name == 'posix':
os.wait() # kill zombi
except:
traceback.print_exc()
#traceback.print_exc()
pass
os.environ['FREECELL_SOLVER_QUIET'] = '1'

View file

@ -374,6 +374,7 @@ class Options:
self.save_games_geometry = False
self.games_geometry = {} # saved games geometry (gameid: (width, height))
self.game_geometry = (0, 0) # game geometry before exit
self.offsets = {} # cards offsets
#
self.randomize_place = False
self.save_cardsets = True
@ -517,6 +518,10 @@ class Options:
config['games_geometry'][str(key)] = val
config['general']['game_geometry'] = self.game_geometry
# offsets
for key, val in self.offsets.items():
config['offsets'][key] = val
config.write()
##config.write(sys.stdout); print
@ -568,6 +573,7 @@ class Options:
'timeouts',
'cardsets',
'games_geometry',
'offsets',
):
if section not in config:
config[section] = {}
@ -693,4 +699,13 @@ class Options:
except:
traceback.print_exc()
# cards offsets
for key, val in config['offsets'].items():
try:
val = [int(i) for i in val]
assert len(val) == 2
self.offsets[key] = val
except:
traceback.print_exc()

View file

@ -383,6 +383,9 @@ class Cardset(Resource):
self.backindex = backindex % len(self.backnames)
self.backname = self.backnames[self.backindex]
def saveSettings(self):
print 'saveSettings'
class CardsetManager(ResourceManager):
def __init__(self):

View file

@ -358,11 +358,11 @@ class Stack:
assert self.cap.max_move <= 1
# prepare some variables
ox, oy = self.CARD_XOFFSET, self.CARD_YOFFSET
if isinstance(ox, int):
if isinstance(ox, (int, float)):
self.CARD_XOFFSET = (ox,)
else:
self.CARD_XOFFSET = tuple([int(round(x)) for x in ox])
if isinstance(oy, int):
if isinstance(oy, (int, float)):
self.CARD_YOFFSET = (oy,)
else:
self.CARD_YOFFSET = tuple([int(round(y)) for y in oy])
@ -394,7 +394,7 @@ class Stack:
## # and the images don't match
## self.max_shadow_cards = 1
if (self.game.app.opt.shrink_face_down and
isinstance(ox, int) and isinstance(oy, int)):
isinstance(ox, (int, float)) and isinstance(oy, (int, float))):
# no shrink if xoffset/yoffset too small
f = self.SHRINK_FACTOR
if ((ox == 0 and oy >= self.game.app.images.CARD_YOFFSET/f) or

View file

@ -1199,35 +1199,14 @@ class PysolMenubarTk:
def mSelectCardsetDialog(self, *event):
if self._cancelDrag(break_pause=False): return
t = CARDSET
key = self.app.nextgame.cardset.index
d = SelectCardsetDialogWithPreview(self.top, title=_("Select ")+t,
app=self.app, manager=self.app.cardset_manager, key=key)
cs = self.app.cardset_manager.get(d.key)
if d.status != 0 or d.button != 0 or cs is None:
cs = self.app.selectCardset(_("Select ")+CARDSET, key)
if not cs:
return
if USE_PIL:
changed = (self.app.opt.scale_x,
self.app.opt.scale_y,
self.app.opt.auto_scale,
self.app.opt.preserve_aspect_ratio) != d.scale_values
else:
changed = False
if d.key == self.app.cardset.index and not changed:
return
if d.key >= 0:
self.app.nextgame.cardset = cs
if USE_PIL:
(self.app.opt.scale_x,
self.app.opt.scale_y,
self.app.opt.auto_scale,
self.app.opt.preserve_aspect_ratio) = d.scale_values
if not self.app.opt.auto_scale:
self.app.images.resize(self.app.opt.scale_x,
self.app.opt.scale_y)
self._cancelDrag()
self.game.endGame(bookmark=1)
self.game.quitGame(bookmark=1)
self.app.nextgame.cardset = cs
self._cancelDrag()
self.game.endGame(bookmark=1)
self.game.quitGame(bookmark=1)
def _mOptCardback(self, index):
if self._cancelDrag(break_pause=False): return

View file

@ -25,6 +25,7 @@ __all__ = ['SelectCardsetDialogWithPreview']
# imports
import os
import traceback
import Tkinter
import ttk
@ -180,6 +181,7 @@ class SelectCardsetDialogWithPreview(MfxDialog):
self.manager = manager
self.key = key
self.app = app
self.cardset_values = None
#padx, pady = kw.padx, kw.pady
padx, pady = 5, 5
if self.TreeDataHolder_Class.data is None:
@ -272,9 +274,13 @@ class SelectCardsetDialogWithPreview(MfxDialog):
MfxDialog.destroy(self)
def initKw(self, kw):
if USE_PIL:
s = (_("&Info / Settings..."), 10)
else:
s = (_("&Info..."), 10)
kw = KwStruct(kw,
strings = ((_("&Info..."), 10), 'sep',
_("&Load"), _("&Cancel"),),
strings = (s, 'sep',
_("&OK"), _("&Cancel"),),
default=0,
resizable=True,
)
@ -304,7 +310,9 @@ class SelectCardsetDialogWithPreview(MfxDialog):
return
##title = CARDSET+" "+cs.name
title = CARDSET.capitalize()+" "+cs.name
CardsetInfoDialog(self.top, title=title, cardset=cs, images=self.preview_images)
d = CardsetInfoDialog(self.top, title=title, cardset=cs,
images=self.preview_images)
self.cardset_values = d.cardset_values
return
MfxDialog.mDone(self, button)
@ -388,9 +396,11 @@ class CardsetInfoDialog(MfxDialog):
frame.pack(fill="both", expand=True, padx=5, pady=10)
#
#
row = 0
info_frame = ttk.LabelFrame(frame, text=_('About cardset'))
info_frame.grid(row=0, column=0, columnspan=2, sticky='ew',
info_frame.grid(row=row, column=0, columnspan=2, sticky='ew',
padx=0, pady=5, ipadx=5, ipady=5)
row += 1
styles = nationalities = year = None
if cardset.si.styles:
styles = '\n'.join([CSI.STYLE[i] for i in cardset.si.styles])
@ -399,7 +409,7 @@ class CardsetInfoDialog(MfxDialog):
for i in cardset.si.nationalities])
if cardset.year:
year = str(cardset.year)
row = 0
frow = 0
for n, t in (
##('Version:', str(cardset.version)),
(_('Type:'), CSI.TYPE[cardset.type]),
@ -412,11 +422,11 @@ class CardsetInfoDialog(MfxDialog):
if t is not None:
l = ttk.Label(info_frame, text=n,
anchor='w', justify='left')
l.grid(row=row, column=0, sticky='nw', padx=4)
l.grid(row=frow, column=0, sticky='nw', padx=4)
l = ttk.Label(info_frame, text=t,
anchor='w', justify='left')
l.grid(row=row, column=1, sticky='nw', padx=4)
row += 1
l.grid(row=frow, column=1, sticky='nw', padx=4)
frow += 1
if images:
try:
from random import choice
@ -424,22 +434,52 @@ class CardsetInfoDialog(MfxDialog):
f = os.path.join(cardset.dir, cardset.backname)
self.back_image = loadImage(file=f) # store the image
l = ttk.Label(info_frame, image=im, padding=5)
l.grid(row=0, column=2, rowspan=row+1, sticky='ne')
l.grid(row=0, column=2, rowspan=frow+1, sticky='ne')
l = ttk.Label(info_frame, image=self.back_image,
padding=(0,5,5,5)) # left margin = 0
l.grid(row=0, column=3, rowspan=row+1, sticky='ne')
l.grid(row=0, column=3, rowspan=frow+1, sticky='ne')
info_frame.columnconfigure(2, weight=1)
info_frame.rowconfigure(row, weight=1)
info_frame.rowconfigure(frow, weight=1)
except:
traceback.print_exc()
pass
if USE_PIL:
padx = 4
pady = 0
settings_frame = ttk.LabelFrame(frame, text=_('Settings'))
settings_frame.grid(row=row, column=0, columnspan=2, sticky='ew',
padx=0, pady=5, ipadx=5, ipady=5)
row += 1
var = Tkinter.IntVar()
self.x_offset = PysolScale(
settings_frame, label=_('X offset:'),
from_=5, to=40, resolution=1,
orient='horizontal', variable=var,
value=cardset.CARD_XOFFSET,
#command=self._updateScale
)
self.x_offset.grid(row=0, column=0, sticky='ew',
padx=padx, pady=pady)
var = Tkinter.IntVar()
self.y_offset = PysolScale(
settings_frame, label=_('Y offset:'),
from_=5, to=40, resolution=1,
orient='horizontal', variable=var,
value=cardset.CARD_YOFFSET,
#command=self._updateScale
)
self.y_offset.grid(row=1, column=0, sticky='ew',
padx=padx, pady=pady)
row += 1
##bg = top_frame["bg"]
bg = 'white'
text_w = Tkinter.Text(frame, bd=1, relief="sunken", wrap="word",
padx=4, width=64, height=16, bg=bg)
text_w.grid(row=1, column=0, sticky='nsew')
text_w.grid(row=row, column=0, sticky='nsew')
sb = ttk.Scrollbar(frame)
sb.grid(row=1, column=1, sticky='ns')
sb.grid(row=row, column=1, sticky='ns')
text_w.configure(yscrollcommand=sb.set)
sb.configure(command=text_w.yview)
frame.columnconfigure(0, weight=1)
@ -461,12 +501,22 @@ class CardsetInfoDialog(MfxDialog):
self.mainloop(focus, kw.timeout)
def initKw(self, kw):
if USE_PIL:
strings = (_("&Save"),_("&Cancel"))
else:
strings = (_("&OK"),)
kw = KwStruct(kw,
strings=(_("&OK"),),
strings=strings,
default=0,
resizable=True,
separator=True,
)
return MfxDialog.initKw(self, kw)
def mDone(self, button):
if USE_PIL and button == 0:
self.cardset_values = self.x_offset.get(), self.y_offset.get()
else:
self.cardset_values = None
MfxDialog.mDone(self, button)