configspecs.html

来自「perl教程」· HTML 代码 · 共 338 行 · 第 1/2 页

HTML
338 行
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Tk::ConfigSpecs - Defining behaviour of 'configure' for composite widgets.</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>Tk::ConfigSpecs - Defining behaviour of 'configure' for composite widgets.</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<ul>

		<li><a href="#defining_the_configspecs_for_a_class_">Defining the ConfigSpecs for a class.</a></li>
		<li><a href="#delegating_all_options_of_a_widget_class_to_a_subwidget">Delegating all options of a widget class to a subwidget</a></li>
		<li><a href="#default_values">Default values</a></li>
		<li><a href="#new__time_configure"><strong>New()-time configure</strong></a></li>
		<li><a href="#configuring_composites">Configuring composites</a></li>
		<li><a href="#inquiring_attributes_of_composites">Inquiring attributes of composites</a></li>
	</ul>

	<li><a href="#caveats">CAVEATS</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Tk::ConfigSpecs - Defining behaviour of 'configure' for composite widgets.</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
    <span class="keyword">sub</span><span class="variable"> Populate
    </span><span class="operator">{</span>
     <span class="keyword">my</span> <span class="operator">(</span><span class="variable">$composite</span><span class="operator">,</span><span class="variable">$args</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">@_</span><span class="operator">;</span>
     <span class="operator">...</span>
     <span class="variable">$composite</span><span class="operator">-&gt;</span><span class="variable">ConfigSpecs</span><span class="operator">(</span><span class="string">'-attribute'</span> <span class="operator">=&gt;</span> <span class="operator">[</span> <span class="variable">where</span><span class="operator">,</span><span class="variable">dbName</span><span class="operator">,</span><span class="variable">dbClass</span><span class="operator">,</span><span class="variable">default</span> <span class="operator">]</span><span class="operator">);</span>
     <span class="variable">$composite</span><span class="operator">-&gt;</span><span class="variable">ConfigSpecs</span><span class="operator">(</span><span class="string">'-alias'</span> <span class="operator">=&gt;</span> <span class="string">'-otherattribute'</span><span class="operator">);</span>
     <span class="variable">$composite</span><span class="operator">-&gt;</span><span class="variable">ConfigSpecs</span><span class="operator">(</span><span class="string">'DEFAULT'</span> <span class="operator">=&gt;</span> <span class="operator">[</span> <span class="variable">where</span> <span class="operator">]</span><span class="operator">);</span>
     <span class="variable">$composite</span><span class="operator">-&gt;</span><span class="variable">ConfigSpecs</span><span class="operator">(</span><span class="variable">$subwidget</span><span class="operator">-&gt;</span><span class="variable">ConfigSpecs</span><span class="operator">);</span>
     <span class="operator">...</span>
    <span class="operator">}</span>
</pre>
<pre>
    <span class="variable">$composite</span><span class="operator">-&gt;</span><span class="variable">configure</span><span class="operator">(</span><span class="string">-attribute</span> <span class="operator">=&gt;</span> <span class="variable">value</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The aim is to make the composite widget configure method look as much like
a regular Tk widget's configure as possible.
(See <a href="../../lib/Tk/options.html">the Tk::options manpage</a> for a description of this behaviour.)
To enable this the attributes that the composite as a whole accepts
needs to be defined.</p>
<p>
</p>
<h2><a name="defining_the_configspecs_for_a_class_">Defining the ConfigSpecs for a class.</a></h2>
<p>Typically a widget will have one or more calls like the following</p>
<pre>
    <span class="variable">$composite</span><span class="operator">-&gt;</span><span class="variable">ConfigSpecs</span><span class="operator">(</span><span class="string">-attribute</span> <span class="operator">=&gt;</span> <span class="operator">[</span><span class="variable">where</span><span class="operator">,</span><span class="variable">dbName</span><span class="operator">,</span><span class="variable">dbClass</span><span class="operator">,</span><span class="variable">default</span><span class="operator">]</span><span class="operator">);</span>
</pre>
<p>in its <strong>Populate</strong> method. When <strong>ConfigSpecs</strong> is called this way
(with arguments) the arguments are used to construct or augment/replace
a hash table for the widget. (More than one <em>-option</em>=&gt;<em>value</em>
pair can be specified to a single call.)</p>
<p><strong>dbName</strong>, <strong>dbClass</strong> and default are only used by <strong>ConfigDefault</strong> described
below, or to respond to 'inquiry' configure commands.</p>
<p>It may be either one of the values below, or a list of such values
enclosed in <strong>[]</strong>.</p>
<p>The currently permitted values of <strong>where</strong> are:</p>
<dl>
<dt><strong><a name="item__27advertised_27"><strong>'ADVERTISED'</strong></a></strong>

<dd>
<p>Apply <strong>configure</strong> to <em>advertised</em> subwidgets.</p>
</dd>
</li>
<dt><strong><a name="item__27descendants_27"><strong>'DESCENDANTS'</strong></a></strong>

<dd>
<p>Apply <strong>configure</strong> recursively to all descendants.</p>
</dd>
</li>
<dt><strong><a name="item__27callback_27"><strong>'CALLBACK'</strong></a></strong>

<dd>
<p>Setting the attribute does <code>Tk::Callback-&gt;new($value)</code> before storing
in <code>$composite-&gt;{Configure}{-attribute}</code>. This is appropriate for
<code>-command =&gt; ...</code> attributes that are handled by the composite and not
forwarded to a subwidget. (E.g. <strong>Tk::Tiler</strong> has <code>-yscrollcommand</code> to
allow it to have scrollbar attached.)</p>
</dd>
<dd>
<p>This may be the first of several 'validating' keywords (e.g. font, cursor,
anchor etc.) that core Tk makes special for C code.</p>
</dd>
</li>
<dt><strong><a name="item__27children_27"><strong>'CHILDREN'</strong></a></strong>

<dd>
<p>Apply <strong>configure</strong> to all children.  (Children are the immediate
descendants of a widget.)</p>
</dd>
</li>
<dt><strong><a name="item__27method_27"><strong>'METHOD'</strong></a></strong>

<dd>
<p>Call <code>$cw-&gt;attribute(value)</code></p>
</dd>
<dd>
<p>This is the most general case. Simply have a method of the composite
class with the same name as the attribute.  The method may do any
validation and have whatever side-effects you like.  (It is probably
worth 'queueing' using <strong>afterIdle</strong> for more complex side-effects.)</p>
</dd>
</li>
<dt><strong><a name="item__27passive_27"><strong>'PASSIVE'</strong></a></strong>

<dd>
<p>Simply store value in <code>$composite-&gt;{Configure}{-attribute}</code>.</p>
</dd>
<dd>
<p>This form is also a useful placeholder for attributes which you
currently only handle at create time.</p>
</dd>
</li>
<dt><strong><a name="item__27self_27"><strong>'SELF'</strong></a></strong>

<dd>
<p>Apply <strong>configure</strong> to the core widget (e.g. <strong>Frame</strong>) that is the basis of
the composite. (This is the default behaviour for most attributes which
makes a simple Frame behave the way you would expect.) Note that once
you have specified <strong>ConfigSpecs</strong> for an attribute you must explicitly
include <a href="#item__27self_27"><code>'SELF'</code></a> in the list if you want the attribute to apply to the
composite itself (this avoids nasty infinite recursion problems).</p>
</dd>
</li>
<dt><strong><a name="item_reference"><strong>$reference</strong> (blessed)</a></strong>

<dd>
<p>Call <strong>$reference</strong>-&gt;configure(-attribute =&gt; value)</p>
</dd>
<dd>
<p>A common case is where <strong>$reference</strong> is a subwidget.</p>
</dd>
<dd>
<p>$reference may also be result of</p>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?