Skip to content

Commit

Permalink
Merge pull request #16 from ibois-epfl/comp_mac
Browse files Browse the repository at this point in the history
Compatibility for MAC for script-sync grasshopper
  • Loading branch information
9and3 authored May 31, 2024
2 parents 966bbb8 + 33d2d3f commit 07e0486
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 42 deletions.
169 changes: 168 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,171 @@ temp/
# General
######################
# get rid of all build folders
build/
build/

######################
# Python
######################

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
46 changes: 6 additions & 40 deletions GH/PyGH/components/scriptsynccpy/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import System
import System.Drawing
import System.Windows.Forms
import Rhino
import rhinoscriptsyntax as rs
import Grasshopper
import Grasshopper as gh
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
Expand Down Expand Up @@ -173,7 +173,7 @@ def handle_connection_error(self, e):
error_messages = {
ConnectionRefusedError: "script-sync::Connection refused by the vscode",
ConnectionResetError: "script-sync::Connection was forcibly closed by the vscode",
socket.error: f"script-sync::Error connecting to the vscode: {str(e)}"
socket.error: f"script-sync::Error connecting to the vscode: {str(e)}, have you tried to press Shift+F4 on VSCode?"
}
self.add_runtime_warning(error_messages[type(e)])
self.is_connected = False if type(e) != socket.error or e.winerror != 10056 else True
Expand Down Expand Up @@ -213,37 +213,6 @@ def is_file_modified(self, last_modified):
return current_modified
return last_modified

class DialogThread(threading.Thread):
"""
A vanilla thread to open a dialog to select a file. The windows form
is done in a thread because sometimes it blocks the main thread on which
the Grasshopper canvas is running.
"""
def __init__(self):
threading.Thread.__init__(self)
self.path = None

def run(self):
"""
Open a dialog to select a Python file.
"""
dialog = System.Windows.Forms.OpenFileDialog()
dialog.Filter = "Python files (*.py)|*.py"
dialog.Title = "Select a Python file"
dialog.InitialDirectory = os.path.dirname("")
dialog.FileName = ""
dialog.Multiselect = False
dialog.CheckFileExists = True
dialog.CheckPathExists = True
dialog.RestoreDirectory = True

if dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK:
self.path = dialog.FileName
else:
raise Exception("script-sync::File not selected")



class ScriptSyncCPy(component):
def __init__(self):
super(ScriptSyncCPy, self).__init__()
Expand Down Expand Up @@ -290,13 +259,10 @@ def init_script_path(self, select_file : bool = False):
"""
# check if button is pressed
if select_file is True:
dialog_thread = DialogThread()
dialog_thread.start()
dialog_thread.join() # Wait for the dialog to close
if dialog_thread.path is not None:
self.path = dialog_thread.path
else:
raise Exception("script-sync::File not selected")
filename = rs.OpenFileName("Open", "Python Files (*.py)|*.py||")
if filename is None:
raise Exception("script-sync::No file selected")
self.path = filename

# fi file is in table view before
if not os.path.exists(self.path):
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: script-sync
version: 1.1.24
version: 1.2.0
authors:
- Andrea Settimi
description: Script-sync is a Rhino plug-in to run C# and Python (IronPython or CPython) in RhinoV8.
Expand Down

0 comments on commit 07e0486

Please sign in to comment.