
    ը	f^=                    L   d Z ddlZddlZddlZddlZddlZddlmZ ddlZddl	Z	 ddl
mc mc mZ ej"                  j%                  ej&                  d      ej"                  vr?ej"                  j)                  ej"                  j%                  ej&                  d             ddlmZ ddlmZ ddlmZmZmZ ddlmZmZ dd	l m!Z!m"Z"m#Z#m$Z$ dd
l%m&Z&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? ddl@mAZA ddl@mBZC ddlDmEZE ddlFmGZGmHZH ddlFmIZImJZJmKZK ddlLmMZM ddlNmOZO ddlPmQZQ ddlRmSZS ddlTmUZU ddlVmWZW ddlXmYZY ddlZmBZBm[Z[ ddl\m]Z]m^Z^m_Z_m`Z` dd lambZb  G d! d"ej                        Zdy# e$ r ddlmc mZ Y pw xY w)#aE  
@package lmgr::frame

@brief Layer Manager - main menu, layer management toolbar, notebook
control for display management and access to command console.

Classes:
 - frame::GMFrame

(C) 2006-2015 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 Michael Barton (Arizona State University)
@author Jachym Cepicky (Mendel University of Agriculture)
@author Martin Landa <landa.martin gmail.com>
@author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
    N)	globalvarpython)core)decode)
RunCommandGErrorGMessage)UserSettingsGetDisplayVectSettings)SetAddOnPathGetLayerNameFromCmdcommand2ltypeget_shell_pid)MapsetAccessPreferencesDialog)	LayerTreeLMIcons)LayerManagerMenuDataLayerManagerModuleTree)	GNotebookFormNotebook)GConsoleEVT_IGNORED_CMD_RUN)Notification)GConsoleWindow	GC_PROMPT)LocationDialogMapsetDialogCreateNewVectorGroupDialogMapLayersDialog
QuitDialog)SearchModuleWindow)Menu)Debug)LMWorkspaceToolbarLMToolsToolbar)LMMiscToolbarLMNvizToolbarDisplayPanelToolbar)SbMain)WorkspaceManager)PyShellWindow)LayerManagerGrassInterface)
MapDisplay)DataCatalog)GUI)r$   TextEntryDialog)can_switch_mapset_interactiveswitch_mapset_interactivelycreate_mapset_interactivelycreate_location_interactively)is_first_time_userc                      e Zd ZdZej
                  ddej                  ej                  f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ddZddZd Zd Zd Zd Zd Zd Zd ZddZddZ ddZ!ddZ"ddZ#ddZ$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,d' Z-d( Z.d) Z/d* Z0d+ Z1dd,Z2d- Z3d. Z4d/ Z5d0 Z6dg fd1Z7dg fd2Z8d3 Z9d4 Z:d5 Z;d6 Z<d7 Z=d8 Z>d9 Z?dd:Z@d; ZAd< ZBd= ZCd> ZDd? ZEdd@ZFddAZGddBZHddCZIddDZJddEZKdF ZLdG ZMddHZNdI ZOdJ ZPdK ZQddLZRdM ZSdN ZTdO ZUdP ZVdQ ZWddRZXddSZYddTZZddUZ[dV Z\ddWZ]dX Z^dY Z_ddZZ`dd[Zadd\Zbdd]Zcdd^Zddd_Zed` ZfddaZgdb Zhdc ZidddZjddeZkdf ZlddgZmdh Zndi Zodj Zpdk Zqdl Zrdm Zsdn Ztdo Zudp Zvdq Zwdr Zxds Zydt Zzdu Z{dv Z|dw Z}dx Z~dy Zdz Zd{ Zd| Zd} Zd~ Zd Zd Zd Zd Zd ZddZy)GMFramezLayer Manager frame with notebook widget for controlling GRASS
    GIS. Includes command console page for typing GRASS (and other)
    commands, tree widget page for managing map layers.
    Nc                     | _         |r| _        nt        d       _        d _        d _        d  _        d  _        d  _        t        j                  j                   f||||d| t                _        t          j                         _         j                           j!                  d        j#                  t        j$                  t&        j(                  j+                  t,        j.                  d      t        j0                               g fd} fd	}	t3        |
       _        t7        |
       _        t        j:                  j=                          _        tA                _!        d  jB                  d<   d  jB                  d<   tE                jB                  d<    jG                           j                  jI                   jJ                         tM          j                         _'         jQ                          _)         jU                   jR                          jW                   jR                          jY                   jR                          j[                   jR                          j]                   jR                          j_                          ta               tc               te               tg               d _4        dt        d      ddfdt        d      ddfdt        d      ddfdt        d      ddfd _5        d}
|
D ]8  } jj                  |   \  }}}} j>                  jm                   jh                  |   t        j:                  jo                         jq                  |      js                  |      ju                         jw                         jy                  |      j{                  |      j}                  d      j                  d      j                  d      j                  d      j                  d      j                  d      j                   jh                  |   j                                      ;  j>                  j                  d      j                           j>                  jm                   jN                  j                         t        j:                  jo                         j                         j                  dd      j                         jq                  d       j                  d      j                  d      ju                         j                  d      j                  d      j                  d              j                  t        j                   j                          j                  t        j                   j                          j                  j                  j                   j                          j                  j                  j                   j                          j                  j                  j                   j                          j                  t,        j                          j>                  jm                   jR                  t        j:                  jo                         j                         j                         j                  d!      j                  d      j                  d      j                  d      jy                  d      j                  d              j>                  j                          t        j                   jR                  j                  d"       t        j                  d#d$d%&      rt        j                  d#d$d'&      }	 t        t        |j                  d(      dd       \  }}t        t        |j                  d(      dd)       \  }}t        j                         }|dk(  r|d   }|dk(  r|d   } j                  ||f        j                  ||f       n j                           j                           j                          |r, j                  j                  |      r# j                          n j                  d*        j                         D ]  }|j                            j                  j                           j                  j                  t         j                         d   d+z                |	        j
                  r j                         j                          t        j                   j                          j                          y #  Y >xY w),Nz	GRASS GIS)   r;   r   )parentidsizestyle)lmgrgifaceLayerManagerz	grass.icoc                 (    j                  |        y N)append)messagemenu_errorss    +/usr/lib/grass83/gui/wxpython/lmgr/frame.pyadd_menu_errorz(GMFrame.__init__.<locals>.add_menu_error   s    w'    c                     | rGj                   j                  t        d             | D ]  }j                   j                  |        y y )Nz6There were some issues when loading menu or Tools tab:)	_gconsole
WriteError_)messagesrF   selfs     rH   show_menu_errorsz*GMFrame.__init__.<locals>.show_menu_errors   sI    ))QR  ( 7GNN--g67	 rJ   )message_handlerpreferencesnvizPreferencesatm)menur<   rA   r<   )	workspacetoolsmiscnviztoolbarWorkspacezWorkspace Toolbar   toolbarToolszTools ToolbartoolbarMisczMisc Toolbar   toolbarNvizz3D view Toolbar   FT   	statusbar)rf   cataloggeneraldefWindowPosenabledgroupkeysubkeydim,   showg?)yr<   	baseTitlerN   iconsizedisplayIndexcurrentPagecurrentPageNumcwdPathwxFrame__init__r.   _gifacer,   workspace_manager	_setTitleSetNameSetIconIconospathjoinr   ICONDIRBITMAP_TYPE_ICOr   _menuTreeBuilderr   _moduleTreeBuilderaui
AuiManager_auimgrdictdialogslist_createMenuBarCreateRecentFilesMenumenubarr+   re   _createNotebooknotebook_createDataCatalog_createDisplay_createSearchModule_createConsole_createPythonShell_addPagesToNotebookr&   r'   r(   r)   toolbars_toolbarsDataAddPaneAuiPaneInfoNameCaptionToolbarPaneTopRowPositionLeftDockableRightDockableBottomDockableTopDockableCloseButtonLayerBestSizeGetBestSizeGetPaneHide	GetWidgetBottomMinSizeFixedDestroyOnCloseDockable
PaneBorderGripperBind	EVT_CLOSEOnCloseWindowOrExitEVT_KEY_DOWN	OnKeyDown
mapCreatedconnectOnMapCreated	updateMap_updateCurrentMapcurrentMapsetChangedOnMapsetChanged
SetMinSizeGM_WINDOW_MIN_SIZELeft
CentrePaneUpdate	CallAfterSetSelectionByNamer
   GetmapintsplitClientDisplayRectSetPositionSetSizeCentreLayoutShowLoad
