Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/Tools/pynche/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/Tools/pynche/__pycache__/Switchboard.cpython-37.opt-1.pyc

B

� f��@s&dZddlZddlZGdd�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@sneZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zddd�Z
dd�ZdS)�Switchboardc
Cs�||_d|_i|_g|_d|_d|_d|_d|_d}|r�z\y<t|d�}t	�
|�|_t|jt�stt
d|tjd�i|_Wntttfk
r�YnXWd|r�|��XdS)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/python37/lib64/python3.7/Tools/pynche/Switchboard.py�__init__2s,



zSwitchboard.__init__cCs|j�|�dS)N)r�append)rZviewrrr�add_viewLszSwitchboard.add_viewcCs4||_||_||_x|jD]}|�|||�qWdS)N)r	r
rrZupdate_yourself)rZredZgreenZblue�vrrr�update_viewsOs
zSwitchboard.update_viewscCs|�|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.colordbcCs6||_x"|jD]}t|d�r|�|�qW|��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<x$|jD]}t|d�r,|�|j�q,W|j��|jd<d}zJyt	|j
d�}Wn&tk
r�td|j
t
jd�YnXt�|j|�Wd|r�|��XdS)	NZREDZGREENZBLUE�save_optionsZDBFILE�wbzCannot write options to file:)r)r	rr
rrr&r)r�filenamer
rrrrrr�dumpr)rr rrrr�
save_viewsis"
zSwitchboard.save_viewscCs&x |jD]}t|d�r|��qWdS)N�withdraw)rr&r.)rr rrr�withdraw_views�s
zSwitchboard.withdraw_views�cCs
||_dS)N)r)r�flagrrr�canceled�szSwitchboard.canceledcCs|jS)N)r)rrrr�
canceled_p�szSwitchboard.canceled_pN)r0)�__name__�
__module__�__qualname__rrr!r"r#r$r'r(r-r/r2r3rrrrr1s
r)�__doc__rrrrrrr�<module>*s