Placeholder of output .. deprecated:: 1.5 See :ref:`User Guide ` for new way to set css style for output. ``output()`` can be passed in anywhere that ``put_xxx()`` can passed in. A handler it returned by ``output()``, and after being output, the content can also be
(*contents)
| 1803 | |
| 1804 | @safely_destruct_output_when_exp('contents') |
| 1805 | def output(*contents): |
| 1806 | """Placeholder of output |
| 1807 | |
| 1808 | .. deprecated:: 1.5 |
| 1809 | See :ref:`User Guide <put_scope>` for new way to set css style for output. |
| 1810 | |
| 1811 | ``output()`` can be passed in anywhere that ``put_xxx()`` can passed in. A handler it returned by ``output()``, |
| 1812 | and after being output, the content can also be modified by the handler (See code example below). |
| 1813 | |
| 1814 | :param contents: The initial contents to be output. |
| 1815 | The item is ``put_xxx()`` call, and any other type will be converted to ``put_text(content)``. |
| 1816 | :return: An OutputHandler instance, the methods of the instance are as follows: |
| 1817 | |
| 1818 | * ``reset(*contents)`` : Reset original contents to ``contents`` |
| 1819 | * ``append(*contents)`` : Append ``contents`` to original contents |
| 1820 | * ``insert(idx, *contents)`` : insert ``contents`` into original contents. |
| 1821 | |
| 1822 | | when idx>=0, the output content is inserted before the element of the ``idx`` index. |
| 1823 | | when idx<0, the output content is inserted after the element of the ``idx`` index. |
| 1824 | |
| 1825 | Among them, the parameter ``contents`` is the same as ``output()``. |
| 1826 | |
| 1827 | :Example: |
| 1828 | |
| 1829 | .. exportable-codeblock:: |
| 1830 | :name: output |
| 1831 | :summary: `output()` usage |
| 1832 | |
| 1833 | hobby = output(put_text('Coding')) # equal to output('Coding') |
| 1834 | put_table([ |
| 1835 | ['Name', 'Hobbies'], |
| 1836 | ['Wang', hobby] # hobby is initialized to Coding |
| 1837 | ]) |
| 1838 | ## ---- |
| 1839 | |
| 1840 | hobby.reset('Movie') # hobby is reset to Movie |
| 1841 | ## ---- |
| 1842 | hobby.append('Music', put_text('Drama')) # append Music, Drama to hobby |
| 1843 | ## ---- |
| 1844 | hobby.insert(0, put_markdown('**Coding**')) # insert the Coding into the top of the hobby |
| 1845 | |
| 1846 | """ |
| 1847 | |
| 1848 | import warnings |
| 1849 | |
| 1850 | # use stacklevel=2 to make the warning refer to the output() call |
| 1851 | warnings.warn("`pywebio.output.output()` is deprecated since v1.5 and will remove in the future version, " |
| 1852 | "use `pywebio.output.put_scope()` instead", DeprecationWarning, stacklevel=2) |
| 1853 | |
| 1854 | class OutputHandler(Output): |
| 1855 | """ |
| 1856 | 与 `Output` 的不同在于, 不会在销毁时(__del__)自动输出 |
| 1857 | The difference with `Output` is that `OutputHandler` will not automatically output when destroyed (__del__) |
| 1858 | """ |
| 1859 | |
| 1860 | def __del__(self): |
| 1861 | pass |
| 1862 |
no test coverage detected
searching dependent graphs…