コード例 #1
0
ファイル: analyzegameDialog.py プロジェクト: fowode/pychess
        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)
コード例 #2
0
 def setLocked(self, locked):
     """ Makes the board insensitive and turns off the tab ready indicator """
     log.debug("GameWidget.setLocked: %s locked=%s" %
               (self.gamemodel.players, str(locked)))
     self.board.setLocked(locked)
     if not self.tabcontent.get_children(): return
     if len(self.tabcontent.get_child().get_children()) < 2:
         log.warning(
             "GameWidget.setLocked: Not removing last tabcontent child")
         return
     glock.acquire()
     try:
         child = self.tabcontent.get_child()
         if child:
             child.remove(child.get_children()[0])
             if not locked:
                 #child.pack_start(createImage(light_on, True, True, 0), expand=False)
                 child.pack_start(createImage(light_on), True, True, 0)
             else:
                 #child.pack_start(createImage(light_off, True, True, 0), expand=False)
                 child.pack_start(createImage(light_off), True, True, 0)
         self.tabcontent.show_all()
     finally:
         glock.release()
     log.debug("GameWidget.setLocked: %s: returning" %
               self.gamemodel.players)
コード例 #3
0
    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()
コード例 #4
0
    def __init__(self, gamemodel):
        GObject.GObject.__init__(self)
        self.gamemodel = gamemodel
        self.cids = {}

        tabcontent, white_label, black_label, game_info_label = self.initTabcontents(
        )
        boardvbox, board, infobar, clock = self.initBoardAndClock(gamemodel)
        statusbar, stat_hbox = self.initStatusbar(board)

        self.tabcontent = tabcontent
        self.player_name_labels = (white_label, black_label)
        self.game_info_label = game_info_label
        self.board = board
        self.statusbar = statusbar
        self.infobar = infobar
        infobar.connect("hide", self.infobar_hidden)
        self.game_ended_message = None
        self.clock = clock
        self.notebookKey = Gtk.Label()
        self.notebookKey.set_size_request(0, 0)
        self.boardvbox = boardvbox
        self.stat_hbox = stat_hbox
        self.menuitems = MenuItemsDict(self)

        gamemodel.connect("game_started", self.game_started)
        gamemodel.connect("game_ended", self.game_ended)
        gamemodel.connect("game_changed", self.game_changed)
        gamemodel.connect("game_paused", self.game_paused)
        gamemodel.connect("game_resumed", self.game_resumed)
        gamemodel.connect("moves_undone", self.moves_undone)
        gamemodel.connect("game_unended", self.game_unended)
        gamemodel.connect("game_saved", self.game_saved)
        gamemodel.connect("players_changed", self.players_changed)
        gamemodel.connect("analyzer_added", self.analyzer_added)
        gamemodel.connect("analyzer_removed", self.analyzer_removed)
        gamemodel.connect("analyzer_resumed", self.analyzer_resumed)
        gamemodel.connect("analyzer_paused", self.analyzer_paused)
        self.players_changed(gamemodel)
        if self.gamemodel.display_text:
            self.game_info_label.set_text(" " + self.gamemodel.display_text)
        if gamemodel.timed:
            gamemodel.timemodel.connect("zero_reached", self.zero_reached)
        if isinstance(gamemodel, ICGameModel):
            gamemodel.connection.bm.connect("player_lagged",
                                            self.player_lagged)
            gamemodel.connection.bm.connect("opp_not_out_of_time",
                                            self.opp_not_out_of_time)
        board.view.connect("shown_changed", self.shown_changed)

        # 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()
コード例 #5
0
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()
コード例 #6
0
ファイル: BoardControl.py プロジェクト: Alex-Linhares/pychess
    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()
コード例 #7
0
        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)
コード例 #8
0
    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()
コード例 #9
0
    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()
コード例 #10
0
    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)
コード例 #11
0
 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)
