
    g
f2                         d Z dZdZdZdZdZddlZddlZ ej                  dd	       dd
l	m
Z
 ddl	mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  G d d      Z G d d      Z e       Zd Zy)z Module for notification messagesz$Id$z
$Revision$z$Date$zLCopyright (c) 2023 Igalia, S.L.Copyright (c) 2010 Informal Informatica LTDA.LGPL    NGtkz3.0)GObject)r      )cmdnames)debug)	guilabels)input_event)keybindings)messages)
orca_statec                   j    e Zd ZdZd ZddZddZd Zd Zd Z	d Z
d	 ZddZddZddZddZd Zy
)NotificationPresenterz,Provides access to the notification history.c                     d | _         | j                  d      | _        t        j                         | _        d| _        g | _        d| _        y )NT7   )	_guiget_handlers	_handlersr   KeyBindings	_bindings	_max_size_notifications_current_indexselfs    =/usr/lib/python3/dist-packages/orca/notification_presenter.py__init__zNotificationPresenter.__init__3   sD    	**40$002 !     c                     |rCd}t        j                  t         j                  |d       | j                          | j                  S | j                  j                         r| j                          | j                  S )z/Returns the notification-presenter keybindings.z,NOTIFICATION PRESENTER: Refreshing bindings.T)r   printMessage
LEVEL_INFO_setup_bindingsr   isEmpty)r   refresh
is_desktopmsgs       r   get_bindingsz"NotificationPresenter.get_bindings@   sd     @Cu//d;  " ~~ ^^##%  "~~r   c                     |r7d}t        j                  t         j                  |d       | j                          | j                  S )z,Returns the notification-presenter handlers.z,NOTIFICATION PRESENTER: Refreshing handlers.T)r   r!   r"   _setup_handlersr   )r   r%   r'   s      r   r   z"NotificationPresenter.get_handlersL   s:     @Cu//d;  "~~r   c                 <   d|dg}t        j                  t         j                  |d       t        t	        | j
                        | j                  z
  dz   d      }| j
                  |d | _        | j
                  j                  |t        j                         g       y)z2Adds message to the list of notification messages.z NOTIFICATION PRESENTER: Adding 'z'.Tr   r   N)	r   printTokensr"   maxlenr   r   appendtime)r   messagetokens	to_removes       r   save_notificationz'NotificationPresenter.save_notificationV   s     5gtD%**FD9D//04>>AAEqI	"11)*=""GTYY[#9:r   c                 n    d}t        j                  t         j                  |d       g | _        d| _        y)zClears the notifications list.z&NOTIFICATION PRESENTER: Clearing list.Tr   N)r   r!   r"   r   r   r   r'   s     r   
clear_listz NotificationPresenter.clear_list_   s1     75++S$7  r   c                 8   i | _         t        j                  | j                  t        j
                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   d}t        j                  t        j                  |d       y)z8Sets up the notification-presenter input event handlers.present_last_notificationpresent_next_notificationpresent_previous_notificationshow_notification_listz(NOTIFICATION PRESENTER: Handlers set up.TN)r   r
   InputEventHandler_present_last_notificationr   NOTIFICATION_MESSAGES_LAST_present_next_notificationNOTIFICATION_MESSAGES_NEXT_present_previous_notificationNOTIFICATION_MESSAGES_PREVIOUS_show_notification_listNOTIFICATION_MESSAGES_LISTr   r!   r"   r6   s     r   r*   z%NotificationPresenter._setup_handlersg   s      ))//335 	23 ))//335 	23 ))33779 	67 )),,335 	/0
 95++S$7r   c           
         t        j                         | _        | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   d}t        j                  t        j                  |d       y)	z0Sets up the notification-presenter key bindings. r9   r:   r;   r<   z(NOTIFICATION PRESENTER: Bindings set up.TN)r   r   r   add
