ó ur™Vc@sýdZddlZddlZddlZddlmZddlmZmZm Z ddl j Z ddl m Z m Z ddlmZddlmZmZmZddlmZmZdd lmZd efd „ƒYZd efd „ƒYZdS(s; Support for building and utilizing an editable text field iÿÿÿÿN(tTextbox(tisprinttctrltismeta(t_tLOG_LEVEL_INPUT(t UIMessage(t charwidtht rjust_columnst textwidth(tconsume_actiont no_action(t ScrollWindowt EditFieldc Bs1eZdZedƒZedƒZeedƒƒZeedƒƒZeedƒƒZ eedƒƒZ dde ddddddde d„ Z ed „ƒZd „Zd „Zed „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(sEditFields represent editable text areas on the screen At any time, the text of the object can be accessed by referencing an EditField's 'text' parameter (edit_field.text). Note that this returns a list of character codes. To get a string, see EditField.get_text() t*tsBB                       cCs|jS(s\Returns True if the text in this field has been modified since the field was created(R(R:((s edit_field.pytmodified¨scCst|_|j|ƒdS(sqSet the text of this EditField to text. Processes each character individually; thus emulating a user typing in the text. This means that each substring of text that start at text[0] must be valid in the context of any validation function this EditField has. If numeric_pad is set, pad text with it if field isn't blank. N(R.RR8(R:R1((s edit_field.pytset_text®s cCsV|jdk rR|jjd}|rR|j|jƒ}t|||jƒ}qRn|S(s!Apply the numeric padding to textiN(RR#R;tcolumnstlstripR(R:R1twidth((s edit_field.pyt_do_padºs cCs­|r|j|ƒ}n|dkr-d}n|jƒtjjtdt|ƒ|jj |ƒt|ƒ|jj }|dkr”|j d|ƒnxt |ƒD]ú\}}|dkrÛ||krÛ|j j tjƒn°|jrú|j j |jƒn‘tjj|ƒru|j jjƒ\}}|j jj||tt|ƒƒjtjƒƒƒ|j jj||dƒn|j j t|ƒƒ|jj|ƒq¡W|j ƒdS(sVUsed internally to bypass the the public interface's numeric_pad functionalityus+_set_text textwidth=%s, columns=%s, text=%sitscroll_to_columniN(!RBR#t _reset_textt terminaluitLOGGERtlogRR R;R?tscrollt enumerateR-t do_commandR t LARROW_CHARR*R,R3tasciiRtwintgetyxtaddstrtunichrtordtencodetlocaletgetpreferredencodingtmoveR1tappendt no_ut_refresh(R:R1tdo_padt length_difftidxtchartytx((s edit_field.pyR8Ãs0      "cCs;|jdk r|jjƒn|j|ƒ}|j|ƒrM||_tjSd|_t|ƒrÎ|j j t |ƒƒ|j ƒs­t |j ƒdkr©|j jƒndSt|_|jr7|j}q7nit|ƒr­|tjkr­|j s tjjdƒdkr%|jjtdƒƒdStj|ƒ|jjƒ}|j j t |ƒƒ|j ƒsŒt |j ƒdkrˆ|j jƒndSt|_|jr7|j}q7nŠ|tjkr7t |j ƒdkr*|j jƒ}t|_t |ƒ}t!|j"ƒƒ|j#j$kr*|j%d| ƒq*n|j ƒn|S(s´ For each keystroke, determine if it's a special character (and needs to end editing), printable character, or backspace. For special characters, send the return the done-editing code (CTRL-G), and store the special character for processing by parent window objects. If printable, append it to self.text, and try to validate. If validation fails, reject the character. it LC_MESSAGEStCs Unicode characters not supportedR?N(&R"R#t clear_errttranslate_inputtis_special_charR0R t CMD_DONE_EDITRR1RVRPtis_validtlentpopR.RR*R,RR3tKEY_MINRtostenvirontgett display_errRtungetchRtget_wcht KEY_BACKSPACERR tget_textR;R?RH(R:R0tdel_chart del_width((s edit_field.pyt handle_inputäsP              cCsRd}xE|tjkrM|j|jƒƒ}|j|jƒƒtjƒq WdS(s_Loop for handling characters in an edit field. Called by EditField.process(). N( R#R RcRrtgetchR8RoR3tdoupdate(R:R0((s edit_field.pyt edit_loop-s cCsytjdƒWn$tjk r7tjjdƒnX|dk rü|j|ƒ rütj|ƒ|j dk r˜|j |j ƒj |j ƒdt ƒn|jr®|jƒn|jjtjƒ|jƒ|j}|j dk r|j |j ƒƒqn|}tjjd|ƒ|S(sjProcess a keystroke. For an EditField, this means preparing the textpad for processing and passing the input_key in. Try to enable the blinking cursor (if it was disabled) before editing begins, so the user can see where they're typing. Once finished, restore the cursor state to its previous condition. After editing, return self.input_key, which will either be None (indicating all keystrokes were processed by the Textbox) or a special character (such as F2) which caused EditField.handle_input to stop processing text through the Textbox. is%Got curses.error when enabling cursorRXs Returning: %sN(R3tcurs_setterrorRERFtdebugR#RbRlRR8RoR@RR9t clear_textR-RJR t CMD_MV_EOLRuR0(R:R0t return_key((s edit_field.pytprocess8s&      cCsdj|jƒS(s0Join the array of characters as a unicode stringu(tjoinR1(R:((s edit_field.pyRo`scCs6|ttjtjƒks*||jkr.tStSdS(s•Check to see if this is a keystroke that should break us out of adding input to the Textbox and return control to the parent window N(trangeR3tKEY_F0tKEY_F10R2R.R(R:R0((s edit_field.pyRbdscCs|jjƒd}t|jƒj|jƒƒ|krk|jdk rg|jjt dƒ|dƒnt St |j ƒrÓy|j ||j WqÓtk rÏ}|jdk rË|jjt|ƒƒnt SXn|jdk rþ|jjrþ|jjƒntS(sÛCheck to see if the text we have is valid or not. First check the length to make sure it fits in the space alloted. If it doesn't, flag an error indicating the maximum supported length for the field. Then, if this EditField has a validate function, call it (passing in any validate_kwargs we have). If validate raises an exception, display the error (if we have a handle to an ErrorWindow) and return False. isMax supported field length: %sN(RtgetmaxyxReRoR@RR"R#RkRRtcallableR RRtunicodetvisibleR`R.(R:t win_size_xt error_str((s edit_field.pyRdos $cCs›t|jƒr—yF|j||j|jdk rP|jjrP|jjƒntSWq—tk r“}|jdk r|jj t |ƒƒnt SXntS(sˆFire the on_exit function, if there is one. If an error occurs, and this EditField has an error_win, display it there. N( R‚R!RR"R#R„R`R.RRkRƒR(R:R†((s edit_field.pyt run_on_exitscCsOtt|ƒjƒytjdƒWn$tjk rJtjjdƒnXdS(s,Enable the cursor when activating this fieldis%Got curses.error when enabling cursorN( R(R t make_activeR3RvRwRERFRx(R:((s edit_field.pyRˆžs cCsY|jƒytjdƒWn$tjk rAtjjdƒnXtt|ƒj ƒdS(s\Fire the on_exit function before leaving the field and making it inactive. is&Got curses.error when reverting cursorN( R‡R3RvRwRERFRxR(R t make_inactive(R:((s edit_field.pyR‰¦s  cCs=|jjtjƒ|jjtjƒg|_|jƒdS(s¬Resets the text area, either to permanently remove the text, or as part of the process of redrawing with additional text (during self._set_text()) N(R-RJR t CMD_MV_BOLt CMD_CLR_LINER1RW(R:((s edit_field.pyRD²s cCs't|_|jddƒ|jƒdS(sƒIssue the commands to textbox to clear itself, reset self.text to an empty array, and reset horizontal scrolling. RCiN(R.RRHRD(R:((s edit_field.pyRy¿s cCsX|jjƒ}|d}|jsJ|tt|jƒƒ|jjƒ7}n|d|fS(s:Cursor should be positioned at the end of the entered textii(RtgetbegyxR9tminR RoR;R?(R:twin_loctx_loc((s edit_field.pytget_cursor_locÈs   (N( t__name__t __module__t__doc__RQR+RKRRcRŠRzR‹R#RR)tpropertyR=R>RBR.R8RrRuR|RoRbRdR‡RˆR‰RDRyR(((s edit_field.pyR ,s6     g ! I (     t PasswordFieldcBseeZdZed„Zd„Zed„ƒZejd„ƒZed„ƒZ e jd„ƒZ RS(sField for editing passwords. One may not set the masked or clear_on_enter attributes of a PasswordField - they are always True cKsE|rd|j}nd}tt|ƒj|dtd||dS(sCAn EditField designed for password editing. A PasswordField cannot be initialized with text; instead, one can indicate whether the field should 'appear' to be filled out or not. Retrieving the value of a PasswordField is only valuable when PasswordField.modified is True. RRR*R1N(R?R(R•R)R.(R:R;tfillR<R1((s edit_field.pyR)Ùs cCsjt|tƒs(tdt|ƒƒ‚n|jrY|jrf|jƒ|jƒkrftSn |jsftStS(sUCompares the status of this PasswordField to another. Returns True if: * Neither field is modified, or * Both fields are modified, and their text values are the same Note that a return value of True doesn't guarantee that the text is equal for a given context. (For example, comparing an unmodified root password to an unmodified user password returns True, even though it's unlikely the values are actually identical). Thus, this is not a true equality comparison (and not defined as the __eq__ function) s'Cannot compare with object of type '%s'(t isinstanceR•t TypeErrorttypeR=RoR.R(R:tother((s edit_field.pytcompareës ! cCstS(sAlways true for password fields(R.(R:((s edit_field.pyR9 scCsdS(sclear_on_enter cannot be setN((R:tvalue((s edit_field.pyR9scCstS(sAlways true for password fields(R.(R:((s edit_field.pyR*scCsdS(smasked cannot be setN((R:Rœ((s edit_field.pyR*s( R‘R’R“RR)R›R”R9tsetterR*(((s edit_field.pyR•Ñs  (R“R3RSRhtcurses.textpadRt curses.asciiRRRtsolaris_install.terminaluiRERRt&solaris_install.terminalui.base_screenRtsolaris_install.terminalui.i18nRRR t'solaris_install.terminalui.inner_windowR R t(solaris_install.terminalui.scroll_windowR R R•(((s edit_field.pyts   ÿ¦