NewDisplayGetAllMapDisplaysrL   RedirectgoutputSetSashPositionGetSizeGetMapDisplayRaise_show_demo_map)rP   r<   r=   titlerY   r>   r?   kwargsrI   rQ   toolbarsListtoolbarnamecaptionrowpositionro   xywhclient_dispmapdisprG   s   `                      @rH   r|   zGMFrame.__init__X   s    "DN{^DN  	 
$Wv"4uWPVW1$7 "2tDLL!Q^$GGBGGLL!2!2K@"BTBTU	
 	(	7 !5^ T"8"Xvv((. v&*]#*.&'"fU 	44 	5 	
  tDLLA,,..DMM*  /DMM*.  "+48#40!.!.	
 #%&	 %a&8!Q?"An$5q!<"A&7$8!Q?

 ># 	G+/+=+=g+F(D'3LL  g&""$d!S(#e$u%&T"U#q4==1==?A	( 	]+002 	NN$$&FF VXWR_UWT+[^D![]Xe_ZWU^	
  			",, 8 89		"//4>>2''(9(9:&&t'='=>))11$2F2FG 		445 	MMFF TVZ\XhXe_[^D!SVU1X	
 	
T]]55yA )	R""uUC3		#q 3413		#q 341 2246#AA6#AA  !Q(aV$
 KKM		 %%**95  OOO' --/ 	GLLN	 	! 	$$S):S)@%AB%  &&(
TZZ Gs   Be< <fc                    t        j                         }|d   }|d   }| j                  j                  rt        j
                  j                  t        j
                  j                  | j                  j                              d   }| j                  dj                  |||| j                               y| j                  dj                  ||| j                               y)	zSet frame titleLOCATION_NAMEMAPSETr   z-{workspace} - {location}/{mapset} - {program})locationmapsetrY   programz{location}/{mapset} - {program})r   r   r   N)grassgisenvr~   workspaceFiler   r   splitextbasenameSetTitleformatrt   )rP   r   r   r   filenames        rH   r   zGMFrame._setTitle-  s    /*!!!//ww''  !7!7!E!EFH MM?FF%!& NN	 G  MM188%fdnn 9 rJ   c                     t        | | j                  j                  d            | _        | j	                  | j                         | j                  j                         | _        y)zCreates menu barT)
separators)r<   modelN)GMenur   GetModelr   
SetMenuBarGetCmdmenucmdrP   s    rH   r   zGMFrame._createMenuBarE  sM    t44===N
 	%||**,rJ   c                     t               }t        j                  |t        j                  t	        d            }|j                  |       | j                  t        j                  | j                  |       |S )zPCreates context menu for display tabs.

        Used to rename display.
        zRename current Map Display)r=   text)	r$   rz   MenuItemID_ANYrN   
AppendItemr   EVT_MENUOnRenameDisplay)rP   rV   items      rH   _createTabMenuzGMFrame._createTabMenuM  sR    
 v{{4BIIA6R4ST		"++t33T:rJ   c                 j    t        j                  ddd      }| j                  j                  |       y )NmanagercopySelectedTextToClipboardrj   rk   )r
   r   r   SetCopyingOfSelectedText)rP   copys     rH   _setCopyingOfSelectedTextz!GMFrame._setCopyingOfSelectedTextY  s.    !>y
 	--d3rJ   c                     | j                   j                  |      j                         r)| j                   j                  |      j                         S y)z=Check if pane (toolbar, ...) of given name is currently shownF)r   r   IsOkIsShownrP   r   s     rH   IsPaneShownzGMFrame.IsPaneShown_  s>    <<%**,<<''-5577rJ   c                 6     | j                   j                  |  y)z Override SbMain statusbar methodN)re   SetStatusText)rP   argss     rH   r  zGMFrame.SetStatusTexte  s    $$$d+rJ   c                     t         j                  dk(  rt        | t        j                        S t        | t        j                        S )zInitialize notebook widgetwin32r<   r?   )sysplatformr   r   FNPageDStyler   rz   	NB_BOTTOMr  s    rH   r   zGMFrame._createNotebooki  s2    <<7"D	0F0FGGt2<<@@rJ   c                      t        | j                         _         j                  j                  j	                   fd       y)zInitialize Data Catalog widgetrW   c                 &    j                  |       S rD   r  rF   rP   s    rH   <lambda>z,GMFrame._createDataCatalog.<locals>.<lambda>t      D..w7 rJ   N)r0   r}   datacatalogshowNotificationr   rP   r<   s   ` rH   r   zGMFrame._createDataCatalogp  s3    &fT\\J))117	
rJ   c                 j   t        |t        j                        | _        | j	                         }| j                  j                  |       | j                  j                  t        j                  | j                         | j                  j                  t        j                  | j                         y)zInitialize Display widgetr  N)r   r   FNPageStylenotebookLayersr  SetRightClickMenur   FNEVT_FLATNOTEBOOK_PAGE_CHANGEDOnCBPageChangedEVT_FLATNOTEBOOK_PAGE_CLOSINGOnCBPageClosing)rP   r<   rV   s      rH   r   zGMFrame._createDisplayw  s     (vY=R=RS""$--d3  !A!A4CWCWX  !A!A4CWCWXrJ   c                     t        j                  ddd      s_t        |  j                   j                  j                                _         j                  j                  j                   fd       yd _        y)zInitialize Search module widgetr  hideTabssearchrk   )r<   
handlerObjrA   r   c                 &    j                  |       S rD   r#  r$  s    rH   r%  z-GMFrame._createSearchModule.<locals>.<lambda>  s     2 27 ; rJ   N)	r
   r   r#   r}   r   r   r5  r(  r   r)  s   ` rH   r   zGMFrame._createSearchModule  sf    iZQ,||--668	DK KK((00; DKrJ   c                     t          j                  d       _        t        | j                   j                   j                  j                         t               _         j                  j                  j                   fd        j                  j                  j                   j                          j                  j                  t         fd        j                          y)zInitialize Console widgetz^d\..*|^r[3]?\.mapcalc$|^i.group$|^r.import$|^r.external$|^r.external.out$|^v.import$|^v.external$|^v.external.out$|^cd$|^cd .*)	guiparentrA   ignoredCmdPattern)r<   rA   gconsole	menuModelgcstylec                 &    j                  |       S rD   r#  r$  s    rH   r%  z(GMFrame._createConsole.<locals>.<lambda>  r&  rJ   c                 :    j                  | j                        S rD   )RunSpecialCmdcmd)eventrP   s    rH   r%  z(GMFrame._createConsole.<locals>.<lambda>  s    t/A/A%))/L rJ   N)r   r}   rL   r   r   r   r   r   r(  r   r   r   r   r   r  r)  s   ` rH   r   zGMFrame._createConsole  s     "<<
 &<<^^--668
 	%%--7	
 	!!))$*;*;<!L	
 	&&(rJ   c                     t        j                  ddd      s(t        || j                  | j                        | _        yd| _        y)zInitialize Python shell widgetr  r4  pyshellrk   )r<   rA   simpleEditorHandlerN)r
   r   r-   r}   OnSimpleEditorrD  r)  s     rH   r   zGMFrame._createPythonShell  s<    iZ	R(||$($7$7DL  DLrJ   c                 $    | j                          y)z5Create new layer tree and map display window instanceN)r   rP   rB  s     rH   OnNewDisplayzGMFrame.OnNewDisplay  s    rJ   c                 d    t        j                  dd j                  z         s(t        d      j	                   j                  dz         t        j                   j                  t
        j                  t
        j                         _
        t         j                         } j                  j                   j                  d        j                  j                          _         fd	}t         j                   j                   |t
        j                  t
        j"                  t
        j$                  t
        j&                  t
        j(                  z  t
        j*                  z  t
        j,                  z  t
        j.                  z  t
        j0                  z    j                  

       j                  _        t        j4                  t
        j6                        }|j9                  |dt
        j:                         |j9                   j=                         dt
        j:                  d        j                  j?                  |        j                  jA                           j                  jC                           xj                  dz  c_         jE                         S )zCreate new layer tree structure and associated map display and
        add it to display notebook tab
        :param name: name of new map display window
        :param show: show map display window if True
        r^   zGMFrame.NewDisplay(): idx=%dzMap Display {number})number)r=   r?   )r9  r<   T)pager  selectc                    t        j                  j                  dz   dz  j                  dz   dz        }t        j                  |t         j                  |t
        j                  t         j                        }t        || t         j                  t
        j                  |j                  |j                  	      }j                  |       r|j                          |S )zCallback function which creates a new Map Display window
            :param giface: giface for map display
            :param layertree: layer tree object
            :return: reference to mapdisplay instance
            r^      )r=   posr>   r?   r   )	r<   rA   r=   r>   treer@   idxMapr   )rz   Pointrv   r{   r  r   MAP_WINDOW_SIZEDEFAULT_FRAME_STYLEr/   rS  _setUpMapDisplayr   )rA   	layertreerP  mapframe
mapdisplayr   rP   rs   s        rH   CreateNewMapDisplayz/GMFrame.NewDisplay.<locals>.CreateNewMapDisplay  s     ((D--1R7$:K:Ka:OSU9UVC xx99..,,H $99..%%MM
J !!*- !rJ   )
r<   rA   createNewMapDisplayr=   rP  r>   r?   r@   r   r   r   )
proportionflag)r]  r^  border)#r%   msgrv   rN   r   rz   Panelr,  r  BORDER_NONEpg_panelr*   AddPageGetCurrentPagerw   r   r}   DefaultPositionDefaultSizeTR_HAS_BUTTONSTR_LINES_AT_ROOTTR_HIDE_ROOTTR_DEFAULT_STYLE	NO_BORDERFULL_REPAINT_ON_RESIZEmaptreeBoxSizerVERTICALAddEXPANDGetLayerTreeSetSizerFitr   r   )rP   r   rs   dmgrToolbarr[  cb_boxsizers   ```   rH   r   zGMFrame.NewDisplay  s     			!3d6G6GGH+,334;L;Lq;P3QD BIIR^^
 *DMM$O##T$#O..==?&	T $-##<< 3yy""##!!"oo !!" ll	
 ''( (($
 & kk"++.		B))+		RST!!+.!Q!!##rJ   c                      j                    fd}||_        |j                  t        j                   j                   f fd	       |j
                  j                   j                   f fd	       |j
                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  t        j                  ddd      t        j                  ddd	      t        j                  dd
d      t        j                  ddd      t        j                  ddd             y)zSet up Map Display propertiesc                     i }j                   j                        |d<   j                   j                  |d         }t        d      j	                  |      }| r| rj
                  j                  |      r|S y)a  Callback to check if user wants to close display.

            :return dict/None pgnum_dict/None: dict "layers" key represent
                                               map display notebook layers
                                               tree page index
            layersClose Map Display {}N)r,  GetPageIndexGetPageTextrN   r   r~   CanClosePage)askIfSaveWorkspace
