推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
imn1
V2EX  ›  Python

伸手,有什么富文本编辑模块?

  •  
  •   imn1 · May 1, 2020 · 3643 views
    This topic created in 2343 days ago, the information mentioned may be changed or developed.
    1.纯自用
    2.py3+pyqt5,要 import 到现有的一个 GUI 程序,懒得研究其他 —— 只要不是阻断运行的 bug 我都懒得理的,关掉重开就是了
    3.有最基础的功能即可,字体、字号、颜色、左右对齐、插入图片(可视)、代码框、预览( webview 方式)……
    如果编辑的同时也可视,也不一定要预览
    4.markdown 之类不要求,编辑完成目标是入库,最好输出 html 格式,方便图片转 base64

    搜了一轮 github/pypi 和 google,大项目倒是找到几个,单窗模块方便调用的没找到,不知道怎么找
    Supplement 1  ·  May 1, 2020
    自问自答吧

    锲而不舍,搜到 https://python-forum.io/Thread-RichTextEditor
    然后作者代码放在

    两个 class,非常适合 import,比我期望的需求还多了导出 PDF 等

    原作有个小问题(非 bug ),插入图片只显示个占位小图标,而且产出是 src=file:// 方式
    稍微改动变为 base64

    搜
    self.editor.textCursor().insertImage("file://" + path)
    改为
    self.editor.textCursor().insertHtml(img2base64(path, html=True))

    ps: img2base64 是自写的一个图片转 base64 的小函数,简单几行而已,这里就懒得放了

    这样的话,插入图片无需预览也能直接显示
    后面就剩下把 open/save 改为数据流,方便数据库进出,都不算什么事,不提

    今天 todo 完成,明天要找 editable treewidget……
    5 replies  •  2020-05-02 17:21:57 +08:00
    imn1
        1
    imn1  
    OP
       May 1, 2020
    结贴
    imn1
        3
    imn1  
    OP
       May 1, 2020
    @jin7
    这个搜过了,它是 CPP 的,改 pyqt5 大工程,以我的能力两三个月吧,👅
    zengxs
        4
    zengxs  
       May 1, 2020   ❤️ 1
    直接 webview 嵌入一个 HTML 的富文本编辑器不就行了
    imn1
        5
    imn1  
    OP
       May 2, 2020
    @jin7
    先道个歉,qt 的例子,在 github/pyqt 上面有 example,不用自己改 —— 其实有印象,不过忘了这回事
    然后是我慢慢摸索……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3797 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:48 · PVG 17:48 · LAX 02:48 · JFK 05:48
    ♥ Do have faith in what you're doing.