Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Refactor WalkHandler Drag to work on 3 tickers #35

Open
wants to merge 1 commit into
base: dev-3.0.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 61 additions & 18 deletions addon/operators/walkhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@

from bpy.types import (
Context,
Event,
Operator,
PropertyGroup,
Region,
Scene,
bpy_prop_collection,
)
Expand Down Expand Up @@ -73,19 +75,12 @@ def call_WalkHandler(_: Scene) -> None:

class BM_OT_WalkHandler(Operator):
bl_idname = 'bakemaster.walkhandler'
bl_label = "BakeMaster Walk Handler"
bl_description = "User Interface Walk Handler for operating Drag, Drop, Multi Selection" # noqa: E501
bl_label = "BakeMaster WalkHandler"
bl_description = "UI WalkHandler for operating Drag, Drop, and Multi Selection" # noqa: E501
bl_options = {'INTERNAL'}

_handler = None

def cancel(self, _: Context) -> None:
cls = self.__class__
cls._handler = None

global _is_wh_invoked
_is_wh_invoked = False

def handler_poll(self) -> bool:
cls = self.__class__
if cls._handler is not None:
Expand All @@ -95,6 +90,14 @@ def handler_poll(self) -> bool:
global _is_wh_invoked
return not _is_wh_invoked

def cancel(self, _: Context) -> None:
cls = self.__class__
cls._handler = None

global _is_wh_invoked
_is_wh_invoked = False

# TODO: replace with j bakemaster.get_active_... call?
def get_containers(self, bakemaster: PropertyGroup
) -> typing.Union[None, typing.Tuple[
PropertyGroup, bpy_prop_collection, str]]:
Expand All @@ -108,6 +111,7 @@ def get_containers(self, bakemaster: PropertyGroup
return None
return data, containers, attr

# TODO: cleanup
def reset_props(self, bakemaster: PropertyGroup) -> None:
self.is_dropping = False
self.is_dragging = False
Expand Down Expand Up @@ -141,14 +145,13 @@ def reset_props(self, bakemaster: PropertyGroup) -> None:
bakemaster.is_double_click = False
bakemaster.last_left_click_ticker = False

def is_cursor_in_region(self, region, event):
# area as region is acceptable
if all([region.x <= event.mouse_x <= region.x + region.width,
region.y <= event.mouse_y <= region.y + region.height]):
return True
else:
return False
# TODO: used?
def is_cursor_in_region(self, region: Region, event: Event) -> bool:

return all([region.x <= event.mouse_x <= region.x + region.width,
region.y <= event.mouse_y <= region.y + region.height])

# TODO: used?
def get_uiarea_of_type(self, screen: not None, area_type: str):
for area in screen.areas:
if area is None:
Expand Down Expand Up @@ -468,7 +471,7 @@ def drag(self, bakemaster):

self.drag_end(bakemaster)

def modal(self, context, event):
def modal(self, context: Context, event: Event) -> set:
if 'TIMER' in event.type:
return {'PASS_THROUGH'}

Expand All @@ -478,8 +481,10 @@ def modal(self, context, event):
if not bakemaster.allow_drag and self.is_dragging:
self.is_dragging = False

# TODO: eval from prop_updates only, just check here
self.set_last_left_click_ticker(bakemaster)

# TODO: rename query_events_end -> dp_wait_end
if self.query_events_end:
self.remove_drop_prompts(bakemaster)
self.query_events_end = False
Expand Down Expand Up @@ -515,12 +520,13 @@ def modal(self, context, event):
self.events_end(bakemaster)
return {'PASS_THROUGH'}

# TODO: rename wait_events_end -> events_wait_end
self.wait_events_end = True
if not bakemaster.allow_drag:
self.is_dropping = True
return {'PASS_THROUGH'}

def invoke(self, context, _):
def invoke(self, context: Context, _: Event) -> set:
if not self.handler_poll():
return {'CANCELLED'}

Expand All @@ -532,10 +538,47 @@ def invoke(self, context, _):

wm = context.window_manager
wm.modal_handler_add(self)

self.reset_props(context.scene.bakemaster)
return {'RUNNING_MODAL'}






































class BM_OT_Global_WalkData_AddDropped(Operator):
"""
Add dropped objects to given walk_data data.
Expand Down