o
    r3by                     @   s  d Z ddlmZmZmZ ddlZddlZddlZddlmZm	Z	m
Z
mZmZmZmZ dZdZdZdZd	Zd
diZG dd dZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZi d"ej d#ej!d$ej"d%ej#d&ej$d'ej%d(ej&d)ej'd*ej(d+ej)d,ej*d-ej+d.ej,d/ej-d0ej.d1ej/d2ej0ej1ej2e3d3d4Z4e5e46 D ]Z7e7e4e4e7 < qd5d6 ej8ej9 D D ]\Z:Z;e:e4e;< e;e4e:< qG d7d8 d8Z<G d9d: d:Z=i d;ej>d<ej?d=ej@d>ejAd?ejBd@ejCdAejDdBejEdCejFdDejGdEejHdFejIdGejJdHejKdIejLdJejMdKejNejOejPejQejRejSejTdLZUG dMdN dNZVdndPdQZWG dRdS dSeZXG dTdU dUe=ZYG dVdW dWe=ZZG dXdY dYe=Z[G dZd[ d[e[Z\G d\d] d]eZ]	^		dod`daZ^dbdcgd_dddfdddeZ_dfd_dgdbdcgdfdhdiZ`G djdk dke=Zadldm ZbdS )pa  
This module provides the NEWT Windowing toolkit API for Python
This is a lightweight text-mode windowing library, based on slang.

Classes:

 - Widget  
 - Button  
 - CompactButton
 - Checkbox
 - SingleRadioButton
 - Listbox
 - Textbox
 - TextboxReflowed
 - Label
 - Scale
 - Entry
 - Form
 - Grid
 - SnackScreen
 - RadioGroup
 - RadioBar
 - ButtonBar
 - GridFormHelp
 - GridForm
 - CheckboxTree
 - Clistbox

Functions:

 - ListboxChoiceWindow
 - ButtonChoiceWindow
 - EntryWindow
    )absolute_importprint_functionunicode_literalsN)FLAG_DISABLED	FLAGS_SETFLAGS_RESETFLAGS_TOGGLEFD_READFD_WRITE	FD_EXCEPT)r   )r   r   r   r   )   r   )r   r   appendr   c                   @   s"   e Zd ZdZdddZdd ZdS )WidgetzBase class for NEWT toolkit - Do not use directly

    methods:

     - Widget(self)
     - setCallback(self, obj, data = None) : 
          The callback for when object activated.
          data is passed to obj.
    Nc                 C   s&   |r| j || d S | j | d S N)wsetCallback)selfobjdata r   '/usr/lib/python3/dist-packages/snack.pyr   D   s   zWidget.setCallbackc                 C   s   t r   )NotImplementedErrorr   r   r   r   __init__J   s   zWidget.__init__r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   :   s    
	r   c                   @      e Zd ZdZdd ZdS )ButtonzqBasic button class, takes button text as parameter

    method:

     - Button(self, text): returns a button
    c                 C      t || _d S r   )_snackbuttonr   r   textr   r   r   r   T      zButton.__init__Nr   r   r   r   r   r   r   r   r   r!   M       r!   c                   @   r    )CompactButtonzCompact Button class (less frilly button decoration).

    methods:

     - CompactButton(self,text) : create button, with text.
    c                 C   r"   r   )r#   Zcompactbuttonr   r%   r   r   r   r   ^   r'   zCompactButton.__init__Nr(   r   r   r   r   r*   W   r)   r*   c                   @   s:   e Zd ZdZdd Zdd Zdd Zdd	 ZdddZdS )Checkboxa  A checkbox.

    methods:
    
      - Checkbox(self, text, isOn = 0) : text, and boolean as to default value
      - setValue(self)                 : set value
      - value(self, value)             : return checkbox value
      - selected(self)                 : returns boolean
      - setFlags(self, flag, sense)    : set flags

      flags:  FLAG_DISABLED, FLAGS_SET, FLAGS_RESET
    c                 C      | j jS r   r   ZcheckboxValuer   r   r   r   valuen      zCheckbox.valuec                 C   s   | j jdkS Nr   r-   r   r   r   r   selectedq      zCheckbox.selectedc                 C      | j ||S r   )r   ZcheckboxSetFlagsr   flagZsenser   r   r   setFlagst   s   zCheckbox.setFlagsc                 C   s   | j |S r   )r   ZcheckboxSetValue)r   r.   r   r   r   setValuex   r2   zCheckbox.setValuer   c                 C      t ||| _d S r   )r#   Zcheckboxr   )r   r&   isOnr   r   r   r   {      zCheckbox.__init__Nr   )	r   r   r   r   r.   r1   r6   r7   r   r   r   r   r   r+   a   s    r+   c                   @   s"   e Zd ZdZdd ZdddZdS )	SingleRadioButtonzSingle Radio Button.

    methods:
    
     -  SingleRadioButton(text, group, isOn = 0)  : create button
     -  selected(self)                            : returns bool, whether or not is selected.
    c                 C   s   | j j| j jkS r   )r   keyZ
radioValuer   r   r   r   r1      r'   zSingleRadioButton.selectedr   c                 C   s.   |rt ||j|| _d S t |d || _d S r   )r#   Zradiobuttonr   )r   r&   groupr9   r   r   r   r      s   zSingleRadioButton.__init__Nr;   )r   r   r   r   r1   r   r   r   r   r   r<   ~   s    r<   c                   @   sZ   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdddZdS )Listboxa  Listbox class.

    methods:

     - Listbox(self, height, scroll = 0, returnExit = 0, width = 0, showCursor = 0, multiple = 0, border = 0)
     - insert(self, text, item, before) : insert element; before = key to item to insert before, or None.
     - delete(self, item)               : delete item from list.
     - replace(self, text,item)         : Replace a given item's text
     - current(self)                    : returns currently selected item
     - getSelection(self)               : returns a list of selected items
     - setCurrent(self,i tem)           : select current.
     - clear(self)                      : clear listbox
    c                 C   s$   | j |}|| j|< || j|< d S r   )r   ZlistboxAddItemkey2itemitem2keyr   r&   itemr=   r   r   r   r      s   
zListbox.appendc                 C   s@   |s
| j |d}n
| j || j| }|| j|< || j|< d S r0   )r   listboxInsertItemrA   r@   )r   r&   rC   beforer=   r   r   r   insert   s
   
zListbox.insertc                 C   s,   | j | j|  | j| j| = | j|= d S r   )r   listboxDeleteItemrA   r@   r   rC   r   r   r   delete   s   zListbox.deletec                 C   sL   | j || j| }| j | j|  | j| j| = || j|< || j|< d S r   )r   rD   rA   rG   r@   rB   r   r   r   replace   s
   
zListbox.replacec                 C   s   | j | j  S r   )r@   r   ZlistboxGetCurrentr   r   r   r   current   r'   zListbox.currentc                 C   ,   g }| j  }|D ]
}|| j|  q	|S r   )r   ZlistboxGetSelectionr   r@   r   Z	selectionlistr=   r   r   r   getSelection   
   
zListbox.getSelectionc                 C      | j | j|  d S r   )r   ZlistboxSetCurrentrA   rH   r   r   r   
setCurrent      zListbox.setCurrentc                 C   s   i | _ i | _| j  d S r   )r@   rA   r   ZlistboxClearr   r   r   r   clear   s   zListbox.clearr   c                 C   s:   t ||||||| _i | _i | _|r| j| d S d S r   )r#   listboxr   r@   rA   ZlistboxSetWidth)r   heightscroll
returnExitwidthZ
showCursorZmultipleZborderr   r   r   r      s   zListbox.__init__N)r   r   r   r   r   r   )r   r   r   r   r   rF   rI   rJ   rK   rO   rR   rT   r   r   r   r   r   r?      s    r?   c                   @   s*   e Zd ZdZdd Zdd Zd
ddZd	S )Textboxa  Textbox, container for text.

    methods:

     - Textbox(self, width, height, scroll = 0, wrap = 0): scroll, wrap are flags
                                   include scroll bars, or text wrap.
     - setText(text) : set text.
     - setHeight(height): set height.
    c                 C      | j | d S r   )r   ZtextboxTextr%   r   r   r   setText   r'   zTextbox.setTextc                 C   r[   r   )r   ZtextboxHeight)r   rV   r   r   r   	setHeight   r'   zTextbox.setHeightr   c                 C   s   t |||||| _d S r   )r#   Ztextboxr   )r   rY   rV   r&   rW   wrapr   r   r   r         zTextbox.__init__Nr   )r   r   r   r   r\   r]   r   r   r   r   r   rZ      s
    
