B @r. @sdZddlTddlZdZdZdZdZdZd d Zd d Z d dZ ddZ ddZ ddZ ddZGdddZGdddeZGdddZGdddZdS)azStrip viewer and related widgets. The classes in this file implement the StripViewer shown in the top two thirds of the main Pynche window. It consists of three StripWidgets which display the variations in red, green, and blue respectively of the currently selected r/g/b color value. Each StripWidget shows the color variations that are reachable by varying an axis of the currently selected color. So for example, if the color is (R,G,B)=(127,163,196) then the Red variations show colors from (0,163,196) to (255,163,196), the Green variations show colors from (127,0,196) to (127,255,196), and the Blue variations show colors from (127,163,0) to (127,163,255). The selected color is always visible in all three StripWidgets, and in fact each StripWidget highlights the selected color, and has an arrow pointing to the selected chip, which includes the value along that particular axis. Clicking on any chip in any StripWidget selects that color, and updates all arrows and other windows. By toggling on Update while dragging, Pynche will select the color under the cursor while you drag it, but be forewarned that this can be slow. )*Nzproc setcolor {canv colors} { set i 1 foreach c $colors { $canv itemconfigure $i -fill $c -outline $c incr i } }  cCsDd|d}d}g}x*|dkr>|t|||}|d}qW|S)Ngo@gr)appendint)numchipsstepstartseqr=/opt/alt/python37/lib64/python3.7/Tools/pynche/StripViewer.pyconstant4s   rcCst|}tt|g|||S)N)rlistzip)r redgreenbluer rrrconstant_red_generator?srcCst|}tt||g||S)N)rrr)r rrrr rrrconstant_green_generatorDsrcCst|}tt|||g|S)N)rrr)r rrrr rrrconstant_blue_generatorIsrcCs$t|}tt||g||g|S)N)rrr)r rrrr rrrconstant_cyan_generatorNsrcCs$t|}tt|g|||g|S)N)rrr)r rrrr rrrconstant_magenta_generatorSsrcCs$t|}tt|g||g||S)N)rrr)r rrrr rrrconstant_yellow_generatorXsrc@sHeZdZdZdZdZdZdZddZdd Z d d Z d d Z ddZ dS) LeftArrow r)Z leftarrowcCs&||_||\|_|_||dS)N)_canvas_createZ_LeftArrow__arrow_LeftArrow__textmove_to)selfcanvasxrrr__init__eszLeftArrow.__init__c Csb|jj||j|j||j||j|jdd|jd }|jj||jd|j|j|jdd}||fS)Nfirstg@)arrowwidthtagsr128)r+text)r create_line _ARROWHEIGHT_YOFFSET _ARROWWIDTH_TAG create_text _TEXTYOFFSET)r$r&r)r-rrrr!js     zLeftArrow._createcCs"t|j|j}|st|dS)Nr)rr coordsr2AssertionError)r$r5rrr_xysz LeftArrow._xcCs"||}|j|j|ddS)Nr)r7r Zmover2)r$r&Zdeltaxrrrr#~s zLeftArrow.move_tocCs|jj|j|ddS)N)r-)r itemconfigurer")r$r-rrrset_textszLeftArrow.set_textN) __name__ __module__ __qualname__r1r/r0r4r2r'r!r7r#r9rrrrr^src@s eZdZdZddZddZdS) RightArrow)Z rightarrowc Csj|jj||j||j|j||j|j|jdd|jd }|jj||jd|j|jtd|jd}||fS)NZlastg@)r)r*r+rr,)Zjustifyr-r+) r r.r0r1r/r2r3r4ZRIGHT)r$r&r)r-rrrr!s     zRightArrow._createcCs(t|j|j}|st|d|jS)Nr)rr r5r2r6r1)r$r5rrrr7sz RightArrow._xN)r:r;r<r2r!r7rrrrr=sr=c @s^eZdZdZdZdZdeeedddddf ddZdd Zdd d Zd d Z ddZ ddZ dS) StripWidget2 (Nc  CsV||_||_||_|jdks t| |_| |_d|_||_||d} |d} t|| | d} |_ | | d|j | d|j | d|j | j tg}|_d}d}d }xLt|jD]>}d }| j|||||||||d ||d}||qW| jd ||d |td|_|d}t| ||_|t|d}t| ||_dS)N)rrr+)r*Zheightzzz r)chipZgrey)filloutliner+)r-Zanchorr)_StripWidget__generator_StripWidget__axis_StripWidget__numchipsr6_StripWidget__uwd_StripWidget__hexp_StripWidget__lastchip_StripWidget__sbZCanvas_StripWidget__canvaspackZbind_StripWidget__select_chiptkevalTCLPROC_StripWidget__chipsrangeZcreate_rectanglerr3W_StripWidget__label_StripWidget__arrow_xr_StripWidget__leftarrowlenr=_StripWidget__rightarrow)r$ switchboardmasterZ chipwidthZ chipheightr generatoraxislabeluwdvarhexvarZ canvaswidthZ canvasheightr%chipsr&yr+ccolorZchipxrrrr'sL         zStripWidget.__init__cCs0|j|d}|st|\}}}}||dS)Nrg@)rQr5r6)r$Zchipnumr5Zx0Zy0Zx1Zy1rrrZ __arrow_xs zStripWidget.__arrow_xc Cs|j}|j}|j}|||||}|rd|dkr@|jkrnnf|j|dd}t|\}}} t|j } | t ks|j r|j ||| n||d||| fdS)Nrr)r&rgrQZfind_overlappingrLrWColorDBZrrggbb_to_tripletr typeBTNUPrMgetrP update_views_StripWidget__trackarrow) r$eventr&rgr%rErirrretyperrrZ __select_chips" zStripWidget.__select_chipcCs|jdk r,|j|jd}|jj|j|d||_||j}|jrPt|}nt|}|dkr|j ||j | |d|j dn.|j ||j | |d|j dt|}|dkrd}nd}|jj||ddS)NrF)rGriZwhiteZblack)rOrQZitemcgetr8rKrNrmhexreprr\r9r#r[r^rjZtriplet_to_brightness)r$rEZrgbtupleriZ coloraxisr-Z brightnessrGrrrZ __trackarrows(        zStripWidget.__trackarrowcCs|js td}d}g}|_|jj}x\||j|||D]F}t|} || |\} } } | |krv| |krv| |krv|}|d}q8Wt |} | d|jj | f| ||||fdS)Nrrzsetcolor %s {%s})rJr6rWrQrTrLrjZtriplet_to_rrggbbrSPACEjoinrUZ_wro)r$rrrirErfrTtZrrggbbZtredZtgreenZtblueZcolorsrrrupdate_yourself#s       zStripWidget.update_yourselfcCs|jj|j|d||_dS)N)r-)rQr8rZrJ)r$rcrarrrset7szStripWidget.set)N) r:r;r<Z _CHIPHEIGHTZ _CHIPWIDTHZ _NUMCHIPSr'r[rSroryrzrrrrr>s" ; "r>c@sDeZdZdddZddZdddZddd Zdd d Zd d ZdS) StripViewerNc Cs||_|}t|tdd}|jdddddt}|_||ddt}|_ ||ddt|}|j t t d t ||tdd ||d |_t ||tdd ||d |_t ||tdd ||d |_t|}|j t t d |jddd|jdddd} t|d|jd} | jdddt| dt|d|d} | jddtdt|d||jd} | jddtdt|d|jd} | jdddt| ddS)Nr)ZreliefZ borderwidthrrCZNSEW)rowcolumnZ columnspansticky UPWHILEDRAGHEXSTRIP)expandrFzRed Variations)rarbrcrdrezGreen VariationszBlue Variations)ZweightrIZBlack)r-command)r|r}Zrowspanr~padxzUpdate while dragging)r-variable)r|r}r~Z Hexadecimal)r-rrZWhite)_StripViewer__sboptiondbZFrameZRAISEDZgridZ BooleanVar_StripViewer__uwdvarrzrm_StripViewer__hexpvarrRZYESZBOTHr>r_StripViewer__redsr_StripViewer__greensr_StripViewer__bluesZcolumnconfigureZButton_StripViewer__toblackrYZ Checkbutton_StripViewer__togglehex_StripViewer__towhiteE)r$r_r`rframeZuwdZhexpZframe1Zframe2rZblackbtnZuwdbtnZhexbtnZwhitebtnrrrr'=s^        zStripViewer.__init__cCs4|j||||j||||j|||dS)N)rryrr)r$rrrrrrryszStripViewer.update_yourselfcCs"|j\}}}||||dS)N)rZ current_rgbry)r$rprrrrrrZ __togglehexszStripViewer.__togglehexcCs|jddddS)Nr)rrn)r$rprrrZ __toblackszStripViewer.__toblackcCs|jddddS)N)rrn)r$rprrrZ __towhiteszStripViewer.__towhitecCs |j|d<|j|d<dS)Nrr)rrmr)r$rrrr save_optionsszStripViewer.save_options)N)N)N)N) r:r;r<r'ryrrrrrrrrr{<s  O   r{)__doc__ZtkinterrjrVZBTNDOWNrlZBTNDRAGrurrrrrrrrr=r>r{rrrrs&  (