4
4
5
5
class RMN_OT_right_mouse_navigation (Operator ):
6
6
"""Timer that decides whether to display a menu after Right Click"""
7
+
7
8
bl_idname = "rmn.right_mouse_navigation"
8
9
bl_label = "Right Mouse Navigation"
9
- bl_options = {' REGISTER' , ' UNDO' }
10
+ bl_options = {" REGISTER" , " UNDO" }
10
11
11
12
_timer = None
12
13
_count = 0
@@ -16,30 +17,29 @@ class RMN_OT_right_mouse_navigation(Operator):
16
17
_ortho = False
17
18
_back_to_ortho = False
18
19
menu_by_mode = {
19
- ' OBJECT' : ' VIEW3D_MT_object_context_menu' ,
20
- ' EDIT_MESH' : ' VIEW3D_MT_edit_mesh_context_menu' ,
21
- ' EDIT_SURFACE' : ' VIEW3D_MT_edit_surface' ,
22
- ' EDIT_TEXT' : ' VIEW3D_MT_edit_font_context_menu' ,
23
- ' EDIT_ARMATURE' : ' VIEW3D_MT_edit_armature' ,
24
- ' EDIT_CURVE' : ' VIEW3D_MT_edit_curve_context_menu' ,
25
- ' EDIT_METABALL' : ' VIEW3D_MT_edit_metaball_context_menu' ,
26
- ' EDIT_LATTICE' : ' VIEW3D_MT_edit_lattice_context_menu' ,
27
- ' POSE' : ' VIEW3D_MT_pose_context_menu' ,
28
- ' PAINT_VERTEX' : ' VIEW3D_PT_paint_vertex_context_menu' ,
29
- ' PAINT_WEIGHT' : ' VIEW3D_PT_paint_weight_context_menu' ,
30
- ' PAINT_TEXTURE' : ' VIEW3D_PT_paint_texture_context_menu' ,
31
- ' SCULPT' : ' VIEW3D_PT_sculpt_context_menu' ,
20
+ " OBJECT" : " VIEW3D_MT_object_context_menu" ,
21
+ " EDIT_MESH" : " VIEW3D_MT_edit_mesh_context_menu" ,
22
+ " EDIT_SURFACE" : " VIEW3D_MT_edit_surface" ,
23
+ " EDIT_TEXT" : " VIEW3D_MT_edit_font_context_menu" ,
24
+ " EDIT_ARMATURE" : " VIEW3D_MT_edit_armature" ,
25
+ " EDIT_CURVE" : " VIEW3D_MT_edit_curve_context_menu" ,
26
+ " EDIT_METABALL" : " VIEW3D_MT_edit_metaball_context_menu" ,
27
+ " EDIT_LATTICE" : " VIEW3D_MT_edit_lattice_context_menu" ,
28
+ " POSE" : " VIEW3D_MT_pose_context_menu" ,
29
+ " PAINT_VERTEX" : " VIEW3D_PT_paint_vertex_context_menu" ,
30
+ " PAINT_WEIGHT" : " VIEW3D_PT_paint_weight_context_menu" ,
31
+ " PAINT_TEXTURE" : " VIEW3D_PT_paint_texture_context_menu" ,
32
+ " SCULPT" : " VIEW3D_PT_sculpt_context_menu" ,
32
33
}
33
34
34
35
def modal (self , context , event ):
35
-
36
36
preferences = context .preferences
37
37
addon_prefs = preferences .addons [__package__ ].preferences
38
38
enable_nodes = addon_prefs .enable_for_node_editors
39
39
40
40
space_type = context .space_data .type
41
41
42
- if space_type == ' VIEW_3D' :
42
+ if space_type == " VIEW_3D" :
43
43
# Check if the Viewport is Perspective or Orthographic
44
44
if bpy .context .region_data .is_perspective :
45
45
self ._ortho = False
@@ -61,7 +61,7 @@ def reset_cursor():
61
61
62
62
if self ._callMenu :
63
63
# Always reset the cursor if menu is called, as that implies a canceled navigation
64
- if addon_prefs .reset_cursor_on_exit and not space_type == ' NODE_EDITOR' :
64
+ if addon_prefs .reset_cursor_on_exit and not space_type == " NODE_EDITOR" :
65
65
reset_cursor ()
66
66
self .callMenu (context )
67
67
else :
@@ -72,11 +72,11 @@ def reset_cursor():
72
72
if self ._back_to_ortho :
73
73
bpy .ops .view3d .view_persportho ()
74
74
75
- return {' CANCELLED' }
75
+ return {" CANCELLED" }
76
76
77
- if space_type == ' VIEW_3D' or space_type == ' NODE_EDITOR' and enable_nodes :
78
- if event .type in {' RIGHTMOUSE' }:
79
- if event .value in {' RELEASE' }:
77
+ if space_type == " VIEW_3D" or space_type == " NODE_EDITOR" and enable_nodes :
78
+ if event .type in {" RIGHTMOUSE" }:
79
+ if event .value in {" RELEASE" }:
80
80
# This brings back our mouse cursor to use with the menu
81
81
context .window .cursor_modal_restore ()
82
82
# If the length of time you've been holding down
@@ -87,33 +87,38 @@ def reset_cursor():
87
87
self .cancel (context )
88
88
# We now set the flag to true to exit the modal operator on the next loop
89
89
self ._finished = True
90
- return {' PASS_THROUGH' }
90
+ return {" PASS_THROUGH" }
91
91
92
- if event .type == ' TIMER' :
92
+ if event .type == " TIMER" :
93
93
if self ._count <= addon_prefs .time :
94
94
self ._count += 0.1
95
- return {' PASS_THROUGH' }
95
+ return {" PASS_THROUGH" }
96
96
97
97
def callMenu (self , context ):
98
98
select_mouse = context .window_manager .keyconfigs .active .preferences .select_mouse
99
99
space_type = context .space_data .type
100
100
101
- if select_mouse == ' LEFT' :
102
- if space_type == ' NODE_EDITOR' :
101
+ if select_mouse == " LEFT" :
102
+ if space_type == " NODE_EDITOR" :
103
103
node_tree = context .space_data .node_tree
104
104
if node_tree :
105
- if node_tree .nodes .active is not None and node_tree .nodes .active .select :
106
- bpy .ops .wm .call_menu (name = 'NODE_MT_context_menu' )
105
+ if (
106
+ node_tree .nodes .active is not None
107
+ and node_tree .nodes .active .select
108
+ ):
109
+ bpy .ops .wm .call_menu (name = "NODE_MT_context_menu" )
107
110
else :
108
- bpy .ops .wm .search_single_menu ('INVOKE_DEFAULT' , menu_idname = 'NODE_MT_add' )
111
+ bpy .ops .wm .search_single_menu (
112
+ "INVOKE_DEFAULT" , menu_idname = "NODE_MT_add"
113
+ )
109
114
else :
110
115
try :
111
116
bpy .ops .wm .call_menu (name = self .menu_by_mode [context .mode ])
112
117
except RuntimeError :
113
118
bpy .ops .wm .call_panel (name = self .menu_by_mode [context .mode ])
114
119
else :
115
- if space_type == ' VIEW_3D' :
116
- bpy .ops .view3d .select (' INVOKE_DEFAULT' )
120
+ if space_type == " VIEW_3D" :
121
+ bpy .ops .view3d .select (" INVOKE_DEFAULT" )
117
122
118
123
def invoke (self , context , event ):
119
124
# Store Blender cursor position
@@ -130,25 +135,25 @@ def execute(self, context):
130
135
131
136
# Execute is the first thing called in our operator, so we start by
132
137
# calling Blender's built-in Walk Navigation
133
- if space_type == ' VIEW_3D' :
134
- bpy .ops .view3d .walk (' INVOKE_DEFAULT' )
138
+ if space_type == " VIEW_3D" :
139
+ bpy .ops .view3d .walk (" INVOKE_DEFAULT" )
135
140
# Adding the timer and starting the loop
136
141
wm = context .window_manager
137
142
self ._timer = wm .event_timer_add (0.1 , window = context .window )
138
143
wm .modal_handler_add (self )
139
- return {' RUNNING_MODAL' }
144
+ return {" RUNNING_MODAL" }
140
145
141
- elif space_type == ' NODE_EDITOR' and enable_nodes :
142
- bpy .ops .view2d .pan (' INVOKE_DEFAULT' )
146
+ elif space_type == " NODE_EDITOR" and enable_nodes :
147
+ bpy .ops .view2d .pan (" INVOKE_DEFAULT" )
143
148
wm = context .window_manager
144
149
# Adding the timer and starting the loop
145
150
self ._timer = wm .event_timer_add (0.01 , window = context .window )
146
151
wm .modal_handler_add (self )
147
- return {' RUNNING_MODAL' }
152
+ return {" RUNNING_MODAL" }
148
153
149
- elif space_type == ' IMAGE_EDITOR' :
154
+ elif space_type == " IMAGE_EDITOR" :
150
155
bpy .ops .wm .call_panel (name = "VIEW3D_PT_paint_texture_context_menu" )
151
- return {' FINISHED' }
156
+ return {" FINISHED" }
152
157
153
158
def cancel (self , context ):
154
159
wm = context .window_manager
0 commit comments