Example #1
0
 def load(self, gmwidg):
     self.chatView = ChatView()
     self.chatView.disable("Waiting for game to load")
     self.chatView.connect("messageTyped", self.onMessageSent)
     self.gamemodel = gmwidg.gamemodel
     self.gamemodel.connect("game_started", self.onGameStarted)
     return self.chatView
Example #2
0
 def load(self, gmwidg):
     self.gamemodel = gmwidg.gamemodel
     self.gamemodel.connect("game_started", self.onGameStarted)
     self.chatView = ChatView(self.gamemodel)
     self.chatView.disable("Waiting for game to load")
     self.chatView.connect("messageTyped", self.onMessageSent)
     if isinstance(self.gamemodel, ICGameModel):
         self.gamemodel.connect("observers_received",
                                self.chatView.update_observers)
         self.gamemodel.connect("message_received", self.onICMessageReieved)
     return self.chatView
Example #3
0
 def load(self, gmwidg):
     self.gamemodel = gmwidg.gamemodel
     self.model_cids = [
         self.gamemodel.connect("game_started", self.onGameStarted),
         self.gamemodel.connect_after("game_terminated", self.on_game_terminated),
     ]
     self.chatView = ChatView(self.gamemodel)
     self.chatView.disable("Waiting for game to load")
     self.chatview_cid = self.chatView.connect("messageTyped", self.onMessageSent)
     if isinstance(self.gamemodel, ICGameModel):
         self.model_cids.append(self.gamemodel.connect("observers_received",
                                self.chatView.update_observers))
         self.model_cids.append(self.gamemodel.connect("message_received",
                                self.onICMessageReieved))
     return self.chatView
Example #4
0
 def load (self, gmwidg):
     self.chatView = ChatView()
     self.chatView.disable("Waiting for game to load")
     self.chatView.connect("messageTyped", self.onMessageSent)
     self.gamemodel = gmwidg.gamemodel
     self.gamemodel.connect("game_started", self.onGameStarted)
     return self.chatView
Example #5
0
 def onConversationAdded(self, panel, grp_id, text, grp_type):
     # deferred import to not slow down PyChess starting up
     from pychess.widgets.ChatView import ChatView
     chatView = ChatView()
     plus_channel = '+channel ' + str(grp_id)
     self.connection.cm.connection.client.run_command(plus_channel)
     for panel in self.panels:
         panel.addItem(grp_id, text, grp_type, chatView)
Example #6
0
 def load (self, gmwidg):
     self.chatView = ChatView()
     self.chatView.disable("Waiting for game to load")
     self.chatView.connect("messageTyped", self.onMessageSent)
     self.gamemodel = gmwidg.gamemodel
     self.gamemodel.connect("game_started", self.onGameStarted)
     if isinstance(self.gamemodel, ICGameModel):
         self.gamemodel.connect("message_received", self.onICMessageReieved)
     return self.chatView
Example #7
0
 def load(self, gmwidg):
     self.gamemodel = gmwidg.gamemodel
     self.model_cids = [
         self.gamemodel.connect("game_started", self.onGameStarted),
         self.gamemodel.connect_after("game_terminated", self.on_game_terminated),
     ]
     self.chatView = ChatView(self.gamemodel)
     self.chatView.disable("Waiting for game to load")
     self.chatview_cid = self.chatView.connect("messageTyped", self.onMessageSent)
     if isinstance(self.gamemodel, ICGameModel):
         self.model_cids.append(self.gamemodel.connect("observers_received",
                                self.chatView.update_observers))
         self.model_cids.append(self.gamemodel.connect("message_received",
                                self.onICMessageReieved))
     return self.chatView
Example #8
0
 def onConversationAdded(self, panel, id, text, type):
     chatView = ChatView()
     for panel in self.panels:
         panel.addItem(id, text, type, chatView)
