From e16a52fc24b3896642e99faeec5e9a6c829787ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Dole=C5=BEal?= Date: Tue, 7 Apr 2020 01:45:21 +0200 Subject: [PATCH] UI Fixed, Pip ensure added, Select container --- data_vis/__init__.py | 15 ++++---- data_vis/colors.py | 8 ++--- data_vis/general.py | 53 +++++++++++++++++------------ data_vis/operators/bar_chart.py | 4 +-- data_vis/operators/line_chart.py | 1 + data_vis/operators/pie_chart.py | 2 ++ data_vis/operators/point_chart.py | 1 + data_vis/operators/surface_chart.py | 14 ++++---- 8 files changed, 56 insertions(+), 42 deletions(-) diff --git a/data_vis/__init__.py b/data_vis/__init__.py index 3cf5898..89dc155 100644 --- a/data_vis/__init__.py +++ b/data_vis/__init__.py @@ -59,16 +59,15 @@ def execute(self, context): try: self.install(python_path) except Exception as e: - self.report({'ERROR'}, 'Try to run Blender as administrator or install dependencies manually! :(\n Exception: {}'.format(str(e))) + self.report({'ERROR'}, 'Error ocurred, try to install dependencies manually. \n Exception: {}'.format(str(e))) return {'FINISHED'} def install(self, python_path): - import platform + pip_result = subprocess.check_call([python_path, '-m', 'ensurepip', '--user']) + if pip_result != 0: + raise Exception('Failed to install pip!') - if platform.system() == 'Windows': - result = subprocess.check_call([python_path, '-m', 'pip', 'install', '--user', 'scipy']) - elif platform.system() == 'Linux': - result = subprocess.check_call(['sudo', python_path, '-m', 'pip', 'install', '--user', 'scipy']) + result = subprocess.check_call([python_path, '-m', 'pip', 'install', '--user', 'scipy']) if result == 0: bpy.utils.unregister_class(OBJECT_OT_SurfaceChart) @@ -88,13 +87,11 @@ class DV_AddonPanel(bpy.types.Panel): def draw(self, context): layout = self.layout - row = layout.row() - row.label(text='Data', icon='WORLD_DATA') - row = layout.row() row.operator('ui.dv_load_data') box = layout.box() + box.label(icon='WORLD_DATA', text='Data Information:') box.label(text='Dims: ' + str(data_manager.dimensions)) box.label(text='Labels: ' + str(data_manager.has_labels)) box.label(text='Type: ' + str(data_manager.predicted_data_type)) diff --git a/data_vis/colors.py b/data_vis/colors.py index 8a3e9f1..245f15e 100644 --- a/data_vis/colors.py +++ b/data_vis/colors.py @@ -11,12 +11,12 @@ class ColorType(Enum): Custom = 3 def str_to_type(value): - if str(value) == '0' or value == 'Constant': + if str(value) == '0' or value == 'Gradient': + return ColorType.Gradient + if str(value) == '1' or value == 'Constant': return ColorType.Constant - if str(value) == '1' or value == 'Random': + if str(value) == '2' or value == 'Random': return ColorType.Random - if str(value) == '2' or value == 'Gradient': - return ColorType.Gradient class NodeShader: diff --git a/data_vis/general.py b/data_vis/general.py index 10a2171..0779c52 100644 --- a/data_vis/general.py +++ b/data_vis/general.py @@ -42,7 +42,6 @@ def range_updated(self, context): x_step: bpy.props.FloatProperty( name='Step of x axis', default=1.0, - min=0.05 ) x_range: bpy.props.FloatVectorProperty( @@ -55,7 +54,6 @@ def range_updated(self, context): y_step: bpy.props.FloatProperty( name='Step of y axis', default=1.0, - min=0.05 ) y_range: bpy.props.FloatVectorProperty( @@ -75,18 +73,21 @@ def range_updated(self, context): z_step: bpy.props.FloatProperty( name='Step of z axis', default=1.0, - min=0.05 ) thickness: bpy.props.FloatProperty( name='Thickness', - default=0.01, + min=0.001, + max=0.02, + default=0.005, description='How thick is the axis object' ) tick_mark_height: bpy.props.FloatProperty( name='Tick Mark Height', - default=0.03, + default=0.015, + min=0.001, + max=0.02, description='Thickness of axis mark objects' ) @@ -133,11 +134,11 @@ class DV_ColorPropertyGroup(bpy.types.PropertyGroup): ) color_type: bpy.props.EnumProperty( - name='Coloring Type', + name='Color Type', items=( - ('0', 'Constant', 'One color'), - ('1', 'Random', 'Random colors'), - ('2', 'Gradient', 'Gradient based on value') + ('0', 'Gradient', 'Gradient based on value'), + ('1', 'Constant', 'One color'), + ('2', 'Random', 'Random colors'), ), default='2', description='Type of coloring for chart' @@ -183,8 +184,10 @@ def __init__(self): def draw(self, context): layout = self.layout + box = layout.box() + box.label(icon='WORLD_DATA', text='Chart settings:') if hasattr(self, 'data_type'): - row = layout.row() + row = box.row() row.prop(self, 'data_type') only_2d = hasattr(self, 'dimensions') @@ -197,7 +200,7 @@ def draw(self, context): if hasattr(self, 'dimensions') and self.dm.predicted_data_type != DataType.Categorical: if numerical: - row = layout.row() + row = box.row() row.prop(self, 'dimensions') else: self.dimensions = '2' @@ -208,7 +211,7 @@ def draw(self, context): def draw_label_settings(self, box): if hasattr(self, 'label_settings'): row = box.row() - row.label(text='Label Settings:') + row.label(icon='FILE_FONT', text='Label Settings:') row.prop(self.label_settings, 'create') if self.label_settings.create: box.prop(self.label_settings, 'from_data') @@ -219,9 +222,10 @@ def draw_label_settings(self, box): row.prop(self.label_settings, 'y_label') row.prop(self.label_settings, 'z_label') - def draw_color_settings(self, box): + def draw_color_settings(self, layout): if hasattr(self, 'color_settings'): - box.label(text='Color settings') + box = layout.box() + box.label(icon='COLOR', text='Color settings') box.prop(self.color_settings, 'use_shader') box.prop(self.color_settings, 'color_type') if not ColorType.str_to_type(self.color_settings.color_type) == ColorType.Random: @@ -232,24 +236,26 @@ def draw_axis_settings(self, layout, numerical): return box = layout.box() - box.label(text='Axis Settings:') + box.label(icon='ORIENTATION_VIEW', text='Axis Settings:') row = box.row() - row.prop(self.axis_settings, 'x_range', text='x') + row.label(text='Range settings:') + row = box.row() + row.prop(self.axis_settings, 'x_range', text='X') if hasattr(self, 'dimensions') and self.dimensions == '3': row = box.row() - row.prop(self.axis_settings, 'y_range', text='y') + row.prop(self.axis_settings, 'y_range', text='Y') row = box.row() - row.prop(self.axis_settings, 'z_range', text='z') + row.prop(self.axis_settings, 'z_range', text='Z') box.prop(self.axis_settings, 'auto_steps') if not self.axis_settings.auto_steps: row = box.row() if numerical: - row.prop(self.axis_settings, 'x_step', text='x') + row.prop(self.axis_settings, 'x_step', text='X') if hasattr(self, 'dimensions') and self.dimensions == '3': - row.prop(self.axis_settings, 'y_step', text='y') - row.prop(self.axis_settings, 'z_step', text='z') + row.prop(self.axis_settings, 'y_step', text='Y') + row.prop(self.axis_settings, 'z_step', text='Z') row = box.row() row.prop(self.axis_settings, 'create') @@ -368,3 +374,8 @@ def in_axis_range_bounds_new(self, entry): return True + def select_container(self): + '''Makes container object active and selects it''' + bpy.ops.object.select_all(action='DESELECT') + bpy.context.view_layer.objects.active = self.container_object + self.container_object.select_set(True) diff --git a/data_vis/operators/bar_chart.py b/data_vis/operators/bar_chart.py index 231cf6a..9f67702 100644 --- a/data_vis/operators/bar_chart.py +++ b/data_vis/operators/bar_chart.py @@ -27,7 +27,7 @@ class OBJECT_OT_BarChart(OBJECT_OT_GenericChart): data_type: bpy.props.EnumProperty( name='Chart type', items=( - ('0', 'Numerical', 'X relative to Z or Y'), + ('0', 'Numerical', 'X, [Y] relative to Z'), ('1', 'Categorical', 'Label and value'), ), ) @@ -121,5 +121,5 @@ def execute(self, context): auto_steps=self.axis_settings.auto_steps, offset=0.0 ) - + self.select_container() return {'FINISHED'} diff --git a/data_vis/operators/line_chart.py b/data_vis/operators/line_chart.py index a445d26..81369e0 100644 --- a/data_vis/operators/line_chart.py +++ b/data_vis/operators/line_chart.py @@ -137,6 +137,7 @@ def execute(self, context): auto_steps=self.axis_settings.auto_steps, offset=0.0 ) + self.select_container() return {'FINISHED'} def create_curve(self, verts, edges): diff --git a/data_vis/operators/pie_chart.py b/data_vis/operators/pie_chart.py index f19971e..9707312 100644 --- a/data_vis/operators/pie_chart.py +++ b/data_vis/operators/pie_chart.py @@ -49,6 +49,7 @@ def draw(self, context): row = layout.row() row.prop(self, 'vertices') box = layout.box() + box.label(icon='COLOR', text='Color settings:') box.prop(self, 'color_shade') box.prop(self, 'color_type') @@ -103,6 +104,7 @@ def execute(self, context): label_obj.rotation_euler = (0, 0, 0) prev_i += increment + self.select_container() return {'FINISHED'} def join_slices(self, i_from, i_to): diff --git a/data_vis/operators/point_chart.py b/data_vis/operators/point_chart.py index e78fb7b..d9b5a4c 100644 --- a/data_vis/operators/point_chart.py +++ b/data_vis/operators/point_chart.py @@ -104,4 +104,5 @@ def execute(self, context): auto_steps=self.axis_settings.auto_steps, offset=0.0 ) + self.select_container() return {'FINISHED'} diff --git a/data_vis/operators/surface_chart.py b/data_vis/operators/surface_chart.py index d2cb1bb..ad50f6a 100644 --- a/data_vis/operators/surface_chart.py +++ b/data_vis/operators/surface_chart.py @@ -31,9 +31,10 @@ class OBJECT_OT_SurfaceChart(OBJECT_OT_GenericChart): ) density: bpy.props.IntProperty( - name='Density of grid', + name='Grid size', min=1, - default=100, + max=200, + default=20, ) rbf_function: bpy.props.EnumProperty( @@ -75,15 +76,16 @@ def draw(self, context): super().draw(context) layout = self.layout + box = layout.box() + box.label(icon='COLOR', text='Color Settings:') + box.prop(self, 'color_shade') + row = layout.row() row.prop(self, 'rbf_function') row = layout.row() row.prop(self, 'density') - row = layout.row() - row.prop(self, 'color_shade') - def face(self, column, row): return (column * self.density + row, (column + 1) * self.density + row, @@ -142,6 +144,6 @@ def execute(self, context): auto_steps=self.axis_settings.auto_steps, offset=0.0 ) - + self.select_container() return {'FINISHED'}