
    ը	f                     `   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
mZmZ ddlmZ  G d d	e      Z G d
 d      Z G d d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy) a  
@package mapdisp.statusbar

@brief Classes for statusbar management

Classes:
 - statusbar::SbException
 - statusbar::SbManager
 - statusbar::SbItem
 - statusbar::SbRender
 - statusbar::SbMapScale
 - statusbar::SbGoTo
 - statusbar::SbTextItem
 - statusbar::SbDisplayGeometry
 - statusbar::SbCoordinates
 - statusbar::SbRegionExtent
 - statusbar::SbCompRegionExtent
 - statusbar::SbProgress

(C) 2006-2011 by the GRASS Development Team

This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.

@author Vaclav Petras <wenzeslaus gmail.com>
@author Anna Kratochvilova <kratochanna gmail.com>
    N)utils)
RunCommand)UserSettings)TextCtrlMenuNewId)Signalc                       e Zd ZdZd Zd Zy)SbExceptionz-Exception class used in SbManager and SbItemsc                     || _         y Nmessage)selfr   s     2/usr/lib/grass83/gui/wxpython/mapdisp/statusbar.py__init__zSbException.__init__+   s	        c                     | j                   S r   r   r   s    r   __str__zSbException.__str__/   s    ||r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   (   s    7r   r   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)	SbManagera  Statusbar manager for wx.Statusbar and SbItems.

    Statusbar manager manages items added by AddStatusbarItem method.
    Provides progress bar (SbProgress).
    Items with position 0 are shown according to selection in Map Display settings dialog.
    Only one item of the same class is supposed to be in statusbar.
    Manager user have to create statusbar on his own, add items to manager
    and call Update method to show particular widgets.
    User settings (group = 'display', key = 'statusbarMode', subkey = 'selection')
    are taken into account.

    .. todo::
        generalize access to UserSettings (specify group, etc.)

    .. todo::
        add GetMode method using name instead of index
    c                 f   || _         || _        t               | _        d| _        d| _        d| _        t        | j                   | j                  |       | _        | j                  j                  j                  | j                         | j                  j                  j                  | j                         | j                  j                  t        j                   | j"                         | j                   j$                  j&                  j                  | j(                         d| _        i | _        y)zEConnects manager to statusbar

        Creates progress bar.
        Fr    N)mapFrame	statusbardictstatusbarItems_postInitialized_modeIndexSet_mode
SbProgressprogressbarprogressShownconnect_progressShownprogressHidden_progressHiddenBindwxEVT_CONTEXT_MENUOnContextMenumapWindowPropertiessbItemChangedSetMode
_oldStatusdisabledItems)r   mapframer!   s      r   r   zSbManager.__init__F   s    
 !""f %"
%dmmT^^TJ&&..t/B/BC''//0D0DEB//1C1CD))77??Mr   c                 @    | j                   |   j                  |       y)zSets property represented by one of contained SbItems

        :param name: name of SbItem (from name attribute)
        :param value: value to be set
        N)r#   SetValue)r   namevalues      r   SetPropertyzSbManager.SetProperty_   s     	D!**51r   c                 <    | j                   |   j                         S )z|Returns property represented by one of contained SbItems

        :param name: name of SbItem (from name attribute)
        )r#   GetValuer   r:   s     r   GetPropertyzSbManager.GetPropertyg   s    
 ""4(1133r   c                 "    || j                   v ryy)zChecks whether property is represented by one of contained SbItems

        :param name: name of SbItem (from name attribute)

        :return: True if particular SbItem is contained, False otherwise
        TF)r#   r?   s     r   HasPropertyzSbManager.HasPropertyn   s     4&&&r   c                 6    || j                   |j                  <   y)zAdds item to statusbarN)r#   r:   r   items     r   AddStatusbarItemzSbManager.AddStatusbarItemy   s    )-DII&r   c                 D    |D ]  } |di |}| j                  |        y)zAdds items to statusbar

        :param list itemClasses: list of classes of items to be add
        :param kwargs: SbItem constructor parameters

        :func:`AddStatusbarItem`
        Nr   )rF   )r   itemClasseskwargsItemrE   s        r   AddStatusbarItemsByClassz"SbManager.AddStatusbarItemsByClass}   s,       	(D>&>D!!$'	(r   c                     |D ]y  }t        dt        | j                  j                                     D ]G  }t	        | j                  j                               |   }|j
                  |k(  s9|| j                  |<   I { y)zyFill list of item indexes that are disabled.

        :param itemClasses list of classes of items to be disabled
        r   N)rangelenr#   valueslist	__class__r6   )r   rH   	itemClassirE   s        r   DisableStatusbarItemsByClassz&SbManager.DisableStatusbarItemsByClass   sw    
 % 	1I1c$"5"5"<"<">?@ 1D//6689!<>>Y.,0D&&q)1	1r   c                     | j                   j                         D cg c]!  }|j                         dk(  r|j                  # c}S c c}w )zGet list of item labelsr   )r#   rO   GetPositionlabelr   r;   s     r   GetItemLabelszSbManager.GetItemLabels   sH     ,,335
  "a' KK
 	
 
   &Ac                     | j                   j                         D cg c]!  }|j                         dk(  r|j                  # c}S c c}w )z Get list of disabled item labelsr   )r6   rO   rV   rW   rX   s     r   GetDisabledItemLabelszSbManager.GetDisabledItemLabels   sH     ++224
  "a' KK
 	
 
rZ   c                     | j                   |   j                         dk7  s| j                  j                         s| j                   |   j	                          yy)zCInvokes showing of particular item

        :func:`Update`
        r   N)r#   rV   r(   IsShownShow)r   itemNames     r   ShowItemzSbManager.ShowItem   sN     )5571<##++-)..0 .r   c                 J   t        j                  ddd| j                         d       | j                  sX| j	                  t        j
                  ddd             t        j
                  ddd      | j                  j                  _        | j                          d| _
        y	)
zPost-initialization method

        It sets internal user settings,
        set selection (from map display settings) and does reposition.
        It is called automatically.
        displaystatusbarModechoicesinternal)groupkeysubkeyr;   settings_type	selectionrg   rh   ri   TN)r   SetrY   r%   r4   Getr    r2   sbItem
Repositionr$   r   s    r   	_postInitzSbManager._postInit   s     	$$&$	
 !!LL  #
 8D7G7G_[8DMM--4 	 $r   c                 
   | j                   j                          | j                  s| j                          | j                  j                         D ]Q  }|j                         dk(  r,| j                   j                         r1|j                          B|j                          S | j                   j                         ryt        | j                  j                               | j                            }|j                          y)zUpdates statusbarr   N)r(   Updater$   rq   r#   rO   rV   r^   HiderP   GetModerD   s     r   rs   zSbManager.Update   s    !$$NN''..0 	D!Q&''//1IIK	 ##%++2245dllnEDKKMr   c                    g }| j                   j                         D ]1  }|j                  |j                         |j	                         f       3 |j                  d| j
                  j	                         f       |D ]  \  }}|s	| j                  j                  |      }|dk(  rC|j                         \  }}|j                  dz   |j                  dz
  }	}||j                  dz   }}
ni|j                  |j                  }	}|j                  |j                  dz   }}
|| j
                  j	                         k(  r|j                  dz
  }|dk(  r|dz  }|j                  ||	f       |j                  |
|f        y)zReposition items in statusbar

        Set positions to all items managed by statusbar manager.
        It should not be necessary to call it manually.
           r               N)r#   rO   appendrV   	GetWidgetr(   r!   GetFieldRectGetBestSizexyheightwidthSetPositionSetSize)r   widgetsrE   idxwinrectwWinhWinr   r   whs               r   rp   zSbManager.Reposition   sV    ''..0 	CDNND,,.0@AB	C 	4++55789 	 HC>>..s3Dax __.
d vvz466A:1T[[1_1vvtvv1zz4;;?1$**4466::>D!8FAOOQF#KKA-	 r   c                     | j                   S )zReturns progress bar)r(   r   s    r   GetProgressBarzSbManager.GetProgressBar  s    r   c                 D    | j                   j                  d      | _        y Nr   )r!   GetStatusTextr5   r   s    r   r+   zSbManager._progressShown  s    ..66q9r   c                 P    | j                   j                  | j                  d       y r   )r!   SetStatusTextr5   r   s    r   r-   zSbManager._progressHidden	  s    $$T__a8r   c                 @    || _         d| _        | j                          y)zvSets current mode and updates statusbar

        Mode is usually driven by user through map display settings.
        TN)r&   r%   rs   )r   modes     r   r4   zSbManager.SetMode  s    
 
!r   c                     | j                   S )zReturns current mode)r&   r   s    r   ru   zSbManager.GetMode  s    zzr   c                     | j                   j                  |       | j                   j                  |       |r| j                  j	                  |       yy)zUpdate progress.N)r(   SetRanger9   r!   r   )r   rM   r;   texts       r   SetProgresszSbManager.SetProgress  sD    !!%(!!%(NN((. r   c                 j     fd fd}t               }t         j                               D ]  \  }}t               } j                  j                  t        j                  |ffd	|       |j                  ||t        j                         |j                  |      d   }| |       k(  r!|j                  |j                         du        | j                         v s|j                  d         j                  j                  |       |j!                          |j#                          y	)
zOPopup context menu enabling to choose a widget that will be shown in statusbar.c                 <    | j                   j                  _        y r   r    r2   ro   )r   r   s    r   setSbItemPropertyz2SbManager.OnContextMenu.<locals>.setSbItemProperty#  s    7:DMM--4r   c                  D     j                   j                  j                  S r   r   r   s   r   getSbItemPropertyz2SbManager.OnContextMenu.<locals>.getSbItemProperty&  s    ==44;;;r   c                      |      S r   r   )evtr   r   s     r   <lambda>z)SbManager.OnContextMenu.<locals>.<lambda>.  s    #4S#9 r   )id)kindr   F)enableN)r   	enumeraterY   r   r!   r.   r/   EVT_MENUAppend
ITEM_RADIOFindItemCheck	IsCheckedr\   Enable	PopupMenuDestroySkip)	r   eventr   menurS   rW   wxidrE   r   s	   `       @r   r1   zSbManager.OnContextMenu   s    	;	< v!$"4"4"67 	*HAu7DNN !9   
 KKe"--K8==&q)D%''

