Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'uv_magic_uv/op/move_uv.py')
-rw-r--r--uv_magic_uv/op/move_uv.py95
1 files changed, 76 insertions, 19 deletions
diff --git a/uv_magic_uv/op/move_uv.py b/uv_magic_uv/op/move_uv.py
index 6382376c..a229ae34 100644
--- a/uv_magic_uv/op/move_uv.py
+++ b/uv_magic_uv/op/move_uv.py
@@ -20,23 +20,68 @@
__author__ = "kgeogeo, mem, Nutti <nutti.metro@gmail.com>"
__status__ = "production"
-__version__ = "5.1"
-__date__ = "24 Feb 2018"
+__version__ = "5.2"
+__date__ = "17 Nov 2018"
import bpy
import bmesh
from mathutils import Vector
+from bpy.props import BoolProperty
+from .. import common
-class MUV_MVUV(bpy.types.Operator):
+__all__ = [
+ 'Properties',
+ 'Operator',
+]
+
+
+def is_valid_context(context):
+ obj = context.object
+
+ # only edit mode is allowed to execute
+ if obj is None:
+ return False
+ if obj.type != 'MESH':
+ return False
+ if context.object.mode != 'EDIT':
+ return False
+
+ # only 'VIEW_3D' space is allowed to execute
+ for space in context.area.spaces:
+ if space.type == 'VIEW_3D':
+ break
+ else:
+ return False
+
+ return True
+
+
+class Properties:
+ @classmethod
+ def init_props(cls, scene):
+ scene.muv_move_uv_enabled = BoolProperty(
+ name="Move UV Enabled",
+ description="Move UV is enabled",
+ default=False
+ )
+
+ @classmethod
+ def del_props(cls, scene):
+ del scene.muv_move_uv_enabled
+
+
+class Operator(bpy.types.Operator):
"""
- Operator class: Move UV from View3D
+ Operator class: Move UV
"""
- bl_idname = "view3d.muv_mvuv"
- bl_label = "Move the UV from View3D"
+ bl_idname = "uv.muv_move_uv_operator"
+ bl_label = "Move UV"
bl_options = {'REGISTER', 'UNDO'}
+ __running = False
+
def __init__(self):
self.__topology_dict = []
self.__prev_mouse = Vector((0.0, 0.0))
@@ -44,7 +89,20 @@ class MUV_MVUV(bpy.types.Operator):
self.__prev_offset_uv = Vector((0.0, 0.0))
self.__first_time = True
self.__ini_uvs = []
- self.__running = False
+ self.__operating = False
+
+ @classmethod
+ def poll(cls, context):
+ # we can not get area/space/region from console
+ if common.is_console_mode():
+ return False
+ if cls.is_running(context):
+ return False
+ return is_valid_context(context)
+
+ @classmethod
+ def is_running(cls, _):
+ return cls.__running
def __find_uv(self, context):
bm = bmesh.from_edit_mesh(context.object.data)
@@ -59,12 +117,7 @@ class MUV_MVUV(bpy.types.Operator):
return topology_dict, uvs
- @classmethod
- def poll(cls, context):
- return context.edit_object
-
def modal(self, context, event):
- props = context.scene.muv_props.mvuv
if self.__first_time is True:
self.__prev_mouse = Vector((
event.mouse_region_x, event.mouse_region_y))
@@ -85,9 +138,9 @@ class MUV_MVUV(bpy.types.Operator):
event.mouse_region_x, event.mouse_region_y))
# check if operation is started
- if self.__running:
+ if not self.__operating:
if event.type == 'LEFTMOUSE' and event.value == 'RELEASE':
- self.__running = False
+ self.__operating = True
return {'RUNNING_MODAL'}
# update UV
@@ -111,20 +164,24 @@ class MUV_MVUV(bpy.types.Operator):
if event.type == cancel_btn and event.value == 'PRESS':
for (fidx, vidx), uv in zip(self.__topology_dict, self.__ini_uvs):
bm.faces[fidx].loops[vidx][active_uv].uv = uv
- props.running = False
+ Operator.__running = False
return {'FINISHED'}
# confirmed
if event.type == confirm_btn and event.value == 'PRESS':
- props.running = False
+ Operator.__running = False
return {'FINISHED'}
return {'RUNNING_MODAL'}
def execute(self, context):
- props = context.scene.muv_props.mvuv
- props.running = True
- self.__running = True
+ Operator.__running = True
+ self.__operating = False
self.__first_time = True
+
context.window_manager.modal_handler_add(self)
self.__topology_dict, self.__ini_uvs = self.__find_uv(context)
+
+ if context.area:
+ context.area.tag_redraw()
+
return {'RUNNING_MODAL'}