コード例 #12
0
 def status(self, message):
     glock.acquire()
     try:
         self.statusbar.pop(0)
         if message:
             self.statusbar.push(0, message)
     finally:
         glock.release()
コード例 #13
0
 def __stopSearching(self):
     lsearch.searching = False
     if self.worker:
         self.worker.cancel()
         glock.acquire()
         self.worker.get()
         glock.release()
         self.worker = None
コード例 #14
0
 def status(self, message):
     glock.acquire()
     try:
         self.statusbar.pop(0)
         if message:
             self.statusbar.push(0, message)
     finally:
         glock.release()
コード例 #15
0
def game_unended(gamemodel, gmwidg):
    glock.acquire()
    try:
        print "sending hideMessage"
        gmwidg.hideMessage()
        gmwidg.status("")
    finally:
        glock.release()
コード例 #16
0
ファイル: gamenanny.py プロジェクト: fowode/pychess
def on_gmwidg_closed (gmwidg):
    glock.acquire()
    try:
        if len(key2gmwidg) == 1:
            getWidgets()['window1'].set_title('%s - PyChess' % _('Welcome'))
    finally:
        glock.release()
    return False
コード例 #17
0
def on_gmwidg_closed(gmwidg):
    glock.acquire()
    try:
        if len(key2gmwidg) == 1:
            getWidgets()['window1'].set_title('%s - PyChess' % _('Welcome'))
    finally:
        glock.release()
    return False
コード例 #18
0
def game_unended (gamemodel, gmwidg):
    glock.acquire()
    try:
        print "sending hideMessage"
        gmwidg.hideMessage()
        gmwidg.status("")
    finally:
        glock.release()
コード例 #19
0
ファイル: gamewidget.py プロジェクト: Alex-Linhares/pychess
 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()
コード例 #20
0
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
コード例 #21
0
 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()
コード例 #22
0
ファイル: MenuItemsDict.py プロジェクト: btrent/knave
 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()
コード例 #23
0
ファイル: gamenanny.py プロジェクト: fowode/pychess
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
コード例 #24
0
ファイル: gamenanny.py プロジェクト: fowode/pychess
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
コード例 #25
0
 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
コード例 #26
0
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()
コード例 #27
0
ファイル: MenuItemsDict.py プロジェクト: rajrakeshdr/pychess
 def _set_widget(self, prop, value):
     if not self.gamewidget.isInFront(): return
     from . import gamewidget
     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()
コード例 #28
0
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
コード例 #29
0
ファイル: BoardControl.py プロジェクト: Alex-Linhares/pychess
 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
コード例 #30
0
ファイル: gamewidget.py プロジェクト: fowode/pychess
    def __init__(self, gamemodel):
        GObject.GObject.__init__(self)
        self.gamemodel = gamemodel
        self.cids = {}

        tabcontent, white_label, black_label, game_info_label = self.initTabcontents()
        boardvbox, board, infobar, clock = self.initBoardAndClock(gamemodel)
        statusbar, stat_hbox = self.initStatusbar(board)

        self.tabcontent = tabcontent
        self.player_name_labels = (white_label, black_label)
        self.game_info_label = game_info_label
        self.board = board
        self.statusbar = statusbar
        self.infobar = infobar
        infobar.connect("hide", self.infobar_hidden)
        self.game_ended_message = None
        self.clock = clock
        self.notebookKey = Gtk.Label()
        self.notebookKey.set_size_request(0, 0)
        self.boardvbox = boardvbox
        self.stat_hbox = stat_hbox
        self.menuitems = MenuItemsDict(self)

        gamemodel.connect("game_started", self.game_started)
        gamemodel.connect("game_ended", self.game_ended)
        gamemodel.connect("game_changed", self.game_changed)
        gamemodel.connect("game_paused", self.game_paused)
        gamemodel.connect("game_resumed", self.game_resumed)
        gamemodel.connect("moves_undone", self.moves_undone)
        gamemodel.connect("game_unended", self.game_unended)
        gamemodel.connect("game_saved", self.game_saved)
        gamemodel.connect("players_changed", self.players_changed)
        gamemodel.connect("analyzer_added", self.analyzer_added)
        gamemodel.connect("analyzer_removed", self.analyzer_removed)
        gamemodel.connect("analyzer_resumed", self.analyzer_resumed)
        gamemodel.connect("analyzer_paused", self.analyzer_paused)
        self.players_changed(gamemodel)
        if self.gamemodel.display_text:
            self.game_info_label.set_text(" " + self.gamemodel.display_text)
        if gamemodel.timed:
            gamemodel.timemodel.connect("zero_reached", self.zero_reached)
        if isinstance(gamemodel, ICGameModel):
            gamemodel.connection.bm.connect("player_lagged", self.player_lagged)
            gamemodel.connection.bm.connect("opp_not_out_of_time", self.opp_not_out_of_time)
        board.view.connect("shown_changed", self.shown_changed)

        # 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()
