Skip to main content

FanLang — Streamlit integration. Pre-built symbol bar and interaction components.

Project description

FanLang Streamlit

FanLang 符号系统的 Streamlit 集成插件,提供符号按钮栏、符号选择器和术语提示卡片等预构建组件。

安装

pip install fanlang-streamlit

快速开始

import streamlit as st
from fanlang_streamlit import render_symbol_bar, render_symbol_picker

# 渲染核心符号按钮栏(8 个核心符号)
selected = render_symbol_bar()
if selected:
    st.write(f"你选择了符号:{selected}")

# 渲染展开式符号选择器(按梯队分组)
picked = render_symbol_picker()
if picked:
    st.write(f"选中的符号:{picked}")

组件说明

render_symbol_bar(symbols=None, max_cols=8)

渲染一行符号按钮。

  • 默认展示 8 个核心符号:写、改、翻、总、问、查、比、理
  • 每个按钮包含 emoji + 中文字符
  • 支持自定义符号列表和最大列数
  • 选中状态通过 session_state 管理并高亮显示
  • 返回被点击的符号字符(str)或 None
# 自定义符号列表
custom = [
    {"character": "写", "emoji": "✍️"},
    {"character": "改", "emoji": "✏️"},
]
selected = render_symbol_bar(symbols=custom, max_cols=4)

render_symbol_picker(symbols=None)

展开式符号选择器,按梯队分组展示。

  • 一梯队(7 个):核心高频符号
  • 二梯队(5 个):扩展符号
  • 三梯队(8 个):领域符号
  • 四梯队(5 个):辅助符号
  • 使用 st.expander 折叠,节省页面空间
  • 返回选中的符号字符(str)或 None

render_terminology_tooltip(term)

渲染术语提示卡片。

render_terminology_tooltip({
    "term_en": "Translate",
    "term_zh": "翻 - 翻译",
})

回调函数

from fanlang_streamlit import on_symbol_click, get_selected_symbol, clear_selected_symbol

# 手动写入选中状态
on_symbol_click("写")

# 读取当前选中符号
sym = get_selected_symbol()  # "写"

# 清除选中状态
clear_selected_symbol()

依赖

  • Python >= 3.10
  • streamlit >= 1.28
  • fanlang >= 0.1.0

许可

MIT

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

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

pyfanlang_streamlit-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file pyfanlang_streamlit-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyfanlang_streamlit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2aa59c35a03882036bec1a2d3e4845f304ef06599663e61e7d1a6300335aea6c
MD5 bb0e169df998845a3f964f7545cd8310
BLAKE2b-256 53e64e02dcca255e5998b81f5ed2bf49abb0c2b6e01631444d1029546c11c26c

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