4>>+u4533565)	* 	  &

r   N)r   r   r   r   r   r<   r@   rB   rF   rK   rT   rY   r\   ra   rq   rs   rp   r   r+   r-   r4   ru   r   r1   r   r   r   r   r   3   sl    $ 224	.
(	1

	1%6&# J :9/r   r   c                   H    e Zd ZdZddZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)SbItema  Base class for statusbar items.

    Each item represents functionality (or action) controlled by statusbar
    and related to MapFrame.
    One item is usually connected with one widget but it is not necessary.
    Item can represent property (depends on manager).
    Items are not widgets but can provide interface to them.
    Items usually has requirements to MapFrame instance
    (specified as MapFrame.methodname or MapWindow.methodname).

    .. todo::
        consider externalizing position (see SbProgress use in SbManager)
    c                 .    || _         || _        || _        y)a$  

        :param mapframe: instance of class with MapFrame interface
        :param statusbar: statusbar instance (wx.Statusbar)
        :param position: item position in statusbar

        .. todo::
            rewrite Update also in derived classes to take in account item position
        N)r    r!   positionr   r7   r!   r   s       r   r   zSbItem.__init__M  s     !" r   c                 8    | j                   j                          y)zInvokes showing of underlying widget.

        In derived classes it can do what is appropriate for it,
        e.g. showing text on statusbar (only).
        N)widgetr_   r   s    r   r_   zSbItem.Show[  s     	r   c                 8    | j                   j                          y r   )r   rt   r   s    r   rt   zSbItem.Hidec  s    r   c                 :    | j                   j                  |       y r   r   r9   rX   s     r   r9   zSbItem.SetValuef      U#r   c                 6    | j                   j                         S r   )r   r>   r   s    r   r>   zSbItem.GetValuei  s    {{##%%r   c                     | j                   S r   )r   r   s    r   rV   zSbItem.GetPositionl  s    }}r   c                     | j                   S )zUReturns underlying widget.

        :return: widget or None if doesn't exist
        r   r   s    r   r}   zSbItem.GetWidgeto      
 {{r   c                     | j                   j                  dd       | j                          | j                  j	                  |       y)zzDefault implementation for Update method.

        :param longHelp: True to enable long help (help from toolbars)
        r   r   N)r!   r   r_   r    StatusbarEnableLongHelp)r   longHelps     r   _updatezSbItem._updatev  s3    
 	$$R+		--h7r   c                 (    | j                  d       y)zNCalled when statusbar action is activated (e.g. through Map Display settings).Fr   Nr   r   s    r   rs   zSbItem.Update  s    e$r   Nr   )r   r   r   r   r   r_   rt   r9   r>   rV   r}   r   rs   r   r   r   r   r   >  s4    !$&8%r   r   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
