
    cc;                         d dl Z d dlZd dlZ ej                  dd        ej                  dd       d dlmZmZmZmZ ddl	m
Z
 dd	lmZ dd
lmZ d Z G d dej                         Zy)    NGtkz3.0
PangoCairoz1.0)r   GioGLibGdk   )DrWindow)DrPrefsWindow)utilities_gfile_is_imagec                 V    t        |       }|j                  t        j                        S N)Applicationrunsysargv)versionapps     ./usr/lib/python3/dist-packages/drawing/main.pymainr      s    7    c                        e Zd ZdZdZdZdZdZdZdZ	 fdZ
d Zd	 Zd%d
Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"g fd Z#d! Z$d" Z%d# Z&d$ Z' xZ(S )&r   Ncom.github.maoschanz.drawingz/com/github/maoschanz/drawingz6https://github.com/maoschanz/drawing/issues/new/choosez/app/bin/drawing c           	         t         |   | j                  t        j                  j
                         t        j                  t        d             t        j                  | j                         || _
        d| _        d| _        | j                  d| j                         | j                  d        | j                  d| j                          | j                  d| j"                         | j%                  ddt        j&                  j(                  t        j*                  j(                  t        d	      d        | j%                  d
dt        j&                  j(                  t        j*                  j(                  t        d      d        | j%                  ddt        j&                  j(                  t        j*                  j(                  t        d      d        | j%                  ddt        j&                  j(                  t        j*                  j(                  t        d      d        t,        j.                  j1                         }|j3                  | j4                  dz          |j3                  | j4                  dz          y )N)application_idflagsDrawingFstartupactivatezcommand-liner      vzShow the app version
new-window   nzOpen a new windownew-tab   tzOpen a new tabedit-clipboard   czEdit the clipboard contentz/iconsz/tools/icons)super__init__APP_IDr   ApplicationFlagsHANDLES_COMMAND_LINEr   set_application_name_set_prgname_versionhas_tools_in_menubarruns_in_sandboxconnect
on_startupregisteron_activateon_cliadd_main_optionOptionFlagsNONE	OptionArgr   	IconThemeget_defaultadd_resource_pathAPP_PATH)selfr   
icon_theme	__class__s      r   r(   zApplication.__init__-   s   '$++--BB  D AiL)4;;$-#$$,,y$//*--,,z4++,,,~t{{+y$(8(8(=(=~~**A.D,EtM |T4+;+;+@+@~~**A.A,BDJ y$(8(8(=(=~~**A.>,?G 't/?/?/D/D~~""A&B$CTK }}((**t}}x78t}}~=>r   c                     | j                          t        j                  j                  | j                  dz         }|j                  d      }| j                  |       y)zACalled only once, add app-wide menus and actions, and all accels.z/ui/app-menus.uizmenu-barN)_build_actionsr   Buildernew_from_resourcer>   
get_objectset_menubar)r?   argsbuildermenubar_models       r   r3   zApplication.on_startupM   sJ    KK))$--:L*LM'$$Z0-=!r   c                 J   | j                  d| j                  dg       | j                  d| j                         t        j                  j	                         }|j
                  dk(  r+|j                  dk(  r| j                  d| j                         | j                  d| j                  dg       | j                  d	| j                         | j                  d
| j                         | j                  d| j                         | j                  d| j                         | j                  d| j                         | j                  d| j                         | j                  d| j                         | j                  d| j                          | j                  d| j"                         | j                  d| j$                         | j                  d| j&                  ddg       | j                  d| j(                  dg       | j                  d| j*                  dg       y)zAdd all app-wide actions.
new_windowz<Ctrl>nsettings   r   zapril-foolshelpF1	help_main	help_zoomhelp_fullscreen
help_toolshelp_colorshelp_transformhelp_selection
help_prefshelp_whats_newzreport-issue	shortcutsz<Ctrl>questionz<Ctrl>F1aboutz	<Shift>F1quitz<Ctrl>qN)add_action_simpleon_new_windowon_prefsdatetimenowmonthdayon_april_foolson_help_indexon_help_mainon_help_zoomon_help_fullscreenon_help_toolson_help_colorson_help_transformon_help_selectionon_help_prefson_help_whats_new	on_reporton_shortcutson_abouton_quit)r?   current_dates     r   rC   zApplication._build_actionsT   s   t'9'9I;GT]]3""&&(,1!1!1Q!6-)<)<=!3!3dV<d&7&78d&7&78*D,C,CDt'9'9:(;(;<)4+A+AB)4+A+ABt'9'9:)4+A+AB8d&7&7,<j+IK$--+?	{;r   c                    |S|rQ| j                  |j                               \  }}|-|j                  |      s|j                  j	                  |       yt        |       }|j                          ||d}|j                  |       |S )zOpen a new window with an optional Gio.File as an argument. If get_cb
		is true, the Gio.File is ignored and the picture is built from the
		clipboard content.Napplication)gfileget_cb)has_image_openedget_pathconfirm_open_twicenotebookset_current_pager	   presentinit_window_content_async)r?   rw   rx   check_duplicateswalready_opened_indexwincontent_paramss           r   open_window_with_contentz$Application.open_window_with_contentq   s     +!225>>3CD1m&ZZ  !56T"#++-"f5. /	*r   c                 v    | j                   j                  }|s| j                          y|j                          y)zZI don't know if this is ever called from the 'activate' signal, but
		it's called anyways.N)propsactive_windowr^   r~   r?   rH   r   s      r   r5   zApplication.on_activate   s+     	

  #	;;=r   c                 d   |j                         }|d   | _        | j                  | j                  k(  rd| _        |j	                         }|j                  d      rwt        t        d      dz   | j                  z          | j                         rt        t        d             t                t        t        d      dz   | j                  z          y|j                  d	      rL| j                  j                  }|s| j                  d
