[Bf-extensions-cvs] [5f88305] master: Paint Palletes: Cleanup, refactor some code
lijenstina
noreply at git.blender.org
Sat Apr 15 03:26:45 CEST 2017
Commit: 5f883054ce5904d4d1fb34216530b6df9cb04a81
Author: lijenstina
Date: Sat Apr 15 03:25:47 2017 +0200
Branches: master
https://developer.blender.org/rBA5f883054ce5904d4d1fb34216530b6df9cb04a81
Paint Palletes: Cleanup, refactor some code
Bumped version to 0.9.2
Pep8 cleanup
Remove star imports
Imports as tuples
Consistent props definitions
Refactor the VIEW3D_OT_reset_weight_palette operator
and VIEW3D_PT_weight_palette panel removing if else walls
Fix crash with trying to save a preset into a non existing path
Small UI fixes (introduce the active icon in the palette menu)
Update some tooltips
Update links
===================================================================
M paint_palette.py
===================================================================
diff --git a/paint_palette.py b/paint_palette.py
index c343978..2a221cc 100644
--- a/paint_palette.py
+++ b/paint_palette.py
@@ -1,34 +1,33 @@
# paint_palette.py (c) 2011 Dany Lebel (Axon_D)
+
+# ##### BEGIN GPL LICENSE BLOCK #####
#
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-# ***** END GPL LICENCE BLOCK *****
+# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Paint Palettes",
"author": "Dany Lebel (Axon D)",
- "version": (0, 9, 1),
+ "version": (0, 9, 2),
"blender": (2, 63, 0),
"location": "Image Editor and 3D View > Any Paint mode > Color Palette or Weight Palette panel",
"description": "Palettes for color and weight paint modes",
"warning": "",
- "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+ "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/Paint/Palettes",
"category": "Paint",
}
@@ -44,7 +43,21 @@ with the brush by using the button under the color.
"""
import bpy
-from bpy.props import *
+from bpy.types import (
+ Operator,
+ Menu,
+ Panel,
+ PropertyGroup,
+ )
+from bpy.props import (
+ BoolProperty,
+ FloatProperty,
+ FloatVectorProperty,
+ IntProperty,
+ StringProperty,
+ PointerProperty,
+ CollectionProperty,
+ )
def update_panels():
@@ -55,6 +68,7 @@ def update_panels():
brush.color = current_color
pp.index = pp.current_color_index
+
def sample():
pp = bpy.context.scene.palette_props
current_color = pp.colors[pp.current_color_index]
@@ -62,15 +76,16 @@ def sample():
current_color.color = brush.color
return None
+
def current_brush():
context = bpy.context
if context.area.type == 'VIEW_3D' and context.vertex_paint_object:
brush = context.tool_settings.vertex_paint.brush
elif context.area.type == 'VIEW_3D' and context.image_paint_object:
brush = context.tool_settings.image_paint.brush
- elif context.area.type == 'IMAGE_EDITOR' and context.space_data.mode == 'PAINT':
+ elif context.area.type == 'IMAGE_EDITOR' and context.space_data.mode == 'PAINT':
brush = context.tool_settings.image_paint.brush
- else :
+ else:
brush = None
return brush
@@ -82,7 +97,7 @@ def update_weight_value():
return None
-class PALETTE_MT_menu(bpy.types.Menu):
+class PALETTE_MT_menu(Menu):
bl_label = "Presets"
preset_subdir = ""
preset_operator = "palette.load_gimp_palette"
@@ -98,7 +113,7 @@ class PALETTE_MT_menu(bpy.types.Menu):
layout.label("* Missing Paths *")
# collect paths
- else :
+ else:
files = []
for directory in searchpaths:
files.extend([(f, os.path.join(directory, f)) for f in os.listdir(directory)])
@@ -153,8 +168,6 @@ class LoadGimpPalette(bpy.types.Operator):
preset_class = getattr(bpy.types, self.menu_idname)
preset_class.bl_label = bpy.path.display_name(basename(filepath))
-
- ts = bpy.context.tool_settings
palette_props.columns = 0
if filepath[-4:] == ".gpl":
gpl = open(filepath, "r")
@@ -170,9 +183,9 @@ class LoadGimpPalette(bpy.types.Operator):
palette_props.columns = int(line[8:])
elif line[0] == "#":
palette_props.notes += line
- else :
+ else:
has_color = True
- #index_0 = i
+ # index_0 = i
break
i = -1
if has_color:
@@ -181,7 +194,7 @@ class LoadGimpPalette(bpy.types.Operator):
palette_props.colors[i]
except IndexError:
palette_props.colors.add()
- color = [float(rgb)/255 for rgb in [ln[0:3], ln[4:7], ln[8:11]]]
+ color = [float(rgb) / 255 for rgb in [ln[0: 3], ln[4: 7], ln[8: 11]]]
palette_props.colors[i].color = color
@@ -195,7 +208,7 @@ class LoadGimpPalette(bpy.types.Operator):
update_panels()
gpl.close()
pass
- else :
+ else:
self.report({'INFO'}, "Not a supported palette format")
return {'FINISHED'}
@@ -206,14 +219,17 @@ class WriteGimpPalette():
subclasses must define
- preset_values
- preset_subdir """
- bl_options = {'REGISTER'} # only because invoke_props_popup requires.
-
-
-
- name = bpy.props.StringProperty(name="Name",
- description="Name of the preset, used to make the path name",
- maxlen=64, default="")
- remove_active = bpy.props.BoolProperty(default=False, options={'HIDDEN'})
+ bl_options = {'REGISTER'} # only because invoke_props_popup requires
+
+ name = StringProperty(
+ name="Name",
+ description="Name of the preset, used to make the path name",
+ maxlen=64, default=""
+ )
+ remove_active = BoolProperty(
+ default=False,
+ options={'HIDDEN'}
+ )
@staticmethod
def as_filename(name): # could reuse for other presets
@@ -242,7 +258,13 @@ class WriteGimpPalette():
self.report({'WARNING'}, "Failed to create presets path")
return {'CANCELLED'}
+ if not os.path.exists(target_path):
+ self.report({'WARNING'},
+ "Failure to open the saved Palletes Folder. Check if the path exists")
+ return {'CANCELLED'}
+
filepath = os.path.join(target_path, filename) + ".gpl"
+
file_preset = open(filepath, 'wb')
gpl = "GIMP Palette\n"
gpl += "Name: %s\n" % filename
@@ -250,7 +272,8 @@ class WriteGimpPalette():
gpl += pp.notes
if pp.colors.items():
for i, color in enumerate(pp.colors):
- gpl += "%3d%4d%4d %s" % (color.color.r * 255, color.color.g * 255, color.color.b * 255, color.name + '\n')
+ gpl += "%3d%4d%4d %s" % (color.color.r * 255, color.color.g * 255,
+ color.color.b * 255, color.name + '\n')
file_preset.write(bytes(gpl, 'UTF-8'))
file_preset.close()
@@ -298,22 +321,21 @@ class WriteGimpPalette():
return self.execute(context)
-class AddPresetPalette(WriteGimpPalette, bpy.types.Operator):
- """Add a Palette Preset"""
+class AddPresetPalette(WriteGimpPalette, Operator):
bl_idname = "palette.preset_add"
bl_label = "Add Palette Preset"
preset_menu = "PALETTE_MT_menu"
+ bl_description = "Add a Palette Preset"
preset_defines = []
preset_values = []
preset_subdir = "palette"
-class PALETTE_OT_add_color(bpy.types.Operator):
+class PALETTE_OT_add_color(Operator):
+ bl_idname = "palette_props.add_color"
bl_label = ""
bl_description = "Add a Color to the Palette"
- bl_idname = "palette_props.add_color"
-
def execute(self, context):
pp = bpy.context.scene.palette_props
@@ -324,81 +346,82 @@ class PALETTE_OT_add_color(bpy.types.Operator):
last = pp.colors.__len__() - 1
-
pp.colors.move(last, new_index)
pp.current_color_index = new_index
sample()
update_panels()
+
return {'FINISHED'}
-class PALETTE_OT_remove_color(bpy.types.Operator):
+class PALETTE_OT_remove_color(Operator):
+ bl_idname = "palette_props.remove_color"
bl_label = ""
bl_description = "Remove Selected Color"
- bl_idname = "palette_props.remove_color"
@classmethod
def poll(cls, context):
pp = bpy.context.scene.palette_props
return bool(pp.colors.items())
-
def execute(self, context):
- pp = bpy.context.scene.palette_props
+ pp = context.scene.palette_props
i = pp.current_color_index
pp.colors.remove(i)
if pp.current_color_index >= pp.colors.__len__():
pp.index = pp.current_color_index = pp.colors.__len__() - 1
+
return {'FINISHED'}
-class PALETTE_OT_sample_tool_color(bpy.types.Operator):
+class PALETTE_OT_sample_tool_color(Operator):
+ bl_idname = "palette_props.sample_tool_color"
bl_label = ""
bl_description = "Sample Tool Color"
- bl_idname = "palette_props.sample_tool_color"
def execute(self, context):
- pp = bpy.context.scene.palette_props
+ pp = context.scene.palette_props
brush = current_brush()
pp.colors[pp.current_color_index].color = brush.color
+
return {'FINISHED'
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list