Example #9
0
class Sidepanel:
    def load(self, gmwidg):
        self.gamemodel = gmwidg.gamemodel
        self.gamemodel.connect("game_started", self.onGameStarted)
        self.chatView = ChatView(self.gamemodel)
        self.chatView.disable("Waiting for game to load")
        self.chatView.connect("messageTyped", self.onMessageSent)
        if isinstance(self.gamemodel, ICGameModel):
            self.gamemodel.connect("observers_received",
                                   self.chatView.update_observers)
            self.gamemodel.connect("message_received", self.onICMessageReieved)
        return self.chatView

    @idle_add
    def onGameStarted(self, gamemodel):
        if gamemodel.isObservationGame() or gamemodel.examined:
            # no local player but enable chat to send/receive whisper/kibitz
            pass
        elif gamemodel.players[0].__type__ == LOCAL:
            self.player = gamemodel.players[0]
            self.opplayer = gamemodel.players[1]
            if gamemodel.players[1].__type__ == LOCAL:
                log.warning("Chatpanel loaded with two local players")
        elif gamemodel.players[1].__type__ == LOCAL:
            self.player = gamemodel.players[1]
            self.opplayer = gamemodel.players[0]
        else:
            log.info("Chatpanel loaded with no local players")
            self.chatView.hide()

        if isinstance(gamemodel, ICGameModel):
            allob = 'allob ' + str(gamemodel.ficsgame.gameno)
            gamemodel.connection.client.run_command(allob)

        if hasattr(self, "player"):
            self.player.connect("messageReceived", self.onMessageReieved)

        self.chatView.enable()

    @idle_add
    def onMessageReieved(self, player, text):
        self.chatView.addMessage(repr(self.opplayer), text)

    def onICMessageReieved(self, icgamemodel, player, text):
        self.chatView.addMessage(player, text)
        # emit an allob <gameno> to FICS
        allob = 'allob ' + str(icgamemodel.ficsgame.gameno)
        icgamemodel.connection.client.run_command(allob)

    def onMessageSent(self, chatView, text):
        if hasattr(self, "player"):
            if text.startswith('# '):
                text = text[2:]
                self.gamemodel.connection.cm.whisper(text)
            elif text.startswith('whisper '):
                text = text[8:]
                self.gamemodel.connection.cm.whisper(text)
            else:
                self.player.sendMessage(text)
                self.chatView.addMessage(repr(self.player), text)
        else:
            self.gamemodel.connection.cm.whisper(text)
Example #10
0
class Sidepanel:
    def load (self, gmwidg):
        self.chatView = ChatView()
        self.chatView.disable("Waiting for game to load")
        self.chatView.connect("messageTyped", self.onMessageSent)
        self.gamemodel = gmwidg.gamemodel
        self.gamemodel.connect("game_started", self.onGameStarted)
        return self.chatView
    
    @idle_add
    def onGameStarted (self, gamemodel):
        if gamemodel.players[0].__type__ == LOCAL:
            self.player = gamemodel.players[0]
            self.opplayer = gamemodel.players[1]
            if gamemodel.players[1].__type__ == LOCAL:
                log.warning("Chatpanel loaded with two local players")
        elif gamemodel.players[1].__type__ == LOCAL:
            self.player = gamemodel.players[1]
            self.opplayer = gamemodel.players[0]
        else:
            log.info("Chatpanel loaded with no local players")
            self.chatView.hide()
        
        if hasattr(self, "player"):
            self.player.connect("messageRecieved", self.onMessageReieved)
        
        self.chatView.enable()
    
    def onMessageReieved (self, player, text):
        self.chatView.addMessage(repr(self.opplayer), text)
    
    def onMessageSent (self, chatView, text):
        self.player.sendMessage(text)
        self.chatView.addMessage(repr(self.player), text)