d       y|j                          |j                          y|j                  d      rXt!        |      dk(  rJ| j                  j                  }|s| j#                          y|j                          |j%                          y|j                  d      rZd}|dd
 D ]:  }| j'                  ||      }|dk(  r|dk(  rd
n|}| j                  |d       |dz   }< |dk(  r| j#                          yt!        |      dk(  r| j)                          y|dd
 D ]  }| j'                  ||      }|dk(  r| j                  j                  }|s|dk(  rd
n|}| j                  |d       O|j                          |dk(  r|j%                          u|j+                  |        y)zyMain handler, managing options and CLI arguments.
		Arguments are a `Gio.Application` and a `Gio.ApplicationCommandLine`.r   Tr   r    zThis version isn't stable!Report bugs or ideasu	    👉️ r%   Nr#   r   r!   F)rw   )get_argumentsCURRENT_BINARY_PATHFLATPAK_BINARY_PATHr1   get_options_dictcontainsprintr-   r/   is_betaBUG_REPORT_URLr   r   r   r~   build_image_from_clipboardlenr^   build_blank_image_get_valid_filer5   build_new_from_file)	r?   gio_appgio_command_line	argumentsoptionsr   windows_counterfpathfs	            r   r6   zApplication.on_cli   s    ,,.)&q\$	!9!994
 --/'i 9	dmm	+,
lln	!(
)*7!	"[	043F3F	FGt 
q ()		!	!3
!!$-j 
g KKM""$d 
a 	"s9~':		!	!3
X 
U KKMR 
O % ?!" *u-u5A 	EzT	qA!!!U+%)O* 2 
/ 9~, 
% !" 'u-u5A 	Ez
**
"
"CdQ	""1e,[[]	T			A&'$ 
r   c                 &    | j                  dd      S )z;Action callback, opening a new window with an empty canvas.NF)r   r?   rH   s     r   r^   zApplication.on_new_window   s    		&	&tU	33r   c                     | j                   j                  }t        j                  || j                  t
        j                         y)z8Action callback, opening a new issue on the github repo.N)r   r   r   show_uri_on_windowr   r   CURRENT_TIMEr   s      r   ro   zApplication.on_report   s/    

  #d1133C3CDr   c                    | j                   | j                   j                          t        j                         j	                  | j
                  dz         }|j                  d      | _         | j                   j                          y)z0Action callback, showing the 'shortcuts' dialog.Nz/ui/shortcuts.uizshortcuts-window)shortcuts_windowdestroyr   rD   rE   r>   rF   r~   )r?   rH   rI   s      r   rp   zApplication.on_shortcuts   sf    	&  "KKM++DMM<N,NO'!,,-?@$!r   c                 
   | j                   | j                   j                          d| j                  j                  j                  v }t        | j                         ||       | _         | j                   j                          y)z0Action callback, showing the preferences window.Nhru   )prefs_windowr   r   r   deco_layoutr
   r   r~   )r?   rH   	wants_csds      r   r_   zApplication.on_prefs   sg    	"TZZ--999)#DLLNIEIK$r   c                 v    t        j                  | j                  j                  dt        j
                         y)z&Action callback, rickrolling the user.z+https://www.youtube.com/watch?v=dQw4w9WgXcQN)r   r   r   r   r   r   r   s     r   rd   zApplication.on_april_fools   s)    ::0r   c                 &    | j                  d       y)z7Action callback, showing the index of user help manual.r   N_show_help_pager   s     r   re   zApplication.on_help_index  s    rr   c                 &    | j                  d       y )Nz/main_featuresr   r   s     r   rf   zApplication.on_help_main      '(r   c                 &    | j                  d       y )Nz/zoom_previewr   r   s     r   rg   zApplication.on_help_zoom  s    'r   c                 &    | j                  d       y )Nz/fullscreenr   r   s     r   rh   zApplication.on_help_fullscreen  s    }%r   c                 &    | j                  d       y )Nz/tools_classicr   r   s     r   ri   zApplication.on_help_tools  r   r   c                 &    | j                  d       y )Nz/tools_classic_colorsr   r   s     r   rj   zApplication.on_help_colors  s    ./r   c                 &    | j                  d       y )Nz/tools_transformr   r   s     r   rk   zApplication.on_help_transform      )*r   c                 &    | j                  d       y )Nz/tools_selectionr   r   s     r   rl   zApplication.on_help_selection  r   r   c                 &    | j                  d       y )Nz/preferencesr   r   s     r   rm   zApplication.on_help_prefs  s    ~&r   c                 &    | j                  d       y )Nz
