Skip to content

Commit

Permalink
Merge pull request #8 from Griperis/hotfix/python-ui
Browse files Browse the repository at this point in the history
UI Fixed, Pip ensure added, Select container
  • Loading branch information
Griperis committed Apr 6, 2020
2 parents 7f487f2 + e16a52f commit 322cc58
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
15 changes: 6 additions & 9 deletions data_vis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions data_vis/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
53 changes: 32 additions & 21 deletions data_vis/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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'
)

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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')
Expand All @@ -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'
Expand All @@ -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')
Expand All @@ -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:
Expand All @@ -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')
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions data_vis/operators/bar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
),
)
Expand Down Expand Up @@ -121,5 +121,5 @@ def execute(self, context):
auto_steps=self.axis_settings.auto_steps,
offset=0.0
)

self.select_container()
return {'FINISHED'}
1 change: 1 addition & 0 deletions data_vis/operators/line_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions data_vis/operators/pie_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions data_vis/operators/point_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ def execute(self, context):
auto_steps=self.axis_settings.auto_steps,
offset=0.0
)
self.select_container()
return {'FINISHED'}
14 changes: 8 additions & 6 deletions data_vis/operators/surface_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -142,6 +144,6 @@ def execute(self, context):
auto_steps=self.axis_settings.auto_steps,
offset=0.0
)

self.select_container()
return {'FINISHED'}

0 comments on commit 322cc58

Please sign in to comment.