Skip to content

Commit eecafa6

Browse files
Merge pull request #32 from SpectralVectors/actions/black
Format Python code with psf/black push
2 parents 70170de + a2fb448 commit eecafa6

File tree

3 files changed

+85
-98
lines changed

3 files changed

+85
-98
lines changed

Preferences.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@
99
def update_node_keymap(self, context):
1010
wm = context.window_manager
1111
active_kc = wm.keyconfigs.active
12-
for key in active_kc.keymaps['Node Editor'].keymap_items:
13-
if (
14-
key.idname == "wm.call_menu"
15-
and key.type == "RIGHTMOUSE"
16-
):
12+
for key in active_kc.keymaps["Node Editor"].keymap_items:
13+
if key.idname == "wm.call_menu" and key.type == "RIGHTMOUSE":
1714
key.active = not key.active
1815

1916
addon_kc = wm.keyconfigs.addon
20-
for key in addon_kc.keymaps['Node Editor'].keymap_items:
21-
if (
22-
key.idname == "rmn.right_mouse_navigation"
23-
and key.type == "RIGHTMOUSE"
24-
):
17+
for key in addon_kc.keymaps["Node Editor"].keymap_items:
18+
if key.idname == "rmn.right_mouse_navigation" and key.type == "RIGHTMOUSE":
2519
key.active = not key.active
2620

2721

@@ -54,13 +48,13 @@ def draw(self, context):
5448
layout = self.layout
5549

5650
box = layout.box()
57-
box.label(text="Menu / Movement", icon='DRIVER_DISTANCE')
58-
box.prop(self, 'time')
51+
box.label(text="Menu / Movement", icon="DRIVER_DISTANCE")
52+
box.prop(self, "time")
5953

6054
row = layout.row()
6155
box = row.box()
62-
box.label(text="Cursor", icon='ORIENTATION_CURSOR')
63-
box.prop(self, 'reset_cursor_on_exit')
56+
box.label(text="Cursor", icon="ORIENTATION_CURSOR")
57+
box.prop(self, "reset_cursor_on_exit")
6458
box = row.box()
65-
box.label(text='Node Editor', icon='NODETREE')
66-
box.prop(self, 'enable_for_node_editors')
59+
box.label(text="Node Editor", icon="NODETREE")
60+
box.prop(self, "enable_for_node_editors")

RightMouseNavigation.py

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
class RMN_OT_right_mouse_navigation(Operator):
66
"""Timer that decides whether to display a menu after Right Click"""
7+
78
bl_idname = "rmn.right_mouse_navigation"
89
bl_label = "Right Mouse Navigation"
9-
bl_options = {'REGISTER', 'UNDO'}
10+
bl_options = {"REGISTER", "UNDO"}
1011

1112
_timer = None
1213
_count = 0
@@ -16,30 +17,29 @@ class RMN_OT_right_mouse_navigation(Operator):
1617
_ortho = False
1718
_back_to_ortho = False
1819
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",
3233
}
3334

3435
def modal(self, context, event):
35-
3636
preferences = context.preferences
3737
addon_prefs = preferences.addons[__package__].preferences
3838
enable_nodes = addon_prefs.enable_for_node_editors
3939

4040
space_type = context.space_data.type
4141

42-
if space_type == 'VIEW_3D':
42+
if space_type == "VIEW_3D":
4343
# Check if the Viewport is Perspective or Orthographic
4444
if bpy.context.region_data.is_perspective:
4545
self._ortho = False
@@ -61,7 +61,7 @@ def reset_cursor():
6161

6262
if self._callMenu:
6363
# 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":
6565
reset_cursor()
6666
self.callMenu(context)
6767
else:
@@ -72,11 +72,11 @@ def reset_cursor():
7272
if self._back_to_ortho:
7373
bpy.ops.view3d.view_persportho()
7474

