Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/Tools/pynche/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/Tools/pynche/__pycache__/Switchboard.cpython-34.pyc

�
e f��@s5dZddlZddlZGdd�d�ZdS)a�Switchboard class.

This class is used to coordinate updates among all Viewers.  Every Viewer must
conform to the following interface:

    - it must include a method called update_yourself() which takes three
      arguments; the red, green, and blue values of the selected color.

    - When a Viewer selects a color and wishes to update all other Views, it
      should call update_views() on the Switchboard object.  Note that the
      Viewer typically does *not* update itself before calling update_views(),
      since this would cause it to get updated twice.

Optionally, Viewers can also implement:

    - save_options() which takes an optiondb (a dictionary).  Store into this
      dictionary any values the Viewer wants to save in the persistent
      ~/.pynche file.  This dictionary is saved using marshal.  The namespace
      for the keys is ad-hoc; make sure you don't clobber some other Viewer's
      keys!

    - withdraw() which takes no arguments.  This is called when Pynche is
      unmapped.  All Viewers should implement this.

    - colordb_changed() which takes a single argument, an instance of
      ColorDB.  This is called whenever the color name database is changed and
      gives a chance for the Viewers to do something on those events.  See
      ListViewer for details.

External Viewers are found dynamically.  Viewer modules should have names such
as FooViewer.py.  If such a named module has a module global variable called
ADDTOVIEW and this variable is true, the Viewer will be added dynamically to
the `View' menu.  ADDTOVIEW contains a string which is used as the menu item
to display the Viewer (one kludge: if the string contains a `%', this is used
to indicate that the next character will get an underline in the menu,
otherwise the first character is underlined).

FooViewer.py should contain a class called FooViewer, and its constructor
should take two arguments, an instance of Switchboard, and optionally a Tk
master window.

�Nc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zddd�Z
dd�ZdS)�SwitchboardcCs�||_d|_i|_g|_d|_d|_d|_d|_d}|r�z{yYt|d�}t	j
|�|_t|jt�s�t
d|dtj�i|_nWntttfk
r�YnXWd|r�|j�nXndS)Nr�rbz"Problem reading options from file:�file)�_Switchboard__initfile�_Switchboard__colordb�_Switchboard__optiondb�_Switchboard__views�_Switchboard__red�_Switchboard__green�_Switchboard__blue�_Switchboard__canceled�open�marshal�load�
isinstance�dict�print�sys�stderr�IOError�EOFError�
ValueError�close)�selfZinitfile�fp�r�=/opt/alt/python34/lib64/python3.4/Tools/pynche/Switchboard.py�__init__2s,								
	zSwitchboard.__init__cCs|jj|�dS)N)r�append)rZviewrrr�add_viewLszSwitchboard.add_viewcCsF||_||_||_x$|jD]}|j|||�q%WdS)N)r	r
rrZupdate_yourself)rZredZgreenZblue�vrrr�update_viewsOs
			zSwitchboard.update_viewscCs |j|j|j|j�dS)N)r!r	r
r)rrrr�update_views_currentVsz Switchboard.update_views_currentcCs|j|j|jfS)N)r	r
r)rrrr�current_rgbYszSwitchboard.current_rgbcCs|jS)N)r)rrrr�colordb\szSwitchboard.colordbcCsJ||_x0|jD]%}t|d�r|j|�qqW|j�dS)N�colordb_changed)rr�hasattrr%r")rr$r rrr�set_colordb_s
	zSwitchboard.set_colordbcCs|jS)N)r)rrrr�optiondbfszSwitchboard.optiondbcCs�|j|jd<|j|jd<|j|jd<x3|jD](}t|d�r:|j|j�q:q:W|jj�|jd<d}z[yt	|j
d�}Wn+tk
r�td|j
dt
j�YnXtj|j|�Wd|r�|j�nXdS)	NZREDZGREENZBLUE�save_optionsZDBFILE�wbzCannot write options to file:r)r	rr
rrr&r)r�filenamer
rrrrrr�dumpr)rr rrrr�
save_viewsis"
zSwitchboard.save_viewscCs4x-|jD]"}t|d�r
|j�q
q
WdS)N�withdraw)rr&r.)rr rrr�withdraw_views�szSwitchboard.withdraw_views�cCs
||_dS)N)r)rZflagrrr�canceled�szSwitchboard.canceledcCs|jS)N)r)rrrr�
canceled_p�szSwitchboard.canceled_pN)�__name__�
__module__�__qualname__rrr!r"r#r$r'r(r-r/r1r2rrrrr1sr)�__doc__rrrrrrr�<module>*s