コード例 #31
0
ファイル: ChatView.py プロジェクト: btrent/knave
 def addMessage (self, sender, text):
     glock.acquire()
     try:
         tb = self.readView.get_buffer()
         iter = tb.get_end_iter()
         # Messages have linebreak before the text. This is opposite to log
         # messages
         if tb.props.text: tb.insert(iter, "\n")
         self.__addMessage(iter, strftime("%H:%M:%S"), sender, text)
     finally:
         glock.release()
コード例 #32
0
def offer_callback (player, offer, gamemodel, gmwidg):
    if offer.type == DRAW_OFFER:
        if gamemodel.status != RUNNING:
            return # If the offer has already been handled by
                   # Gamemodel and the game was drawn, we need
                   # to do nothing
        glock.acquire()
        try:
            gmwidg.status(_("You sent a draw offer"))
        finally:
            glock.release()
コード例 #33
0
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()
コード例 #34
0
 def redraw_canvas(self):
     if self.window:
         glock.acquire()
         try:
             if self.window:
                 a = self.get_allocation()
                 rect = gdk.Rectangle(0, 0, a.width, a.height)
                 self.window.invalidate_rect(rect, True)
                 self.window.process_updates(True)
         finally:
             glock.release()
コード例 #35
0
def offer_callback(player, offer, gamemodel, gmwidg):
    if offer.type == DRAW_OFFER:
        if gamemodel.status != RUNNING:
            return  # If the offer has already been handled by
            # Gamemodel and the game was drawn, we need
            # to do nothing
        glock.acquire()
        try:
            gmwidg.status(_("You sent a draw offer"))
        finally:
            glock.release()
コード例 #36
0
ファイル: ChatView.py プロジェクト: rajrakeshdr/pychess
 def addMessage(self, sender, text):
     glock.acquire()
     try:
         tb = self.readView.get_buffer()
         iter = tb.get_end_iter()
         # Messages have linebreak before the text. This is opposite to log
         # messages
         if tb.props.text: tb.insert(iter, "\n")
         self.__addMessage(iter, strftime("%H:%M:%S"), sender, text)
     finally:
         glock.release()