75-
return {'CANCELLED'}
75+
return {"CANCELLED"}
7676

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"}:
8080
# This brings back our mouse cursor to use with the menu
8181
context.window.cursor_modal_restore()
8282
# If the length of time you've been holding down
@@ -87,33 +87,38 @@ def reset_cursor():
8787
self.cancel(context)
8888
# We now set the flag to true to exit the modal operator on the next loop
8989
self._finished = True
90-
return {'PASS_THROUGH'}
90+
return {"PASS_THROUGH"}
9191

92-
if event.type == 'TIMER':
92+
if event.type == "TIMER":
9393
if self._count <= addon_prefs.time:
9494
self._count += 0.1
95-
return {'PASS_THROUGH'}
95+
return {"PASS_THROUGH"}
9696

9797
def callMenu(self, context):
9898
select_mouse = context.window_manager.keyconfigs.active.preferences.select_mouse
9999
space_type = context.space_data.type
100100

101-
if select_mouse == 'LEFT':
102-
if space_type == 'NODE_EDITOR':
101+
if select_mouse == "LEFT":
102+
if space_type == "NODE_EDITOR":
103103
node_tree = context.space_data.node_tree
104104
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")
107110
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+
)
109114
else:
110115
try:
111116
bpy.ops.wm.call_menu(name=self.menu_by_mode[context.mode])
112117
except RuntimeError:
113118
bpy.ops.wm.call_panel(name=self.menu_by_mode[context.mode])
114119
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")
117122

118123
def invoke(self, context, event):
119124
# Store Blender cursor position
@@ -130,25 +135,25 @@ def execute(self, context):
130135

131136
# Execute is the first thing called in our operator, so we start by
132137
# 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")
135140
# Adding the timer and starting the loop
136141
wm = context.window_manager
137142
self._timer = wm.event_timer_add(0.1, window=context.window)
138143
wm.modal_handler_add(self)
139-
return {'RUNNING_MODAL'}
144+
return {"RUNNING_MODAL"}
140145

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")
143148
wm = context.window_manager
144149
# Adding the timer and starting the loop
145150
self._timer = wm.event_timer_add(0.01, window=context.window)
146151
wm.modal_handler_add(self)
147-
return {'RUNNING_MODAL'}
152+
return {"RUNNING_MODAL"}
148153

149-
elif space_type == 'IMAGE_EDITOR':
154+
elif space_type == "IMAGE_EDITOR":
150155
bpy.ops.wm.call_panel(name="VIEW3D_PT_paint_texture_context_menu")
151-
return {'FINISHED'}
156+
return {"FINISHED"}
152157

153158
def cancel(self, context):
154159
wm = context.window_manager

__init__.py

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ def register():
1313
wm = bpy.context.window_manager
1414
addon_kc = wm.keyconfigs.addon
1515

16-
km = addon_kc.keymaps.new(name='3D View', space_type='VIEW_3D')
17-
kmi = km.keymap_items.new(
18-
"rmn.right_mouse_navigation",
19-
'RIGHTMOUSE',
20-
'PRESS'
21-
)
16+
km = addon_kc.keymaps.new(name="3D View", space_type="VIEW_3D")
17+
kmi = km.keymap_items.new("rmn.right_mouse_navigation", "RIGHTMOUSE", "PRESS")
2218
kmi.active = True
2319

24-
km2 = addon_kc.keymaps.new(name='Node Editor', space_type='NODE_EDITOR')
25-
kmi2 = km2.keymap_items.new(
26-
"rmn.right_mouse_navigation",
27-
'RIGHTMOUSE',
28-
'PRESS'
29-
)
20+
km2 = addon_kc.keymaps.new(name="Node Editor", space_type="NODE_EDITOR")
21+
kmi2 = km2.keymap_items.new("rmn.right_mouse_navigation", "RIGHTMOUSE", "PRESS")
3022
kmi2.active = False
3123

3224
addon_keymaps.append((km, kmi, km2, kmi2))
3325