Example #11
0
class Sidepanel:
    def load(self, gmwidg):
        self.gamemodel = gmwidg.gamemodel
        self.player_cid = None
        self.model_cids = [
            self.gamemodel.connect("game_started", self.onGameStarted),
            self.gamemodel.connect_after("game_terminated",
                                         self.on_game_terminated),
        ]
        self.chatView = ChatView(self.gamemodel)
        self.chatView.disable("Waiting for game to load")
        self.chatview_cid = self.chatView.connect("messageTyped",
                                                  self.onMessageSent)
        if isinstance(self.gamemodel, ICGameModel):
            self.model_cids.append(
                self.gamemodel.connect("observers_received",
                                       self.chatView.update_observers))
            self.model_cids.append(
                self.gamemodel.connect("message_received",
                                       self.onICMessageReieved))
        return self.chatView

    def on_game_terminated(self, model):
        self.chatView.disconnect(self.chatview_cid)
        if hasattr(self, "player") and hasattr(
                self, "player_cid") and not self.gamemodel.examined:
            self.player.disconnect(self.player_cid)
        for cid in self.model_cids:
            self.gamemodel.disconnect(cid)

    def onGameStarted(self, gamemodel):
        if gamemodel.examined:
            if gamemodel.players[0].name == gamemodel.connection.username:
                self.player = gamemodel.players[0]
                self.opplayer = gamemodel.players[1]
            else:
                self.player = gamemodel.players[1]
                self.opplayer = gamemodel.players[0]
        elif gamemodel.isObservationGame():
            # no local player but enable chat to send/receive whisper/kibitz
            pass
        elif gamemodel.players[0].__type__ == LOCAL:
            self.player = gamemodel.players[0]
            self.opplayer = gamemodel.players[1]
            if gamemodel.players[1].__type__ == LOCAL:
                log.warning("Chatpanel loaded with two local players")
        elif gamemodel.players[1].__type__ == LOCAL:
            self.player = gamemodel.players[1]
            self.opplayer = gamemodel.players[0]
        else:
            log.info("Chatpanel loaded with no local players")
            self.chatView.hide()

        if isinstance(gamemodel, ICGameModel):
            if gamemodel.connection.ICC:
                gamemodel.connection.client.run_command("set-2 %s 1" %
                                                        DG_PLAYERS_IN_MY_GAME)
            else:
                allob = 'allob ' + str(gamemodel.ficsgame.gameno)
                gamemodel.connection.client.run_command(allob)

        if hasattr(self, "player"
                   ) and not gamemodel.examined and self.player_cid is None:
            self.player_cid = self.player.connect("messageReceived",
                                                  self.onMessageRecieved)

        self.chatView.enable()

    def onMessageRecieved(self, player, text):
        sender = "pychessbot" if player.gamemodel.offline_lecture else repr(
            self.opplayer)
        self.chatView.addMessage(sender, text)

    def onICMessageReieved(self, icgamemodel, player, text):
        self.chatView.addMessage(player, text)
        # emit an allob <gameno> to FICS
        if not icgamemodel.connection.ICC:
            allob = 'allob ' + str(icgamemodel.ficsgame.gameno)
            icgamemodel.connection.client.run_command(allob)

    def onMessageSent(self, chatView, text):
        if hasattr(self, "player") or self.gamemodel.examined:
            if text.startswith('# '):
                text = text[2:]
                self.gamemodel.connection.cm.whisper(text)
            elif text.startswith('whisper '):
                text = text[8:]
                self.gamemodel.connection.cm.whisper(text)
            else:
                if not hasattr(self, "player"):
                    if self.gamemodel.players[
                            0].name == self.gamemodel.connection.username:
                        self.player = self.gamemodel.players[0]
                        self.opplayer = self.gamemodel.players[1]
                    else:
                        self.player = self.gamemodel.players[1]
                        self.opplayer = self.gamemodel.players[0]

                if self.gamemodel.examined:
                    self.opplayer.putMessage(text)
                else:
                    self.player.sendMessage(text)
                self.chatView.addMessage(repr(self.player), text)
        else:
            self.gamemodel.connection.cm.whisper(text)
Example #12
0
 def onConversationAdded(self, panel, grp_id, text, grp_type):
     chatView = ChatView()
     plus_channel = '+channel ' + str(grp_id)
     self.connection.cm.connection.client.run_command(plus_channel)
     for panel in self.panels:
         panel.addItem(grp_id, text, grp_type, chatView)
