Mini Shell

Direktori : /lib/python3.6/site-packages/orca/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/orca/__pycache__/chat.cpython-36.pyc

3

�2[���@s�dZdZdZdZdZdZddlZdd	lmZdd
lm	Z	ddlm
Z
ddlmZdd
lmZddlm
Z
ddlmZddlmZddlmZej�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZdS)z Implements generic chat support.z$Id$z
$Revision$z$Date$z%Copyright (c) 2010-2011 The Orca TeamZLGPL�N�)�cmdnames)�debug)�	guilabels)�input_event)�keybindings)�messages)�
orca_state)�settings)�settings_managerc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�RingListcCsg|_d|_||_d|_dS)Nr)�__data__�__full__�__max__�__cur__)�selfZlength�r�/usr/lib/python3.6/chat.py�__init__4szRingList.__init__cCsz|jdkrJx,td|jd�D]}|j|d|j|<qW||j|jd<n,|jj|�|jd7_|j|jkrvd|_dS)Nrr)r�rangerr
�appendr)r�x�irrrr:s
zRingList.appendcCs|jS)N)r
)rrrr�getEszRingList.getcCs*|jdkr&|j|jd=|jd8_dS)Nrr)rr
)rrrr�removeHs
zRingList.removecCs|jS)N)r)rrrr�sizeMsz
RingList.sizecCs|jS)N)r)rrrr�maxsizePszRingList.maxsizecCsdj|j�S)N�)�joinr
)rrrr�__str__SszRingList.__str__N)
�__name__�
__module__�__qualname__rrrrrrrrrrrr3src@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�Conversation�	NcCsR||_||_||_ttj�|_d}x$||jj�krF|jd�|d7}q$Wd|_	dS)aCreates a new instance of the Conversation class.

        Arguments:
        - name: the chatroom/conversation name
        - accHistory: the accessible which holds the conversation history
        - inputArea: the editable text object for this conversation.
        rrrN)
�name�
accHistory�	inputArearr#�MESSAGE_LIST_LENGTH�_messageHistoryr�
addMessage�
_typingStatus)rr%r&r'rrrrrbs

zConversation.__init__cCs|jj|�dS)z�Adds the current message to the message history.

        Arguments:
        - message: A string containing the message to add
        N)r)r)r�messagerrrr*�szConversation.addMessagecCs|jj�}||S)z�Returns the specified message from the message history.

        Arguments:
        - messageNumber: the index of the message to get.
        )r)r)r�
messageNumberrrrr�
getNthMessage�s
zConversation.getNthMessagecCs|jS)z<Returns the typing status of the buddy in this conversation.)r+)rrrr�getTypingStatus�szConversation.getTypingStatuscCs
||_dS)z�Sets the typing status of the buddy in this conversation.

        Arguments:
        - status: a string describing the current status.
        N)r+)r�statusrrr�setTypingStatus�szConversation.setTypingStatus)N)	r r!r"r(rr*r.r/r1rrrrr#\s
	r#c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ConversationListcCsJg|_t|�|_t|�|_d}x&||jj�krD|jdd�|d7}q WdS)z�Creates a new instance of the ConversationList class.

        Arguments:
        - messageListLength: the size of the message history to keep.
        rrNr)�
conversationsrr)�_roomHistoryrr*)r�messageListLengthrrrrr�s

zConversationList.__init__cCs@|s
d}n|j|�s|j|�|j}|jj|�|jj|�dS)z�Adds the current message to the message history.

        Arguments:
        - message: A string containing the message to add
        - conversation: The instance of the Conversation class with which
          the message is associated
        rN)�hasConversation�addConversationr%r)rr4)rr,�conversationr%rrrr*�s	

zConversationList.addMessagecCs$|jj�}|jj�}||||fS)z�Returns a list containing the specified message from the message
        history and the name of the chatroom/conversation associated with
        that message.

        Arguments:
        - messageNumber: the index of the message to get.
        )r)rr4)rr-rZroomsrrr�getNthMessageAndName�s	

