o utZ>@sdZddlZddlZddlZddlmZmZddlmZddl m Z m Z ddl Z GdddeZGdd d eZgZeD]Zeejed eejed q|jd|YdSw||vrzz |j|d|_Wn ty[d|_Ynwz |j|d|_WdStyy|jd|YdSwt d |rt |s|jd |dSdS) Nr z#Key 'Name' in Group '%s' is missingr&z&Key 'Comment' in Group '%s' is missingrArBr7z#Key 'Size' in Group '%s' is missing^\[X-Invalid Group name: %s) rSrWrrXrYrUr-r3rematchrr r:rrr checkGrouprs2       zIconTheme.checkGroupcCsd||jkrwtdtjjd|rdStdtjjd|r!dS|dkr/|j||dddS|dkr=|j||dddS|dkrK|j||dddS|d krY|j||d d dS|d kre|||dStd |rmdS|jd|dS|| vr0|dkr|j||dd dS|dkr|||dS|dkr||||dvr|jd|dSdS|dkr|j||dd |j dkr|jd|j dSdS|dkr|j||dd |j dkr|jd|j dSdS|dkr|j||dd |j dkr |jd|j dSdS|dkr|j||dd dStd |r&dS|jd|dSdS)Nz^Name$z^Commentr(Tr)r,r.r0r1r2r5^X-[a-zA-Z0-9-]+Invalid key: %sr7r8r>rA)FixedScalablerBzGKey 'Type' must be one out of 'Fixed','Scalable','Threshold', but is %srGrgz"Key 'MaxSize' give, but Type is %srKz"Key 'MinSize' give, but Type is %srBz$Key 'Threshold' give, but Type is %srO) rSr_r`xdgLocaleregex checkValuerYrUr-r3r keyrDr:rrrcheckKeysb        zIconTheme.checkKeyN)__name__ __module__ __qualname____doc__r rrrr%r'r+r-r/r4r6r=r@rErIrLrNrQr\rbrnrrrrrs. rc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)IconDataz*Class to parse and validate IconData FilescCrr r r rrrr rzIconData.__init__cCs|}|r d|SdS)Nzz )getDisplayName)r displaynamerrrrszIconData.__repr__cCst||dgdS)Nz Icon Data)rr)r rrrrrszIconData.parsecCr)zBRetrieve the display name from the icon data, if one is specified. DisplayNameTr!r#r rrrrtszIconData.getDisplayNamecC|jddddS)zzRetrieve the embedded text rectangle from the icon data as a list of numbers (x0, y0, x1, y1), if it is specified.EmbeddedTextRectangler8Tr3r*r#r rrrgetEmbeddedTextRectanglez!IconData.getEmbeddedTextRectanglecCrw)zRetrieve the anchor points for overlays & emblems from the icon data, as a list of co-ordinate pairs, if they are specified. AttachPointspointTryr#r rrrgetAttachPointsr{zIconData.getAttachPointscCs|jdkr |jddSdS)N.iconrR)rVrTrUr rrrr\s zIconData.checkExtrascCsB||jkstd|rt|s|jd|dddSdSdS)Nr]r^asciireplace)rSr_r`rrYrUencoderarrrrbs  zIconData.checkGroupcCs|tdtjjd|rdS|dkr|j||ddddS|dkr,|j||ddddStd |r4dS|jd |dS) Nz ^DisplayNamercrxr8Tryr|r}rdre)r_r`rhrirjrkrYrUrlrrrrns zIconData.checkKeyN) rorprqrrr rrrtrzr~r\rbrnrrrrrss rsiconspixmapsz~/.icons)pngsvgxpmc CsB|dkrtjj}|dkrtjj}tj|r|Stj|ddd|vr.tj|d}tgks9tdj |kr?t t |a|||t |f}zt |\}}Wn tyXYnwt|tjjkrgt |=n|StD]}t||||}|rt|ft |<|SqktD]8}|tvsttt|dtjjkrt|dtj|krtj|rt|ttj|ft|<qtD]G\} } |D]@} z&|d| | dvrtj| |d| }t|gt |<|WSWqty} z tr|  WYd} ~ qd} ~ wwq|dkrt||d}t|gt |<|SdS)aGet the path to a specified icon. size : Icon size in pixels. Defaults to ``xdg.Config.icon_size``. theme : Icon theme name. Defaults to ``xdg.Config.icon_theme``. If the icon isn't found in the specified theme, it will be looked up in the basic 'hicolor' theme. extensions : List of preferred file extensions. Example:: >>> getIconPath("inkscape", 32) '/usr/share/icons/hicolor/32x32/apps/inkscape.png' NrPrrM.hicolor)rhConfig icon_size icon_themerrisabssplitextthemesrr* __get_themestuple icon_cacherXtime cache_time LookupIconicondirs dir_cacheintgetmtimeisdirlistdiritemsjoinUnicodeDecodeErrorr getIconPath) iconnamesizetheme extensionstmp timestampiconthmer<rvalues extensionerrrrsj       rcCsHtj|r tj|dd}tj|r"t}|||SdSdS)zRetrieve the data from the .icon file corresponding to the given file. If there is no .icon file, it returns None. Example:: getIconData("/usr/share/icons/Tango/scalable/places/folder.svg") rrN)rrisfilerrsr)r icon_filedatarrr getIconDataPs   rccstD]"}tj||d}tj|rntj||d}tj|r%n qtr,t|dSt}|||V| D] }t |D]}|VqCq=dS)zjGenerator yielding IconTheme objects for a specified theme and any themes from which it inherits. z index.themez index.desktopN) rrrrrrrrrr+r) themenamer theme_filersubthemetrrrr_s(     rc Cs"|jtvr+gt|j<t|jttjjdt|jdt|jtttt|jdtjjkrtt|jd<| D]U}t D]P}t j ||j|}|t|jdvstt|jdt j t j ||jkr|dkrt j |r|t |gt|jd|<t j t j ||jt|jd<qMqIt|jdD]*\}}t|d||r|D]}|d||dvrt j ||d|Sqqd} d} t|jdD].\}}t|d||} | | kr|D]}|d||dvr t j ||d|} | } qq| S)NrPrrMrl)r theme_cacherUrrhrrdictrr-rrrrrrrrDirectoryMatchesSizeDirectorySizeDistance) rrrrsubdirr<rrr minimal_sizeclosest_filenamedistancerrrrvsJ   " & "  rcCs||}||}||}||}||}|dkr!||kS|dkr1||ko.|kSS|dkrE|||koB||kSSdS)Nrf ScaleablerB)rEr=rNrLrIriconsizerrAr7rBrKrGrrrrs      rcCs||}||}||}||}||}|dkr#t||S|dkr9||kr/||S||kr7||SdS|dkrS|||krG||S|||krQ||SdSdS)NrfrgrrB)rEr=rNrLrIabsrrrrrs(        r) rrrrr_ xdg.IniFilerrxdg.BaseDirectoryrxdg.Exceptionsrr xdg.ConfigrhrrsrbasedirrUrr expanduserrrrrrrrrrrrrrrs2 -7R'