ó «‡Uc@sñdZddlZddlZejdƒddlZddlZejjejje ƒdƒZ ejje dƒZ ejje dƒZ ejje dƒZ d„Zd „Zd ejfd „ƒYZd „Zed kríeƒndS(sÿImages GtkImage is used to display an image; the image can be in a number of formats. Typically, you load an image into a GdkPixbuf, then display the pixbuf. This demo code shows some of the more obscure cases, in the simple case a call to gtk_image_new_from_file() is all you need. If you want to put image data in your program as a C variable, use the make-inline-pixbuf program that comes with GTK+. This way you won't need to depend on loading external files, your application binary can be self-contained.iÿÿÿÿNs2.0timagess alphatest.pngsgtk-logo-rgb.gifsfloppybuddy.gifcCs*|jƒ}|jdƒ|j|ƒdS(Ni(t get_pixbuftfilltset_from_pixbuf(tloadertimagetpixbuf((s$/usr/lib/pygtk27/2.0/demos/images.pytprogressive_prepared_callbacks  cCs|jƒdS(sŠ We know the pixbuf inside the GtkImage has changed, but the image itself doesn't know this; so queue a redraw. If we wanted to be really efficient, we could use a drawing area or something instead of a GtkImage, so we could control the exact position of the pixbuf on the display, then we could queue a draw for only the updated area of the image. N(t queue_draw(RtxtytwidththeightR((s$/usr/lib/pygtk27/2.0/demos/images.pytprogressive_updated_callback#st ImagesDemocBsJeZdZdZdZdd„Zd„Zd„Zd„Z d„Z RS(c Cs{tjj|ƒy|j|jƒƒWn$tk rM|jdd„ƒnX|jd|jƒ|j|j j ƒ|j dƒtj t dƒ}|j dƒ|j|ƒtjƒ}|jdƒ|j|t t dƒtjƒ}|jtjƒtjddddƒ}|j|ƒ|j|t t dƒtjƒ}y#tjjtƒ}|j|ƒWn[tjk r¿}tj|tjtjtj d|ƒ} | jdd „ƒ| j!ƒnX|j|ƒtjƒ}|jd ƒ|j|t t dƒtjƒ}|jtjƒtjddddƒ}|j|ƒ|j|t t dƒtjƒ}|j"t#ƒ|j|ƒtjƒ}|jd ƒ|j|t t dƒtjƒ}|jtjƒtjddddƒ}|j|ƒ|j|t t dƒtjƒ}|jdƒ|j|ƒ|j%|ƒtj&d ƒ} |j| t t dƒ| jd |j'|ƒ|j(ƒdS(NtdestroycWs tjƒS(N(tgtkt main_quit(tw((s$/usr/lib/pygtk27/2.0/demos/images.pyt7sisImage loaded from a fileigà?s1Unable to open image file 'gtk-logo-rgb.gif': %stresponsecSs |jƒS(N(R(tdlgtresp((s$/usr/lib/pygtk27/2.0/demos/images.pyRbss#Animation loaded from a files Progressive image loadingt _Insensitivettoggled()RtWindowt__init__t set_screent get_screentAttributeErrortconnecttcleanup_callbackt set_titlet __class__t__name__tset_border_widthtVBoxtFalsetaddtLabelt set_markupt pack_starttFrametset_shadow_typet SHADOW_INt AlignmenttImagetgdktpixbuf_new_from_filet GTKLOGO_IMAGERtgobjecttGErrort MessageDialogtDIALOG_DESTROY_WITH_PARENTt MESSAGE_ERRORt BUTTONS_CLOSEtshowt set_from_filet BUDDY_IMAGEtNonetstart_progressive_loadingt ToggleButtonton_sensitivity_toggledtshow_all( tselftparenttvboxtlabeltframetalignRRterrortdialogtbutton((s$/usr/lib/pygtk27/2.0/demos/images.pyR2sv                           cCs|jdkr+tj|jƒd|_n|jdk rS|jjƒd|_n|jdk r{|jjƒd|_ndS(Ni(t load_timeoutRttimeout_removet pixbuf_loaderR;tcloset image_stream(R@twin((s$/usr/lib/pygtk27/2.0/demos/images.pyRžs    cCsP|jƒ}x=|D]5}t|ƒt|ƒkr|j|jƒ ƒqqWdS(N(t get_childrenttypet set_sensitivet get_active(R@t togglebuttont containertchildrentchild((s$/usr/lib/pygtk27/2.0/demos/images.pyR>¬s  cCstjd|j|ƒ|_dS(s„ This is obviously totally contrived(we slow down loading on purpose to show how incremental loading works). The real purpose of incremental loading is the case where you are reading data from a slow source such as the network. The timeout simply simulates a slow data source by inserting pauses in the reading process. i–N(Rt timeout_addtprogressive_timeoutRI(R@R((s$/usr/lib/pygtk27/2.0/demos/images.pyR<µscCs§|jdk r¼y"|jjdƒ}t|ƒ}Wnxtk r«}tj|tjtjtj d|ƒ}|j dd„ƒ|jj ƒd|_|j ƒd|_ tSX|jj||ƒs%tj|tjtjtj dƒ}|j dd„ƒ|jj ƒd|_|j ƒd|_ tS|dkr£|jj ƒd|_|jj ƒs­tj|tjtjtj dƒ}|j dd„ƒ|j ƒd|_d|_ tSd|_q£nçyttd ƒ|_Wnhtk r<}d }tj|tjtjtj ||ƒ}|j dd „ƒ|j ƒd|_ tSX|jdk re|jj ƒd|_ntjjƒ|_|jj d t|ƒ|jj d t|ƒtS(Nis.Failure reading image file 'alphatest.png': %sRcSs |jƒS(N(R(tdtr((s$/usr/lib/pygtk27/2.0/demos/images.pyRÑsisFailed to load imagecSs |jƒS(N(R(RYRZ((s$/usr/lib/pygtk27/2.0/demos/images.pyRäscSs |jƒS(N(R(RYRZ((s$/usr/lib/pygtk27/2.0/demos/images.pyRstrbs.Unable to open image file 'alphatest.png' : %scSs |jƒS(N(R(RYRZ((s$/usr/lib/pygtk27/2.0/demos/images.pyRst area_preparedt area_updated(RMR;treadtlentIOErrorRR4R5R6R7RRLR8RIR%RKtwritetopent ALPHA_IMAGER/t PixbufLoaderRR tTrue(R@Rtbuft bytes_readRFRGt error_message((s$/usr/lib/pygtk27/2.0/demos/images.pyRX¿s‚                              N( R"t __module__R;RKRIRMRRR>R<RX(((s$/usr/lib/pygtk27/2.0/demos/images.pyR-s l  cCstƒtjƒdS(N(RRtmain(((s$/usr/lib/pygtk27/2.0/demos/images.pyRj0st__main__(t__doc__tostpygtktrequireR2Rtpathtjointdirnamet__file__tIMAGEDIRRcR1R:RR RRRjR"(((s$/usr/lib/pygtk27/2.0/demos/images.pyt s      ! ÿ