summaryrefslogtreecommitdiffstats
path: root/Lib/email/Generator.py
blob: e969d00d89ed19792f4ba48fe5ab1b3facb9e4dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# Copyright (C) 2001 Python Software Foundation
# Author: barry@zope.com (Barry Warsaw)

"""Classes to generate plain text from a message object tree.
"""

import time
import re
import random

from types import ListType, StringType
from cStringIO import StringIO

# Intrapackage imports
import Message
import Errors

EMPTYSTRING = ''
SEMISPACE = '; '
BAR = '|'
UNDERSCORE = '_'
NL = '\n'
NLTAB = '\n\t'
SEMINLTAB = ';\n\t'
SPACE8 = ' ' * 8

fcre = re.compile(r'^From ', re.MULTILINE)



class Generator:
    """Generates output from a Message object tree.

    This basic generator writes the message to the given file object as plain
    text.
    """
    #
    # Public interface
    #

    def __init__(self, outfp, mangle_from_=1, maxheaderlen=78):
        """Create the generator for message flattening.

        outfp is the output file-like object for writing the message to.  It
        must have a write() method.

        Optional mangle_from_ is a flag that, when true, escapes From_ lines
        in the body of the message by putting a `>' in front of them.

        Optional maxheaderlen specifies the longest length for a non-continued
        header.  When a header line is longer (in characters, with tabs
        expanded to 8 spaces), than maxheaderlen, the header will be broken on
        semicolons and continued as per RFC 2822.  If no semicolon is found,
        then the header is left alone.  Set to zero to disable wrapping
        headers.  Default is 78, as recommended (but not required by RFC
        2822.
        """
        self._fp = outfp
        self._mangle_from_ = mangle_from_
        self.__first = 1
        self.__maxheaderlen = maxheaderlen

    def write(self, s):
        # Just delegate to the file object
        self._fp.write(s)

    def __call__(self, msg, unixfrom=0):
        """Print the message object tree rooted at msg to the output file
        specified when the Generator instance was created.

        unixfrom is a flag that forces the printing of a Unix From_ delimiter
        before the first object in the message tree.  If the original message
        has no From_ delimiter, a `standard' one is crafted.  By default, this
        is 0 to inhibit the printing of any From_ delimiter.

        Note that for subobjects, no From_ line is printed.
        """
        if unixfrom:
            ufrom = msg.get_unixfrom()
            if not ufrom:
                ufrom = 'From nobody ' + time.ctime(time.time())
            print >> self._fp, ufrom
        self._write(msg)

    #
    # Protected interface - undocumented ;/
    #

    def _write(self, msg):
        # We can't write the headers yet because of the following scenario:
        # say a multipart message includes the boundary string somewhere in
        # its body.  We'd have to calculate the new boundary /before/ we write
        # the headers so that we can write the correct Content-Type:
        # parameter.
        #
        # The way we do this, so as to make the _handle_*() methods simpler,
        # is to cache any subpart writes into a StringIO.  The we write the
        # headers and the StringIO contents.  That way, subpart handlers can
        # Do The Right Thing, and can still modify the Content-Type: header if
        # necessary.
        oldfp = self._fp
        try:
            self._fp = sfp = StringIO()
            self._dispatch(msg)
        finally:
            self._fp = oldfp
        # Write the headers.  First we see if the message object wants to
        # handle that itself.  If not, we'll do it generically.
        meth = getattr(msg, '_write_headers', None)
        if meth is None:
            self._write_headers(msg)
        else:
            meth(self)
        self._fp.write(sfp.getvalue())

    def _dispatch(self, msg):
        # Get the Content-Type: for the message, then try to dispatch to
        # self._handle_maintype_subtype().  If there's no handler for the full
        # MIME type, then dispatch to self._handle_maintype().  If that's
        # missing too, then dispatch to self._writeBody().
        ctype = msg.get_type()
        if ctype is None:
            # No Content-Type: header so try the default handler
            self._writeBody(msg)
        else:
            # We do have a Content-Type: header.
            specific = UNDERSCORE.join(ctype.split('/')).replace('-', '_')
            meth = getattr(self, '_handle_' + specific, None)
            if meth is None:
                generic = msg.get_main_type().replace('-', '_')
                meth = getattr(self, '_handle_' + generic, None)
                if meth is None:
                    meth = self._writeBody
            meth(msg)

    #
    # Default handlers
    #

    def _write_headers(self, msg):
        for h, v in msg.items():
            # We only write the MIME-Version: header for the outermost
            # container message.  Unfortunately, we can't use same technique
            # as for the Unix-From above because we don't know when
            # MIME-Version: will occur.
            if h.lower() == 'mime-version' and not self.__first:
                continue
            # RFC 2822 says that lines SHOULD be no more than maxheaderlen
            # characters wide, so we're well within our rights to split long
            # headers.
            text = '%s: %s' % (h, v)
            if self.__maxheaderlen > 0 and len(text) > self.__maxheaderlen:
                text = self._split_header(text)
            print >> self._fp, text
        # A blank line always separates headers from body
        print >> self._fp

    def _split_header(self, text):
        maxheaderlen = self.__maxheaderlen
        # Find out whether any lines in the header are really longer than
        # maxheaderlen characters wide.  There could be continuation lines
        # that actually shorten it.  Also, replace hard tabs with 8 spaces.
        lines = [s.replace('\t', SPACE8) for s in text.split('\n')]
        for line in lines:
            if len(line) > maxheaderlen:
                break
        else:
            # No line was actually longer than maxheaderlen characters, so
            # just return the original unchanged.
            return text
        rtn = []
        for line in text.split('\n'):
            # Short lines can remain unchanged
            if len(line.replace('\t', SPACE8)) <= maxheaderlen:
                rtn.append(line)
                SEMINLTAB.join(rtn)
            else:
                oldlen = len(text)
                # Try to break the line on semicolons, but if that doesn't
                # work, try to split on folding whitespace.
                while len(text) > maxheaderlen:
                    i = text.rfind(';', 0, maxheaderlen)
                    if i < 0:
                        break
                    rtn.append(text[:i])
                    text = text[i+1:].lstrip()
                if len(text) <> oldlen:
                    # Splitting on semis worked
                    rtn.append(text)
                    return SEMINLTAB.join(rtn)
                # Splitting on semis didn't help, so try to split on
                # whitespace.
                parts = re.split(r'(\s+)', text)
                # Watch out though for "Header: longnonsplittableline"
                if parts[0].endswith(':') and len(parts) == 3:
                    return text
                first = parts.pop(0)
                sublines = [first]
                acc = len(first)
                while parts:
                    len0 = len(parts[0])
                    len1 = len(parts[1])
                    if acc + len0 + len1 < maxheaderlen:
                        sublines.append(parts.pop(0))
                        sublines.append(parts.pop(0))
                        acc += len0 + len1
                    else:
                        # Split it here, but don't forget to ignore the
                        # next whitespace-only part
                        rtn.append(EMPTYSTRING.join(sublines))
                        del parts[0]
                        first = parts.pop(0)
                        sublines = [first]
                        acc = len(first)
                rtn.append(EMPTYSTRING.join(sublines))
                return NLTAB.join(rtn)

    #
    # Handlers for writing types and subtypes
    #

    def _handle_text(self, msg):
        payload = msg.get_payload()
        if payload is None:
            return
        if not isinstance(payload, StringType):
            raise TypeError, 'string payload expected: %s' % type(payload)
        if self._mangle_from_:
            payload = fcre.sub('>From ', payload)
        self._fp.write(payload)

    # Default body handler
    _writeBody = _handle_text

    def _handle_multipart(self, msg, isdigest=0):
        # The trick here is to write out each part separately, merge them all
        # together, and then make sure that the boundary we've chosen isn't
        # present in the payload.
        msgtexts = []
        for part in msg.get_payload():
            s = StringIO()
            g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
            g(part, unixfrom=0)
            msgtexts.append(s.getvalue())
        # Now make sure the boundary we've selected doesn't appear in any of
        # the message texts.
        alltext = NL.join(msgtexts)
        # BAW: What about boundaries that are wrapped in double-quotes?
        boundary = msg.get_boundary(failobj=_make_boundary(alltext))
        # If we had to calculate a new boundary because the body text
        # contained that string, set the new boundary.  We don't do it
        # unconditionally because, while set_boundary() preserves order, it
        # doesn't preserve newlines/continuations in headers.  This is no big
        # deal in practice, but turns out to be inconvenient for the unittest
        # suite.
        if msg.get_boundary() <> boundary:
            msg.set_boundary(boundary)
        # Write out any preamble
        if msg.preamble is not None:
            self._fp.write(msg.preamble)
        # First boundary is a bit different; it doesn't have a leading extra
        # newline.
        print >> self._fp, '--' + boundary
        if isdigest:
            print >> self._fp
        # Join and write the individual parts
        joiner = '\n--' + boundary + '\n'
        if isdigest:
            # multipart/digest types effectively add an extra newline between
            # the boundary and the body part.
            joiner += '\n'
        self._fp.write(joiner.join(msgtexts))
        print >> self._fp, '\n--' + boundary + '--',
        # Write out any epilogue
        if msg.epilogue is not None:
            if not msg.epilogue.startswith('\n'):
                print >> self._fp
            self._fp.write(msg.epilogue)

    def _handle_multipart_digest(self, msg):
        self._handle_multipart(msg, isdigest=1)

    def _handle_message_delivery_status(self, msg):
        # We can't just write the headers directly to self's file object
        # because this will leave an extra newline between the last header
        # block and the boundary.  Sigh.
        blocks = []
        for part in msg.get_payload():
            s = StringIO()
            g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
            g(part, unixfrom=0)
            text = s.getvalue()
            lines = text.split('\n')
            # Strip off the unnecessary trailing empty line
            if lines and lines[-1] == '':
                blocks.append(NL.join(lines[:-1]))
            else:
                blocks.append(text)
        # Now join all the blocks with an empty line.  This has the lovely
        # effect of separating each block with an empty line, but not adding
        # an extra one after the last one.
        self._fp.write(NL.join(blocks))

    def _handle_message(self, msg):
        s = StringIO()
        g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
        # A message/rfc822 should contain a scalar payload which is another
        # Message object.  Extract that object, stringify it, and write that
        # out.
        g(msg.get_payload(), unixfrom=0)
        self._fp.write(s.getvalue())