KeyBindingdefaultModifierMaskNO_MODIFIER_MASKr   getr   r!   r"   r6   s     r   r#   z%NotificationPresenter._setup_bindings   s_    %002""//,,""#>?	A	B 	""//,,""#>?	A	B 	""//,,""#BC	E	F 	""//,,""#;<	>	? 95++S$7r   c                 J   t        j                          |z
  }|dk  rt        j                  |      S |dk  r#t        |dz        }t        j                  |      S |dk  r#t        |dz        }t        j
                  |      S t        |dz        }t        j                  |      S )N<   i  iQ )r0   r   
secondsAgoround
minutesAgohoursAgodaysAgo)r   	timestampdiffminuteshoursdayss         r   _timestamp_to_stringz*NotificationPresenter._timestamp_to_string   s    yy{Y&"9&&t,,$;D2I&G&&w//%<$+&E$$U++TE\"%%r   Nc                 *   | j                   s |j                  t        j                         yd}t	        j
                  t        j                  |d       | j                   d   \  }}| d| j                  |       }|j                  |       d| _        y)zPresents the last notification.Tz5NOTIFICATION PRESENTER: Presenting last notification.r    )	r   presentMessager   NOTIFICATION_NO_MESSAGESr   r!   r"   rY   r   )r   scripteventr'   r1   rT   strings          r   r>   z0NotificationPresenter._present_last_notification   s     ""!!("C"CDE5++S$7!0049Ad77	BCDf% r   c                    | j                   s |j                  t        j                         yd| j                   }t        j                  t
        j                  |d       | j                  dk(  r<|j                  t        j                         | j                   | j                     \  }}n7	 | j                  dz
  }| j                   |   \  }}| xj                  dz  c_        | d| j                  |       }|j                  |       y# t        $ re d}t        j                  t
        j                  |d       |j                  t        j                         | j                   | j                     \  }}Y w xY w)z#Presents the previous notification.TzINOTIFICATION PRESENTER: Presenting previous notification. Current index: r   r   6NOTIFICATION PRESENTER: Handling IndexError exception.r[   )r   r\   r   r]   r   r   r!   r"   NOTIFICATION_LIST_TOP
IndexErrorrY   r   r^   r_   r'   r1   rT   indexr`   s           r   rB   z4NotificationPresenter._present_previous_notification   sb    ""!!("C"CD"1124 	 	5++S$7 !#!!("@"@A!%!4!4T5H5H!IGYN++a/%)%8%8%?"##q(# 9Ad77	BCDf%  NN""5#3#3S$?%%h&D&DE%)%8%89L9L%M"	N   -6D A+E98E9c                    | j                   s |j                  t        j                         yd| j                   }t        j                  t
        j                  |d       | j                  dk(  r<|j                  t        j                         | j                   | j                     \  }}n7	 | j                  dz   }| j                   |   \  }}| xj                  dz  c_        | d| j                  |       }|j                  |       y# t        $ re d}t        j                  t
        j                  |d       |j                  t        j                         | j                   | j                     \  }}Y w xY w)zPresents the next notification.TzENOTIFICATION PRESENTER: Presenting next notification. Current index: r   r   rb   r[   )r   r\   r   r]   r   r   r!   r"   NOTIFICATION_LIST_BOTTOMrd   rY   re   s           r   r@   z0NotificationPresenter._present_next_notification   sb    ""!!("C"CD"1124 	 	5++S$7 "$!!("C"CD!%!4!4T5H5H!IGYN++a/%)%8%8%?"##q(# 9Ad77	BCDf%  NN""5#3#3S$?%%h&G&GH%)%8%89L9L%M"	Nrg   c                    | j                   s |j                  t        j                         yd}t	        j
                  t        j                  |d       t        | j                         D cg c]  \  }}|| j                  |      f }}}t        j                  t        | j                               }t        j                  t        j                  g}t        ||||      | _        | j                  j!                          yc c}}w )z0Opens a dialog with a list of the notifications.Tz2NOTIFICATION PRESENTER: Showing notification list.)r   r\   r   r]   r   r!   r"   reversedrY   r	   notifications_countr.   NOTIFICATIONS_COLUMN_HEADERNOTIFICATIONS_RECEIVED_TIMENotificationListGUIr   show_gui)	r   r^   r_   r'   r1   rT   rowstitlecolumn_headerss	            r   rD   z-NotificationPresenter._show_notification_list  s     ""!!("C"CDB5++S$7 /7t7J7J.KM* $33I>? M M--c$2E2E.FG#??#??A'~tL			Ms   ,Dc                     d| _         y)z1Handler for the 'destroyed' signal of the dialog.N)r   r   s    r   on_dialog_destroyedz)NotificationPresenter.on_dialog_destroyed  s     	r   )FT)FN)__name__
