Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Private Attributes
pynche.TextViewer.TextViewer Class Reference

List of all members.

Public Member Functions

def __init__
def withdraw
def deiconify
def update_yourself
def save_options

Private Member Functions

def __quit
def __forceupdate
def __toggletrack
def __set_color

Private Attributes

 __sb
 __root
 __text
 __trackp
 __which
 __t
 __frame
 __labels
 __radios

Detailed Description

Definition at line 25 of file TextViewer.py.


Constructor & Destructor Documentation

def pynche.TextViewer.TextViewer.__init__ (   self,
  switchboard,
  master = None 
)

Definition at line 26 of file TextViewer.py.

00026 
00027     def __init__(self, switchboard, master=None):
00028         self.__sb = switchboard
00029         optiondb = switchboard.optiondb()
00030         root = self.__root = Toplevel(master, class_='Pynche')
00031         root.protocol('WM_DELETE_WINDOW', self.withdraw)
00032         root.title('Pynche Text Window')
00033         root.iconname('Pynche Text Window')
00034         root.bind('<Alt-q>', self.__quit)
00035         root.bind('<Alt-Q>', self.__quit)
00036         root.bind('<Alt-w>', self.withdraw)
00037         root.bind('<Alt-W>', self.withdraw)
00038         #
00039         # create the text widget
00040         #
00041         self.__text = Text(root, relief=SUNKEN,
00042                            background=optiondb.get('TEXTBG', 'black'),
00043                            foreground=optiondb.get('TEXTFG', 'white'),
00044                            width=35, height=15)
00045         sfg = optiondb.get('TEXT_SFG')
00046         if sfg:
00047             self.__text.configure(selectforeground=sfg)
00048         sbg = optiondb.get('TEXT_SBG')
00049         if sbg:
00050             self.__text.configure(selectbackground=sbg)
00051         ibg = optiondb.get('TEXT_IBG')
00052         if ibg:
00053             self.__text.configure(insertbackground=ibg)
00054         self.__text.pack()
00055         self.__text.insert(0.0, optiondb.get('TEXT', '''\
00056 Insert some stuff here and play
00057 with the buttons below to see
00058 how the colors interact in
00059 textual displays.
00060 
00061 See how the selection can also
00062 be affected by tickling the buttons
00063 and choosing a color.'''))
00064         insert = optiondb.get('TEXTINS')
00065         if insert:
00066             self.__text.mark_set(INSERT, insert)
00067         try:
00068             start, end = optiondb.get('TEXTSEL', (6.0, END))
00069             self.__text.tag_add(SEL, start, end)
00070         except ValueError:
00071             # selection wasn't set
00072             pass
00073         self.__text.focus_set()
00074         #
00075         # variables
00076         self.__trackp = BooleanVar()
00077         self.__trackp.set(optiondb.get('TRACKP', 0))
00078         self.__which = IntVar()
00079         self.__which.set(optiondb.get('WHICH', 0))
00080         #
00081         # track toggle
00082         self.__t = Checkbutton(root, text='Track color changes',
00083                                variable=self.__trackp,
00084                                relief=GROOVE,
00085                                command=self.__toggletrack)
00086         self.__t.pack(fill=X, expand=YES)
00087         frame = self.__frame = Frame(root)
00088         frame.pack()
00089         #
00090         # labels
00091         self.__labels = []
00092         row = 2
00093         for text in ('Text:', 'Selection:', 'Insertion:'):
00094             l = Label(frame, text=text)
00095             l.grid(row=row, column=0, sticky=E)
00096             self.__labels.append(l)
00097             row += 1
00098         col = 1
00099         for text in ('Foreground', 'Background'):
00100             l = Label(frame, text=text)
00101             l.grid(row=1, column=col)
00102             self.__labels.append(l)
00103             col += 1
00104         #
00105         # radios
00106         self.__radios = []
00107         for col in (1, 2):
00108             for row in (2, 3, 4):
00109                 # there is no insertforeground option
00110                 if row==4 and col==1:
00111                     continue
00112                 r = Radiobutton(frame, variable=self.__which,
00113                                 value=(row-2)*2 + col-1,
00114                                 command=self.__set_color)
00115                 r.grid(row=row, column=col)
00116                 self.__radios.append(r)
00117         self.__toggletrack()

Here is the caller graph for this function:


Member Function Documentation

def pynche.TextViewer.TextViewer.__forceupdate (   self,
  event = None 
) [private]

