Skip to content

Commit

Permalink
Lint check on source code
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwright committed Feb 14, 2025
1 parent 590e091 commit fff414d
Show file tree
Hide file tree
Showing 24 changed files with 2,211 additions and 1,845 deletions.
22 changes: 11 additions & 11 deletions bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
from shutil import make_archive
from cq_editor import __version__ as version

out_p = Path('dist/CQ-editor')
out_p = Path("dist/CQ-editor")
out_p.rmtree_p()

build_p = Path('build')
build_p = Path("build")
build_p.rmtree_p()

system("pyinstaller pyinstaller.spec")

if platform == 'linux':
if platform == "linux":
with out_p:
p = Path('.').glob('libpython*')[0]
p.symlink(p.split(".so")[0]+".so")
make_archive(f'CQ-editor-{version}-linux64','bztar', out_p / '..', 'CQ-editor')
elif platform == 'win32':
make_archive(f'CQ-editor-{version}-win64','zip', out_p / '..', 'CQ-editor')
p = Path(".").glob("libpython*")[0]
p.symlink(p.split(".so")[0] + ".so")

make_archive(f"CQ-editor-{version}-linux64", "bztar", out_p / "..", "CQ-editor")

elif platform == "win32":

make_archive(f"CQ-editor-{version}-win64", "zip", out_p / "..", "CQ-editor")
27 changes: 13 additions & 14 deletions collect_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@
from subprocess import call
from os import remove

