Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Coder committed Apr 4, 2024
1 parent 9c05c11 commit c199fc6
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
3 changes: 1 addition & 2 deletions docs/examples/matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"%matplotlib widget\n",
"\n",
"from ogdf_python import *\n",
"from ogdf_python.matplotlib import *\n",
"import matplotlib.pyplot as plt\n",
"\n",
"cppinclude(\"ogdf/basic/graph_generators/randomized.h\")\n",
"cppinclude(\"ogdf/layered/SugiyamaLayout.h\")\n",
Expand Down Expand Up @@ -74,6 +72,7 @@
"metadata": {},
"outputs": [],
"source": [
"# import matplotlib.pyplot as plt\n",
"# oldpoints = None\n",
"\n",
"# def click(event):\n",
Expand Down
2 changes: 2 additions & 0 deletions src/ogdf_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
pass
else:
from ogdf_python.matplotlib import *

__all__ += ogdf_python.matplotlib.__all__
12 changes: 10 additions & 2 deletions src/ogdf_python/matplotlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from importlib.resources import *

from ogdf_python.loader import *
from ogdf_python.matplotlib.gui import GraphEditorLayout
from ogdf_python.matplotlib.util import *
from ogdf_python.matplotlib.widget import MatplotlibGraph, MatplotlibGraphEditor

__all__ = ["MatplotlibGraph", "MatplotlibGraphEditor", "GraphEditorLayout"]
__all__ = ["MatplotlibGraph", "MatplotlibGraphEditor"]

try:
import ipywidgets
except ImportError:
pass
else:
from ogdf_python.matplotlib.gui import GraphEditorLayout

__all__ += ["GraphEditorLayout"]

with as_file(files(__package__).joinpath("rendering.h")) as header:
cppinclude(header)
Expand Down
2 changes: 2 additions & 0 deletions src/ogdf_python/matplotlib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from ogdf_python.matplotlib.util import new_figure
from ogdf_python.matplotlib.widget import MatplotlibGraphEditor

__all__ = ["GraphEditorLayout"]

L = ipywidgets.Label


Expand Down
10 changes: 8 additions & 2 deletions src/ogdf_python/matplotlib/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from dataclasses import dataclass, asdict
from typing import List, Optional

Expand Down Expand Up @@ -75,7 +76,12 @@ def dPolylineToPath(poly, closed=False):
return Path(dPolylineToPathVertices(poly), closed=False)


@dataclass(frozen=True, slots=True)
FROZEN_DATACLASS = dict(frozen=True)
if sys.version_info >= (3, 10):
FROZEN_DATACLASS["slots"] = True


@dataclass(**FROZEN_DATACLASS)
class EdgeStyle:
edgecolor: str
linestyle: str
Expand Down Expand Up @@ -112,7 +118,7 @@ def dict_from_GA(GA, obj):
)


@dataclass(frozen=True, slots=True)
@dataclass(**FROZEN_DATACLASS)
class NodeStyle(EdgeStyle):
facecolor: str
hatch: str
Expand Down
2 changes: 2 additions & 0 deletions src/ogdf_python/matplotlib/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from ogdf_python.loader import *
from ogdf_python.matplotlib.util import *

__all__ = ["MatplotlibGraph", "MatplotlibGraphEditor"]


def catch_exception(wrapped):
@functools.wraps(wrapped)
Expand Down
4 changes: 1 addition & 3 deletions src/ogdf_python/pythonize/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def GraphAttributes_to_svg(self):
SVGConf.bezierInterpolation(False)
# SVGConf.curviness(0.1)
with tempfile.NamedTemporaryFile("w+t", suffix=".svg", prefix="ogdf-python-") as f:
os = cppyy.gbl.std.ofstream(f.name)
cppyy.gbl.ogdf.GraphIO.drawSVG(self, os, SVGConf)
os.close()
cppyy.gbl.ogdf.GraphIO.drawSVG(self, f.name, SVGConf)
return f.read()


Expand Down

0 comments on commit c199fc6

Please sign in to comment.