Example #13
0
class Sidepanel:
    def load(self, gmwidg):
        self.gamemodel = gmwidg.gamemodel
        self.gamemodel.connect("game_started", self.onGameStarted)
        self.chatView = ChatView(self.gamemodel)
        self.chatView.disable("Waiting for game to load")
        self.chatView.connect("messageTyped", self.onMessageSent)
        if isinstance(self.gamemodel, ICGameModel):
            self.gamemodel.connect("observers_received",
                                   self.chatView.update_observers)
            self.gamemodel.connect("message_received", self.onICMessageReieved)
        return self.chatView

    @idle_add
    def onGameStarted(self, gamemodel):
        if gamemodel.isObservationGame() or gamemodel.examined:
            # no local player but enable chat to send/receive whisper/kibitz
            pass
        elif gamemodel.players[0].__type__ == LOCAL:
            self.player = gamemodel.players[0]
            self.opplayer = gamemodel.players[1]
            if gamemodel.players[1].__type__ == LOCAL:
                log.warning("Chatpanel loaded with two local players")
        elif gamemodel.players[1].__type__ == LOCAL:
            self.player = gamemodel.players[1]
            self.opplayer = gamemodel.players[0]
        else:
            log.info("Chatpanel loaded with no local players")
            self.chatView.hide()

        if isinstance(gamemodel, ICGameModel):
            allob = 'allob ' + str(gamemodel.ficsgame.gameno)
            gamemodel.connection.client.run_command(allob)

        if hasattr(self, "player"):
            self.player.connect("messageReceived", self.onMessageReieved)

        self.chatView.enable()

    @idle_add
    def onMessageReieved(self, player, text):
        self.chatView.addMessage(repr(self.opplayer), text)

    def onICMessageReieved(self, icgamemodel, player, text):
        self.chatView.addMessage(player, text)
        # emit an allob <gameno> to FICS
        allob = 'allob ' + str(icgamemodel.ficsgame.gameno)
        icgamemodel.connection.client.run_command(allob)

    def onMessageSent(self, chatView, text):
        if hasattr(self, "player"):
            if text.startswith('# '):
                text = text[2:]
                self.gamemodel.connection.cm.whisper(text)
            elif text.startswith('whisper '):
                text = text[8:]
                self.gamemodel.connection.cm.whisper(text)
            else:
                self.player.sendMessage(text)
                self.chatView.addMessage(repr(self.player), text)
        else:
            self.gamemodel.connection.cm.whisper(text)
Example #14
0
class Sidepanel:
    def load(self, gmwidg):
        self.chatView = ChatView()
        self.chatView.disable("Waiting for game to load")
        self.chatView.connect("messageTyped", self.onMessageSent)
        self.gamemodel = gmwidg.gamemodel
        self.gamemodel.connect("game_started", self.onGameStarted)
        return self.chatView

    @idle_add
    def onGameStarted(self, gamemodel):
        if gamemodel.players[0].__type__ == LOCAL:
            self.player = gamemodel.players[0]
            self.opplayer = gamemodel.players[1]
            if gamemodel.players[1].__type__ == LOCAL:
                log.warning("Chatpanel loaded with two local players")
        elif gamemodel.players[1].__type__ == LOCAL:
            self.player = gamemodel.players[1]
            self.opplayer = gamemodel.players[0]
        else:
            log.info("Chatpanel loaded with no local players")
            self.chatView.hide()

        if hasattr(self, "player"):
            self.player.connect("messageRecieved", self.onMessageReieved)

        self.chatView.enable()

    def onMessageReieved(self, player, text):
        self.chatView.addMessage(repr(self.opplayer), text)

    def onMessageSent(self, chatView, text):
        self.player.sendMessage(text)
        self.chatView.addMessage(repr(self.player), text)