TEMPLATE = \
'''<RCC>
TEMPLATE = """<RCC>
<qresource prefix="/images">
{}
</qresource>
</RCC>'''
</RCC>"""

ITEM_TEMPLATE = '<file>{}</file>'
ITEM_TEMPLATE = "<file>{}</file>"

QRC_OUT = 'icons.qrc'
RES_OUT = 'src/icons_res.py'
TOOL = 'pyrcc5'
QRC_OUT = "icons.qrc"
RES_OUT = "src/icons_res.py"
TOOL = "pyrcc5"

items = []

for i in glob('icons/*.svg'):
for i in glob("icons/*.svg"):
items.append(ITEM_TEMPLATE.format(i))


qrc_text = TEMPLATE.format('\n'.join(items))

with open(QRC_OUT,'w') as f:

qrc_text = TEMPLATE.format("\n".join(items))

with open(QRC_OUT, "w") as f:
f.write(qrc_text)
call([TOOL,QRC_OUT,'-o',RES_OUT])

call([TOOL, QRC_OUT, "-o", RES_OUT])
remove(QRC_OUT)
10 changes: 5 additions & 5 deletions cq_editor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

from PyQt5.QtWidgets import QApplication

NAME = 'CQ-editor'
NAME = "CQ-editor"

#need to initialize QApp here, otherewise svg icons do not work on windows
app = QApplication(sys.argv,
applicationName=NAME)
# need to initialize QApp here, otherewise svg icons do not work on windows
app = QApplication(sys.argv, applicationName=NAME)

from .main_window import MainWindow


def main():

parser = argparse.ArgumentParser(description=NAME)
parser.add_argument('filename',nargs='?',default=None)
parser.add_argument("filename", nargs="?", default=None)

Check warning on line 17 in cq_editor/__main__.py

View check run for this annotation

Codecov / codecov/patch

cq_editor/__main__.py#L17

Added line #L17 was not covered by tests

args = parser.parse_args(app.arguments()[1:])

Expand Down
101 changes: 60 additions & 41 deletions cq_editor/cq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
from OCP.XCAFPrs import XCAFPrs_AISObject
from OCP.TopoDS import TopoDS_Shape
from OCP.AIS import AIS_InteractiveObject, AIS_Shape
from OCP.Quantity import \
Quantity_TOC_RGB as TOC_RGB, Quantity_Color, Quantity_NOC_GOLD as GOLD
from OCP.Quantity import (
Quantity_TOC_RGB as TOC_RGB,
Quantity_Color,
Quantity_NOC_GOLD as GOLD,
)
from OCP.Graphic3d import Graphic3d_NOM_JADE, Graphic3d_MaterialAspect

from PyQt5.QtGui import QColor
Expand All @@ -25,48 +28,66 @@ def is_cq_obj(obj):
return isinstance(obj, (Workplane, Shape, Assembly, Sketch))


def find_cq_objects(results : dict):
def find_cq_objects(results: dict):

return {k:SimpleNamespace(shape=v,options={}) for k,v in results.items() if is_cq_obj(v)}
return {
k: SimpleNamespace(shape=v, options={})
for k, v in results.items()
if is_cq_obj(v)
}


def to_compound(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Shape], cq.Sketch]):
def to_compound(
obj: Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Shape], cq.Sketch],
):

vals = []

if isinstance(obj,cq.Workplane):
if isinstance(obj, cq.Workplane):
vals.extend(obj.vals())
elif isinstance(obj,cq.Shape):
elif isinstance(obj, cq.Shape):
vals.append(obj)
elif isinstance(obj,list) and isinstance(obj[0],cq.Workplane):
for o in obj: vals.extend(o.vals())
elif isinstance(obj,list) and isinstance(obj[0],cq.Shape):
elif isinstance(obj, list) and isinstance(obj[0], cq.Workplane):
for o in obj:
vals.extend(o.vals())
elif isinstance(obj, list) and isinstance(obj[0], cq.Shape):
vals.extend(obj)
elif isinstance(obj, TopoDS_Shape):
vals.append(cq.Shape.cast(obj))
elif isinstance(obj,list) and isinstance(obj[0],TopoDS_Shape):
elif isinstance(obj, list) and isinstance(obj[0], TopoDS_Shape):
vals.extend(cq.Shape.cast(o) for o in obj)
elif isinstance(obj, cq.Sketch):
if obj._faces:
vals.append(obj._faces)
else:
vals.extend(obj._edges)
else:
raise ValueError(f'Invalid type {type(obj)}')
raise ValueError(f"Invalid type {type(obj)}")

return cq.Compound.makeCompound(vals)


def to_workplane(obj : cq.Shape):
def to_workplane(obj: cq.Shape):

rv = cq.Workplane('XY')
rv.objects = [obj,]
rv = cq.Workplane("XY")
rv.objects = [

Check warning on line 73 in cq_editor/cq_utils.py

View check run for this annotation

Codecov / codecov/patch

cq_editor/cq_utils.py#L72-L73

Added lines #L72 - L73 were not covered by tests
obj,
]

return rv


def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Shape], cq.Assembly, AIS_InteractiveObject],
options={}):
def make_AIS(
obj: Union[
cq.Workplane,
List[cq.Workplane],
cq.Shape,
List[cq.Shape],
cq.Assembly,
AIS_InteractiveObject,
],
options={},
):

shape = None

Expand All @@ -82,28 +103,29 @@ def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Sha
set_material(ais, DEFAULT_MATERIAL)
set_color(ais, DEFAULT_FACE_COLOR)

if 'alpha' in options:
set_transparency(ais, options['alpha'])
if 'color' in options:
set_color(ais, to_occ_color(options['color']))
if 'rgba' in options:
r,g,b,a = options['rgba']
set_color(ais, to_occ_color((r,g,b)))
if "alpha" in options:
set_transparency(ais, options["alpha"])
if "color" in options:
set_color(ais, to_occ_color(options["color"]))
if "rgba" in options:
r, g, b, a = options["rgba"]
set_color(ais, to_occ_color((r, g, b)))
set_transparency(ais, a)

return ais,shape
return ais, shape


def export(obj : Union[cq.Workplane, List[cq.Workplane]], type : str,
file, precision=1e-1):
def export(
obj: Union[cq.Workplane, List[cq.Workplane]], type: str, file, precision=1e-1
):

comp = to_compound(obj)

if type == 'stl':
if type == "stl":
comp.exportStl(file, tolerance=precision)
elif type == 'step':
elif type == "step":
comp.exportStep(file)
elif type == 'brep':
elif type == "brep":
comp.exportBrep(file)


Expand All @@ -116,17 +138,14 @@ def to_occ_color(color) -> Quantity_Color:
elif isinstance(color[0], float):
color = QColor.fromRgbF(*color)
else:
raise ValueError('Unknown color format')
raise ValueError("Unknown color format")
else:
color = QColor(color)

return Quantity_Color(color.redF(),
color.greenF(),
color.blueF(),
TOC_RGB)
return Quantity_Color(color.redF(), color.greenF(), color.blueF(), TOC_RGB)


def get_occ_color(obj : Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:
def get_occ_color(obj: Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:

if isinstance(obj, AIS_InteractiveObject):
color = Quantity_Color()
Expand All @@ -137,7 +156,7 @@ def get_occ_color(obj : Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:
return QColor.fromRgbF(color.Red(), color.Green(), color.Blue())


def set_color(ais : AIS_Shape, color : Quantity_Color) -> AIS_Shape:
def set_color(ais: AIS_Shape, color: Quantity_Color) -> AIS_Shape:

drawer = ais.Attributes()
drawer.SetupOwnShadingAspect()
Expand All @@ -146,7 +165,7 @@ def set_color(ais : AIS_Shape, color : Quantity_Color) -> AIS_Shape:
return ais


def set_material(ais : AIS_Shape, material: Graphic3d_MaterialAspect) -> AIS_Shape:
def set_material(ais: AIS_Shape, material: Graphic3d_MaterialAspect) -> AIS_Shape:

drawer = ais.Attributes()
drawer.SetupOwnShadingAspect()
Expand All @@ -155,7 +174,7 @@ def set_material(ais : AIS_Shape, material: Graphic3d_MaterialAspect) -> AIS_Sha
return ais


def set_transparency(ais : AIS_Shape, alpha: float) -> AIS_Shape:
def set_transparency(ais: AIS_Shape, alpha: float) -> AIS_Shape:

drawer = ais.Attributes()
drawer.SetupOwnShadingAspect()
Expand Down Expand Up @@ -184,13 +203,13 @@ def reload_cq():
reload(cq.occ_impl.exporters.dxf)
reload(cq.occ_impl.exporters.amf)
reload(cq.occ_impl.exporters.json)
#reload(cq.occ_impl.exporters.assembly)
# reload(cq.occ_impl.exporters.assembly)
reload(cq.occ_impl.exporters)
reload(cq.assembly)
reload(cq)


def is_obj_empty(obj : Union[cq.Workplane,cq.Shape]) -> bool:
def is_obj_empty(obj: Union[cq.Workplane, cq.Shape]) -> bool:

rv = False

Expand Down
10 changes: 5 additions & 5 deletions cq_editor/cqe_run.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os, sys, asyncio

if 'CASROOT' in os.environ:
del os.environ['CASROOT']
if "CASROOT" in os.environ:
del os.environ["CASROOT"]

Check warning on line 4 in cq_editor/cqe_run.py

View check run for this annotation

Codecov / codecov/patch

cq_editor/cqe_run.py#L4

Added line #L4 was not covered by tests

if sys.platform == 'win32':
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

from cq_editor.__main__ import main


if __name__ == '__main__':
main()
if __name__ == "__main__":
main()
Loading

0 comments on commit fff414d

Please sign in to comment.