pgnum_dictr   r   rL  rP   s       rH   CanCloseDisplayz1GMFrame._setUpMapDisplay.<locals>.CanCloseDisplay  sx     J#'#6#6#C#CD#IJx &&22:h3GHD./66t<G%"t'='='J'J7'S!!rJ   c                 &    j                  |      S rD   )_onMapDisplayFocus)rB  rL  rP   s     rH   r%  z*GMFrame._setUpMapDisplay.<locals>.<lambda>4  s    1H1H1N rJ   c                 &    j                  |      S rD   )_onMapDisplayStarting3dMode)	firstTimemapDisplayPagerP   s     rH   r%  z*GMFrame._setUpMapDisplay.<locals>.<lambda>8  s    t?_?_@ rJ   displayautoRenderingrj   rk   statusbarMode	selectionalignExtentcompResolutionshowCompExtent)rendermoder  constrainResr  N)rw   canCloseDisplayCallbackBindToFramerz   EVT_ACTIVATEstarting3dModer   AddNvizToolsending3dModeRemoveNvizToolsclosingDisplay_closePageNoEventSetPropertiesr
   r   )rP   rZ  r  rL  s   `  @rH   rW  zGMFrame._setUpMapDisplay  s<   	" .=
* 	OO#//N	

 	!!))-1-=-= 	

 	!!))$*;*;<''(<(<=!!))$*@*@A 	  ##_Y !!_[ %((]9 &))%5i (++%5i 	! 	
rJ   c                      j                   j                   j                  t        d      d        j                   j                   j                  t        d      d        j
                  r1 j                   j                   j
                  t        d      d        j                   j                   j                  t        d      d	        j                  j                  j                   fd
        j                  r1 j                   j                   j                  t        d      d       t        j                  dk(  r5 j                   j                  t        j                   j                         n4 j                   j                  t         j"                   j                         t!        j$                   j                  j&                         y)zAdd pages to notebook widgetDatarg   )rL  r  r   Layersrz  Toolsr5  Consoleoutputc                 &    j                  |       S rD   )_switchPage)notificationrP   s    rH   r%  z-GMFrame._addPagesToNotebook.<locals>.<lambda>b  s    !1!1,!? rJ   PythonrD  r  N)r   rd  r'  rN   r,  r5  r   contentChangedr   rD  r  r  r   r.  r/  OnPageChangedrz   EVT_NOTEBOOK_PAGE_CHANGEDr   	LoadItemsr  s   `rH   r   zGMFrame._addPagesToNotebookS  sE    	4#3#3!F))T 	4#6#6Qx[xX ;;MM!!t{{7(!S 	4<<a	lR##++?	

 <<MM!!t||!H+I!V <<7"MMr??ASASTMMr;;T=O=OP
T%%//0rJ   c                 R      fd}t               rt        j                  d|       yy)zwIf in demolocation, add demo map to map display

        This provides content for first-time user experience.
        c            	          d} t        j                  | d      d   }|s&t        j                  ddj	                  |              y j                         j                  d| ddd	j	                  |       g
       y )Nzcountry_boundaries@PERMANENTvector)r   elementr      z+GMFrame._show_demo_map(): {} does not existTd.vectzmap={}ltypelnamelcheckedlcmd)r   	find_filer%   r`  r   rs  AddLayer)
layer_nameexistsrP   s     rH   	show_demoz)GMFrame._show_demo_map.<locals>.show_demow  sx    7J__*hGOF		DKKJW (( 
 ;<	 ) rJ   i  N)r7   rz   	CallLater)rP   r  s   ` rH   r   zGMFrame._show_demo_mapq  s#    	  LLy)  rJ   c                    t        j                  dd       ddlm} |syddlm} | j
                  j                  d      j                          t        d      D ]>  \  }}| j
                  j                  |      j                  d	      j                  |       @ | j
                  j                           || j                  | j                         | j                         
      | _        | j                  j!                  d      }| j                  j#                  |d	z   | j                  t%        d      d       | j                  j'                  d       |s#dD ]  }| j                  j)                  |        yy)zAdd nviz notebook page

        :param firstTime: if a mapdisplay is starting 3D mode for the
                          first time
        r  zGMFrame.AddNvizTools()r   )haveNvizN)NvizToolWindowrb   )r]   r_   r`   rb   r^   )r<   rQ  r  rz  z3D viewr\   )indexrL  r  r   )viewlightfringeconstantcplane	animation)r%   r`  	nviz.mainr  r  r   r   r   	enumerater   r   r   r   rs  r   r\   GetPageIndexByNameInsertNBPagerN   r   
UpdatePage)rP   r  r  r  rP  r   rR  rL  s           rH   r  zGMFrame.AddNvizTools  s?    			!-.&, 	]+002%N
 	?LC LL  )--a099#>	? 	 #==t'8'8':DDVDVDX
	 mm..x8""'		)6 	# 	
 	((0 V +		$$T*+ rJ   c                    | j                   j                  d       | j                   j                  d       | j                  j	                  d      j                          t        d      D ]>  \  }}| j                  j	                  |      j                  d      j                  |       @ | j                  j                          y)zRemove nviz notebook pagerz  r\   rb   )r]   r_   r`   r^   N)
r   r   DeleteNBPager   r   r   r  r   r   r   )rP   rP  r   s      rH   r  zGMFrame.RemoveNvizTools  s     	((2""6* 	]+002%?
 	?LC LL  )--a099#>	? 	rJ   c                    t        j                         }t        | |d         \  }}}|ra| j                  j                  j                  ||dd       ||d   k(  rd}n|}t        | |||      rt        | | j                  |||d       yyy)zLaunch location wizardGISDBASEnewr   )grassdbr   actionr  NTshow_confirmation)r   r   r6   r}   grassdbChangedemitr3   r4   )rP   rB  r   r  r   r   switch_grassdbs          rH   OnLocationWizardzGMFrame.OnLocationWizard  s    $A&$%
!6 LL'',,(5* -  &,,!%!(,T7HfM+LL"&* N rJ   c                 $    | j                          y)zHere can be functions which have to be called
        after receiving settingsChanged signal.
        Now only set copying of selected text to clipboard (in goutput).
        N)r  r  s    rH   OnSettingsChangedzGMFrame.OnSettingsChanged  s     	&&(rJ   c                 6    ddl m}  || | j                         y)z6Launch georectifier module. See OnIClass documentationr   )	GCPWizardN)gcp.managerr  r}   )rP   rB  rA  r  s       rH   OnGCPManagerzGMFrame.OnGCPManager  s    )$%rJ   c                 x    ddl m}  || | j                        }|j                          |j	                          y)z4Launch Graphical Modeler. See OnIClass documentationr   )
ModelFramerW   N)gmodeler.framer  r}   CentreOnScreenr   )rP   rB  rA  r  wins        rH   
OnGModelerzGMFrame.OnGModeler  s*    -T\\:
rJ   c                 b    ddl m}  ||       }|j                          |j                          y)z8Launch Cartographic Composer. See OnIClass documentationr   )
PsMapFramerX   N)psmap.framer  r  r   )rP   rB  rA  r  r  s        rH   OnPsMapzGMFrame.OnPsMap  s$    *%
rJ   c                 z   ddl m} t        j                  dt        j
                  t        d            } ||| j                        }g }| j                         }|rj|j                         D ]W  }|j                  |d      j                         d	k7  r(|j                  |j                  |d      j                                Y t        |      d
k\  r|j                  |d          t        |      dk\  r$|j!                  |d
          |j#                          |j%                          |j'                          y)z,Launch Map Swipe. See OnIClass documentationr   )SwipeMapDisplayNzMap Swipe Toolr<   r>   r   rW   maplayerrm   rasterr^   ra   )mapswipe.framer  rz   r{   r   rU  rN   r}   rs  GetSelectionsGetLayerInfoGetTyperE   GetNamelenSetFirstRasterSetSecondRasterSetRasterNamesr  r   )	rP   rB  rA  r  framer  rastersrQ  layers	            rH   
OnMapSwipezGMFrame.OnMapSwipe  s   2i77qAQ?R
 <<

   "++- S$$U
$;CCEQt00J0GOOQRS
 w<1wqz*w<1
+ 
rJ   c                 b    ddl m}  ||       }|j                          |j                          y)z-Launch r.li setup. See OnIClass documentationr   )RLiSetupFramerX   N)rlisetup.framer  r  r   )rP   rB  rA  r  r  s        rH   
OnRLiSetupzGMFrame.OnRLiSetup  s$    04(
rJ   c                 x    ddl m}  || | j                        }|j                          |j	                          y)zLaunch Data Catalogr   )DataCatalogFramerW   N)datacatalog.framer  r}   r  r   )rP   rB  rA  r  r  s        rH   OnDataCatalogzGMFrame.OnDataCatalog  s*    6d4<<@
rJ   c                     t        | d      r(| j                  j                  | j                         | `| j	                  d       y)zCommand execution finishedr   )log N)hasattrr   DeleteIntermediateDatarL   r  rH  s     rH   OnDonezGMFrame.OnDone#  s8    4!JJ--$..-A
2rJ   c                    d}t        j                  | t        d      t        j                         t        d            }|j                         t         j                  k(  r|j                         }|s|j                          yddl	m
}  |       | _        | j                  j                  |       | j                  j                  | j                         | j                  |        |j                          y)	z	Run modelr  zChoose model to runzGRASS Model File (*.gxm)|*.gxmr<   rF   
defaultDirwildcardNr   )Model)r  onDoner<   )rz   
FileDialogrN   r   getcwd	ShowModalID_OKGetPathDestroygmodeler.modelr  r   	LoadModelRunGetLogWindowr  )rP   rB  r   dlgr  s        rH   
OnRunModelzGMFrame.OnRunModel*  s    mm+,yy{78	
 ==?bhh&{{}HKKM(W


X&

4,,.t{{4PrJ   c                     t        | t        j                        }|j                          |j	                         t        j
                  k(  r2|j                         }t        d| ddj                  |      z  d       yy)zLaunch mapset access dialog)r<   r=   z	g.mapsetsz%srp   set)r<   r   	operationN)	r   rz   r  CenterOnScreenr  r  