z%ConversationList.getNthMessageAndNamecCs
||jkS)z�Returns True if we know about this conversation.

        Arguments:
        - conversation: the conversation of interest
        )r3)rr8rrrr6�sz ConversationList.hasConversationcCs
t|j�S)z<Returns the number of conversations we currently know about.)�lenr3)rrrr�getNConversations�sz"ConversationList.getNConversationscCs|jj|�dS)z|Adds conversation to the list of conversations.

        Arguments:
        - conversation: the conversation to add
        N)r3r)rr8rrrr7�sz ConversationList.addConversationc	Cs$y|jj|�Wn
dSdSdS)z�Removes conversation from the list of conversations.

        Arguments:
        - conversation: the conversation to remove

        Returns True if conversation was successfully removed.
        FTN)r3r)rr8rrr�removeConversation�s
z#ConversationList.removeConversationN)
r r!r"rr*r9r6r;r7r<rrrrr2�s		r2c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zd5dd�Zd6dd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd7d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�ZdS)8�ChatzTThis class implements the chat functionality which is available to
    scripts.
    c	Cs�||_||_ddddddddd	g	|_tj|_i|_|j�|j�|_	t
|j�|_t|j�|_
d
|_d
|_d
|_d
|_d
|_d
|_d
S)atCreates an instance of the Chat class.

        Arguments:
        - script: the script with which this instance is associated.
        - buddyListAncestries: a list of lists of pyatspi roles beginning
          with the the object serving as the actual buddy list (e.g.
          ROLE_TREE_TABLE) and ending with the top level object (e.g.
          ROLE_FRAME).
        ZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9N)�_script�_buddyListAncestries�messageKeysr�ORCA_MODIFIER_MASK�messageKeyModifier�inputEventHandlers�setupInputEventHandlers�getKeyBindings�keyBindingsr:r5r2�_conversationList�focusedChannelRadioButton�allChannelsRadioButton�allMessagesRadioButton�buddyTypingCheckButton�chatRoomHistoriesCheckButton�speakNameCheckButton)r�scriptZbuddyListAncestriesrrrrs
z
Chat.__init__cCs\tj|jtj�|jd<tj|jtj�|jd<tj|jtj	�|jd<tj|j
tj�|jd<dS)z�Defines InputEventHandler fields for chat functions which
        will be used by the script associated with this chat instance.�togglePrefixHandler�toggleBuddyTypingHandler�toggleMessageHistoriesHandler�
reviewMessageN)rZInputEventHandler�togglePrefixrZCHAT_TOGGLE_ROOM_NAME_PREFIXrC�toggleBuddyTypingZCHAT_TOGGLE_BUDDY_TYPING�toggleMessageHistoriesZCHAT_TOGGLE_MESSAGE_HISTORIES�readPreviousMessageZCHAT_PREVIOUS_MESSAGE)rrrrrDKszChat.setupInputEventHandlerscCs�tj�}|jtjdtjtj|jd��|jtjdtjtj|jd��|jtjdtjtj|jd��x.|jD]$}|jtj||jtj	|jd��qpW|S)z�Defines the chat-related key bindings which will be used by
        the script associated with this chat instance.

        Returns: an instance of keybindings.KeyBindings.
        rrOrPrQrR)
rZKeyBindings�addZ
KeyBindingZdefaultModifierMaskZNO_MODIFIER_MASKrCr@rBrA)rrFZ
messageKeyrrrrEes6zChat.getKeyBindingscCsBddlm}|j�}|jd�tj}tjd�}|jj	|�|_
|j
j|�|j|j
dddd�tj
}tjd�}|jj	|�|_|jj|�|j|jdddd�tj}tjd�}|jj	|�|_|jj|�|j|jdddd�|j�}|j|dd	dd�|jd
tj�}|jd�|j|�|jjdddd�}|jdddd�|j|�|j�}|j|�tjd
�}tj}|jj	d|�}|j|tjk�||_|j|jdddd�tj}|jj	d|�}	|	j |�|	j|tj!k�|	|_"|j|j"dddd�tj#|j$j%j&}|jj	d|�}
|
j |�|
j|tj'k�|
|_(|j|j(dddd�|j)�|S)zpReturn a GtkGrid containing the application unique configuration
        GUI items for the current application. r)�Gtk��chatSpeakRoomNamer�chatAnnounceBuddyTyping�chatRoomHistories��z	<b>%s</b>Tg�?�chatMessageVerbosityN)*Z
