diff options
author | Barry Warsaw <barry@python.org> | 1998-10-20 20:45:46 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-10-20 20:45:46 (GMT) |
commit | 8a09e1ccdab7e47780780761c3ea8355ca7ded60 (patch) | |
tree | 8f64e55bfe4e697aaef08bdc3cd05f9c2c090d04 /Tools/pynche/TextViewer.py | |
parent | 28e7b4cce1bc8186206bdcd1a08b560f55b65923 (diff) | |
download | cpython-8a09e1ccdab7e47780780761c3ea8355ca7ded60.zip cpython-8a09e1ccdab7e47780780761c3ea8355ca7ded60.tar.gz cpython-8a09e1ccdab7e47780780761c3ea8355ca7ded60.tar.bz2 |
Saving/Restoring state into ~/.pynche file
Diffstat (limited to 'Tools/pynche/TextViewer.py')
-rw-r--r-- | Tools/pynche/TextViewer.py | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/Tools/pynche/TextViewer.py b/Tools/pynche/TextViewer.py index 254e7e0..7e8cec5 100644 --- a/Tools/pynche/TextViewer.py +++ b/Tools/pynche/TextViewer.py @@ -21,6 +21,7 @@ import ColorDB class TextViewer: def __init__(self, switchboard, parent=None): self.__sb = switchboard + optiondb = switchboard.optiondb() root = self.__root = Toplevel(parent, class_='Pynche') root.protocol('WM_DELETE_WINDOW', self.__withdraw) root.title('Pynche Text Window') @@ -33,11 +34,20 @@ class TextViewer: # create the text widget # self.__text = Text(root, relief=SUNKEN, - background='black', - foreground='white', + background=optiondb.get('TEXTBG', 'black'), + foreground=optiondb.get('TEXTFG', 'white'), width=35, height=15) + sfg = optiondb.get('TEXT_SFG') + if sfg: + self.__text.configure(selectforeground=sfg) + sbg = optiondb.get('TEXT_SBG') + if sbg: + self.__text.configure(selectbackground=sbg) + ibg = optiondb.get('TEXT_IBG') + if ibg: + self.__text.configure(insertbackground=ibg) self.__text.pack() - self.__text.insert(0.0, '''\ + self.__text.insert(0.0, optiondb.get('TEXT', '''\ Insert some stuff here and play with the buttons below to see how the colors interact in @@ -45,14 +55,23 @@ textual displays. See how the selection can also be affected by tickling the buttons -and choosing a color.''') - self.__text.tag_add(SEL, 6.0, END) +and choosing a color.''')) + insert = optiondb.get('TEXTINS') + if insert: + self.__text.mark_set(INSERT, insert) + try: + start, end = optiondb.get('TEXTSEL', (6.0, END)) + self.__text.tag_add(SEL, start, end) + except ValueError: + # selection wasn't set + pass + self.__text.focus_set() # # variables self.__trackp = BooleanVar() - self.__trackp.set(0) + self.__trackp.set(optiondb.get('TRACKP', 0)) self.__which = IntVar() - self.__which.set(0) + self.__which.set(optiondb.get('WHICH', 0)) # # track toggle self.__t = Checkbutton(root, text='Track color changes', @@ -130,3 +149,15 @@ and choosing a color.''') self.__text.configure(selectbackground=colorname) elif which == 5: self.__text.configure(insertbackground=colorname) + + def save_options(self, optiondb): + optiondb['TRACKP'] = self.__trackp.get() + optiondb['WHICH'] = self.__which.get() + optiondb['TEXT'] = self.__text.get(0.0, 'end - 1c') + optiondb['TEXTSEL'] = self.__text.tag_ranges(SEL)[0:2] + optiondb['TEXTINS'] = self.__text.index(INSERT) + optiondb['TEXTFG'] = self.__text['foreground'] + optiondb['TEXTBG'] = self.__text['background'] + optiondb['TEXT_SFG'] = self.__text['selectforeground'] + optiondb['TEXT_SBG'] = self.__text['selectbackground'] + optiondb['TEXT_IBG'] = self.__text['insertbackground'] |