GetMapsetsr   r   )rP   rB  r  mss       rH   	OnMapsetszGMFrame.OnMapsetsA  s`    $2995==?bhh&!BD1DPU 'rJ   c                 (   | j                   j                         | _        | j                   j                         | _        	 | j                         j                          | j                         j                          |j                          y#  Y xY w)z"Page in notebook (display) changedN)	r,  re  rw   GetSelectionrx   r   SetFocusr   SkiprH  s     rH   r0  zGMFrame.OnCBPageChangedL  st    ..==?"11>>@	 ))+ &&( 	

	s    <B Bc                     |j                         }|| j                  j                  d      k(  r)t        j                  | j
                  j                         | j                  dd       |j                          y)zPage in notebook changedr  r  r   N)	r"  r   r  rz   r   r   
ResetFocusr  r$  )rP   rB  rL  s      rH   r  zGMFrame.OnPageChangedX  sV    !!#4==33H==LL0012q!

rJ   c                    | j                   j                  |j                               }t        d      j	                  |      }| j
                  j                  |      s|j                          y| j                   j                  |j                               j                  }|j                         j                          |j                  d       d| _        |j                          y)zPage of notebook is being closed
        from Layer Manager (x button next to arrows)
        Also close associated map display.
        r{  NT)r,  r}  r"  rN   r   r~   r~  VetoGetPagern  r   CleanUpCloserw   r$  )rP   rB  r   r   rn  s        rH   r2  zGMFrame.OnCBPageClosinga  s     ""..u/A/A/CD*+2248%%227;JJL%%--e.@.@.BCKK'')d

rJ   c                     | j                   j                  t        j                         | j                   j	                  |d          | j                   j                  t        j                  | j                         y)zClose page and destroy map display without generating notebook
        page closing event.

        :param dict pgnum_dict: dict "layers" key represent map display
                                notebook layers tree page index
        rz  N)r,  Unbindr.  r1  
DeletePager   r2  )rP   r  s     rH   r  zGMFrame._closePageNoEventu  s]     	""2#C#CD&&z(';<  ,,  	
rJ   c                 H    | j                  |       |j                          y )Nr  )r  r$  )rP   rB  r  s      rH   _switchPageHandlerzGMFrame._switchPageHandler  s    l3

rJ   c                 Z   |t         j                  k(  r| j                  j                  d       |t         j                  k(  r| j                  j                  d       |t         j                  k(  r<| j                  j                  d       | j                          | j                          yy)zBManages @c 'output' notebook page according to event notification.r  N)	r   	HIGHLIGHTr   HighlightPageByNameMAKE_VISIBLEr   RAISE_WINDOWr#  r   )rP   r  s     rH   r  zGMFrame._switchPage  sy    <111MM--h7<444MM,,X6<444MM,,X6MMOJJL 5rJ   c                    t        j                  d      j                  |d         r| j                  |       yt        j                  d      j                  |d         r| j	                  d|       y|d   dk(  r| j                  d|       y|d   dk(  r| j                  d|       y|d   dk(  r| j                  d|       y|d   d	k(  r| j                  d
       y|d   dk(  r| j                  d|       y|d   dk(  r| j                  d|       y|d   dk(  r| j                  d
       y|d   dk(  r| j                  d|       yt        ddj                  |      z        )z5Run command from command line, check for GUI wrappersz^d\..*r   zr[3]?\.mapcalcN)rB  rA  zi.groupzr.importz
r.externalr.external.out)rB  zv.importz
v.externalzv.external.outcdz1Layer Manager special command (%s) not supported. )recompiler5  RunDisplayCmdOnMapCalculatorOnEditImageryGroupsOnImportGdalLayersOnLinkGdalLayersOnRasterOutputFormatOnImportOgrLayersOnLinkOgrLayersOnVectorOutputFormatOnChangeCWD
ValueErrorr   )rP   commands     rH   r@  zGMFrame.RunSpecialCmd  ss   ::h&&wqz2w'ZZ()00<  t 9QZ9$$$4W$=QZ:%##$G#<QZ<'!!'!:QZ++%%D%1QZ:%""7";QZ<'  t 9QZ++%%D%1QZ44W5"$'HHW$56 rJ   c                    | j                   s| j                  d       |d   dk(  r| j                         j                          y	 t        |d      }|dk(  rNt        |      d	kD  r!| j                         j                  |
       y| j                         j                          y|dk(  rNt        |      d	kD  r!| j                         j                  |
       y| j                         j                          y|dk(  rQt        |      d	kD  r"| j                         j                  |d       y| j                         j                  d       y|dk(  rNt        |      d	kD  r!| j                         j                  |
       y| j                         j                          y|dk(  rNt        |      d	kD  r!| j                         j                  |
       y| j                         j                          y|dk(  r | j                         j                  d       y|dk(  r:t!        | d      j#                  || j                         j$                  ddf       y|dk(  rt        |      d	k  r:t!        | d      j#                  || j                         j&                  ddf      }yt!        | d      j#                  || j                         j&                  ddf      }| j                         j)                  |j+                                yt-        |d|      \  }}| j                         j/                  ||rdnd||       y# t
        $ r t        | t        d      |d   z         Y yw xY w)zMHandles display commands.

        :param command: command in a list
        Trr   r   zd.eraseNzXCommand '%s' not yet implemented in the WxGUI. Try adding it as a command layer instead.r<   rF   barscaler^   rA  rastlegvectlegF)rA  
showDialog)rO  
northarrowr  redrawexport)r<   rs   r  )	completedtorastrH  )fullyQualified	layerType)r  r  r  r  )rw   r   rs  DeleteAllLayersr   KeyErrorr	   rN   r  r   AddBarscaleAddLegendRastAddLegendVectAddArrowAddDtextOnRenderr1   ParseCommandDOutFileOptDataDToRastOptDataDToRastget_cmdr   r  )rP   rH  	layertypetaskr  founds         rH   r=  zGMFrame.RunDisplayCmd  s5   
 OOO&1:"//1	%gaj1I 
"7|a""$00W0=""$002)#7|a""$22w2?""$224)#7|a""$22w52Q""$22d2C,&7|a""$--'-:""$--/& 7|a""$--'-:""$--/(" ))$/("t%(55D$6$6$8$H$H"b#Q 6  ("7|q $T2??(:(:(<(K(KRQS'T @  $T2??(:(:(<(K(KRQS'T @  ""$,,T\\^,D /	LE5 ((!&D	 ) s  		@ !*	 		s   M %M/.M/c                     | j                   S )zGet Layers Notebook)r,  r  s    rH   GetLayerNotebookzGMFrame.GetLayerNotebook  s    """rJ   c                 H    | j                   r| j                   j                  S y)zqGet current layer tree

        :return: LayerTree instance
        :return: None no layer tree selected
        N)rw   rn  r  s    rH   rs  zGMFrame.GetLayerTree  s"     ##+++rJ   c                 J   |r+| j                   r| j                         j                         S yt               }t	        d| j
                  j                               D ]D  }|j                  | j
                  j                  |      j                  j                                F |S )a  Get current map display

        :param bool onlyCurrent: True to return only active mapdisplay
                                 False for list of all mapdisplays

        :return: MapFrame instance (or list)
        :return: None no mapdisplay selected
        Nr   )
rw   rs  r   r   ranger,  GetPageCountrE   r)  rn  )rP   onlyCurrentmlistrR  s       rH   r   zGMFrame.GetMapDisplay  s     ((*88::FEQ 3 3 @ @ BC WT0088=EESSUVW LrJ   c                 &    | j                  d      S )zGet all (open) map displaysFrn  )r   r  s    rH   r   zGMFrame.GetAllMapDisplays   s    !!e!44rJ   c                     | j                   S )z,Gets console for command output and messages)rL   r  s    rH   r  zGMFrame.GetLogWindow$  s    ~~rJ   c                 >    || j                   v r| j                   |   S y)z#Returns toolbar if exists else NoneN)r   r  s     rH   
GetToolbarzGMFrame.GetToolbar(  s     4== ==&&rJ   c                 N   d}|r| j                   |j                            }nd}	 |j                  d      }|dv r|S 	 | j                         j                  }| j                         j                  |d      j                  }| j                         j                  |d      }|rmt        |      dk(  r_d	k(  r|d
   d
   dk(  r|d
   d   dk7  s|dk(  r?|d
   d
   dk(  r4t               j                  |d
         }|r|j                  |d       |S #  |}Y xY w#  d}Y xY w)zDGet GRASS command from menu item

        :return: command as a listNr  r:  )vcolors	r.mapcalcz
r3.mapcalcr  r  typer^   r  r   r3r  v=)r  GetIdr   rs  layer_selectedr  r   r  r1   GetCommandInputMapParamKeyrE   )rP   rB  r  rA  cmdlistr   rx  inputs           rH   
GetMenuCmdzGMFrame.GetMenuCmd/  s5    ,,u{{}-CC	iinG 88N	%%'66E$$&33Ez3JOOD$$&33Ev3FD S\Q& WQZ]c%9gajms>R WQZ]c%988DNNeT#:;/	G	Es   D A&D DD$c                 `    |r| j                  |      }| j                  j                  |       y)zRun command selected from menuN)r  rL   RunCmdrP   rB  rA  s      rH   
RunMenuCmdzGMFrame.RunMenuCmdT  s%    //%(Cc"rJ   c                 v    |r| j                  |      }t        | | j                        j                  |       y)z Parse command selected from menurW   N)r  r1   r}   r`  r  s      rH   	OnMenuCmdzGMFrame.OnMenuCmdZ  s,    //%(C4-::3?rJ   c                     | j                         r | j                         j                  |       y| j                  d      j                  |       y)zVector network analysis toolTrr   N)r   OnVNetr   rH  s     rH   r  zGMFrame.OnVNet`  s>     ''.OOO&--e4rJ   c                    | j                   s| j                          y| j                         }|j                  }|s| j                          y	 |j	                  |d      }|r|j                         dk7  rt        | t        d             y|j                         t        j                         d   k7  rt        | t        d             y|j	                  |      sy|j	                  |d	      }|sy| j                         j                  d
      }|r*d}||j                         u rd}|j                  d       |ry|j                  d       y#  d}Y xY w)zStart vector digitizerNr  r  r  !Selected map layer is not vector.rJ  r   z@Editing is allowed only for vector maps from the current mapset.rA  vdigitFT)rw   MsgNoLayerSelectedrs  r~  r  r  r	   rN   	GetMapsetr   r   r   rt  GetLayerOnStopEditingOnStartEditing)rP   rB  rQ  r  mapLayerdcmddigitToolbarstopOnlys           rH   OnVDigitzGMFrame.OnVDigitg  sR   ##%  "####%	((J(?H 8++-9D!,O*PQ5<<>(#;;&   '  E 2))+66x@H<0022t$D!A	Hs   E Ec           	         t        j                  | t        d      t        j                         t        d            }d}|j                         t         j                  k(  r|j                         }|syt        j                  j                  |      st        | t        d      |z         yt        j                  |t        j                        st        j                  | t        dt        j                  j                  |      z        t        d	      t         j                  t         j                   z  t         j"                  z  
      }|j                         t         j$                  k7  ry|j'                          	 t)        j*                  t        j,                  |      t(        j.                           }t        j0                  ||t(        j2                  z         t        j6                  dg       }|r|j9                  t        j:                        }t        j                  j=                  |      }||vr|j?                  |       t        j                  | t        d      |z  t        d      t         j                  t         j                   z  t         j"                  z  
      }|j                         t         j$                  k(  r*tA        t        j:                  jC                  |      d       |j'                          | jD                  jG                  t        d      |z         | jD                  jI                  |g       y# t4        $ r t        t        d      |        Y yw xY w)zRun user-defined scriptzChoose script file to runz1Python script (*.py)|*.py|Bash script (*.sh)|*.shr	  NFz3Script file '%s' doesn't exist. Operation canceled.rJ  zScript <%s> is not executable. Do you want to set the permissions that allows you to run this script (note that you must be the owner of the file)?zSet permission?)rF   r   r?   z-Unable to set permission. Operation canceled.rX   GRASS_ADDON_PATHzfDirectory '%s' is not defined in GRASS_ADDON_PATH. Do you want add this directory to GRASS_ADDON_PATH?zUpdate Addons path?PATHr  zLaunching script '%s'...)%rz   r  rN   r   r  r  r  r  r   r  r   accessX_OKMessageDialogr   YES_NOYES_DEFAULTICON_QUESTIONID_YESr  statS_IMODElstatST_MODEchmodS_IXUSROSErrorgetenvr   pathsepdirnamerE   r   r   rL   WriteCmdLogr  )rP   rB  r  r   r  	addonPathdirNames          rH   OnRunScriptzGMFrame.OnRunScript  s    mm12yy{JK	
 ==?bhh&{{}Hww~~h'RS
  yy277+""E gg&&x0	1 +,ii"..023C3CCC }}"))+KKM||BHHX$6t||$DE4$,,#67 II0"5	!

3I''//(+)#W%""J 	
 /0ii"..023C3CC	C }}"))+RZZ__Y7VDKKM""1%?#@8#KLxj)5  qHIRVWs    A M M*)M*c                 Z   t        |       }t        j                         }|j                         t        j
                  k(  rj|j                         \  }}|j                          |r|st        | t        d             yt        | |d   ||      rt        | | j                  d||       yyy)zChange current locationrX   z0No location/mapset provided. Operation canceled.rJ  Nr  )r   r   r   r  rz   r  	GetValuesr  r   rN   r3   r4   r}   )rP   rB  r  r   r   r   s         rH   OnChangeLocationzGMFrame.OnChangeLocation  s    D)==?bhh&"}}HfKKM6PQ ,fZ((F ,D$,,hPVW 'rJ   c                    t        j                         }t        | |d   |d         }|ra| j                  j                  j                  |d   |d   |dd       t        | |d   |d   |      rt        | | j                  dd|d       yyy)	zCreate new mapsetr  r   r  r   )r  r   r   r  r  NTr  )r   r   r5   r}   r  r  r3   r4   )rP   rB  r   r   s       rH   OnCreateMapsetzGMFrame.OnCreateMapset  s    ,&$f_&=
 LL'',,z*0  -  -fZ(&*A6 ,$,,dFd rJ   c                 V   t        |       }t        j                         }|j                         t        j
                  k(  rh|j                         }|j                          |st        | t        d             yt        | |d   |d   |      rt        | | j                  dd|       yyy)zChange current mapsetrX   z'No mapset provided. Operation canceled.rJ  Nr  r   )r   r   r   r  rz   r  r  r  r   rN   r3   r4   r}   )rP   rB  r  r   r   s        rH   OnChangeMapsetzGMFrame.OnChangeMapset  s    $'==?bhh&]]_FKKM+T)U ,fZ(&*A6 ,D$,,dFS 'rJ   c                 j    |s| j                          y| j                          | j                          y)z]Current mapset changed.
        If location is None, mapset changed within location.
        N)r   OnWorkspaceCloseOnWorkspaceNew)rP   dbaser   r   s       rH   r   zGMFrame.OnMapsetChanged  s+     NN !!#!rJ   c                     d fd	} fd} fd} fd}|r|d   dk7  rt        d      |rJt        |      d	kD  r< ||
        j                  j                  t	        d              |         |        y|rwt        |      d	k(  ri ||d          |d   dv r |         |        y	 t
        j                  j                  |d         }t        j                  |        |         |        yt        j                   t	        d      t        j                               }	|	j                         t        j                  k(  rV|	j!                          _         | j"                         t        j                   j"                          |         |        yy# t        $ r.} j                  j                  t        |             Y d}~d}~ww xY w)zChange current working directory

        :param event: to be able to serve as a handler of wx event
        :param cmd: command as a list (must start with 'cd')
        Nc                     | r"j                   j                  d| z   dz          y j                   j                  dj                  |             y )Nzcd ""r:  )r}   r  r   )	parameterrH  rP   s     rH   write_beginningz,GMFrame.OnChangeCWD.<locals>.write_beginning1  s?    (());c)AB (('):;rJ   c                  x     j                   j                  t        d      t        j                         z         y )Nz"Working directory changed to:
"%s")r}   WriteLogrN   r   r  r  s   rH   write_changedz*GMFrame.OnChangeCWD.<locals>.write_changed8  s)    LL!!78299;FrJ   c                  <     j                   j                  d       y )Nr:  )r}   r  r  s   rH   	write_endz&GMFrame.OnChangeCWD.<locals>.write_end=  s    LL$$S)rJ   c                  &    j                   j                  t        d              j                   j                  t        d              j                   j                  t        d              j                   j                  t        d             y )Nz/Changes current working directory for this GUI.zUsage: cd [directory]z%Without parameters it opens a dialog.zdIf ~ (tilde) is present as the first directory on the path, it is replaced by user's home directory.)r}   r  rN   r  s   rH   
write_helpz'GMFrame.OnChangeCWD.<locals>.write_help@  sq    LL!!FG LL!!!$;"<=LL!!!$K"LM LL!!1rJ   r   r9  zPOnChangeCWD cmd parameter must be list of length 1 or 2 and 'cd' as a first itemra   rU  z!More than one parameter provided.r^   )r  )z-hz--hz--helphelpzChoose a working directory)r<   rF   defaultPathNN)rG  r  r}   rM   rN   r   r   
expanduserchdirr  strrz   	DirDialogr  r  r  r  ry   )
rP   rB  rA  r  r  r  r  r   errorr  s
   `         rH   rF  zGMFrame.OnChangeCWD)  sw   	<	
	*	$ 3q6T> :  3s8a<C(LL##A&I$JKLK3s8q=c!f-1v884ww))#a&1 K,,67IIKC }}"((*"{{}$,,7& +  4''E
334s   +>F 	G%$GGc                     | j                   S )z%Get current working directory or None)ry   r  s    rH   
GetCwdPathzGMFrame.GetCwdPath}  s    ||rJ   c                     t        | | j                  dddidf      }|sy|j                  d      }|r9|j                  d	      r(| j	                         j                  d
|ddd|z  g       |j                          y)zCreate new vector map layerzv.edittoolcreater   )rA   rA  NT)fulladdr  r  map=%sr  )r   r}   r  	IsCheckedrs  r  r  )rP   rB  r  r   s       rH   OnNewVectorzGMFrame.OnNewVector  s    X7I5,Q
 {{{%CMM%(((40	 )  	rJ   c                    t        j                         }|s(t        j                  j	                  t        d             t        j                  dk(  rSt        j                  j                  t        j                  j                  t        j                  d      d            sd}nd}| j                  j                  t        d             t        t        j                               }| j                  j                  dj                  g t        d      d	|j!                  d
t        d            dt        d      d	|j!                  dd      dt        d      d	|j!                  dd      dt        d      d	|j!                  dd      d|j!                  dd      d|j!                  dd      d|j!                  dd      d|j!                  dd      dt        j"                         dt$        j&                  dt        d      d	||d      t(        j*                         | j                  j                  d        y!)"zPrint system informationzUnable to get GRASS version
r  GISBASEzWinGRASS-README.urlz
 (OSGeo4W)r  zSystem InfozGRASS versionz: versionzunknown version
zCode revisionrevision?z
Build date
build_datezBuild platformbuild_platformz
GDAL: gdalz
PROJ: projz
GEOS: geosz	
SQLite: sqlitez	
Python: z
wxPython: Platformr0  r:  N)r   r  r  stderrwriterN   r  r   r   r  r   r  rL   r  r   r  getpython_versionrz   __version__r   r5  )rP   rB  vInfoosgeo4w	platform_s        rH   OnSystemInfozGMFrame.OnSystemInfo  s
   JJQ>?@ <<7"277>>GGLL9-/DE,
 #GG""1]#34 8,,./	  /" 		)Q'8%9: /" 		*c* , 		,,  "#!" 		*C0#, 		&#&-. 		&#&/0 		&#&12 		(C(34 '')56 78 *9: ;< =@ &22C 	  "	
F 	""3'rJ   c                 b    ddl m}  ||       }|j                          |j                  d       y)zDisplay 'About GRASS' dialogr   )AboutWindowTN)gui_core.ghelpr  r  r   )rP   rB  r  r  s       rH   OnAboutGRASSzGMFrame.OnAboutGRASS  s&    .$rJ   c                    t               }|D ]  \  }}||j                          t        j                  |t        j                  t
        |   j                               }|j                  t
        |   j                  | j                               |j                  |       | j                  t        j                  ||        | j                  |       |j                          y)zCreate popup menuN)r$   AppendSeparatorrz   r  r  r   GetLabel	SetBitmap	GetBitmapru   r  r   r  	PopupMenur  )rP   datarV   rm   handlerr
  s         rH   
_popupMenuzGMFrame._popupMenu  s    v  	2LC{$$&;;tRYY0E0E0GHDNN73<11$--@AOOD!IIbkk7D1	2 	trJ   c                 8    | j                   j                          y)zCreate new workspace fileN)r~   NewrH  s     rH   r  zGMFrame.OnWorkspaceNew  s    ""$rJ   c                 8    | j                   j                          y)z#Open file with workspace definitionN)r~   OpenrH  s     rH   OnWorkspaceOpenzGMFrame.OnWorkspaceOpen      ##%rJ   c                 8    | j                   j                          y)z#Save file with workspace definitionN)r~   SaverH  s     rH   OnWorkspaceSavezGMFrame.OnWorkspaceSave  r  rJ   c                 8    | j                   j                          y)z*Save workspace definition to selected fileN)r~   SaveAsrH  s     rH   OnWorkspaceSaveAszGMFrame.OnWorkspaceSaveAs  s    %%'rJ   c                 8    | j                   j                          y)z$Close file with workspace definitionN)r~   r+  rH  s     rH   r  zGMFrame.OnWorkspaceClose  s    $$&rJ   c                 ~    | j                   r1| j                         r | j                         j                  |       yyy)z Close current map display windowN)rw   r   OnCloseWindowrH  s     rH   OnDisplayClosezGMFrame.OnDisplayClose  s5     2 2 4 ..u5 !5rJ   c                 p    | j                   j                  t        d            sy| j                          y)z.Close all open map display windows (from menu)zClose all Map Displaysr   N)r~   r~  rN   DisplayCloseAllrH  s     rH   OnDisplayCloseAllzGMFrame.OnDisplayCloseAll  s.    %%221=U;V2WrJ   c                 X    | j                  d      D ]  }|j                  dd        y)z"Close all open map display windowsFrq  N)rB  r  )r   r
  )rP   r  s     rH   r  zGMFrame.DisplayCloseAll  s4    ))e)< 	HG!!!G	HrJ   c                 P    | j                         D ]  }|j                  d         y rD   )r   r_  )rP   rB  r  s      rH   OnRenderAllMapDisplayszGMFrame.OnRenderAllMapDisplays
  s(    --/ 	#GT"	#rJ   c                    | j                   j                  | j                        }t        | t	        d      t	        d      |      }|j                         t        j                  k(  rX|j                         }| j                   j                  | j                  |       | j                         }|j                  |       |j                          y)zChange Map Display namezEnter new name:zRename Map Display)rF   r   value)rL  r  N)r,  r}  rx   r2   rN   r  rz   r  GetValueSetPageTextr   r   r  )rP   rB  r   r  rZ  s        rH   r	  zGMFrame.OnRenameDisplay  s    ""..t/B/BC'(*+	
 ==?bhh&<<>D++1D1D4+P++-J%rJ   c                     ddl m}  || | j                               }|j                          |j	                          y)z&Launches dialog for raster color rulesr   )RasterColorTable)	layerTreeN)modules.colorrulesr  rs  r   r  )rP   rB  r  ctables       rH   OnRasterRuleszGMFrame.OnRasterRules  s/    7!$$2C2C2EFrJ   c                     ddl m}  || | j                         d      }|j                          |j	                          y)z&Launches dialog for vector color rulesr   )VectorColorTablecolor)r  attributeTypeN)r  r  rs  r   r  )rP   rB  r  r  s       rH   OnVectorRuleszGMFrame.OnVectorRules&  s6    7!D--/w
 	rJ   c                 Z    t        |       }|j                          |j                          y)z,Show dialog for creating and editing groups.N)r    r  r   )rP   rB  rA  r  s       rH   r?  zGMFrame.OnEditImageryGroups0  s!    $
rJ   c                 z    ddl m}  || | j                  d      }|j                          |j	                          y)z.Install extension from GRASS Addons repositoryr   )InstallExtensionWindow)  i&  )rA   r>   N)modules.extensionsr$  r}   r  r   )rP   rB  r$  r  s       rH   OnInstallExtensionzGMFrame.OnInstallExtension6  s,    =$T$,,ZP
rJ   c                 d    ddl m}  || d      }|j                          |j                          y)zManage or uninstall extensionsr   )ManageExtensionWindow)r%  ,  )r>   N)r&  r)  r  r   )rP   rB  r)  r  s       rH   OnManageExtensionzGMFrame.OnManageExtension>  s&    <#Dz:
rJ   c                 v     j                   d   st          j                        }| j                   d<    j                   d   j                          |j                  j                   j                          j                  t        j                   fd|        j                   d   j                          y)z General GUI preferences/settingsrS   rW   c                 <    j                   j                  d       S )N)rS   )r   update)evtrP   s    rH   r%  z'GMFrame.OnPreferences.<locals>.<lambda>O  s    $,,*=*=$*=*O rJ   N)r   r   r}   CenterOnParentsettingsChangedr   r  r   rz   r   r   )rP   rB  r  s   `  rH   OnPreferenceszGMFrame.OnPreferencesF  s    ||M*#4EC*-DLL'LL'668''(>(>?IIOQT 	]#((*rJ   c                     | j                   d   sFddlm}  || | j                        }|| j                   d<   | j                   d   j	                          | j                   d   j                          y)zShow nviz preferencesrT   r   )NvizPreferencesDialogrW   N)r   nviz.preferencesr4  r}   r  r   )rP   rB  r4  r  s       rH   OnNvizPreferenceszGMFrame.OnNvizPreferencesT  s]    ||-.>'tDLLIC.1DLL*+LL*+::<&',,.rJ   c                 >    | j                   j                  ddg       y)z	Show helpzg.manualz-iN)rL   r  rH  s     rH   OnHelpzGMFrame.OnHelp^  s    z401rJ   c                    ddl m}m}m} |st	        t        d      |z         yt        j                  dt        j                  t        d            } ||| j                        }|j                          |j                          y)a  Start wxIClass tool

        The parameters of all handlers which are associated with module
        and contained in menu/toolboxes must be event and cmd.
        When called from menu event is always None and cmd is the
        associated command (list containing a module name and parameters).

        .. todo::
            This documentation is actually documentation of some
            component related to gui_core/menu.py file.
        r   )IClassMapDisplay
