Pie Palette


(Urf) #1

I have tried for 2 days to figure out the code on this and Im stumped. I have made simple menu’s before, and a Pie Menu with the Grease Pencil tools in it but for some reason the color palette, color wheel, value sliders, etc in texture paint just will not evoke properly. Can someone who knows this better than I chime in and offer a solution?

The goal is either a simple menu / pie menu to popup at the mouse with a color wheel or palette. It drives me crazy going to the left tool shelf to pick colors. If you know Krita then you know the menu Im looking for, even MyPaint with its “v” key popup. Here is what I tried last thinking I had a solution and still nothing.

import bpy
from bpy.types import Menu

class PiePalette(Menu):
bl_label = “PiePalette”

def draw(self, context):
    layout = self.layout

    pie = layout.menu_pie()
    pie.template_palette(settings, "palette", color=True)

def register():
bpy.utils.register_class(PiePalette)

def unregister():
bpy.utils.unregister_class(PiePalette)

if name == “main”:
register()

bpy.ops.wm.call_menu_pie(name="PiePalette")

(Urf) #2

Im much closer. I refuse to give up on this (even though Im far from a programmer)

Here is what I have so far.

and the code

bl_info = {
“name”: “Pie_Palette”,
“author”: “Urf”,
“version”: (0, 1,),
“blender”: (2, 77, 0),
“description”: “Pie Palette”,
“warning”: “”,
“wiki_url”: “”,
“category”: “User Interface”,
}

import bpy
from bpy.types import Menu

class PiePalette(Menu):
bl_label = “Pie Palette”
bl_idname=“Pie_Palette”

def draw(self, context):
    layout = self.layout

    pie = layout.menu_pie()
    brush = context.tool_settings.image_paint.brush
    
    # Color Wheel
    col = pie.column(align=True)
    col.label(text="Color Wheel")
    col.prop(brush, "color", text="")
    
    #Brushes
    pie.operator("paint.brush_select",text="Draw",icon='BRUSH_TEXDRAW').texture_paint_tool='DRAW'
    pie.operator("paint.brush_select",text="Smear",icon='BRUSH_SMEAR').texture_paint_tool='SMEAR'
    pie.operator("paint.brush_select",text="Soften",icon='BRUSH_SOFTEN').texture_paint_tool='SOFTEN'

def register():
bpy.utils.register_class(PiePalette)
addon = bpy.context.window_manager.keyconfigs.addon
km = addon.keymaps.new(name = “3D View”, space_type = “VIEW_3D”)

kmi = km.keymap_items.new("wm.call_menu_pie", "SPACE", "PRESS")
kmi.properties.name = "Pie_Palette"

addon_keymaps.append(km)

def unregister():
bpy.utils.unregister_class(PiePalette)

if name == “main”:
register()

bpy.ops.wm.call_menu_pie(name="PiePalette")

I wish I didnt have to click on the sample color box but it works. :smiley:

Attachments



(Craig Jones) #3

I was looking at making a similar attempt and then realized that in latest Texture Paint Plus, the brush popup already has access to them, though it does mean you have a larger popup there. Call it with W and you will see what I mean. If you want, look over the code for the brush popup and see how it is handled, and then rob what you need there, okay? Cheers.


(Ethan Aeris) #4

Hi,
here is the paint part of my custom pie . hope it will help you.
It includes texture slots, palette and a little slot manager.
And like Craig Jones said, it was inspired from the texture paint plus.
pie radius must be set above 170 in blender preferences for good results.



# -*- coding: utf-8 -*-

# ##### 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 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.
#
# ##### END GPL LICENSE BLOCK #####