コード例 #37
0
        def analyse_moves():
            from_current = conf.get("fromCurrent", True)
            start_ply = gmwidg.board.view.shown if from_current else 0
            move_time = int(conf.get("max_analysis_spin", 3))
            thresold = int(conf.get("variation_thresold_spin", 50))
            for board in gamemodel.boards[start_ply:]:
                if stop_event.is_set():
                    break
                glock.acquire()
                try:
                    gmwidg.board.view.setShownBoard(board)
                finally:
                    glock.release()
                analyzer.setBoard(board)
                inv_analyzer.setBoard(board)
                time.sleep(move_time+0.1)

                ply = board.ply
                if ply-1 in gamemodel.scores and ply in gamemodel.scores: 
                    color = (ply-1) % 2
                    oldmoves, oldscore, olddepth = gamemodel.scores[ply-1]
                    score_str = prettyPrintScore(oldscore, olddepth)
                    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):
                        if threat_PV:
                            try:
                                oldmoves0, oldscore0, olddepth0 = gamemodel.spy_scores[ply-1]
                                score_str0 = prettyPrintScore(oldscore0, olddepth0)
                                pv0 = listToMoves(gamemodel.boards[ply-1], ["--"] + oldmoves0, validate=True)
                                gamemodel.add_variation(gamemodel.boards[ply-1], pv0, comment="Treatening", score=score_str0)
                            except ParsingError as e:
                                # ParsingErrors may happen when parsing "old" lines from
                                # analyzing engines, which haven't yet noticed their new tasks
                                log.debug("__parseLine: Ignored (%s) from analyzer: ParsingError%s" % \
                                    (' '.join(oldmoves),e))
                        try:
                            pv = listToMoves(gamemodel.boards[ply-1], oldmoves, validate=True)
                            gamemodel.add_variation(gamemodel.boards[ply-1], pv, comment="Better is", score=score_str)
                        except ParsingError as e:
                            # ParsingErrors may happen when parsing "old" lines from
                            # analyzing engines, which haven't yet noticed their new tasks
                            log.debug("__parseLine: Ignored (%s) from analyzer: ParsingError%s" % \
                                (' '.join(oldmoves),e))

            widgets["analyze_game"].hide()
            widgets["analyze_ok_button"].set_sensitive(True)
            conf.set("analyzer_check", old_check_value)
            if threat_PV:
                conf.set("inv_analyzer_check", old_inv_check_value)
            message.dismiss()
コード例 #38
0
 def onSizeAllocate(self, widget, requisition):
     if self.window:
         glock.acquire()
         try:
             a = self.get_allocation()
             rect = gdk.Rectangle(a.x, a.y, a.width, a.height)
             unionrect = self.lastRectangle.union(rect) if self.lastRectangle != None else rect
             self.window.invalidate_rect(unionrect, True)
             self.window.process_updates(True)
             self.lastRectangle = rect
         finally:
             glock.release()
コード例 #39
0
ファイル: ChatView.py プロジェクト: btrent/knave
 def insertLogMessage (self, timestamp, sender, text):
     """ Takes a list of (timestamp, sender, text) pairs, and inserts them in
         the beginning of the document.
         All text will be in a gray color """
     glock.acquire()
     try:
         tb = self.readView.get_buffer()
         iter = tb.get_iter_at_mark(tb.get_mark("logMark"))
         time = strftime("%H:%M:%S", localtime(timestamp))
         self.__addMessage(iter, time, sender, text)
         tb.insert(iter, "\n")
     finally:
         glock.release()
コード例 #40
0
ファイル: gamewidget.py プロジェクト: systemovich/pychess
 def status (self, message):
     # Enable only moves entered by keyboard
     # TODO: revise all statusbar messages, maybe some of them can be sent to infobar
     if len(message) > 7:
         return
     glock.acquire()
     try:
         self.statusbar.pop(0)
         if message:
             #print "Setting statusbar to \"%s\"" % str(message)
             self.statusbar.push(0, message)
     finally:
         glock.release()
コード例 #41
0
ファイル: BoardControl.py プロジェクト: Alex-Linhares/pychess
 def moves_undone (self, gamemodel, moves):
     glock.acquire()
     self.stateLock.acquire()
     try:
         self.view.selected = None
         self.view.active = None
         self.view.hover = None
         self.view.draggedPiece = None
         self.view.setPremove(None, None, None, None)
         self.currentState = self.lockedNormalState
     finally:
         self.stateLock.release()
         glock.release()
コード例 #42
0
 def onSizeAllocate(self, widget, requisition):
     if self.window:
         glock.acquire()
         try:
             a = self.get_allocation()
             rect = gdk.Rectangle(a.x, a.y, a.width, a.height)
             unionrect = self.lastRectangle.union(
                 rect) if self.lastRectangle != None else rect
             self.window.invalidate_rect(unionrect, True)
             self.window.process_updates(True)
             self.lastRectangle = rect
         finally:
             glock.release()