haveIClasserrMsgz>Unable to launch "Supervised Classification Tool".

Reason: %sNzSupervised Classification Toolr  rW   )iclass.framer:  r;  r<  r   rN   rz   r{   r   rU  r}   r  r   )rP   rB  rA  r:  r;  r<  r  r  s           rH   OnIClasszGMFrame.OnIClassb  sv     	FEWX **45

 eDLLA
rJ   c                 H   ddl m}  || | j                        }|j                          |j	                          | j                         }|rg }|j                  d      D ]I  }|j                  |d      dk(  s|j                  |j                  |d	      j                                K t        |      d
k\  rgddlm} ddlm}	  |       }
 |	       }d|_        dj!                  |      |_        ddg|_        |
j'                  |       |j)                  |
dddg       yyy)z2Launch Animation tool. See OnIClass documentation.r   )AnimationFramerW   F)checkedOnlyrx  r  r  r  ra   )	LayerList)	AnimLayerrp   d.rastzmap=N)animation.framer@  r}   r  r   rs  GetSelectedLayersr  rE   r  r  core.layerlistrB  animation.datarC  mapTyper   r   rA  r  SetAnimations)rP   rB  rA  r@  r  rQ  r  r  rB  rC  	layerLists              rH   OnAnimationToolzGMFrame.OnAnimationTool  s   2d4<<@

  "G//E/B W$$U$78CNN4#4#4U
#4#K#S#S#UVW 7|q 44%K	! ( XXg.
%v.	""5)##YdD$AB ! rJ   c                     	 ddl m}  |d      }|j                          y# t        $ r t        | t	        d             Y yw xY w)zLaunch Timeline Toolr   )TimelineFramezUnable to start Timeline Tool.rJ  N)timeline.framerN  ImportErrorr   rN   r   )rP   rB  rA  rN  r  s        rH   OnTimelineToolzGMFrame.OnTimelineTool  sC    	4 d#

	  	$*J(KL	s   ! AAc                     	 ddl m}  || | j
                        }|j                          y# t        $ r t        | t	        d             Y yw xY w)zLaunch Temporal Plot Toolr   )
TplotFramez#Unable to start Temporal Plot Tool.rJ  NrW   )tplot.framerS  rP  r   rN   r}   r   )rP   rB  rA  rS  r  s        rH   OnTplotToolzGMFrame.OnTplotTool  sI    	. $t||<

	  	$*O(PQ	s   - AAc                     ddl m}  || | j                        }|j                          |j	                          |j                          |j                          y)z'Init histogram display canvas and toolsr   )HistogramFrame)rA   N)modules.histogramrW  r}   r  r   Refreshr   )rP   rB  rW  r  s       rH   OnHistogramzGMFrame.OnHistogram  s<    4T$,,7


rJ   c                     ddl m} |r	 | j                  |      } || | j                  |d         }|j                          |j                          y# t        $ r dg}Y Gw xY w)zBInit map calculator for interactive creation of mapcalc statementsr   )MapCalcFramerw  )r<   rA   rA  N)modules.mcalc_builderr\  r  rY  r}   r  r   )rP   rB  rA  r\  r  s        rH   r>  zGMFrame.OnMapCalculator  s`    6$ooe, $t||QH
	  $"m$s   A A#"A#c                 *    | j                  dg       y)z Set raster output format handlerr8  rL  N)r  rH  s     rH   rB  zGMFrame.OnRasterOutputFormat  s    ,-.rJ   c                 d    ddl m}  || d      }|j                          |j                          y)z Set vector output format handlerr   )GdalOutputDialogT)r<   ogrN)modules.import_exportr`  r  r   )rP   rB  r`  r  s       rH   rE  zGMFrame.OnVectorOutputFormat  s&    :d5
