mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
* fixed bug with flipAllMove
* improved toolbar: set `pause' button as checkbutton git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@25 efabe8c0-fbe8-4139-b769-b5e6d273206e
This commit is contained in:
parent
fab79bb483
commit
7d832033b2
7 changed files with 69 additions and 38 deletions
|
@ -934,7 +934,9 @@ class Game:
|
||||||
return
|
return
|
||||||
if self.app.debug and not self.top.winfo_ismapped():
|
if self.app.debug and not self.top.winfo_ismapped():
|
||||||
return
|
return
|
||||||
self.top.busyUpdate()
|
#self.top.busyUpdate()
|
||||||
|
self.canvas.after(200)
|
||||||
|
self.canvas.update_idletasks()
|
||||||
old_a = self.app.opt.animations
|
old_a = self.app.opt.animations
|
||||||
if old_a == 0:
|
if old_a == 0:
|
||||||
self.app.opt.animations = 1 # timer based
|
self.app.opt.animations = 1 # timer based
|
||||||
|
|
|
@ -107,7 +107,7 @@ class DoubleBisley(Bisley):
|
||||||
l, s = Layout(self), self.s
|
l, s = Layout(self), self.s
|
||||||
|
|
||||||
# set window
|
# set window
|
||||||
w, h = l.XM+(8+4)*l.XS, l.YM+max(3*(l.YS+8*l.YOFFSET), 8*l.YS)
|
w, h = l.XM+(8+2)*l.XS, l.YM+max(3*(l.YS+8*l.YOFFSET), 8*l.YS)
|
||||||
self.setSize(w, h)
|
self.setSize(w, h)
|
||||||
|
|
||||||
# create stacks
|
# create stacks
|
||||||
|
|
|
@ -168,12 +168,12 @@ class PictureGallery_TableauStack(SS_RowStack):
|
||||||
def getBottomImage(self):
|
def getBottomImage(self):
|
||||||
return self.game.app.images.getLetter(self.cap.base_rank)
|
return self.game.app.images.getLetter(self.cap.base_rank)
|
||||||
|
|
||||||
def closeStackMove(self):
|
## def closeStackMove(self):
|
||||||
if len(self.cards) == self.cap.max_cards:
|
## if len(self.cards) == self.cap.max_cards:
|
||||||
self.game.flipAllMove(self)
|
## self.game.closeStackMove(self)
|
||||||
|
## ##self.game.flipAllMove(self)
|
||||||
def canFlipCard(self):
|
## def canFlipCard(self):
|
||||||
return False
|
## return False
|
||||||
|
|
||||||
|
|
||||||
class PictureGallery_RowStack(BasicRowStack):
|
class PictureGallery_RowStack(BasicRowStack):
|
||||||
|
|
|
@ -281,9 +281,9 @@ class LarasGame(Game):
|
||||||
s.talon = self.Talon_Class(x, y, self, max_rounds=self.MAX_ROUNDS)
|
s.talon = self.Talon_Class(x, y, self, max_rounds=self.MAX_ROUNDS)
|
||||||
l.createText(s.talon, "s")
|
l.createText(s.talon, "s")
|
||||||
if self.MAX_ROUNDS - 1:
|
if self.MAX_ROUNDS - 1:
|
||||||
|
tx, ty, ta, tf = l.getTextAttr(s.talon, "nn")
|
||||||
s.talon.texts.rounds = MfxCanvasText(self.canvas,
|
s.talon.texts.rounds = MfxCanvasText(self.canvas,
|
||||||
x + l.XS / 2, y - l.YM,
|
tx, ty, anchor=ta,
|
||||||
anchor="center",
|
|
||||||
font=self.app.getFont("canvas_default"))
|
font=self.app.getFont("canvas_default"))
|
||||||
y = h - l.YS * 2
|
y = h - l.YS * 2
|
||||||
s.rows.append(LarasGame_RowStack(x, y, self, yoffset=0))
|
s.rows.append(LarasGame_RowStack(x, y, self, yoffset=0))
|
||||||
|
|
|
@ -142,19 +142,17 @@ class AFlipAllMove(AtomicMove):
|
||||||
def __init__(self, stack):
|
def __init__(self, stack):
|
||||||
self.stack_id = stack.id
|
self.stack_id = stack.id
|
||||||
|
|
||||||
# do the actual move
|
def redo(self, game):
|
||||||
def __doMove(self, game, stack):
|
stack = game.allstacks[self.stack_id]
|
||||||
for card in stack.cards:
|
for card in stack.cards:
|
||||||
if card.face_up:
|
if card.face_up:
|
||||||
card.showBack()
|
card.showBack()
|
||||||
else:
|
|
||||||
card.showFace()
|
|
||||||
|
|
||||||
def redo(self, game):
|
|
||||||
self.__doMove(game, game.allstacks[self.stack_id])
|
|
||||||
|
|
||||||
def undo(self, game):
|
def undo(self, game):
|
||||||
self.__doMove(game, game.allstacks[self.stack_id])
|
stack = game.allstacks[self.stack_id]
|
||||||
|
for card in stack.cards:
|
||||||
|
if not card.face_up:
|
||||||
|
card.showFace()
|
||||||
|
|
||||||
def cmpForRedo(self, other):
|
def cmpForRedo(self, other):
|
||||||
return cmp(self.stack_id, other.stack_id)
|
return cmp(self.stack_id, other.stack_id)
|
||||||
|
|
|
@ -828,6 +828,8 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
filename = self.app.getGameSaveName(self.game.id)
|
filename = self.app.getGameSaveName(self.game.id)
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
filename = filename + "-" + self.game.getGameNumber(format=0)
|
filename = filename + "-" + self.game.getGameNumber(format=0)
|
||||||
|
elif os.path.supports_unicode_filenames: # new in python 2.3
|
||||||
|
filename = filename + "-" + self.game.getGameNumber(format=0)
|
||||||
else:
|
else:
|
||||||
filename = filename + "-01"
|
filename = filename + "-01"
|
||||||
filename = filename + self.DEFAULTEXTENSION
|
filename = filename + self.DEFAULTEXTENSION
|
||||||
|
|
|
@ -63,18 +63,18 @@ n_ = lambda x: x
|
||||||
# //
|
# //
|
||||||
# ************************************************************************/
|
# ************************************************************************/
|
||||||
|
|
||||||
class ToolbarButton(Tkinter.Button):
|
class AbstractToolbarButton:
|
||||||
def __init__(self, parent, toolbar, toolbar_name, position, **kwargs):
|
def __init__(self, parent, toolbar, toolbar_name, position):
|
||||||
Tkinter.Button.__init__(self, parent, kwargs)
|
|
||||||
self.toolbar = toolbar
|
self.toolbar = toolbar
|
||||||
self.toolbar_name = toolbar_name
|
self.toolbar_name = toolbar_name
|
||||||
self.position = position
|
self.position = position
|
||||||
self.visible = False
|
self.visible = False
|
||||||
|
|
||||||
def show(self, orient, force=False):
|
def show(self, orient, force=False):
|
||||||
if self.visible and not force:
|
if self.visible and not force:
|
||||||
return
|
return
|
||||||
self.visible = True
|
self.visible = True
|
||||||
padx, pady= 2, 2
|
padx, pady = 2, 2
|
||||||
if orient == Tkinter.HORIZONTAL:
|
if orient == Tkinter.HORIZONTAL:
|
||||||
self.grid(row=0,
|
self.grid(row=0,
|
||||||
column=self.position,
|
column=self.position,
|
||||||
|
@ -85,11 +85,25 @@ class ToolbarButton(Tkinter.Button):
|
||||||
column=0,
|
column=0,
|
||||||
ipadx=padx, ipady=pady,
|
ipadx=padx, ipady=pady,
|
||||||
sticky='nsew')
|
sticky='nsew')
|
||||||
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
if not self.visible: return
|
if not self.visible: return
|
||||||
self.visible = False
|
self.visible = False
|
||||||
self.grid_forget()
|
self.grid_forget()
|
||||||
|
|
||||||
|
|
||||||
|
class ToolbarCheckbutton(AbstractToolbarButton, Tkinter.Checkbutton):
|
||||||
|
def __init__(self, parent, toolbar, toolbar_name, position, **kwargs):
|
||||||
|
Tkinter.Checkbutton.__init__(self, parent, kwargs)
|
||||||
|
AbstractToolbarButton.__init__(self, parent, toolbar, toolbar_name, position)
|
||||||
|
|
||||||
|
|
||||||
|
class ToolbarButton(AbstractToolbarButton, Tkinter.Button):
|
||||||
|
def __init__(self, parent, toolbar, toolbar_name, position, **kwargs):
|
||||||
|
Tkinter.Button.__init__(self, parent, kwargs)
|
||||||
|
AbstractToolbarButton.__init__(self, parent, toolbar, toolbar_name, position)
|
||||||
|
|
||||||
|
|
||||||
class ToolbarSeparator(Tkinter.Frame):
|
class ToolbarSeparator(Tkinter.Frame):
|
||||||
def __init__(self, parent, toolbar, position, **kwargs):
|
def __init__(self, parent, toolbar, position, **kwargs):
|
||||||
Tkinter.Frame.__init__(self, parent, kwargs)
|
Tkinter.Frame.__init__(self, parent, kwargs)
|
||||||
|
@ -200,6 +214,8 @@ class PysolToolbar(PysolToolbarActions):
|
||||||
sep = self._createSeparator()
|
sep = self._createSeparator()
|
||||||
sep.bind("<1>", self.clickHandler)
|
sep.bind("<1>", self.clickHandler)
|
||||||
sep.bind("<3>", self.rightclickHandler)
|
sep.bind("<3>", self.rightclickHandler)
|
||||||
|
elif l == 'Pause':
|
||||||
|
self._createButton(l, f, check=True, tooltip=t)
|
||||||
else:
|
else:
|
||||||
self._createButton(l, f, tooltip=t)
|
self._createButton(l, f, tooltip=t)
|
||||||
|
|
||||||
|
@ -322,24 +338,33 @@ class PysolToolbar(PysolToolbarActions):
|
||||||
self._widgets.append(sep)
|
self._widgets.append(sep)
|
||||||
return sep
|
return sep
|
||||||
|
|
||||||
def _createButton(self, label, command, tooltip=None):
|
def _createButton(self, label, command, check=False, tooltip=None):
|
||||||
name = label.lower()
|
name = label.lower()
|
||||||
image = self._loadImage(name)
|
image = self._loadImage(name)
|
||||||
position = len(self._widgets)
|
position = len(self._widgets)
|
||||||
bd = self.button_relief == 'flat' and 1 or 2
|
bd = self.button_relief == 'flat' and 1 or 2
|
||||||
button = ToolbarButton(self.frame,
|
kw = {
|
||||||
position=position,
|
'position': position,
|
||||||
toolbar=self,
|
'toolbar': self,
|
||||||
toolbar_name=name,
|
'toolbar_name': name,
|
||||||
command=command, takefocus=0,
|
'command': command,
|
||||||
text=gettext(label),
|
'takefocus': 0,
|
||||||
bd=bd,
|
'text': gettext(label),
|
||||||
relief=self.button_relief,
|
'bd': bd,
|
||||||
overrelief='raised',
|
'relief': self.button_relief,
|
||||||
padx=self.button_pad,
|
'overrelief': 'raised',
|
||||||
pady=self.button_pad)
|
'padx': self.button_pad,
|
||||||
|
'pady': self.button_pad
|
||||||
|
}
|
||||||
if image:
|
if image:
|
||||||
button.config(image=image)
|
kw['image'] = image
|
||||||
|
if check:
|
||||||
|
kw['offrelief'] = self.button_relief
|
||||||
|
kw['indicatoron'] = False
|
||||||
|
kw['selectcolor'] = ''
|
||||||
|
button = ToolbarCheckbutton(self.frame, **kw)
|
||||||
|
else:
|
||||||
|
button = ToolbarButton(self.frame, **kw)
|
||||||
button.show(orient=self.orient)
|
button.show(orient=self.orient)
|
||||||
setattr(self, name + "_image", image)
|
setattr(self, name + "_image", image)
|
||||||
setattr(self, name + "_button", button)
|
setattr(self, name + "_button", button)
|
||||||
|
@ -435,6 +460,7 @@ class PysolToolbar(PysolToolbarActions):
|
||||||
self.popup = None
|
self.popup = None
|
||||||
if menubar:
|
if menubar:
|
||||||
tkopt = menubar.tkopt
|
tkopt = menubar.tkopt
|
||||||
|
self.pause_button.config(variable=tkopt.pause)
|
||||||
self.popup = MfxMenu(master=None, label=n_('Toolbar'), tearoff=0)
|
self.popup = MfxMenu(master=None, label=n_('Toolbar'), tearoff=0)
|
||||||
createToolbarMenu(menubar, self.popup)
|
createToolbarMenu(menubar, self.popup)
|
||||||
|
|
||||||
|
@ -453,7 +479,7 @@ class PysolToolbar(PysolToolbarActions):
|
||||||
data = []
|
data = []
|
||||||
try:
|
try:
|
||||||
for w in self._widgets:
|
for w in self._widgets:
|
||||||
if not isinstance(w, ToolbarButton):
|
if not isinstance(w, (ToolbarButton, ToolbarCheckbutton)):
|
||||||
continue
|
continue
|
||||||
name = w.toolbar_name
|
name = w.toolbar_name
|
||||||
image = self._loadImage(name)
|
image = self._loadImage(name)
|
||||||
|
@ -476,9 +502,12 @@ class PysolToolbar(PysolToolbarActions):
|
||||||
self._setRelief(relief)
|
self._setRelief(relief)
|
||||||
self.frame.config(relief=self.frame_relief)
|
self.frame.config(relief=self.frame_relief)
|
||||||
for w in self._widgets:
|
for w in self._widgets:
|
||||||
if isinstance(w, ToolbarButton):
|
|
||||||
bd = relief == 'flat' and 1 or 2
|
bd = relief == 'flat' and 1 or 2
|
||||||
|
if isinstance(w, ToolbarButton):
|
||||||
w.config(relief=self.button_relief, bd=bd)
|
w.config(relief=self.button_relief, bd=bd)
|
||||||
|
elif isinstance(w, ToolbarCheckbutton):
|
||||||
|
w.config(relief=self.button_relief,
|
||||||
|
offrelief=self.button_relief, bd=bd)
|
||||||
elif w.__class__ is ToolbarSeparator: # not ToolbarFlatSeparator
|
elif w.__class__ is ToolbarSeparator: # not ToolbarFlatSeparator
|
||||||
w.config(relief=self.separator_relief)
|
w.config(relief=self.separator_relief)
|
||||||
return True
|
return True
|
||||||
|
@ -487,7 +516,7 @@ class PysolToolbar(PysolToolbarActions):
|
||||||
if not force and self.compound == compound:
|
if not force and self.compound == compound:
|
||||||
return False
|
return False
|
||||||
for w in self._widgets:
|
for w in self._widgets:
|
||||||
if not isinstance(w, ToolbarButton):
|
if not isinstance(w, (ToolbarButton, ToolbarCheckbutton)):
|
||||||
continue
|
continue
|
||||||
if compound == 'text':
|
if compound == 'text':
|
||||||
w.config(compound=Tkinter.NONE, image='')
|
w.config(compound=Tkinter.NONE, image='')
|
||||||
|
|
Loading…
Add table
Reference in a new issue