本文整理汇总了Python中pychess.System.glock.acquire函数的典型用法代码示例。如果您正苦于以下问题:Python acquire函数的具体用法?Python acquire怎么用?Python acquire使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acquire函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_rotation
def _set_rotation (self, radians):
if not conf.get("fullAnimation", True):
glock.acquire()
try:
self._rotation = radians
self.nextRotation = radians
self.matrix = cairo.Matrix.init_rotate(radians)
self.redraw_canvas()
finally:
glock.release()
else:
if hasattr(self, "nextRotation") and \
self.nextRotation != self.rotation:
return
self.nextRotation = radians
oldr = self.rotation
start = time()
def callback ():
glock.acquire()
try:
amount = (time()-start)/ANIMATION_TIME
if amount > 1:
amount = 1
next = False
else: next = True
self._rotation = new = oldr + amount*(radians-oldr)
self.matrix = cairo.Matrix.init_rotate(new)
self.redraw_canvas()
finally:
glock.release()
return next
repeat(callback)
示例2: __init__
def __init__(self, gamemodel):
gobject.GObject.__init__(self)
self.gamemodel = gamemodel
tabcontent = self.initTabcontents()
boardvbox, board, messageSock = self.initBoardAndClock(gamemodel)
statusbar, stat_hbox = self.initStatusbar(board)
self.tabcontent = tabcontent
self.board = board
self.statusbar = statusbar
self.messageSock = messageSock
self.notebookKey = gtk.Label()
self.notebookKey.set_size_request(0, 0)
self.boardvbox = boardvbox
self.stat_hbox = stat_hbox
# Some stuff in the sidepanels .load functions might change UI, so we
# need glock
# TODO: Really?
glock.acquire()
try:
self.panels = [panel.Sidepanel().load(self) for panel in sidePanels]
finally:
glock.release()
示例3: setLocked
def setLocked (self, locked):
do_animation = False
glock.acquire()
self.stateLock.acquire()
try:
if locked and self.isLastPlayed(self.getBoard()) and \
self.view.model.status == RUNNING:
if self.view.model.status != RUNNING:
self.view.selected = None
self.view.active = None
self.view.hover = None
self.view.draggedPiece = None
do_animation = True
if self.currentState == self.selectedState:
self.currentState = self.lockedSelectedState
elif self.currentState == self.activeState:
self.currentState = self.lockedActiveState
else:
self.currentState = self.lockedNormalState
else:
if self.currentState == self.lockedSelectedState:
self.currentState = self.selectedState
elif self.currentState == self.lockedActiveState:
self.currentState = self.activeState
else:
self.currentState = self.normalState
finally:
self.stateLock.release()
glock.release()
if do_animation:
self.view.startAnimation()
示例4: game_ended
def game_ended (gamemodel, reason, gmwidg):
nameDic = {"white": gamemodel.players[WHITE],
"black": gamemodel.players[BLACK],
"mover": gamemodel.curplayer}
if gamemodel.status == WHITEWON:
nameDic["winner"] = gamemodel.players[WHITE]
nameDic["loser"] = gamemodel.players[BLACK]
elif gamemodel.status == BLACKWON:
nameDic["winner"] = gamemodel.players[BLACK]
nameDic["loser"] = gamemodel.players[WHITE]
m1 = reprResult_long[gamemodel.status] % nameDic
m2 = reprReason_long[reason] % nameDic
md = gtk.MessageDialog()
md.set_markup("<b><big>%s</big></b>" % m1)
md.format_secondary_markup(m2)
if gamemodel.players[0].__type__ == LOCAL or gamemodel.players[1].__type__ == LOCAL:
if gamemodel.players[0].__type__ == REMOTE or gamemodel.players[1].__type__ == REMOTE:
md.add_button(_("Offer Rematch"), 0)
else:
md.add_button(_("Play Rematch"), 1)
if gamemodel.ply > 1:
md.add_button(_("Undo two moves"), 2)
elif gamemodel.ply == 1:
md.add_button(_("Undo one move"), 2)
def cb (messageDialog, responseId):
if responseId == 0:
if gamemodel.players[0].__type__ == REMOTE:
gamemodel.players[0].offerRematch()
else:
gamemodel.players[1].offerRematch()
elif responseId == 1:
from pychess.widgets.newGameDialog import createRematch
createRematch(gamemodel)
elif responseId == 2:
if gamemodel.curplayer.__type__ == LOCAL and gamemodel.ply > 1:
offer = Offer(TAKEBACK_OFFER, gamemodel.ply-2)
else:
offer = Offer(TAKEBACK_OFFER, gamemodel.ply-1)
if gamemodel.players[0].__type__ == LOCAL:
gamemodel.players[0].emit("offer", offer)
else: gamemodel.players[1].emit("offer", offer)
md.connect("response", cb)
glock.acquire()
try:
gmwidg.showMessage(md)
gmwidg.status("%s %s." % (m1,m2[0].lower()+m2[1:]))
if reason == WHITE_ENGINE_DIED:
engineDead(gamemodel.players[0], gmwidg)
elif reason == BLACK_ENGINE_DIED:
engineDead(gamemodel.players[1], gmwidg)
finally:
glock.release()
示例5: analyse_moves
def analyse_moves():
move_time = int(conf.get("max_analysis_spin", 3))
thresold = int(conf.get("variation_thresold_spin", 50))
for board in gamemodel.boards:
if stop_event.is_set():
break
glock.acquire()
try:
gmwidg.board.view.setShownBoard(board)
finally:
glock.release()
analyzer.setBoard(board)
time.sleep(move_time + 0.1)
ply = board.ply
if ply - 1 in gamemodel.scores:
color = (ply - 1) % 2
oldmoves, oldscore, olddepth = gamemodel.scores[ply - 1]
oldscore = oldscore * -1 if color == BLACK else oldscore
moves, score, depth = gamemodel.scores[ply]
score = score * -1 if color == WHITE else score
diff = score - oldscore
if (diff > thresold and color == BLACK) or (diff < -1 * thresold and color == WHITE):
gamemodel.add_variation(gamemodel.boards[ply - 1], oldmoves)
widgets["analyze_game"].hide()
widgets["analyze_ok_button"].set_sensitive(True)
conf.set("analyzer_check", old_check_value)
示例6: __stopSearching
def __stopSearching(self):
lsearch.searching = False
if self.worker:
self.worker.cancel()
glock.acquire()
self.worker.get()
glock.release()
self.worker = None
示例7: status
def status(self, message):
glock.acquire()
try:
self.statusbar.pop(0)
if message:
self.statusbar.push(0, message)
finally:
glock.release()
示例8: game_unended
def game_unended (gamemodel, gmwidg):
glock.acquire()
try:
print "sending hideMessage"
gmwidg.hideMessage()
gmwidg.status("")
finally:
glock.release()
示例9: on_gmwidg_closed
def on_gmwidg_closed (gmwidg):
glock.acquire()
try:
if len(key2gmwidg) == 1:
getWidgets()['window1'].set_title('%s - PyChess' % _('Welcome'))
finally:
glock.release()
return False
示例10: game_unended
def game_unended (gamemodel, gmwidg):
log.debug("gamenanny.game_unended: %s" % gamemodel.boards[-1])
glock.acquire()
try:
gmwidg.clearMessages()
finally:
glock.release()
_set_statusbar(gmwidg, "")
return False
示例11: status
def status (self, message):
glock.acquire()
try:
self.statusbar.pop(0)
if message:
#print "Setting statusbar to \"%s\"" % str(message)
self.statusbar.push(0, message)
finally:
glock.release()
示例12: _set_widget
def _set_widget (self, prop, value):
if not self.gamewidget.isInFront(): return
if gamewidget.getWidgets()[self.name].get_property(prop) != value:
#print "setting %s property %s to %s.." % (self.name, prop, str(value)),
glock.acquire()
try:
gamewidget.getWidgets()[self.name].set_property(prop, value)
finally:
glock.release()
示例13: getPromotion
def getPromotion(self):
color = self.view.model.boards[-1].color
variant = self.view.model.boards[-1].variant
promotion = None
glock.acquire()
try:
promotion = self.promotionDialog.runAndHide(color, variant)
finally:
glock.release()
return promotion
示例14: game_loaded
def game_loaded (gamemodel, uri, gmwidg):
if type(uri) in (str, unicode):
s = "%s: %s" % (_("Loaded game"), str(uri))
else: s = _("Loaded game")
glock.acquire()
try:
gmwidg.status(s)
finally:
glock.release()
示例15: on_gmwidg_title_changed
def on_gmwidg_title_changed (gmwidg, new_title):
log.debug("gamenanny.on_gmwidg_title_changed: starting %s" % repr(gmwidg))
glock.acquire()
try:
if gmwidg.isInFront():
getWidgets()['window1'].set_title('%s - PyChess' % new_title)
finally:
glock.release()
log.debug("gamenanny.on_gmwidg_title_changed: returning")
return False