Definition at line 127 of file TextViewer.py.

00127 
00128     def __forceupdate(self, event=None):
00129         self.__sb.update_views_current()

def pynche.TextViewer.TextViewer.__quit (   self,
  event = None 
) [private]

Definition at line 118 of file TextViewer.py.

00118 
00119     def __quit(self, event=None):
00120         self.__root.quit()

def pynche.TextViewer.TextViewer.__set_color (   self,
  event = None 
) [private]

Definition at line 142 of file TextViewer.py.

00142 
00143     def __set_color(self, event=None):
00144         which = self.__which.get()
00145         text = self.__text
00146         if which == 0:
00147             color = text['foreground']
00148         elif which == 1:
00149             color = text['background']
00150         elif which == 2:
00151             color = text['selectforeground']
00152         elif which == 3:
00153             color = text['selectbackground']
00154         elif which == 5:
00155             color = text['insertbackground']
00156         try:
00157             red, green, blue = ColorDB.rrggbb_to_triplet(color)
00158         except ColorDB.BadColor:
00159             # must have been a color name
00160             red, green, blue = self.__sb.colordb().find_byname(color)
00161         self.__sb.update_views(red, green, blue)

def pynche.TextViewer.TextViewer.__toggletrack (   self,
  event = None 
) [private]

Definition at line 130 of file TextViewer.py.

00130 
00131     def __toggletrack(self, event=None):
00132         if self.__trackp.get():
00133             state = NORMAL
00134             fg = self.__radios[0]['foreground']
00135         else:
00136             state = DISABLED
00137             fg = self.__radios[0]['disabledforeground']
00138         for r in self.__radios:
00139             r.configure(state=state)
00140         for l in self.__labels:
00141             l.configure(foreground=fg)

def pynche.TextViewer.TextViewer.deiconify (   self,
  event = None 
)

Definition at line 124 of file TextViewer.py.

00124 
00125     def deiconify(self, event=None):
00126         self.__root.deiconify()

def pynche.TextViewer.TextViewer.save_options (   self,
  optiondb 
)

Definition at line 178 of file TextViewer.py.

00178 
00179     def save_options(self, optiondb):
00180         optiondb['TRACKP'] = self.__trackp.get()
00181         optiondb['WHICH'] = self.__which.get()
00182         optiondb['TEXT'] = self.__text.get(0.0, 'end - 1c')
00183         optiondb['TEXTSEL'] = self.__text.tag_ranges(SEL)[0:2]
00184         optiondb['TEXTINS'] = self.__text.index(INSERT)
00185         optiondb['TEXTFG'] = self.__text['foreground']
00186         optiondb['TEXTBG'] = self.__text['background']
00187         optiondb['TEXT_SFG'] = self.__text['selectforeground']
00188         optiondb['TEXT_SBG'] = self.__text['selectbackground']
00189         optiondb['TEXT_IBG'] = self.__text['insertbackground']
def pynche.TextViewer.TextViewer.update_yourself (   self,
  red,
  green,
  blue 
)

Definition at line 162 of file TextViewer.py.

00162 
00163     def update_yourself(self, red, green, blue):
00164         if self.__trackp.get():
00165             colorname = ColorDB.triplet_to_rrggbb((red, green, blue))
00166             which = self.__which.get()
00167             text = self.__text
00168             if which == 0:
00169                 text.configure(foreground=colorname)
00170             elif which == 1:
00171                 text.configure(background=colorname)
00172             elif which == 2:
00173                 text.configure(selectforeground=colorname)
00174             elif which == 3:
00175                 text.configure(selectbackground=colorname)
00176             elif which == 5:
00177                 text.configure(insertbackground=colorname)

Here is the caller graph for this function:

def pynche.TextViewer.TextViewer.withdraw (   self,
  event = None 
)

Definition at line 121 of file TextViewer.py.

00121 
00122     def withdraw(self, event=None):
00123         self.__root.withdraw()


Member Data Documentation

Definition at line 86 of file TextViewer.py.

Definition at line 90 of file TextViewer.py.

Definition at line 105 of file TextViewer.py.

Definition at line 29 of file TextViewer.py.

Definition at line 27 of file TextViewer.py.

Definition at line 81 of file TextViewer.py.

Definition at line 40 of file TextViewer.py.

Definition at line 75 of file TextViewer.py.

Definition at line 77 of file TextViewer.py.


The documentation for this class was generated from the following file: