mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Make tix_configure() work the same way configure() works for the basic
Tkinter classes. Adjust a lot of docstrings. Convert a few type checks to use isinstance() instead of type(). This is part of SF patch #485959.
This commit is contained in:
parent
a0b767625b
commit
723293cb49
1 changed files with 90 additions and 84 deletions
|
|
@ -49,6 +49,14 @@ BALLOON = 'balloon'
|
||||||
AUTO = 'auto'
|
AUTO = 'auto'
|
||||||
ACROSSTOP = 'acrosstop'
|
ACROSSTOP = 'acrosstop'
|
||||||
|
|
||||||
|
# Some constants used by Tkinter dooneevent()
|
||||||
|
TCL_DONT_WAIT = 1 << 1
|
||||||
|
TCL_WINDOW_EVENTS = 1 << 2
|
||||||
|
TCL_FILE_EVENTS = 1 << 3
|
||||||
|
TCL_TIMER_EVENTS = 1 << 4
|
||||||
|
TCL_IDLE_EVENTS = 1 << 5
|
||||||
|
TCL_ALL_EVENTS = 0
|
||||||
|
|
||||||
# BEWARE - this is implemented by copying some code from the Widget class
|
# BEWARE - this is implemented by copying some code from the Widget class
|
||||||
# in Tkinter (to override Widget initialization) and is therefore
|
# in Tkinter (to override Widget initialization) and is therefore
|
||||||
# liable to break.
|
# liable to break.
|
||||||
|
|
@ -56,23 +64,22 @@ import Tkinter, os
|
||||||
|
|
||||||
# Could probably add this to Tkinter.Misc
|
# Could probably add this to Tkinter.Misc
|
||||||
class tixCommand:
|
class tixCommand:
|
||||||
"""The tix command provides access to miscellaneous elements
|
"""The tix commands provide access to miscellaneous elements
|
||||||
of Tix's internal state and the Tix application context.
|
of Tix's internal state and the Tix application context.
|
||||||
Most of the information manipulated by this command per
|
Most of the information manipulated by these commands pertains
|
||||||
tains to the application as a whole, or to a screen or
|
to the application as a whole, or to a screen or
|
||||||
display, rather than to a particular window. The command
|
display, rather than to a particular window.
|
||||||
can take any of a number of different forms depending on
|
|
||||||
the option argument.
|
|
||||||
|
|
||||||
This is a mixin class, assumed to be mixed to Tkinter.Tk
|
This is a mixin class, assumed to be mixed to Tkinter.Tk
|
||||||
that supports the self.tk.call method.
|
that supports the self.tk.call method.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def tix_addbitmapdir(self, directory):
|
def tix_addbitmapdir(self, directory):
|
||||||
"""Tix maintains a list of directory under which which
|
"""Tix maintains a list of directories under which
|
||||||
the tix_getimage and tix_getbitmap commands will
|
the tix_getimage and tix_getbitmap commands will
|
||||||
search for image files. The standard bitmap direc
|
search for image files. The standard bitmap directory
|
||||||
tory is $TIX_LIBRARY/bitmaps. The addbitmapdir com
|
is $TIX_LIBRARY/bitmaps. The addbitmapdir command
|
||||||
mand adds directory into this list. By using this
|
adds directory into this list. By using this
|
||||||
command, the image files of an applications can
|
command, the image files of an applications can
|
||||||
also be located using the tix_getimage or tix_getbitmap
|
also be located using the tix_getimage or tix_getbitmap
|
||||||
command.
|
command.
|
||||||
|
|
@ -87,34 +94,39 @@ class tixCommand:
|
||||||
return self.tk.call('tix', 'cget', option)
|
return self.tk.call('tix', 'cget', option)
|
||||||
|
|
||||||
def tix_configure(self, cnf=None, **kw):
|
def tix_configure(self, cnf=None, **kw):
|
||||||
"""Query or modify the configuration options of the
|
"""Query or modify the configuration options of the Tix application
|
||||||
Tix application context. If no option is specified,
|
context. If no option is specified, returns a dictionary all of the
|
||||||
returns a list describing all of the available
|
available options. If option is specified with no value, then the
|
||||||
options (see Tk_ConfigureInfo for information on
|
command returns a list describing the one named option (this list
|
||||||
the format of this list). If option is specified
|
will be identical to the corresponding sublist of the value
|
||||||
with no value, then the command returns a list
|
returned if no option is specified). If one or more option-value
|
||||||
describing the one named option (this list will be
|
pairs are specified, then the command modifies the given option(s)
|
||||||
identical to the corresponding sublist of the value
|
to have the given value(s); in this case the command returns an
|
||||||
returned if no option is specified). If one or
|
empty string. Option may be any of the configuration options.
|
||||||
more option-value pairs are specified, then the
|
|
||||||
command modifies the given option(s) to have the
|
|
||||||
given value(s); in this case the command returns an
|
|
||||||
empty string. Option may be any of the options
|
|
||||||
described in the CONFIGURATION OPTIONS section.
|
|
||||||
"""
|
"""
|
||||||
return apply(self.tk.call, ('tix', configure) +
|
# Copied from Tkinter.py
|
||||||
self._options(cnf,kw) )
|
if kw:
|
||||||
|
cnf = _cnfmerge((cnf, kw))
|
||||||
|
elif cnf:
|
||||||
|
cnf = _cnfmerge(cnf)
|
||||||
|
if cnf is None:
|
||||||
|
cnf = {}
|
||||||
|
for x in self.tk.split(self.tk.call('tix', 'configure')):
|
||||||
|
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
|
||||||
|
return cnf
|
||||||
|
if isinstance(cnf, StringType):
|
||||||
|
x = self.tk.split(self.tk.call('tix', 'configure', '-'+cnf))
|
||||||
|
return (x[0][1:],) + x[1:]
|
||||||
|
return self.tk.call(('tix', 'configure') + self._options(cnf))
|
||||||
|
|
||||||
def tix_filedialog(self, dlgclass=None):
|
def tix_filedialog(self, dlgclass=None):
|
||||||
"""Returns the file selection dialog that may be
|
"""Returns the file selection dialog that may be shared among
|
||||||
shared among different modules of this application.
|
different calls from this application. This command will create a
|
||||||
This command will create a file selection dialog
|
file selection dialog widget when it is called the first time. This
|
||||||
widget when it is called the first time. This dialog
|
dialog will be returned by all subsequent calls to tix_filedialog.
|
||||||
will be returned by all subsequent calls to tix
|
An optional dlgclass parameter can be passed to specified what type
|
||||||
filedialog. An optional dlgclass parameter can be
|
of file selection dialog widget is desired. Possible options are
|
||||||
passed to specified what type of file selection
|
tix FileSelectDialog or tixExFileSelectDialog.
|
||||||
dialog widget is desired. Possible options are 'tix'
|
|
||||||
'FileSelectDialog' or 'tixExFileSelectDialog'.
|
|
||||||
"""
|
"""
|
||||||
if dlgclass is not None:
|
if dlgclass is not None:
|
||||||
return self.tk.call('tix', 'filedialog', dlgclass)
|
return self.tk.call('tix', 'filedialog', dlgclass)
|
||||||
|
|
@ -122,38 +134,33 @@ class tixCommand:
|
||||||
return self.tk.call('tix', 'filedialog')
|
return self.tk.call('tix', 'filedialog')
|
||||||
|
|
||||||
def tix_getbitmap(self, name):
|
def tix_getbitmap(self, name):
|
||||||
"""Locates a bitmap file of the name name.xpm or name
|
"""Locates a bitmap file of the name name.xpm or name in one of the
|
||||||
in one of the bitmap directories (self, see the
|
bitmap directories (see the tix_addbitmapdir command above). By
|
||||||
tix_addbitmapdir command above). By using tix_getbitmap,
|
using tix_getbitmap, you can avoid hard coding the pathnames of the
|
||||||
you can advoid hard coding the pathnames of
|
bitmap files in your application. When successful, it returns the
|
||||||
the bitmap files in your application. When successful,
|
complete pathname of the bitmap file, prefixed with the character
|
||||||
it returns the complete pathname of the bitmap
|
'@'. The returned value can be used to configure the -bitmap
|
||||||
file, prefixed with the character '@'. The returned
|
option of the TK and Tix widgets.
|
||||||
value can be used to configure the -bitmap option
|
|
||||||
of the TK and Tix widgets.
|
|
||||||
"""
|
"""
|
||||||
return self.tk.call('tix', 'getbitmap', name)
|
return self.tk.call('tix', 'getbitmap', name)
|
||||||
|
|
||||||
def tix_getimage(self, name):
|
def tix_getimage(self, name):
|
||||||
"""Locates an image file of the name name.xpm,
|
"""Locates an image file of the name name.xpm, name.xbm or name.ppm
|
||||||
name.xbm or name.ppm in one of the bitmap directo
|
in one of the bitmap directories (see the addbitmapdir command
|
||||||
ries (see the addbitmapdir command above). If more
|
above). If more than one file with the same name (but different
|
||||||
than one file with the same name (but different
|
extensions) exist, then the image type is chosen according to the
|
||||||
extensions) exist, then the image type is chosen
|
depth of the X display: xbm images are chosen on monochrome
|
||||||
according to the depth of the X display: xbm images
|
displays and color images are chosen on color displays. By using
|
||||||
are chosen on monochrome displays and color images
|
tix_ getimage, you can advoid hard coding the pathnames of the
|
||||||
are chosen on color displays. By using tix getim
|
image files in your application. When successful, this command
|
||||||
age, you can advoid hard coding the pathnames of
|
returns the name of the newly created image, which can be used to
|
||||||
the image files in your application. When success
|
configure the -image option of the Tk and Tix widgets.
|
||||||
ful, this command returns the name of the newly
|
|
||||||
created image, which can be used to configure the
|
|
||||||
-image option of the TK and Tix widgets.
|
|
||||||
"""
|
"""
|
||||||
return self.tk.call('tix', 'getimage', name)
|
return self.tk.call('tix', 'getimage', name)
|
||||||
|
|
||||||
def tix_option_get(self, name):
|
def tix_option_get(self, name):
|
||||||
"""Gets the options manitained by the Tix
|
"""Gets the options manitained by the Tix
|
||||||
scheme mechanism. Available options are:
|
scheme mechanism. Available options include:
|
||||||
|
|
||||||
active_bg active_fg bg
|
active_bg active_fg bg
|
||||||
bold_font dark1_bg dark1_fg
|
bold_font dark1_bg dark1_fg
|
||||||
|
|
@ -169,21 +176,19 @@ class tixCommand:
|
||||||
return self.tk.call('tix', 'option', 'get', name)
|
return self.tk.call('tix', 'option', 'get', name)
|
||||||
|
|
||||||
def tix_resetoptions(self, newScheme, newFontSet, newScmPrio=None):
|
def tix_resetoptions(self, newScheme, newFontSet, newScmPrio=None):
|
||||||
"""Resets the scheme and fontset of the Tix application
|
"""Resets the scheme and fontset of the Tix application to
|
||||||
to newScheme and newFontSet, respectively.
|
newScheme and newFontSet, respectively. This affects only those
|
||||||
This affects only those widgets created after this
|
widgets created after this call. Therefore, it is best to call the
|
||||||
call. Therefore, it is best to call the resetop
|
resetoptions command before the creation of any widgets in a Tix
|
||||||
tions command before the creation of any widgets in
|
application.
|
||||||
a Tix application.
|
|
||||||
|
|
||||||
The optional parameter newScmPrio can be given to
|
The optional parameter newScmPrio can be given to reset the
|
||||||
reset the priority level of the TK options set by
|
priority level of the Tk options set by the Tix schemes.
|
||||||
the Tix schemes.
|
|
||||||
|
|
||||||
Because of the way TK handles the X option database, after
|
Because of the way Tk handles the X option database, after Tix has
|
||||||
tixwish has started up, it is not possible to reset the
|
been has imported and inited, it is not possible to reset the color
|
||||||
color schemes and font sets using the tix config command.
|
schemes and font sets using the tix config command. Instead, the
|
||||||
Instead, the tix resetoptions command must be used.
|
tix_resetoptions command must be used.
|
||||||
"""
|
"""
|
||||||
if newScmPrio is not None:
|
if newScmPrio is not None:
|
||||||
return self.tk.call('tix', 'resetoptions', newScheme, newFontSet, newScmPrio)
|
return self.tk.call('tix', 'resetoptions', newScheme, newFontSet, newScmPrio)
|
||||||
|
|
@ -203,7 +208,7 @@ class Tk(Tkinter.Tk, tixCommand):
|
||||||
# Load Tix - this should work dynamically or statically
|
# Load Tix - this should work dynamically or statically
|
||||||
# If it's static, lib/tix8.1/pkgIndex.tcl should have
|
# If it's static, lib/tix8.1/pkgIndex.tcl should have
|
||||||
# 'load {} Tix'
|
# 'load {} Tix'
|
||||||
# If it's dynamic, lib/tix8.1/pkgIndex.tcl should have
|
# If it's dynamic under Unix, lib/tix8.1/pkgIndex.tcl should have
|
||||||
# 'load libtix8.1.8.3.so Tix'
|
# 'load libtix8.1.8.3.so Tix'
|
||||||
self.tk.eval('package require Tix')
|
self.tk.eval('package require Tix')
|
||||||
|
|
||||||
|
|
@ -362,9 +367,9 @@ class TixWidget(Tkinter.Widget):
|
||||||
"""Set configuration options for all subwidgets (and self)."""
|
"""Set configuration options for all subwidgets (and self)."""
|
||||||
if option == '':
|
if option == '':
|
||||||
return
|
return
|
||||||
elif type(option) != type(''):
|
elif not isinstance(option, StringType):
|
||||||
option = `option`
|
option = `option`
|
||||||
if type(value) != type(''):
|
if not isinstance(value, StringType):
|
||||||
value = `value`
|
value = `value`
|
||||||
names = self._subwidget_names()
|
names = self._subwidget_names()
|
||||||
for name in names:
|
for name in names:
|
||||||
|
|
@ -485,17 +490,18 @@ class Balloon(TixWidget):
|
||||||
|
|
||||||
Subwidget Class
|
Subwidget Class
|
||||||
--------- -----
|
--------- -----
|
||||||
label Label
|
label Label
|
||||||
message Message"""
|
message Message"""
|
||||||
|
|
||||||
def __init__(self, master=None, cnf={}, **kw):
|
def __init__(self, master=None, cnf={}, **kw):
|
||||||
# static seem to be -installcolormap -initwait -statusbar -cursor
|
# static seem to be -installcolormap -initwait -statusbar -cursor
|
||||||
static = ['options', 'installcolormap', 'initwait', 'statusbar', 'cursor']
|
static = ['options', 'installcolormap', 'initwait', 'statusbar',
|
||||||
|
'cursor']
|
||||||
TixWidget.__init__(self, master, 'tixBalloon', static, cnf, kw)
|
TixWidget.__init__(self, master, 'tixBalloon', static, cnf, kw)
|
||||||
self.subwidget_list['label'] = _dummyLabel(self, 'label',
|
self.subwidget_list['label'] = _dummyLabel(self, 'label',
|
||||||
destroy_physically=0)
|
destroy_physically=0)
|
||||||
self.subwidget_list['message'] = _dummyLabel(self, 'message',
|
self.subwidget_list['message'] = _dummyLabel(self, 'message',
|
||||||
destroy_physically=0)
|
destroy_physically=0)
|
||||||
|
|
||||||
def bind_widget(self, widget, cnf={}, **kw):
|
def bind_widget(self, widget, cnf={}, **kw):
|
||||||
"""Bind balloon widget to another.
|
"""Bind balloon widget to another.
|
||||||
|
|
@ -512,13 +518,13 @@ class ButtonBox(TixWidget):
|
||||||
"""
|
"""
|
||||||
def __init__(self, master=None, cnf={}, **kw):
|
def __init__(self, master=None, cnf={}, **kw):
|
||||||
TixWidget.__init__(self, master, 'tixButtonBox',
|
TixWidget.__init__(self, master, 'tixButtonBox',
|
||||||
['orientation', 'options'], cnf, kw)
|
['orientation', 'options'], cnf, kw)
|
||||||
|
|
||||||
def add(self, name, cnf={}, **kw):
|
def add(self, name, cnf={}, **kw):
|
||||||
"""Add a button with given name to box."""
|
"""Add a button with given name to box."""
|
||||||
|
|
||||||
btn = apply(self.tk.call,
|
btn = apply(self.tk.call,
|
||||||
(self._w, 'add', name) + self._options(cnf, kw))
|
(self._w, 'add', name) + self._options(cnf, kw))
|
||||||
self.subwidget_list[name] = _dummyButton(self, name)
|
self.subwidget_list[name] = _dummyButton(self, name)
|
||||||
return btn
|
return btn
|
||||||
|
|
||||||
|
|
@ -541,13 +547,13 @@ class ComboBox(TixWidget):
|
||||||
|
|
||||||
def __init__ (self, master=None, cnf={}, **kw):
|
def __init__ (self, master=None, cnf={}, **kw):
|
||||||
TixWidget.__init__(self, master, 'tixComboBox',
|
TixWidget.__init__(self, master, 'tixComboBox',
|
||||||
['editable', 'dropdown', 'fancy', 'options'],
|
['editable', 'dropdown', 'fancy', 'options'],
|
||||||
cnf, kw)
|
cnf, kw)
|
||||||
self.subwidget_list['label'] = _dummyLabel(self, 'label')
|
self.subwidget_list['label'] = _dummyLabel(self, 'label')
|
||||||
self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
|
self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
|
||||||
self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
|
self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
|
||||||
self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
|
self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
|
||||||
'slistbox')
|
'slistbox')
|
||||||
try:
|
try:
|
||||||
self.subwidget_list['tick'] = _dummyButton(self, 'tick')
|
self.subwidget_list['tick'] = _dummyButton(self, 'tick')
|
||||||
self.subwidget_list['cross'] = _dummyButton(self, 'cross')
|
self.subwidget_list['cross'] = _dummyButton(self, 'cross')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue