5!gȷ"dZdZdZgdZddlZddlmZmZmZmZdBdZ dCdZ d Z dBd Z dBd Z dDd Zd ZdZdZdZdZdZdZdZdEdZGddeZGddej4ZGddeZGddeZGddeej:ZGd d!eZGd"d#eZGd$d%eZ Gd&d'eZ!e!Z"Gd(d)eZ#Gd*d+eZ$Gd,d-eejJZ&e&Z%Gd.d/eZ'Gd0d1eZ(Gd2d3eejRZ)Gd4d5eejTZ*Gd6d7eZ+Gd8d9eZ,Gd:d;eZ-Gd<d=eej\ej^Z0Gd>d?eZ1Gd@dAe#Z2y)FaTtk wrapper. This module provides classes to allow using Tk themed widget set. Ttk is based on a revised and enhanced version of TIP #48 (http://tip.tcl.tk/48) specified style engine. Its basic idea is to separate, to the extent possible, the code implementing a widget's behavior from the code implementing its appearance. Widget class bindings are primarily responsible for maintaining the widget state and invoking callbacks, all aspects of the widgets appearance lies at Themes. z0.3.1z!Guilherme Polo )Button CheckbuttonComboboxEntryFrameLabel Labelframe LabelFrame MenubuttonNotebook Panedwindow PanedWindow Progressbar RadiobuttonScale Scrollbar SeparatorSizegripSpinboxStyleTreeview LabeledScale OptionMenu tclobjs_to_py setup_masterN)_flatten_join _stringify _splitdictcf|r t|}|St|ttfr t |}|S)zInternal function.)r isinstancelisttupler)valuescripts 2/opt/alt/python312/lib64/python3.12/tkinter/ttk.py_format_optvaluer' s6 5! L ED%= )e  Lcg}|jD]>\}}|r||vs |jd|z|$|jt||@t|S)zFormats optdict to a tuple to pass it to tk.call. E.g. (script=False): {'foreground': 'blue', 'padding': [1, 2, 3, 4]} returns: ('-foreground', 'blue', '-padding', '1 2 3 4')-%s)itemsappendr'r)optdictr%ignoreoptsoptr$s r&_format_optdictr1*s] Dmmo UF* KK $  ,UF;< & D>r(cg}|D]S^}}t|dk(r |dxsd}ndj|}|j||C|j|U|S)Nr )lenjoinr,)r+opt_valstatevals r&_mapdict_valuesr;:sdG  u:?!HNEHHUOEu ? NN3  Nr(c g}|jD].\}}|jd|ztt||f0t |S)zFormats mapdict to pass it to tk.call. E.g. (script=False): {'expand': [('active', 'selected', 'grey'), ('focus', [1, 2, 3, 4])]} returns: ('-expand', '{active selected} grey focus {1, 2, 3, 4}')r*)r+extendr'r;r)mapdictr%r/r0r$s r&_format_mapdictr?OsQ Dmmo U US[%oe&r(cXd}d}|dvr_|dk(r$|d}tt|dd}|d|}n)|dd\}} tt|dd} |d| d| }t||}n(|d k(r#|d}t|dkDrt |d|f}|rd |z}dj |}||fS) zAFormats args and kw according to the given element factory etype.N)imagevsapirBrr3r5fromz{%s})rr;r1r6r'r7) etyper%argskwspecr/iname imagespec class_namepart_idstatemaps r&_format_elemcreaterO`s D D "" G GEod12h78I#Y/D#'r( J_T!"X67H!+Wh?Dr6* &Aw t9q=$T!Wf57D }xx~ :r(cg}|D]}|\}}|xsi}djt|dd}d|z||rd|znd}d|vrZ|j|dz||z }t|d||\} }|j| ||z}|jdd|zz|j|d j||fS) a$Formats a layout list so we can pass the result to ttk::style layout and ttk::style settings. Note that the layout doesn't have to be a list necessarily. E.g.: [("Menubutton.background", None), ("Menubutton.button", {"children": [("Menubutton.focus", {"children": [("Menubutton.padding", {"children": [("Menubutton.label", {"side": "left", "expand": 1})] })] })] }), ("Menubutton.indicator", {"side": "right"}) ] returns: Menubutton.background Menubutton.button -children { Menubutton.focus -children { Menubutton.padding -children { Menubutton.label -side left -expand 1 } } } Menubutton.indicator -side rightr5T)childrenz %sr4rQz -children {z%s} )r7r1r,_format_layoutlist) layoutindent indent_sizer% layout_elemelemr/foptshead newscripts r&rSrSs8F  dzrt]CD<% R/OP   MM$/ 0 k !F 24 3CV! Iv MM) $ k !F MM%3<0 1 MM$ " 99V f $$r(c <g}|jD]v\}}|jdr6djt|dd}|j d|d|d|jdr6djt |dd}|j d|d|dd|vr1|dsd }nt |d\}}|j d |d |d |jd s|d }|d}d}|t|kr2t||ds#|dz }|t|krt||ds#|d|} |t|kr ||r||ni} t|dg| i| \} }|j d|d|d| d|ydj|S)zReturns an appropriate script, based on settings, according to theme_settings definition to be used by theme_settings and theme_create. configurer5Tzttk::style configure ;mapzttk::style map rTnullzttk::style layout z { z }zelement createrr3r+zttk::style element create rR) r+getr7r1r,r?rSr6hasattrrO) settingsr%namer/s_eoptsrFargcelemargselemkwrIs r&_script_from_settingsrksFnn& d 88K k):DABA MM4C D 88E?ed; t >)$x.91 MMT1E F 88$ %)*E!HEDU#GE$K,I U#GE$K,IQt}H$(3u:$5%+U4[2F+E4M(MfMJD$ MMeT4) *='B 99V r(ct|tr|Sg}t|}t||D]\}}t |drt|j }n:t|tr|j }nt|t tfs|f}t |dr t|}|jg|||S)ztConstruct a list from the given statespec tuple according to the accepted statespec accepted by _format_mapdict.typename) r!striterziprbsplitr#r"r,)stupleresultitr9r:s r&_list_from_statespecrus&# F fB"bk s 5* %J$$&E s #KKMEEE4=1HE 3 #c(C mmsm$" Mr(c\|j|}g}d}|t|kr||}i}|j||f|dz }|t|krL|||dz\}}|jdsn/|dd}|dz }|dk(r t ||}|||<|t|krL|t|kr|S)zpConstruct a list from the tuple returned by ttk::layout, this is somewhat the reverse of _format_layoutlist.rr3rD-NrQ) splitlistr6r, startswith_list_from_layouttuple)tkltupleresindxrdr/r0r:s r&rzrzs\\& !F C D V d| D$<   S[ d4!8,HC>>#&ab'C AIDj ,R5DIS[ V & Jr(ct|}|j||z}t|dzr|St||tS)ahFormat options then call Tk command with args and options and return the appropriate result. If no option is specified, a dict is returned. If an option is specified with the None value, the value for that option is returned. Otherwise, the function just sets the passed options and the caller shouldn't be expecting a return value anyway.rD)conv)r1callr6r _tclobj_to_py)r{optionsrGr}s r& _val_or_dictrsBg&G "''D7N $C 7|a b#M 22r(c`t|} t|}|S#ttf$rY|SwxYw)zAConverts a value to, hopefully, a more appropriate Python object.)rnint ValueError TypeError)r$s r&_convert_stringvalr s> JE E  L  "  L s --c^t|trd|vr t|}|St|}|S)N.)r!rnfloatr)xs r& _to_numberr*s3!S !8aA HAA Hr(c|rWt|drKt|ts;t|ddddk(r t |}|St t t|}|St|dr t|}|S)z8Return value converted from Tcl object to Python object.__len__rrmN StateSpec)rbr!rngetattrrur"r_r)r:s r&rr2ss wsI&z#s/C 3q6:t , ;&s+C J s-s34C J j ! % Jr(cR|jD]\}}t|||<|S)zOReturns adict with its values converted from Tcl objects to Python objects.)r+r)adictr0r:s r&rr?s-KKMS"3'c " Lr(c2|tj}|S)aIf master is not None, itself is returned. If master is None, the default master is returned if there is one, otherwise a new master is created and returned. If it is not allowed to use the default root and master is None, RuntimeError is raised.)tkinter_get_default_root)masters r&rrGs~**, Mr(cjeZdZdZdZddZddZddZddZddZ d Z d Z d Z dd Z d ZdZddZy)rzManipulate style database.z ttk::styleNc^t|}||_|jj|_yN)rrr{)selfrs r&__init__zStyle.__init__Xs"f% ++..r(c d|d||<t|j||jd|}|s|r|Sy)zQuery or sets the default value of the specified option(s) in style. Each key in kw is an option and each value is either a string or a sequence identifying the value for that option.Nr])rr{_name)rstyle query_optrHrss r&r]zStyle.configure^s<   ByMdggr4::{EJ YMr(c |O|jj|jd|d|z}t|jj |S|jj|jd|gt |}t |j|jDcic]*\}}|t|jj |,c}}Scc}}w)aSQuery or sets dynamic values of the specified option(s) in style. Each key in kw is an option and each value should be a list or a tuple (usually) containing statespecs grouped in tuples, or list, or something else of your preference. A statespec is compound of one or more states and then a value.r_r*)r{rrrurxr?rr+)rrrrHrskvs r&r_z Style.mapks  WW\\$**eUEI >r(ct|dg|i|\}}|jj|jdd|||g|y)z9Create a new element in the current theme of given etype.FelementcreateN)rOr{rr)r elementnamerFrGrHrIr/s r&element_createzStyle.element_createsG'uBtBrB d TZZHk5   r(c td|jj|jj|jddDS)z:Returns the list of elements defined in the current theme.c3>K|]}|jdywrwNlstrip).0ns r& z&Style.element_names..s!;-:qQXXc]-:rnamesr#r{rxrrrs r& element_nameszStyle.element_namessB;DGG,=,= GGLLY 8-:;; ;r(c td|jj|jj|jdd|DS)z)Return the list of elementname's options.c3>K|]}|jdywrr)ros r&rz(Style.element_options..s$J-IqQXXc]-Irrrr)rrs r&element_optionszStyle.element_optionssIJDGG,=,= GGLLY ; G-IJJ Jr(c |r t|nd}|r-|jj|jdd|d|d|y|jj|jdd|d|y)a.Creates a new theme. It is an error if themename already exists. If parent is specified, the new theme will inherit styles, elements and layouts from the specified parent theme. If settings are present, they are expected to have the same syntax used for theme_settings.r4themerz-parentz -settingsNrkr{rr)r themenameparentrcr%s r& theme_createzStyle.theme_creates^5=&x0"  GGLLWh 6; 8 GGLLWh V %r(clt|}|jj|jdd||y)aTemporarily sets the current theme to themename, apply specified settings and then restore the previous theme. Each key in settings is a style and each value may contain the keys 'configure', 'map', 'layout' and 'element create' and they are expected to have the same format as specified by the methods configure, map, layout and element_create respectively.rrcNr)rrrcr%s r&theme_settingszStyle.theme_settingss*'x0  TZZ*iHr(c|jj|jj|jddS)z#Returns a list of all known themes.rr)r{rxrrrs r& theme_nameszStyle.theme_namess,ww  djj'7!KLLr(cv||jjdS|jjd|y)zIf themename is None, returns the theme in use, otherwise, set the current theme to themename, refreshes all widgets and emits a <> event.Nzreturn $ttk::currentThemez ttk::setTheme)r{evalr)rrs r& theme_usezStyle.theme_uses4  77<< ;< <  _i0r(rNN)__name__ __module__ __qualname____doc__rrr]r_rrTrrrrrrrrAr(r&rrSsK$ E! A" (>V; J %" IM 1r(rc.eZdZdZddZdZddZddZy)Widgetz!Base class for Tk themed widgets.Nc`t|}tjj||||y)aConstructs a Ttk Widget with the parent master. STANDARD OPTIONS class, cursor, takefocus, style SCROLLABLE WIDGET OPTIONS xscrollcommand, yscrollcommand LABEL WIDGET OPTIONS text, textvariable, underline, image, compound, width WIDGET STATES active, disabled, focus, pressed, selected, background, readonly, alternate, invalid )rHN)rrrr)rr widgetnamerHs r&rzWidget.__init__s)(f%fjR@r(cR|jj|jd||S)zReturns the name of the element at position x, y, or the empty string if the point does not lie within any element. x and y are pixel coordinates relative to the widget.identifyr{r_wrrys r&rzWidget.identifys! ww||DGGZA66r(c |jj|jj|jddj |}|r |||i|S|S)a1Test the widget's state. If callback is not specified, returns True if the widget state matches statespec and False otherwise. If callback is specified, then it will be invoked with *args, **kw if the widget state matches statespec. statespec is expected to be a sequence.instater5)r{ getbooleanrrr7)r statespeccallbackrGrHrets r&rzWidget.instatesWgg   TWWi)1DEG 8'T(R( ( r(c |dj|}|jjt|jj |j d|S)aModify or inquire widget state. Widget state is returned if statespec is None, otherwise it is set according to the statespec flags and then a new state spec is returned indicating which flags were changed. statespec is expected to be a sequence.r5r9)r7r{rxrnrr)rrs r&r9z Widget.state)sG  +Iww  TWW\\$''7I%N!OPPr(r)rrrrrrrr9rAr(r&rrs+A07  Qr(rceZdZdZddZdZy)rzcTtk Button widget, displays a textual label and/or image, and evaluates a command when pressed.Nc 4tj||d|y)aConstruct a Ttk Button widget with the parent master. STANDARD OPTIONS class, compound, cursor, image, state, style, takefocus, text, textvariable, underline, width WIDGET-SPECIFIC OPTIONS command, default, width z ttk::buttonNrrrrrHs r&rzButton.__init__:s fmR8r(cN|jj|jdS)z/Invokes the command associated with the button.invokerrs r&rz Button.invokeIsww||DGGX..r(rrrrrrrrAr(r&rr6s) 9/r(rceZdZdZddZdZy)rz;Ttk Checkbutton widget which is either in on- or off-state.Nc 4tj||d|y)a'Construct a Ttk Checkbutton widget with the parent master. STANDARD OPTIONS class, compound, cursor, image, state, style, takefocus, text, textvariable, underline, width WIDGET-SPECIFIC OPTIONS command, offvalue, onvalue, variable zttk::checkbuttonNrrs r&rzCheckbutton.__init__Q f&8"=r(cN|jj|jdS)aWToggles between the selected and deselected states and invokes the associated command. If the widget is currently selected, sets the option variable to the offvalue option and deselects the widget; otherwise, sets the option variable to the option onvalue. Returns the result of the associated command.rrrs r&rzCheckbutton.invoke`sww||DGGX..r(rrrAr(r&rrNsE >/r(rc*eZdZdZddZdZdZdZy)rzeTtk Entry widget displays a one-line text string and allows that string to be edited by the user.Nc <tj|||xsd|y)aConstructs a Ttk Entry widget with the parent master. STANDARD OPTIONS class, cursor, style, takefocus, xscrollcommand WIDGET-SPECIFIC OPTIONS exportselection, invalidcommand, justify, show, state, textvariable, validate, validatecommand, width VALIDATION MODES none, key, focus, focusin, focusout, all z ttk::entryNr)rrwidgetrHs r&rzEntry.__init__os ff&< bAr(cn|j|jj|jd|S)zqReturn a tuple of (x, y, width, height) which describes the bounding box of the character given by index.bbox_getintsr{rr)rindexs r&rz Entry.bboxs(}}TWW\\$''65ABBr(cR|jj|jd||S)zxReturns the name of the element at position x, y, or the empty string if the coordinates are outside the window.rrrs r&rzEntry.identify!ww||DGGZA66r(c|jj|jj|jdS)zForce revalidation, independent of the conditions specified by the validate option. Returns False if validation fails, True if it succeeds. Sets or clears the invalid state accordingly.validater{rrrrs r&rzEntry.validates,ww!!$'',,tww "CDDr(r)rrrrrrrrrAr(r&rrks(B&C 7 Er(rc&eZdZdZddZddZdZy)rzMTtk Combobox widget combines a text field with a pop-down list of values.Nc 4tj||dfi|y)aConstruct a Ttk Combobox widget with the parent master. STANDARD OPTIONS class, cursor, style, takefocus WIDGET-SPECIFIC OPTIONS exportselection, justify, height, postcommand, state, textvariable, values, width z ttk::comboboxNrrrs r&rzCombobox.__init__s tV_;;r(c|G|jj|jd}|dk(ry|jj|S|jj|jd|S)aIf newindex is supplied, sets the combobox value to the element at position newindex in the list of values. Otherwise, returns the index of the current value in the list of values or -1 if the current value does not appear in the list.currentr4)r{rrgetint)rnewindexr}s r&rzCombobox.currentsZ  '',,tww 2Cby77>>#& &ww||DGGY99r(cR|jj|jd|y)z(Sets the value of the combobox to value.setNrrr$s r&rz Combobox.set  TWWeU+r(r)rrrrrrrrAr(r&rrs < :,r(rceZdZdZddZy)rzJTtk Frame widget is a container, used to group other widgets together.Nc 4tj||d|y)zConstruct a Ttk Frame with parent master. STANDARD OPTIONS class, cursor, style, takefocus WIDGET-SPECIFIC OPTIONS borderwidth, relief, padding, width, height z ttk::frameNrrs r&rzFrame.__init__ flB7r(rrrrrrrAr(r&rrs  8r(rceZdZdZddZy)rz7Ttk Label widget displays a textual label and/or image.Nc 4tj||d|y)aGConstruct a Ttk Label with parent master. STANDARD OPTIONS class, compound, cursor, image, style, takefocus, text, textvariable, underline, width WIDGET-SPECIFIC OPTIONS anchor, background, font, foreground, justify, padding, relief, text, wraplength z ttk::labelNrrs r&rzLabel.__init__s flB7r(rr rAr(r&rrs A 8r(rceZdZdZddZy)rzTtk Labelframe widget is a container used to group other widgets together. It has an optional label, which may be a plain text string or another widget.Nc 4tj||d|y)zConstruct a Ttk Labelframe with parent master. STANDARD OPTIONS class, cursor, style, takefocus WIDGET-SPECIFIC OPTIONS labelanchor, text, underline, padding, labelwidget, width, height zttk::labelframeNrrs r&rzLabelframe.__init__s f&7