tinengine 2.5.0
tkinter-Tin标记文本|富文本渲染框
License: MIT License
Requires Python: ==3.9

# TinEngine

A advanced tkinter widget for Tin-lang.

内置一个基于tkinter的富文本渲染组件——TinText，可以将Tin标记文本渲染为富文本。

## install

```sh
python -m pip install tinengine
```

or

```shel
pip install tinengine
```

## require

Tin需要以下第三方库。| Tin needs these packages.

- PIL(pillow) - load images while rendering.
- requests - get content from web.
- pythonnet - use clr.
- pywebview - for WebView2.
- tkinterweb - for hype text in TinText.

---

## What is Tin

Tin标记语言是一个语言规范，也是一个文本格式，以标记为主。

具体见：[Tin知识库](https://tinhome.baklib-free.com/c788/6099)。

Tin is a markup language, and Tin is also a format of text file.

For more information, see ["about Tin"](https://tinhome.baklib-free.com/c788/6099).

---

## Why is Tin

Tin可应用在以下几个方面：

1. 将Tin标记文本渲染为易读的富文本进行阅读，这是Tin的最初目的
2. 基于tkinter，实现类似于HTMLlayout的Tinlayout，这是Tin正在努力的
3. 将格式、数据、信息进行样式化呈现，这是每个富文本的通用功能

这是Tin相较于其他tkinter拓展最独特的。

Tin can be used in these situation:

1. Render Tin marked text into easy-to-read rich text for reading, it's the original purpose of Tin.
2. Based on tkinter, Tinlayout similar to HTMLlayout can be realized, which Tin is trying to improve.
3. Style presentation of format, data and information is the general function of  every rich text language.

This is the most unique ability of Tin compared with other tkinter's extended widgets and libs.

---

## Use Tin based Python

### TinText

==TinText==是TinEngine的核心组件，是负责将Tin标记文本渲染为易读的富文本。

TinText is the main widget of TinEngine, which is responsible for rendering Tin markup text into easy-to-read rich text.

TinText的主要函数是`point_file`，这将实现渲染功能。函数定义以及参数如下：

The main function of TinText is `point_file`, which will realize the rendering function. The function definition and parameters are as follows:

```python
def point_file(self,unit:str,cls:int=0,insert:str='end',*arg)->(str,int):
    #-2.3.0-版本，unit使用list；-2.3.1-及以上版本，unit使用str
    '''
    unit::Tin标记文本段 | Text segment marked by Tin
    cls::是否清空，若为值1，本轮操作清空文本框 | Clear, if it is 1, the text box will be cleared in this operation
    insert::渲染的起始位置 | Start position of rendering
    '''
```

关于TinText的初始化参数，详见：[参考文章](https://blog.csdn.net/tinga_kilin/article/details/116086272)。

See the initialization parameters of TinText for details, see ["about TinText Class"](https://blog.csdn.net/tinga_kilin/article/details/116086272).

### Demo

实际上，拓展包里的`__init__.py`文件就是一个例子。下面是更加简单的使用方法。

```python
from tkinter import *
from tinengine.TinEngine import TinText

tin='''
<title>Tin的测试
<main>这是关于Tin标记文本应用于TinText的一个demo。
<main>Tin是世界上第一个可用tkinter系统地渲染的标记语言。
'''

a=Tk()
a.geometry('750x500')
t=TinText(a,font=('微软雅黑',12))
t.pack(fill='both',expand=True)

#-2.3.0-版本：
t.point_file(tin.split('\n'))
#-2.3.1-及以上版本：
t.point_file(tin)

a.mainloop()
```

Actually, the ` __init__.py ` file in the extension package is an example. The following is a simpler way to use it.

```python
from tkinter import *
from tinengine.TinEngine import TinText

tin='''
<title>Test of TinText
<main>This is a demo about the useage of Tin marked text on TinText.
<main>Tin is the first markup language that can be rendered systematically by tkinter.
'''

a=Tk()
a.geometry('750x500')
t=TinText(a,font=('微软雅黑',12))
t.pack(fill='both',expand=True)

#-2.3.0- version use this：
#t.point_file(tin.split('\n'))
#-2.3.1- version and above use this：
t.point_file(tin)

a.mainloop()
```

---

## Use Tin based Tin

使用TinEngine，就要知道Tin标记语言。以下是获取Tin标记语言规范的方式：

- 在[Tin知识库](http://tinhome.baklib-free.com/)下载软件TinReader，附带Tin标记说明
- 从[coding库](https://smartspace5.coding.net/p/Tin/d/Tin/git/raw/master/Tin%E4%BD%BF%E7%94%A8%E6%96%87%E4%BB%B6.rar)下载使用说明的压缩包

To use TinEngine, you need to know Tin markup language. The following is how to get the Tin markup language specification:

- Download the software TinReader in [Tin knowledge base](http://Tinhome.baklib-free.com/) with Tin tag instructions
- Download the compressed package of instructions from the [Coding library](https://smartspace5.coding.net/p/Tin/d/Tin/git/raw/master/Tin%E4%BD%BF%E7%94%A8%E6%96%87%E4%BB%B6.rar)

---

## Call me

如果你有什么想法或者是问题，可以告诉我。

If you have some problems or great ideas, you can tell me. (If I have enough time, I am a student, actually.)

使用邮件：smart-space@qq.com

Use e-mail to report me: smart-space@qq.com

---

## What's new

-2.5.0-

- fix loading `<hptext>` and `<html>` in a child thread.
- using the newest tkinterweb version.
- add `<quo>` to add a quote text.
- add `<sst>` to show subscript and superscript text.
- add `<rtf>` to render *.rtf file (in `\data\depend\`) in TinText.

-2.4.0-

- Now you can use `<table>` with TinUI's table if you want.

- Use `@LBK@` in `<table>` if you want to start a newline of a item with using TinUI's table control.

- Use WebView2 to render html. But it can't be rendered in a child thread, and reader can render it by using a tip button later.

- `<stop>` won't delay so much in Main Thread.

-2.3.9-

- `<tinframe>` allows you to add a TinText widget in your *.tin file rendering.

- You can use `<depend>` to download necessary files while rendering.

-2.3.7-

- `<mode>`can get more args as a sentence with line breaks.

- `<download>` can download files using multithreading.

- Add `<topic>` to show the main idea of what TinText is rendering.

-2.3.6-

- `<do>` is added into TinText to run scripts with out calling.

- We continue to make tables in TinText more beautiful and add args to `<code>`. And TinUI support is  available.

-2.3.5-

- We add `<download>`, which can allow reader to download a file or not.

- As well, It is better to render the tables written in TinText.

-2.3.2-

- It uses the ieframe fo show the `<html>`.

- A frame will be added in TinText while asking a key do render more.

-2.3.1-

- An epoch-making version. It has a more powerful engine. Speed, Performance, and stability all have been promoted.

-2.3.0-

- Upload to PYPI. But the first verstion of `TinEngine.pyd` is called `TinEngine-2.1.3`.

- You can find more information about the versions of TinEngine in [Tin-version](https://tinhome.baklib-free.com/c608/04d4). TinReader's versions and news on rendering are the same as TinEngine's.