#!/usr/bin/env python
#
# $Id: TagAttributeChooserDialog.py,v 1.4 2001/11/03 11:05:22 doughellmann Exp $
#
# Copyright 2001 Doug Hellmann.
#
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Doug
# Hellmann not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Dialog for defining all of the attributes of a text tag style.
"""
__rcs_info__ = {
#
# Creation Information
#
'module_name' : '$RCSfile: TagAttributeChooserDialog.py,v $',
'rcs_id' : '$Id: TagAttributeChooserDialog.py,v 1.4 2001/11/03 11:05:22 doughellmann Exp $',
'creator' : 'Doug Hellmann <doug@hellfly.net>',
'project' : 'PmwContribD',
'created' : 'Sat, 05-May-2001 13:28:48 EDT',
#
# Current Information
#
'author' : '$Author: doughellmann $',
'version' : '$Revision: 1.4 $',
'date' : '$Date: 2001/11/03 11:05:22 $',
}
#
# Import system modules
#
from Tkinter import *
import Pmw
import string
#
# Import Local modules
#
from FontChooserDialog import FontChooserDialog
from OptionColorButton import OptionColorButton
#
# Module
#
RELIEF_OPTIONS=( FLAT, RAISED, SUNKEN, RIDGE, GROOVE, SOLID )
class TagAttributeChooserDialog(FontChooserDialog):
"""Dialog for defining all of the attributes of a text tag style.
This dialog type extends the FontChooserDialog to include
parameters which are only usable in the Text widget.
Options
'background' -- Background color of the tag style.
'borderwidth' -- Width of the border of the tag style.
'foreground' -- Foreground color of the tag style.
'relief' -- Relief of the tag style.
"""
def __init__(self, parent=None, **kw):
optiondefs = (
('relief', FLAT, None),
('borderwidth', 1, None),
('background', 'lightgrey', None),
('foreground', 'black', None),
)
self.defineoptions(kw, optiondefs)
FontChooserDialog.__init__(self, parent)
self.createTagParametersPage()
self.initialiseoptions(TagAttributeChooserDialog)
return
def value(self):
fontspec = FontChooserDialog.value(self)
tagspec = {}
try:
tagspec['background'] = self.bgvar.get()
except AttributeError:
tagspec['background'] = self['background']
try:
tagspec['foreground'] = self.fgvar.get()
except AttributeError:
tagspec['foreground'] = self['foreground']
try:
tagspec['relief'] = self.reliefvar.get()
except AttributeError:
tagspec['relief'] = self['relief']
try:
tagspec['borderwidth'] = self.borderwidthvar.get()
except AttributeError:
tagspec['borderwidth'] = self['borderwidth']
apply(self.configure, (), tagspec)
return (fontspec, tagspec)
def updateSelected(self):
FontChooserDialog.updateSelected(self)
self.component('background').set(self['background'])
self.component('foreground').set(self['foreground'])
self.reliefvar.set(self['relief'])
self.borderwidthvar.set(self['borderwidth'])
return
def updateExample(self):
fontspec, tagspec = self.value()
tagspec['font'] = fontspec
apply(self.component('example').tag_configure, ('example',), tagspec)
return
def createTagParametersPage(self):
self.component('notebook').add('taggroup',
tab_text='Text Tag Parameters')
taggroup = self.component('notebook').page('taggroup')
self.bgvar = StringVar(taggroup)
self.bgvar.set(self['background'])
bg = self.createcomponent('background', (), None, OptionColorButton,
(taggroup,),
variable=self.bgvar,
command=self.updateExample,
labelpos='w',
label_text='Background',
)
#bg.pack(side=TOP, expand=NO, fill=NONE)
bg.grid(row=0, column=0, sticky='w')
self.fgvar = StringVar(taggroup)
self.fgvar.set(self['foreground'])
fg = self.createcomponent('foreground', (), None, OptionColorButton,
(taggroup,),
variable=self.fgvar,
command=self.updateExample,
labelpos='w',
label_text='Foreground',
)
#fg.pack(side=TOP, expand=NO, fill=NONE)
fg.grid(row=1, column=0, sticky='w')
self.reliefvar = StringVar(taggroup)
self.reliefvar.set(self['relief'])
relief = self.createcomponent('relief', (), None, Pmw.ComboBox,
(taggroup,),
entry_textvariable=self.reliefvar,
labelpos='w',
label_text='Relief',
entry_width=10,
entryfield_modifiedcommand=self.updateExample,
)
relief.component('scrolledlist').setlist(RELIEF_OPTIONS)
#relief.pack(side=TOP, expand=NO, fill=NONE)
relief.grid(row=2, column=0, sticky='w')
self.borderwidthvar = IntVar(taggroup)
self.borderwidthvar.set(self['borderwidth'])
borderwidth = self.createcomponent('borderwidth', (), None, Pmw.Counter,
(taggroup,),
labelpos='w',
label_text='Border',
entry_textvariable=self.borderwidthvar,
entry_width=3,
entryfield_modifiedcommand=self.updateExample,
)
#borderwidth.pack(side=TOP, expand=NO, fill=NONE)
borderwidth.grid(row=3, column=0, sticky='w')
Pmw.alignlabels( (bg, fg, relief, borderwidth) )
return
if __name__ == '__main__':
fontspec = TagAttributeChooserDialog().activate()
print 'Result: ', fontspec
|