SbRenderz[Checkbox to enable and disable auto-rendering.

    Requires MapFrame.OnRender method.
    c                 h   t         j                  | |||       d| _        |j                  | _        t        j                  | j                  t
        j                  t        d            | _
        | j                  j                  | j                  j                         | j                  j                          | j                  j                  t        j                  t        d                   | j!                          | j                  j#                  t
        j$                  | j&                         y )NrenderRender)parentr   rW   zEnable/disable auto-rendering)r   r   r:   r2   _propertiesr/   CheckBoxr!   ID_ANY_r   r9   
autoRenderrt   
SetToolTipToolTip_connectAutoRenderr.   EVT_CHECKBOX_onCheckboxr   s       r   r   zSbRender.__init__  s    h	8<	#77kk>>biiq{
 	T--889rzz!,K*LMN!$*:*:;r   c                 :    | j                   j                  |       y r   r   rX   s     r   	_setValuezSbRender._setValue  r   r   c                 b    | j                   j                  j                  | j                         y r   )r   autoRenderChangedr*   r   r   s    r   r   zSbRender._connectAutoRender  s     **224>>Br   c                 b    | j                   j                  j                  | j                         y r   )r   r   
disconnectr   r   s    r   _disconnectAutoRenderzSbRender._disconnectAutoRender  s     **55dnnEr   c                     | j                          | j                  j                         | j                  _        | j                          y r   )r   r   r>   r   r   r   )r   r   s     r   r   zSbRender._onCheckbox  s5    ""$&*kk&:&:&<#!r   c                 $    | j                          y r   )r_   r   s    r   rs   zSbRender.Update  s    		r   Nr   )
r   r   r   r   r   r   r   r   r   rs   r   r   r   r   r     s'    
<$CF"
r   r   c                   $    e Zd ZdZddZd Zd Zy)
SbMapScalezEditable combobox to get/set current map scale.

    Requires MapFrame.GetMapScale, MapFrame.SetMapScale
    and MapFrame.GetWindow (and GetWindow().UpdateMap()).
    c                    t         j                  | |||       d| _        t        d      | _        t        j                  | j                  t
        j                  t
        j                  d      | _
        | j                  j                  g d       | j                  j                          | j                  j                  t        j                  t        d                   | j                  j                  t
        j                   | j"                         | j                  j                  t
        j$                  | j"                         d | _        y )Nmapscalez	Map scale)   )r   r   stylesize)z1:1000z1:5000z1:10000z1:25000z1:50000z1:100000z	1:1000000zAs everyone's monitors and resolutions are set differently these values are not true map scales, but should get you into the right neighborhood.)r   r   r:   r   rW   r/   ComboBoxr!   r   TE_PROCESS_ENTERr   SetItemsrt   r   r   r.   EVT_TEXT_ENTEROnChangeMapScaleEVT_COMBOBOXlastMapScaler   s       r   r   zSbMapScale.__init__  s    h	8<	{^
