Skip to content

Commit

Permalink
fixes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Jan 17, 2023
1 parent 0f3688a commit 54f9d93
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 79 deletions.
21 changes: 0 additions & 21 deletions examples/advanced/cutWithMesh2.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/basic/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ echo Press Esc at anytime to skip example, F1 to interrupt
for f in *.py
do
echo "Processing $f script.."
python3 "$f"
python "$f"
done
1 change: 1 addition & 0 deletions examples/simulations/airplane1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
if t==0:
airplane.add_trail(n=200).add_shadow('z', -4)
plt.show(world, airplane, __doc__, viewup="z", resetcam=False)
#plt.process_events()

plt.interactive().close()

12 changes: 6 additions & 6 deletions examples/simulations/optics_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def count(self):
def integrate(self, pols):
"""Integrate the polarization vector and store
the probability in cell array 'Probability'."""
arr = np.zeros([self.ncells, 3], dtype=np.float)
arr = np.zeros([self.ncells, 3], dtype=float)
for i, cid in enumerate(self.cellids):
arr[cid] += pols[i]
arr = np.power(np.linalg.norm(arr, axis=1), 2) / len(self.cellids)
Expand Down Expand Up @@ -203,23 +203,23 @@ def trace(self, elements):

for _ in range(self.maxiterations):

hit_cids = element.intersect_with_line( # faster
hits, cids = element.intersect_with_line( # faster
self.p,
self.p + self.v * self.dmax,
return_ids=True,
tol=self.OBBTreeTolerance,
)
# hit_cids = self.intersect(element, self.p, self.p + self.v * self.dmax)

if len(hit_cids) == 0:
if len(hits) == 0:
break # no hits
hit, cid = hit_cids[0] # grab the first hit, point and cell ID of the mesh
hit, cid = hits[0], cids[0] # grab the first hit, point and cell ID of the mesh
d = np.linalg.norm(hit - self.p)
if d < self.tolerance:
# it's picking itself.. get the second hit if it exists
if len(hit_cids) < 2:
if len(hits) < 2:
break
hit, cid = hit_cids[1]
hit, cid = hits[1], cids[1]
d = np.linalg.norm(hit - self.p)

n = element.normals[cid]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vtk
Deprecated

Pygments
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"console_scripts": ["vedo=vedo.cli:execute_cli"],
},

install_requires=["vtk", "numpy", "Deprecated"],
install_requires=["vtk", "numpy", "Deprecated", "Pygments"],
include_package_data=True,

description="A python module for scientific analysis and visualization of 3D objects and point clouds based on VTK.",
Expand Down
18 changes: 13 additions & 5 deletions vedo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def execute_cli():
args = parser.parse_args()

if "/vedo/vedo" in vedo.installdir:
vedo.installdir = vedo.installdir.replace("vedo/", "").replace("vedo\\", "")
vedo.installdir = vedo.installdir.replace("vedo/", "")

if "\\vedo\\vedo" in vedo.installdir:
vedo.installdir = vedo.installdir.replace("vedo\\", "")


if args.info is not None:
system_info()
Expand All @@ -72,7 +76,7 @@ def execute_cli():
elif args.eog:
exe_eog(args)

elif len(args.files) == 0 or os.name == "nt":
elif len(args.files) == 0:
exe_gui(args)

else:
Expand Down Expand Up @@ -257,7 +261,7 @@ def exe_run(args):
# print()

printc("(" + matching[0] + ")", c="y", bold=0, italic=1)
os.system("python3 " + matching[0])
os.system("python " + matching[0])


################################################################################################
Expand Down Expand Up @@ -321,8 +325,12 @@ def exe_search(args):
if pattern in bline:
if fflag:
name = os.path.basename(ifile)
etype = ifile.split("/")[-2]
printc("--> examples/"+etype+"/"+name+":", c='y', italic=1, invert=1)
try:
etype = ifile.split("/")[-2]
printc("--> examples/"+etype+"/"+name+":", c='y', italic=1, invert=1)
except IndexError:
etype = ifile.split("\\")[-2]
printc("--> examples\\"+etype+"\\"+name+":", c='y', italic=1, invert=1)
fflag = False
line = line.replace(pattern, "\x1b[4m\x1b[1m"+pattern+"\x1b[0m\u001b[33m")
print(f"\u001b[33m{i}\t{line}\x1b[0m", end='')
Expand Down
10 changes: 3 additions & 7 deletions vedo/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,19 +561,14 @@
r"\sigma": "\U000003C3",
}


# terminal color print
def _has_colors(stream):
if not hasattr(stream, "isatty"):
return False
if not stream.isatty():
return False
try:
import curses
curses.setupterm()
return curses.tigetnum("colors") > 2
except:
return False
#
return True
_terminal_has_colors = _has_colors(sys.stdout)


