diff options
| author | marco giusti <marco.giusti@gmail.com> | 2011-12-12 23:22:38 +0100 |
|---|---|---|
| committer | marco giusti <marco.giusti@gmail.com> | 2011-12-12 23:22:38 +0100 |
| commit | cf7047926c30aaa77a53185ab58c4610c444ae51 (patch) | |
| tree | 69fcc1b4d514233227ab56399d74b0cfe658e1c5 /docs/tutorial | |
| parent | ddd3c8283bd387bf13bfdf7359adb1dff4904a29 (diff) | |
| download | urwid-cf7047926c30aaa77a53185ab58c4610c444ae51.tar.gz | |
Fix objects references
--HG--
branch : feature-sphinx
Diffstat (limited to 'docs/tutorial')
| -rw-r--r-- | docs/tutorial/index.rst | 447 |
1 files changed, 239 insertions, 208 deletions
diff --git a/docs/tutorial/index.rst b/docs/tutorial/index.rst index c598fa0..c4e8619 100644 --- a/docs/tutorial/index.rst +++ b/docs/tutorial/index.rst @@ -22,21 +22,22 @@ screen and will run until interrupted with *CTRL+C* (*^C*). .. literalinclude:: minimal.py :linenos: -* The :class:`Text` widget handles formatting blocks of text, wrapping to the - next line when necessary. Widgets like this are called "flow widgets" because - their sizing can have a number of columns given, in this case the full screen - width, then they will flow to fill as many rows as necessary. - -* The :class:`Filler` is widget fills in blank lines above or below flow - widgets so that they can be displayed in a fixed number of rows. This Filler - will align our Text to the top of the screen, filling all the rows below with - blank lines. Widgets which are given both the number of columns and number of - rows they must be displayed in are called "box widgets". The "topmost" widget - displayed on the screen must be a box widget. - -* The :class:`MainLoop` class handles displaying our widgets as well as input - from the user. In this case our widgets can't handle the input so we need to - interrupt the program to exit with *^C*. +* The :class:`~urwid.widget.Text` widget handles formatting blocks of text, + wrapping to the next line when necessary. Widgets like this are called "flow + widgets" because their sizing can have a number of columns given, in this + case the full screen width, then they will flow to fill as many rows as + necessary. + +* The :class:`~urwid.decoration.Filler` is widget fills in blank lines above or + below flow widgets so that they can be displayed in a fixed number of rows. + This Filler will align our Text to the top of the screen, filling all the + rows below with blank lines. Widgets which are given both the number of + columns and number of rows they must be displayed in are called "box + widgets". The "topmost" widget displayed on the screen must be a box widget. + +* The :class:`urwid.main_loop.MainLoop` class handles displaying our widgets as + well as input from the user. In this case our widgets can't handle the input + so we need to interrupt the program to exit with *^C*. .. image:: minimal1.png @@ -49,16 +50,17 @@ each key pressed, exiting when the user presses *Q*. .. literalinclude:: input.py :linenos: -* The :class:`MainLoop` class has an optional function parameter - *unhandled_input* This function will be called once for each keypress that is - not handled by the widgets being displayed. +* The :class:`urwid.main_loop.MainLoop` class has an optional function + parameter *unhandled_input* This function will be called once for each + keypress that is not handled by the widgets being displayed. * None of the widgets being displayed here handle input, so every key the user presses will be passed to the *show_or_exit* function. -* The :exc:`ExitMainLoop` exception is used to exit cleanly from the - :meth:`MainLoop.run` function when the user presses *Q*. All other input is - displayed by replacing the current Text widget's content. +* The :exc:`~urwid.main_loop.MainLoop.ExitMainLoop` exception is used to exit + cleanly from the :meth:`~urwid.main_loop.MainLoop.run` function when the user + presses *Q*. All other input is displayed by replacing the current Text + widget's content. .. image:: input1.png .. image:: input2.png @@ -77,31 +79,35 @@ and the space above and below the text. It waits for a keypress before exiting. :linenos: * Attributes are defined as part of a palette. Valid foreground, background and - setting values are documented in the :class:`AttrSpec` class. A palette is a - list of tuples containing: + setting values are documented in the :class:`~urwid.display_common.AttrSpec` + class. A palette is a list of tuples containing: 1. Name of the attribute, typically a string 2. Foreground color and settings for 16-color (normal) mode 3. Background color for normal mode 4. Settings for monochrome mode (optional) - 5. Foreground color and settings for 88 and 256-color modes (optional, see next example) + 5. Foreground color and settings for 88 and 256-color modes (optional, see + next example) 6. Background color for 88 and 256-color modes (optional) -* The palette is passed to :class:`MainLoop` to make it available to our - program -* A :class:`Text` widget is created containing the string " Hello World " - with attribute *banner*. The attributes of text in a Text widget is set by - using a ``(attribute, text)`` tuple instead of a simple text string. Text - attributes will flow with the text, and multiple attributes may be specified - by combining tuples into a list. -* An :class:`AttrMap` widget is created to wrap the text widget with attribute - "streak". :class:`AttrMap` widgets allow you to map any attribute to any - other attribute, but by default they will set the attribute of everything - that does not already have an attribute. In this case the text has an - attribute, so only the areas around the text used for alignment will be have - the new attribute. -* A second :class:`AttrMap` widget is created to wrap the filler widget with - attribute "bg". +* The palette is passed to :class:`urwid.main_loop.MainLoop` to make it + available to our program + +* A :class:`~urwid.widget.Text` widget is created containing the string " Hello + World " with attribute *banner*. The attributes of text in a Text widget is + set by using a ``(attribute, text)`` tuple instead of a simple text string. + Text attributes will flow with the text, and multiple attributes may be + specified by combining tuples into a list. + +* An :class:`~urwid.decoration.AttrMap` widget is created to wrap the text + widget with attribute "streak". :class:`~urwid.decoration.AttrMap` widgets + allow you to map any attribute to any other attribute, but by default they + will set the attribute of everything that does not already have an attribute. + In this case the text has an attribute, so only the areas around the text + used for alignment will be have the new attribute. + +* A second :class:`~urwid.decoration.AttrMap` widget is created to wrap the + filler widget with attribute "bg". When this program is run you can now clearly see the separation of the text, the alignment around the text, and the filler above and below the text. This @@ -126,16 +132,21 @@ and will work in any terminal that supports 256-color mode. It will exit when * This palette only defines values for the high color foregroundand backgrounds, because only the high colors will be used. A real application should define values for all the modes in their palette. Valid foreground, - background and setting values are documented in the :class:`AttrSpec` class. -* :class:`Divider` widgets are used to create blank lines, colored with - :class:`AttrMap`. -* A :class:`Pile` widget arranges the :class:`Divider` widgets above and below - our text. -* Behind the scenes our :class:`MainLoop` class has created a - :class:`raw_display.Screen` object for drawing the screen. The program is - put into 256-color mode by using the screen object's - :meth:`set_terminal_properties` method. This method works only when using the - default :class:`raw_display.Screen` class in our :class:`MainLoop`. + background and setting values are documented in the + :class:`~urwid.display_common.AttrSpec` class. + +* :class:`~urwid.widget.Divider` widgets are used to create blank lines, + colored with :class:`~urwid.decoration.AttrMap`. + +* A :class:`~urwid.container.Pile` widget arranges the + :class:`~urwid.widget.Divider` widgets above and below our text. + +* Behind the scenes our :class:`urwid.main_loop.MainLoop` class has created a + :class:`urwid.raw_display.Screen` object for drawing the screen. The program + is put into 256-color mode by using the screen object's + :meth:`urwid.raw_display.Screen.set_terminal_properties` method. This method + works only when using the default :class:`urwid.raw_display.Screen` class in + our :class:`urwid.main_loop.MainLoop`. .. image:: highcolors1.png @@ -151,19 +162,22 @@ name).`` .. literalinclude:: edit.py :linenos: -* An :class:`Edit` widget is created with the caption ``What is your name?``. A - newline at the end of the caption makes the user input start on the next row. -* Most keystrokes will be handled by the :class:`Edit` widget, allowing the - user to enter their name. -* The :func:`unhandled_input` function will replace the :class:`Edit` widget - inside the :class:`Filler` widget with a reply when the user presses *ENTER*. +* An :class:`~urwid.widget.Edit` widget is created with the caption ``What is + your name?``. A newline at the end of the caption makes the user input start + on the next row. +* Most keystrokes will be handled by the :class:`~urwid.widget.Edit` widget, + allowing the user to enter their name. +* The :func:`unhandled_input` function will replace the + :class:`~urwid.widget.Edit` widget inside the + :class:`~urwid.decoration.Filler` widget with a reply when the user presses + *ENTER*. * When the user presses *ENTER* again the :func:`unhandled_input` function will cause the program to exit. -The :class:`Edit` widget has many capabilities. It lets you make corrections -and move the cursor around with the *HOME*, *END* and arrow keys. It is based -on the :class:`Text` widget so it supports the same wrapping and alignment -modes. +The :class:`~urwid.widget.Edit` widget has many capabilities. It lets you make +corrections and move the cursor around with the *HOME*, *END* and arrow keys. +It is based on the :class:`~urwid.widget.Text` widget so it supports the same +wrapping and alignment modes. .. image:: edit1.png .. image:: edit2.png @@ -178,20 +192,23 @@ This program asks for your name and responds "Nice to meet you, (your name)" .. literalinclude:: frlb.py :linenos: -* An :class:`Edit` widget and :class:`Text` reply widget are created, like in - the previous example. -* A :class:`SimpleListWalker` is then created to manage the contents and focus - of our :class:`ListBox`. The :class:`SimpleListWalker` behaves just like a - list of widgets, and can be modified like a regular list. -* A :class:`ListBox` is created and passed the :class:`SimpleListWalker`. The - :class:`ListBox` is a box widget and allows scrolling through its contents. - This example is simple enough that we could have used a :class:`Pile` widget - and :class:`Filler` widget instead, but we will see how the :class:`ListBox` - can be useful in later examples. +* An :class:`~urwid.widget.Edit` widget and :class:`~urwid.widget.Text` reply + widget are created, like in the previous example. +* A :class:`~urwid.listbox.SimpleListWalker` is then created to manage the + contents and focus of our :class:`~urwid.listbox.ListBox`. The + :class:`~urwid.listbox.SimpleListWalker` behaves just like a list of widgets, + and can be modified like a regular list. +* A :class:`~urwid.listbox.ListBox` is created and passed the + :class:`~urwid.listbox.SimpleListWalker`. The :class:`~urwid.listbox.ListBox` + is a box widget and allows scrolling through its contents. This example is + simple enough that we could have used a :class:`~urwid.container.Pile` widget + and :class:`~urwid.decoration.Filler` widget instead, but we will see how the + :class:`~urwid.listbox.ListBox` can be useful in later examples. * The :func:`connect_signal` function is used to attach our - :func:`on_ask_change` function to our :class:`Edit` widget's *change* event. - Now any time the content of the :class:`Edit` widget changes - :func:`on_ask_change` will be called and passed the new content. + :func:`on_ask_change` function to our :class:`~urwid.widget.Edit` widget's + *change* event. Now any time the content of the :class:`~urwid.widget.Edit` + widget changes :func:`on_ask_change` will be called and passed the new + content. * Now :func:`on_ask_change` updates the reply text as the user enters their name. @@ -212,29 +229,30 @@ be updated when you press *ENTER*. *ENTER* on a blank line exits. * When the user presses *ENTER*: * The widget in focus and its current position is retrieved by calling the - :meth:`ListBox.get_focus` function. + :meth:`urwid.listbox.ListBox.get_focus` function. * If the widget in focus does not have an :attr:`edit_text` attribute, then - it is not one of the :class:`Edit` widgets we are interested in. One of - the :class:`Text` widgets might receive focus if it covers the entire - visible area of the :class:`ListBox` widget and there is no :class:`Edit` - widget to take focus. While this is unlikely, it should be handled or the - program will fail when trying to access it. + it is not one of the :class:`~urwid.widget.Edit` widgets we are interested + in. One of the :class:`~urwid.widget.Text` widgets might receive focus if + it covers the entire visible area of the :class:`~urwid.listbox.ListBox` + widget and there is no :class:`~urwid.widget.Edit` widget to take focus. + While this is unlikely, it should be handled or the program will fail when + trying to access it. * If there is no edit text we exit the program. * The widget after the widget in focus (if any exists) is replaced with a response. - * If there is no widget after that widget, a new :class:`Edit` widget is - created. - * The focus is then moved to the next :class:`Edit` widget by calling - :meth:`ListBox.set_focus`. + * If there is no widget after that widget, a new :class:`~urwid.widget.Edit` + widget is created. + * The focus is then moved to the next :class:`~urwid.widget.Edit` widget by + calling :meth:`urwid.listbox.ListBox.set_focus`. -* All other keys are passed to the top widget to handle. The :class:`ListBox` - widget does most of the hard work: +* All other keys are passed to the top widget to handle. The + :class:`~urwid.listbox.ListBox` widget does most of the hard work: * *UP* and *DOWN* will change the focus and/or scroll the widgets in the list box. * *PAGE UP* and *PAGE DOWN* will try to move the focus one screen up or down. * The cursor's column is maintained as best as possible when moving from one - :class:`Edit` widget to another. + :class:`~urwid.widget.Edit` widget to another. .. image:: lbcont1.png .. image:: lbcont2.png @@ -246,27 +264,31 @@ Zen of ListBox ListBox Focus and Scrolling --------------------------- -The :class:`ListBox` is a box widget that contains flow widgets. Its contents -are displayed stacked vertically, and the :class:`ListBox` allows the user to -scroll through its content. One of the flow widgets displayed in the -:class:`ListBox` is the focus widget. The :class:`ListBox` passes key presses -to the focus widget to allow the user to interact with it. If the focus widget -does not handle a keypress then the :class:`ListBox` may handle the keypress by -scrolling and/or selecting another widget to become the focus widget. - -The :class:`ListBox` tries to do the most sensible thing when scrolling and -changing focus. When the widgets displayed are all :class:`Text` widgets or -other unselectable widgets then the :class:`ListBox` will behave like a web -browser does when the user presses *UP*, *DOWN*, *PAGE UP* and *PAGE DOWN*: new -text is immediately scrolled in from the top or bottom. The :class:`ListBox` -chooses one of the visible widgets as its focus widget when scrolling. When -scrolling up the :class:`ListBox` chooses the topmost widget as the focus, and -when scrolling down the :class:`ListBox` chooses the bottommost widget as the -focus. +The :class:`~urwid.listbox.ListBox` is a box widget that contains flow widgets. +Its contents are displayed stacked vertically, and the +:class:`~urwid.listbox.ListBox` allows the user to scroll through its content. +One of the flow widgets displayed in the :class:`~urwid.listbox.ListBox` is the +focus widget. The :class:`~urwid.listbox.ListBox` passes key presses to the +focus widget to allow the user to interact with it. If the focus widget does +not handle a keypress then the :class:`~urwid.listbox.ListBox` may handle the +keypress by scrolling and/or selecting another widget to become the focus +widget. + +The :class:`~urwid.listbox.ListBox` tries to do the most sensible thing when +scrolling and changing focus. When the widgets displayed are all +:class:`~urwid.widget.Text` widgets or other unselectable widgets then the +:class:`~urwid.listbox.ListBox` will behave like a web browser does when the +user presses *UP*, *DOWN*, *PAGE UP* and *PAGE DOWN*: new text is immediately +scrolled in from the top or bottom. The :class:`~urwid.listbox.ListBox` chooses +one of the visible widgets as its focus widget when scrolling. When scrolling +up the :class:`~urwid.listbox.ListBox` chooses the topmost widget as the focus, +and when scrolling down the :class:`~urwid.listbox.ListBox` chooses the +bottommost widget as the focus. When all the widgets displayed are not selectable the user would typically have no way to tell which widget is in focus, but if we wrap the widgets with -:class:`AttrWrap` we can see what is happening while the focus changes: +:class:`~urwid.decoration.AttrWrap` we can see what is happening while the +focus changes: .. literalinclude:: lbscr.py :linenos: @@ -278,40 +300,43 @@ no way to tell which widget is in focus, but if we wrap the widgets with .. image:: lbscr5.png .. image:: lbscr6.png -The :class:`ListBox` remembers the location of the widget in focus as either an -"offset" or an "inset". An offset is the number of rows between the top of the -:class:`ListBox` and the beginning of the focus widget. An offset of zero -corresponds to a widget with its top aligned with the top of the -:class:`ListBox`. An inset is the fraction of rows of the focus widget that are -"above" the top of the :class:`ListBox` and not visible. The :class:`ListBox` -uses this method of remembering the focus widget location so that when the -:class:`ListBox` is resized the text displayed will stay roughly aligned with -the top of the :class:`ListBox`. +The :class:`~urwid.listbox.ListBox` remembers the location of the widget in +focus as either an "offset" or an "inset". An offset is the number of rows +between the top of the :class:`~urwid.listbox.ListBox` and the beginning of the +focus widget. An offset of zero corresponds to a widget with its top aligned +with the top of the :class:`~urwid.listbox.ListBox`. An inset is the fraction +of rows of the focus widget that are "above" the top of the +:class:`~urwid.listbox.ListBox` and not visible. The +:class:`~urwid.listbox.ListBox` uses this method of remembering the focus +widget location so that when the :class:`~urwid.listbox.ListBox` is resized the +text displayed will stay roughly aligned with the top of the +:class:`~urwid.listbox.ListBox`. .. image:: lbscr7.png .. image:: lbscr8.png .. image:: lbscr9.png -When there are selectable widgets in the :class:`ListBox` the focus will move -between the selectable widgets, skipping the unselectable widgets. The -:class:`ListBox` will try to scroll all the rows of a selectable widget into -view so that the user can see the new focus widget in its entirety. This -behavior can be used to bring more than a single widget into view by using -composite widgets to combine a selectable widget with other widgets that should -be displayed at the same time. +When there are selectable widgets in the :class:`~urwid.listbox.ListBox` the +focus will move between the selectable widgets, skipping the unselectable +widgets. The :class:`~urwid.listbox.ListBox` will try to scroll all the rows of +a selectable widget into view so that the user can see the new focus widget in +its entirety. This behavior can be used to bring more than a single widget into +view by using composite widgets to combine a selectable widget with other +widgets that should be displayed at the same time. Dynamic ListBox with ListWalker ------------------------------- -While the :class:`ListBox` stores the location of its focus widget, it does not -directly store the actual focus widget or other contents of the -:class:`ListBox`. The storage of a :class:`ListBox`'s content is delegated to a -"List Walker" object. If a list of widgets is passed to the :class:`ListBox` -constructor then it creates a :class:`SimpleListWalker` object to manage the -list. +While the :class:`~urwid.listbox.ListBox` stores the location of its focus +widget, it does not directly store the actual focus widget or other contents of +the :class:`~urwid.listbox.ListBox`. The storage of a +:class:`~urwid.listbox.ListBox`'s content is delegated to a "List Walker" +object. If a list of widgets is passed to the :class:`~urwid.listbox.ListBox` +constructor then it creates a :class:`~urwid.listbox.SimpleListWalker` object +to manage the list. -When the :class:`ListBox` is `rendering a canvas`_ or `handling input`_ it -will: +When the :class:`~urwid.listbox.ListBox` is `rendering a canvas`_ or `handling +input`_ it will: .. _rendering a canvas: http://excess.org/urwid/reference.html#ListBox-render .. _handling input: http://excess.org/urwid/reference.html#ListBox-keypress @@ -328,28 +353,28 @@ will: 4. Optionally call the :meth:`set_focus` method passing one of the position objects returned in the previous steps. -This is the only way the :class:`ListBox` accesses its contents, and it will -not store copies of any of the widgets or position objects beyond the current -rendering or input handling operation. +This is the only way the :class:`~urwid.listbox.ListBox` accesses its contents, +and it will not store copies of any of the widgets or position objects beyond +the current rendering or input handling operation. -The :class:`SimpleListWalker` stores a list of widgets, and uses integer -indexes into this list as its position objects. It stores the focus position as -an integer, so if you insert a widget into the list above the focus position -then you need to remember to increment the focus position in the -:class:`SimpleListWalker` object or the contents of the :class:`ListBox` will -shift. +The :class:`~urwid.listbox.SimpleListWalker` stores a list of widgets, and uses +integer indexes into this list as its position objects. It stores the focus +position as an integer, so if you insert a widget into the list above the focus +position then you need to remember to increment the focus position in the +:class:`~urwid.listbox.SimpleListWalker` object or the contents of the +:class:`~urwid.listbox.ListBox` will shift. -A custom List Walker object may be passed to the :class:`ListBox` constructor instead -of a plain list of widgets. List Walker objects must implement the -`List Walker interface`_. +A custom List Walker object may be passed to the +:class:`~urwid.listbox.ListBox` constructor instead of a plain list of widgets. +List Walker objects must implement the `List Walker interface`_. .. _List Walker interface: http://excess.org/urwid/reference.html#List_Walker_interface_definition The fib.py_ example program demonstrates a custom list walker that doesn't store any widgets. It uses a tuple of two successive Fibonacci numbers as its position objects and it generates Text widgets to display the numbers on the -fly. The result is a :class:`ListBox` that can scroll through an unending list of -widgets. +fly. The result is a :class:`~urwid.listbox.ListBox` that can scroll through an +unending list of widgets. The edit.py_ example program demonstrates a custom list walker that loads lines from a text file only as the user scrolls them into view. This allows even @@ -369,36 +394,38 @@ directories to be hidden from view when they are "collapsed". Setting the focus ----------------- -The easiest way to change the current :class:`ListBox` focus is to call the -:meth:`ListBox.set_focus` method. -This method doesn't require that you know the :class:`ListBox`'s -current dimensions ``(maxcol, maxrow)``. It will wait until the next call to -either keypress or render to complete setting the offset and inset values -using the dimensions passed to that method. +The easiest way to change the current :class:`~urwid.listbox.ListBox` focus is +to call the :meth:`urwid.listbox.ListBox.set_focus` method. This method doesn't +require that you know the :class:`~urwid.listbox.ListBox`'s current dimensions +``(maxcol, maxrow)``. It will wait until the next call to either keypress or +render to complete setting the offset and inset values using the dimensions +passed to that method. The position object passed to :meth:`set_focus` must be compatible with the -List Walker object that the :class:`ListBox` is using. For -:class:`SimpleListWalker` the position is the integer index of the widget -within the list. - -The *coming_from* parameter should be set if you know that the old position -is "above" or "below" the previous position. When the :class:`ListBox` completes -setting the offset and inset values it tries to find the old widget among -the visible widgets. If the old widget is still visible, if will try to -avoid causing the :class:`ListBox` contents to scroll up or down from its previous -position. If the widget is not visible, then the :class:`ListBox` will: - -* Display the new focus at the bottom of the :class:`ListBox` if *coming_from* - is "above". -* Display the new focus at the top of the :class:`ListBox` if *coming_from* is - "below". -* Display the new focus in the middle of the :class:`ListBox` if coming_from is - ``None``. +List Walker object that the :class:`~urwid.listbox.ListBox` is using. For +:class:`~urwid.listbox.SimpleListWalker` the position is the integer index of +the widget within the list. + +The *coming_from* parameter should be set if you know that the old position is +"above" or "below" the previous position. When the +:class:`~urwid.listbox.ListBox` completes setting the offset and inset values +it tries to find the old widget among the visible widgets. If the old widget is +still visible, if will try to avoid causing the :class:`~urwid.listbox.ListBox` +contents to scroll up or down from its previous position. If the widget is not +visible, then the :class:`~urwid.listbox.ListBox` will: + +* Display the new focus at the bottom of the :class:`~urwid.listbox.ListBox` if + *coming_from* is "above". +* Display the new focus at the top of the :class:`~urwid.listbox.ListBox` if + *coming_from* is "below". +* Display the new focus in the middle of the :class:`~urwid.listbox.ListBox` if + coming_from is ``None``. If you know exactly where you want to display the new focus widget within the -:class:`ListBox` you may call :meth:`ListBox.set_focus_valign`. This method -lets you specify the *top*, *bottom*, *middle*, a relative position or the -exact number of rows from the top or bottom of the :class:`ListBox`. +:class:`~urwid.listbox.ListBox` you may call +:meth:`urwid.listbox.ListBox.set_focus_valign`. This method lets you specify +the *top*, *bottom*, *middle*, a relative position or the exact number of rows +from the top or bottom of the :class:`~urwid.listbox.ListBox`. Combining widgets ================= @@ -406,39 +433,40 @@ Combining widgets Piling widgets -------------- -:class:`Pile` widgets are used to combine multiple widgets by stacking them -vertically. A Pile can manage selectable widgets by keeping track of which -widget is in focus and it can handle moving the focus between widgets when the -user presses the *UP* and *DOWN* keys. A Pile will also work well when used -within a :class:`ListBox`. +:class:`~urwid.container.Pile` widgets are used to combine multiple widgets by +stacking them vertically. A Pile can manage selectable widgets by keeping track +of which widget is in focus and it can handle moving the focus between widgets +when the user presses the *UP* and *DOWN* keys. A Pile will also work well when +used within a :class:`~urwid.listbox.ListBox`. A Pile is selectable only if its focus widget is selectable. If you create a Pile containing one Text widget and one Edit widget the Pile will choose the Edit widget as its default focus widget. To change the pile's focus widget you -can call :meth:`Pile.set_focus`. +can call :meth:`urwid.container.Pile.set_focus`. Dividing into columns --------------------- -:class:`Columns` -widgets may be used to arrange either flow widgets or box widgets -horizontally into columns. Columns widgets will manage selectable widgets -by keeping track of which column is in focus and it can handle moving the -focus between columns when the user presses the *LEFT* and *RIGHT* keys. -Columns widgets also work well when used within a :class:`ListBox`. +:class:`~urwid.container.Columns` widgets may be used to arrange either flow +widgets or box widgets horizontally into columns. Columns widgets will manage +selectable widgets by keeping track of which column is in focus and it can +handle moving the focus between columns when the user presses the *LEFT* and +*RIGHT* keys. Columns widgets also work well when used within a +:class:`~urwid.listbox.ListBox`. Columns widgets are selectable only if the column in focus is selectable. If a focus column is not specified the first selectable widget will be chosen as the -focus column. The :meth:`Columns.set_focus` method may be used to select the -focus column. +focus column. The :meth:`urwid.container.Columns.set_focus` method may be used +to select the focus column. ``GridFlow`` Arrangment ----------------------- -The :class:`GridFlow` widget is a flow widget designed for use with -:class:`Button`, :class:`CheckBox` and :class:`RadioButton` widgets. It -renders all the widgets it contains the same width and it arranges them from -left to right and top to bottom. +The :class:`~urwid.container.GridFlow` widget is a flow widget designed for use +with :class:`~urwid.wimp.Button`, :class:`~urwid.wimp.CheckBox` and +:class:`~urwid.wimp.RadioButton` widgets. It renders all the widgets it +contains the same width and it arranges them from left to right and top to +bottom. The GridFlow widget uses Pile, Columns, Padding and Divider widgets to build a display widget that will handle the keyboard input and rendering. When the @@ -448,17 +476,17 @@ new space. ``Overlay`` widgets ------------------- -The :class:`Overlay` widget is a box widget that contains two other box -widgets. The bottom widget is rendered the full size of the Overlay widget and -the top widget is placed on top, obscuring an area of the bottom widget. This -widget can be used to create effects such as overlapping "windows" or pop-up -menus. +The :class:`~urwid.container.Overlay` widget is a box widget that contains two +other box widgets. The bottom widget is rendered the full size of the Overlay +widget and the top widget is placed on top, obscuring an area of the bottom +widget. This widget can be used to create effects such as overlapping "windows" +or pop-up menus. The Overlay widget always treats the top widget as the one in focus. All keyboard input will be passed to the top widget. If you want to use a flow flow widget for the top widget, first wrap the flow -widget with a :class:`Filler` widget. +widget with a :class:`~urwid.decoration.Filler` widget. Creating custom widgets ======================= @@ -475,9 +503,9 @@ widget that doesn't need tight coupling with the original widget, such as a widget that displays customer address information, then wrapping is more appropriate. -The :class:`WidgetWrap` class simplifies wrapping existing widgets. You can -create a custom widget simply by creating a subclass of WidgetWrap and passing -a widget into WidgetWrap's constructor. +The :class:`~urwid.widget.WidgetWrap` class simplifies wrapping existing +widgets. You can create a custom widget simply by creating a subclass of +WidgetWrap and passing a widget into WidgetWrap's constructor. This is an example of a custom widget that uses WidgetWrap: @@ -510,8 +538,9 @@ BoxPudding is a box widget. Pudding will render as much "Pudding" as will fit in a single row, and BoxPudding will render as much "Pudding" as will fit into the entire area given. -It is not strictly necessary to inherit from :class:`BoxWidget` or -:class:`FlowWidget`, but doing so does add some documentation to your code. +It is not strictly necessary to inherit from :class:`~urwid.widget.BoxWidget` +or :class:`~urwid.widget.FlowWidget`, but doing so does add some documentation +to your code. Note that the rows and render methods' focus parameter must have a default value of False. Also note that for flow widgets the number of rows returned by @@ -564,18 +593,19 @@ letters *P*, *U*, *D*, *D*, *I*, *N* and *G* on the keyboard. When the user has Note that keys that are unhandled in the keypress method are returned so that another widget may be able to handle them. This is a good convention to follow unless you have a very good reason not to. In this case the *UP* and *DOWN* -keys are returned so that if this widget is in a :class:`ListBox` the -:class:`ListBox` will behave as the user expects and change the focus or scroll -the :class:`ListBox`. +keys are returned so that if this widget is in a +:class:`~urwid.listbox.ListBox` the :class:`~urwid.listbox.ListBox` will behave +as the user expects and change the focus or scroll the +:class:`~urwid.listbox.ListBox`. Widget displaying the cursor ---------------------------- Widgets that display the cursor must implement the get_cursor_coords_ method. Similar to the rows method for flow widgets, this method lets other widgets -make layout decisions without rendering the entire widget. The :class:`ListBox` -widget in particular uses get_cursor_coords to make sure that the cursor is -visible within its focus widget. +make layout decisions without rendering the entire widget. The +:class:`~urwid.listbox.ListBox` widget in particular uses get_cursor_coords to +make sure that the cursor is visible within its focus widget. .. _get_cursor_coords: http://excess.org/urwid/reference.html#Widget_interface_definition-get_cursor_coords @@ -594,12 +624,13 @@ moving up or down off this widget. .. _get_pref_col: http://excess.org/urwid/reference.html#Widget_interface_definition-get_pref_col Another optional method is move_cursor_to_coords_. This method allows other -widgets to try to position the cursor within this widget. The :class:`ListBox` -widget uses :meth:`move_cursor_to_coords` when changing focus and when the user -pressed *PAGE UP* or *PAGE DOWN*. This method must return ``True`` on success -and ``False`` on failure. If the cursor may be placed at any position within -the row specified (not only at the exact column specified) then this method -must move the cursor to that position and return ``True``. +widgets to try to position the cursor within this widget. The +:class:`~urwid.listbox.ListBox` widget uses :meth:`move_cursor_to_coords` when +changing focus and when the user pressed *PAGE UP* or *PAGE DOWN*. This method +must return ``True`` on success and ``False`` on failure. If the cursor may be +placed at any position within the row specified (not only at the exact column +specified) then this method must move the cursor to that position and return +``True``. .. _move_cursor_to_coords: http://excess.org/urwid/reference.html#Widget_interface_definition-move_cursor_to_coords |
