autopep8 aggressive

autopep8 --in-place --recursive  --max-line-length=200 --aggressive --aggressive --aggressive ifcopenshell
This commit is contained in:
thorade
2017-11-06 11:06:40 +01:00
committed by Thomas Krijnen
parent 8439e5b46d
commit 6cd59aa121
9 changed files with 61 additions and 35 deletions
@@ -49,6 +49,7 @@ except Exception as e:
if int(python_version_tuple[0]) == 2:
# Only for py2, as py3 has exception chaining
import traceback
traceback.print_exc()
print('-' * 64)
raise ImportError("IfcOpenShell not built for '%s'" % python_distribution)
@@ -65,6 +65,7 @@ class entity_instance(object):
def wrap(e): return entity_instance(e)
def is_instance(e): return isinstance(e, ifcopenshell_wrapper.entity_instance)
return entity_instance.walk(is_instance, wrap, v)
@staticmethod
@@ -72,6 +73,7 @@ class entity_instance(object):
def unwrap(e): return e.wrapped_data
def is_instance(e): return isinstance(e, entity_instance)
return entity_instance.walk(is_instance, unwrap, v)
def attribute_type(self, attr):
@@ -99,12 +101,13 @@ class entity_instance(object):
try:
if isinstance(value, unicode):
value = value.encode("utf-8")
except:
except BaseException:
pass
try:
getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value))
except:
raise ValueError("Expected %s for attribute %s.%s, got %r" % (real_attr_type, self.is_a(), self.attribute_name(idx), value))
except BaseException:
raise ValueError("Expected %s for attribute %s.%s, got %r" % (
real_attr_type, self.is_a(), self.attribute_name(idx), value))
return value
def __len__(self):
@@ -120,7 +123,7 @@ class entity_instance(object):
return self.wrapped_data.id()
def __eq__(self, other):
if type(self) != type(other):
if not isinstance(self, type(other)):
return False
return self.wrapped_data == other.wrapped_data
@@ -140,7 +143,7 @@ class entity_instance(object):
if include_identifier:
yield "id", self.id()
yield "type", self.is_a()
except:
except BaseException:
logging.exception("unhandled exception while getting id / type info on {}".format(self))
for i in range(len(self)):
try:
@@ -160,10 +163,12 @@ class entity_instance(object):
return_type=return_type,
ignore=ignore
)
attr_value = entity_instance.walk(is_instance, get_info_, attr_value)
yield self.attribute_name(i), attr_value
except:
except BaseException:
logging.exception("unhandled exception occured setting attribute name for {}".format(self))
return return_type(_())
__dict__ = property(get_info)
+4 -2
View File
@@ -61,9 +61,11 @@ class file(object):
elif isinstance(key, basestring):
return entity_instance(self.wrapped_data.by_guid(str(key)))
def by_id(self, id): return self[id]
def by_id(self, id):
return self[id]
def by_guid(self, guid): return self[guid]
def by_guid(self, guid):
return self[guid]
def add(self, inst):
inst.wrapped_data.this.disown()
@@ -15,7 +15,7 @@ from collections import defaultdict, Iterable, OrderedDict
os.environ['QT_API'] = 'pyqt4'
try:
from pyqode.qt import QtCore
except:
except BaseException:
pass
from PyQt4 import QtGui, QtCore
@@ -24,22 +24,21 @@ from .code_editor_pane import code_edit
try:
from OCC.Display.pyqt4Display import qtViewer3d
except:
except BaseException:
import OCC.Display
try:
import OCC.Display.backend
except:
except BaseException:
pass
try:
OCC.Display.backend.get_backend("qt-pyqt4")
except:
except BaseException:
OCC.Display.backend.load_backend("qt-pyqt4")
from OCC.Display.qtDisplay import qtViewer3d
from .main import settings, iterator
from .occ_utils import display_shape
@@ -58,10 +57,11 @@ class configuration(object):
try:
import ConfigParser
Cfg = ConfigParser.RawConfigParser
except:
except BaseException:
import configparser
def Cfg(): return configparser.ConfigParser(interpolation=None)
def Cfg():
return configparser.ConfigParser(interpolation=None)
conf_file = os.path.expanduser(os.path.join("~", ".ifcopenshell", "app", "snippets.conf"))
if conf_file.startswith("~"):
@@ -114,7 +114,6 @@ if selection:
class application(QtGui.QApplication):
"""A pythonOCC, PyQt based IfcOpenShell application
with two tree views and a graphical 3d view"""
@@ -165,7 +164,8 @@ class application(QtGui.QApplication):
itm = self.product_to_item.get(product)
if itm is None:
return
self.selectionModel().setCurrentIndex(itm, QtGui.QItemSelectionModel.SelectCurrent | QtGui.QItemSelectionModel.Rows)
self.selectionModel().setCurrentIndex(itm,
QtGui.QItemSelectionModel.SelectCurrent | QtGui.QItemSelectionModel.Rows)
class decomposition_treeview(abstract_treeview):
@@ -233,6 +233,7 @@ class application(QtGui.QApplication):
itm = items[t2] = QtGui.QTreeWidgetItem(items.get(s2, self), [t2])
itm.setData(0, QtCore.Qt.UserRole, t2)
self.children[s2].append(t2)
add(t)
for p in products:
@@ -379,6 +380,7 @@ class application(QtGui.QApplication):
shp = OCC.AIS.Handle_AIS_Shape.DownCast(li.Value(i + 1))
if not shp.IsNull():
yield shp
return tuple(shp.HashCode(1 << 24) for shp in yield_shapes())
def __init__(self, widget):
@@ -528,6 +530,7 @@ class application(QtGui.QApplication):
for c in self.components:
if c != component:
c.select(inst)
return handler
def __init__(self, settings=None):
@@ -582,7 +585,8 @@ class application(QtGui.QApplication):
sys.exit(self.exec_())
def browse(self):
filename = QtGui.QFileDialog.getOpenFileName(self.window, 'Open file', ".", "Industry Foundation Classes (*.ifc)")
filename = QtGui.QFileDialog.getOpenFileName(self.window, 'Open file', ".",
"Industry Foundation Classes (*.ifc)")
self.load(filename)
def clear(self):
@@ -11,7 +11,7 @@ from PyQt4 import QtCore, QtGui
try:
from PyQt4 import QtWidgets
except:
except BaseException:
QtWidgets = QtGui
try:
@@ -24,14 +24,14 @@ try:
from pyqode.python.backend import server
from pyqode.python import modes as pymodes, panels as pypanels, widgets
from pyqode.python.widgets import PyInteractiveConsole
has_pyqode = True
except:
except BaseException:
has_pyqode = False
CodeEdit = QtWidgets.QPlainTextEdit
class StdoutRedirector(object):
'''A class for redirecting stdout to this Text widget.'''
def __init__(self, widget):
@@ -49,7 +49,6 @@ class StdoutRedirector(object):
class code_edit(QtGui.QWidget):
class Console(InteractiveConsole):
def __init__(*args):
InteractiveConsole.__init__(*args)
@@ -32,7 +32,7 @@ from ..entity_instance import entity_instance
def has_occ():
try:
import OCC.BRepTools
except:
except BaseException:
return False
return True
@@ -40,13 +40,17 @@ def has_occ():
has_occ = has_occ()
def wrap_shape_creation(settings, shape): return shape
def wrap_shape_creation(settings, shape):
return shape
if has_occ:
from . import occ_utils as utils
def wrap_shape_creation(settings, shape): return utils.create_shape_from_serialization(shape) if getattr(settings, 'use_python_opencascade', False) else shape
def wrap_shape_creation(settings, shape): return utils.create_shape_from_serialization(shape) if getattr(settings,
'use_python_opencascade',
False) else shape
# Subclass the settings module to provide an additional
# setting to enable pythonOCC when available
@@ -83,6 +87,7 @@ class iterator(_iterator):
else:
file_or_filename = os.path.abspath(file_or_filename)
_iterator.__init__(self, settings, file_or_filename)
if has_occ:
def get(self):
return wrap_shape_creation(self.settings, _iterator.get(self))
@@ -108,6 +113,7 @@ class tree(ifcopenshell_wrapper.tree):
elif all(map(lambda v: hasattr(value, v), "XYZ")):
return value.X(), value.Y(), value.Z()
return value
args = [self, unwrap(value)]
if isinstance(value, entity_instance):
args.append(kwargs.get("completely_within", False))
@@ -124,6 +130,7 @@ class tree(ifcopenshell_wrapper.tree):
elif hasattr(value, "Get"):
return value.Get()[:3], value.Get()[3:]
return value
args = [self, unwrap(value)]
if "extend" in kwargs or "completely_within" in kwargs:
args.append(kwargs.get("completely_within", False))
@@ -152,7 +159,9 @@ def iterate(settings, filename):
def make_shape_function(fn):
def entity_instance_or_none(e): return None if e is None else entity_instance(e)
def entity_instance_or_none(e):
return None if e is None else entity_instance(e)
if has_occ:
import OCC.TopoDS
@@ -61,7 +61,7 @@ def initialize_display():
while True:
try:
active_light = viewer.ActiveLight()
except:
except BaseException:
break
yield active_light
viewer.NextActiveLights()
@@ -115,7 +115,8 @@ def display_shape(shape, clr=None, viewer_handle=None):
ais.SetMaterial(material)
if isinstance(clr, str):
qclr = getattr(OCC.Quantity, "Quantity_NOC_%s" % clr.upper(), getattr(OCC.Quantity, "Quantity_NOC_%s1" % clr.upper(), None))
qclr = getattr(OCC.Quantity, "Quantity_NOC_%s" % clr.upper(),
getattr(OCC.Quantity, "Quantity_NOC_%s1" % clr.upper(), None))
if qclr is None:
raise Exception("No color named '%s'" % clr.upper())
elif isinstance(clr, Iterable):
@@ -146,7 +147,8 @@ def display_shape(shape, clr=None, viewer_handle=None):
for shp, stl in zip(subshapes, representation.styles):
subshape = OCC.AIS.AIS_Shape(shp)
if min(stl) < 0. or max(stl) > 1.:
default_style_applied = stl = DEFAULT_STYLES.get(representation.data.type, DEFAULT_STYLES["DEFAULT"])
default_style_applied = stl = DEFAULT_STYLES.get(representation.data.type,
DEFAULT_STYLES["DEFAULT"])
subshape.SetColor(OCC.Quantity.Quantity_Color(stl[0], stl[1], stl[2], OCC.Quantity.Quantity_TOC_RGB))
subshape.SetMaterial(material)
if len(stl) == 4 and stl[3] < 1.:
@@ -171,7 +173,9 @@ def display_shape(shape, clr=None, viewer_handle=None):
ais = OCC.AIS.AIS_Shape(shape)
ais.SetMaterial(material)
def r(): return random.random() * 0.3 + 0.7
def r():
return random.random() * 0.3 + 0.7
clr = OCC.Quantity.Quantity_Color(r(), r(), r(), OCC.Quantity.Quantity_TOC_RGB)
ais.SetColor(clr)
@@ -211,12 +215,12 @@ def create_shape_from_serialization(brep_object):
try:
brep_data = brep_object.geometry.brep_data
styles = brep_object.geometry.surface_styles
except:
except BaseException:
try:
brep_data = brep_object.brep_data
styles = brep_object.surface_styles
is_product_shape = False
except:
except BaseException:
pass
styles = tuple(styles[i:i + 4] for i in range(0, len(styles), 4))
@@ -228,7 +232,7 @@ def create_shape_from_serialization(brep_object):
ss = OCC.BRepTools.BRepTools_ShapeSet()
ss.ReadFromString(brep_data)
occ_shape = ss.Shape(ss.NbShapes())
except:
except BaseException:
pass
if is_product_shape:
+3 -1
View File
@@ -33,13 +33,15 @@ def compress(g):
bs = [int(g[i:i + 2], 16) for i in range(0, len(g), 2)]
def b64(v, l=4):
return ''.join([chars[(v // (64**i)) % 64] for i in range(l)][::-1])
return ''.join([chars[(v // (64 ** i)) % 64] for i in range(l)][::-1])
return ''.join([b64(bs[0], 2)] + [b64((bs[i] << 16) + (bs[i + 1] << 8) + bs[i + 2]) for i in range(1, 16, 3)])
def expand(g):
def b64(v):
return reduce(lambda a, b: a * 64 + b, map(lambda c: chars.index(c), v))
bs = [b64(g[0:2])]
for i in range(5):
d = b64(g[2 + 4 * i:6 + 4 * i])
@@ -74,13 +74,13 @@ DEFAULTS = {
def create(filename=None, timestring=None, organization=None, creator=None,
schema_identifier=None, application_version=None, timestamp=None,
application=None, project_globalid=None, project_name=None):
d = dict(locals())
def _():
for var, value in d.items():
if value is None:
yield var, DEFAULTS.get(var, lambda *args: '')(d)
d.update(dict(_()))
return file.from_string(TEMPLATE % d)