Expand Down Expand Up @@ -1158,6 +1153,7 @@ def printc(
sys.stdout.write(out + end)

except: # ------------------------------------------------------------- fallback

try:
print(*strings, end=end)
except UnicodeEncodeError as e:
Expand Down
2 changes: 1 addition & 1 deletion vedo/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ def __init__(
self.frames = []
self.tmp_dir = TemporaryDirectory()
self.get_filename = lambda x: os.path.join(self.tmp_dir.name, x)
colors.printc("\video Video", self.name, "is open... ", c="m", end="")
colors.printc("Video file", self.name, "is open... ", c="m", end="")

def add_frame(self):
"""Add frame to current video."""
Expand Down
53 changes: 19 additions & 34 deletions vedo/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,10 @@ def __exit__(self, *args, **kwargs):

def process_events(self):
if self.interactor:
self.interactor.ProcessEvents()
try:
self.interactor.ProcessEvents()
except AttributeError:
pass
return self

def at(self, nren, yren=None):
Expand Down Expand Up @@ -976,12 +979,6 @@ def render(self, resetcam=False):
if not self.interactor.GetInitialized():
self.interactor.Initialize()

# if vedo.vtk_version[0] == 9 and "Darwin" in vedo.sys_platform:
# for a in self.actors:
# if isinstance(a, vtk.vtkVolume):
# self.window.SetMultiSamples(0) # to fix mac OSX BUG vtk9
# break

self.camera = self.renderer.GetActiveCamera()
if resetcam:
self.renderer.ResetCamera()
Expand All @@ -1000,15 +997,6 @@ def interactive(self):
self.interactor.GetRenderWindow().SetDisplayId("_0_p_void") ##HACK
return self

def enable_renderer(self, at=None, value=True):
"""Enable a render() call to refresh this renderer."""
if at is None:
ren = self.renderer
else:
ren = self.renderers[at]
ren.SetDraw(value)
return self

def use_depth_peeling(self, at=None, value=True):
"""
Specify whether use depth peeling algorithm at this specific renderer
Expand Down Expand Up @@ -2992,7 +2980,6 @@ def show(
if not self.interactor.GetInitialized():
self.interactor.Initialize()
self.interactor.RemoveObservers("CharEvent")
# self.interactor.ProcessEvents()

if self.sharecam:
for r in self.renderers:
Expand All @@ -3001,12 +2988,6 @@ def show(
if self.qt_widget is not None:
self.qt_widget.GetRenderWindow().AddRenderer(self.renderer)

if vedo.vtk_version[0] == 9 and "Darwin" in vedo.sys_platform:
for a in self.actors:
if isinstance(a, vtk.vtkVolume):
self.window.SetMultiSamples(0) # to fix mac OSX BUG vtk9
break

if self.axes is not None:
if viewup != "2d" or self.axes in [1, 8] or isinstance(self.axes, dict):
addons.add_global_axes(self.axes)
Expand Down Expand Up @@ -3075,7 +3056,13 @@ def show(

self.window.SetWindowName(self.title)

# 2d ####################################################################
if settings.default_backend == "2d":
return backends.get_notebook_backend()
#########################################################################

try:
# Needs pip install pyobjc
if (self._cocoa_initialized is False
and "Darwin" in vedo.sys_platform
and not self.offscreen
Expand All @@ -3085,18 +3072,8 @@ def show(
pid = os.getpid()
x = NSRunningApplication.runningApplicationWithProcessIdentifier_(int(pid))
x.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)
# self.interactor.LeftButtonPressEvent()
# self.interactor.LeftButtonReleaseEvent()
# self.interactor.ShowWindowOn()
# self.interactor.ProcessEvents()
# self.window.MakeCurrent()
except:
pass

# 2d ####################################################################
if settings.default_backend == "2d":
return backends.get_notebook_backend()
#########################################################################
vedo.logger.debug("On Mac OSX try: pip install pyobjc")

if self.interactor: # can be offscreen..

Expand Down Expand Up @@ -3140,6 +3117,14 @@ def show(
# vtk BUG:
if vedo.vtk_version == (9,2,2):
self.interactor.GetRenderWindow().SetDisplayId("_0_p_void") ##HACK
elif (
"Darwin" in vedo.sys_platform
and settings.allow_interaction
and len(self.renderers) == 1
):
# this causes focus problems with boolean.py and others
# when multirendering is present, but makes the window pop up
self.process_events()

if rate:
if self.clock is None: # set clock and limit rate
Expand Down
2 changes: 1 addition & 1 deletion vedo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __init__(self, level=0):
self.screeshot_large_image = False

# [DISABLED] Allow to continuously interact with scene during interactor.Start() execution
self.allow_interaction = False
self.allow_interaction = True

# BUG in vtk9.0 (if true close works but sometimes vtk crashes, if false doesnt crash but cannot close)
# see plotter.py line 555
Expand Down
2 changes: 1 addition & 1 deletion vedo/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_version='2022.4.2.dev6'
_version='2022.4.2.dev8'

0 comments on commit 54f9d93

Please sign in to comment.