python xmind 包使用详解(其中解决导出的xmind文件 xmind8可以打开 xmind2020及之后版本打开报错问题)
作者:weixin_40105587 发布时间:2022-10-01 17:23:57
标签:python,xmind,包
pip install xmind 使用
場景xmind8 可以打开xmind2020 报错
main_fest.xml(xmind8 打开另存后 更改后缀为.zip 里边包含META-INF/manifest.xml)
** 将xmind文件修改后缀为zip ---->解压---->放入main_fest.xml —>压缩为zip —>修改后缀为xmind**
import xmind
import os
import re
import shutil
import zipfile
from xmind.core.const import TOPIC_DETACHED
from xmind.core.markerref import MarkerId
from xmind.core.topic import TopicElement
def extract(d_path, f_path, mode="zip"):
"""
zip解压缩乱码问题处理
:param d_path:
:param f_path:
:return:
"""
root = d_path
if not os.path.exists(root):
os.makedirs(root)
if mode == 'zip':
zf = zipfile.ZipFile(f_path,"r")
elif mode == 'rar':
zf = rarfile.RarFile(f_path,"r")
for n in zf.infolist():
srcName = n.filename
try:
decodeName = srcName.encode("cp437").decode("utf-8")
except:
try:
decodeName = srcName.encode("cp437").decode("gbk")
except:
decodeName = srcName
spiltArr = decodeName.split("/")
path = root
for temp in spiltArr:
path = os.path.join(path, temp)
if decodeName.endswith("/"):
if not os.path.exists(path):
os.makedirs(path)
else:
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
f = open(path, "wb")
f.write(zf.read(srcName))
f.close()
zf.close()
def aftertreatment(path):
"""
**場景xmind8 可以打开xmind2020 报错
main_fest.xml(xmind8 打开另存后 更改后缀为.zip 里边包含META-INF/manifest.xml)
xmind 修改后缀为zip ----》解压---- 》放入main_fest.xml --- 》压缩zip 修改后缀为xmind**
"""
# 修改名字
retval = os.path.dirname(os.path.abspath(__file__))
folder = os.path.dirname(path)
name = os.path.basename(path)
unzip_folder = os.path.splitext(name)[0]
zip_name = unzip_folder + ".zip"
os.chdir(folder)
os.rename(name, zip_name)
os.chdir(retval)
# 解压
unzip_path = os.path.join(folder, unzip_folder)
if not os.path.exists(unzip_path):
os.mkdir(unzip_path)
inf_folder = os.path.join(unzip_path, "META-INF")
if not os.path.exists(inf_folder):
os.mkdir(inf_folder)
extract(unzip_path, os.path.join(folder, zip_name))
shutil.copyfile("./META-INF/manifest.xml", os.path.join(inf_folder, "manifest.xml"))
os.remove(os.path.join(folder, zip_name))
shutil.make_archive(unzip_path, 'zip', unzip_path)
file_path = unzip_path + '.zip'
print(file_path)
os.chdir(os.path.dirname(file_path))
os.rename(os.path.basename(file_path), name)
os.chdir(retval)
shutil.rmtree(unzip_path)
def gen_xmind_file(data, path):
# load an existing file or create a new workbook if nothing is found
workbook = xmind.load(path)
# get the first sheet(a new workbook has a blank sheet by default)
sheet1 = workbook.getPrimarySheet()
# design_sheet1(sheet1)
# create sheet2
gen_sheet2(workbook, sheet1, data)
# now we save as test.xmind
xmind.save(workbook, path=path)
# 修复
aftertreatment(path)
def recursive(children, node, workbook):
if len(children) == 0:
return
for c in children:
t = TopicElement(ownerWorkbook=workbook)
t.setTitle(c["data"]["text"])
if len(c["children"]):
recursive(c["children"], t, workbook)
node.addSubTopic(t)
def gen_sheet2(workbook, sheet2, data):
# ***** second sheet *****
# create a new sheet and add to the workbook by default
# sheet2 = workbook.createSheet()
center = data["root"]["data"]["text"]
sheet2.setTitle(center)
# a sheet has a blank sheet by default
root_topic2 = sheet2.getRootTopic()
root_topic2.setTitle(center)
topics = data["root"]["children"]
for t in topics:
# use other methods to create some sub topic element
topic = TopicElement(ownerWorkbook=workbook)
# set a topic hyperlink from this topic to the first sheet given by s1.getID()
# topic1.setTopicHyperlink(sheet1.getID())
# print(t["data"]["text"], t["data"]["layout_mind_offset"]["x"], t["data"]["layout_mind_offset"]["y"])
topic.setTitle(t["data"]["text"]) # set its title
# topic.setPosition(t["data"]["layout_mind_offset"]["x"], t["data"]["layout_mind_offset"]["y"])
recursive(t["children"], topic, workbook)
root_topic2.addSubTopic(topic)
if __name__ == '__main__':
data = {
"root": {
"data": {
"id": "c1jsg864saw0",
"created": 1585126506413,
"text": "新手指南",
"color": "#000000",
"font-weight": "bold",
"font-size": 32
},
"children": [
{
"data": {
"id": "c1jsisau8rc0",
"created": 1585126706961,
"text": "节点操作",
"expandState": "expand",
"layout_mind_offset": {
"x": 36,
"y": 93
},
"background": "#ffc000",
"font-size": 22,
"color": "#000000",
"font-weight": "bold",
"layout_right_offset": {
"x": -48,
"y": -39
},
"icon": "youxian_01"
},
"children": [
{
"data": {
"id": "c1jslg11qzk0",
"created": 1585126915340,
"text": "插入节点",
"font-size": 18,
"color": "#ffc000",
"layout_right_offset": {
"x": 96,
"y": -95
},
"background": "#404040",
"font-weight": "bold",
"icon": "qizhi_01"
},
"children": [
{
"data": {
"id": "c1jsn3rlhbc0",
"created": 1585127045376,
"text": "下级:快捷键【Tab】 ",
"font-size": 18,
"color": "#ffc000",
"layout_right_offset": {
"x": 27,
"y": -12
},
"background": "transparent"
},
"children": [
]
},
{
"data": {
"id": "c1jso0dk2cg0",
"created": 1585127116361,
"text": "同级:快捷键【Enter】 ",
"font-size": 18,
"color": "#ffc000",
"layout_right_offset": {
"x": 27,
"y": 0
},
"background": "transparent"
},
"children": [
]
},
{
"data": {
"id": "c1jsp3q5g4g0",
"created": 1585127202017,
"text": "上级:快捷键【Shift + Tab】",
"font-size": 18,
"color": "#ffc000",
"layout_right_offset": {
"x": 30,
"y": 13
},
"background": "transparent"
},
"children": [
]
}
]
},
{
"data": {
"id": "c1jslivsluw0",
"created": 1585126921553,
"text": "移动节点",
"font-size": 18,
"color": "#fabf8f",
"expandState": "expand",
"layout_right_offset": {
"x": 97,
"y": -36
},
"background": "#404040",
"font-weight": "bold"
},
"children": [
{
"data": {
"id": "c1jsqis0d540",
"created": 1585127313145,
"text": "上移:快捷键【Alt + ↑ 】",
"background": "transparent",
"font-size": 18,
"color": "#fbd4b4",
"layout_right_offset": {
"x": 32,
"y": -12
}
},
"children": [
]
},
{
"data": {
"id": "c1jsqjz54o80",
"created": 1585127315753,
"text": "下移:快捷键【Alt + ↓ 】",
"font-size": 18,
"color": "#fbd4b4",
"layout_right_offset": {
"x": 31,
"y": 0
},
"background": "transparent"
},
"children": [
]
},
{
"data": {
"id": "c1jsqkfoncw0",
"created": 1585127316753,
"text": "收起/展开:快捷键【 / 】",
"font-size": 18,
"color": "#fbd4b4",
"layout_right_offset": {
"x": 34,
"y": 13
},
"background": "transparent"
},
"children": [
]
}
]
},
{
"data": {
"id": "c1jt8kpu4x40",
"created": 1585128727922,
"text": "文字换行 ",
"expandState": "expand",
"font-size": 18,
"layout_right_offset": {
"x": 103,
"y": 25
},
"color": "#ffc000",
"background": "#404040",
"font-weight": "bold",
"icon": "star_02"
},
"children": [
{
"data": {
"id": "c1jt94rf40w0",
"created": 1585128771553,
"text": "快捷键【Shift + Enter 】",
"font-size": 18,
"layout_right_offset": {
"x": 13,
"y": -1
},
"color": "#ffc000"
},
"children": [
]
}
]
}
]
},
{
"data": {
"id": "c1jswayqnqo0",
"created": 1585127766323,
"text": "画布操作",
"layout_mind_offset": {
"x": -737,
"y": -222
},
"font-size": 22,
"background": "#e5dfec",
"color": "#000000",
"font-weight": "bold",
"layout_right_offset": {
"x": 29,
"y": 83
}
},
"children": [
{
"data": {
"id": "c1jswgwssps0",
"created": 1585127779266,
"text": "放大画布:Ctrl +“+”",
"font-size": 18,
"color": "#ccc0d9",
"layout_right_offset": {
"x": 68,
"y": -38
},
"layout_left_offset": {
"x": -36,
"y": -47
}
},
"children": [
]
},
{
"data": {
"id": "c1jswhh0nmo0",
"created": 1585127780488,
"text": "缩小画布:Ctrl +“-”",
"font-size": 18,
"color": "#ccc0d9",
"layout_right_offset": {
"x": 68,
"y": -22
},
"layout_left_offset": {
"x": -39,
"y": -28
}
},
"children": [
]
},
{
"data": {
"id": "c1jswivop5k0",
"created": 1585127783552,
"text": "拖动画布:按住鼠标右键",
"font-size": 18,
"color": "#ccc0d9",
"layout_right_offset": {
"x": 69,
"y": 2
},
"layout_left_offset": {
"x": -39,
"y": -3
}
},
"children": [
]
},
{
"data": {
"id": "c1jswjvpi9k0",
"created": 1585127785730,
"text": "定位节点中心:双击鼠标左键",
"font-size": 18,
"color": "#ccc0d9",
"layout_right_offset": {
"x": 71,
"y": 14
},
"layout_left_offset": {
"x": -41,
"y": 10
}
},
"children": [
]
}
]
},
{
"data": {
"id": "c1jsleo62hk0",
"created": 1585126912385,
"text": "导出格式",
"layout_mind_offset": {
"x": -46,
"y": 108
},
"expandState": "expand",
"font-size": 22,
"background": "#c2d69b",
"color": "#262626",
"font-weight": "bold",
"layout_right_offset": {
"x": 5,
"y": 153
}
},
"children": [
{
"data": {
"id": "c1knktgogog0",
"created": 1585214320627,
"text": "图片",
"font-size": 18,
"color": "#000000",
"expandState": "expand",
"layout_right_offset": {
"x": 58,
"y": -20
},
"background": "#c2d69b",
"layout_left_offset": {
"x": -48,
"y": -28
}
},
"children": [
{
"data": {
"id": "c1jsqis0d540",
"created": 1585127313145,
"text": "JPG、PNG、SVG",
"background": "transparent",
"font-size": 18,
"color": "#c2d69b",
"layout_right_offset": {
"x": 1,
"y": 1
}
},
"children": [
]
}
]
},
{
"data": {
"id": "c1knl8lj2m00",
"created": 1585214353572,
"text": "文件",
"font-size": 18,
"color": "#000000",
"expandState": "expand",
"layout_right_offset": {
"x": 61,
"y": 0
},
"background": "#c2d69b",
"layout_left_offset": {
"x": -47,
"y": 2
}
},
"children": [
{
"data": {
"id": "c1jsqis0d540",
"created": 1585127313145,
"text": "PDF、json、TXT、markdown",
"background": "transparent",
"font-size": 18,
"color": "#c2d69b",
"layout_right_offset": {
"x": 0,
"y": 1
}
},
"children": [
]
}
]
}
]
}
]
},
"subtree": [
],
"template": "default",
"theme": "classic-compact",
"relLine": [
],
"style": {
},
"themeBgColor": "",
"background": "",
"version": "1.5.2",
"ppts": [
]
}
path = '/home/python/Desktop/proejct_xx/_media/temp_file/test.xmind'
gen_xmind_file(data, path=path)
来源:https://blog.csdn.net/weixin_40105587/article/details/117557740
0
投稿
猜你喜欢
- 本文实例讲述了Python实现测试磁盘性能的方法。分享给大家供大家参考。具体如下:该代码做了如下工作:create 300000 files
- 今天要做一个量子隧穿的的演示动画,在CSDN上看了很多大佬的文章,然而忙了接近半天才做好这件事。把踩过的坑记一下,同时这段代码也是值得记录的
- QueueTornado的tornado.queue模块为基于协程的应用程序实现了一个异步生产者/消费者模式的队列。这与python标准库为
- Microsoft建立了一种既灵活又强大的安全管理机制,它能够对用户访问SQL Server服务器系统和数据库的安全进行全面地管理。按照本文
- 目录1 简介2 在Dash中实现文件上传与下载2.1 在Dash中配合dash-uploader实现文件上传2.1.1
- 装饰器通用模型def wrapper(fn): def inner(*args, **kwargs):  
- 本文实例讲述了Python3.5局部变量与全局变量作用域。分享给大家供大家参考,具体如下:1、局部变量与全局变量定义:在子程序(函数)中定义
- python中的Reportlab模块reportlab模块是用python语言生成pdf文件的模块安装:pip install repor
- 把dataframe转换为list输入多维dataframe: df = pd.DataFrame({'a':[1,3,5,
- 1. 游戏循环和游戏时钟之前几篇文章中,飞机大战游戏中的英雄飞机已经被绘制到屏幕上了,怎么能够让飞机移动呢?1.1 游戏中的动画实现原理跟电
- Python 用了好长一段时间了,起初是基于对爬虫的兴趣而接触到的。随着不断的深入,慢慢的转了其它语言,毕竟工作机会真的太少了。很多技能长时
- 本文实例为大家分享了python3通过qq邮箱发送邮件以及附件的具体代码,供大家参考,具体内容如下开启qq邮箱的smtp服务代码:impor
- Python将控制台输出另存为日志文件需求  在 PyCharm 中或者说运行 python 程序时会使
- mysql数据库没有增量备份的机制,当数据量太大的时候备份是一个很大的问题。还好mysql数据库提供了一种主从备份的机制,其实就是把主数据库
- Python程序的注释感觉很不合群,对于习惯了使用/**/多行注释的人来说,到Python中只能使用#号进行单行注释很痛苦。# 这里是单行注
- set是什么?数学上,把set称做由不同的元素组成的集合,集合(set)的成员通常被称做集合元素(set elements)。Python把
- A.截取从字符串左边开始N个字符 Declare @S1 varchar(100) Select @S1='http://www.x
- <% dim conn,mdbfile mdbfile=server.mappath("数据库名称.mdb") s
- 测试配置文件test.conf内容如下:[first]w = 2v: 3c =11-3[second]sw=4test: hello测试配置
- 在Windows中安装MySQL时,有3种MySQL 5.1安装软件包可供选择:· 基本安装:该安装软件包的文件名类似