Uc@sdZddlZddlZddlZejdddlZddlZdZdZdZ ej j ej j e ddZej j ej j e ddZd ejfd YZd Zed krendS( sText Widget/TextView The GtkTextView widget displays a GtkTextBuffer. One GtkTextBuffer can be displayed by multiple GtkTextViews. This demo has two views displaying a single buffer, and shows off the widget's text formatting features.iNs2.0istimagessgtk-logo-rgb.gifsfloppybuddy.gift TextViewDemocBsJeZddZdZdZdZdZdZdZ RS(cCstjj|y|j|jWn$tk rM|jddnX|j|jj |j dd|j dtj }|j d|j |tj}|j}tj|}tj}|jtj|jtjtj|j||j |tj}|jtj|jtjtj|j||j ||j||j||j||j|d|_|jdS(NtdestroycWs tjS(N(tgtkt main_quit(tw((s&/usr/lib/pygtk27/2.0/demos/textview.pyt siii(RtWindowt__init__t set_screent get_screentAttributeErrortconnectt set_titlet __class__t__name__tset_default_sizetset_border_widthtVPanedtaddtTextViewt get_buffertScrolledWindowtset_shadow_typetSHADOW_ETCHED_INt set_policytPOLICY_AUTOMATICtadd1tadd2t create_tagst insert_texttattach_widgetstNonetwintshow_all(tselftparenttvpanedtview1tbuffer_1tview2tsw((s&/usr/lib/pygtk27/2.0/demos/textview.pyRs<                  c Csddl}|jdd|jdd|j|jdd|j|jd d|j|jd dd |j|jd d |j|jdd |j|jddd|jddd|jdddtjj dt t t }|jdd||jdd||jddd|jddd|jddd |jd!d"t|jd#d$tj|jd%d$tj|jd&d$tj|jd'd(tj|jd)d(tj|jd*d+d,d-d,|jd.d.t|jd/d/|j|jd0d/|j|jd1d2d |jdd3|j|jd4d2d5|jdd3|j|jd6d$tjd7tjd8dd+d d-d dS(9s Create a bunch of tags. Note that it's also possible to create tags with gtk.text_tag_new() then add them to the tag table for the buffer, text_buffer.create_tag() is just a convenience function. Also note that you don't have to give tags a name; pass None for the name to create an anonymous tag. In any real app, another useful optimization would be to create a GtkTextTagTable in advance, and reuse the same tag table for all the buffers with the same tag set, instead of creating new copies of the same tags for every buffer. Tags are assigned default priorities in order of addition to the tag table. That is, tags created later that affect the same text property affected by an earlier tag will override the earlier tag. You can modify tag priorities with gtk.text_tag_set_priority(). iNtheadingtweighttsizeititalictstyletboldtbigisxx-smalltscalesx-larget monospacetfamilytblue_foregroundt foregroundtbluetred_backgroundt backgroundtredtbackground_stippletforeground_stippletbig_gap_before_linetpixels_above_linesitbig_gap_after_linetpixels_below_linestdouble_spaced_linetpixels_inside_wrapi t not_editableteditablet word_wrapt wrap_modet char_wraptno_wraptcentert justificationt right_justifyt wide_marginst left_margini2t right_margint strikethrought underlinetdouble_underlinet superscripttriseit subscriptit rtl_quotet directiontindent(tpangot create_tagt WEIGHT_BOLDtSCALEt STYLE_ITALICtSCALE_XX_SMALLt SCALE_X_LARGERtgdktbitmap_create_from_dataR t gray50_bitst gray50_widtht gray50_heighttFalset WRAP_WORDt WRAP_CHARt WRAP_NONEtJUSTIFY_CENTERt JUSTIFY_RIGHTtTruetUNDERLINE_SINGLEtUNDERLINE_DOUBLEt TEXT_DIR_RTL(R#t text_bufferRWtstipple((s&/usr/lib/pygtk27/2.0/demos/textview.pyRKsR               c Csytjjt}Wn#tjk r;}tjdnX|jddd}|}|j d}|j |d|j |dd|j |d|j |d d |j |d |j |d d |j |d d |j |dd|j |d |j |dd|j |d|j |d|j |dd|j |d|j |dd|j |d|j |dd|j |d|j |dd|j |d|j |dd|j |dd |j |ddd|j |dd |j |d ddd!|j |d"d |j |d#d|j |d$d%|j |d d |j |d&d&|j |d d |j |d'd(|j |d d |j |d)d)|j |d*d |j |d+d+|j |d,d |j |d-d|j |d.d |j |||j |||j |||j |d/d |j |d0d|j |d1d |j |d2d3d4|j |d5d6d4|j |d7d8d4|j |d9d |j |d:d|j |d;d<|j |d=d|j |d>d |j |d?d@|j |dAdB|j |dCd|j |dDdE|j |dFdG|j |dHd4|j |dId|j |dJd |j |dKd |j |dLdM|j |dNd |j |}|j |dOd |j |}|j |dPd |j |}|j |dQd |j |}|j |dRd |j |}|j |dSd |j |dTd |j\}}|jdU||dS(VNs+Failed to load image file gtk-logo-rgb.gif i tbilinearisThe text widget can display text with all kinds of nifty attributes. It also supports multiple views of the same buffer; this demo is showing the same buffer in two places. s Font styles. R*sFor example, you can have R-s, R/s, or ismonospace(typewriter)R2R0s text. s_It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as sxx-smalls or sx-largesY to ensure that your program properly adapts if the user changes the default font size. sColors. sColors such as sa blue foregroundR4sa red backgroundR7s or even sa stippled red backgroundR:s2a stippled blue foreground on solid red backgroundR;s'(select that to read it) can be used. s$Underline, strikethrough, and rise. t StrikethroughRNROsdouble underlineRPRQs, and RSs are all supported. sImages. s"The buffer can have images in it: s for example. s Spacing. s5You can adjust the amount of space before each line. s.This line has a whole lot of space before it. R<RKsfYou can also adjust the amount of space after each line; this line has a whole lot of space after it. R>sYou can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah. R@s5Also note that those lines have extra-wide margins. s Editability. sgThis line is 'locked down' and can't be edited by the user - just try it! You can't delete this line. RBs Wrapping. s>This line(and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah sThis line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah RFsVThis line has all wrapping turned off, so it makes the horizontal scrollbar appear. RGsJustification. s% This line has center justification. RHs#This line has right justification. RJs This line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text. sInternationalization. s[You can put all sorts of Unicode text in the buffer. German(Deutsch Süd) Grüß Gott Greek(Ελληνικά) Γειά σας Hebrew שלום Japanese(日本語) The widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework. s9Here's a word-wrapped quote in a right-to-left language: sوقد بدأ ثلاث من أكثر المؤسسات تقدما في شبكة اكسيون برامجها كمنظمات لا تسعى للربح، ثم تحولت في السنوات الخمس الماضية إلى مؤسسات مالية منظمة، وباتت جزءا من النظام المالي في بلدانها، ولكنها تتخصص في خدمة قطاع المشروعات الصغيرة. وأحد أكثر هذه المؤسسات نجاحا هو »بانكوسول« في بوليفيا. RTs4You can put widgets in the buffer: Here's a button: s and a menu: s and a scale: s and an animation: s finally a text entry: s. s This demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text(doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such...RD(RR^tpixbuf_new_from_filet GTKLOGO_IMAGEtgobjecttGErrortsystexitt scale_simpletget_iter_at_offsettinserttinsert_with_tags_by_namet insert_pixbuftcreate_child_anchort get_boundstapply_tag_by_name( R#Rmtpixbufterrortscaledtitertanchortstarttend((s&/usr/lib/pygtk27/2.0/demos/textview.pyRs                                                  "  cCs_|j}|j}d}x:|j|rZ|j}|dkrmtjd}|jd|jn|dkrtj}|j d|j d|j dn|dkrtj }|j dd |j d d nI|d krtj }|jtn!|d kr-tj}nt|j|||j|d7}q!WdS(NisClick MetclickedisOption 1sOption 2sOption 3iidiFiii(Rtget_start_itert find_anchortget_child_anchorRtButtonR teaster_egg_callbacktcombo_box_new_textt append_texttHScalet set_rangetset_size_requesttImaget set_from_filetFLOPPYBUDDY_IMAGEtEntryt ValueErrortadd_child_at_anchorR"(R#t text_viewtbufferRtiRtwidget((s&/usr/lib/pygtk27/2.0/demos/textview.pyRs6              cCs'x |jr"|jrtSqWtS(N(t forward_charRRiRc(R#R((s&/usr/lib/pygtk27/2.0/demos/textview.pyRs cCs|jr|jjdStj}|j}|j|d|j|}|j|dtj|}|jd||tj |_tj }|j tj tj |jj ||j ||jjdd|jjdS(NsCThis buffer is shared by a set of nested text views. Nested view: s- Don't do this in real applications, please. ii,i(R!tpresentRt TextBufferRRyR|Rtrecursive_attach_viewRRRRRRR"(R#tbuttonRRRtviewR)((s&/usr/lib/pygtk27/2.0/demos/textview.pyRs(         cCs|dkrdStj|j}tj}tjjd}|jtj|tjdddd}|j d|j ||j ||j |||j |d||dS(Nitblackg?g?i( RRRtEventBoxR^t color_parset modify_bgt STATE_NORMALt AlignmentRRRR(R#tdepthRRt child_viewt event_boxtcolortalign((s&/usr/lib/pygtk27/2.0/demos/textview.pyRs     N( Rt __module__R RRRRRRR(((s&/usr/lib/pygtk27/2.0/demos/textview.pyRs 1 [   cCsttjdS(N(RRtmain(((s&/usr/lib/pygtk27/2.0/demos/textview.pyRst__main__(t__doc__tosRutpygtktrequireRsRRaRbR`tpathtjointdirnamet__file__RrRRRRR(((s&/usr/lib/pygtk27/2.0/demos/textview.pyts$