/whats_newr   r   s     r   rn   zApplication.on_help_whats_new   s    |$r   c                    t        j                  | j                  j                  dg dt	        d      ddt	        d      gt	        d      t         j
                  j                  | j                  t        | j                        dt	        d	      
      }t        j                  t         j                  j                  dt	        d      | j                        }|j                  d       |j                          |j!                          y)z,Action callback, showing the "about" dialog.u   © 2018-2023 Romain F. T.)Romain F. T.u   Fábio ColaciozAlexis Lozanoztranslator-creditszTobias Bernardr   z$GNOME's "Art Libre" icon set authorszSimple image editor for Linuxz$https://maoschanz.github.io/drawing/zOfficial webpage)transient_for	copyrightauthorstranslator_creditsartistscommentslicense_typelogo_icon_namer   websitewebsite_labelTr   )halignvisiblelabelurir   N)r   AboutDialogr   r   r-   LicenseGPL_3_0r)   strr/   
LinkButtonAlignCENTERr   set_icon_namer   r   )r?   rH   about_dialogbug_report_btns       r   rq   zApplication.on_about#  s    tzz/G/G(> ,-n DEG -.##++s4=='91%&(, >>)9)94/0d6I6IK. ;<r   c                 Z   | j                   | j                   j                          | j                  | j                  j                          d}| j                         }|D ]5  }|j	                         rd}|j                          |j                          7 |r| j                          yy)z)Action callback, quitting the entire app.NTF)r   r   r   get_windowson_closecloser\   )r?   rH   can_quitmain_windowsr   s        r   rr   zApplication.on_quit<  s    	&  "	"(!!#, ajjlHGGIIIK 99; r   c                 b    t        | j                  j                  d      d         dz  dz  dk(  S )zTells is the app version is even or odd, odd versions being considered
		as unstable versions. This affects available options and the style of
		the headerbar..r      
   )intr/   splitr?   s    r   r   zApplication.is_betaW  s2     dmm!!#&q)
*Q
."	4	99r   c                     | j                   S r   )r/   r   s    r   get_current_versionzApplication.get_current_version]  s    	r   c                     t         j                  j                  |d       }|j                  d|       | j	                  |       | j                  d|z   |       y )Nr   zapp.)r   SimpleActionnewr2   
add_actionset_accels_for_action)r?   action_namecallbackrZ   actions        r   r]   zApplication.add_action_simple`  sI    T2&..X&//&Vk19=r   c                     t        j                         j                  |d t        j                  j                  |            }|j                  d|       | j                  |       y )Nzchange-state)r   r   new_statefulr   Variantnew_booleanr2   r   )r?   r   defaultr   r   s        r   add_action_booleanzApplication.add_action_booleanf  sL    **;(,(@(@(IK&..*//&r   c                     | j                   j                  }t        j                  |d|z   t        j
                         y )Nzhelp:drawing)r   r   r   r   r   r   )r?   suffixr   s      r   r   zApplication._show_help_pagel  s.    

  #nv5s7G7GHr   c                 `    | j                         D ]  }|j                  |      }|||fc S  y)zReturns the window in which the given file is opened, and the index
		of the tab where it is in the window's notebook.
		Or `None, None` otherwise.)NN)r   ry   )r?   	file_pathr   position_in_windows       r   ry   zApplication.has_image_openedp  sD      #c,,Y7$"""# 
r   c                 x   || j                   k(  ryt        d      dz   }	 |j                  |      }t        ||      \  }}|r|S t        |       y# t        $ r`}| j                  r0d}|j                  | j                  |      }|t        d      |z  z   }n||j                  z   }t        |       Y d}~yd}~ww xY w)zCreates a GioFile object if the path corresponds to an image. If no
		GioFile can be created, it returns a boolean telling whether or not a
		window should be opened anyway.FzError opening this file.r   z.
	flatpak run --file-forwarding {0} @@ {1} @@
zDid you mean %s ?NT)
r   r-   create_file_for_arg	Exceptionr1   formatr)   messager   r   )r?   r   patherrrw   excpcommandis_images           r   r   zApplication._get_valid_filez  s     
T%%% 	
$%+#""4(5 +5#6-(C
<:
! 
 	
AGnnT[[$/G
%&0
0C

C:
	s   A 	B9AB44B9)T))__name__
__module____qualname__r   r   r)   r>   r   r   r   r(   r3   rC   r   r5   r6   r^   ro   rp   r_   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   rq   rr   r   r   r]   r   r   ry   r   __classcell__)rA   s   @r   r   r       s    
(+J)
?@"<:(Oh4E
")(&)0++'%26: ?A >Ir   r   )r   gir`   require_versiongi.repositoryr   r   r   r   windowr	   preferencesr
   utilities_filesr   r   r    r   r   <module>r     sW   $     5%     < ' - -  & 5v#// vr   