kk>>yy%%	
 	
	
 	JJ.		
 	**D,A,AB$*?*?@ r   c                     | j                   j                         }| j                  j                  d       	 | j	                  d|dz   z         || _        | j                          | j                   j                  d       y # t
        $ r Y >w xY w)Nr   1:%ld      ?F)	r    GetMapScaler!   r   r9   	TypeErrorr   r_   r   )r   scales     r   rs   zSbMapScale.Update  s{    ))+$$R(	MM'US[12 "		 	--e4  		s   B 	BBc                    |j                         }	 |dd dk7  rt        t        |dd       }| j
                  j                  |       | j
                  j                         j                          | j                         j                          y# t        $ r* | j                  dt        | j                        z         Y yw xY w)zMap scale changed by userNry   z1:r   )	GetString
ValueErrorintr9   r   r    SetMapScale	GetWindow	UpdateMapr}   SetFocus)r   r   r   r;   s       r   r   zSbMapScale.OnChangeMapScale  s    !	RayD   ab	NE
 	!!%( 	!++-!!#  	MM'C(9(9$::;	s   B 0CCNr   )r   r   r   r   r   rs   r   r   r   r   r   r     s    &!P5$r   r   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
SbGoTozlTextctrl to set coordinates which to focus on.

    Requires MapFrame.GetWindow, MapWindow.GoTo method.
    c                 t   t         j                  | |||       d| _        t        d      | _        t        | j                  t        j                  dt        j                  d      | _
        | j                  j                          | j                  j                  t        j                  | j                         y )NgotozGo to XY coordinatesr   )i,  r   )r   r   r;   r   r   )r   r   r:   r   rW   r   r!   r/   r   r   r   rt   r.   r   OnGoTor   s       r   r   zSbGoTo.__init__  s    h	8<	-.