rZ   c                   @   s   e Zd ZdddZdS )TextboxReflowed   
   r   c                 C   sP   t ||||\}}}|dkr||krt| |||d d S t| |||d d S )Nr   r   r   )reflowrZ   r   )r   rY   r&   flexDownflexUp	maxHeightZnewtextrV   r   r   r   r      s   zTextboxReflowed.__init__N)ra   rb   r   )r   r   r   r   r   r   r   r   r`      s    r`   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	LabelzA Label (simple text).

    methods:

     - Label(self,text)   : create label
     - setText(self,text) : change text.
     - setColors(self, colorset) : change individual colors
    c                 C   r[   r   )r   Z	labelTextr%   r   r   r   r\      r'   zLabel.setTextc                 C   r"   r   )r#   labelr   r%   r   r   r   r      r'   zLabel.__init__c                 C   r[   r   )r   ZlabelSetColors)r   colorsetr   r   r   	setColors   r'   zLabel.setColorsN)r   r   r   r   r\   r   rj   r   r   r   r   rg      s
    rg   c                   @       e Zd ZdZdd Zdd ZdS )ScalezA Scale (progress bar).

    methods:

     - Scale(self,width, total) : create scale; width: size on screen, fullamount: integer.
     - set(self,amount)         : set amount to integer.
    c                 C   r[   r   )r   ZscaleSet)r   amountr   r   r   set  r'   z	Scale.setc                 C   r8   r   )r#   Zscaler   )r   rY   totalr   r   r   r     r:   zScale.__init__N)r   r   r   r   rn   r   r   r   r   r   rl      s    rl   c                   @   s8   e Zd ZdZdd ZdddZdd Z		
dddZdS )Entrya  Entry widget.

    methods:

     - Entry(self, width, text = "", hidden = 0, password = 0, scroll = 1, returnExit = 0)
          constructor. hidden doesn't show text, password stars it out,
          scroll includes scroll bars;
          if returnExit is set, return from Form when exiting this element, else
           proceed to next entry widget.
     - value(self): return value.
     - set(text, cursorAtEnd = 1) : set the text
     - setFlags (flag, sense) : flags can be FLAG_DISABLED, FLAGS_SET, FLAGS_RESET, FLAGS_TOGGLE
    c                 C   r,   r   )r   Z
entryValuer   r   r   r   r.     r/   zEntry.valuer   c                 C   r3   r   )r   ZentrySetValue)r   r&   ZcursorAtEndr   r   r   rn        z	Entry.setc                 C   r3   r   )r   ZentrySetFlagsr4   r   r   r   r6   "  rq   zEntry.setFlags r   c                 C   s   t ||||||| _d S r   )r#   entryr   )r   rY   r&   ZhiddenZpasswordrW   rX   r   r   r   r   %  s   zEntry.__init__Nr   )rr   r   r   r   r   )r   r   r   r   r.   rn   r6   r   r   r   r   r   rp     s    
rp   ZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9ZF10ZF11ZF12ZESCZENTERZSUSPENDZ	BACKSPACEZDELETE )ZINSERTZRESIZEru   c                 C   s   g | ]}t ||fqS r   )ord).0cr   r   r   
<listcomp>7  s    ry   c                   @   sR   e Zd ZdZdd Zdd Zdd Zdd	 ZdddZdd Z	dd Z
dd Zd
S )Forma   Base Form class, from which Grid, etc. inherit

    methods:

     - Form(self, helpArg = None) : constructor. 
     - addHotKey(self, keyname) : keynames of form "F1" through "F12", "ESC"
     - add(self, widget) : Add a widget
     - run(self): run a  form, expecting input
     - draw(self): draw form.
     - setTimer(self, timer) : add a timer
     - watchFile(self, file, flags) : watch a named file
     - setCurrent (self, co): Set a given widget as the current focus
    c                 C   s   | j t|  d S r   )r   Z	addhotkeyhotkeysr   Zkeynamer   r   r   	addHotKeyI  s   zForm.addHotKeyc                 C   sr   d|j v r|j D ]}| | q
d|j v r$|jD ]}| | qd S d|j v r7|| j|jj< | j|jS d S )Nr{   gridmembersr   )	__dict__r{   keysr}   r~   addtransr   r=   )r   widgetr=   r   r   r   r   r   L  s   



zForm.addc                 C   s^   | j  \}}|tjkr| j| S |tjkrdS |tjkr"| j| S |tjkr+t	| S t
d)NZTIMERzEOF or IO error)r   runr#   ZFORM_EXIT_WIDGETr   ZFORM_EXIT_TIMERZFORM_EXIT_FDREADYfilemapZFORM_EXIT_HOTKEYr{   RuntimeError)r   whatwhichr   r   r   r   Y  s   





zForm.runc                 C      | j   d S r   )r   drawr   r   r   r   r   e  s   
z	Form.drawNc                 C   s"   i | _ i | _t|| _|| _d S r   )r   r   r#   formr   helpArg)r   r   r   r   r   r   i  s   
zForm.__init__c                 C   s   | j |j  d S r   )r   Z
setcurrentr   cor   r   r   rR   p  r:   zForm.setCurrentc                 C   r[   r   )r   Zsettimer)r   Ztimerr   r   r   setTimers  r'   zForm.setTimerc                 C   s$   || j | < | j| | d S r   )r   filenor   Zwatchfd)r   fileflagsr   r   r   	watchFilev  s   zForm.watchFiler   )r   r   r   r   r}   r   r   r   r   rR   r   r   r   r   r   r   rz   ;  s    
rz   c                   @   s0   e Zd ZdZdd Z			dddZdd	 Zd
S )Griday  Grid class.

    methods:

     - place(self,x,y): Return what is placed at (x,y)
     - setField(self, what, col, row, padding = (0, 0, 0, 0),
                anchorLeft = 0, anchorTop = 0, anchorRight = 0,
                anchorBottom = 0, growx = 0, growy = 0):
                used to add widget 'what' to grid.
     - Grid(self, *args): eg. g = Grid(2,3) for 2x3 grid
    c                 C   r3   r   )gplacer   xyr   r   r   r     rq   z
Grid.placer   r   r   r   r   c                 C   s   | j | d}|rtj}n|rtj}|r|tjB }n|r"|tjB }d}|	r)tj}|
r0|tjB }d|j	v rA| j
|||j
|||S | j
|||j||S )Nr   r   )r~   r   r#   ZANCHOR_LEFTZANCHOR_RIGHTZ
ANCHOR_TOPZANCHOR_BOTTOMZ
GRID_GROWXZ
GRID_GROWYr   r   Zsetfieldr   )r   r   colrowpadding
anchorLeft	anchorTopanchorRightanchorBottomgrowxgrowyZanchorFlagsZ	gridFlagsr   r   r   setField  s(   


zGrid.setFieldc                 G   s   t j| | _g | _d S r   )r#   gridr   r~   )r   argsr   r   r   r        
zGrid.__init__Nr   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   z  s    
r   ZROOTZBORDERZWINDOWZSHADOWZTITLEZBUTTONZ	ACTBUTTONZCHECKBOXZACTCHECKBOXZENTRYZLABELZLISTBOXZ
ACTLISTBOXZTEXTBOXZ
ACTTEXTBOXZHELPLINEZROOTTEXT)Z
EMPTYSCALEZ	FULLSCALEZDISENTRYZCOMPACTBUTTONZACTSELLISTBOXZ
SELLISTBOXc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	d$ddZ
dd Zdd Zdd Zdd Zdd Zd%ddZd&ddZd d! Zd"d# ZdS )'SnackScreena
  A Screen;

    methods:

    - Screen(self) : constructor
    - finish(self)
    - resume(self)
    - suspend(self)
    - doHelpCallback(self,arg) call callback with arg
    - helpCallback(self,cb): Set help callback
    - suspendcallback(self,cb, data=None) : set callback. data=data to pass to cb.
    - openWindow(self,left, top, width, height, title): Open a window.
    - pushHelpLine(self,text): put help line on screen. Returns current help line if text=None
    - setColor(self, colorset, fg, bg): Set foreground and background colors;
            colorset = key from snack.colorsets,
            fg & bg = english color names defined by S-Lang
                (ref: S-Lang Library C Programmer's Guide section:
                8.4.4.  Setting Character Attributes)
    c                 C   s&   t   t  \| _| _| d  d S r   )r#   ZinitsizerY   rV   pushHelpLiner   r   r   r   r     s   zSnackScreen.__init__c                 C      t  S r   )r#   finishr   r   r   r   r     r/   zSnackScreen.finishc                 C      t   d S r   )r#   resumer   r   r   r   r     r2   zSnackScreen.resumec                 C   r   r   )r#   suspendr   r   r   r   r     r2   zSnackScreen.suspendc                 C   s   |  | | d S r   )helpCb)r   argr   r   r   doHelpCallback  r'   zSnackScreen.doHelpCallbackc                 C   s   || _ t| jS r   )r   r#   Zhelpcallbackr   )r   cbr   r   r   helpCallback  s   zSnackScreen.helpCallbackNc                 C   s   |rt ||S t |S r   )r#   Zsuspendcallback)r   r   r   r   r   r   suspendCallback  s   
zSnackScreen.suspendCallbackc                 C   s   t |||||S r   )r#   Z
openwindow)r   lefttoprY   rV   titler   r   r   
openWindow  r:   zSnackScreen.openWindowc                 C   s   |st dS t |S )Nz	*default*)r#   Zpushhelpliner%   r   r   r   r     s   

zSnackScreen.pushHelpLinec                 C   r   r   )r#   Zpophelpliner   r   r   r   popHelpLine  r/   zSnackScreen.popHelpLinec                 C      t |||S r   )r#   Zdrawroottext)r   r   r   r&   r   r   r   drawRootText  rq   zSnackScreen.drawRootTextc                 C   r   r   )r#   Zcenteredwindow)r   rY   rV   r   r   r   r   centeredWindow  rq   zSnackScreen.centeredWindowc                 C   s(   |r|rt |j|||S t |j|S r   )r#   Zgridwrappedwindowr   )r   r   r   r   r   r   r   r   gridWrappedWindow   s   zSnackScreen.gridWrappedWindowTc                 C   s   |rt  S t  S r   )r#   Z	popwindowZpopwindownorefresh)r   refreshr   r   r   	popWindow  s   zSnackScreen.popWindowc                 C   r   r   )r#   r   r   r   r   r   r     r/   zSnackScreen.refreshc                 C   s(   |t v rtt | ||S t|||S r   )	colorsetsr#   Zsetcolor)r   ri   Zfgbgr   r   r   setColor  s   zSnackScreen.setColorr   NN)T)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s$    


r   ra   c                 C   s   t | |||S )zR returns a tuple of the wrapped text, the actual width, and the actual height
    )r#   rc   )r&   rY   rd   re   r   r   r   rc     s   rc   c                   @   s*   e Zd ZdZdd Zd	ddZdd ZdS )

RadioGroupz Combo widget: Group of Radio buttons

    methods:

     - RadioGroup(self): constructor.
     - add(self,title, value, default = None): add a button. Returns button.
     - getSelection(self) : returns value of selected button | None    
    c                 C   s   d | _ g | _d S r   )prev
buttonlistr   r   r   r   r   %  s   
zRadioGroup.__init__Nc                 C   s:   | j s	|d kr	d}t|| j |}|| _ | j||f |S Nr   )r   r<   r   r   )r   r   r.   defaultbr   r   r   r   )  s   zRadioGroup.addc                 C   s$   | j D ]\}}| r|  S qd S r   )r   r1   )r   r   r.   r   r   r   rO   3  s   zRadioGroup.getSelectionr   )r   r   r   r   r   r   rO   r   r   r   r   r     s
    

r   c                   @   rk   )RadioBarz Bar of Radio buttons, based on Grid.

    methods:

    - RadioBar(self, screen, buttonlist) : constructor.
    - getSelection(self): return value of selected button 
    c                 C   sz   g | _ d| _t | _t| dt| |D ]%\}}}| j|||}| j ||f | j	|d| jdd | jd | _qd S )Nr   r   r   )
rN   rC   r   r>   r   r   lenr   r   r   )r   screenr   r   r.   r   r   r   r   r   r   B  s   zRadioBar.__init__c                 C   
   | j  S r   )r>   rO   r   r   r   r   rO   M     
zRadioBar.getSelectionN)r   r   r   r   r   rO   r   r   r   r   r   9  s    r   c                   @   s"   e Zd ZdZdddZdd ZdS )		ButtonBara   Bar of buttons, based on grid.

    methods:

     - ButtonBar(screen, buttonlist,buttonlist, compact = 0):
     - buttonPressed(self, result):  Takes the widget returned by Form.run and looks to see
                     if it was one of the widgets in the ButtonBar.
    r   c           	      C   s   g | _ i | _d| _t| t|d |D ]L}t|tjdkrt	nt
r)|}| }nt|dkr4|\}}n
|\}}}|| j|< |rEt|}nt|}| j ||f | || jdd | jd | _qd S )Nr   r   3   )r   r   r   r   )rN   r{   rC   r   r   r   
isinstancesysversionstr
basestringlowerr*   r!   r   r   )	r   r   r   compactZblistr   r.   Zhotkeyr   r   r   r   r   \  s&   




zButtonBar.__init__c                 C   s8   || j v r
| j | S | jD ]\}}||kr|  S qd S r   )r{   rN   )r   resultr$   r.   r   r   r   buttonPresseds  s   

zButtonBar.buttonPressedNr;   )r   r   r   r   r   r   r   r   r   r   r   S  s    
r   c                   @   sn   e Zd ZdZdd Z			dddZdd	d
Zdd Zdd ZdddZ	dddZ
dd Zdd Zdd ZdS )GridFormHelpa=   Subclass of Grid, for the help form text.

    methods:

     - GridFormHelp(self, screen, title, help, *args) :
     - add (self, widget, col, row, padding = (0, 0, 0, 0),
            anchorLeft = 0, anchorTop = 0, anchorRight = 0,
            anchorBottom = 0, growx = 0, growy = 0):
     - runOnce(self, x = None, y = None):  pop up the help window
     - addHotKey(self, keyname):
     - setTimer(self, keyname):
     - create(self, x = None, y = None):
     - run(self, x = None, y = None):
     - draw(self):
     - runPopup(self):
     - setCurrent (self, co):
    c                 G   sJ   || _ || _t|| _g | _d| _t|}| g|d d< tjt	|  d S r0   )
r   r   rz   r   	childListform_createdrN   r   r   tuple)r   r   r   helpr   r   r   r   r     s   
zGridFormHelp.__init__r   r   c                 C   s,   |  |||||||||	|

 | j| d S r   )r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s
   zGridFormHelp.addNc                 C   s   |  ||}| j  |S r   )r   r   r   )r   r   r   r   r   r   r   runOnce  s   
zGridFormHelp.runOncec                 C   r[   r   )r   r}   r|   r   r   r   r}     r'   zGridFormHelp.addHotKeyc                 C   r[   r   )r   r   r|   r   r   r   r     r'   zGridFormHelp.setTimerc                 C   sL   | j s$| dd | jD ]}| j| q| j| | j|| d| _ d S d S r   )r   r   r   r   r   r   r   r   )r   r   r   childr   r   r   create  s   

zGridFormHelp.createc                 C   s   |  || | j S r   )r   r   r   r   r   r   r   r     r   zGridFormHelp.runc                 C   s   |    | j S r   )r   r   r   r   r   r   r   r     s   
zGridFormHelp.drawc                 C   s0   |    | j| | j | j }| j  |S r   )r   r   r   r   r   r   r   )r   r   r   r   r   runPopup  s
   

zGridFormHelp.runPopupc                 C   r[   r   )r   rR   r   r   r   r   rR     r'   zGridFormHelp.setCurrentr   r   )r   r   r   r   r   r   r   r}   r   r   r   r   r   rR   r   r   r   r   r   }  s    




