Skip to content

Commit

Permalink
Merge pull request #31 from gojuukaze/3.0.0
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
gojuukaze authored Jan 13, 2023
2 parents ba5d978 + a4374fb commit a28d003
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 344 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ pip install terminal-layout
```

# Dependencies
* Python 2.7, 3.5+ (maybe 3.4)
* Python 3.5+ (maybe 3.4)
* Linux, OS X, and Windows systems.

## Python Support

| Python | terminal_layout |
| ------ | --------------- |
| 2.7 | 2.1.x |
| 3.5+ | 3.x |

# Usage

* easy demo:
Expand Down
13 changes: 12 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,20 @@ install
Dependencies
============

- Python 2.7, 3.5+ (maybe 3.4)
- Python 3.5+ (maybe 3.4)
- Linux, OS X, and Windows systems.


Python Support
--------------

====== ===============
Python terminal_layout
====== ===============
2.7 2.1.x
3.5+ 3.x
====== ===============

Usage
=====

Expand Down
64 changes: 53 additions & 11 deletions docs/draw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- **LayoutCtl** :layout管理器,负责绘制所有元素
- **View** : 基础控件,Layout 与 TextView 其实都属于 View

- Layout : 布局控制器,控制 TextView 显示的位置。 目前支持的Layout有两种 TableLayout(表格布局), TableRow(行布局)
- Layout : 布局控制器,控制 TextView 显示的位置。 目前支持的Layout有两种 TableLayout(表格布局), TableRow(行布局)

- TextView : 用于显示文字的view。

Expand Down Expand Up @@ -43,7 +43,8 @@

每次手动创建layout,text_view会很麻烦,这里为 TableRow,TableLayout,LayoutCtl 提供了quick_init()函数帮助快速创建

- TableRow
TableRow
~~~~~~~~~~~~~~~~

.. code-block:: python
Expand All @@ -59,14 +60,13 @@
.. note::
LayoutCtl()接受的参数是View,因此直接把TableRow放到ctl中。

你也可以把TextView直接放入LayoutCtl(),如:

.. code-block:: python
你也可以把TextView直接放入LayoutCtl(),如::

ctl = LayoutCtl(TextView('title', 'Title', width=10, back=Back.blue))


- TableLayout
TableLayout
~~~~~~~~~~~~~~~~~

.. code-block:: python
Expand All @@ -85,8 +85,23 @@
ctl.draw()
ctl.stop()
- LayoutCtl
v3.0.0+ data支持 ``[[TextView]]`` 这样的形式,且可以通过 ``row_id_formatter`` 修改row的默认id。( ``row_id_formatter`` 说明见下方 **LayoutCtl.quick** 部分)

.. code-block:: python
from terminal_layout import *
table = TableLayout.quick_init('root',
[ # table id: root
[TextView('', '1')], # row id: root_row_0
[TextView('', '2')] # row id: root_row_1
] ,
row_id_formatter='{table_id}_row_{index}'
)
LayoutCtl
~~~~~~~~~~~~~~~~
.. code-block:: python
from terminal_layout import *
Expand All @@ -95,14 +110,21 @@
[
[TextView('title', 'Title', width=Width.wrap)], # row id: root_row_0
[TextView('data1', '1.', width=3), TextView('data2', 'foo', width=5)], # row id: root_row_1
]
],
id="root",
row_id_formatter='{table_id}_row_{index}'
)
ctl.draw()
ctl.stop()
.. note::

对于LayoutCtl.quick(),会自动为layout添加id
v3.0.0开始,可以通过 ``id`` 配置最外层的layout id。

创建 ``TableLayout`` 时可通过 ``row_id_formatter`` 配置 row id。其支持的展位符如下:

- table_id :即 id 设置的值
- index

修改view的属性
----------------
Expand Down Expand Up @@ -162,17 +184,37 @@
table = TableLayout('id1')
table.add_view(TextView('', 'text'))
这样做相当于
这样某些情况下做相当于

.. code-block:: python
table = TableLayout('id1')
row = TableRow.quick_init('', [TextView('', 'text') ] )
table.add_view(row)
在某些情况下他们是一样的,而且第一种方式更便捷。但第一种方式将不能正确处理某些 ``TextView`` 自有的属性(非基础 ``View`` 的属性)。
但第一种方式将不能正确处理某些 ``TextView`` 的自有属性(非基础 ``View`` 的属性)。
除非你知道你在做什么,否则建议使用第二种方式。

移除view
---------------------

- 你可以使用remove或remove_view_by_id移除view


.. code-block:: python
from terminal_layout import *
ctl = LayoutCtl.quick(TableLayout,
# table id: root
[
[TextView('title', 'Title', width=Width.wrap)], # row id: root_row_0
[TextView('data1', '1.', width=3), TextView('data2', 'foo', width=5)], # row id: root_row_1
]
)
# remove title
ctl.remove_view_by_id('title')
自动刷新
-------------

Expand Down
4 changes: 3 additions & 1 deletion docs/getStarted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
ctl.draw()
ctl.stop()
``LayoutCtl`` , ``TableLayout`` , ``TextView`` 是该项目重要的元素,阅读 :doc:`/draw` , :doc:`/keyListener` 熟悉如何使用它们
``LayoutCtl`` , ``TableLayout`` , ``TextView`` 是该项目重要的元素,接下来阅读 :doc:`/draw` 熟悉如何使用它们。

如需监听键盘事件,则阅读: :doc:`/keyListener`
6 changes: 6 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ Welcome to terminal_layout's documentation!
.. image:: _static/demo_v2_1.gif

|
.. image:: _static/demo.gif

|
.. image:: https://asciinema.org/a/226120.svg
:target: https://asciinema.org/a/226120

|
你可以从 :doc:`getStarted` 开始学习如何使用terminal_layout


Expand Down
10 changes: 10 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ installation
pip install terminal-layout
Python Support
----------------------

====== ===============
Python terminal_layout
====== ===============
2.7 2.1.x
3.5+ 3.x
====== ===============
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sphinx==3.4.3
sphinx-rtd-theme==0.5.1
Pillow==9.0.1
Pillow==9.3.0
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ build-backend = "setuptools.build_meta"

[project]
name = "terminal_layout"
version = "2.1.6"
version = "3.0.0"
authors = [
{ name="gojuukaze", email="[email protected]" },
]
description = "The project help you to quickly build layouts in terminal (命令行ui布局工具)"
readme = "README.rst"
requires-python = ">=2.7"
requires-python = ">=3.5"
classifiers = [
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"Environment :: Console",
Expand All @@ -22,9 +21,8 @@ classifiers = [
]

dependencies = [
"colorama==0.4.4",
'colored==1.3.93',
"backports.shutil_get_terminal_size==1.0.0"
"colorama==0.4.6",
'colored==1.4.4',
]

[project.urls]
Expand All @@ -34,4 +32,4 @@ dependencies = [

[tool.setuptools.packages.find]
include = ["terminal_layout*"]
exclude = ["demo", "tests"]
exclude = ["demo*", "tests*"]
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
colorama==0.4.4
colored==1.3.93
backports.shutil_get_terminal_size==1.0.0
colorama==0.4.6
colored==1.4.4
48 changes: 3 additions & 45 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,7 @@

__author__ = 'gojuukaze'

from setuptools import setup, find_packages
from setuptools import setup

setup(
name="terminal_layout",
version="2.1.6",
description="The project help you to quickly build layouts in terminal (命令行ui布局工具)",
long_description=open("README.rst", encoding='utf-8').read(),

url="https://github.com/gojuukaze/terminal_layout",
author="gojuukaze",
author_email="[email protected]",

packages=find_packages(exclude=['demo*', 'tests*']),
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
include_package_data=True,
platforms="OSX, Linux",
install_requires=['colorama==0.4.4',
'colored==1.3.93',
'backports.shutil_get_terminal_size'],
tests_require=['colorama==0.4.4',
'colored==1.3.93'],

classifiers=[
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Development Status :: 5 - Production/Stable',
'Topic :: Terminals',
],

project_urls={
'Documentation': 'https://doc.ikaze.cn/terminal_layout',
'Source': 'https://github.com/gojuukaze/terminal_layout',
},
)
# pyproject.toml
setup()
Loading

0 comments on commit a28d003

Please sign in to comment.