def run(self): (height, width) = self.ncurses.chatWindow.getmaxyx() self.ncurses.textboxWindow.move(0, 0) while True: chatInput = self.ncurses.textbox.edit(self.inputValidator) # Don't send anything if we're not connected to a nick if self.ncurses.connectedNick is None: self.ncurses.appendMessage('', "Not connected to client", curses.color_pair(0)) # Stop the thread if the stop flag is set if self.stop.is_set(): self.ncurses.dialogDismissed.acquire() self.ncurses.dialogDismissed.notify() self.ncurses.dialogDismissed.release() return self.ncurses.screen.refresh() # Clear the chat input self.ncurses.textboxWindow.deleteln() self.ncurses.textboxWindow.move(0, 0) self.ncurses.textboxWindow.deleteln() # Add the new input to the chat window prefix = "(%s) %s: " % (utils.getTimestamp(), self.ncurses.nick) self.ncurses.appendMessage(prefix, chatInput[:-1], curses.color_pair(3)) # Send the input to the client self.ncurses.connectionManager.getClient( self.ncurses.connectedNick).sendChatMessage(chatInput[:-1])
def run(self): (height, width) = self.ncurses.chatWindow.getmaxyx() self.ncurses.textboxWindow.move(0, 0) while True: chatInput = self.ncurses.textbox.edit(self.inputValidator) # Don't send anything if we're not connected to a nick if self.ncurses.connectedNick is None: self.ncurses.appendMessage('', "Not connected to client", curses.color_pair(0)) # Stop the thread if the stop flag is set if self.stop.is_set(): self.ncurses.dialogDismissed.acquire() self.ncurses.dialogDismissed.notify() self.ncurses.dialogDismissed.release() return self.ncurses.screen.refresh() # Clear the chat input self.ncurses.textboxWindow.deleteln() self.ncurses.textboxWindow.move(0, 0) self.ncurses.textboxWindow.deleteln() # Add the new input to the chat window prefix = "(%s) %s: " % (utils.getTimestamp(), self.ncurses.nick) self.ncurses.appendMessage(prefix, chatInput[:-1], curses.color_pair(3)) # Send the input to the client self.ncurses.connectionManager.getClient(self.ncurses.connectedNick).sendChatMessage(chatInput[:-1])
def run(self): (height, width) = self.ncurses.chatWindow.getmaxyx() while True: try: response = self.ncurses.client.receiveMessage(constants.COMMAND_MSG) except exceptions.ProtocolEnd: self.ncurses.client.disconnect() CursesDialog(self.ncurses.chatWindow, errors.CLIENT_ENDED_CONNECTION, errors.TITLE_END_CONNECTION, isError=True).show() return except (exceptions.NetworkError, exceptions.CryptoError) as e: self.handleNetworkError(e) mutex.acquire() # Put the received data in the chat window timestamp = utils.getTimestamp() self.ncurses.chatWindow.scroll(1) self.ncurses.chatWindow.addstr(height-1, 0, timestamp) self.ncurses.chatWindow.addstr(height-1, len(timestamp), response, curses.color_pair(3)) # Move the cursor back to the chat input window self.ncurses.textboxWindow.move(0, 0) self.ncurses.chatWindow.refresh() self.ncurses.textboxWindow.refresh() mutex.release()
def run(self): (height, width) = self.ncurses.chatWindow.getmaxyx() while True: chatInput = self.ncurses.textbox.edit(self.inputValidator) mutex.acquire() # Clear the chat input self.ncurses.textboxWindow.deleteln() self.ncurses.textboxWindow.move(0, 0) self.ncurses.textboxWindow.deleteln() # Add the new input to the chat window timestamp = utils.getTimestamp() self.ncurses.chatWindow.scroll(1) self.ncurses.chatWindow.addstr(height-1, 0, timestamp) self.ncurses.chatWindow.addstr(height-1, len(timestamp), chatInput[:-1], curses.color_pair(2)) # Send the input to the client try: self.ncurses.client.sendMessage(constants.COMMAND_MSG, chatInput[:-1]) except exceptions.NetworkError as ne: self.ncurses.client.disconnect() CursesDialog(self.ncurses.chatWindow, str(ne), errors.TITLE_NETWORK_ERROR, isError=True).show() # Move the cursor back to the chat input window self.ncurses.textboxWindow.move(0, 0) self.ncurses.chatWindow.refresh() self.ncurses.textboxWindow.refresh() mutex.release()
def appendMessage(self, message, source, showTimestampAndNick=True): color = self.__getColor(source) if showTimestampAndNick: timestamp = ( '<font color="' + color + '">(' + utils.getTimestamp() + ") <strong>" + (self.connectionManager.nick if source == constants.SENDER else self.nick) + ":</strong></font> " ) else: timestamp = "" # If the user has scrolled up (current value != maximum), do not move the scrollbar # to the bottom after appending the message shouldScroll = True scrollbar = self.chatLog.verticalScrollBar() if scrollbar.value() != scrollbar.maximum() and source != constants.SENDER: shouldScroll = False self.chatLog.append(timestamp + message) # Move the vertical scrollbar to the bottom of the chat log if shouldScroll: scrollbar.setValue(scrollbar.maximum())
def __receiveMessageLoop(self): self.inRecveiveLoop = True while True: # Keyboard interrupts are ignored unless a timeout is specified # See http://bugs.python.org/issue1360 message = self.messageQueue.get(True, 31536000) if self.errorRaised.is_set(): self.__restart() return prefix = "(%s) %s: " % (utils.getTimestamp(), message[1]) self.appendMessage(prefix, message[2], curses.color_pair(2)) self.messageQueue.task_done()
def appendMessage(self, message, source, showTimestamp=True): if showTimestamp: timestamp = utils.getTimestamp() else: timestamp = '' color = self.__getColor(source) # If the user has scrolled up (current value != maximum), do not move the scrollbar # to the bottom after appending the message shouldScroll = True scrollbar = self.chatLog.verticalScrollBar() if scrollbar.value() != scrollbar.maximum() and source != constants.SENDER: shouldScroll = False # Append the message to the end of the chat log self.chatLog.append(timestamp + '<font color="' + color + '">' + message + "</font>") # Move the vertical scrollbar to the bottom of the chat log if shouldScroll: scrollbar.setValue(scrollbar.maximum())
def appendMessage(self, message, source, showTimestampAndNick=True): color = self.__getColor(source) if showTimestampAndNick: timestamp = '<font color="' + color + '">(' + utils.getTimestamp() + ') <strong>' + \ (self.connectionManager.nick if source == constants.SENDER else self.nick) + \ ':</strong></font> ' else: timestamp = '' # If the user has scrolled up (current value != maximum), do not move the scrollbar # to the bottom after appending the message shouldScroll = True scrollbar = self.chatLog.verticalScrollBar() if scrollbar.value() != scrollbar.maximum( ) and source != constants.SENDER: shouldScroll = False self.chatLog.append(timestamp + message) # Move the vertical scrollbar to the bottom of the chat log if shouldScroll: scrollbar.setValue(scrollbar.maximum())
def __addMessageToChat(self, message): prefix = "(%s) %s: " % (utils.getTimestamp(), self.ncurses.nick) self.ncurses.appendMessage(prefix, message, curses.color_pair(3))