rJ   c                 x    ddl m}  || | j                        }|j                          |j	                          y)z6Convert multiple DXF layers to GRASS vector map layersr   )DxfImportDialogrW   N)rb  rd  r}   r  r   )rP   rB  rA  rd  r  s        rH   OnImportDxfFilezGMFrame.OnImportDxfFile  *    9T$,,?
rJ   c                 x    ddl m}  || | j                        }|j                          |j	                          y)z7Convert multiple GDAL layers to GRASS raster map layersr   GdalImportDialogrW   Nrb  ri  r}   r  r   rP   rB  rA  ri  r  s        rH   r@  zGMFrame.OnImportGdalLayers  s*    :d4<<@
rJ   c                 z    ddl m}  || | j                  d      }|j                          |j	                          y)z4Link multiple GDAL layers to GRASS raster map layersr   rh  Tr<   rA   linkNrj  rk  s        rH   rA  zGMFrame.OnLinkGdalLayers  s,    :d4<<dK
rJ   c                 x    ddl m}  || | j                        }|j                          |j	                          y)z6Convert multiple OGR layers to GRASS vector map layersr   OgrImportDialogrW   Nrb  rq  r}   r  r   rP   rB  rA  rq  r  s        rH   rC  zGMFrame.OnImportOgrLayers  rf  rJ   c                 z    ddl m}  || | j                  d      }|j                          |j	                          y)z4Links multiple OGR layers to GRASS vector map layersr   rp  Trm  Nrr  rs  s        rH   rD  zGMFrame.OnLinkOgrLayers  s,    9T$,,TJ
rJ   c                     ddl m}  || | j                        }|j                          |j	                         \  }}|j                  ||dz
  f       |j                          y)zAdd web services layerr   )AddWSDialogrW      N)web_services.dialogsrv  r}   r  GetPositionr   r   )rP   rB  rA  rv  r  r   r   s          rH   OnAddWSzGMFrame.OnAddWS  sN    4dll; 1AG%
rJ   c                     ddl m}  || | j                        }|j                  | j	                                |j                          |j                          y )Nr   )PyEditFramerW   )gui_core.pyeditr|  r}   r   r   r  r   )rP   rB  r|  simpleEditors       rH   rF  zGMFrame.OnSimpleEditor  sC    / #$t||DT\\^,##%rJ   c                 R   | j                   s| j                          y| j                         }|j                  }|s| j                          y	 |j	                  |d      j
                  }|r|dk7  rt        | t        d             y|j	                  |      sy|j	                  |d      }|sydd	lm	}  || t        j                  t        j                  d
d      || j                  |      }| j                  d   j                  |       |j!                          y#  d}Y xY w)z2Show attribute table of the given vector map layerNr  r  r  r  rJ  rA  r   )AttributeManageri  r*  )r<   r=   r>   r
  r  r  rU   )rw   r  rs  r~  r  rx  r	   rN   dbmgr.managerr  rz   r  SizerL   r   rE   r   )	rP   rB  r  rQ  r  maptyper  r  	dbmanagers	            rH   OnShowAttributeTablezGMFrame.OnShowAttributeTable  s   ##%  "####%	'':'>CCG 'X-D!,O*PQ  '  E 22$yyc"
	 	U""9-5	Gs   D   D&c                     | j                   j                  ry| j                  j                  |      }|dkD  r;| j                  j	                  |       | j                  j                         | _        yy)z9Changes bookcontrol page to page associated with display.Nrf   )r~   loadingWorkspacer,  r|  SetSelectionre  rw   )rP   notebookLayerPagepgnums      rH   r  zGMFrame._onMapDisplayFocus<  sd    
 !!22##001BC2:,,U3#22AACD rJ   c                 2   t        d| j                         j                               D ]l  }| j                         j                  |      j                  j                         }| j                         j                  |      |k7  s]|j                          n y)z>Disables 3D mode for all map displays except for @p mapDisplayr   N)rl  ri  rm  r)  rn  r   Disable3dMode)rP   r  rL  r   s       rH   r  z#GMFrame._onMapDisplayStarting3dModeH  s|     !T224AACD 	(D++-55d;CCQQSG$$&..t4F%%'	(rJ   c                 @   t        | t        d             }|j                  j                  | j                         |j                         }|t        j                  k(  r0| j	                  |j                         |j                  d             |j                          y)z'Add selected map layers into layer tree)r<   r   TrL  N)r!   rN   applyAddingMapLayersr   AddMapsr  rz   r  GetMapLayersGetLayerTyper  )rP   rB  dialogvals       rH   	OnAddMapszGMFrame.OnAddMapsQ  sy     q!JK
 	##++DLL9 "((?LL,,.0C0C0C0MNrJ   c           	      2   | j                   s| j                          | j                         }|D ]f  }|dk(  rdd|z  g}n@|dk(  rdd|z  g}n3|dk(  rdd|z  gt               z   }nt	        | t        d      |z  	        y
|j                  |||d|d
      }h y
)a  Add map layers to layer tree.

        :param list mapLayers: list of map names
        :param str ltype: layer type ('raster', 'raster_3d', 'vector')
        :param bool check: True if new layers should be checked in
                           layer tree False otherwise
        r  rD  r  	raster_3dzd.rast3dr  r   Unsupported map layer type <%s>.rJ  Ng      ?)r  r  r  lopacityr  lgroup)rw   r   rs  r   r   rN   r  )rP   	mapLayersr  checkrn  	layerNamerA  newItems           rH   r  zGMFrame.AddMaps]  s     OO##%" 	I I!56+%!8i#78("I!569O9QQ+M)NQV)V && ' G	rJ   c                     d|v r2| j                         j                         j                  |d          y| j                         j                         j                          y)z&Updates map of the current map window.delay)r  N)r   	GetWindow	UpdateMap)rP   r   s     rH   r   zGMFrame._updateCurrentMap  sO    f **,66VG_6M **,668rJ   c                     |,t        j                  ddd      r| j                  ||       yy|r| j                  ||       y| j                         }|j	                         j                  d       y)z6Decides whether the map should be added to layer tree.NrA  addNewLayerrj   rk   Tr  )r
   r   AddOrUpdateMapr   r  r  )rP   r   r  r  r  s        rH   r   zGMFrame.OnMapCreated  sl    ;eyQ##D%0 Re, ((*G)))6rJ   c                 n   |dvrt        | t        d      |z         y| j                  s| j                  |g|d       y| j	                         }t        d |j                         j                  |            }||v r!|j                         j                  d	       y| j                  |g|d       y)
zAdd map layer or update)r  r  r  r  rJ  NT)r  c                 "    | j                         S rD   )r  )r   s    rH   r%  z(GMFrame.AddOrUpdateMap.<locals>.<lambda>  s    !))+ rJ   )r  r  )
r   rN   rw   r  r   r   GetMapGetListOfLayersr  r  )rP   mapNamer  r  r  s        rH   r  zGMFrame.AddOrUpdateMap  s     99$*L(MPU(UVLL'EL6((*G%w~~'7'G'Ge'G'TI )#!!#--T-:gYT:rJ   c                     | j                   s| j                  d       | j                  j                  d       | j	                         j                  d       y)zAdd raster map layerTrr   rz  r  Nrw   r   r   r   rs  r  rH  s     rH   OnAddRasterzGMFrame.OnAddRaster  D     OOO&((2$$X.rJ   c                 @   | j                   s| j                  d       | j                  d| j                  fdd| j                  fd| j
                  fdd| j                  fdd| j                  fd	| j                  ff	       | j                         j                          y
)zCreate misc raster popup-menuTrr   layerRaster_3dr  layerRgblayerHislayerShadedlayerRastarrowlayerRastnumN)rw   r   r  OnAddRaster3DOnAddRasterRGBOnAddRasterHISOnAddRasterShadedOnAddRasterArrowOnAddRasterNumr   r   rH  s     rH   OnAddRasterMisczGMFrame.OnAddRasterMisc  s     OOO&!4#5#56T001T001 6 67!4#8#89!4!45
	
 	!!#rJ   c                     | j                   s| j                  d       | j                  j                  d       | j	                         j                  d       y)z(Add vector map to the current layer treeTrr   rz  r  Nr  rH  s     rH   OnAddVectorzGMFrame.OnAddVector  r  rJ   c                     | j                   s| j                  d       | j                  d| j                  fd| j                  ff       | j                         j                          y)zCreate misc vector popup-menuTrr   layerThememaplayerThemechartN)rw   r   r  OnAddVectorThemeOnAddVectorChartr   r   rH  s     rH   OnAddVectorMisczGMFrame.OnAddVectorMisc  s_     OOO& $"7"78"D$9$9:	
 	!!#rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z1Add thematic vector map to the current layer treerz  thememapNr   r   rs  r  rH  s     rH   r  zGMFrame.OnAddVectorTheme  +    ((2$$Z0rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z.Add chart vector map to the current layer treerz  
themechartNr  rH  s     rH   r  zGMFrame.OnAddVectorChart  s+    ((2$$\2rJ   c           	      "   | j                   s| j                  d       | j                  d| j                  fd| j                  fd| j
                  fd| j                  fdd| j                  ff       | j                         j                          y	)
zCreate decoration overlay menuTrr   	layerGridlayerLabelslayerGeodesic
layerRhumbr  layerCmdN)
rw   r   r  	OnAddGridOnAddLabelsOnAddGeodesic
OnAddRhumbOnAddCommandr   r   rH  s     rH   OnAddOverlayzGMFrame.OnAddOverlay  s     OOO&dnn- 0 01 $"4"45t/T../		
 	!!#rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z+Add 3D raster map to the current layer treerz  r  Nr  rH  s     rH   r  zGMFrame.OnAddRaster3D   s+    ((2$$[1rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z,Add RGB raster map to the current layer treerz  rgbNr  rH  s     rH   r  zGMFrame.OnAddRasterRGB  +    ((2$$U+rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z,Add HIS raster map to the current layer treerz  hisNr  rH  s     rH   r  zGMFrame.OnAddRasterHIS
  r  rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z6Add shaded relief raster map to the current layer treerz  shadedNr  rH  s     rH   r  zGMFrame.OnAddRasterShaded  s+    ((2$$X.rJ   c                 l   | j                   j                  d       | j                         }|j                  j                  }|sR| j                         }|j                         t        j                  k(  rd|j                  _        |j                          | j                         j                  d       y)z4Add flow arrows raster map to the current layer treerz  T	rastarrowN)r   r   r   mapWindowProperties
