grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a BjŒjºAã@sbddlmZmZddlmZmZdd„ZGdd„deƒZGdd„deƒZ d d „Z e d kr^e ƒd S) é)ÚdivisionÚprint_function)ÚPYTHON3Úxrangecs‡fdd„}|S)Ncs"ˆ|g|¢Ri|¤Ž}| ¡|S©N©Ú _modified)ÚselfÚargsÚkwargsÚrval©Úfn©ú:/usr/lib64/python3.9/site-packages/urwid/monitored_list.pyÚcall_modified_wrappersz-_call_modified..call_modified_wrapperr)rrrr rÚ_call_modifieds rc@sÚeZdZdZdd„Zdd„Zdd„Zeej ƒZ eej ƒZ e sFeej ƒZ eej ƒZ eejƒZeejƒZeejƒZe s|eejƒZeejƒZeejƒZeejƒZeejƒZeejƒZeejƒZeejƒZeedƒrÖeejƒZd S) Ú MonitoredListz… This class can trigger a callback any time its contents are changed with the usual list operations append, extend, etc. cCsdSrr©r rrrr&szMonitoredList._modifiedcCs ||_dS)a; Assign a callback function with no parameters that is called any time the list is modified. Callback's return value is ignored. >>> import sys >>> ml = MonitoredList([1,2,3]) >>> ml.set_modified_callback(lambda: sys.stdout.write("modified\n")) >>> ml MonitoredList([1, 2, 3]) >>> ml.append(10) modified >>> len(ml) 4 >>> ml += [11, 12, 13] modified >>> ml[:] = ml[:2] + ml[-2:] modified >>> ml MonitoredList([1, 2, 12, 13]) Nr©r ÚcallbackrrrÚset_modified_callback)sz#MonitoredList.set_modified_callbackcCsd|jjt|ƒfS)Nz%s(%r))Ú __class__Ú__name__ÚlistrrrrÚ__repr__@szMonitoredList.__repr__ÚclearN)rÚ __module__Ú __qualname__Ú__doc__rrrrrÚ__add__Ú __delitem__rÚ __delslice__Ú__iadd__Ú__imul__Ú__rmul__Ú __setitem__Ú __setslice__ÚappendÚextendÚinsertÚpopÚremoveÚreverseÚsortÚhasattrrrrrrr!s.                rcseZdZdZ‡fdd„Zdd„Zdd„Zdd „Zeeed d �Z d d „Z dd„Z dd„Z dd„Z d3dd„Z‡fdd„Z‡fdd„Zes”dd„Zdd„Z‡fdd „Z‡fd!d"„Z‡fd#d$„Z‡fd%d&„Zd4‡fd(d)„ Z‡fd*d+„Z‡fd,d-„Z‡fd.d/„Zeed0ƒ�r‡fd1d2„Z‡ZS)5ÚMonitoredFocusListzž This class can trigger a callback any time its contents are modified, before and/or after modification, and any time the focus index is changed. cs6| dd¡}tt|ƒj|i|¤Ž||_dd„|_dS)a� This is a list that tracks one item as the focus item. If items are inserted or removed it will update the focus. >>> ml = MonitoredFocusList([10, 11, 12, 13, 14], focus=3) >>> ml MonitoredFocusList([10, 11, 12, 13, 14], focus=3) >>> del(ml[1]) >>> ml MonitoredFocusList([10, 12, 13, 14], focus=2) >>> ml[:2] = [50, 51, 52, 53] >>> ml MonitoredFocusList([50, 51, 52, 53, 13, 14], focus=4) >>> ml[4] = 99 >>> ml MonitoredFocusList([50, 51, 52, 53, 99, 14], focus=4) >>> ml[:] = [] >>> ml MonitoredFocusList([], focus=None) ÚfocusrcSsdSrr)ÚmlÚindicesÚ new_itemsrrrÚwóz-MonitoredFocusList.__init__..N)r+Úsuperr0Ú__init__Ú_focusZ_focus_modified)r ZarglZargdr1©rrrr8]s zMonitoredFocusList.__init__cCsd|jjt|ƒ|jfS)Nz%s(%r, focus=%r))rrrr1rrrrrysÿzMonitoredFocusList.__repr__cCs|sdS|jS)zÖ Return the index of the item "in focus" or None if the list is empty. >>> MonitoredFocusList([1,2,3], focus=2)._get_focus() 2 >>> MonitoredFocusList()._get_focus() N)r9rrrrÚ _get_focus}s zMonitoredFocusList._get_focuscCsp|sd|_dS|dks"|t|ƒkr0td|fƒ‚|t|ƒkrJtd|fƒ‚t|ƒ}||jkrf| |¡||_dS)aÿ index -- index into this list, any index out of range will raise an IndexError, except when the list is empty and the index passed is ignored. This function may call self._focus_changed when the focus is modified, passing the new focus position to the callback just before changing the old focus setting. That method may be overridden on the instance with set_focus_changed_callback(). >>> ml = MonitoredFocusList([9, 10, 11]) >>> ml._set_focus(2); ml._get_focus() 2 >>> ml._set_focus(0); ml._get_focus() 0 >>> ml._set_focus(-2) Traceback (most recent call last): ... IndexError: focus index is out of range: -2 rNzfocus index is out of range: %szinvalid focus index: %s)r9ÚlenÚ IndexErrorÚintÚ_focus_changed)r ÚindexrrrÚ _set_focusŠs   zMonitoredFocusList._set_focuszÈ Get/set the focus index. This value is read as None when the list is empty, and may only be set to a value between 0 and len(self)-1 or an IndexError will be raised. )ÚdoccCsdSrr)r Z new_focusrrrr?²sz!MonitoredFocusList._focus_changedcCs ||_dS)a  Assign a callback to be called when the focus index changes for any reason. The callback is in the form: callback(new_focus) new_focus -- new focus index >>> import sys >>> ml = MonitoredFocusList([1,2,3], focus=1) >>> ml.set_focus_changed_callback(lambda f: sys.stdout.write("focus: %d\n" % (f,))) >>> ml MonitoredFocusList([1, 2, 3], focus=1) >>> ml.append(10) >>> ml.insert(1, 11) focus: 2 >>> ml MonitoredFocusList([1, 11, 2, 3, 10], focus=2) >>> del ml[:2] focus: 0 >>> ml[:0] = [12, 13, 14] focus: 3 >>> ml.focus = 5 focus: 5 >>> ml MonitoredFocusList([12, 13, 14, 2, 3, 10], focus=5) N)r?rrrrÚset_focus_changed_callbackµsz-MonitoredFocusList.set_focus_changed_callbackcCsdSrr)r r3r4rrrÚ_validate_contents_modifiedÒsz.MonitoredFocusList._validate_contents_modifiedcCs ||_dS)až Assign a callback function to handle validating changes to the list. This may raise an exception if the change should not be performed. It may also return an integer position to be the new focus after the list is modified, or None to use the default behaviour. The callback is in the form: callback(indices, new_items) indices -- a (start, stop, step) tuple whose range covers the items being modified new_items -- an iterable of items replacing those at range(*indices), empty if items are being removed, if step==1 this list may contain any number of items N)rDrrrrÚset_validate_contents_modifiedÕsz1MonitoredFocusList.set_validate_contents_modifiedrc Csät|ƒ}| t|ƒ¡\}}}}ttt|Žƒƒ}| ||¡} | durH| S|j} |dkr�||| krn|krvnn|} || krÊ| |||7} n:|sÊ| t|||ƒvr¬| d7} | ttt|t| |ƒ|ƒƒƒ8} t| t|ƒ||dƒS)a Default behaviour is to move the focus to the item following any removed items, unless that item was simply replaced. Failing that choose the last item in the list. returns focus position for after change is applied Né)r<r3rrrDr9Úmin) r Zslcr4Z num_new_itemsÚstartÚstopÚstepr3Z num_removedr1rrrÚ"_adjust_focus_on_contents_modifiedçs"  z5MonitoredFocusList._adjust_focus_on_contents_modifiedcsLt|tƒr| |¡}n| t||dp(dƒ¡}tt|ƒ |¡}| |¡|S)a¤ >>> ml = MonitoredFocusList([0,1,2,3,4], focus=2) >>> del ml[3]; ml MonitoredFocusList([0, 1, 2, 4], focus=2) >>> del ml[-1]; ml MonitoredFocusList([0, 1, 2], focus=2) >>> del ml[0]; ml MonitoredFocusList([1, 2], focus=1) >>> del ml[1]; ml MonitoredFocusList([1], focus=0) >>> del ml[0]; ml MonitoredFocusList([], focus=None) >>> ml = MonitoredFocusList([5,4,6,4,5,4,6,4,5], focus=4) >>> del ml[1::2]; ml MonitoredFocusList([5, 6, 5, 6, 5], focus=2) >>> del ml[::2]; ml MonitoredFocusList([6, 6], focus=1) >>> ml = MonitoredFocusList([0,1,2,3,4,6,7], focus=2) >>> del ml[-2:]; ml MonitoredFocusList([0, 1, 2, 3, 4], focus=2) >>> del ml[-4:-2]; ml MonitoredFocusList([0, 3, 4], focus=1) >>> del ml[:]; ml MonitoredFocusList([], focus=None) rFN)Ú isinstanceÚslicerKr7r0r!rA)r Úyr1r r:rrr! s   ÿ zMonitoredFocusList.__delitem__csTt|tƒr| ||¡}n| t||dp*dƒ|g¡}tt|ƒ ||¡}| |¡|S)aj >>> def modified(indices, new_items): ... print("range%r <- %r" % (indices, new_items)) >>> ml = MonitoredFocusList([0,1,2,3], focus=2) >>> ml.set_validate_contents_modified(modified) >>> ml[0] = 9 range(0, 1, 1) <- [9] >>> ml[2] = 6 range(2, 3, 1) <- [6] >>> ml.focus 2 >>> ml[-1] = 8 range(3, 4, 1) <- [8] >>> ml MonitoredFocusList([9, 1, 6, 8], focus=2) >>> ml[1::2] = [12, 13] range(1, 4, 2) <- [12, 13] >>> ml[::2] = [10, 11] range(0, 4, 2) <- [10, 11] >>> ml[-3:-1] = [21, 22, 23] range(1, 3, 1) <- [21, 22, 23] >>> ml MonitoredFocusList([10, 21, 22, 23, 13], focus=2) >>> ml[:] = [] range(0, 5, 1) <- [] >>> ml MonitoredFocusList([], focus=None) rFN)rLrMrKr7r0r&rA)r ÚirNr1r r:rrr&0s   zMonitoredFocusList.__setitem__cCs| t||ƒ¡Sr)r!rM)r rOÚjrrrr"VszMonitoredFocusList.__delslice__cCs| t||ƒ|¡Sr)r&rM)r rOrPrNrrrr'YszMonitoredFocusList.__setslice__csb|dkr0| tt|ƒt|ƒƒt|ƒ|d¡}n| tdt|ƒƒ¡}tt|ƒ |¡}| |¡|S)aÔ >>> def modified(indices, new_items): ... print("range%r <- %r" % (indices, list(new_items))) >>> ml = MonitoredFocusList([0,1,2], focus=2) >>> ml.set_validate_contents_modified(modified) >>> ml *= 3 range(3, 3, 1) <- [0, 1, 2, 0, 1, 2] >>> ml MonitoredFocusList([0, 1, 2, 0, 1, 2, 0, 1, 2], focus=2) >>> ml *= 0 range(0, 9, 1) <- [] >>> print(ml.focus) None rrF)rKrMr<rr7r0r$rA)r Únr1r r:rrr$\sÿ zMonitoredFocusList.__imul__cs:| tt|ƒt|ƒƒ|g¡}tt|ƒ |¡}| |¡|S)a >>> def modified(indices, new_items): ... print("range%r <- %r" % (indices, new_items)) >>> ml = MonitoredFocusList([0,1,2], focus=2) >>> ml.set_validate_contents_modified(modified) >>> ml.append(6) range(3, 3, 1) <- [6] )rKrMr<r7r0r(rA)r Úitemr1r r:rrr(ts ÿ zMonitoredFocusList.appendcs8| tt|ƒt|ƒƒ|¡}tt|ƒ |¡}| |¡|S)a, >>> def modified(indices, new_items): ... print("range%r <- %r" % (indices, list(new_items))) >>> ml = MonitoredFocusList([0,1,2], focus=2) >>> ml.set_validate_contents_modified(modified) >>> ml.extend((6,7,8)) range(3, 3, 1) <- [6, 7, 8] )rKrMr<r7r0r)rA)r Úitemsr1r r:rrr)ƒs ÿ zMonitoredFocusList.extendcs4| t||ƒ|g¡}tt|ƒ ||¡}| |¡|S)aS >>> ml = MonitoredFocusList([0,1,2,3], focus=2) >>> ml.insert(-1, -1); ml MonitoredFocusList([0, 1, 2, -1, 3], focus=2) >>> ml.insert(0, -2); ml MonitoredFocusList([-2, 0, 1, 2, -1, 3], focus=3) >>> ml.insert(3, -3); ml MonitoredFocusList([-2, 0, 1, -3, 2, -1, 3], focus=4) )rKrMr7r0r*rA)r r@rRr1r r:rrr*’s ÿ zMonitoredFocusList.insertéÿÿÿÿcs6| t||dpdƒ¡}tt|ƒ |¡}| |¡|S)a� >>> ml = MonitoredFocusList([-2,0,1,-3,2,3], focus=4) >>> ml.pop(3); ml -3 MonitoredFocusList([-2, 0, 1, 2, 3], focus=3) >>> ml.pop(0); ml -2 MonitoredFocusList([0, 1, 2, 3], focus=2) >>> ml.pop(-1); ml 3 MonitoredFocusList([0, 1, 2], focus=2) >>> ml.pop(2); ml 2 MonitoredFocusList([0, 1], focus=1) rFN)rKrMr7r0r+rA)r r@r1r r:rrr+¢s  ÿ zMonitoredFocusList.popcs@| |¡}| t||dpdƒ¡}tt|ƒ |¡}| |¡|S)aF >>> ml = MonitoredFocusList([-2,0,1,-3,2,-1,3], focus=4) >>> ml.remove(-3); ml MonitoredFocusList([-2, 0, 1, 2, -1, 3], focus=3) >>> ml.remove(-2); ml MonitoredFocusList([0, 1, 2, -1, 3], focus=2) >>> ml.remove(3); ml MonitoredFocusList([0, 1, 2, -1], focus=2) rFN)r@rKrMr7r0r,rA)r Úvaluer@r1r r:rrr,¸s  ÿ zMonitoredFocusList.removecs0tt|ƒ ¡}| tdt|ƒ|jdƒ¡|S)z• >>> ml = MonitoredFocusList([0,1,2,3,4], focus=1) >>> ml.reverse(); ml MonitoredFocusList([4, 3, 2, 1, 0], focus=3) rrF)r7r0r-rAÚmaxr<r9)r r r:rrr-ÉszMonitoredFocusList.reversec s<|sdS||j}tt|ƒjfi|¤Ž}| | |¡¡|S)z¢ >>> ml = MonitoredFocusList([-2,0,1,-3,2,-1,3], focus=4) >>> ml.sort(); ml MonitoredFocusList([-3, -2, -1, 0, 1, 2, 3], focus=5) N)r9r7r0r.rAr@)r r rUr r:rrr.Ós  zMonitoredFocusList.sortrcs,| tddƒ¡}tt|ƒ ¡}| |¡|S©Nr)rKrMr7r0rrA)r r1r r:rrrás zMonitoredFocusList.clear)r)rT) rrrrr8rr;rAÚpropertyr1r?rCrDrErKr!r&rr"r'r$r(r)r*r+r,r-r.r/rrÚ __classcell__rrr:rr0Xs4  " & # %      r0cCsddl}| ¡dSrW)ÚdoctestZtestmod)rZrrrÚ_testësr[Ú__main__N) Z __future__rrZ urwid.compatrrrrrr0r[rrrrrÚs7