class DecodedGenerator(Generator):
    """Generator a text representation of a message.

    Like the Generator base class, except that non-text parts are substituted
    with a format string representing the part.
    """
    def __init__(self, outfp, mangle_from_=1, maxheaderlen=78, fmt=None):
        """Like Generator.__init__() except that an additional optional
        argument is allowed.

        Walks through all subparts of a message.  If the subpart is of main
        type `text', then it prints the decoded payload of the subpart.

        Otherwise, fmt is a format string that is used instead of the message
        payload.  fmt is expanded with the following keywords (in
        %(keyword)s format):

        type       : Full MIME type of the non-text part
        maintype   : Main MIME type of the non-text part
        subtype    : Sub-MIME type of the non-text part
        filename   : Filename of the non-text part
        description: Description associated with the non-text part
        encoding   : Content transfer encoding of the non-text part

        The default value for fmt is None, meaning

        [Non-text (%(type)s) part of message omitted, filename %(filename)s]
        """
        Generator.__init__(self, outfp, mangle_from_, maxheaderlen)
        if fmt is None:
            fmt = ('[Non-text (%(type)s) part of message omitted, '
                   'filename %(filename)s]')
        self._fmt = fmt

    def _dispatch(self, msg):
        for part in msg.walk():
            maintype = part.get_main_type('text')
            if maintype == 'text':
                print >> self, part.get_payload(decode=1)
            elif maintype == 'multipart':
                # Just skip this
                pass
            else:
                print >> self, self._fmt % {
                    'type'       : part.get_type('[no MIME type]'),
                    'maintype'   : part.get_main_type('[no main MIME type]'),
                    'subtype'    : part.get_subtype('[no sub-MIME type]'),
                    'filename'   : part.get_filename('[no filename]'),
                    'description': part.get('Content-Description',
                                            '[no description]'),
                    'encoding'   : part.get('Content-Transfer-Encoding',
                                            '[no encoding]'),
                    }