gi.repositoryrXZGridZset_border_widthrZCHAT_SPEAK_ROOM_NAME�_settingsManager�
getSettingZCheckButtonZnew_with_mnemonicrMZ
set_activeZattachZCHAT_ANNOUNCE_BUDDY_TYPINGrKZCHAT_SEPARATE_MESSAGE_HISTORIESrLZFrameZLabelZCHAT_SPEAK_MESSAGES_FROMZset_use_markupZset_label_widgetZ	Alignment�newZset_paddingrWZCHAT_SPEAK_MESSAGES_ALLZRadioButtonr
�CHAT_SPEAK_ALLrJZCHAT_SPEAK_MESSAGES_ACTIVEZ
join_group�CHAT_SPEAK_FOCUSED_CHANNELrHZ"CHAT_SPEAK_MESSAGES_ALL_IF_FOCUSEDr>�appr%�CHAT_SPEAK_ALL_IF_FOCUSEDrIZshow_all)rrXZgridZlabel�valueZ
messagesFrameZmessagesAlignmentZmessagesGridZrb1Zrb2Zrb3rrr�getAppPreferencesGUI�sb










zChat.getAppPreferencesGUIcCsJ|jj�rtj}n|jj�r$tj}ntj}||jj�|jj�|j	j�d�S)z7Returns a dictionary with the app-specific preferences.)r_rZr[r\)
rIZ
get_activer
rfrHrdrcrMrKrL)r�	verbosityrrr�getPreferencesFromGUI�s

zChat.getPreferencesFromGUIcCs8tj}tjd�}tjd|�|r(tj}|jj|�dS)z� Toggle whether we prefix chat room messages with the name of
        the chat room.

        Arguments:
        - script: the script associated with this event
        - inputEvent: if not None, the input event that caused this action.
        rZT)rZCHAT_ROOM_NAME_PREFIX_ONr`ra�
setSettingZCHAT_ROOM_NAME_PREFIX_OFFr>�presentMessage)rrN�
inputEvent�lineZ
speakRoomNamerrrrS�s	
zChat.togglePrefixcCs8tj}tjd�}tjd|�|r(tj}|jj|�dS)z� Toggle whether we announce when our buddies are typing a message.

        Arguments:
        - script: the script associated with this event
        - inputEvent: if not None, the input event that caused this action.
        r[T)rZCHAT_BUDDY_TYPING_ONr`rarkZCHAT_BUDDY_TYPING_OFFr>rl)rrNrmrnZannounceTypingrrrrT�s

zChat.toggleBuddyTypingcCs8tj}tjd�}tjd|�|r(tj}|jj|�dS)z� Toggle whether we provide chat room specific message histories.

        Arguments:
        - script: the script associated with this event
        - inputEvent: if not None, the input event that caused this action.
        r\T)rZCHAT_SEPARATE_HISTORIES_ONr`rarkZCHAT_SEPARATE_HISTORIES_OFFr>rl)rrNrmrnZ
roomHistoriesrrrrUs
zChat.toggleMessageHistoriesNrc
Cs�y|jj|j�}WnYnX|j|d}d\}}tjd�rb|jtj�}|rr|j	|�}|j
}n|jj|�\}}|r�|r�|j
||d�dS)a� Speak/braille a previous chat room message.

        Arguments:
        - script: the script associated with this event
        - inputEvent: if not None, the input event that caused this action.
        - index: The index of the message to read -- by default, the most
          recent message. If we get an inputEvent, however, the value of
          index is ignored and the index of the event_string with respect
          to self.messageKeys is used instead.
        rNr\T)NN)r@�indexZevent_stringr5r`ra�getConversationr	ZlocusOfFocusr.r%rGr9�utterMessage)rrNrmror-r,�chatRoomNamer8rrrrVs

zChat.readPreviousMessageTcCs�tj|jjd�}tjj|jjkr.|tjkr.dS|rB|tj	krBdSd}|rdtj|jjd�rdt
j|}tjs||jj
j||�}n|jj
j||�}t|j��r�|jjj|d�}|jj||d�|jj|�dS)aj Speak/braille a chat room message.

        Arguments:
        - chatRoomName: name of the chat room this message came from
        - message: the chat room message
        - focused: whether or not the current chatroom has focus. Defaults
          to True so that we can use this method to present chat history
          as well as incoming messages.
        r_NrrZ)�string)�voice)r`Z
getAppSettingr>rer	ZactiveScriptr%r
rfrdrZCHAT_MESSAGE_FROM_ROOMZpresentChatRoomLast�	utilitiesZappendStringr:�strip�speechGeneratorrt�speakMessageZdisplayBrailleMessage)rrrr,�focusedri�textrtrrrrq<s"

zChat.utterMessagecCs|jS)ayGet the actual displayed message. This will almost always be the
        unaltered any_data from an event of type object:text-changed:insert.

        Arguments:
        - event: the Event from which to take the text.

        Returns the string which should be presented as the newly-inserted
        text. (Things like chatroom name prefacing get handled elsewhere.)
        )�any_data)r�eventrrr�getMessageFromEvent`szChat.getMessageFromEventcCs:|s|jjd�s|jr dS|j|j�r0dS|j|j�r@dS|j|�r\|j||j�dS|j|j��r|j	j
r||j	j�|j|j�r�|j
|j�}t||j�}n|j|j�}|j}|j|�jd�}|r�|j||�|j|j�}|r�d}|�r�|j|||�dS|j|��r6|j}|j	jj|d�}|j	j||d�dSdS)aSGives the Chat class an opportunity to present the text from the
        text inserted Event.

        Arguments:
        - event: the text inserted Event

        Returns True if we handled this event here; otherwise False, which
        tells the associated script that is not a chat event that requires
        custom handling.
        zobject:text-changed:insertFT�
r)rs)rt)�type�
startswithr{�isGenericTextObject�source�
isInBuddyList�isTypingStatusChangedEvent�presentTypingStatusChange�
isChatRoomMsgr>ZflatReviewContextZtoggleFlatReviewMode�isNewConversation�getChatRoomNamer#rpr%r}rv�addMessageToHistory�
isFocusedChatrq�isAutoCompletedTextEventrwrtrx)rr|r%r8r,ryrzrtrrr�presentInsertedTextmsD

zChat.presentInsertedTextcCsXtjd�rT|j|j�}|rT||j�krT|jjj|d�}|jj||d�|j	|�dSdS)aCPresents a change in typing status for the current conversation
        if the status has indeed changed and if the user wants to hear it.

        Arguments:
        - event: the accessible Event
        - status: a string containing the status change

        Returns True if we spoke the change; False otherwise
        r[)rs)rtTF)
r`rarpr�r/r>rwrtrxr1)rr|r0r8rtrrrr��s

zChat.presentTypingStatusChangecCs|j|�|jj||�dS)aQAdds message to both the individual conversation's history
        as well as to the complete history stored in our conversation
        list.

        Arguments:
        - message: a string containing the message to be added
        - conversation: the instance of the Conversation class to which
          this message belongs
        N)r*rG)rr,r8rrrr��s
zChat.addMessageToHistorycCs(|j�}|jtj�r$|jtj�r$dSdS)z�Returns True if the given accessible seems to be something
        unrelated to the custom handling we're attempting to do here.

        Arguments:
        - obj: the accessible object to examine.
        TF)�getState�contains�pyatspi�STATE_EDITABLEZSTATE_SINGLE_LINE)r�obj�staterrrr��s
zChat.isGenericTextObjectcCs,|r(x"|jD]}|jjj||�rdSqWdS)ayReturns True if obj is the list of buddies in the buddy list
        window. Note that this method relies upon a hierarchical check,
        using a list of hierarchies provided by the script. Scripts
        which have more reliable means of identifying the buddy list
        can override this method.

        Arguments:
        - obj: the accessible being examined
        TF)r?r>ruZhasMatchingHierarchy)rr��roleListrrr�isBuddyList�s
zChat.isBuddyListcCsT|r|j|�rdSx<|jD]2}|d}|jjj||gtjg�}|j|�rdSqWdS)z�Returns True if obj is, or is inside of, the buddy list.

        Arguments:
        - obj: the accessible being examined
        - includeList: whether or not the list itself should be
          considered "in" the buddy list.
        TrF)r�r?r>ru�ancestorWithRoler��
ROLE_FRAME)rr�ZincludeListr�Z
buddyListRole�	candidaterrrr��s	
zChat.isInBuddyListcCs|j|�}|jj|�S)z�Returns True if the given accessible is the chat history
        associated with a new conversation.

        Arguments:
        - obj: the accessible object to examine.
        )rprGr6)rr�r8rrrr�s
zChat.isNewConversationcCsr|sdSd}|j�tjtjgkr:|j�jtj�r:|j|�}x2|jj	D]&}|r\||j
krj|SqD||jkrD|SqDWdS)z�Attempts to locate the conversation associated with obj.

        Arguments:
        - obj: the accessible of interest

        Returns the conversation if found; None otherwise
        Nr)�getRoler��	ROLE_TEXTZ
ROLE_ENTRYr�r�r�r�rGr3r%r&)rr�r%r8rrrrps		


zChat.getConversationcCsL|rH|j�tjkrH|jj�tjkrH|j�}|jtj�rH|jtj�rHdSdS)z�Returns True if the given accessible is the text object for
        associated with a chat room conversation.

        Arguments:
        - obj: the accessible object to examine.
        TF)	r�r�r��parentZROLE_SCROLL_PANEr�r�r�ZSTATE_MULTI_LINE)rr�r�rrrr�CszChat.isChatRoomMsgcCs^|rB|j�jtj�rB|jjj|�}d||f}tjtj	|d�|Sd|}tjtj	|d�dS)z�Returns True if we plan to treat this chat as focused for
        the purpose of deciding whether or not a message should be
        presented to the user.

        Arguments:
        - obj: the accessible object to examine.
        z%INFO: %s's window is focused chat: %sTz*INFO: %s is not focused chat (not showing)F)
r�r�r�Z
STATE_SHOWINGr>ruZ topLevelObjectIsActiveAndCurrentrZprintlnZ
LEVEL_INFO)rr�Zactive�msgrrrr�Ts	zChat.isFocusedChatcCs�|jjj|tjtjgtjg�}d}y2|jjj|�}|j�j	�|jj
j�j	�krR|}WnYnX|s�|jjj|tjgtjg�}y2|jjj|�}|j�j	�|jj
j�j	�kr�|}WnYnX|S)z�Attempts to find the name of the current chat room.

        Arguments:
        - obj: The accessible of interest

        Returns a string containing what we think is the chat room name.
        r)r>rur�r�Z
ROLE_PAGE_TABr�ZROLE_APPLICATIONZ
displayedText�lowerrvr%)rr�Zancestorr%rzrrrr�gs*

zChat.getChatRoomNamecCs0|jjj�\}}|dkr,|jr,|jdkr,dSdS)z�Returns True if event is associated with text being autocompleted.

        Arguments:
        - event: the accessible event being examined
        ZTab�	TF)r>ruZlastKeyAndModifiersr{)rr|ZlastKeyZmodsrrrr��szChat.isAutoCompletedTextEventcCsdS)z�Returns True if event is associated with a change in typing status.

        Arguments:
        - event: the accessible event being examined
        Fr)rr|rrrr��szChat.isTypingStatusChangedEvent)Nr)T)T)r r!r"�__doc__rrDrErhrjrSrTrUrVrqr}r�r�r�r�r�r�r�rpr�r�r�r�r�rrrrr=s2,(C
 
$
G
%*
r=)r�Z__id__�__version__Z__date__Z
__copyright__Z__license__r�rrrrrrrr	r
rZ
getManagerr`rr#r2r=rrrr�<module>s()Mq