Example #15
0
class Sidepanel:
    def load(self, gmwidg):
        self.gamemodel = gmwidg.gamemodel
        self.player_cid = None
        self.model_cids = [
            self.gamemodel.connect("game_started", self.onGameStarted),
            self.gamemodel.connect_after("game_terminated", self.on_game_terminated),
        ]
        self.chatView = ChatView(self.gamemodel)
        self.chatView.disable("Waiting for game to load")
        self.chatview_cid = self.chatView.connect("messageTyped", self.onMessageSent)
        if isinstance(self.gamemodel, ICGameModel):
            self.model_cids.append(self.gamemodel.connect("observers_received",
                                   self.chatView.update_observers))
            self.model_cids.append(self.gamemodel.connect("message_received",
                                   self.onICMessageReieved))
        return self.chatView

    def on_game_terminated(self, model):
        self.chatView.disconnect(self.chatview_cid)
        if hasattr(self, "player") and hasattr(self, "player_cid") and not self.gamemodel.examined:
            self.player.disconnect(self.player_cid)
        for cid in self.model_cids:
            self.gamemodel.disconnect(cid)

    def onGameStarted(self, gamemodel):
        if gamemodel.examined:
            if gamemodel.players[0].name == gamemodel.connection.username:
                self.player = gamemodel.players[0]
                self.opplayer = gamemodel.players[1]
            else:
                self.player = gamemodel.players[1]
                self.opplayer = gamemodel.players[0]
        elif gamemodel.isObservationGame():
            # no local player but enable chat to send/receive whisper/kibitz
            pass
        elif gamemodel.players[0].__type__ == LOCAL:
            self.player = gamemodel.players[0]
            self.opplayer = gamemodel.players[1]
            if gamemodel.players[1].__type__ == LOCAL:
                log.warning("Chatpanel loaded with two local players")
        elif gamemodel.players[1].__type__ == LOCAL:
            self.player = gamemodel.players[1]
            self.opplayer = gamemodel.players[0]
        else:
            log.info("Chatpanel loaded with no local players")
            self.chatView.hide()

        if isinstance(gamemodel, ICGameModel):
            if gamemodel.connection.ICC:
                gamemodel.connection.client.run_command("set-2 %s 1" % DG_PLAYERS_IN_MY_GAME)
            else:
                allob = 'allob ' + str(gamemodel.ficsgame.gameno)
                gamemodel.connection.client.run_command(allob)

        if hasattr(self, "player") and not gamemodel.examined and self.player_cid is None:
            self.player_cid = self.player.connect("messageReceived", self.onMessageRecieved)

        self.chatView.enable()

    def onMessageRecieved(self, player, text):
        sender = "pychessbot" if player.gamemodel.offline_lecture else repr(self.opplayer)
        self.chatView.addMessage(sender, text)

    def onICMessageReieved(self, icgamemodel, player, text):
        self.chatView.addMessage(player, text)
        # emit an allob <gameno> to FICS
        if not icgamemodel.connection.ICC:
            allob = 'allob ' + str(icgamemodel.ficsgame.gameno)
            icgamemodel.connection.client.run_command(allob)

    def onMessageSent(self, chatView, text):
        if hasattr(self, "player") or self.gamemodel.examined:
            if text.startswith('# '):
                text = text[2:]
                self.gamemodel.connection.cm.whisper(text)
            elif text.startswith('whisper '):
                text = text[8:]
                self.gamemodel.connection.cm.whisper(text)
            else:
                if not hasattr(self, "player"):
                    if self.gamemodel.players[0].name == self.gamemodel.connection.username:
                        self.player = self.gamemodel.players[0]
                        self.opplayer = self.gamemodel.players[1]
                    else:
                        self.player = self.gamemodel.players[1]
                        self.opplayer = self.gamemodel.players[0]

                if self.gamemodel.examined:
                    self.opplayer.putMessage(text)
                else:
                    self.player.sendMessage(text)
                self.chatView.addMessage(repr(self.player), text)
        else:
            self.gamemodel.connection.cm.whisper(text)