resolutionMsgDisplayResolutionr  rz   r  r  rs  r  )rP   rB  rZ  r  r  s        rH   r  zGMFrame.OnAddRasterArrow  s    ((2'')
33>>
++-C}}"))+<@
..9KKM$$[1rJ   c                    | j                   j                  d       | j                         }|j                  j                  }|s^t        d      }| j                  |      }|j                         t        j                  k(  rd|j                  _        |j                          | j                         j                  d       y)z4Add cell number raster map to the current layer treerz  zRNote that cell values can only be displayed for regions of less than 10,000 cells.TrastnumN)r   r   r   r  r  rN   r  r  rz   r  r  rs  r  )rP   rB  rZ  r  	limitTextr  s         rH   r  zGMFrame.OnAddRasterNum"  s    ((2'')
33>>
5I ++I6C}}"))+<@
..9KKM
 	$$Y/rJ   c                     | j                   s| j                  d       | j                  j                  d       | j	                         j                  d       | j                         j                          y)z4Add command line map layer to the current layer treeTrr   rz  rH  Nrw   r   r   r   rs  r  r   r   rH  s     rH   r  zGMFrame.OnAddCommand6  s[     OOO&((2$$Y/ 	!!#rJ   c                     | j                   s| j                  d       | j                  j                  d       | j	                         j                  d       | j                         j                          y)zAdd layer groupTrr   rz  rl   Nr  rH  s     rH   
OnAddGroupzGMFrame.OnAddGroupB  s[     OOO&((2$$W- 	!!#rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z,Add grid map layer to the current layer treerz  gridNr  rH  s     rH   r  zGMFrame.OnAddGridN  s+    ((2$$V,rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z5Add geodesic line map layer to the current layer treerz  geodesicNr  rH  s     rH   r  zGMFrame.OnAddGeodesicS  r  rJ   c                 x    | j                   j                  d       | j                         j                  d       y)z-Add rhumb map layer to the current layer treerz  rhumbNr  rH  s     rH   r  zGMFrame.OnAddRhumbX  s+    ((2$$W-rJ   c                     | j                   s| j                  d       | j                  j                  d       | j	                         j                  d       | j                         j                          y)5Add vector labels map layer to the current layer treeTrr   rz  labelsNr  rH  s     rH   r  zGMFrame.OnAddLabels]  s[     OOO&((2$$X. 	!!#rJ   c                    | j                   s| j                  d       | j                         }d|j                  _        |j                          |j                         r!|j                         j                  d       yy)r  Trr   Fr  N)	rw   r   r   r  
showRegionr   IsAutoRenderedGetMapWindowr  )rP   rB  r   s      rH   OnShowRegionExtentzGMFrame.OnShowRegionExtenti  sm     OOO&$$&15##. !!#  ",,E,: $rJ   c                    | j                   r| j                         j                  s| j                          yt	        j
                  ddd      r\d}| j                         j                         D ]l  }| j                         j                  |      }|j                  dt        d      z         }|d	kD  r|d
|d| j                  d      z   dz   z  }b|d
|z   dz   z  }n |j                  d      }t        |      dkD  rt        d      |z  }nt        d      }t        j                  | |t        d      t        j                  t        j                   z  t        j"                  z        }|j%                         t        j&                  k7  r|j)                          y|j)                          | j                         j                         D ]e  }| j                         j+                  |d      dk(  r| j                         j-                  |       	 | j                         j/                  |       g y# t0        $ r Y tw xY w)z5Remove selected map layer from the current layer TreeNr  askOnRemoveLayerrj   rk   r  (zopacity:rf   <r:  z>,
z,
ra   z6Do you want to remove map layer(s)
%s
from layer tree?z<Do you want to remove selected map layer(s) from layer tree?zRemove map layerr<   rF   r   r?   rx  r  rl   )rw   rs  r~  r  r
   r   r  GetItemTextfindrN   striprstripr  rz   r  r  r  r  r  r  r  r  DeleteChildrenDeleterG  )	rP   rB  r  r
  r   rR  rF   r  r  s	            rH   OnDeleteLayerzGMFrame.OnDeleteLayerz  s   t'8'8':'I'I##%)1CIVI))+99; 5((*66t<iia
m 348tDSz'7'7'<!<v!EEItf!44I5 "((/I9~!ST  
 U "",-ii"..023C3CC	C }}"))+KKM&&(668 	E  "//6/BgM!!#2259!!#**51	  s   H44	I ?I c                 d   |j                         }|j                         r|t        j                  k(  rm| j                  j                         | j                  j                  d      k(  r| j                  j                  d       n| j                  j                  d       |j                          y)zKey pressedrz  r  N)	
GetKeyCodeControlDownrz   WXK_TABr   r"  r  r   r$  )rP   rB  kcs      rH   r   zGMFrame.OnKeyDown  s    RZZ==--/4==3S3S4  MM44X>MM44X>

rJ   c                 &    | j                  |       y)zCleanup when wxGUI is quitN)_closeWindowrH  s     rH   r
  zGMFrame.OnCloseWindow  s    % rJ   c                     t        |       }|j                         }|j                          |t        j                  k7  r6| j                  |       |t        j                  k(  r| j                          yyy)z[Cleanup when wxGUI is quit

        Ask user also to quit GRASS including terminal
        N)r"   r  r  rz   	ID_CANCELr  r  
_quitGRASS)rP   rB  r  rets       rH   r   zGMFrame.OnCloseWindowOrExit  s\    
 mmo",,e$bii!   rJ   c                 j   | j                   s+| j                  j                          | j                          y| j                  j                  t        d            st        |d      r|j                          y| j                          | j                  j                          | j                          y)zClose wxGUINzQuit GRASS GUIr  r(  )
rw   r   UnInitr  r~   r~  rN   r  r(  r  rH  s     rH   r  zGMFrame._closeWindow  s    LL!LLN%%221=M;N2O uf%

rJ   c                     t               }|yt        j                  ddj                  |             ddl}t        j                  ||j                         y)zQuit GRASS terminalNr^   zExiting shell with pid={0}r   )r   r%   r`  r   signalr   killSIGTERM)rP   shellPidr  s      rH   r  zGMFrame._quitGRASS  sA     ?		!188BC
&..)rJ   c                     t        j                  | t        d      t        d      t         j                  t         j                  z  t         j
                  z         y)z'Show dialog message 'No layer selected'z*No map layer selected. Operation canceled.Messager  N)rz   
MessageBoxrN   OKICON_INFORMATIONCENTREr  s    rH   r  zGMFrame.MsgNoLayerSelected  s<    
BCiL%%"---		9		
rJ   c                    t        d      }|r|dt        |      z  z  }t        j                  | |t        d      t        j                  t        j                  z  t        j
                  z  t        j                  z        }|S )zReturns dialog for d.rast.num, d.rast.arrow
            when display resolution is not constrained

        :param limitText: adds a note about cell limit
        zDisplay resolution is currently not constrained to computational settings. It's suggested to constrain map to region geometry. Do you want to constrain the resolution?z

%sz!Constrain map to region geometry?r  )rN   rz   r  r  r  r  r  )rP   r  rF   r  s       rH   r  zGMFrame.MsgDisplayResolution  su     
 x!I,..G9:))bnn,r/?/??"))K	
 
rJ   rD   )NTr  )T)r  )F)__name__
__module____qualname____doc__rz   r  r   GM_WINDOW_SIZErV  r|   r   r   r  r  r  r  r   r   r   r   r   r   rI  r   rW  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r   r0  r  r2  r  r1  r  r@  r=  ri  rs  r   r   r  rt  r  r  r  r  r  r  r  r  r  r   rF  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r	  r  r!  r?  r'  r+  r2  r6  r8  r>  rL  rQ  rU  rZ  r>  rB  rE  re  r@  rA  rC  rD  rz  rF  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r
  r   r  r  r  r   rJ   rH   r9   r9   R   s    99%%$$Sj0-
4,A
Y)<	 [$z7
r1<*4$+L0)&:.	
(
	8M^#*5#J  $ # # @50"dG*RX(*T&	"Rh(6(p"%&&('6
H
#   +/2>C4	/	*X
D(
"H97;&/$./$ 1
3
$(2
,
,
/
20(
$
$-
1
.

$;"/b !"$*
rJ   r9   )er!  r  r   r  r  r;  r   r   rz   wx.auiwx.lib.agw.flatnotebooklibagwflatnotebookr.  rP  wx.lib.flatnotebookr   r   ETCDIRrE   grass.scriptr   grass.script.utilsr   	core.gcmdr   r   r	   core.settingsr
   r   
core.utilsr   r   r   r   gui_core.preferencesr   r   lmgr.layertreer   r   lmgr.menudatar   r   gui_core.widgetsr   r   core.gconsoler   r   core.gifacer   gui_core.goutputr   r   gui_core.dialogsr   r   r   r    r!   r"   gui_core.menur#   r$   r   
core.debugr%   lmgr.toolbarsr&   r'   r(   r)   r*   lmgr.statusbarr+   lmgr.workspacer,   lmgr.pyshellr-   lmgr.gifacer.   mapdisp.framer/   datacatalog.catalogr0   gui_core.formsr1   gui_core.wrapr2   startup.guiutilsr3   r4   r5   r6   grass.grassdb.checksr7   r{   r9   r#  rJ   rH   <module>rE     s  (  	   	  	 %(( 77<<	  (+388;HHOOBGGLL!1!18<= & % 2 2 > V V @ - F 4 7 $ 6  - '  < K K ! + & 2 $ +  /  4t"bhh t"c  %$$%s   F F#"F#