
4S y                 @   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 dm Z dp Z dq Z dr Z ds Z i dt d 6Z Gd d   d  Z Gd	 d
   d
 e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z i e j  d 6e j! d 6e j" d 6e j# d  6e j$ d! 6e j% d" 6e j& d# 6e j' d$ 6e j( d% 6e j) d& 6e j* d' 6e j+ d( 6e j, d) 6e j- d* 6e j. d+ 6e j/ d, 6e j0 d- 6e j1 d. 6e2 d/  d/ 6Z3 x( e4 e3 j5    D] Z6 e6 e3 e3 e6 <qnWx? d0 d1   e j7 e j8 D D]  \ Z9 Z: e9 e3 e: <e: e3 e9 <qWGd2 d3   d3  Z; Gd4 d5   d5  Z< i e j= d6 6e j> d7 6e j? d8 6e j@ d9 6e jA d: 6e jB d; 6e jC d< 6e jD d= 6e jE d> 6e jF d? 6e jG d@ 6e jH dA 6e jI dB 6e jJ dC 6e jK dD 6e jL dE 6e jM dF 6e jN dG 6e jO dH 6e jP dI 6e jQ dJ 6e jR dK 6e jS dL 6ZT GdM dN   dN  ZU dO dO dP dQ  ZV GdR dS   dS e  ZW GdT dU   dU e<  ZX GdV dW   dW e<  ZY GdX dY   dY e<  ZZ GdZ d[   d[ eZ  Z[ Gd\ d]   d] e  Z\ du d` d dv d d da db  Z] d^ d_ g d` d d d dc dd  Z^ d d` de d^ d_ g d df dg  Z_ Gdh di   di e<  Z` dj dk   Za d S)wa  
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   appendc               @   s1   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   s0   | r |  j  j | |  n |  j  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   d  S)N)NotImplementedError)r   r   r   r   __init__J   s    zWidget.__init__)__name__
__module____qualname____doc__r   r   r   r   r   r   r   :   s   	r   c               @   s"   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   s   t  j |  |  _ d  S)N)_snackbuttonr   )r   textr   r   r   r   T   s    zButton.__init__N)r   r   r   r   r   r   r   r   r   r   M   s   r   c               @   s"   e  Z d  Z d Z d d   Z d S)CompactButtonzCompact Button class (less frilly button decoration).

    methods:

     - CompactButton(self,text) : create button, with text.
    c             C   s   t  j |  |  _ d  S)N)r   Zcompactbuttonr   )r   r   r   r   r   r   ^   s    zCompactButton.__init__N)r   r   r   r   r   r   r   r   r   r    W   s   r    c               @   sU   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   s
   |  j  j S)N)r   checkboxValue)r   r   r   r   valuen   s    zCheckbox.valuec             C   s   |  j  j d k S)Nr   )r   r"   )r   r   r   r   selectedq   s    zCheckbox.selectedc             C   s   |  j  j | |  S)N)r   ZcheckboxSetFlags)r   flagsenser   r   r   setFlagst   s    zCheckbox.setFlagsc             C   s   |  j  j |  S)N)r   ZcheckboxSetValue)r   r#   r   r   r   setValuex   s    zCheckbox.setValuer   c             C   s   t  j | |  |  _ d  S)N)r   Zcheckboxr   )r   r   isOnr   r   r   r   {   s    zCheckbox.__init__N)	r   r   r   r   r#   r$   r'   r(   r   r   r   r   r   r!   a   s   r!   c               @   s1   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)N)r   keyZ
radioValue)r   r   r   r   r$      s    zSingleRadioButton.selectedr   c             C   s@   | r$ t  j | | j |  |  _ n t  j | d  |  |  _ d  S)N)r   Zradiobuttonr   )r   r   groupr)   r   r   r   r      s    zSingleRadioButton.__init__N)r   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 d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d d d d 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   s0   |  j  j |  } | |  j | <| |  j | <d  S)N)r   ZlistboxAddItemkey2itemitem2key)r   r   itemr+   r   r   r   r      s    zListbox.appendc             C   sX   | s |  j  j | d  } n |  j  j | |  j |  } | |  j | <| |  j | <d  S)Nr   )r   listboxInsertItemr/   r.   )r   r   r0   beforer+   r   r   r   insert   s
    zListbox.insertc             C   s6   |  j  j |  j |  |  j |  j | =|  j | =d  S)N)r   listboxDeleteItemr/   r.   )r   r0   r   r   r   delete   s    zListbox.deletec             C   sb   |  j  j | |  j |  } |  j  j |  j |  |  j |  j | =| |  j | <| |  j | <d  S)N)r   r1   r/   r4   r.   )r   r   r0   r+   r   r   r   replace   s
    zListbox.replacec             C   s   |  j  |  j j   S)N)r.   r   ZlistboxGetCurrent)r   r   r   r   current   s    zListbox.currentc             C   s>   g  } |  j  j   } x" | D] } | j |  j |  q W| S)N)r   ZlistboxGetSelectionr   r.   )r   	selectionlistr+   r   r   r   getSelection   s
    zListbox.getSelectionc             C   s   |  j  j |  j |  d  S)N)r   ZlistboxSetCurrentr/   )r   r0   r   r   r   
