Skip to main content

简单易用的python Web UI库

Project description

jxWebUI是为python程序员开发的简单易用的WebUI库,通过简单的文本定义即可定义各种web界面发布使用。适合不追求炫酷的界面,而是侧重快速实现功能的python程序员。

版本更新说明

0.3.0版本的修改:

1、增加capa的Init事件,在capa初始化时会调用该事件

2、增加变量-数据对象属性映射,大幅度简单数据对象的输入输出工作

3、增加了capa.data以提供整个capa的全局性数据

详见编程指南中【变量-数据对象属性映射】一节。

4、通过了对接jxORM的测试,在文档部分增加了jxORM的使用说明

说明

jxWebUI的使用非常简单,主要包括几个步骤:

1、导入依赖

from jxWebUI import jxWebLogger, jxWebServer, jxWebCapa, jxWebGetUser, jxWebSQLGetDBConnection

2、创建一个capa

capa = jxWebCapa('test.first_page')

capa就是一个桥【可以理解为一个功能模块】,把web界面和python代码衔接起来。这里定义了一个名为【test.first_page】的capa。对于名字,capa本身并无特殊要求,这里是为了便于代码组织,采用了点分方式。

3、通过capa定义一个界面

@capa.disp  
def test_web(ci, db, ctx):  
	jxWebLogger.info(f'testUI_tms::test_web')  
    ci.setOutput('input1', '测试输出3')

@capa.web  
def test_web(page):  
    t = page.table('table1').width(900)
    r = t.row()
    r.text('text1').bind('text1').width(200)
    r.input('input1').bind('input1').width(200)

这就定义了一个【test_web】的页面:

test_web

4、定义一个打开这个界面的快捷栏菜单

capa.shortCutTree_add_item('测试', '测试1', 'test_web')

这会在左侧的快捷工具栏中出现一个二级目录:测试->测试1

test_web

点击【测试1】就会显示上面的【test_web】页面。

5、启动web服务

jxWebServer.start(port=10068)

启动后,打开: http://127.0.0.1:10068/tms.html# 会弹出一个登录窗口,随便输入用户名和密码就会登入。

注::用户认证,请参考【用户】一节

因为jxWebUI需要做一点初始化的工作,所以可能要等两三秒中,就会在左侧的快捷栏,出现【测试->测试1】。点击测试1就会弹出test_web界面。

注::因python代码第一次执行时需进行编译,启动后第一次打开页面时,编译时间如果超过了这个等待时间,可能导致页面无法打开,多刷新几次即可。

需要注意的是,和上面的截图不同,输入框中会出现:【测试输出3】。这是因为我们还定义了一个用【@capa.disp】修饰的【test_web】事件函数。

jxWebUI在显示一个页面时,会调用这个函数来实现对该页面的初始化工作。

初始化test_web函数的代码:

jxWebLogger.info(f'testUI_tms::test_web') 

会将字符串【testUI_tms::test_web】以info级别记入jxWebLogger。其对应的日志文件位于执行程序所在目录的子目录【./logs】中的【jxWebUI.log】。

ci.setOutput('input1', '测试输出3')

是将一个字符串【测试输出3】输出到web界面的【input1】中,根据test_web函数中的定义,也就是输出到文本输入框中。

总的代码是:

from jxWebUI import jxWebLogger, jxWebServer, jxWebCapa, jxWebGetUser, jxWebSQLGetDBConnection

capa = jxWebCapa('test.first_page')

@capa.disp  
def test_web(ci, db, ctx):  
	jxWebLogger.info(f'testUI_tms::test_web')  
    ci.setOutput('input1', '测试输出3')

@capa.web  
def test_web(page):  
    t = page.table('table1').width(900)
    r = t.row()
    r.text('text1').bind('text1').width(200)
    r.input('input1').bind('input1').width(200)

capa.shortCutTree_add_item('测试', '测试1', 'test_web')

jxWebServer.start(port=10068)

将上述代码保存为testUI_tms.py,然后在命令行执行:

python3 testUI_tms.py

然后在浏览器中打开: http://127.0.0.1:10068/tms.html# 进行查看。

jxWebUI编程指南

请在python解释器中执行:

>>> from jxWebUI import startJxWebUIManualServer
>>> startJxWebUIManualServer(port=10068, web_def=True)

然后在浏览器中打开: http://127.0.0.1:10068/tms.html# 随便输入用户名、密码登录后,就可以查看到编程手册的目录:

编程手册

整体说明菜单下是jxWebUI编程的总体概念和API说明等,web组件说明菜单下则详细介绍了已开放的web组件的说明和属性等。点击这二者的章节会以markdown的形式提供相应的说明:

编程手册

web组件定义菜单下则提供了一个jxWebUI自举的web组件定义和展示功能:

编程手册

编程手册

安装jxWebUI

pip install jxWebUI

日志

启动jxWebUI后,会在当前目录下的logs子目录【没有则会自动创建】中会创建两个日志文件:

  • jxWebUI.log:是jxWebUI的运行日志,包括用户的操作等
  • web.log:jxWebUI的web服务所依赖的tornado的日志

这两种日志都是30个日志文件、每个日志文件500M进行循环,所以如长期运行需注意硬盘空间的使用情况。

Project details


Download files

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

Source Distribution

jxwebui-0.3.6.tar.gz (12.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jxwebui-0.3.6-py3-none-any.whl (13.7 MB view details)

Uploaded Python 3

File details

Details for the file jxwebui-0.3.6.tar.gz.

File metadata

  • Download URL: jxwebui-0.3.6.tar.gz
  • Upload date:
  • Size: 12.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for jxwebui-0.3.6.tar.gz
Algorithm Hash digest
SHA256 1f0298c8f625ecc70fa3735f461f84fc8ddeb8e11d5f14104cdd16f343d99484
MD5 68d100ad16d49adb36a152aa0be8aca8
BLAKE2b-256 b714de2d453e8bb0ec12e8c4c734bbc4b159aafded29c8fdf9da35d53636a7eb

See more details on using hashes here.

File details

Details for the file jxwebui-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: jxwebui-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for jxwebui-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 cb358e79580c20615e4ad3943f78cfa9802eebd1d0890b3abd2fe02ed22591d2
MD5 8e57e05e58a58eba95cff91c278b2191
BLAKE2b-256 26e63354e1ead888d0f8ffb1b47af4863e9338b2dc96025b6bd7ec64b6ba7d5f

See more details on using hashes here.

Supported by

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