>>yy%%
 	**DKK8r   c                    |rt        j                  ddd      }|st        t        d            |}t	        ddd	      }|j                  d
      d   j                  d      d   }|dv r@t        j                  ||      \  }}t        j                  ||f||d      \  }}|\  }}||fS t        |      t        |      }}t        j                  ||f||d      \  }}|\  }}||fS | j                  j                         j                  d   dk(  rt        j                  ||      \  }}||fS t        |      t        |      }}||fS )a@  Reproject east, north from user defined projection

        :param e,n: coordinate (for DMS string, else float or string)
        :param useDefinedProjection: projection defined by user in settings dialog

        @throws SbException if useDefinedProjection is True and projection is not defined in UserSettings
        
projectionr!   proj4rl   +Projection not defined (check the settings)zg.projjfT)flagsread r   =rw   lllatlonglonglatd)coordprojInprojOutr  projr  )r   rn   r   r   r   splitr   DMS2DegReprojectCoordinatesfloatr    GetMapprojinfo)	r   enuseDefinedProjectionsettingsr  r  r  coord1s	            r   ReprojectENToMapzSbGoTo.ReprojectENToMap  sg     #''"GH !!$Q"RSS "$XTE||C(+11#6q977 ==A.DAq#(#=#= !fVWC$LD& "DAq !t !8U1XqA#(#=#= !fVWC$LD& "DAq
 !t	 ]]!!#,,V4<==A&DAq !t 8U1XqA!tr   c           	      z   	 | j                         j                  d      \  }}| j                  ||| j                  j	                  d            \  }}| j                  j                         j                  ||       | j                  j                          y# t        $ r | j                  j                         j                         }t        t        j                  ddd            }t        j                  ddd      }| j                  j                         j                  d   dk(  r7|d	k(  r2| j!                  d
t#        j$                  |d   |d   |      z         Y y| j!                  d||d   ||d   fz         Y yt&        $ r/}| j(                  j+                  t-        |      d       Y d}~yd}~ww xY w)zGo to position;r#  r
  format	precisionrl   r  r  DMS%scenter_eastingcenter_northingr*  