# Helper
def _make_boundary(self, text=None):
    # Craft a random boundary.  If text is given, ensure that the chosen
    # boundary doesn't appear in the text.
    boundary = ('=' * 15) + repr(random.random()).split('.')[1] + '=='
    if text is None:
        return boundary
    b = boundary
    counter = 0
    while 1:
        cre = re.compile('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
        if not cre.search(text):
            break
        b = boundary + '.' + str(counter)
        counter += 1
    return b
e. +Widget class bindings are primarily responsible for +maintaining the widget state and invoking callbacks; +all aspects of the widgets appearance is +.SH "THEMES" +A \fItheme\fR is a collection of elements and styles +that determine the look and feel of the widget set. +Themes can be used to: +.IP \(bu +Isolate platform differences (X11 vs. classic Windows vs. XP vs. Aqua ...) +.IP \(bu +Adapt to display limitations (low-color, grayscale, monochrome, tiny screens) +.IP \(bu +Accessibility (high contrast, large type) +.IP \(bu +Application suite "branding" +.IP \(bu +Blend in with the rest of the desktop (Gnome, KDE, Java) +.IP \(bu +And, of course: eye candy. + +.SH "ELEMENTS" +An \fIelement\fR displays an individual part of a widget. +For example, a vertical scrollbar widget contains \fBuparrow\fR, +\fBdownarrow\fR, \fBtrough\fR and \fBslider\fR elements. +.PP +Element names use a recursive dotted notation. +For example, \fBuparrow\fR identifies a generic arrow element, +and \fBScrollbar.arrow\fR and \fBCombobox.uparrow\fR identify +widget-specific elements. +When looking for an element, the style engine looks for +the specific name first, and if an element of that name is +not found it looks for generic elements by stripping off +successive leading components of the element name. +.PP +Like widgets, elements have \fIoptions\fR which +specify what to display and how to display it. +For example, the \fBtext\fR element +(which displays a text string) has +\fB-text\fR, \fB-font\fR, \fB-foreground\fR, \fB-background\fR, +\fB-underline\fR, and \fB-width\fR options. +The value of an element resource is taken from: +.IP \(bu +A dynamic setting specified by \fBstyle map\fR and the current state; +.IP \(bu +An option of the same name and type in the widget containing the element; +.IP \(bu +The default setting specified by \fBstyle default\fR; or +.IP \(bu +The element's built-in default value for the resource. +.SH "LAYOUTS" +A \fIlayout\fR specifies which elements make up a widget +and how they are arranged. +The layout engine uses a simplified version of the \fBpack\fR +algorithm: starting with an initial cavity equal to the size +of the widget, elements are allocated a parcel within the cavity along +the side specified by the \fB-side\fR option, +and placed within the parcel according to the \fB-sticky\fR +option. +For example, the layout for a horizontal scrollbar +.CS +style layout Horizontal.TScrollbar { + Scrollbar.trough -children { + Scrollbar.leftarrow -side left -sticky w + Scrollbar.rightarrow -side right -sticky e + Scrollbar.thumb -side left -expand true -sticky ew + } +} +.CE +By default, the layout for a widget is the same as its class name. +Some widgets may override this (for example, the \fBscrollbar\fR +widget chooses different layouts based on the \fB-orient\fR option). + +.SH "STATES" +In standard Tk, many widgets have a \fB-state\fR option +which (in most cases) is either \fBnormal\fR or \fBdisabled\fR. +Some widgets support additional states, such +as the \fBentry\fR widget which has a \fBreadonly\fR state +and the various flavors of buttons which have \fBactive\fR state. +.PP +The themed Tk widgets generalizes this idea: +every widget has a bitmap of independent state flags. +Widget state flags include \fBactive\fR, \fBdisabled\fR, +\fBpressed\fR, \fBfocus\fR, etc., +(see \fIwidget(n)\fR for the full list of state flags). +.PP +Instead of a \fB-state\fR option, every widget now has +a \fBstate\fR widget command which is used to set or query +the state. +A \fIstate specification\fR is a list of symbolic state names +indicating which bits are set, each optionally prefixed with an +exclamation point indicating that the bit is cleared instead. +.PP +For example, the class bindings for the \fBtbutton\fR +widget are: +.CS +bind TButton { %W state active } +bind TButton { %W state !active } +bind TButton { %W state pressed } +bind TButton { %W state !pressed } +bind TButton { %W state pressed } +bind TButton \e + { %W instate {pressed} { %W state !pressed ; %W invoke } } +.CE +This specifies that the widget becomes \fBactive\fR when +the pointer enters the widget, and inactive when it leaves. +Similarly it becomes \fBpressed\fR when the mouse button is pressed, +and \fB!pressed\fR on the ButtonRelease event. +In addition, the button unpresses if +pointer is dragged outside the widget while Button-1 is held down, +and represses if it's dragged back in. +Finally, when the mouse button is released, the widget's +\fB-command\fR is invoked, but only if the button is currently +in the \fBpressed\fR state. +(The actual bindings are a little more complicated than the above, +but not by much). +.PP +\fINote to self: rewrite that paragraph. It's horrible.\fR +.SH "STYLES" +Each widget is associated with a \fIstyle\fR, +which specifies values for element resources. +Style names use a recursive dotted notation like layouts and elements; +by default, widgets use the class name to look up a style in the current theme. +For example: +.CS +style default TButton \e + -background #d9d9d9 \e + -foreground black \e + -relief raised \e + ; +.CE +Many elements are displayed differently depending on the widget state. +For example, buttons have a different background when they are active, +a different foreground when disabled, and a different relief when pressed. +The \fBstyle map\fP command specifies dynamic resources +for a particular style: +.CS +style map TButton \e + -background [list disabled #d9d9d9 active #ececec] \e + -foreground [list disabled #a3a3a3] \e + -relief [list {pressed !disabled} sunken] \e + ; +.CE +.SH "SEE ALSO" +widget(n), style(n) diff --git a/doc/ttk_label.n b/doc/ttk_label.n new file mode 100644 index 0000000..77ac736 --- /dev/null +++ b/doc/ttk_label.n @@ -0,0 +1,75 @@ +'\" +'\" Copyright (c) 2004 Joe English +'\" +.so man.macros +.TH ttk_label n 8.5 Tk "Tk Themed Widget" +.BS +.SH NAME +ttk::label \- Display a text string and/or image +.SH SYNOPSIS +\fBttk::label\fR \fIpathName \fR?\fIoptions\fR? +.BE +.SH DESCRIPTION +A \fBlabel\fP widget displays a textual label and/or image. +The label may be linked to a Tcl variable +to automatically change the displayed text. +.SO +\-class \-compound \-cursor \-image +\-style \-takefocus \-text \-textvariable +\-underline \-width +.SE +.SH "WIDGET-SPECIFIC OPTIONS" +.OP \-anchor anchor Anchor +Specifies how the information in the widget is positioned +relative to the inner margins. Legal values are +\fBn\fR, \fBne\fR, \fBe\fR, \fBse\fR, +\fBs\fR, \fBsw\fR, \fBw\fR, \fBnw\fR, and \fBcenter\fR. +See also \fB-justify\fP. +.OP \-background frameColor FrameColor +The widget's background color. +If unspecified, the theme default is used. +.OP \-font font Font +Font to use for label text. +.OP \-foreground textColor TextColor +The widget's foreground color. +If unspecified, the theme default is used. +.OP \-justify justify Justify +If there are multiple lines of text, specifies how +the lines are laid out relative to one another. +One of \fBleft\fP, \fBcenter\fP, or \fBright\fP. +See also \fB-anchor\fP. +.OP \-padding padding Padding +Specifies the amount of extra space to allocate for the widget. +The padding is a list of up to four length specifications +\fIleft top right bottom\fR. +If fewer than four elements are specified, +\fIbottom\fR defaults to \fItop\fR, +\fIright\fR defaults to \fIleft\fR, and +\fItop\fR defaults to \fIleft\fR. +.OP \-relief relief Relief +.\" Rewrite this: +Specifies the 3-D effect desired for the widget border. +Valid values are +\fBflat\fR, \fBgroove\fR, \fBraised\fR, \fBridge\fR, \fBsolid\fR, +and \fBsunken\fR. +.OP \-text text Text +Specifies a text string to be displayed inside the widget +(unless overridden by \fB-textvariable\fR). +.OP \-wraplength wrapLength WrapLength +Specifies the maximum line length (in pixels). +If this option is less than or equal to zero, +then automatic wrapping is not performed; otherwise +the text is split into lines such that no line is longer +than the specified value. +.SH "WIDGET COMMAND" +.TP +\fIpathName \fBcget\fR \fIoption\fR +.TP +\fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR? +.TP +\fIpathName \fBinstate \fIstatespec\fR ?\fIscript\fR? +.TP +\fIpathName \fBstate\fR ?\fIstateSpec\fR? +See \fIwidget(n)\fP +.SH "SEE ALSO" +widget(n) diff --git a/doc/ttk_labelframe.n b/doc/ttk_labelframe.n new file mode 100644 index 0000000..1eabcf2 --- /dev/null +++ b/doc/ttk_labelframe.n @@ -0,0 +1,64 @@ +'\" Copyright (c) 2005 Joe English +.so man.macros +.TH ttk_labelframe n 8.5 Tk "Tk Themed Widget" +.BS +.SH NAME +ttk::labelframe \- Container widget with optional label +.SH SYNOPSIS +\fBttk::labelframe\fR \fIpathName \fR?\fIoptions\fR? +.BE +.SH DESCRIPTION +A \fBlabelframe\fP widget is a container used to group other widgets together. +It has an optional label, which may be a plain text string or another widget. +.SO +\-class \-cursor \-takefocus \-style +.SE +.SH "WIDGET-SPECIFIC OPTIONS" +'\" XXX: Currently included, but may go away: +'\" XXX: .OP -borderwidth borderWidth BorderWidth +'\" XXX: The desired width of the widget border. Default is theme-dependent. +'\" XXX: .OP -relief relief Relief +'\" XXX: One of the standard Tk border styles: +'\" XXX: \fBflat\fR, \fBgroove\fR, \fBraised\fR, \fBridge\fR, +'\" XXX: \fBsolid\fR, or \fBsunken\fP. +'\" XXX: Default is theme-dependent. +.OP -labelanchor labelAnchor LabelAnchor +Specifies where to place the label. +Allowed values are (clockwise from the top upper left corner): +\fBnw\fR, \fBn\fR, \fBne\fR, \fBen\fR, \fBe\fR, \fBes\fR, +\fBse\fR, \fBs\fR,\fBsw\fR, \fBws\fR, \fBw\fR and \fBwn\fR. +The default value is theme-dependent. +'\" Alternate explanation: The first character must be one of n, s, e, or w +'\" and specifies which side the label should be placed on; +'\" the remaining characters specify how the label is aligned on that side. +'\" NOTE: Now allows other values as well; leave this undocumented for now +.OP -text text Text +Specifies the text of the label. +.OP -underline underline Underline +If set, specifies the integer index (0-based) of a character to +underline in the text string. +The underlined character is used for mnemonic activation +(see \fIkeynav(n)\fR). +Mnemonic activation for a \fBttk::labelframe\fP +sets the keyboard focus to the first child of the \fBttk::labelframe\fP widget. +.OP -padding padding Padding +Additional padding to include inside the border. +.OP -labelwidget labelWidget LabelWidget +The name of a widget to use for the label. +If set, overrides the \fB-text\fP option. +The \fB-labelwidget\fP must be a child of the \fBlabelframe\fP widget +or one of the \fBlabelframe\fP's ancestors, and must belong to the +same top-level widget as the \fBlabelframe\fP. +.OP -width width Width +If specified, the widget's requested width in pixels. +.OP -height height Height +If specified, the widget's requested height in pixels. +(See \fIttk::frame\fP for further notes on \fB-width\fP and \fB-height\fP). +.SH "WIDGET COMMAND" +Supports the standard widget commands +\fBconfigure\fP, \fBcget\fP, \fBinstate\fP, and \fBstate\fP; +see \fIwidget(n)\fP. +.SH "SEE ALSO" +widget(n), frame(n) +.SH "KEYWORDS" +widget, frame, container, label, groupbox diff --git a/doc/ttk_menubutton.n b/doc/ttk_menubutton.n new file mode 100644 index 0000000..cf3c576 --- /dev/null +++ b/doc/ttk_menubutton.n @@ -0,0 +1,41 @@ +'\" +'\" Copyright (c) 2004 Joe English +'\" +.so man.macros +.TH ttk_menubutton n 8.5 Tk "Tk Themed Widget" +.BS +.SH NAME +ttk::menubutton \- Widget that pops down a menu when pressed +.SH SYNOPSIS +\fBttk::menubutton\fR \fIpathName \fR?\fIoptions\fR? +.BE +.SH DESCRIPTION +A \fBmenubutton\fP widget displays a textual label and/or image, +and displays a menu when pressed. +.SO +\-class \-compound \-cursor \-image +\-state \-style \-takefocus \-text +\-textvariable \-underline \-width +.SE +.SH "WIDGET-SPECIFIC OPTIONS" +.OP \-direction direction Direction +Specifies where the menu is to be popped up relative +to the menubutton. +One of: \fIabove\fR, \fIbelow\fR, \fIleft\fR, \fIright\fR, +or \fIflush\fR. The default is \fIbelow\fR. +\fIflush\fR pops the menu up directly over the menubutton. +.OP \-menu menu Menu +Specifies the path name of the menu associated with the menubutton. +To be on the safe side, the menu ought to be a direct child of the +menubutton. +.\" not documented: may go away: +.\" .OP \-anchor anchor Anchor +.\" .OP \-padding padding Pad +.SH "WIDGET COMMAND" +Menubutton widgets support the standard +\fBcget\fR, \fBconfigure\fR, \fBinstate\fR, and \fBstate\fR +methods. No other widget methods are used. +.SH "SEE ALSO" +widget(n), keynav(n), menu(n) +.SH "KEYWORDS" +widget, button, menu diff --git a/doc/ttk_notebook.n b/doc/ttk_notebook.n new file mode 100644 index 0000000..e123077 --- /dev/null +++ b/doc/ttk_notebook.n @@ -0,0 +1,179 @@ +'\" +'\" Copyright (c) 2004 Joe English +'\" +.so man.macros +.TH ttk_notebook n 8.5 Tk "Tk Themed Widget" +.BS +.SH NAME +ttk::notebook \- Multi-paned container widget +.SH SYNOPSIS +\fBttk::notebook\fR \fIpathName \fR?\fIoptions\fR? +.br +\fIpathName \fBadd\fR \fIpathName\fR.\fIsubwindow\fR ?\fIoptions...\fR? +\fIpathName \fBinsert\fR \fIindex\fR \fIpathName\fR.\fIsubwindow\fR ?\fIoptions...\fR? +.BE +.SH DESCRIPTION +A \fBnotebook\fP widget manages a collection of subpanes +and displays a single one at a time. +Each pane is associated with a tab, which the user +may select to change the currently-displayed pane. +.SO +\-class \-cursor \-takefocus \-style +.SE +.SH "WIDGET OPTIONS" +.OP \-height height Height +If present and greater than zero, +specifies the desired height of the pane area +(not including internal padding or tabs). +Otherwise, the maximum height of all panes is used. +.OP \-padding padding Padding +Specifies the amount of extra space to add around the outside +of the notebook. +The padding is a list of up to four length specifications +\fIleft top right bottom\fR. +If fewer than four elements are specified, +\fIbottom\fR defaults to \fItop\fR, +\fIright\fR defaults to \fIleft\fR, and +\fItop\fR defaults to \fIleft\fR. +.OP \-width width Width +If present and greater than zero, +specifies the desired width of the pane area +(not including internal padding). +Otherwise, the maximum width of all panes is used. +.SH "TAB OPTIONS" +The following options may be specified for individual notebook panes: +.OP \-state state State +Either \fBnormal\fP, \fBdisabled\fP or \fBhidden\fP. +If \fBdisabled\fP, then the tab is not selectable. If \fBhidden\fP, +then the tab is not shown. +.OP \-sticky sticky Sticky +Specifies how the child pane is positioned within the pane area. +Value is a string containing zero or more of the characters +\fBn, s, e,\fR or \fBw\fR. +Each letter refers to a side (north, south, east, or west) +that the child window will "stick" to, +as per the \fBgrid\fR geometry manager. +.OP \-padding padding Padding +Specifies the amount of extra space to add between the notebook and this pane. +Syntax is the same as for the widget \fB-padding\fP option. +.OP \-text text Text +Specifies a string to be displayed in the tab. +.OP \-image image Image +Specifies an image to display in the tab, +which must have been created with the \fBimage create\fR command. +.OP \-compound compound Compound +Specifies how to display the image relative to the text, +in the case both \fB-text\fR and \fB-image\fR are present. +See \fIlabel(n)\fR for legal values. +.OP \-underline underline Underline +Specifies the integer index (0-based) of a character to underline +in the text string. +The underlined character is used for mnemonic activation +if \fBttk::notebook::enableTraversal\fR is called. +.SH "WIDGET COMMAND" +.TP +\fIpathname \fBadd \fIchild\fR ?\fIoptions...\fR? +Adds a new tab to the notebook. +When the tab is selected, the \fIchild\fR window +will be displayed. +\fIchild\fR must be a direct child of the notebook window. +See \fBTAB OPTIONS\fR for the list of available \fIoptions\fR. +.TP +\fIpathname \fBconfigure\fR ?\fIoptions\fR? +See \fIwidget(n)\fR. +.TP +\fIpathname \fBcget\fR \fIoption\fR +See \fIwidget(n)\fR. +.TP +\fIpathname \fBforget\fR \fItabid\fR +Removes the tab specified by \fItabid\fR, +unmaps and unmanages the associated child window. +.TP +\fIpathname \fBindex\fR \fItabid\fR +Returns the numeric index of the tab specified by \fItabid\fR, +or the total number of tabs if \fItabid\fR is the string "\fBend\fR". +.TP +\fIpathname \fBinsert\fR \fIpos\fR \fIsubwindow\fR \fIoptions...\fR +Inserts a pane at the specified position. +\fIpos\fR is either the string \fBend\fR, an integer index, +or the name of a managed subwindow. +If \fIsubwindow\fR is already managed by the notebook, +moves it to the specified position. +See \fBTAB OPTIONS\fR for the list of available options. +.TP +\fIpathname \fBinstate\fR \fIstatespec \fR?\fIscript...\fR? +See \fIwidget(n)\fR. +.TP +\fIpathname \fBselect\fR ?\fItabid\fR? +Selects the specified tab. The associated child pane will be displayed, +and the previously-selected pane (if different) is unmapped. +If \fItabid\fR is omitted, returns the widget name of the +currently selected pane. +.TP +\fIpathname \fBstate\fR ?\fIstatespec\fR? +See \fIwidget(n)\fR. +.TP +\fIpathname \fBtab\fR \fItabid\fR ?\fI-options \fR?\fIvalue ...\fR +Query or modify the options of the specific tab. +If no \fI-option\fR is specified, returns a dictionary of the tab option values. +If one \fI-option\fP is specified, returns the value of that \fIoption\fR. +Otherwise, sets the \fI-option\fRs to the corresponding \fIvalue\fRs. +See \fBTAB OPTIONS\fR for the available options. +.TP +\fIpathname \fBtabs\fR +Returns a list of all windows managed by the widget. +.\" Perhaps "panes" is a better name for this command? +.SH "KEYBOARD TRAVERSAL" +To enable keyboard traversal for a toplevel window +containing a notebook widget \fI$nb\fR, call: +.CS +ttk::notebook::enableTraversal $nb +.CE +.PP +This will extend the bindings for the toplevel widget +containing the notebook as follows: +.IP \(bu +\fBControl-Tab\fR selects the tab following the currently selected one. +.IP \(bu +\fBShift-Control-Tab\fR selects the tab preceding the currently selected one. +.IP \(bu +\fBAlt-K\fP, where \fBK\fP is the mnemonic (underlined) character +of any tab, will select that tab. +.PP +Multiple notebooks in a single toplevel may be enabled for traversal, +including nested notebooks. +However, notebook traversal only works properly if all panes +are direct children of the notebook. +.SH "TAB IDENTIFIERS" +The \fItabid\fR argument to the above commands may take +any of the following forms: +.IP \(bu +An integer between zero and the number of tabs; +.IP \(bu +The name of a child pane window; +.IP \(bu +A positional specification of the form "@\fIx\fR,\fIy\fR", +which identifies the tab +.IP \(bu +The literal string "\fBcurrent\fR", +which identifies the currently-selected tab; or: +.IP \(bu +The literal string "\fBend\fR", +which returns the number of tabs +(only valid for "\fIpathname \fBindex\fR"). + +.SH "VIRTUAL EVENTS" +The notebook widget generates a \fB<>\fP +virtual event after a new tab is selected. +.SH "EXAMPLE" +.CS +notebook .nb +\.nb add [frame .nb.f1] -text "First tab" +\.nb add [frame .nb.f2] -text "Second tab" +\.nb select .nb.f2 +ttk::notebook::enableTraversal .nb +.CE +.SH "SEE ALSO" +widget(n), grid(n) +.SH "KEYWORDS" +pane, tab diff --git a/doc/ttk_panedwindow.n b/doc/ttk_panedwindow.n new file mode 100644 index 0000000..d38a007 --- /dev/null +++ b/doc/ttk_panedwindow.n @@ -0,0 +1,78 @@ +'\" $Id: ttk_panedwindow.n,v 1.1 2006/10/31 01:42:25 hobbs Exp $ +'\" Copyright (c) 2005 Joe English +.so man.macros +.TH ttk_panedwindow n 8.5 Tk "Tk Themed Widget" +.BS +.SH "NAME" +ttk::panedwindow \- Multi-pane container window +.SH SYNOPSIS +.nf +\fBttk::panedwindow\fR \fIpathName \fR?\fIoptions\fR? +.br +\fIpathName \fBadd\fR \fIpathName.subwindow\fR ?\fIoptions...\fR? +\fIpathName \fBinsert\fR \fIindex\fR \fIpathName.subwindow\fR ?\fIoptions...\fR? +.fi +.BE +.SH "DESCRIPTION" +A paned widget displays a number of subwindows, +stacked either vertically or horizontally. +The user may adjust the relative sizes of the subwindows +by dragging the sash between panes. +.SO +\-class \-cursor \-takefocus \-style +.SE +.SH "WIDGET OPTIONS" +.OP \-orient orient Orient +Specifies the orientation of the window. +If \fBvertical\fP, subpanes are stacked top-to-bottom; +if \fBhorizontal\fP, subpanes are stacked left-to-right. +.SH "PANE OPTIONS" +The following options may be specified for each pane: +.OP \-weight weight Weight +An integer specifying the relative stretchability of the pane. +When the paned window is resized, the extra space is added +or subracted to each pane proportionally to its \fB-weight\fP. +.SH "WIDGET COMMAND" +Supports the standard \fBconfigure\fR, \fBcget\fR, \fBstate\fP, +and \fBinstate\fR commands; see \fIwidget(n)\fR for details. +Additional commands: +.TP +\fIpathname \fBadd\fR \fIsubwindow\fR \fIoptions...\fR +Adds a new pane to the window. +\fIsubwindow\fR must be a direct child of the paned window \fIpathname\fR. +See \fBPANE OPTIONS\fR for the list of available options. +.TP +\fIpathname \fBforget\fR \fIpane\fR +Removes the specified subpane from the widget. +\fIpane\fR is either an integer index or the name of a managed subwindow. +.TP +\fIpathname \fBinsert\fR \fIpos\fR \fIsubwindow\fR \fIoptions...\fR +Inserts a pane at the specified position. +\fIpos\fR is either the string \fBend\fR, an integer index, +or the name of a managed subwindow. +If \fIsubwindow\fR is already managed by the paned window, +moves it to the specified position. +See \fBPANE OPTIONS\fR for the list of available options. +.TP +\fIpathname \fBpane\fR \fIpane -option \fR?\fIvalue \fR?\fI-option value...\fR +Query or modify the options of the specified \fIpane\fR, +where \fIpane\fR is either an integer index or the name of a managed subwindow. +If n