setCurrent   s    zListbox.setCurrentc             C   s#   i  |  _  i  |  _ |  j j   d  S)N)r.   r/   r   ZlistboxClear)r   r   r   r   clear   s    		zListbox.clearr   c             C   sP   t  j | | | | | |  |  _ i  |  _ i  |  _ | rL |  j j |  n  d  S)N)r   listboxr   r.   r/   ZlistboxSetWidth)r   heightscroll
returnExitwidthZ
showCursorZmultipleZborderr   r   r   r      s
    !		zListbox.__init__N)r   r   r   r   r   r3   r5   r6   r7   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 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   s   |  j  j |  d  S)N)r   ZtextboxText)r   r   r   r   r   setText   s    zTextbox.setTextc             C   s   |  j  j |  d  S)N)r   ZtextboxHeight)r   r>   r   r   r   	setHeight   s    zTextbox.setHeightr   c             C   s"   t  j | | | | |  |  _ d  S)N)r   Ztextboxr   )r   rA   r>   r   r?   Zwrapr   r   r   r      s    zTextbox.__init__N)r   r   r   r   rC   rD   r   r   r   r   r   rB      s   	rB   c               @   s%   e  Z d  Z d d d d d  Z d S)TextboxReflowed   
   r   c             C   so   t  | | | |  \ } } } | d k rR | | k rR t j |  | | | d  n t j |  | | | d  d  S)Nr   r   )reflowrB   r   )r   rA   r   flexDownflexUp	maxHeightZnewtextr>   r   r   r   r      s    zTextboxReflowed.__init__NrH   )r   r   r   r   r   r   r   r   rE      s   rE   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   s   |  j  j |  d  S)N)r   Z	labelText)r   r   r   r   r   rC      s    zLabel.setTextc             C   s   t  j |  |  _ d  S)N)r   labelr   )r   r   r   r   r   r      s    zLabel.__init__c             C   s   |  j  j |  d  S)N)r   ZlabelSetColors)r   colorsetr   r   r   	setColors   s    zLabel.setColorsN)r   r   r   r   rC   r   rP   r   r   r   r   rM      s   rM   c               @   s.   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   s   |  j  j |  d  S)N)r   ZscaleSet)r   Zamountr   r   r   set  s    z	Scale.setc             C   s   t  j | |  |  _ d  S)N)r   Zscaler   )r   rA   Ztotalr   r   r   r     s    zScale.__init__N)r   r   r   r   rR   r   r   r   r   r   rQ      s   rQ   c               @   sX   e  Z d  Z d Z d d   Z d d d  Z d d   Z d	 d
 d
 d 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   s
   |  j  j S)N)r   Z
