Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3..../tkinter
File: tix.py
# Tix.py -- Tix widget wrappers.
[0] Fix | Delete
#
[1] Fix | Delete
# For Tix, see http://tix.sourceforge.net
[2] Fix | Delete
#
[3] Fix | Delete
# - Sudhir Shenoy (sshenoy@gol.com), Dec. 1995.
[4] Fix | Delete
# based on an idea of Jean-Marc Lugrin (lugrin@ms.com)
[5] Fix | Delete
#
[6] Fix | Delete
# NOTE: In order to minimize changes to Tkinter.py, some of the code here
[7] Fix | Delete
# (TixWidget.__init__) has been taken from Tkinter (Widget.__init__)
[8] Fix | Delete
# and will break if there are major changes in Tkinter.
[9] Fix | Delete
#
[10] Fix | Delete
# The Tix widgets are represented by a class hierarchy in python with proper
[11] Fix | Delete
# inheritance of base classes.
[12] Fix | Delete
#
[13] Fix | Delete
# As a result after creating a 'w = StdButtonBox', I can write
[14] Fix | Delete
# w.ok['text'] = 'Who Cares'
[15] Fix | Delete
# or w.ok['bg'] = w['bg']
[16] Fix | Delete
# or even w.ok.invoke()
[17] Fix | Delete
# etc.
[18] Fix | Delete
#
[19] Fix | Delete
# Compare the demo tixwidgets.py to the original Tcl program and you will
[20] Fix | Delete
# appreciate the advantages.
[21] Fix | Delete
#
[22] Fix | Delete
[23] Fix | Delete
import os
[24] Fix | Delete
import tkinter
[25] Fix | Delete
from tkinter import *
[26] Fix | Delete
from tkinter import _cnfmerge
[27] Fix | Delete
[28] Fix | Delete
import _tkinter # If this fails your Python may not be configured for Tk
[29] Fix | Delete
[30] Fix | Delete
# Some more constants (for consistency with Tkinter)
[31] Fix | Delete
WINDOW = 'window'
[32] Fix | Delete
TEXT = 'text'
[33] Fix | Delete
STATUS = 'status'
[34] Fix | Delete
IMMEDIATE = 'immediate'
[35] Fix | Delete
IMAGE = 'image'
[36] Fix | Delete
IMAGETEXT = 'imagetext'
[37] Fix | Delete
BALLOON = 'balloon'
[38] Fix | Delete
AUTO = 'auto'
[39] Fix | Delete
ACROSSTOP = 'acrosstop'
[40] Fix | Delete
[41] Fix | Delete
# A few useful constants for the Grid widget
[42] Fix | Delete
ASCII = 'ascii'
[43] Fix | Delete
CELL = 'cell'
[44] Fix | Delete
COLUMN = 'column'
[45] Fix | Delete
DECREASING = 'decreasing'
[46] Fix | Delete
INCREASING = 'increasing'
[47] Fix | Delete
INTEGER = 'integer'
[48] Fix | Delete
MAIN = 'main'
[49] Fix | Delete
MAX = 'max'
[50] Fix | Delete
REAL = 'real'
[51] Fix | Delete
ROW = 'row'
[52] Fix | Delete
S_REGION = 's-region'
[53] Fix | Delete
X_REGION = 'x-region'
[54] Fix | Delete
Y_REGION = 'y-region'
[55] Fix | Delete
[56] Fix | Delete
# Some constants used by Tkinter dooneevent()
[57] Fix | Delete
TCL_DONT_WAIT = 1 << 1
[58] Fix | Delete
TCL_WINDOW_EVENTS = 1 << 2
[59] Fix | Delete
TCL_FILE_EVENTS = 1 << 3
[60] Fix | Delete
TCL_TIMER_EVENTS = 1 << 4
[61] Fix | Delete
TCL_IDLE_EVENTS = 1 << 5
[62] Fix | Delete
TCL_ALL_EVENTS = 0
[63] Fix | Delete
[64] Fix | Delete
# BEWARE - this is implemented by copying some code from the Widget class
[65] Fix | Delete
# in Tkinter (to override Widget initialization) and is therefore
[66] Fix | Delete
# liable to break.
[67] Fix | Delete
[68] Fix | Delete
# Could probably add this to Tkinter.Misc
[69] Fix | Delete
class tixCommand:
[70] Fix | Delete
"""The tix commands provide access to miscellaneous elements
[71] Fix | Delete
of Tix's internal state and the Tix application context.
[72] Fix | Delete
Most of the information manipulated by these commands pertains
[73] Fix | Delete
to the application as a whole, or to a screen or
[74] Fix | Delete
display, rather than to a particular window.
[75] Fix | Delete
[76] Fix | Delete
This is a mixin class, assumed to be mixed to Tkinter.Tk
[77] Fix | Delete
that supports the self.tk.call method.
[78] Fix | Delete
"""
[79] Fix | Delete
[80] Fix | Delete
def tix_addbitmapdir(self, directory):
[81] Fix | Delete
"""Tix maintains a list of directories under which
[82] Fix | Delete
the tix_getimage and tix_getbitmap commands will
[83] Fix | Delete
search for image files. The standard bitmap directory
[84] Fix | Delete
is $TIX_LIBRARY/bitmaps. The addbitmapdir command
[85] Fix | Delete
adds directory into this list. By using this
[86] Fix | Delete
command, the image files of an applications can
[87] Fix | Delete
also be located using the tix_getimage or tix_getbitmap
[88] Fix | Delete
command.
[89] Fix | Delete
"""
[90] Fix | Delete
return self.tk.call('tix', 'addbitmapdir', directory)
[91] Fix | Delete
[92] Fix | Delete
def tix_cget(self, option):
[93] Fix | Delete
"""Returns the current value of the configuration
[94] Fix | Delete
option given by option. Option may be any of the
[95] Fix | Delete
options described in the CONFIGURATION OPTIONS section.
[96] Fix | Delete
"""
[97] Fix | Delete
return self.tk.call('tix', 'cget', option)
[98] Fix | Delete
[99] Fix | Delete
def tix_configure(self, cnf=None, **kw):
[100] Fix | Delete
"""Query or modify the configuration options of the Tix application
[101] Fix | Delete
context. If no option is specified, returns a dictionary all of the
[102] Fix | Delete
available options. If option is specified with no value, then the
[103] Fix | Delete
command returns a list describing the one named option (this list
[104] Fix | Delete
will be identical to the corresponding sublist of the value
[105] Fix | Delete
returned if no option is specified). If one or more option-value
[106] Fix | Delete
pairs are specified, then the command modifies the given option(s)
[107] Fix | Delete
to have the given value(s); in this case the command returns an
[108] Fix | Delete
empty string. Option may be any of the configuration options.
[109] Fix | Delete
"""
[110] Fix | Delete
# Copied from Tkinter.py
[111] Fix | Delete
if kw:
[112] Fix | Delete
cnf = _cnfmerge((cnf, kw))
[113] Fix | Delete
elif cnf:
[114] Fix | Delete
cnf = _cnfmerge(cnf)
[115] Fix | Delete
if cnf is None:
[116] Fix | Delete
return self._getconfigure('tix', 'configure')
[117] Fix | Delete
if isinstance(cnf, str):
[118] Fix | Delete
return self._getconfigure1('tix', 'configure', '-'+cnf)
[119] Fix | Delete
return self.tk.call(('tix', 'configure') + self._options(cnf))
[120] Fix | Delete
[121] Fix | Delete
def tix_filedialog(self, dlgclass=None):
[122] Fix | Delete
"""Returns the file selection dialog that may be shared among
[123] Fix | Delete
different calls from this application. This command will create a
[124] Fix | Delete
file selection dialog widget when it is called the first time. This
[125] Fix | Delete
dialog will be returned by all subsequent calls to tix_filedialog.
[126] Fix | Delete
An optional dlgclass parameter can be passed to specified what type
[127] Fix | Delete
of file selection dialog widget is desired. Possible options are
[128] Fix | Delete
tix FileSelectDialog or tixExFileSelectDialog.
[129] Fix | Delete
"""
[130] Fix | Delete
if dlgclass is not None:
[131] Fix | Delete
return self.tk.call('tix', 'filedialog', dlgclass)
[132] Fix | Delete
else:
[133] Fix | Delete
return self.tk.call('tix', 'filedialog')
[134] Fix | Delete
[135] Fix | Delete
def tix_getbitmap(self, name):
[136] Fix | Delete
"""Locates a bitmap file of the name name.xpm or name in one of the
[137] Fix | Delete
bitmap directories (see the tix_addbitmapdir command above). By
[138] Fix | Delete
using tix_getbitmap, you can avoid hard coding the pathnames of the
[139] Fix | Delete
bitmap files in your application. When successful, it returns the
[140] Fix | Delete
complete pathname of the bitmap file, prefixed with the character
[141] Fix | Delete
'@'. The returned value can be used to configure the -bitmap
[142] Fix | Delete
option of the TK and Tix widgets.
[143] Fix | Delete
"""
[144] Fix | Delete
return self.tk.call('tix', 'getbitmap', name)
[145] Fix | Delete
[146] Fix | Delete
def tix_getimage(self, name):
[147] Fix | Delete
"""Locates an image file of the name name.xpm, name.xbm or name.ppm
[148] Fix | Delete
in one of the bitmap directories (see the addbitmapdir command
[149] Fix | Delete
above). If more than one file with the same name (but different
[150] Fix | Delete
extensions) exist, then the image type is chosen according to the
[151] Fix | Delete
depth of the X display: xbm images are chosen on monochrome
[152] Fix | Delete
displays and color images are chosen on color displays. By using
[153] Fix | Delete
tix_ getimage, you can avoid hard coding the pathnames of the
[154] Fix | Delete
image files in your application. When successful, this command
[155] Fix | Delete
returns the name of the newly created image, which can be used to
[156] Fix | Delete
configure the -image option of the Tk and Tix widgets.
[157] Fix | Delete
"""
[158] Fix | Delete
return self.tk.call('tix', 'getimage', name)
[159] Fix | Delete
[160] Fix | Delete
def tix_option_get(self, name):
[161] Fix | Delete
"""Gets the options maintained by the Tix
[162] Fix | Delete
scheme mechanism. Available options include:
[163] Fix | Delete
[164] Fix | Delete
active_bg active_fg bg
[165] Fix | Delete
bold_font dark1_bg dark1_fg
[166] Fix | Delete
dark2_bg dark2_fg disabled_fg
[167] Fix | Delete
fg fixed_font font
[168] Fix | Delete
inactive_bg inactive_fg input1_bg
[169] Fix | Delete
input2_bg italic_font light1_bg
[170] Fix | Delete
light1_fg light2_bg light2_fg
[171] Fix | Delete
menu_font output1_bg output2_bg
[172] Fix | Delete
select_bg select_fg selector
[173] Fix | Delete
"""
[174] Fix | Delete
# could use self.tk.globalgetvar('tixOption', name)
[175] Fix | Delete
return self.tk.call('tix', 'option', 'get', name)
[176] Fix | Delete
[177] Fix | Delete
def tix_resetoptions(self, newScheme, newFontSet, newScmPrio=None):
[178] Fix | Delete
"""Resets the scheme and fontset of the Tix application to
[179] Fix | Delete
newScheme and newFontSet, respectively. This affects only those
[180] Fix | Delete
widgets created after this call. Therefore, it is best to call the
[181] Fix | Delete
resetoptions command before the creation of any widgets in a Tix
[182] Fix | Delete
application.
[183] Fix | Delete
[184] Fix | Delete
The optional parameter newScmPrio can be given to reset the
[185] Fix | Delete
priority level of the Tk options set by the Tix schemes.
[186] Fix | Delete
[187] Fix | Delete
Because of the way Tk handles the X option database, after Tix has
[188] Fix | Delete
been has imported and inited, it is not possible to reset the color
[189] Fix | Delete
schemes and font sets using the tix config command. Instead, the
[190] Fix | Delete
tix_resetoptions command must be used.
[191] Fix | Delete
"""
[192] Fix | Delete
if newScmPrio is not None:
[193] Fix | Delete
return self.tk.call('tix', 'resetoptions', newScheme, newFontSet, newScmPrio)
[194] Fix | Delete
else:
[195] Fix | Delete
return self.tk.call('tix', 'resetoptions', newScheme, newFontSet)
[196] Fix | Delete
[197] Fix | Delete
class Tk(tkinter.Tk, tixCommand):
[198] Fix | Delete
"""Toplevel widget of Tix which represents mostly the main window
[199] Fix | Delete
of an application. It has an associated Tcl interpreter."""
[200] Fix | Delete
def __init__(self, screenName=None, baseName=None, className='Tix'):
[201] Fix | Delete
tkinter.Tk.__init__(self, screenName, baseName, className)
[202] Fix | Delete
tixlib = os.environ.get('TIX_LIBRARY')
[203] Fix | Delete
self.tk.eval('global auto_path; lappend auto_path [file dir [info nameof]]')
[204] Fix | Delete
if tixlib is not None:
[205] Fix | Delete
self.tk.eval('global auto_path; lappend auto_path {%s}' % tixlib)
[206] Fix | Delete
self.tk.eval('global tcl_pkgPath; lappend tcl_pkgPath {%s}' % tixlib)
[207] Fix | Delete
# Load Tix - this should work dynamically or statically
[208] Fix | Delete
# If it's static, tcl/tix8.1/pkgIndex.tcl should have
[209] Fix | Delete
# 'load {} Tix'
[210] Fix | Delete
# If it's dynamic under Unix, tcl/tix8.1/pkgIndex.tcl should have
[211] Fix | Delete
# 'load libtix8.1.8.3.so Tix'
[212] Fix | Delete
self.tk.eval('package require Tix')
[213] Fix | Delete
[214] Fix | Delete
def destroy(self):
[215] Fix | Delete
# For safety, remove the delete_window binding before destroy
[216] Fix | Delete
self.protocol("WM_DELETE_WINDOW", "")
[217] Fix | Delete
tkinter.Tk.destroy(self)
[218] Fix | Delete
[219] Fix | Delete
# The Tix 'tixForm' geometry manager
[220] Fix | Delete
class Form:
[221] Fix | Delete
"""The Tix Form geometry manager
[222] Fix | Delete
[223] Fix | Delete
Widgets can be arranged by specifying attachments to other widgets.
[224] Fix | Delete
See Tix documentation for complete details"""
[225] Fix | Delete
[226] Fix | Delete
def config(self, cnf={}, **kw):
[227] Fix | Delete
self.tk.call('tixForm', self._w, *self._options(cnf, kw))
[228] Fix | Delete
[229] Fix | Delete
form = config
[230] Fix | Delete
[231] Fix | Delete
def __setitem__(self, key, value):
[232] Fix | Delete
Form.form(self, {key: value})
[233] Fix | Delete
[234] Fix | Delete
def check(self):
[235] Fix | Delete
return self.tk.call('tixForm', 'check', self._w)
[236] Fix | Delete
[237] Fix | Delete
def forget(self):
[238] Fix | Delete
self.tk.call('tixForm', 'forget', self._w)
[239] Fix | Delete
[240] Fix | Delete
def grid(self, xsize=0, ysize=0):
[241] Fix | Delete
if (not xsize) and (not ysize):
[242] Fix | Delete
x = self.tk.call('tixForm', 'grid', self._w)
[243] Fix | Delete
y = self.tk.splitlist(x)
[244] Fix | Delete
z = ()
[245] Fix | Delete
for x in y:
[246] Fix | Delete
z = z + (self.tk.getint(x),)
[247] Fix | Delete
return z
[248] Fix | Delete
return self.tk.call('tixForm', 'grid', self._w, xsize, ysize)
[249] Fix | Delete
[250] Fix | Delete
def info(self, option=None):
[251] Fix | Delete
if not option:
[252] Fix | Delete
return self.tk.call('tixForm', 'info', self._w)
[253] Fix | Delete
if option[0] != '-':
[254] Fix | Delete
option = '-' + option
[255] Fix | Delete
return self.tk.call('tixForm', 'info', self._w, option)
[256] Fix | Delete
[257] Fix | Delete
def slaves(self):
[258] Fix | Delete
return [self._nametowidget(x) for x in
[259] Fix | Delete
self.tk.splitlist(
[260] Fix | Delete
self.tk.call(
[261] Fix | Delete
'tixForm', 'slaves', self._w))]
[262] Fix | Delete
[263] Fix | Delete
[264] Fix | Delete
[265] Fix | Delete
tkinter.Widget.__bases__ = tkinter.Widget.__bases__ + (Form,)
[266] Fix | Delete
[267] Fix | Delete
class TixWidget(tkinter.Widget):
[268] Fix | Delete
"""A TixWidget class is used to package all (or most) Tix widgets.
[269] Fix | Delete
[270] Fix | Delete
Widget initialization is extended in two ways:
[271] Fix | Delete
1) It is possible to give a list of options which must be part of
[272] Fix | Delete
the creation command (so called Tix 'static' options). These cannot be
[273] Fix | Delete
given as a 'config' command later.
[274] Fix | Delete
2) It is possible to give the name of an existing TK widget. These are
[275] Fix | Delete
child widgets created automatically by a Tix mega-widget. The Tk call
[276] Fix | Delete
to create these widgets is therefore bypassed in TixWidget.__init__
[277] Fix | Delete
[278] Fix | Delete
Both options are for use by subclasses only.
[279] Fix | Delete
"""
[280] Fix | Delete
def __init__ (self, master=None, widgetName=None,
[281] Fix | Delete
static_options=None, cnf={}, kw={}):
[282] Fix | Delete
# Merge keywords and dictionary arguments
[283] Fix | Delete
if kw:
[284] Fix | Delete
cnf = _cnfmerge((cnf, kw))
[285] Fix | Delete
else:
[286] Fix | Delete
cnf = _cnfmerge(cnf)
[287] Fix | Delete
[288] Fix | Delete
# Move static options into extra. static_options must be
[289] Fix | Delete
# a list of keywords (or None).
[290] Fix | Delete
extra=()
[291] Fix | Delete
[292] Fix | Delete
# 'options' is always a static option
[293] Fix | Delete
if static_options:
[294] Fix | Delete
static_options.append('options')
[295] Fix | Delete
else:
[296] Fix | Delete
static_options = ['options']
[297] Fix | Delete
[298] Fix | Delete
for k,v in list(cnf.items()):
[299] Fix | Delete
if k in static_options:
[300] Fix | Delete
extra = extra + ('-' + k, v)
[301] Fix | Delete
del cnf[k]
[302] Fix | Delete
[303] Fix | Delete
self.widgetName = widgetName
[304] Fix | Delete
Widget._setup(self, master, cnf)
[305] Fix | Delete
[306] Fix | Delete
# If widgetName is None, this is a dummy creation call where the
[307] Fix | Delete
# corresponding Tk widget has already been created by Tix
[308] Fix | Delete
if widgetName:
[309] Fix | Delete
self.tk.call(widgetName, self._w, *extra)
[310] Fix | Delete
[311] Fix | Delete
# Non-static options - to be done via a 'config' command
[312] Fix | Delete
if cnf:
[313] Fix | Delete
Widget.config(self, cnf)
[314] Fix | Delete
[315] Fix | Delete
# Dictionary to hold subwidget names for easier access. We can't
[316] Fix | Delete
# use the children list because the public Tix names may not be the
[317] Fix | Delete
# same as the pathname component
[318] Fix | Delete
self.subwidget_list = {}
[319] Fix | Delete
[320] Fix | Delete
# We set up an attribute access function so that it is possible to
[321] Fix | Delete
# do w.ok['text'] = 'Hello' rather than w.subwidget('ok')['text'] = 'Hello'
[322] Fix | Delete
# when w is a StdButtonBox.
[323] Fix | Delete
# We can even do w.ok.invoke() because w.ok is subclassed from the
[324] Fix | Delete
# Button class if you go through the proper constructors
[325] Fix | Delete
def __getattr__(self, name):
[326] Fix | Delete
if name in self.subwidget_list:
[327] Fix | Delete
return self.subwidget_list[name]
[328] Fix | Delete
raise AttributeError(name)
[329] Fix | Delete
[330] Fix | Delete
def set_silent(self, value):
[331] Fix | Delete
"""Set a variable without calling its action routine"""
[332] Fix | Delete
self.tk.call('tixSetSilent', self._w, value)
[333] Fix | Delete
[334] Fix | Delete
def subwidget(self, name):
[335] Fix | Delete
"""Return the named subwidget (which must have been created by
[336] Fix | Delete
the sub-class)."""
[337] Fix | Delete
n = self._subwidget_name(name)
[338] Fix | Delete
if not n:
[339] Fix | Delete
raise TclError("Subwidget " + name + " not child of " + self._name)
[340] Fix | Delete
# Remove header of name and leading dot
[341] Fix | Delete
n = n[len(self._w)+1:]
[342] Fix | Delete
return self._nametowidget(n)
[343] Fix | Delete
[344] Fix | Delete
def subwidgets_all(self):
[345] Fix | Delete
"""Return all subwidgets."""
[346] Fix | Delete
names = self._subwidget_names()
[347] Fix | Delete
if not names:
[348] Fix | Delete
return []
[349] Fix | Delete
retlist = []
[350] Fix | Delete
for name in names:
[351] Fix | Delete
name = name[len(self._w)+1:]
[352] Fix | Delete
try:
[353] Fix | Delete
retlist.append(self._nametowidget(name))
[354] Fix | Delete
except:
[355] Fix | Delete
# some of the widgets are unknown e.g. border in LabelFrame
[356] Fix | Delete
pass
[357] Fix | Delete
return retlist
[358] Fix | Delete
[359] Fix | Delete
def _subwidget_name(self,name):
[360] Fix | Delete
"""Get a subwidget name (returns a String, not a Widget !)"""
[361] Fix | Delete
try:
[362] Fix | Delete
return self.tk.call(self._w, 'subwidget', name)
[363] Fix | Delete
except TclError:
[364] Fix | Delete
return None
[365] Fix | Delete
[366] Fix | Delete
def _subwidget_names(self):
[367] Fix | Delete
"""Return the name of all subwidgets."""
[368] Fix | Delete
try:
[369] Fix | Delete
x = self.tk.call(self._w, 'subwidgets', '-all')
[370] Fix | Delete
return self.tk.splitlist(x)
[371] Fix | Delete
except TclError:
[372] Fix | Delete
return None
[373] Fix | Delete
[374] Fix | Delete
def config_all(self, option, value):
[375] Fix | Delete
"""Set configuration options for all subwidgets (and self)."""
[376] Fix | Delete
if option == '':
[377] Fix | Delete
return
[378] Fix | Delete
elif not isinstance(option, str):
[379] Fix | Delete
option = repr(option)
[380] Fix | Delete
if not isinstance(value, str):
[381] Fix | Delete
value = repr(value)
[382] Fix | Delete
names = self._subwidget_names()
[383] Fix | Delete
for name in names:
[384] Fix | Delete
self.tk.call(name, 'configure', '-' + option, value)
[385] Fix | Delete
# These are missing from Tkinter
[386] Fix | Delete
def image_create(self, imgtype, cnf={}, master=None, **kw):
[387] Fix | Delete
if not master:
[388] Fix | Delete
master = self
[389] Fix | Delete
if kw and cnf: cnf = _cnfmerge((cnf, kw))
[390] Fix | Delete
elif kw: cnf = kw
[391] Fix | Delete
options = ()
[392] Fix | Delete
for k, v in cnf.items():
[393] Fix | Delete
if callable(v):
[394] Fix | Delete
v = self._register(v)
[395] Fix | Delete
options = options + ('-'+k, v)
[396] Fix | Delete
return master.tk.call(('image', 'create', imgtype,) + options)
[397] Fix | Delete
def image_delete(self, imgname):
[398] Fix | Delete
try:
[399] Fix | Delete
self.tk.call('image', 'delete', imgname)
[400] Fix | Delete
except TclError:
[401] Fix | Delete
# May happen if the root was destroyed
[402] Fix | Delete
pass
[403] Fix | Delete
[404] Fix | Delete
# Subwidgets are child widgets created automatically by mega-widgets.
[405] Fix | Delete
# In python, we have to create these subwidgets manually to mirror their
[406] Fix | Delete
# existence in Tk/Tix.
[407] Fix | Delete
class TixSubWidget(TixWidget):
[408] Fix | Delete
"""Subwidget class.
[409] Fix | Delete
[410] Fix | Delete
This is used to mirror child widgets automatically created
[411] Fix | Delete
by Tix/Tk as part of a mega-widget in Python (which is not informed
[412] Fix | Delete
of this)"""
[413] Fix | Delete
[414] Fix | Delete
def __init__(self, master, name,
[415] Fix | Delete
destroy_physically=1, check_intermediate=1):
[416] Fix | Delete
if check_intermediate:
[417] Fix | Delete
path = master._subwidget_name(name)
[418] Fix | Delete
try:
[419] Fix | Delete
path = path[len(master._w)+1:]
[420] Fix | Delete
plist = path.split('.')
[421] Fix | Delete
except:
[422] Fix | Delete
plist = []
[423] Fix | Delete
[424] Fix | Delete
if not check_intermediate:
[425] Fix | Delete
# immediate descendant
[426] Fix | Delete
TixWidget.__init__(self, master, None, None, {'name' : name})
[427] Fix | Delete
else:
[428] Fix | Delete
# Ensure that the intermediate widgets exist
[429] Fix | Delete
parent = master
[430] Fix | Delete
for i in range(len(plist) - 1):
[431] Fix | Delete
n = '.'.join(plist[:i+1])
[432] Fix | Delete
try:
[433] Fix | Delete
w = master._nametowidget(n)
[434] Fix | Delete
parent = w
[435] Fix | Delete
except KeyError:
[436] Fix | Delete
# Create the intermediate widget
[437] Fix | Delete
parent = TixSubWidget(parent, plist[i],
[438] Fix | Delete
destroy_physically=0,
[439] Fix | Delete
check_intermediate=0)
[440] Fix | Delete
# The Tk widget name is in plist, not in name
[441] Fix | Delete
if plist:
[442] Fix | Delete
name = plist[-1]
[443] Fix | Delete
TixWidget.__init__(self, parent, None, None, {'name' : name})
[444] Fix | Delete
self.destroy_physically = destroy_physically
[445] Fix | Delete
[446] Fix | Delete
def destroy(self):
[447] Fix | Delete
# For some widgets e.g., a NoteBook, when we call destructors,
[448] Fix | Delete
# we must be careful not to destroy the frame widget since this
[449] Fix | Delete
# also destroys the parent NoteBook thus leading to an exception
[450] Fix | Delete
# in Tkinter when it finally calls Tcl to destroy the NoteBook
[451] Fix | Delete
for c in list(self.children.values()): c.destroy()
[452] Fix | Delete
if self._name in self.master.children:
[453] Fix | Delete
del self.master.children[self._name]
[454] Fix | Delete
if self._name in self.master.subwidget_list:
[455] Fix | Delete
del self.master.subwidget_list[self._name]
[456] Fix | Delete
if self.destroy_physically:
[457] Fix | Delete
# This is bypassed only for a few widgets
[458] Fix | Delete
self.tk.call('destroy', self._w)
[459] Fix | Delete
[460] Fix | Delete
[461] Fix | Delete
# Useful class to create a display style - later shared by many items.
[462] Fix | Delete
# Contributed by Steffen Kremser
[463] Fix | Delete
class DisplayStyle:
[464] Fix | Delete
"""DisplayStyle - handle configuration options shared by
[465] Fix | Delete
(multiple) Display Items"""
[466] Fix | Delete
[467] Fix | Delete
def __init__(self, itemtype, cnf={}, *, master=None, **kw):
[468] Fix | Delete
if not master:
[469] Fix | Delete
if 'refwindow' in kw:
[470] Fix | Delete
master = kw['refwindow']
[471] Fix | Delete
elif 'refwindow' in cnf:
[472] Fix | Delete
master = cnf['refwindow']
[473] Fix | Delete
else:
[474] Fix | Delete
master = tkinter._get_default_root('create display style')
[475] Fix | Delete
self.tk = master.tk
[476] Fix | Delete
self.stylename = self.tk.call('tixDisplayStyle', itemtype,
[477] Fix | Delete
*self._options(cnf,kw) )
[478] Fix | Delete
[479] Fix | Delete
def __str__(self):
[480] Fix | Delete
return self.stylename
[481] Fix | Delete
[482] Fix | Delete
def _options(self, cnf, kw):
[483] Fix | Delete
if kw and cnf:
[484] Fix | Delete
cnf = _cnfmerge((cnf, kw))
[485] Fix | Delete
elif kw:
[486] Fix | Delete
cnf = kw
[487] Fix | Delete
opts = ()
[488] Fix | Delete
for k, v in cnf.items():
[489] Fix | Delete
opts = opts + ('-'+k, v)
[490] Fix | Delete
return opts
[491] Fix | Delete
[492] Fix | Delete
def delete(self):
[493] Fix | Delete
self.tk.call(self.stylename, 'delete')
[494] Fix | Delete
[495] Fix | Delete
def __setitem__(self,key,value):
[496] Fix | Delete
self.tk.call(self.stylename, 'configure', '-%s'%key, value)
[497] Fix | Delete
[498] Fix | Delete
def config(self, cnf={}, **kw):
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function