r   c                   @   r    )GridFormzh GridForm class (extends GridFormHelp):

    methods:

     - GridForm(self, screen, title, *args):
    c                 G   s   | ||d f| }t j|  d S r   )r   r   )r   r   r   r   Zmyargsr   r   r   r     s   zGridForm.__init__Nr(   r   r   r   r   r     r)   r   c                   @   s`   e Zd ZdZdddZdddZdd	 Zdd
dZdd Zdd Z	dd Z
dddZdd ZdS )CheckboxTreea   CheckboxTree combo widget,

    methods:

     - CheckboxTree(self, height, scroll = 0, width = None, hide_checkbox = 0, unselectable = 0)
                    constructor.
     - append(self, text, item = None, selected = 0):
     - addItem(self, text, path, item = None, selected = 0):
     - getCurrent(self):
     - getSelection(self):
     - setEntry(self, item, text):
     - setCurrent(self, item):
     - setEntryValue(self, item, selected = 1):
     - getEntryValue(self, item):
    Nr   c                 C   s   |  |td f|| d S )Nr   )addItem	snackArgs)r   r&   rC   r1   r   r   r   r     s   zCheckboxTree.appendc                 C   s4   |d u r|}| j |||}|| j|< || j|< d S r   )r   ZcheckboxtreeAddItemr@   rA   )r   r&   pathrC   r1   r=   r   r   r   r     s
   
zCheckboxTree.addItemc                 C   s   | j  }| j| S r   )r   ZcheckboxtreeGetCurrentr@   )r   Zcurrr   r   r   
getCurrent  s   

zCheckboxTree.getCurrentc                 C   s6   t ||||| _i | _i | _|r| j| d S d S r   )r#   Zcheckboxtreer   r@   rA   ZcheckboxtreeSetWidth)r   rV   rW   rY   Zhide_checkboxZunselectabler   r   r   r     s   zCheckboxTree.__init__c                 C   rL   r   )r   ZcheckboxtreeGetSelectionr   r@   rM   r   r   r   rO     rP   zCheckboxTree.getSelectionc                 C      | j | j| | d S r   )r   ZcheckboxtreeSetEntryrA   )r   rC   r&   r   r   r   setEntry  r_   zCheckboxTree.setEntryc                 C   rQ   r   )r   ZcheckboxtreeSetCurrentrA   rH   r   r   r   rR      rS   zCheckboxTree.setCurrentr   c                 C   r   r   )r   ZcheckboxtreeSetEntryValuerA   )r   rC   r1   r   r   r   setEntryValue  r_   zCheckboxTree.setEntryValuec                 C   s   | j | j| S r   )r   ZcheckboxtreeGetEntryValuerA   rH   r   r   r   getEntryValue  r:   zCheckboxTree.getEntryValuer0   )r   Nr   r   rt   )r   r   r   r   r   r   r   r   rO   r   rR   r   r   r   r   r   r   r     s    



r   OkCancel(   c
                 C   s   |dkrt |}t| |}
t||}t||dd}d}|D ](}t|tkr*|\}}n|}|}||kr5|}n||kr;|}||| |d }q|dkrO|| t| ||	dd}|	|dd |j	|dddd |j	|
dd	dd
 |
 }|
|| fS )z
    - ListboxChoiceWindow(screen, title, text, items, 
            buttons = ('Ok', 'Cancel'), 
            width = 40, scroll = 0, height = -1, default = None,
            help = None):
    r   r   )rW   rX   r   N   )r   r   r   r   r   r   r   )r   r   r`   r?   typer   r   rR   r   r   r   r   rK   )r   r   r&   itemsbuttonsrY   rW   rV   r   r   bbtlcountrC   r=   r   Zrcr   r   r   ListboxChoiceWindow	  s0   





r   r   r   c                 C   sd   t | |}t||| jd d}	t| ||dd}
|
j|	dddd |
j|dddd ||
||S )	z
     - ButtonChoiceWindow(screen, title, text, 
               buttons = [ 'Ok', 'Cancel' ], 
               width = 40, x = None, y = None, help = None):
       )rf   r   r   r   r   r   r   r   r   r   )r   r`   rV   r   r   r   r   )r   r   r&   r   rY   r   r   r   r   r   r   r   r   r   ButtonChoiceWindow4  s   
r  r      c	                 C   sN  t | |}	t||}
d}|D ]}|d }qtd|}d}g }|D ]@}t|tkr>|\}}t|tjdkr5tnt	r=t
||}nt
|}|jt|d|ddd |j|d|dd |d }|| q t| ||dd}|j|
ddd	d
 |j|ddd	d
 |j|	dddd | }g }d}|D ]}|||   |d }q|	|t|fS )z
    EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40,
        entryWidth = 20, buttons = [ 'Ok', 'Cancel' ], help = None):
    r   r   r   r   )r   r   r   r   )r   r   r   r   r  r   r   )r   r`   r   r   r   r   r   r   r   r   rp   r   rg   r   r   r   r   r.   r   )r   r   r&   ZpromptsZallowCancelrY   Z
entryWidthr   r   r   r   r   nZsgZ	entryLister   r   ZentryValuesr   r   r   EntryWindowD  s<   





r  c                   @   sj   e Zd ZdZ				dddZdddZdd	d
ZdddZdd ZdddZ	dd Z
dd Zdd ZdS )CListboxap  Clistbox convenience class.

    methods:

     - Clistbox(self, height, cols, cols_widths, scroll = 0)       : constructor
     - colFormText(self, col_text, align = None, adjust_width = 0) : column text.
     - append(self, col_text, item, col_text_align = None)         :
     - insert(self, col_text, item, before, col_text_align = None)
     - delete(self, item)
     - replace(self, col_text, item, col_text_align = None)
     - current(self) : returns current item
     - setCurrent(self, item): sets an item as current
     - clear(self): clear the listbox
     
     Alignments may be LEFT, RIGHT, CENTER, None
    r   r   Nc                 C   s   || _ |d d  | _|| _|| _|	d kr5t| dd d}| j|	|