%.*f; %.*fr   N)r>   r  r&  r    r@   r  GoTor   r  r   r  GetCurrentRegionr   r   rn   r   r9   r   Deg2DMSr   r!   r   str)r   r   r!  r"  regionr*  r)  s          r   r  zSbGoTo.OnGoTo7  s   %	4==?((-DAq((1dmm//0FGDAq MM##%**1a0KK  " 	]]))+<<>F  |+VI "%%LhtTF}}##%..v6$>6U?mm/001"+  !/0!01	  	4 NN((Q33		4s%   BB C	F:#F:F:%F55F:c                    |j                         }t        t        j                  ddd            }t        j                  ddd      }t        j                  ddd      }| j                  j                  d      r|st        t        d	            t        j                  |d
   |d   f|d      \  }}|r9|dv r&|dk(  r!dt        j                  |d   |d   |      z  S d||d   ||d   fz  S t        t        d            | j                  j                         j                  d   dk(  r&|dk(  r!dt        j                  |d
   |d   |      z  S d||d
   ||d   fz  S )z,Get current map center in appropriate formatr
  r)  r*  rl   r  r!   r  r#  r  r-  r.  r  r  r  r  r  r+  r,  r   rw   r/  r0  (Error in projection (check the settings)r  )r2  r   r   rn   r    r@   r   r   r   r  r3  r  r   )r   mapr5  r*  r)  r
  r  r  s           r   GetCenterStringzSbGoTo.GetCenterString`  s   %%'<XkR
	 !!(4P!%%K

 ==$$%;<!!$Q"RSS#88!"23V<M5NO&e
 ;;%#emm!!HeAh)'     ,y%(IuUVx.XXX%a(R&STT}}##%..v6$>6U?emm+,,-'   $+,,-	'  r   c                 x    | j                  | j                  j                               }| j                  |       y)z$Set current map center as item valueN)r:  r    r  r9   )r   centers     r   	SetCenterzSbGoTo.SetCenter  s+    %%dmm&:&:&<=fr   c                 (   | j                   j                  d       	 | j                          | j                          | j                  j                  d       y # t        $ r/}| j                   j                  t        |      d       Y d }~Od }~ww xY w)Nr   r   F)r!   r   r=  r_   r   r4  r    r   )r   r!  s     r   rs   zSbGoTo.Update  sm    $$R(	4NNIIK
 	--e4	  	4NN((Q33	4s    A 	B"%BBNr   )
r   r   r   r   r   r&  r  r:  r=  rs   r   r   r   r  r    s(    
9"#J'4R*X

5r   r  c                   <    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d Z
y	)
SbTextItemzIBase class for items without widgets.

    Only sets statusbar text.
    c                 B    t         j                  | |||       d | _        y r   )r   r   r   r   s       r   r   zSbTextItem.__init__  s    h	8<	r   c                 l    | j                   j                  | j                         | j                         y r   )r!   r   r>   r   r   s    r   r_   zSbTextItem.Show  s     $$T]]_dmmDr   c                 P    | j                   j                  d| j                         y )Nr   )r!   r   r   r   s    r   rt   zSbTextItem.Hide  s    $$R7r   c                     || _         y r   r   rX   s     r   r9   zSbTextItem.SetValue  s	    	r   c                     | j                   S r   rE  r   s    r   r>   zSbTextItem.GetValue  s    yyr   c                      y r   r   r   s    r   r}   zSbTextItem.GetWidget  s    r   c                 (    | j                  d       y )NTr   r   r   s    r   rs   zSbTextItem.Update  s    d#r   Nr   )r   r   r   r   r   r_   rt   r9   r>   r}   rs   r   r   r   r@  r@    s+    

E8$r   r@  c                       e Zd ZdZddZd Zy)SbDisplayGeometryz Show current display resolution.c                 b    t         j                  | |||       d| _        t        d      | _        y )NdisplayGeometryzDisplay geometryr@  r   r:   r   rW   r   s       r   r   zSbDisplayGeometry.__init__  s*    D(Ix@%	)*
r   c                 D   t        j                   | j                  j                         j                               }| j                  j                  j
                  r| j                  j                         j                  d      }t        t        |d   |d   z
  |d   z        dz         |d<   t        t        |d   |d	   z
  |d
   z        dz         |d<   |d   |d<   |d
   |d
<   | j                  d|d   |d   |d   |d
   fz         t        j                  |        y )NF)add3dr"  snsresr   rowsr!  r   ewrescolsz(rows=%d; cols=%d; nsres=%.2f; ewres=%.2f)copyr    r  r2  r2   
resolution	GetRegionabsr   r9   r@  r_   )r   r5  
compRegions      r   r_   zSbDisplayGeometry.Show  s   4==//1BBDE==,,77--/999FJ VC[6#;.*W2EEFLF6N !VC[6#;.*W2EEFLF6N )1F7O(1F7O6f~vf~vgwPQ	
 	r   Nr   )r   r   r   r   r   r_   r   r   r   rJ  rJ    s    *+
r   rJ  c                   *    e Zd ZdZddZd Zd Zd Zy)SbCoordinateszPShow map coordinates when mouse moves.

    Requires MapWindow.GetLastEN method.c                 ~    t         j                  | |||       d| _        t        d      | _        d | _        d | _        y )NcoordinatesCoordinates)r@  r   r:   r   rW   _additionalInfo_basicValuer   s       r   r   zSbCoordinates.__init__  s9    D(Ix@!	}%
#r   c                    t        t        j                  ddd            }t        j                  ddd      }| j                  j	                  d      }	 | j                  j                         j                         \  }}| j                  |||||      | _        | j                  r(dj                  | j                  | j                        }n| j                  }| j                  |       t         j#                  |        y	# t        $ r%}| j                  |j                         Y d	}~?d	}~wt        $ r}| j                  d
       Y d	}~ad	}~wt        $ r | j                  d
       Y w xY w)zShow the last map window coordinates.

        .. todo::
            remove last EN call and use coordinates coming from signal
        r
  r)  r*  rl   r  r#  z{coords} ({additionalInfo}))coordsadditionalInfoNr   )r   r   rn   r    r@   r  	GetLastENReprojectENFromMapr`  r_  r)  r9   r   r   r   AttributeErrorr@  r_   )r   r*  r)  r
  r!  r"  r;   s          r   r_   zSbCoordinates.Show  s8    <XkR
	 !!(4P]]../EF
	==**,668DAq#661j)V D ##5<<++D<P<P =  ((MM%  	  	%MM!))$$  	MM" 	MM"	s+   BD 	E-D++E-7EE-,E-c                     || _         y)aB  Sets additional info to be shown together with coordinates.

        The format is translation dependent but the default is
        "coordinates (additional info)"

        It does not show the changed text immediately, it waits for the Show()
        method to be called.

        :param text: string to be shown
        N)r_  )r   r   s     r   SetAdditionalInfozSbCoordinates.SetAdditionalInfo  s      $r   c                    |rt        j                  ddd      }|st        t        d            t	        j
                  ||f|d      \  }}|r/|\  }}|dv r|d	k(  rt	        j                  |||
      S d||||fz  S t        t        d            | j                  j                         j                  d   dk(  r|d	k(  rt	        j                  |||
      S d||||fz  S )zReproject east, north to user defined projection.

        :param e,n: coordinate

        @throws SbException if useDefinedProjection is True and projection is not defined in UserSettings
        r
  r!   r  rl   r  r  r7  r  r+  r/  r0  r8  r  r  )
r   rn   r   r   r   r  r3  r    r  r   )	r   r!  r"  r#  r*  r)  r$  r  r  s	            r   re  z SbCoordinates.ReprojectENFromMap  s      #''"GH !!$Q"RSS $88a&(#e  DAq;;%$}}QYGG+y!Y.JJJ%a(R&STT}}##%..v6$>6U?}}QY??#y!Y&BBBr   Nr   )r   r   r   r   r   r_   rh  re  r   r   r   r[  r[    s    ,  D$Cr   r[  c                   2    e Zd ZdZddZd Zd Zd	dZd Zy)
SbRegionExtentzShows current display regionc                 b    t         j                  | |||       d| _        t        d      | _        y )NdisplayRegionzDisplay extentrM  r   s       r   r   zSbRegionExtent.__init__6  s*    D(Ix@#	'(
r   c                    t        t        j                  ddd            }t        j                  ddd      }| j                  j	                  d      }| j                         }	 | j                  ||||      }| j                  |       t        j                  |        y # t        $ r%}| j                  |j                         Y d }~?d }~ww xY w)Nr
  r)  r*  rl   r  r#  )r   r   rn   r    r@   
_getRegionReprojectRegionFromMapr9   r   r   r@  r_   )r   r*  r)  r
  r5  regionReprojectedr!  s          r   r_   zSbRegionExtent.Show;  s    <XkR
	 !!(4P]]../EF
"	% $ ; ;
Iv! MM+, 	  	%MM!))$$	%s   &%B! !	C*C

Cc                 R    | j                   j                         j                         S )zGet current display region)r    r  r2  r   s    r   ro  zSbRegionExtent._getRegionK  s    }}##%6688r   Nc           	      :    |d||||||||fz  S |d|d|d|S )zWFormat display region string for statusbar

        :param nsres,ewres: unused
        z%.*f - %.*f, %.*f - %.*f - , r   )r   r   r!  rP  r"  rQ  rS  r*  s           r   _formatRegionzSbRegionExtent._formatRegionO  sE    
  -	1 	 	 *+Aq!44r   c           	          |rt        j                  ddd      }|st        t        d            |}t	        j
                  |d   |d   f|d	      \  }}t	        j
                  |d
   |d   f|d	      \  }}	t	        j
                  d|d	      \  }}
t	        j
                  |d   |d   f|d	      \  }}|r|	r|dv r|dk(  rt	        j                  |d   |d   d|      \  }}t	        j                  |	d   |	d   d|      \  }}t	        j                  t        |
d         t        |d         z
  t        |
d         t        |d         z
  dd|      \  }}| j                  ||||||      S |\  }}|	\  }}|
\  }}| j                  |||||||      S t        t        d            | j                  j                         j                  d   dk(  r|dk(  r}t	        j                  |d   |d   d|      \  }}t	        j                  |d
   |d   d|      \  }}t	        j                  |d   |d   d|      \  }}| j                  ||||||      S |d   |d   }}|d
   |d   }}|d   |d   }}| j                  |||||||      S )zReproject region values

        .. todo::
            reorganize this method to remove code useful only for derived class SbCompRegionExtent
        r
  r!   r  rl   r  r   rP  r  r7  r!  r"  )        rx  rS  rQ  r  r+  r   rw   F)stringr*  )ry  