__module____qualname____doc__r   r(   r   r4   r7   r*   r#   rY   r>   rB   r@   rD   ru    r   r   r   r   0   sI    6!
;!88"8H&  @@&r   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)ro   z-The dialog containing the notifications list.c                 P    || _         d | _        | j                  |||      | _        y rv   )_script_model_create_dialogr   )r   r^   rr   rs   rq   s        r   r   zNotificationListGUI.__init__"  s&    ''~tD	r   c           	         t        j                  |d t         j                  j                  t         j                  t         j
                  j                  t         j                  t         j
                  j                  f      }|j                  dd       t        j                         }|j                         }|j                  |       t        j                         }|j                  |       t        j                         }|j                  d       |j!                  d       |j                  |       t#        |      t$        j&                  gz  }	t)        |      D ]V  \  }
}t        j*                         }t        j,                  |||
      }|j/                  |       |sF|j1                  |
       X t        j2                  |	 | _        |D ]M  }| j4                  j7                  d       }t)        |      D ]"  \  }
}| j4                  j9                  ||
|       $ O |j;                  | j4                         |j=                  d| j>                         |S )NiX  i  T)textresponse) r   DialogDialogFlagsMODALSTOCK_CLEARResponseTypeAPPLYSTOCK_CLOSECLOSEset_default_sizeGridget_content_arearH   ScrolledWindowTreeViewset_hexpandset_vexpandr.   r   TYPE_STRING	enumerateCellRendererTextTreeViewColumnappend_columnset_sort_column_id	ListStorer   r/   	set_value	set_modelconnecton_response)r   rr   rs   rq   dialoggridcontent_areascrolled_windowtreecolsiheadercellcolumnrowrow_iters                   r   r   z"NotificationListGUI._create_dialog'  s   E OO11 __c.>.>.D.D __c.>.>.D.DFG
 	S)xxz..0,,.!||~D!>"g&9&9%::">2 	-IAv'')D''1=Fv&))!,	- mmT* 	9C{{))$/H$S> 94%%h489	9
 	t{{#z4#3#34r   c                    |t         j                  j                  k(  r| j                  j	                          y|t         j                  j
                  k(  r| j                  | j                  j                          t               j                          | j                  j                  t        j                         t        j                  d       | j                  j	                          yyy)z&The handler for the 'response' signal.Nr   )r   r   r   r   destroyr   r   cleargetPresenterr7   r~   r\   r   r]   r0   sleep)r   r   r   s      r   r   zNotificationListGUI.on_responseM  s     s''---IIs''---$++2IKKN%%'LL''(I(IJJJqMII 3J-r   c                     | j                   j                          t        j                  j                  }|dk(  rt        j                         }| j                   j                  |       y)z$Shows the notifications list dialog.r   N)r   show_allr   lastInputEventrT   r   get_current_event_timepresent_with_time)r   
time_stamps     r   rp   zNotificationListGUI.show_gui[  sL     			..88
?335J		##J/r   N)rw   rx   ry   rz   r   r   r   rp   r{   r   r   ro   ro     s    7E
$L 0r   ro   c                      t         S )z"Returns the Notification Presenter)
_presenterr{   r   r   r   r   e  s
     r   )rz   __id____version____date____copyright____license__r0   girequire_versiongi.repositoryr   r   rG   r   r   r	   r
   r   r   r   r   ro   r   r   r{   r   r   <module>r      s   0 '@  	   5%   !        m m^C0 C0J #$
r   