
    g
fG                         d Z dZdZdZdZdZ	 ddlZddl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 e       Zd Zy# e$ r dZY Fw xY w)z(Module for presenting system informationz$Id$z
$Revision$z$Date$zyCopyright (c) 2005-2008 Sun Microsystems Inc.Copyright (c) 2016-2024 Igalia, S.L.Copyright (c) 2024 GNOME Foundation Inc.LGPL    N   )cmdnames)debug)input_event)keybindings)messages)settings_managerc                   R    e Zd ZdZd ZddZddZd Zd ZddZ	dd	Z
dd
ZddZy)SystemInformationPresenterz0Provides commands to present system information.c                 b    | j                  d      | _        t        j                         | _        y )NT)get_handlers	_handlersr   KeyBindings	_bindings)selfs    C/usr/lib/python3/dist-packages/orca/system_information_presenter.py__init__z#SystemInformationPresenter.__init__2   s$    **40$002    c                     |rCd}t        j                  t         j                  |d       | j                          | j                  S | j                  j                         r| j                          | j                  S )z5Returns the system-information-presenter keybindings.z2SYSTEM INFORMATION PRESENTER: Refreshing bindings.T)r   printMessage
LEVEL_INFO_setup_bindingsr   isEmpty)r   refresh
is_desktopmsgs       r   get_bindingsz'SystemInformationPresenter.get_bindings6   sd     FCu//d;  " ~~ ^^##%  "~~r   c                     |r7d}t        j                  t         j                  |d       | j                          | j                  S )z2Returns the system-information-presenter handlers.z2SYSTEM INFORMATION PRESENTER: Refreshing handlers.T)r   r   r   _setup_handlersr   )r   r   r   s      r   r   z'SystemInformationPresenter.get_handlersB   s:     FCu//d;  "~~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)z>Sets up the system-information-presenter input event handlers.presentTimeHandlerpresentDateHandlerpresent_battery_statuspresent_cpu_and_memory_usagez.SYSTEM INFORMATION PRESENTER: Handlers set up.TN)r   r   InputEventHandlerpresent_timer   PRESENT_CURRENT_TIMEpresent_datePRESENT_CURRENT_DATEr$   PRESENT_BATTERY_STATUSr%   PRESENT_CPU_AND_MEMORY_USAGEr   r   r   r   r   s     r   r    z*SystemInformationPresenter._setup_handlersL   s      ))!!--/ 	+, ))!!--/ 	+, ))++//1 	/0 ))11557 	56
 ?5++S$7r   c           
         t        j                         | _        | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             d	}t        j                  t        j                  |d
       y)z6Sets up the system-information-presenter key bindings.tr"   r   r#       r$   r%   z.SYSTEM INFORMATION PRESENTER: Bindings set up.TN)r   r   r   add
KeyBindingdefaultModifierMaskORCA_MODIFIER_MASKr   getr   r   r   r-   s     r   r   z*SystemInformationPresenter._setup_bindingsh   se    %002""//..""#78	 	""//..""#78	 	""//..""#;<	 	""//..""#AB	 ?5++S$7r   Nc                     t        j                         j                  d      }|j                  t	        j
                  |t	        j                                      y)zPresents the current time.presentTimeFormatTr
   
getManager
getSettingpresentMessagetimestrftime	localtime)r   scripteventtime_formats       r   r'   z'SystemInformationPresenter.present_time   A     '113>>?RSdmmK9IJKr   c                     t        j                         j                  d      }|j                  t	        j
                  |t	        j                                      y)zPresents the current date.presentDateFormatTr9   )r   r@   rA   data_formats       r   r)   z'SystemInformationPresenter.present_date   rC   r   c                    t         rt        j                         s |j                  t        j                         yt        j                         }|j
                  r1t        j                  |j                  z   dt        j                   }n0t        j                  |j                  z   dt        j                   }|j                  |       y)zPresents the battery status.T )
psutilsensors_batteryr<   r	   BATTERY_STATUS_UNKNOWNpower_pluggedBATTERY_LEVELpercentBATTERY_PLUGGED_IN_TRUEBATTERY_PLUGGED_IN_FALSE)r   r@   rA   batteryr   s        r   r$   z1SystemInformationPresenter.present_battery_status   s     6113!!("A"AB((*  ++goo=>a@`@`?abC++goo=>a@a@a?bcCc"r   c                    t          |j                  t        j                         yt	        t        j
                               }t        j                         }t	        |j                        }|j                  dkD  r1t        j                  |j                  dz  |j                  dz        }n0t        j                  |j                  dz  |j                  dz        }t        j                  ||fz   d| }|j                  |       y)z"Presents the cpu and memory usage.Ti   @i   z. )rI   r<   r	   CPU_AND_MEMORY_USAGE_UNKNOWNroundcpu_percentvirtual_memoryrN   totalmemoryUsageGBusedmemoryUsageMBCPU_AND_MEMORY_USAGE_LEVELS)r   r@   rA   	cpu_usagememorymemory_percentdetailsr   s           r   r%   z7SystemInformationPresenter.present_cpu_and_memory_usage   s     >!!("G"GH&,,./	&&(fnn-<<)#,,V[[I-FXaHbcG,,V[[I-FXaHbcG55N8SSTTVW^V_`c"r   )FT)FN)__name__
__module____qualname____doc__r   r   r   r    r   r'   r)   r$   r%    r   r   r   r   /   s3    :3
88&8P r   r   c                      t         S r`   )
_presenterre   r   r   getPresenterrh      s    r   )rd   __id____version____date____copyright____license__rI   ModuleNotFoundErrorr=   r1   r   r   r   r   r	   r
   r   rg   rh   re   r   r   <module>ro      sy   , /;        Q Qh ()
E  Fs   A AA