3426
active_kc = wm.keyconfigs.active
3527

36-
menumodes = ["Object Mode", "Mesh", "Curve",
37-
"Armature", "Metaball", "Lattice", "Font", "Pose"]
28+
menumodes = [
29+
"Object Mode",
30+
"Mesh",
31+
"Curve",
32+
"Armature",
33+
"Metaball",
34+
"Lattice",
35+
"Font",
36+
"Pose",
37+
]
3838
panelmodes = ["Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"]
3939

4040
# These Modes all call standard menus
@@ -62,69 +62,57 @@ def register():
6262

6363
# Changing the Walk Modal Map
6464
for key in active_kc.keymaps["View3D Walk Modal"].keymap_items:
65-
if (
66-
key.propvalue == "CANCEL"
67-
and key.type == "RIGHTMOUSE"
68-
and key.active
69-
):
65+
if key.propvalue == "CANCEL" and key.type == "RIGHTMOUSE" and key.active:
7066
key.active = False
7167
for key in active_kc.keymaps["View3D Walk Modal"].keymap_items:
72-
if (
73-
key.propvalue == "CONFIRM"
74-
and key.type == "LEFTMOUSE"
75-
and key.active
76-
):
68+
if key.propvalue == "CONFIRM" and key.type == "LEFTMOUSE" and key.active:
7769
key.type = "RIGHTMOUSE"
7870
key.value = "RELEASE"
7971

8072

8173
def unregister():
8274
if not bpy.app.background:
83-
8475
bpy.utils.unregister_class(RMN_OT_right_mouse_navigation)
8576
bpy.utils.unregister_class(RightMouseNavigationPreferences)
8677

8778
wm = bpy.context.window_manager
8879
active_kc = wm.keyconfigs.active
8980
addon_kc = wm.keyconfigs.addon
9081

91-
menumodes = ["Object Mode", "Mesh", "Curve", "Armature",
92-
"Metaball", "Lattice", "Font", "Pose", "Node Editor"]
82+
menumodes = [
83+
"Object Mode",
84+
"Mesh",
85+
"Curve",
86+
"Armature",
87+
"Metaball",
88+
"Lattice",
89+
"Font",
90+
"Pose",
91+
"Node Editor",
92+
]
9393
panelmodes = ["Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"]
9494

9595
# Reactivating menus
9696
# "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",
9797
# "Font", "Pose"
9898
for i in menumodes:
9999
for key in active_kc.keymaps[i].keymap_items:
100-
if (
101-
key.idname == "wm.call_menu"
102-
and key.type == "RIGHTMOUSE"
103-
):
100+
if key.idname == "wm.call_menu" and key.type == "RIGHTMOUSE":
104101
key.active = True
105102

106103
# Reactivating panels
107104
# "Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"
108105
for i in panelmodes:
109106
for key in active_kc.keymaps[i].keymap_items:
110-
if (
111-
key.idname == "wm.call_panel"
112-
and key.type == "RIGHTMOUSE"
113-
):
107+
if key.idname == "wm.call_panel" and key.type == "RIGHTMOUSE":
114108
key.active = True
115109

116110
# Changing the Walk Modal Map back
117111
for key in active_kc.keymaps["View3D Walk Modal"].keymap_items:
118-
if (
119-
key.propvalue == "CANCEL"
120-
and key.type == "RIGHTMOUSE"
121-
):
112+
if key.propvalue == "CANCEL" and key.type == "RIGHTMOUSE":
122113
key.active = True
123114
for key in active_kc.keymaps["View3D Walk Modal"].keymap_items:
124-
if (
125-
key.propvalue == "CONFIRM"
126-
and key.type == "RIGHTMOUSE"
127-
):
115+
if key.propvalue == "CONFIRM" and key.type == "RIGHTMOUSE":
128116
key.type = "LEFTMOUSE"
129117
key.value = "PRESS"
130118

0 commit comments

Comments
 (0)