hemispherer*  )r   rP  r!  r"  rS  rQ  )r   rP  r!  r"  rS  rQ  r*  r8  r  r  )r   rn   r   r   r   r  r3  rX  rv  r    r  r   )r   r5  r#  r*  r)  r$  r  r  r%  coord2coord3coord4r   rP  r!  r"  rS  rQ  s                     r   rp  z%SbRegionExtent.ReprojectRegionFromMapb  s     #''"GH !!$Q"RSS"$99!#;s4gS f  %99!#;s4gS f  %99$gS f  %99!'?F7O<gUX f f;;%$}}"1Ivay) 1  %}}"1Ivay) 1 (-}}q	NS^;q	NS^;#(',&/(u  $111Qe5  2     &1%1'-u#11"'"'&/  2    &a(R&STT }}##%..v6$>6U?}}3KUi1 }}3KUi1  %}}7OVG_Ui u ))Aa1EQV)WWc{F3K1c{F3K1%gwu))1Qe5I *  r   r   r   )	r   r   r   r   r   r_   ro  rv  rp  r   r   r   rk  rk  3  s    &)
 95&Pr   rk  c                   &    e Zd ZdZddZddZd Zy)SbCompRegionExtentzShows computational region.c                 b    t         j                  | |||       d| _        t        d      | _        y )NcomputationalRegionzComputational region)rk  r   r:   r   rW   r   s       r   r   zSbCompRegionExtent.__init__  s*    h	8D)	-.
r   Nc                 P    |d||||||||||||fz  S |d|d|d|d|d|dS )z0Format computational region string for statusbarz%%.*f - %.*f, %.*f - %.*f (%.*f, %.*f)rt  ru  z ()r   )r   r   r!  rP  r"  rS  rQ  r*  s           r   rv  z SbCompRegionExtent._formatRegion  sS     :>   34Q1eUKKr   c                 R    | j                   j                         j                         S )zReturns computational region.)r    r  rW  r   s    r   ro  zSbCompRegionExtent._getRegion  s    }}##%//11r   r   r   )r   r   r   r   r   rv  ro  r   r   r   r  r    s    %/
L(2r   r  c                   H    e Zd ZdZddZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)r'   zOGeneral progress bar to show progress.

    Underlying widget is wx.Gauge.
    c                 8   t        d      | _        t        d      | _        t        j	                  | |||       d| _        || _        t        j                  | j                  t        j                  dt        j                        | _        | j                          y )NzSbProgress.progressShownzSbProgress.progressHiddenprogressr   )r   r   rM   r   )r	   r)   r,   r   r   r:   	sbManagerr/   Gauger!   r   GA_HORIZONTALr   rt   )r   r7   r!   r  r   s        r   r   zSbProgress.__init__  sp    #$>?$%@Ah	8<	"hh>>biiq@P@P
 			r   c                 6    | j                   j                         S )zReturns progress range.)r   GetRanger   s    r   r  zSbProgress.GetRange  s    {{##%%r   c                     |dkD  r?| j                         |k7  r| j                  j                  |       | j                          y| j	                          y)zSets progress range.r   N)r  r   r   r_   rt   )r   rM   s     r   r   zSbProgress.SetRange  s;    19}}%'$$U+IIKIIKr   c                     | j                         s5| j                  j                          | j                  j	                          y y r   )r^   r)   emitr   r_   r   s    r   r_   zSbProgress.Show  s2    ||~##%KK r   c                     | j                         r5| j                  j                          | j                  j	                          y y r   )r^   r,   r  r   rt   r   s    r   rt   zSbProgress.Hide  s2    <<>$$&KK r   c                 6    | j                   j                         S )zIs progress bar shown)r   r^   r   s    r   r^   zSbProgress.IsShown  s    {{""$$r   c                     || j                         kD  r| j                          y| j                  j                  |       || j                         k(  r| j                          yy)zSets value of progressbar.N)r  rt   r   r9   rX   s     r   r9   zSbProgress.SetValue  sJ    4==?"IIKU#DMMO#IIK $r   c                     | j                   S )zUReturns underlying winget.

        :return: widget or None if doesn't exist
        r   r   s    r   r}   zSbProgress.GetWidget  r   r   c                      y r   r   r   s    r   rs   zSbProgress.Update  s    r   Nr   )r   r   r   r   r   r  r   r_   rt   r^   r9   r}   rs   r   r   r   r'   r'     s4    

&

%r   r'   )r   rU  r/   corer   	core.gcmdr   core.settingsr   gui_core.wrapr   r   r   grass.pydispatch.signalr	   	Exceptionr   r   r   r   r   r  r@  rJ  r[  rk  r  r'   r   r   r   <module>r     s   8  	    & / / *) H HVC% C%L$v $NM$ M$``5V `5F$ $<
 6YCJ YCxZ D2 2B? ?r   