entryValue)r   r   r   r   r#     s    zEntry.valuer   c             C   s   |  j  j | |  S)N)r   ZentrySetValue)r   r   ZcursorAtEndr   r   r   rR     s    z	Entry.setc             C   s   |  j  j | |  S)N)r   ZentrySetFlags)r   r%   r&   r   r   r   r'   "  s    zEntry.setFlags r   c             C   s%   t  j | | | | | |  |  _ d  S)N)r   entryr   )r   rA   r   ZhiddenZpasswordr?   r@   r   r   r   r   %  s    zEntry.__init__N)r   r   r   r   r#   rR   r'   r   r   r   r   r   rS     s   rS   ZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9ZF10ZF11ZF12ZESCZENTERZSUSPENDZ	BACKSPACEZDELETEZINSERT c             C   s"   g  |  ] } t  |  | f  q Sr   )ord).0cr   r   r   
<listcomp>7  s   	 rZ   c               @   sy   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  j t |  d  S)N)r   Z	addhotkeyhotkeys)r   keynamer   r   r   	addHotKeyI  s    zForm.addHotKeyc             C   s   d | j  k r9 x' | j j   D] } |  j |  q Wn  d | j  k rl xV | j D] } |  j |  qR Wn5 d | j  k r | |  j | j j <|  j j | j  Sd  S)Nr\   gridmembersr   )	__dict__r\   keysr^   r_   addtransr   r+   )r   widgetr+   r   r   r   r   rb   L  s    zForm.addc             C   sd   |  j  j   \ } } | t j k r/ |  j | S| t j k rB d S| t j k r\ |  j | St | S)NZTIMER)	r   runr   ZFORM_EXIT_WIDGETrc   ZFORM_EXIT_TIMERZFORM_EXIT_FDREADYfilemapr\   )r   whatZwhichr   r   r   re   Y  s    zForm.runc             C   s   |  j  j   d  S)N)r   draw)r   r   r   r   rh   d  s    z	Form.drawNc             C   s1   i  |  _  i  |  _ t j |  |  _ | |  _ d  S)N)rc   rf   r   formr   helpArg)r   rj   r   r   r   r   h  s    		zForm.__init__c             C   s   |  j  j | j   d  S)N)r   Z
setcurrent)r   cor   r   r   r;   o  s    zForm.setCurrentc             C   s   |  j  j |  d  S)N)r   Zsettimer)r   Ztimerr   r   r   setTimerr  s    zForm.setTimerc             C   s0   | |  j  | j   <|  j j | j   |  d  S)N)rf   filenor   Zwatchfd)r   fileflagsr   r   r   	watchFileu  s    zForm.watchFile)r   r   r   r   r^   rb   re   rh   r   r;   rl   rp   r   r   r   r   r[   ;  s   r[   c            	   @   sO   e  Z d  Z d Z d d   Z d
 d d d d d 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   s   |  j  j | |  S)N)gplace)r   xyr   r   r   rs     s    z
Grid.placer   c             C   s   |  j  j |  d } | r( t j } n | r: t j } n  | rP | t j B} n | rf | t j B} n  d } |	 r~ t j } n  |
 r | t j B} n  d | j	 k r |  j
 j | | | j
 | | |  S|  j
 j | | | j | |  Sd  S)Nr   rr   )r_   r   r   ZANCHOR_LEFTZANCHOR_RIGHTZ
