How to use Eto PixelLayout on Windows and Mac in Python script that trims mesh to curve

#1

I have created a GUI using Eto so it can be used on both a Windows and Mac platform. In order to get the form to look reasonable with 3 controls on one line, I used PixelLayout instead of DynamicLayout for some of the controls. But I read this is highly discouraged, as each control may be different sizes based on the platform. One way of dealing with this is to just develop 2 sets of locations for the controls, 1 for Windows and 1 for Mac.

My questions is:
In my Python script, how do I tell whether Rhino is running on a Windows machine or a Mac?

Here is what the form looks like with 3 controls on the second line:

and here are some examples of using it to trim a mesh to a boundary curve, make a hole inside the boundary curve and make a trench inside the boundary curve:


The mesh has 1.4M faces and I have not been able to trim it in Rhino using Mesh Tools -> Trim Mesh without creating ragged edges (mesh faces not trimmed to boundary shape), or failing with no error message. The Python script fixes these issues, at least for my collection of meshes.

Regards,
Terry.

(Nathan 'jesterKing' Letwory) #2

I was going to suggest

mport platform
arch = platform.uname()[0]

but it appears our IronPython is buggy in that respect.

Python2.7 on the command-line on the Mac gives 'Darwin' as the result, but Rhino IronPython gives 'Windows', which is obviously wrong…

edit: I logged https://mcneel.myjetbrains.com/youtrack/issue/RH-52199 to track this bug.

(Graham) #3

How about:

import sys
print sys.platform
#4

The print say
cli
on my Windows system.
What does it say on a Mac system?

(Graham) #5

Or

import os 
os.pathsep

Should give the system path separator
I think it’s \ on Windows / on Mac
It’s : here on my iPhone :wink:

#6

On my Windows system this returns
;

What is this on a Mac system?

(Graham) #7

Ahh that’s not right hmm :thinking:

(Graham) #8

Ahh yes maybe : on Mac …

#9

from sys import exec_prefix gives:
file:///C:/Program Files/Rhino 6/Plug-ins/IronPython/IronPython.DLL
Is this different on a Mac?

(Graham) #10

Ahh I think I was looking for os.sep
Should be backslash for windows, forward for Mac …?

#11

from sys import getwindowsversion

print getwindowsversion()
gives:
sys.getwindowsversion(major=10, minor=0, build=17134, platform=2, service_pack='')
Is this different on a Mac?

(Graham) #12

I don’t have a Mac with Rhino. Maybe @p1r4t3b0y could check a few of these … ahh already done by the JesterKing

#13

os.sep gives
\
on my Windows system.

(Graham) #14

Gives ‘/’ on my iPhone

#15

Ok, I’ll go with os.sep = \ for Windows and os.sep = / for Mac.

Now I need someone to fix the PixelLayout locations in my form on a Mac system.

(Nathan 'jesterKing' Letwory) #16

This gives on the Mac

sys.getwindowsversion(major=18, minor=5, build=0, platform=4, service_pack='')

Which looks like it agrees with the kernel version (platform.uname() on Python2.7 in terminal gives ('Darwin', 'jesterMacPro.local', '18.5.0', 'Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64', 'x86_64', 'i386'), see third element of tuple.

But I don’t think this is a good indicator - what if in the future there is a Windows 18?

The os.sep is probably currently the best workaround, it gives on the Mac indeed a forward slash (as it would on any *nix type system). A proper functioning platform module would be much better though.

1 Like
#17

@nathanletwory,

What do you think of using os.sep = \ vs / that Graham found? This would be really simple.

Regards,
Terry.

(Nathan 'jesterKing' Letwory) #18

Already edited my previous answer with my thoughts on that.

#19

Are you saying the the Eto module should just work on a Windows and Mac system even when using PixelLayout style?

(Nathan 'jesterKing' Letwory) #20

Ehm, no. I meant os.sep usage to identify Mac from Windows.