Skip to main content

tkinter-Tin标记文本|富文本渲染框

Project description

TinEngine

A advanced tkinter widget for Tin-lang.

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

install

python -m pip install tinengine

or

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知识库

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

For more information, see "about Tin".


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:

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的初始化参数,详见:参考文章

See the initialization parameters of TinText for details, see "about TinText Class".

Demo

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

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.

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知识库下载软件TinReader,附带Tin标记说明
  • coding库下载使用说明的压缩包

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


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. TinReader's versions and news on rendering are the same as TinEngine's.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

tinengine-2.5.0-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file tinengine-2.5.0-py3-none-any.whl.

File metadata

  • Download URL: tinengine-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for tinengine-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31b934be16fb094acbbbc87ddad3c62679b663cdd0fe7d3268d81119580bc889
MD5 97c846728e364b082919b43a4c8ea24a
BLAKE2b-256 0e746dc6868d2fddba2f48b0be7047bd0363dc28c1ddf6d618c571a9fab048e8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page