-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMenuUtils.py
155 lines (130 loc) · 5.49 KB
/
MenuUtils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- coding: utf-8 -*-
# ***************************************************************************
# * Copyright (c) 2023 Yorik van Havre <yorik@uncreated.net> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
"""
Menu utilities module - NOT USED YET
"""
# menu building - not used yet
MENU_LINKS = [
[translate("Help", "Home"), "https://freecad.org"],
[translate("Help", "Forum"), "https://forum.freecad.org"],
[translate("Help", "Wiki"), "https://wiki.freecad.org"],
[translate("Help", "Issues"), "https://github.com/FreeCAD/FreeCAD/issues"],
[translate("Help", "Code repository"), "https://github.com/FreeCAD/FreeCAD"],
]
MENU_COMMANDS = [
[
"applications-python.svg",
translate("Help", "Auto Python modules"),
None,
"Std_PythonHelp",
],
["freecad.svg", translate("Help", "About FreeCAD"), None, "Std_About"],
["WhatsThis.svg", translate("Help", "What's this?"), "Shift+F1", "Std_WhatsThis"],
]
def generate_index():
"""
Offline index generator - generates an index file from the documentation
Structure:
- Users
- Workbenches
- Powerusers
- Developers
- Manual
"""
import os
this_folder = os.path.dirname(__file__)
doc_folder = os.join(os.path.dirname(this_folder), "FreeCAD-documentation", "wiki")
if not os.path.isdir(doc_folder):
return
wikifiles = [e for e in os.listdir(dic_folder) if e.endswith(".md")]
json = ""
def add_menu():
"""adds the Help menu of FreeCAD"""
import FreeCADGui
if hasattr(FreeCADGui, "HelpMenu"):
mb = FreeCADGui.getMainWindow().menuBar()
mb.addMenu(FreeCADGui.HelpMenu)
def build_menu():
"""creates and populates a help menu. Menu creation takes several
seconds to fullfill due to the big number of entries."""
import FreeCADGui
from PySide2 import QtGui
menu = QtGui.QMenu(translate("Help", "Help"))
menu.setObjectName("Help")
# On the web
sub = QtGui.QMenu(translate("Help", "On the web"), menu)
for it in MENU_LINKS:
act = QtGui.QAction(it[0], sub)
act.setToolTip(it[1])
act.triggered.connect(lambda f=show, arg=it[1]: f(arg))
sub.addAction(act)
menu.addMenu(sub)
# Documentation
cache = os.path.join(FreeCAD.getUserAppDataDir(), "Help", "menu.md")
if not os.path.exists(cache):
get_menu_structure()
if os.path.exists(cache):
doc = QtGui.QMenu(translate("Help", "Documentation"), menu)
act = QtGui.QAction("Index", doc)
act.setShortcut("F1")
act.setToolTip(
translate("Help", "Shows the index page of the FreeCAD documentation")
)
act.triggered.connect(lambda: show("Main Page"))
doc.addAction(act)
with open(cache) as f:
for line in f:
name = line[line.index("[") + 1 : line.index("]")]
link = line[line.index("(") + 1 : line.index(")")]
if line.startswith("-"):
sub = QtGui.QMenu(name, menu)
doc.addMenu(sub)
else:
act = QtGui.QAction(name, sub)
act.setToolTip(link)
act.triggered.connect(lambda f=show, arg=link: f(arg))
sub.addAction(act)
menu.addMenu(doc)
# Special FreeCAD Help commands
for it in MENU_COMMANDS:
if it[0]:
act = QtGui.QAction(QtGui.QIcon(":/icons/" + it[0]), it[1], menu)
else:
act = QtGui.QAction(it[1], menu)
if it[2]:
act.setShortcut(it[2])
act.triggered.connect(lambda f=FreeCADGui.runCommand, arg=it[3]: f(arg))
menu.addAction(act)
# store menu to FreeCAD for faster access and possible modification by addons
FreeCADGui.HelpMenu = menu
def get_menu_structure():
"""fetches menu structure from documentation"""
location = get_location("Online Help Toc")
if not location:
return
md = get_contents(location)
d = os.path.join(FreeCAD.getUserAppDataDir(), "Help")
if not os.path.isdir(d):
os.makedirs(d)
cache = os.path.join(d, "menu.md")
with open(cache, "w") as f:
f.write(md)