Skip to content

Commit bcebe08

Browse files
committed
Refine to make run as an Addon correctly
1 parent f56acf4 commit bcebe08

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

InitGui.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
22

3-
# InitGui.py is run automatically by FreeCAD during the GUI initialization process
3+
# InitGui.py is run automatically by FreeCAD during the GUI initialization process by reading the
4+
# file into memory and running `exec` on its contents (so __file__ is not defined directly).
45

56
import os
67
import AddonManager
78

8-
if __file__:
9-
FreeCADGui.addLanguagePath(os.path.join(os.path.dirname(__file__), "Resources", "translations"))
10-
else:
11-
FreeCAD.Console.Warning("__file__ not defined, cannot set language path\n")
12-
9+
FreeCADGui.addLanguagePath(
10+
os.path.join(os.path.dirname(AddonManager.__file__), "Resources", "translations")
11+
)
1312
FreeCADGui.addCommand("Std_AddonMgr", AddonManager.CommandAddonManager())

addonmanager_freecad_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
try:
4040
import FreeCAD
41+
from freecad.utils import get_python_exe
4142

4243
if not hasattr(FreeCAD, "Console"):
4344
raise ImportError("Unrecognized FreeCAD version")
@@ -51,7 +52,6 @@
5152
translate = FreeCAD.Qt.translate
5253
loadUi = None
5354
GuiUp = FreeCAD.GuiUp
54-
get_python_exe = FreeCAD.get_python_exe
5555

5656
if GuiUp:
5757
import FreeCADGui

addonmanager_macro_parser.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
import io
3030
import re
31-
from typing import Any, Tuple, Optional
31+
from typing import Any, Tuple
32+
33+
import addonmanager_freecad_interface as fci
3234

3335
try:
3436
from PySide import QtCore
@@ -71,7 +73,6 @@ def __init__(self, name: str, code: str = ""):
7173
"xpm": "",
7274
}
7375
self.remaining_item_map = {}
74-
self.console = None if FreeCAD is None else fci.Console
7576
self.current_thread = DummyThread() if QtCore is None else QtCore.QThread.currentThread()
7677
if code:
7778
self.fill_details_from_code(code)
@@ -114,10 +115,7 @@ def fill_details_from_code(self, code: str) -> None:
114115
self._process_line(line, content_lines)
115116
except SyntaxError as e:
116117
err_string = f"Syntax error when parsing macro {self.name}:\n{str(e)}"
117-
if self.console:
118-
self.console.PrintWarning(err_string)
119-
else:
120-
print(err_string)
118+
fci.Console.PrintWarning(err_string)
121119

122120
def _process_line(self, line: str, content_lines: io.StringIO):
123121
"""Given a single line of the macro file, see if it matches one of our items,

0 commit comments

Comments
 (0)