################################################
# Paint                                                                                                 #
################################################
           
        elif bpy.context.area.type == 'VIEW_3D' and bpy.context.object.mode == 'TEXTURE_PAINT':
            paint = context.tool_settings.image_paint
            settings = context.tool_settings.image_paint
            obj = context.active_object
            mat = obj.active_material

            #4 - Left
            col = pie.column(align=True)
            row=col.row(align=True)
            row = col.row(align=True)
            col.scale_x = 0.7
            col.template_ID(settings, "palette", new="palette.new")
            col.template_palette(settings, \
            "palette", color=True)

            #6 - Right
            col = pie.split().column()
            row = col.split(align=True)
            row.operator("paint.brush_select", text="Draw", icon='BRUSH_TEXDRAW').texture_paint_tool='DRAW'
            row.operator("paint.brush_select", text='Mask', icon='BRUSH_TEXMASK').texture_paint_tool='MASK'
            row.operator("paint.brush_select", text='Clone', icon='BRUSH_CLONE').texture_paint_tool='CLONE'
            row = col.row(align=True)
            row = col.split(align=True)

            row.operator("paint.brush_select", text='Soften', icon='BRUSH_SOFTEN').texture_paint_tool='SOFTEN'
            row.operator("paint.brush_select", text="Fill", icon='BRUSH_TEXFILL').texture_paint_tool='FILL'
            row.operator("paint.brush_select", text='Smear', icon='BRUSH_SMEAR').texture_paint_tool='SMEAR'
     
            #2 - Bottom
            col = pie.column(align=True)
            col.label("Painting Mode")
            col.prop(settings, "mode", text="")
            col.scale_x=0.7
            if settings.mode == 'MATERIAL' and hasattr(mat, "paint_active_slot"):
                col.label("Paint Slots")
                col.template_list("TEXTURE_UL_texpaintslots", "",
                mat, "texture_paint_images",
                mat, "paint_active_slot", rows=3)
     
            elif settings.mode == 'IMAGE':
                col.label("Canvas Image")
                col.template_ID(settings, "canvas")

            
            col.operator_menu_enum("paint.add_texture_paint_slot", "type")
            col.operator("image.save_dirty", text="Save All Images")
     
            col.operator("image.open", text="Open Image")
            col.operator("import_image.brushset", text="Open Alpha Folder")
            col.operator("uv.smart_project", text = "Smart Uv")
     
            #8 - Top
            ups = context.tool_settings.unified_paint_settings
            paintbrush = context.tool_settings.image_paint.brush
     
     
            col = pie.column(align=True)
            row=col.row(align=True)
            row.prop(ups, "size", text="Radius", slider=False)
            row.prop(paintbrush, "use_pressure_size", text="")
            row=col.row(align=True)
            row.prop(paintbrush, "strength", slider=True)
            row.prop(paintbrush, "use_pressure_strength", text="")
     
            row = col.row(align=True)
            row = col.split(align=True)
            row.prop(paintbrush, "color",text="")
            row.prop(paintbrush, "secondary_color", text="")
     
            row.operator("paint.brush_colors_flip", icon='FILE_REFRESH', text="")
     
     
            # - Top Left
            col = pie.column(align=True)
            row=col.row(align=True)
            col.label(text="Symmetry:")
            row=col.row(align=True)
            row.prop(paint, "use_symmetry_x", text="X", toggle=True)
            row.prop(paint, "use_symmetry_y", text="Y", toggle=True)
            row.prop(paint, "use_symmetry_z", text="Z", toggle=True)
            col.prop(paintbrush, "use_smooth_stroke")
            col.prop(paintbrush, "smooth_stroke_radius", text="Radius", slider=True)
            col.prop(paintbrush, "smooth_stroke_factor", text="Factor", slider=True)
            
            #7 - Top Right
            col = pie.column(align=True)
            col.prop(paintbrush, "stroke_method", text="", icon='IPO_CONSTANT')
            col.prop(paintbrush, "spacing", slider=True)
            col.prop(paintbrush,"jitter", slider=True)
            row = col.split(align=True)
            col.prop(paintbrush, "blend", text="")
            row.prop(paintbrush, "use_accumulate")
            row.prop(paintbrush, "use_alpha")

            #9 - Bottom Left
           
            col = pie.column(align=True)
            row = col.split(align=True)
            col.scale_x=0.5
            tex_slot = paintbrush.texture_slot
            mask_tex_slot = paintbrush.mask_texture_slot      
            
            col.template_ID_preview(paintbrush, "texture", new="texture.new", rows=2, cols=2)
            col.prop(tex_slot, "tex_paint_map_mode", text="")
            row = col.row(align=True)
            row.label(text="Brush Mapping")
           
     
            # - Bottom Right
            col = pie.column(align=True)
            row = col.split(align=True)
            col.scale_x=0.5
            row = col.row(align=True)
            col.template_ID_preview(paintbrush, "mask_texture", new="texture.new", rows=2, cols=2)
            col.prop(mask_tex_slot, "mask_map_mode", text="")
            row = col.row(align=True)
            row.label(text="Mask Mapping")

(Craig Jones) #5

Is it okay if I borrow this portion? I want to work out a pie that will return color choices to pick from that follow color rules, and this has a lot of good info on the paint side of pie menus.


(Ethan Aeris) #6

Sure!
It’s under the Gpl license, but it was not copied in the paste .
Now it’s fixed, so everyone can feel free to pick what they want :slight_smile:

About your future pie, will it follow chromatic/complementary/opposite colors rules ?
It will be interesting to follow.

About colors, on my way, I try to figure a way to store automatically the last color painted in a dedicated palette , but I didn’t managed yet.


(Craig Jones) #7

I want to add a pie menu to Texture Paint Plus in Spitou4D’s version to allow to generate a palette for complimentary and analogous for now, but I want to make sure that it is user friendly. Right now I had been only using the pop ups in his version which really help since they are persistent and allow multiple adjustments without disappearing right away. I think BPainter uses a json file to store and recall the paint palettes it has.