|d}t|| _| j	| jdddd n	t| dd d}t
||||| _| j	| jd|dd d S )Nr   r   )adjust_widthr   r   )r   )cols
col_widthscol_padcol_text_alignr   r   colFormTextrg   rh   r   r?   rU   )r   rV   r	  r
  rW   rX   rY   r  r  Z
col_labelsZcol_label_alignr  Zbox_yZlstrr   r   r   r     s    
zCListbox.__init__c                 C   s,  d}d}t |}|| jk r||k r|| }t|}| j| |k r2|r)|| j|< n	|d | j|  }| j| t| }	|	dkrs|d krGt}
n|| }
|
tkrU|d|	  }|
tkrid|	d  | d|	d d   }|
tkrsd|	 | }||d krd| j }nd}|| | }|d }|| jk r||k s|S )Nr   rr   ru   r   r   )	r   r	  r#   Zwstrlenr
  LEFTCENTERRIGHTr  )r   col_textZalignr  ir   Zc_lenZcstrZcstrlenZdeltaaZpstrr   r   r   r    s<   
#zCListbox.colFormTextc                 C   ,   |d kr| j }| ||}| j|| d S r   )r  r  rU   r   r   r  rC   r  r&   r   r   r   r        zCListbox.appendc                 C   s.   |d kr| j }| ||}| j||| d S r   )r  r  rU   rF   )r   r  rC   rE   r  r&   r   r   r   rF     s   zCListbox.insertc                 C   r[   r   )rU   rI   rH   r   r   r   rI     r'   zCListbox.deletec                 C   r  r   )r  r  rU   rJ   r  r   r   r   rJ     r  zCListbox.replacec                 C   r   r   )rU   rK   r   r   r   r   rK     r   zCListbox.currentc                 C   r[   r   )rU   rR   rH   r   r   r   rR     r'   zCListbox.setCurrentc                 C   r   r   )rU   rT   r   r   r   r   rT     rq   zCListbox.clear)r   r   r   r   NNNr   r0   r   )r   r   r   r   r   r  r   rF   rI   rJ   rK   rR   rT   r   r   r   r   r  r  s    


)

r  c                 C   s   d|  S )N   r   )r   r   r   r   customColorset  r/   r  )ra   ra   )r   r   r   r   NN)cr   Z
__future__r   r   r   r#   stringr   r   r   r   r   r	   r
   r   r  ZDOWNr  ZUPr  r   r   r!   r*   r+   r<   r?   rZ   r`   rg   rl   rp   ZKEY_F1ZKEY_F2ZKEY_F3ZKEY_F4ZKEY_F5ZKEY_F6ZKEY_F7ZKEY_F8ZKEY_F9ZKEY_F10ZKEY_F11ZKEY_F12ZKEY_ESCZ	KEY_ENTERZKEY_SUSPENDZKEY_BACKSPACEZ
KEY_DELETEZ
KEY_INSERTZ
KEY_RESIZErv   r{   rN   r   r  Zascii_lettersdigitsorx   rz   r   ZCOLORSET_ROOTZCOLORSET_BORDERZCOLORSET_WINDOWZCOLORSET_SHADOWZCOLORSET_TITLEZCOLORSET_BUTTONZCOLORSET_ACTBUTTONZCOLORSET_CHECKBOXZCOLORSET_ACTCHECKBOXZCOLORSET_ENTRYZCOLORSET_LABELZCOLORSET_LISTBOXZCOLORSET_ACTLISTBOXZCOLORSET_TEXTBOXZCOLORSET_ACTTEXTBOXZCOLORSET_HELPLINEZCOLORSET_ROOTTEXTZCOLORSET_EMPTYSCALEZCOLORSET_FULLSCALEZCOLORSET_DISENTRYZCOLORSET_COMPACTBUTTONZCOLORSET_ACTSELLISTBOXZCOLORSET_SELLISTBOXr   r   rc   r   r   r   r   r   r   r   r  r  r  r  r   r   r   r   <module>   s   $$

A	

?
.	

U*I9
,


.s