コード例 #43
0
ファイル: ChainVBox.py プロジェクト: Alex-Linhares/pychess
 def on_size_allocate(self, widget, requisition):
     if self.get_window():
         glock.acquire()
         try:
             a = self.get_allocation()
             rect = Gdk.Rectangle()
             rect.x, rect.y, rect.width, rect.height = (a.x, a.y, a.width, a.height)
             unionrect = Gdk.rectangle_union(self.lastRectangle, rect) if self.lastRectangle != None else rect
             self.get_window().invalidate_rect(unionrect, True)
             self.get_window().process_updates(True)
             self.lastRectangle = rect
         finally:
             glock.release()        
コード例 #44
0
ファイル: ChatView.py プロジェクト: rajrakeshdr/pychess
 def insertLogMessage(self, timestamp, sender, text):
     """ Takes a list of (timestamp, sender, text) pairs, and inserts them in
         the beginning of the document.
         All text will be in a gray color """
     glock.acquire()
     try:
         tb = self.readView.get_buffer()
         iter = tb.get_iter_at_mark(tb.get_mark("logMark"))
         time = strftime("%H:%M:%S", localtime(timestamp))
         self.__addMessage(iter, time, sender, text)
         tb.insert(iter, "\n")
     finally:
         glock.release()
コード例 #45
0
 def addMessage(self, text, my=False):
     glock.acquire()
     try:
         tb = self.readView.get_buffer()
         iter = tb.get_end_iter()
         # Messages have linebreak before the text. This is opposite to log
         # messages
         if tb.props.text:
             tb.insert(iter, "\n")
         tb = self.readView.get_buffer()
         tag = "mytext" if my else "text"
         tb.insert_with_tags_by_name(iter, text, tag)
     finally:
         glock.release()
コード例 #46
0
 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
コード例 #47
0
ファイル: gamewidget.py プロジェクト: fowode/pychess
 def name_changed(self, player):
     log.debug("GameWidget.name_changed: starting %s" % repr(player))
     color = self.gamemodel.color(player)
     glock.acquire()
     try:
         self.player_name_labels[color].set_text(self.player_display_text(color=color))
         if isinstance(self.gamemodel, ICGameModel) and player.__type__ == REMOTE:
             self.player_name_labels[color].set_tooltip_text(
                 get_player_tooltip_text(self.gamemodel.ficsplayers[color], show_status=False)
             )
     finally:
         glock.release()
     self.emit("title_changed", self.display_text)
     log.debug("GameWidget.name_changed: returning")
コード例 #48
0
 def addMessage (self, text, my=False):
     glock.acquire()
     try:
         tb = self.readView.get_buffer()
         iter = tb.get_end_iter()
         # Messages have linebreak before the text. This is opposite to log
         # messages
         if tb.props.text:
             tb.insert(iter, "\n")
         tb = self.readView.get_buffer()
         tag = "mytext" if my else "text"
         tb.insert_with_tags_by_name(iter, text, tag)
     finally:
         glock.release()
コード例 #49
0
ファイル: BoardControl.py プロジェクト: Alex-Linhares/pychess
    def game_ended (self, gamemodel, reason):
        glock.acquire()
        self.stateLock.acquire()
        try:
            self.view.selected = None
            self.view.active = None
            self.view.hover = None
            self.view.draggedPiece = None
            self.view.setPremove(None, None, None, None)
            self.currentState = self.normalState
        finally:
            self.stateLock.release()
            glock.release()

        self.view.startAnimation()
コード例 #50
0
 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
コード例 #51
0
    def game_ended(self, gamemodel, reason):
        glock.acquire()
        self.stateLock.acquire()
        try:
            self.view.selected = None
            self.view.active = None
            self.view.hover = None
            self.view.draggedPiece = None
            self.view.setPremove(None, None, None, None)
            self.currentState = self.normalState
        finally:
            self.stateLock.release()
            glock.release()

        self.view.startAnimation()
