././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1761054867.9528415 urwidtrees-1.0.4/0000755000076500000240000000000015075710224012404 5ustar00basstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/LICENSE.md0000644000076500000240000010450515075706742014027 0ustar00basstaff GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {one line to give the program's name and a brief idea of what it does.} Copyright (C) {year} {name of author} This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: {project} Copyright (C) {year} {fullname} This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1761054867.9526596 urwidtrees-1.0.4/PKG-INFO0000644000076500000240000000102415075710224013476 0ustar00basstaffMetadata-Version: 2.4 Name: urwidtrees Version: 1.0.4 Summary: Tree widgets for urwid Home-page: https://github.com/pazz/urwidtrees Author: Patrick Totzke Author-email: patricktotzke@gmail.com License: Licensed under the GNU GPL v3+. License-File: LICENSE.md Requires-Dist: urwid>=1.1.0 Provides-Extra: docs Requires-Dist: mock; python_version < "3.3" and extra == "docs" Dynamic: author Dynamic: author-email Dynamic: home-page Dynamic: license Dynamic: license-file Dynamic: provides-extra Dynamic: requires-dist Dynamic: summary ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/README.md0000644000076500000240000000176115075706742013702 0ustar00basstaffUrwid Tree Container API ======================== [![Docs Build][rtfd-img]][rtfd] This is a Widget Container API for the [urwid](http://urwid.org/) toolkit. It uses a MVC approach and allows to build trees of widgets. Its design goals are * clear separation classes that define, decorate and display trees of widgets * representation of trees by local operations on node positions * easy to use default implementation for simple trees * Collapses are considered decoration See the `docs/` subdirectory for autogenetated API docs. ### Examples [](docs/examples/example1.py) [](docs/examples/example2.arrows.py) [](docs/examples/example3.collapse.py) [](docs/examples/example5.nested.py) [rtfd-img]: https://readthedocs.org/projects/urwidtrees/badge/ [rtfd]: https://urwidtrees.readthedocs.org/en/latest/ ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1761054867.952877 urwidtrees-1.0.4/setup.cfg0000644000076500000240000000004615075710224014225 0ustar00basstaff[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/setup.py0000755000076500000240000000112215075706742014127 0ustar00basstaff#!/usr/bin/env python from setuptools import setup # this loads the version string into __version__ with open('urwidtrees/version.py') as f: exec(f.read()) setup( name='urwidtrees', version=__version__, description="Tree widgets for urwid", author="Patrick Totzke", author_email="patricktotzke@gmail.com", url="https://github.com/pazz/urwidtrees", license="Licensed under the GNU GPL v3+.", packages=['urwidtrees'], install_requires=['urwid>=1.1.0'], extras_require={ 'docs': [ 'mock;python_version<"3.3"', ], }, ) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1761054867.9516773 urwidtrees-1.0.4/urwidtrees/0000755000076500000240000000000015075710224014601 5ustar00basstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/urwidtrees/__init__.py0000644000076500000240000000045615075706742016731 0ustar00basstafffrom .tree import Tree, SimpleTree from .decoration import DecoratedTree, CollapsibleTree from .decoration import IndentedTree, CollapsibleIndentedTree from .decoration import ArrowTree, CollapsibleArrowTree from .nested import NestedTree from .widgets import TreeBox from .version import __version__ ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/urwidtrees/decoration.py0000644000076500000240000004663515075706742017332 0ustar00basstaff# Copyright (C) 2013 Patrick Totzke # This file is released under the GNU GPL, version 3 or a later revision. import urwid from .tree import Tree, SimpleTree class NoSpaceError(Exception): """too little space for requested decoration""" class DecoratedTree(Tree): """ :class:`Tree` that wraps around another :class:`Tree` and allows to read original content as well as decorated versions thereof. """ def __init__(self, content): if not isinstance(content, Tree): # do we need this? content = SimpleTree(content) self._tree = content self.root = self._tree.root def get_decorated(self, pos): """ return widget that consists of the content of original tree at given position plus its decoration. """ return self.decorate(pos, self[pos]) def decorate(self, pos, widget, is_first=True): """ decorate `widget` according to a position `pos` in the original tree. setting `is_first` to False indicates that we are decorating a line that is *part* of the (multi-line) content at this position, but not the first part. This allows to omit incoming arrow heads for example. """ return widget # pass on everything else to the original tree. def parent_position(self, pos): return self._tree.parent_position(pos) def first_child_position(self, pos): return self._tree.first_child_position(pos) def last_child_position(self, pos): return self._tree.last_child_position(pos) def next_sibling_position(self, pos): return self._tree.next_sibling_position(pos) def prev_sibling_position(self, pos): return self._tree.prev_sibling_position(pos) def __getitem__(self, pos): return self._tree[pos] class CollapseMixin(object): """ Mixin for :class:`Tree` that allows to collapse subtrees. This works by overwriting :meth:`[first|last]_child_position `, forcing them to return `None` if the given position is considered collapsed. We use a (given) callable `is_collapsed` that accepts positions and returns a boolean to determine which node is considered collapsed. """ def __init__(self, is_collapsed=lambda pos: False, **kwargs): self._initially_collapsed = is_collapsed self._divergent_positions = [] def is_collapsed(self, pos): """checks if given position is currently collapsed""" collapsed = self._initially_collapsed(pos) if pos in self._divergent_positions: collapsed = not collapsed return collapsed # implement functionality by overwriting local position transformations # TODO: ATM this assumes we are in a wrapper: it uses self._tree. # This is not necessarily true, for example for subclasses of SimpleTree! # maybe define this whole class as a wrapper? def last_child_position(self, pos): if self.is_collapsed(pos): return None return self._tree.last_child_position(pos) def first_child_position(self, pos): if self.is_collapsed(pos): return None return self._tree.first_child_position(pos) def collapsible(self, pos): return not self._tree.is_leaf(pos) def set_position_collapsed(self, pos, is_collapsed): if self.collapsible(pos): if self._initially_collapsed(pos) == is_collapsed: if pos in self._divergent_positions: self._divergent_positions.remove(pos) else: if pos not in self._divergent_positions: self._divergent_positions.append(pos) def toggle_collapsed(self, pos): self.set_position_collapsed(pos, not self.is_collapsed(pos)) def collapse(self, pos): self.set_position_collapsed(pos, True) def collapse_all(self): self.set_collapsed_all(True) def expand_all(self): self.set_collapsed_all(False) def set_collapsed_all(self, is_collapsed): self._initially_collapsed = lambda x: is_collapsed self._divergent_positions = [] def expand(self, pos): self.set_position_collapsed(pos, False) class CollapseIconMixin(CollapseMixin): """ Mixin for :class:`Tree` that allows to collapse subtrees and use an indicator icon in line decorations. This Mixin adds the ability to construct collapse-icon for a position, indicating its collapse status to :class:`CollapseMixin`. """ def __init__(self, is_collapsed=lambda pos: False, icon_collapsed_char='+', icon_expanded_char='-', icon_collapsed_att=None, icon_expanded_att=None, icon_frame_left_char='[', icon_frame_right_char=']', icon_frame_att=None, icon_focussed_att=None, **kwargs): """TODO: docstrings""" CollapseMixin.__init__(self, is_collapsed, **kwargs) self._icon_collapsed_char = icon_collapsed_char self._icon_expanded_char = icon_expanded_char self._icon_collapsed_att = icon_collapsed_att self._icon_expanded_att = icon_expanded_att self._icon_frame_left_char = icon_frame_left_char self._icon_frame_right_char = icon_frame_right_char self._icon_frame_att = icon_frame_att self._icon_focussed_att = icon_focussed_att def _construct_collapse_icon(self, pos): width = 0 widget = None char = self._icon_expanded_char charatt = self._icon_expanded_att if self.is_collapsed(pos): char = self._icon_collapsed_char charatt = self._icon_collapsed_att if char is not None: columns = [] if self._icon_frame_left_char is not None: lchar = self._icon_frame_left_char charlen = len(lchar) leftframe = urwid.Text((self._icon_frame_att, lchar)) columns.append((charlen, leftframe)) width += charlen # next we build out icon widget: we feed all markups to a Text, # make it selectable (to toggle collapse) if requested markup = (charatt, char) widget = urwid.Text(markup) charlen = len(char) columns.append((charlen, widget)) width += charlen if self._icon_frame_right_char is not None: rchar = self._icon_frame_right_char charlen = len(rchar) rightframe = urwid.Text((self._icon_frame_att, rchar)) columns.append((charlen, rightframe)) width += charlen widget = urwid.Columns(columns) return width, widget class CollapsibleTree(CollapseMixin, DecoratedTree): """Undecorated Tree that allows to collapse subtrees""" def __init__(self, tree, **kwargs): DecoratedTree.__init__(self, tree) CollapseMixin.__init__(self, **kwargs) class IndentedTree(DecoratedTree): """Indent tree nodes according to their depth in the tree""" def __init__(self, tree, indent=2): """ :param tree: tree of widgets to be displayed :type tree: Tree :param indent: indentation width :type indent: int """ self._indent = indent DecoratedTree.__init__(self, tree) def decorate(self, pos, widget, is_first=True): indent = self._tree.depth(pos) * self._indent cols = [(indent, urwid.SolidFill(' ')), widget] # construct a Columns, defining all spacer as Box widgets line = urwid.Columns(cols, box_columns=range(len(cols))[:-1]) return line class CollapsibleIndentedTree(CollapseIconMixin, IndentedTree): """ Indent collapsible tree nodes according to their depth in the tree and display icons indicating collapse-status in the gaps. """ def __init__(self, walker, icon_offset=1, indent=4, **kwargs): """ :param walker: tree of widgets to be displayed :type walker: Tree :param indent: indentation width :type indent: int :param icon_offset: distance from icon to the eginning of the tree node. :type icon_offset: int """ self._icon_offset = icon_offset IndentedTree.__init__(self, walker, indent=indent) CollapseIconMixin.__init__(self, **kwargs) def decorate(self, pos, widget, is_first=True): """ builds a list element for given position in the tree. It consists of the original widget taken from the Tree and some decoration columns depending on the existence of parent and sibling positions. The result is a urwid.Columns widget. """ void = urwid.SolidFill(' ') line = None cols = [] depth = self._tree.depth(pos) # add spacer filling all but the last indent if depth > 0: cols.append((depth * self._indent, void)), # spacer # construct last indent # TODO iwidth, icon = self._construct_collapse_icon(pos) available_space = self._indent firstindent_width = self._icon_offset + iwidth # stop if indent is too small for this decoration if firstindent_width > available_space: raise NoSpaceError() # add icon only for non-leafs is_leaf = self._tree.is_leaf(pos) if not is_leaf: if icon is not None: # space to the left cols.append((available_space - firstindent_width, urwid.SolidFill(' '))) # icon icon_pile = urwid.Pile([('pack', icon), void]) cols.append((iwidth, icon_pile)) # spacer until original widget available_space = self._icon_offset cols.append((available_space, urwid.SolidFill(' '))) else: # otherwise just add another spacer cols.append((self._indent, urwid.SolidFill(' '))) cols.append(widget) # original widget ] # construct a Columns, defining all spacer as Box widgets line = urwid.Columns(cols, box_columns=range(len(cols))[:-1]) return line class ArrowTree(IndentedTree): """ Decorates the tree by indenting nodes according to their depth and using the gaps to draw arrows indicate the tree structure. """ def __init__(self, walker, indent=3, childbar_offset=0, arrow_hbar_char=u'\u2500', arrow_hbar_att=None, arrow_vbar_char=u'\u2502', arrow_vbar_att=None, arrow_tip_char=u'\u27a4', arrow_tip_att=None, arrow_att=None, arrow_connector_tchar=u'\u251c', arrow_connector_lchar=u'\u2514', arrow_connector_att=None, **kwargs): """ :param walker: tree of widgets to be displayed :type walker: Tree :param indent: indentation width :type indent: int """ IndentedTree.__init__(self, walker, indent) self._childbar_offset = childbar_offset self._arrow_hbar_char = arrow_hbar_char self._arrow_hbar_att = arrow_hbar_att self._arrow_vbar_char = arrow_vbar_char self._arrow_vbar_att = arrow_vbar_att self._arrow_connector_lchar = arrow_connector_lchar self._arrow_connector_tchar = arrow_connector_tchar self._arrow_connector_att = arrow_connector_att self._arrow_tip_char = arrow_tip_char self._arrow_tip_att = arrow_tip_att self._arrow_att = arrow_att def _construct_spacer(self, pos, acc): """ build a spacer that occupies the horizontally indented space between pos's parent and the root node. It will return a list of tuples to be fed into a Columns widget. """ parent = self._tree.parent_position(pos) if parent is not None: grandparent = self._tree.parent_position(parent) if self._indent > 0 and grandparent is not None: parent_sib = self._tree.next_sibling_position(parent) draw_vbar = parent_sib is not None and \ self._arrow_vbar_char is not None space_width = self._indent - 1 * (draw_vbar) - self._childbar_offset if space_width > 0: void = urwid.AttrMap(urwid.SolidFill(' '), self._arrow_att) acc.insert(0, ((space_width, void))) if draw_vbar: barw = urwid.SolidFill(self._arrow_vbar_char) bar = urwid.AttrMap(barw, self._arrow_vbar_att or self._arrow_att) acc.insert(0, ((1, bar))) return self._construct_spacer(parent, acc) else: return acc def _construct_connector(self, pos): """ build widget to be used as "connector" bit between the vertical bar between siblings and their respective horizontal bars leading to the arrow tip """ # connector symbol, either L or |- shaped. connectorw = None connector = None if self._tree.next_sibling_position(pos) is not None: # |- shaped if self._arrow_connector_tchar is not None: connectorw = urwid.Text(self._arrow_connector_tchar) else: # L shaped if self._arrow_connector_lchar is not None: connectorw = urwid.Text(self._arrow_connector_lchar) if connectorw is not None: att = self._arrow_connector_att or self._arrow_att connector = urwid.AttrMap(connectorw, att) return connector def _construct_arrow_tip(self, pos): """returns arrow tip as (width, widget)""" arrow_tip = None width = 0 if self._arrow_tip_char: txt = urwid.Text(self._arrow_tip_char) arrow_tip = urwid.AttrMap( txt, self._arrow_tip_att or self._arrow_att) width = len(self._arrow_tip_char) return width, arrow_tip def _construct_first_indent(self, pos): """ build spacer to occupy the first indentation level from pos to the left. This is separate as it adds arrowtip and sibling connector. """ cols = [] void = urwid.AttrMap(urwid.SolidFill(' '), self._arrow_att) available_width = self._indent if self._tree.depth(pos) > 0: connector = self._construct_connector(pos) if connector is not None: width = connector.pack()[0] if width > available_width: raise NoSpaceError() available_width -= width if self._tree.next_sibling_position(pos) is not None: barw = urwid.SolidFill(self._arrow_vbar_char) below = urwid.AttrMap(barw, self._arrow_vbar_att or self._arrow_att) else: below = void # pile up connector and bar spacer = urwid.Pile([('pack', connector), below]) cols.append((width, spacer)) #arrow tip awidth, at = self._construct_arrow_tip(pos) if at is not None: if awidth > available_width: raise NoSpaceError() available_width -= awidth at_spacer = urwid.Pile([('pack', at), void]) cols.append((awidth, at_spacer)) # bar between connector and arrow tip if available_width > 0: barw = urwid.SolidFill(self._arrow_hbar_char) bar = urwid.AttrMap( barw, self._arrow_hbar_att or self._arrow_att) hb_spacer = urwid.Pile([(1, bar), void]) cols.insert(1, (available_width, hb_spacer)) return cols def decorate(self, pos, widget, is_first=True): """ builds a list element for given position in the tree. It consists of the original widget taken from the Tree and some decoration columns depending on the existence of parent and sibling positions. The result is a urwid.Columns widget. """ line = None if pos is not None: original_widget = widget cols = self._construct_spacer(pos, []) # Construct arrow leading from parent here, # if we have a parent and indentation is turned on if self._indent > 0: if is_first: indent = self._construct_first_indent(pos) if indent is not None: cols = cols + indent else: parent = self._tree.parent_position(pos) if self._indent > 0 and parent is not None: parent_sib = self._tree.next_sibling_position(pos) draw_vbar = parent_sib is not None void = urwid.AttrMap(urwid.SolidFill(' '), self._arrow_att) if self._childbar_offset > 0: cols.append((self._childbar_offset, void)) if draw_vbar: barw = urwid.SolidFill(self._arrow_vbar_char) bar = urwid.AttrMap( barw, self._arrow_vbar_att or self._arrow_att) rspace_width = self._indent - \ 1 - self._childbar_offset cols.append((1, bar)) cols.append((rspace_width, void)) else: cols.append((self._indent, void)) # add the original widget for this line cols.append(original_widget) # construct a Columns, defining all spacer as Box widgets line = urwid.Columns(cols, box_columns=range(len(cols))[:-1]) return line class CollapsibleArrowTree(CollapseIconMixin, ArrowTree): """Arrow-decoration that allows collapsing subtrees""" def __init__(self, treelistwalker, icon_offset=0, indent=5, **kwargs): self._icon_offset = icon_offset ArrowTree.__init__(self, treelistwalker, indent, **kwargs) CollapseIconMixin.__init__(self, **kwargs) def _construct_arrow_tip(self, pos): cols = [] overall_width = self._icon_offset if self._icon_offset > 0: # how often we repeat the hbar_char until width icon_offset is # reached hbar_char_count = len(self._arrow_hbar_char) / self._icon_offset barw = urwid.Text(self._arrow_hbar_char * hbar_char_count) bar = urwid.AttrMap(barw, self._arrow_hbar_att or self._arrow_att) cols.insert(1, (self._icon_offset, bar)) # add icon only for non-leafs if self.collapsible(pos): iwidth, icon = self._construct_collapse_icon(pos) if icon is not None: cols.insert(0, (iwidth, icon)) overall_width += iwidth # get arrow tip awidth, tip = ArrowTree._construct_arrow_tip(self, pos) if tip is not None: cols.append((awidth, tip)) overall_width += awidth return overall_width, urwid.Columns(cols) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/urwidtrees/lru_cache.py0000644000076500000240000001365615075706742017125 0ustar00basstaff# This is a backport of functools.lru_cache, which is part of the stdlib =>v3.3. # http://code.activestate.com/recipes/578078-py26-and-py30-backport-of-python-33s-lru-cache/ from collections import namedtuple from functools import update_wrapper from threading import Lock _CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) def lru_cache(maxsize=100, typed=False): """Least-recently-used cache decorator. If *maxsize* is set to None, the LRU features are disabled and the cache can grow without bound. If *typed* is True, arguments of different types will be cached separately. For example, f(3.0) and f(3) will be treated as distinct calls with distinct results. Arguments to the cached function must be hashable. View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__. See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used """ # Users should only access the lru_cache through its public API: # cache_info, cache_clear, and f.__wrapped__ # The internals of the lru_cache are encapsulated for thread safety and # to allow the implementation to change (including a possible C version). def decorating_function(user_function): cache = dict() stats = [0, 0] # make statistics updateable non-locally HITS, MISSES = 0, 1 # names for the stats fields kwd_mark = (object(),) # separate positional and keyword args cache_get = cache.get # bound method to lookup key or return None _len = len # localize the global len() function lock = Lock() # because linkedlist updates aren't threadsafe root = [] # root of the circular doubly linked list nonlocal_root = [root] # make updateable non-locally root[:] = [root, root, None, None] # initialize by pointing to self PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields def make_key(args, kwds, typed, tuple=tuple, sorted=sorted, type=type): # helper function to build a cache key from positional and keyword args key = args if kwds: sorted_items = tuple(sorted(kwds.items())) key += kwd_mark + sorted_items if typed: key += tuple(type(v) for v in args) if kwds: key += tuple(type(v) for k, v in sorted_items) return key if maxsize == 0: def wrapper(*args, **kwds): # no caching, just do a statistics update after a successful call result = user_function(*args, **kwds) stats[MISSES] += 1 return result elif maxsize is None: def wrapper(*args, **kwds): # simple caching without ordering or size limit key = make_key(args, kwds, typed) if kwds or typed else args result = cache_get(key, root) # root used here as a unique not-found sentinel if result is not root: stats[HITS] += 1 return result result = user_function(*args, **kwds) cache[key] = result stats[MISSES] += 1 return result else: def wrapper(*args, **kwds): # size limited caching that tracks accesses by recency key = make_key(args, kwds, typed) if kwds or typed else args with lock: link = cache_get(key) if link is not None: # record recent use of the key by moving it to the front of the list root, = nonlocal_root link_prev, link_next, key, result = link link_prev[NEXT] = link_next link_next[PREV] = link_prev last = root[PREV] last[NEXT] = root[PREV] = link link[PREV] = last link[NEXT] = root stats[HITS] += 1 return result result = user_function(*args, **kwds) with lock: root = nonlocal_root[0] if _len(cache) < maxsize: # put result in a new link at the front of the list last = root[PREV] link = [last, root, key, result] cache[key] = last[NEXT] = root[PREV] = link else: # use root to store the new key and result root[KEY] = key root[RESULT] = result cache[key] = root # empty the oldest link and make it the new root root = nonlocal_root[0] = root[NEXT] del cache[root[KEY]] root[KEY] = None root[RESULT] = None stats[MISSES] += 1 return result def cache_info(): """Report cache statistics""" with lock: return _CacheInfo(stats[HITS], stats[MISSES], maxsize, len(cache)) def cache_clear(): """Clear the cache and cache statistics""" with lock: cache.clear() root = nonlocal_root[0] root[:] = [root, root, None, None] stats[:] = [0, 0] wrapper.__wrapped__ = user_function wrapper.cache_info = cache_info wrapper.cache_clear = cache_clear return update_wrapper(wrapper, user_function) return decorating_function ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/urwidtrees/nested.py0000644000076500000240000003701715075706742016457 0ustar00basstaff# Copyright (C) 2013 Patrick Totzke # This file is released under the GNU GPL, version 3 or a later revision. from .tree import Tree from .decoration import DecoratedTree, CollapseMixin class NestedTree(Tree): """ A Tree that wraps around Trees that may contain list walkers or other trees. The wrapped tree may contain normal widgets as well. List walkers and subtree contents will be expanded into the tree presented by this wrapper. This wrapper's positions are tuples of positions of the original and subtrees: For example, `(X,Y,Z)` points at position Z in tree/list at position Y in tree/list at position X in the original tree. NestedTree transparently behaves like a collapsible DecoratedTree. """ @property def root(self): root = (self._tree.root,) rcontent = self._tree[self._tree.root] if isinstance(rcontent, Tree): root = root + (rcontent.root,) return root def _sanitize_position(self, pos, tree=None): """ Ensure a position tuple until the result does not point to a :class:`Tree` any more. """ if pos is not None: tree = tree or self._tree entry = self._lookup_entry(tree, pos) if isinstance(entry, Tree): pos = pos + self._sanitize_position((entry.root,), tree=entry) return pos def __init__(self, tree, interpret_covered=False): self._tree = tree self._interpret_covered = interpret_covered def _lookup_entry(self, tree, pos): if len(pos) == 0: entry = tree[tree.root] else: entry = tree[pos[0]] if len(pos) > 1 and isinstance(entry, Tree): subtree = entry entry = self._lookup_entry(subtree, pos[1:]) return entry def _depth(self, tree, pos, outmost_only=True): depth = self._tree.depth(pos[1:]) if not outmost_only: entry = self._tree[pos[0]] if isinstance(entry, Tree) and len(pos) > 1: depth += self._depth(entry, pos[1:], outmost_only=False) return depth def depth(self, pos, outmost=True): return self._depth(self._tree, pos) def __getitem__(self, pos): return self._lookup_entry(self._tree, pos) # DecoratedTree API def _get_decorated_entry(self, tree, pos, widget=None, is_first=True): entry = tree[pos[0]] if entry is None: return None if len(pos) > 1 and isinstance(entry, Tree): subtree = entry entry = self._get_decorated_entry( subtree, pos[1:], widget, is_first) else: entry = widget or entry if isinstance(tree, (DecoratedTree, NestedTree)): # has decorate-API isf = len(pos) < 2 if not isf and isinstance(tree[pos[0]], Tree): isf = (tree[pos[0]].parent_position(pos[1]) is None) or not is_first entry = tree.decorate(pos[0], entry, is_first=isf) return entry def get_decorated(self, pos): return self._get_decorated_entry(self._tree, pos) def decorate(self, pos, widget, is_first=True): return self._get_decorated_entry(self._tree, pos, widget, is_first) # Collapse API def _get_subtree_for(self, pos): """returns Tree that manages pos[-1]""" res = self._tree candidate = self._lookup_entry(self._tree, pos[:-1]) if isinstance(candidate, Tree): res = candidate return res def collapsible(self, pos): res = False subtree = self._get_subtree_for(pos) if isinstance(subtree, (CollapseMixin, NestedTree)): res = subtree.collapsible(pos[-1]) return res def is_collapsed(self, pos): res = False subtree = self._get_subtree_for(pos) if isinstance(subtree, (CollapseMixin, NestedTree)): res = subtree.is_collapsed(pos[-1]) return res def toggle_collapsed(self, pos): subtree = self._get_subtree_for(pos) if isinstance(subtree, (CollapseMixin, NestedTree)): subtree.toggle_collapsed(pos) def collapse(self, pos): subtree = self._get_subtree_for(pos) if isinstance(subtree, (CollapseMixin, NestedTree)): subtree.collapse(pos[-1]) def collapse_all(self): self._collapse_all(self._tree, self.root) def _collapse_all(self, tree, pos=None): if pos is not None: if isinstance(tree, (CollapseMixin, NestedTree)): tree.expand_all() if len(pos) > 1: self._collapse_all(tree[pos[0]], pos[1:]) nextpos = tree.next_position(pos[0]) if nextpos is not None: nentry = tree[nextpos] if isinstance(nentry, Tree): self._collapse_all(nentry, (nentry.root,)) self._collapse_all(tree, (nextpos,)) if isinstance(tree, (CollapseMixin, NestedTree)): tree.collapse_all() def expand(self, pos): subtree = self._get_subtree_for(pos) if isinstance(subtree, (CollapseMixin, NestedTree)): subtree.expand(pos[-1]) def expand_all(self): self._expand_all(self._tree, self.root) def _expand_all(self, tree, pos=None): if pos is not None: if isinstance(tree, (CollapseMixin, NestedTree)): tree.expand_all() if len(pos) > 1: self._expand_all(tree[pos[0]], pos[1:]) nextpos = tree.next_position(pos[0]) if nextpos is not None: nentry = tree[nextpos] if isinstance(nentry, Tree): self._expand_all(nentry, (nentry.root,)) self._expand_all(tree, (nextpos,)) if isinstance(tree, (CollapseMixin, NestedTree)): tree.expand_all() def is_leaf(self, pos, outmost_only=False): return self.first_child_position(pos, outmost_only) is None ################################################ # Tree API ################################################ def parent_position(self, pos): candidate_pos = self._parent_position(self._tree, pos) # return sanitized path (ensure it points to content, not a subtree) return self._sanitize_position(candidate_pos) def _parent_position(self, tree, pos): candidate_pos = None if len(pos) > 1: # get the deepest subtree subtree_pos = pos[:-1] subtree = self._lookup_entry(tree, subtree_pos) # get parent for our position in this subtree least_pos = pos[-1] subparent_pos = subtree.parent_position(least_pos) if subparent_pos is not None: # in case there is one, we are done, the position we look for # is the path up to the subtree plus the local parent position. candidate_pos = subtree_pos + (subparent_pos,) else: # otherwise we recur and look for subtree's parent in the next # outer tree candidate_pos = self._parent_position(self._tree, subtree_pos) else: # there is only one position in the path, we return its parent in # the outmost tree outer_parent = self._tree.parent_position(pos[0]) if outer_parent is not None: # result needs to be valid position (tuple of local positions) candidate_pos = outer_parent, return candidate_pos def first_child_position(self, pos, outmost_only=False): childpos = self._first_child_position(self._tree, pos, outmost_only) return self._sanitize_position(childpos, self._tree) def _first_child_position(self, tree, pos, outmost_only=False): childpos = None # get content at first path element in outmost tree entry = tree[pos[0]] if isinstance(entry, Tree) and not outmost_only and len(pos) > 1: # this points to a tree and we don't check the outmost tree only # recur: get first child in the subtree for remaining path subchild = self._first_child_position(entry, pos[1:]) if subchild is not None: # found a childposition, re-append the path up to this subtree childpos = (pos[0],) + subchild return childpos else: # continue in the next outer tree only if we do not drop # "covered" parts and the position path points to a parent-less # position in the subtree. if (entry.parent_position(pos[1]) is not None or not self._interpret_covered): return None # return the first child of the outmost tree outerchild = tree.first_child_position(pos[0]) if outerchild is not None: childpos = outerchild, return childpos def last_child_position(self, pos, outmost_only=False): childpos = self._last_child_position(self._tree, pos, outmost_only) return self._sanitize_position(childpos, self._tree) def _last_child_position(self, tree, pos, outmost_only=False): childpos = None # get content at first path element in outmost tree entry = tree[pos[0]] if isinstance(entry, Tree) and not outmost_only and len(pos) > 1: # this points to a tree and we don't check the outmost tree only # get last child in the outmost tree if we do not drop "covered" # parts and the position path points to a root of the subtree. if self._interpret_covered and entry.parent_position(pos[1]) is None: # return the last child of the outmost tree outerchild = tree.last_child_position(pos[0]) if outerchild is not None: childpos = outerchild, # continue as if we have not found anything yet if childpos is None: # recur: get last child in the subtree for remaining path subchild = self._last_child_position(entry, pos[1:]) if subchild is not None: # found a childposition, re-prepend path up to this subtree childpos = (pos[0],) + subchild else: # outmost position element does not point to a tree: # return the last child of the outmost tree outerchild = tree.last_child_position(pos[0]) if outerchild is not None: childpos = outerchild, return childpos def _next_sibling_position(self, tree, pos): candidate = None if len(pos) > 1: # if position path does not point to position in outmost tree, # first get the subtree as pointed out by first dimension, recur # and check if some inner tree already returns a sibling subtree = tree[pos[0]] subsibling_pos = self._next_sibling_position(subtree, pos[1:]) if subsibling_pos is not None: # we found our sibling, prepend the path up to the subtree candidate = pos[:1] + subsibling_pos else: # no deeper tree has sibling. If inner position is root node # the sibling in the outer tree is a valid candidate subparent = subtree.parent_position(pos[1]) if subparent is None: # check if outer tree defines sibling next_sib = tree.next_sibling_position(pos[0]) if next_sib is not None: # it has, we found our candidate candidate = next_sib, # if the inner position has depth 1, then the first child # of its parent in the outer tree can be seen as candidate for # this position next sibling. Those live in the shadow of the # inner tree and are hidden unless requested otherwise elif subtree.parent_position(subparent) is None and \ self._interpret_covered: # we respect "covered" stuff and inner position has depth 1 # get (possibly nested) first child in outer tree candidate = self._first_child_position(tree, pos[:1]) else: # the position path points to the outmost tree # just return its next sibling in the outmost tree next_sib = tree.next_sibling_position(pos[0]) if next_sib is not None: candidate = next_sib, return candidate def next_sibling_position(self, pos): candidate = self._next_sibling_position(self._tree, pos) return self._sanitize_position(candidate, self._tree) def _prev_sibling_position(self, tree, pos): candidate = None if len(pos) > 1: # if position path does not point to position in outmost tree, # first get the subtree as pointed out by first dimension, recur # and check if some inner tree already returns a sibling subtree = tree[pos[0]] subsibling_pos = self._prev_sibling_position(subtree, pos[1:]) if subsibling_pos is not None: # we found our sibling, prepend the path up to the subtree candidate = pos[:1] + subsibling_pos else: # no deeper tree has sibling. If inner position is root node # the sibling in the outer tree is a valid candidate subparent = subtree.parent_position(pos[1]) if subparent is None: prev_sib = tree.prev_sibling_position(pos[0]) if prev_sib is not None: candidate = prev_sib, return candidate # my position could be "hidden" by being child of a # position pointing to a Tree object (which is then unfolded). if self._interpret_covered: # we respect "covered" stuff: # if parent is Tree, return last child of its (last) root parent_pos = self._parent_position(tree, pos) if parent_pos is not None: parent = self._lookup_entry(self._tree, parent_pos) if isinstance(parent, Tree): sib = parent.last_sibling_position(parent.root) candidate = parent.last_child_position(sib) if candidate is not None: candidate = parent_pos + (candidate,) else: # pos points to position in outmost tree prev_sib = tree.prev_sibling_position(pos[0]) if prev_sib is not None: candidate = prev_sib, # In case our new candidate points to a Tree, pick its last root node if candidate is not None: entry = self._lookup_entry(tree, candidate) if isinstance(entry, Tree): candidate = (candidate) + (entry.last_sibling_position(entry.root),) return candidate def prev_sibling_position(self, pos): candidate = self._prev_sibling_position(self._tree, pos) return self._sanitize_position(candidate, self._tree) def last_decendant(self, pos): def lastd(pos): c = self.last_child_position(pos) if c is not None: c = self.last_sibling_position(c) return c return self._last_in_direction(pos, lastd) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/urwidtrees/tree.py0000644000076500000240000002107115075706742016125 0ustar00basstaff# Copyright (C) 2013 Patrick Totzke # This file is released under the GNU GPL, version 3 or a later revision. class Tree(object): """ Base class for a tree strucures that can be displayed by :class:`TreeBox` widgets. An instance defines a structure by defining local transformations on positions. That is, by overwriting * `next_sibling_position` * `prev_sibling_position` * `parent_position` * `first_child_position` * `last_child_position` that compute the next position in the respective direction. Also, they need to implement method `__getitem__` that returns a :class:`Widget` for a given position. The type of objects used as positions may vary in subclasses and is deliberately unspecified for the base class. This base class already implements methods based on the local transformations above. These include :meth:`depth`, :meth:`last_decendant` and :meth:`[next|prev]_position ` that computes next/previous positions in depth-first order. """ root = None # local helper def _get(self, pos): """loads widget at given position; handling invalid arguments""" res = None, None if pos is not None: try: res = self[pos], pos except (IndexError, KeyError): pass return res def _next_of_kin(self, pos): """ looks up the next sibling of the closest ancestor with not-None next siblings. """ candidate = None parent = self.parent_position(pos) if parent is not None: candidate = self.next_sibling_position(parent) if candidate is None: candidate = self._next_of_kin(parent) return candidate @staticmethod def _last_in_direction(starting_pos, direction): """ move in the tree in given direction and return the last position. :param starting_pos: position to start at :param direction: callable that transforms a position into a position. """ cur_pos = None next_pos = starting_pos while next_pos is not None: cur_pos = next_pos next_pos = direction(cur_pos) return cur_pos def depth(self, pos): """determine depth of node at pos""" parent = self.parent_position(pos) if parent is None: return 0 else: return self.depth(parent) + 1 def is_leaf(self, pos): """checks if given position has no children""" return self.first_child_position(pos) is None def first_ancestor(self, pos): """ position of pos's ancestor with depth 0. Usually, this should return the root node, but a :class:`Tree` might represent a forrest - have multiple nodes without parent. """ return self._last_in_direction(pos, self.parent_position) def last_decendant(self, pos): """position of last (in DFO) descendant of pos""" return self._last_in_direction(pos, self.last_child_position) def last_sibling_position(self, pos): """position of last sibling of pos""" return self._last_in_direction(pos, self.next_sibling_position) def first_sibling_position(self, pos): """position of first sibling of pos""" return self._last_in_direction(pos, self.prev_sibling_position) def next_position(self, pos): """returns the next position in depth-first order""" candidate = None if pos is not None: candidate = self.first_child_position(pos) if candidate is None: candidate = self.next_sibling_position(pos) if candidate is None: candidate = self._next_of_kin(pos) return candidate def prev_position(self, pos): """returns the previous position in depth-first order""" candidate = None if pos is not None: prevsib = self.prev_sibling_position(pos) # is None if first if prevsib is not None: candidate = self.last_decendant(prevsib) else: parent = self.parent_position(pos) if parent is not None: candidate = parent return candidate def positions(self, reverse=False): """returns a generator that walks the positions of this tree in DFO""" def Posgen(reverse): if reverse: lastrootsib = self.last_sibling_position(self.root) current = self.last_decendant(lastrootsib) while current is not None: yield current current = self.prev_position(current) else: current = self.root while current is not None: yield current current = self.next_position(current) return Posgen(reverse) #################################################################### # End of high-level helper implementation. The following need to be # overwritten by subclasses #################################################################### def parent_position(pos): """returns the position of the parent node of the node at `pos` or `None` if none exists.""" return None def first_child_position(self, pos): """returns the position of the first child of the node at `pos`, or `None` if none exists.""" return None def last_child_position(self, pos): """returns the position of the last child of the node at `pos`, or `None` if none exists.""" return None def next_sibling_position(self, pos): """returns the position of the next sibling of the node at `pos`, or `None` if none exists.""" return None def prev_sibling_position(self, pos): """returns the position of the previous sibling of the node at `pos`, or `None` if none exists.""" return None class SimpleTree(Tree): """ Walks on a given fixed acyclic structure given as a list of nodes; every node is a tuple `(content, children)`, where `content` is a `urwid.Widget` to be displayed at that position and `children` is either `None` or a list of nodes. Positions are lists of integers determining a path from the root node with position `(0,)`. """ def __init__(self, treelist): self._treelist = treelist self.root = (0,) if treelist else None Tree.__init__(self) # a few local helper methods def _get_substructure(self, treelist, pos): """recursive helper to look up node-tuple for `pos` in `treelist`""" subtree = None if len(pos) > 1: subtree = self._get_substructure(treelist[pos[0]][1], pos[1:]) else: try: subtree = treelist[pos[0]] except (IndexError, TypeError): pass return subtree def _get_node(self, treelist, pos): """ look up widget at `pos` of `treelist`; default to None if nonexistent. """ node = None if pos is not None: subtree = self._get_substructure(treelist, pos) if subtree is not None: node = subtree[0] return node def _confirm_pos(self, pos): """look up widget for pos and default to None""" candidate = None if self._get_node(self._treelist, pos) is not None: candidate = pos return candidate # Tree API def __getitem__(self, pos): return self._get_node(self._treelist, pos) @staticmethod def parent_position(pos): parent = None if pos is not None and len(pos) > 1: parent = pos[:-1] return parent def first_child_position(self, pos): return self._confirm_pos(pos + (0,)) def last_child_position(self, pos): candidate = None subtree = self._get_substructure(self._treelist, pos) if subtree is not None: children = subtree[1] if children is not None: candidate = pos + (len(children) - 1,) return candidate def next_sibling_position(self, pos): return self._confirm_pos(pos[:-1] + (pos[-1] + 1,)) @staticmethod def prev_sibling_position(pos): return pos[:-1] + (pos[-1] - 1,) if (pos[-1] > 0) else None # optimizations @staticmethod def depth(pos): """more performant implementation due to specific structure of pos""" return len(pos) - 1 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054641.0 urwidtrees-1.0.4/urwidtrees/version.py0000644000076500000240000000002615075707661016651 0ustar00basstaff__version__ = '1.0.4' ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054178.0 urwidtrees-1.0.4/urwidtrees/widgets.py0000644000076500000240000002020515075706742016632 0ustar00basstaff# Copyright (C) 2013 Patrick Totzke # This file is released under the GNU GPL, version 3 or a later revision. import urwid from urwid import WidgetWrap, ListBox from urwid import signals from .decoration import DecoratedTree, CollapseMixin from .nested import NestedTree try: # lru_cache is part of the stdlib from v3.2 onwards from functools import lru_cache except ImportError: # on older versions we use a backport from .lru_cache import lru_cache # The following functions are used to check dynamically if a tree offers sub-APIs def implementsDecorateAPI(tree): """determines if given tree offers line decoration""" return isinstance(tree, (DecoratedTree, NestedTree)) def implementsCollapseAPI(tree): """determines if given tree can collapse positions""" return isinstance(tree, (CollapseMixin, NestedTree)) class TreeListWalker(urwid.ListWalker): """ ListWalker to walk through a class:`Tree`. This translates a :class:`Tree` into a :class:`urwid.ListWalker` that is digestible by :class:`urwid.ListBox`. It uses :meth:`Tree.[next|prev]_position ` to determine the next/previous position in depth first order. """ def __init__(self, tree, focus=None): """ :param tree: the tree to be displayed :type tree: Tree :param focus: position of node to be focussed initially. This has to be a valid position in the Tree. It defaults to the value of `Tree.root`. """ self._tree = tree self._focus = focus or tree.root self.root = tree.root @lru_cache() def __getitem__(self, pos): """gets (possibly decorated) line widget at given position""" if implementsDecorateAPI(self._tree): entry = self._tree.get_decorated(pos) else: entry = self._tree[pos] return entry def clear_cache(self): """removes all cached lines""" self.__getitem__.cache_clear() self._modified() def _get(self, pos): """looks up widget for given position; handling invalid arguments""" res = None, None if pos is not None: try: res = self[pos], pos except (IndexError, KeyError): pass return res # List Walker API. def get_focus(self): return self._get(self._focus) def set_focus(self, pos): self._focus = pos self._modified() def get_next(self, pos): return self._get(self._tree.next_position(pos)) def get_prev(self, pos): return self._get(self._tree.prev_position(pos)) def positions(self, reverse=False): """returns a generator that walks the tree's positions""" return self._tree.positions(reverse) # end of List Walker API class TreeBox(WidgetWrap): """ A widget that displays a given :class:`Tree`. This is essentially a :class:`ListBox` with the ability to move the focus based on directions in the Tree and to collapse/expand subtrees if possible. TreeBox interprets `left/right` as well as `page up/`page down` to move the focus to parent/first child and next/previous sibling respectively. All other keys are passed to the underlying ListBox. """ def __init__(self, tree, focus=None): """ :param tree: tree of widgets to be displayed. :type tree: Tree :param focus: initially focussed position """ self._tree = tree self._walker = TreeListWalker(tree) self._outer_list = ListBox(self._walker) if focus is not None: self.set_focus(focus) super().__init__(self._outer_list) # Widget API def get_focus(self): return self._outer_list.get_focus() def set_focus(self, pos, valign=None): position = self._outer_list.set_focus(pos) if valign: position = self._outer_list.set_focus_valign(valign) return position def refresh(self): self._walker.clear_cache() signals.emit_signal(self._walker, "modified") def keypress(self, size, key): key = self._outer_list.keypress(size, key) if key in ['left', 'right', '[', ']', '-', '+', 'C', 'E', ]: if key == 'left': self.focus_parent() elif key == 'right': self.focus_first_child() elif key == '[': self.focus_prev_sibling() elif key == ']': self.focus_next_sibling() elif key == '-': self.collapse_focussed() elif key == '+': self.expand_focussed() elif key == 'C': self.collapse_all() elif key == 'E': self.expand_all() # This is a hack around ListBox misbehaving: # it seems impossible to set the focus without calling keypress as # otherwise the change becomes visible only after the next render() return self._outer_list.keypress(size, None) else: return self._outer_list.keypress(size, key) # Collapse operations def collapse_focussed(self): """ Collapse currently focussed position; works only if the underlying tree allows it. """ if implementsCollapseAPI(self._tree): w, focuspos = self.get_focus() self._tree.collapse(focuspos) self._walker.clear_cache() self.refresh() def expand_focussed(self): """ Expand currently focussed position; works only if the underlying tree allows it. """ if implementsCollapseAPI(self._tree): w, focuspos = self.get_focus() self._tree.expand(focuspos) self._walker.clear_cache() self.refresh() def collapse_all(self): """ Collapse all positions; works only if the underlying tree allows it. """ if implementsCollapseAPI(self._tree): self._tree.collapse_all() self.set_focus(self._tree.root) self._walker.clear_cache() self.refresh() def expand_all(self): """ Expand all positions; works only if the underlying tree allows it. """ if implementsCollapseAPI(self._tree): self._tree.expand_all() self._walker.clear_cache() self.refresh() # Tree based focus movement def focus_parent(self): """move focus to parent node of currently focussed one""" w, focuspos = self.get_focus() parent = self._tree.parent_position(focuspos) if parent is not None: self.set_focus(parent) def focus_first_child(self): """move focus to first child of currently focussed one""" w, focuspos = self.get_focus() child = self._tree.first_child_position(focuspos) if child is not None: self.set_focus(child) def focus_last_child(self): """move focus to last child of currently focussed one""" w, focuspos = self.get_focus() child = self._tree.last_child_position(focuspos) if child is not None: self.set_focus(child) def focus_next_sibling(self): """move focus to next sibling of currently focussed one""" w, focuspos = self.get_focus() sib = self._tree.next_sibling_position(focuspos) if sib is not None: self.set_focus(sib) def focus_prev_sibling(self): """move focus to previous sibling of currently focussed one""" w, focuspos = self.get_focus() sib = self._tree.prev_sibling_position(focuspos) if sib is not None: self.set_focus(sib) def focus_next(self): """move focus to next position (DFO)""" w, focuspos = self.get_focus() next = self._tree.next_position(focuspos) if next is not None: self.set_focus(next) def focus_prev(self): """move focus to previous position (DFO)""" w, focuspos = self.get_focus() prev = self._tree.prev_position(focuspos) if prev is not None: self.set_focus(prev) ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1761054867.952384 urwidtrees-1.0.4/urwidtrees.egg-info/0000755000076500000240000000000015075710224016273 5ustar00basstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054867.0 urwidtrees-1.0.4/urwidtrees.egg-info/PKG-INFO0000644000076500000240000000102415075710223017364 0ustar00basstaffMetadata-Version: 2.4 Name: urwidtrees Version: 1.0.4 Summary: Tree widgets for urwid Home-page: https://github.com/pazz/urwidtrees Author: Patrick Totzke Author-email: patricktotzke@gmail.com License: Licensed under the GNU GPL v3+. License-File: LICENSE.md Requires-Dist: urwid>=1.1.0 Provides-Extra: docs Requires-Dist: mock; python_version < "3.3" and extra == "docs" Dynamic: author Dynamic: author-email Dynamic: home-page Dynamic: license Dynamic: license-file Dynamic: provides-extra Dynamic: requires-dist Dynamic: summary ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054867.0 urwidtrees-1.0.4/urwidtrees.egg-info/SOURCES.txt0000644000076500000240000000054215075710223020157 0ustar00basstaffLICENSE.md README.md setup.py urwidtrees/__init__.py urwidtrees/decoration.py urwidtrees/lru_cache.py urwidtrees/nested.py urwidtrees/tree.py urwidtrees/version.py urwidtrees/widgets.py urwidtrees.egg-info/PKG-INFO urwidtrees.egg-info/SOURCES.txt urwidtrees.egg-info/dependency_links.txt urwidtrees.egg-info/requires.txt urwidtrees.egg-info/top_level.txt././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054867.0 urwidtrees-1.0.4/urwidtrees.egg-info/dependency_links.txt0000644000076500000240000000000115075710223022340 0ustar00basstaff ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054867.0 urwidtrees-1.0.4/urwidtrees.egg-info/requires.txt0000644000076500000240000000007115075710223020670 0ustar00basstaffurwid>=1.1.0 [docs] [docs:python_version < "3.3"] mock ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1761054867.0 urwidtrees-1.0.4/urwidtrees.egg-info/top_level.txt0000644000076500000240000000001315075710223021016 0ustar00basstaffurwidtrees