首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python plantUML逻辑示意图使用奇数字符渲染

Python plantUML逻辑示意图使用奇数字符渲染
EN

Stack Overflow用户
提问于 2020-02-08 02:42:55
回答 1查看 163关注 0票数 0

我正在使用这段python代码来生成一个plantUML图:

代码语言:javascript
复制
import codecs
import importlib.util
import os
from plantuml import PlantUML
import sadisplay
import tkinter.filedialog as filedialog
import tkinter.messagebox as messagebox

def create_erd():
    # Get the file with the models.
    modelFile = filedialog.askopenfilename(initialdir = os.getcwd, title = 'Select models.py file', filetypes = (('python files', '*.py'), ('all files', '*.*')))

    # Import the file as a module.
    spec = importlib.util.spec_from_file_location('models', modelFile)
    models = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(models)

    # Create a descriptor that lists all the attributes and relationships outlined in the models.py file.
    desc = sadisplay.describe([getattr(models, attr) for attr in dir(models)])

    # Create the plantuml file based on the descriptor.  This is needed to create the png image file
    with codecs.open('schema.plantuml', 'w', encoding='utf-8') as f:
        f.write(sadisplay.plantuml(desc))

    # Call the plantuml library to take the plantuml file and generate the png file.
    plantuml = PlantUML('http://www.plantuml.com/plantuml/img/')
    done = plantuml.processes_file(filename = 'schema.plantuml', outfile = 'schema.png')    

    # Notify the user if the process was successful.
    if done:
        messagebox.showinfo('Create ERD', 'The ERD was successfully written to schema.png.')
    else:
        messagebox.showinfo('Create ERD', 'The ERD was not successfully generated.')

生成的plantuml文件如下所示:

代码语言:javascript
复制
@startuml

skinparam defaultFontName Courier

Class Department {
    INTEGER ★ id     
    VARCHAR ⚪ name   
    +       employees
}

Class Employee {
    INTEGER  ★ id           
    INTEGER  ☆ department_id
    INTEGER  ☆ role_id      
    DATETIME ⚪ hired_on     
    VARCHAR  ⚪ name         
    +        department     
    +        role           
}

Class Role {
    INTEGER ★ role_id
    VARCHAR ⚪ name   
    +       roles    
}

Employee <--o Department: department_id

Employee <--o Role: role_id

right footer generated by sadisplay v0.4.9

@enduml

但是输出看起来像这样:

我不确定为什么图像以这种方式呈现,因此不知道如何修复它,也不知道它是否可以修复。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2020-02-08 03:36:22

我最终读取了uml文件,并替换了以下字符:

代码语言:javascript
复制
processThis = uml.read().replace('★', '[PK]').replace('☆', '[FK]').replace('⚪', '    ')

这样就行了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60119322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档