コード例 #52
0
    def moves_undone(self, gamemodel, moves):
        glock.acquire()
        self.stateLock.acquire()
        try:
            self.view.selected = None
            self.view.active = None
            self.view.hover = None
            self.view.draggedPiece = None
            self.view.setPremove(None, None, None, None)
            self.currentState = self.lockedNormalState
        finally:
            self.stateLock.release()
            glock.release()

        self.view.startAnimation()
コード例 #53
0
    def __init__(self, filename):
        self.glade = None
        try:
            if filename in cachedGlades:
                self.glade = cachedGlades[filename].get(block=False)
        except Queue.Empty:
            pass

        if not self.glade:
            glock.acquire()
            #            print "uistuff.py:gladefile = %s" % filename
            self.glade = gtk.glade.XML(addDataPrefix("glade/%s" % filename))
            glock.release()

        self.extras = {}
コード例 #54
0
    def __init__ (self, filename):
        self.glade = None
        try:
            if filename in cachedGlades:
                self.glade = cachedGlades[filename].get(block=False)
        except Queue.Empty:
            pass
        
        if not self.glade:
            glock.acquire()
#            print "uistuff.py:gladefile = %s" % filename
            self.glade = gtk.glade.XML(addDataPrefix("glade/%s" % filename))
            glock.release()
        
        self.extras = {}
コード例 #55
0
def on_gmwidg_infront(gmwidg):
    glock.acquire()
    try:
        for widget in MENU_ITEMS:
            if widget in gmwidg.menuitems:
                continue
            elif widget == 'show_sidepanels' and isDesignGWShown():
                getWidgets()[widget].set_property('sensitive', False)
            else:
                getWidgets()[widget].set_property('sensitive', True)

        # Change window title
        getWidgets()['window1'].set_title('%s - PyChess' % gmwidg.display_text)
    finally:
        glock.release()
    return False
コード例 #56
0
 def redraw_canvas(self, r=None, queue=False):
     if self.window:
         glock.acquire()
         try:
             if self.window:
                 if not r:
                     alloc = self.get_allocation()
                     r = gtk.gdk.Rectangle(0, 0, alloc.width, alloc.height)
                 assert type(r[2]) == int
                 if queue:
                     self.queue_draw_area(r.x, r.y, r.width, r.height)
                 else:
                     self.window.invalidate_rect(r, True)
                     self.window.process_updates(True)
         finally:
             glock.release()
コード例 #57
0
 def name_changed(self, player):
     log.debug("GameWidget.name_changed: starting %s" % repr(player))
     color = self.gamemodel.color(player)
     glock.acquire()
     try:
         self.player_name_labels[color].set_text(
             self.player_display_text(color=color))
         if isinstance(self.gamemodel, ICGameModel) and \
                 player.__type__ == REMOTE:
             self.player_name_labels[color].set_tooltip_text(
                 get_player_tooltip_text(self.gamemodel.ficsplayers[color],
                                         show_status=False))
     finally:
         glock.release()
     self.emit('title_changed', self.display_text)
     log.debug("GameWidget.name_changed: returning")
コード例 #58
0
ファイル: ChainVBox.py プロジェクト: rajrakeshdr/pychess
 def on_size_allocate(self, widget, requisition):
     if self.get_window():
         glock.acquire()
         try:
             a = self.get_allocation()
             rect = Gdk.Rectangle()
             rect.x, rect.y, rect.width, rect.height = (a.x, a.y, a.width,
                                                        a.height)
             unionrect = Gdk.rectangle_union(
                 self.lastRectangle,
                 rect) if self.lastRectangle != None else rect
             self.get_window().invalidate_rect(unionrect, True)
             self.get_window().process_updates(True)
             self.lastRectangle = rect
         finally:
             glock.release()