Skip to content

Commit d9991fa

Browse files
committed
removing duplicated from rhino helpers
1 parent 1e9308f commit d9991fa

File tree

1 file changed

+53
-58
lines changed

1 file changed

+53
-58
lines changed

src/compas_rhino/utilities/misc.py

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,43 @@
1313
from compas_rhino.forms import ImageForm
1414

1515
try:
16+
basestring
17+
except NameError:
18+
basestring = str
19+
20+
try:
21+
import rhinoscriptsyntax as rs
1622
import System
1723
import Rhino
18-
import rhinoscriptsyntax as rs
19-
from Rhino.UI.Dialogs import ShowPropertyListBox
24+
25+
except ImportError:
26+
compas.raise_if_ironpython()
27+
28+
# check if MessageBox is already available for Mac
29+
try:
2030
from Rhino.UI.Dialogs import ShowMessageBox
2131

2232
except ImportError:
2333
compas.raise_if_ironpython()
2434

35+
# replace PropertyListBox by Eto form on Mac and Rhino 6
2536
try:
26-
basestring
27-
except NameError:
28-
basestring = str
37+
from compas_rhino.etoforms import PropertyListForm
38+
39+
except:
40+
try:
41+
from Rhino.UI.Dialogs import ShowPropertyListBox
42+
43+
except ImportError:
44+
compas.raise_if_ironpython()
45+
else:
46+
try:
47+
import clr
48+
clr.AddReference('Rhino.UI')
49+
import Rhino.UI
50+
51+
except ImportError:
52+
compas.raise_if_ironpython()
2953

3054

3155
__all__ = [
@@ -41,7 +65,6 @@
4165
'display_image',
4266
'display_html',
4367
'update_settings',
44-
'update_attributes',
4568
'update_named_values',
4669
'screenshot_current_view',
4770
'select_folder',
@@ -81,38 +104,6 @@ def screenshot_current_view(path,
81104
return result
82105

83106

84-
# def add_gui_helpers(helpers, overwrite=False, protected=False):
85-
# def decorate(cls):
86-
# # attr = {}
87-
# for helper in helpers:
88-
# # for name, value in helper.__dict__.items():
89-
# for name, value in inspect.getmembers(helper):
90-
# # magic methods
91-
# if name.startswith('__') and name.endswith('__'):
92-
# continue
93-
# # protected / private methods
94-
# if not protected and name.startswith('_'):
95-
# continue
96-
# # existing methods
97-
# if not overwrite:
98-
# if hasattr(cls, name):
99-
# continue
100-
# # attr[name] = value
101-
# # try:
102-
# # setattr(cls, name, value.__func__)
103-
# # except Exception:
104-
# # setattr(cls, name, value)
105-
# # inspect.ismethoddescriptor
106-
# # inspect.isdatadescriptor
107-
# if inspect.ismethod(value):
108-
# setattr(cls, name, value.__func__)
109-
# else:
110-
# setattr(cls, name, value)
111-
# # cls = type(cls.__name__, (cls, ), attr)
112-
# return cls
113-
# return decorate
114-
115-
116107
def wait():
117108
return Rhino.RhinoApp.Wait()
118109

@@ -202,27 +193,16 @@ def display_html():
202193
# ==============================================================================
203194

204195

205-
def update_settings(settings, message='', title='Update settings'):
206-
names = sorted(settings.keys())
207-
values = [str(settings[name]) for name in names]
208-
values = ShowPropertyListBox(message, title, names, values)
209-
if values:
210-
values = list(values)
211-
for name, value in zip(names, values):
212-
try:
213-
settings[name] = ast.literal_eval(value)
214-
except (TypeError, ValueError, SyntaxError):
215-
settings[name] = value
216-
return True
217-
return False
218-
219-
220-
def update_attributes(names, values, message='', title='Update attributes'):
221-
return ShowPropertyListBox(message, title, names, values)
222-
223-
224196
def update_named_values(names, values, message='', title='Update named values', evaluate=False):
225-
values = ShowPropertyListBox(message, title, names, values)
197+
try:
198+
dialog = PropertyListForm(names, values)
199+
except:
200+
values = ShowPropertyListBox(message, title, names, values)
201+
else:
202+
if dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow):
203+
values = dialog.values
204+
else:
205+
values = None
226206
if evaluate:
227207
if values:
228208
values = list(values)
@@ -236,6 +216,21 @@ def update_named_values(names, values, message='', title='Update named values',
236216
return values
237217

238218

219+
def update_settings(settings, message='', title='Update settings'):
220+
names = sorted(settings.keys())
221+
values = [str(settings[name]) for name in names]
222+
values = update_named_values(names, values, message=message, title=title)
223+
if values:
224+
values = list(values)
225+
for name, value in zip(names, values):
226+
try:
227+
settings[name] = ast.literal_eval(value)
228+
except (TypeError, ValueError, SyntaxError):
229+
settings[name] = value
230+
return True
231+
return False
232+
233+
239234
def unload_modules(top_level_module_name):
240235
"""Unloads all modules named starting with the specified string.
241236

0 commit comments

Comments
 (0)