ANCHOR_TOPZANCHOR_BOTTOMZ
GRID_GROWXZ
GRID_GROWYr`   rr   Zsetfieldr   )r   rg   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)N)r   gridrr   r_   )r   argsr   r   r   r     s    zGrid.__init__N)r   r   r   r   )r   r   r   r   rs   r   r   r   r   r   r   rq   y  s   	rq   ZROOTZBORDERZWINDOWZSHADOWZTITLEZBUTTONZ	ACTBUTTONZCHECKBOXZACTCHECKBOXZENTRYZLABELZLISTBOXZ
ACTLISTBOXZTEXTBOXZ
ACTTEXTBOXZHELPLINEZROOTTEXTZ
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 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   s3   t  j   t  j   \ |  _ |  _ |  j d   d  S)N)r   ZinitsizerA   r>   pushHelpLine)r   r   r   r   r     s    
zSnackScreen.__init__c             C   s
   t  j   S)N)r   finish)r   r   r   r   r     s    zSnackScreen.finishc             C   s   t  j   d  S)N)r   resume)r   r   r   r   r     s    zSnackScreen.resumec             C   s   t  j   d  S)N)r   suspend)r   r   r   r   r     s    zSnackScreen.suspendc             C   s   |  j  |  |  d  S)N)helpCb)r   argr   r   r   doHelpCallback  s    zSnackScreen.doHelpCallbackc             C   s   | |  _  t j |  j  S)N)r   r   Zhelpcallbackr   )r   cbr   r   r   helpCallback  s    	zSnackScreen.helpCallbackNc             C   s#   | r t  j | |  St  j |  S)N)r   Zsuspendcallback)r   r   r   r   r   r   suspendCallback  s    zSnackScreen.suspendCallbackc             C   s   t  j | | | | |  S)N)r   Z
openwindow)r   lefttoprA   r>   titler   r   r   
openWindow  s    zSnackScreen.openWindowc             C   s$   | s t  j d  St  j |  Sd  S)Nz	*default*)r   Zpushhelpline)r   r   r   r   r   r     s    zSnackScreen.pushHelpLinec             C   s
   t  j   S)N)r   Zpophelpline)r   r   r   r   popHelpLine  s    zSnackScreen.popHelpLinec             C   s   t  j | | |  S)N)r   Zdrawroottext)r   r   r   r   r   r   r   drawRootText  s    zSnackScreen.drawRootTextc             C   s   t  j | | |  S)N)r   Zcenteredwindow)r   rA   r>   r   r   r   r   centeredWindow  s    zSnackScreen.centeredWindowc             C   s8   | r% | r% t  j | j | | |  St  j | j |  S)N)r   Zgridwrappedwindowrr   )r   r   r   rt   ru   r   r   r   gridWrappedWindow  s    zSnackScreen.gridWrappedWindowTc             C   s   | r t  j   St  j   S)N)r   Z	popwindowZpopwindownorefresh)r   refreshr   r   r   	popWindow  s    
zSnackScreen.popWindowc             C   s
   t  j   S)N)r   r   )r   r   r   r   r   
  s    zSnackScreen.refreshc             C   s:   | t  k r# t j t  | | |  St j | | |  Sd  S)N)	colorsetsr   Zsetcolor)r   rO   ZfgZbgr   r   r   setColor  s    zSnackScreen.setColor)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   rF   c             C   s   t  j |  | | |  S)zR returns a tuple of the wrapped text, the actual width, and the actual height
    )r   rI   )r   rA   rJ   rK   r   r   r   rI     s    rI   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)N)prev
buttonlist)r   r   r   r   r   $  s    	zRadioGroup.__init__Nc             C   sW   |  j  r | d  k r d } n  t | |  j  |  } | |  _  |  j j | | f  | S)Nr   )r   r*   r   r   )r   r   r#   defaultbr   r   r   rb   (  s    		zRadioGroup.addc             C   s.   x' |  j  D] \ } } | j   r
 | Sq
 Wd  S)N)r   r$   )r   r   r#   r   r   r   r:   2  s     zRadioGroup.getSelection)r   r   r   r   r   rb   r:   r   r   r   r   r     s   
r   c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)RadioBarz Bar of Radio buttons, based on Grid.

    methods:

    - RadioBar(self, screen, buttonlist) : constructor.
    - getSelection(self): return value of selected button 
    c             C   s   g  |  _  d |  _ t   |  _ t j |  d t |   xq | D]i \ } } } |  j j | | |  } |  j  j | | f  |  j	 | d |  j d d |  j d |  _ q> Wd  S)Nr   r   ry   )
r9   r0   r   r,   rq   r   lenrb   r   r   )r   screenr   r   r#   r   r   r   r   r   r   A  s    		zRadioBar.__init__c             C   s   |  j  j   S)N)r,   r:   )r   r   r   r   r:   L  s    zRadioBar.getSelectionN)r   r   r   r   r   r:   r   r   r   r   r   8  s   r   c               @   s1   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 j |  t |  d  x | D] } t | t j d k r\ t	 n t
  rz | } | j   } n= t |  d k r | \ } } n | \ } } } | |  j | <| r t |  } n t |  } |  j  j | | f  |  j | |  j d d  |  j d |  _ q; Wd  S)Nr   r   3   )r   r   r   r   )r9   r\   r0   rq   r   r   
isinstancesysversionstr
basestringlowerr    r   r   r   )	r   r   r   ZcompactZblistr   r#   Zhotkeyr   r   r   r   r   [  s$    			$zButtonBar.__init__c             C   sH   | |  j  k r |  j  | Sx' |  j D] \ } } | | k r$ | Sq$ Wd  S)N)r\   r9   )r   resultr   r#   r   r   r   buttonPressedr  s    zButtonBar.buttonPressedN)r   r   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 d d d d d d d  Z d d d d	  Z d
 d   Z d d   Z d d d d  Z	 d 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   si   | |  _  | |  _ t |  |  _ g  |  _ d |  _ t |  } |  g | d  d  <t j t	 |    d  S)Nr   )
r   r   r[   ri   	childListform_createdr9   rq   r   tuple)r   r   r   helpr   r   r   r   r     s    				zGridFormHelp.__init__r   c             C   s<   |  j  | | | | | | | | |	 |
 
 |  j j |  d  S)N)r   r   r   )r   rd   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   rb     s    	
zGridFormHelp.addNc             C   s#   |  j  | |  } |  j j   | S)N)re   r   r   )r   rt   ru   r   r   r   r   runOnce  s    zGridFormHelp.runOncec             C   s   |  j  j |  d  S)N)ri   r^   )r   r]   r   r   r   r^     s    zGridFormHelp.addHotKeyc             C   s   |  j  j |  d  S)N)ri   rl   )r   r]   r   r   r   rl     s    zGridFormHelp.setTimerc             C   si   |  j  se |  j d d  x! |  j D] } |  j j |  q# W|  j j |  |  j | |  d |  _  n  d  S)Nr   )r   rs   r   ri   rb   r   r   r   )r   rt   ru   Zchildr   r   r   create  s    	zGridFormHelp.createc             C   s   |  j  | |  |  j j   S)N)r   ri   re   )r   rt   ru   r   r   r   re     s    zGridFormHelp.runc             C   s   |  j    |  j j   S)N)r   ri   rh   )r   r   r   r   rh     s    
zGridFormHelp.drawc             C   s@   |  j    |  j j |  |  j  |  j j   } |  j j   | S)N)r   r   r   r   ri   re   r   )r   r   r   r   r   runPopup  s
    
zGridFormHelp.runPopupc             C   s   |  j  j |  d  S)N)ri   r;   )r   rk   r   r   r   r;     s    zGridFormHelp.setCurrent)r   r   r   r   )r   r   r   r   r   rb   r   r^   rl   r   re   rh   r   r;   r   r   r   r   r   |  s   
	r   c               @   s"   e  Z d  Z d Z d d   Z d S)GridFormzh GridForm class (extends GridFormHelp):

    methods:

     - GridForm(self, screen, title, *args):
    c             G   s'   |  | | d  f | } t  j |   d  S)N)r   r   )r   r   r   r   Zmyargsr   r   r   r     s    zGridForm.__init__N)r   r   r   r   r   r   r   r   r   r     s   r   c               @   s   e  Z d  Z d Z d d d d  Z d d d d  Z d d	   Z d d d 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!   |  j  | t d f | |  d  S)Nr   )addItem	snackArgs)r   r   r0   r$   r   r   r   r     s    zCheckboxTree.appendc             C   sK   | d  k r | } n  |  j  j | | |  } | |  j | <| |  j | <d  S)N)r   ZcheckboxtreeAddItemr.   r/   )r   r   pathr0   r$   r+   r   r   r   r     s
    	zCheckboxTree.addItemc             C   s   |  j  j   } |  j | S)N)r   ZcheckboxtreeGetCurrentr.   )r   currr   r   r   
getCurrent  s    zCheckboxTree.getCurrentc             C   sJ   t  j | | | |  |  _ i  |  _ i  |  _ | rF |  j j |  n  d  S)N)r   Zcheckboxtreer   r.   r/   ZcheckboxtreeSetWidth)r   r>   r?   rA   Zhide_checkboxZunselectabler   r   r   r     s
    		zCheckboxTree.__init__c             C   s>   g  } |  j  j   } x" | D] } | j |  j |  q W| S)N)r   ZcheckboxtreeGetSelectionr   r.   )r   r8   r9   r+   r   r   r   r:     s
    zCheckboxTree.getSelectionc             C   s   |  j  j |  j | |  d  S)N)r   ZcheckboxtreeSetEntryr/   )r   r0   r   r   r   r   setEntry  s    zCheckboxTree.setEntryc             C   s   |  j  j |  j |  d  S)N)r   ZcheckboxtreeSetCurrentr/   )r   r0   r   r   r   r;     s    zCheckboxTree.setCurrentr   c             C   s   |  j  j |  j | |  d  S)N)r   ZcheckboxtreeSetEntryValuer/   )r   r0   r$   r   r   r   setEntryValue  s    zCheckboxTree.setEntryValuec             C   s   |  j  j |  j |  S)N)r   ZcheckboxtreeGetEntryValuer/   )r   r0   r   r   r   getEntryValue  s    zCheckboxTree.getEntryValue)r   r   r   r   r   r   r   r   r:   r   r;   r   r   r   r   r   r   r     s   r   OkCancel(   c
          	   C   sw  | d
 k r t  |  } n  t |  |  }
 t | |  } t | d | d d } d } x | D]w } t |  t k r | \ } } n | } | } | | k r | } n | | k r | } n  | j | |  | d } q^ W| d k r | j |  n  t |  | |	 d d  } | j	 | d d  | j	 | d d d d | j	 |
 d d d	 d | j
   } |
 j |  | j   f S)z
    - ListboxChoiceWindow(screen, title, text, items, 
            buttons = ('Ok', 'Cancel'), 
            width = 40, scroll = 0, height = -1, default = None,
            help = None):
    r   r?   r@   r   N   rx   r   r}   rH   )r   r   r   r   )r   r   rE   r-   typer   r   r;   r   rb   r   r   r7   )r   r   r   itemsbuttonsrA   r?   r>   r   r   bbtlcountr0   r+   rr   rcr   r   r   ListboxChoiceWindow  s2    
 		r   c          	   C   s   t  |  |  } t | | d |  j d }	 t |  | | d d  }
 |
 j |	 d d d d |
 j | d d d d | j |
 j | |   S)	z
     - ButtonChoiceWindow(screen, title, text, 
               buttons = [ 'Ok', 'Cancel' ], 
               width = 40, x = None, y = None, help = None):
    rL      r   r   r   rx   r}   )r   r   r   r   )r   rE   r>   r   rb   r   r   )r   r   r   r   rA   rt   ru   r   r   r   rr   r   r   r   ButtonChoiceWindow3  s    r      c	          
   C   s  t  |  |  }	 t | |  }
 d } x | D] } | d } q+ Wt d |  } d } g  } x | D] } t |  t k r | \ } } t | t j d k r t n t	  r t
 | |  } q n t
 |  } | j t |  d | d d	 d d | j | d | d d | d } | j |  qa Wt |  | | d d  } | j |
 d d d d
 | j | d d d d | j |	 d d d d | j   } g  } d } x/ | D]' } | j | | j    | d } qW|	 j |  t |  f S)z
    EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40,
        entryWidth = 20, buttons = [ 'Ok', 'Cancel' ], help = None):
    r   r   r   r   rx   ry   r   r}   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   rE   rq   r   r   r   r   r   r   r   rS   r   rM   r   r   rb   r   r#   r   )r   r   r   ZpromptsZallowCancelrA   Z
entryWidthr   r   r   r   r   nZsgZ	entryListerr   r   ZentryValuesr   r   r   EntryWindowC  s:    $%
r   c            
   @   s   e  Z d  Z d Z d d d d d d d d d d  Z d 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 r t j |  d d  d } |  j |	 |
 d | } t |  |  _ |  j	 |  j d d d d n t j |  d d  d } t
 | | | |  |  _ |  j	 |  j d | d d d  S)Nr   r   adjust_widthr   ry   r{   )cols
col_widthscol_padcol_text_alignrq   r   colFormTextrM   rN   r   r-   r=   )r   r>   r   r   r?   r@   rA   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  |  } xl| |  j k  r| | k  r| | } t j |  } |  j | | k  r | rx | |  j | <q | d  |  j |  } n  |  j | t j |  }	 |	 d k rE| d  k r t }
 n
 | | }
 |
 t k r | d |	 } n  |
 t k r%d |	 d | d |	 d d } n  |
 t k rEd |	 | } qEn  | | d k red |  j } n d } | | | } | d } q W| S)Nr   rT   rV   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     s8    
	
zCListbox.colFormTextc             C   sA   | d  k r |  j  } n  |  j | |  } |  j j | |  d  S)N)r   r   r=   r   )r   r   r0   r   r   r   r   r   r     s    zCListbox.appendc             C   sD   | d  k r |  j  } n  |  j | |  } |  j j | | |  d  S)N)r   r   r=   r3   )r   r   r0   r2   r   r   r   r   r   r3     s    zCListbox.insertc             C   s   |  j  j |  d  S)N)r=   r5   )r   r0   r   r   r   r5     s    zCListbox.deletec             C   sA   | d  k r |  j  } n  |  j | |  } |  j j | |  d  S)N)r   r   r=   r6   )r   r   r0   r   r   r   r   r   r6     s    zCListbox.replacec             C   s   |  j  j   S)N)r=   r7   )r   r   r   r   r7     s    zCListbox.currentc             C   s   |  j  j |  d  S)N)r=   r;   )r   r0   r   r   r   r;     s    zCListbox.setCurrentc             C   s   |  j  j   d  S)N)r=   r<   )r   r   r   r   r<     s    zCListbox.clear)r   r   r   r   r   r   r   r3   r5   r6   r7   r;   r<   r   r   r   r   r   q  s   	)r   c             C   s   d |  S)N   r   )rt   r   r   r   customColorset  s    r   rH   )rH   r   rH   rH   )rH   rH   )r   r   )r   r   )r   r   rH   )r   r   rH   )br   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-   rB   rE   rM   rQ   rS   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_INSERTrW   r\   r9   ra   r   Zascii_lettersZdigitsorY   r[   rq   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   rI   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>(   s   4

A	!
*
>.




















U*I9)	-s