Skip to content

Commit

Permalink
- Fix for restoring default Workspace Object Interaction Modes
Browse files Browse the repository at this point in the history
  • Loading branch information
schroef committed Dec 26, 2018
1 parent 45f9f43 commit c2564dd
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 22 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
All notable changes to this project will be documented in this file.
# Changelog

## [0.0.6] - 2018-12-26
### Changed
- Fix for returning to default Workspace Object Interaction Modes

## [0.0.5] - 2018-12-25
### Added
- Keep Mode stores last Object Interaction Mode and falls back to this instead of Default Workspace Object Interaction Mode


## [0.0.4] - 2018-12-23
### Changed
- Quick render now visible in all screens
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ QuickSwitch a helper to quick switch workspaces and view render menu in viewport

> Some limitations are currently present due to Beta containing some bugs
!['Look UI'](https://raw.githubusercontent.com/wiki/schroef/quickswitch/images/quickswitch_v0.0.5.jpg?v25-12-2018)
!['Look UI'](https://raw.githubusercontent.com/wiki/schroef/quickswitch/images/quickswitch_v006.jpg?v26-12-2018)

> Choose either Pie menu or WM menu
!['Example Addon Prefs'](https://raw.githubusercontent.com/wiki/schroef/quickswitch/images/addon-preferences_v005.jpg?v25-12-2018)
!['Example Addon Prefs'](https://raw.githubusercontent.com/wiki/schroef/quickswitch/images/addon-preferences_v006.jpg)

> Customise shortscuts from addon preferences
Expand Down
125 changes: 106 additions & 19 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
## Added
## 25-12-18 - Keep Mode stores last Object Interaction Mode and falls back to this instead of Default Workspace Object Interaction Mode

## v.0.0.6
## Changed
## 26-12-18 - Fixed basic Workspace modes, using PropertyGroup & PointerProperty to store defaults



#######################################################

Expand All @@ -71,7 +76,7 @@
"description": "QuickSwitch is a little helper to make it easier to switch render engines & workspaces",
"location": "3D VIEW > Quick Switch",
"author": "Rombout Versluijs",
"version": (0, 0, 4),
"version": (0, 0, 6),
"blender": (2, 80, 0),
"wiki_url": "https://github.com/schroef/quickswitch",
"tracker_url": "https://github.com/schroef/quickswitch/issues",
Expand All @@ -81,15 +86,17 @@
import bpy
import rna_keymap_ui
from bl_operators.presets import AddPresetBase, PresetMenu
from bpy.app.handlers import persistent
#from . import AddPresetBase

from bpy.types import (
Panel, WindowManager, AddonPreferences, Menu, Operator, Scene
Panel, WindowManager, AddonPreferences, Menu, Operator, Scene, PropertyGroup
)
from bpy.props import (
EnumProperty, StringProperty, BoolProperty, IntProperty, FloatProperty
EnumProperty, StringProperty, BoolProperty, IntProperty, PointerProperty
)


def avail_workspaces(self,context):
'''
enumerates available Workspaces and adding more items:
Expand All @@ -109,21 +116,86 @@ def avail_workspaces(self,context):
addon_keymaps = []


def defaultWSSmodes(self,context):
'''
Stores all default Object Modes when switching Workspaces
Used to set them back to default if "Keep Mode" is OFF
'''

ws = bpy.data.workspaces
wsModes =[("None","None","None")]
for ws in bpy.data.workspaces:
wsM = ws.object_mode
wsModes.append((ws.name, wsM, ws.name))
return wsModes

#def defaultWSSmodes(self, context):
# '''
# Stores all default Object Modes when switching Workspaces
# Used to set them back to default if "Keep Mode" is OFF
# '''
#
# #ws = bpy.data.workspaces
# wsModes = []
# i = 0
# for ws in bpy.data.workspaces:
# wsM = ws.object_mode
# wsModes.append((str(i), wsM, ws.name))
# i+=1
# return wsModes

class QS_defaultWSSmodes(PropertyGroup):
Animation : StringProperty(
name = "Animation",
default='POSE')
Compositing : StringProperty(
name = "Compositing",
default='OBJECT')
Layout : StringProperty(
name = "Layout",
default='OBJECT')
Modeling : StringProperty(
name = "Modeling",
default='EDIT')
Rendering : StringProperty(
name = "Rendering",
default='OBJECT')
Scripting : StringProperty(
name = "Scripting",
default='OBJECT')
Sculpting : StringProperty(
name = "Sculpting",
default='SCULPT')
Shading : StringProperty(
name = "Shading",
default='OBJECT')
Texture_Paint : StringProperty(
name = "Texture_Paint",
default='TEXTURE_PAINT')
UV_Editing : StringProperty(
name = "UV_Editing",
default='EDIT')

@persistent
def on_scene_update(scene):
context = bpy.context
scene = context.scene
ws = context.workspace
settings = scene.qsWSsmode

settings.Animation = 'POSE'
settings.Compositing = 'OBJECT'
settings.Layout = 'OBJECT'
settings.Modeling = bpy.data.workspaces['Modeling'].object_mode
settings.Rendering = 'OBJECT'
settings.Scripting = 'OBJECT'
settings.Sculpting = 'SCULPT'
settings.Shading = 'OBJECT'
settings.Texture_Paint = 'TEXTURE_PAINT'
settings.UV_Editing = 'EDIT'

#class SetWSmodes(Operator):
# bl_idname = "qs.set_ws_modes"
# bl_label = "Set"
# bl_description = "Saves standard workspace modes"
#
# #@classmethod
# #def poll(clss, context):
# # return ats_poll(context)
#
# def execute(self, context):
# if do_set_tile_size(context):
# return {'FINISHED'}
# return {'CANCELLED'}

bpy.types.Scene.qsDefWSmodes = bpy.props.EnumProperty(name = "Def WorkSpace Modes", items=defaultWSSmodes)
#bpy.types.Scene.qsDefWSmodes = bpy.props.EnumProperty(name = "Def WorkSpace Modes", items=defaultWSSmodes)

bpy.types.Scene.qsKeepMode = bpy.props.BoolProperty(name = "Keep Mode", default=False, description="This stores the current Object Interaction Mode, now when you switch workspaces you will return to prior mode and not the default one.")

Expand Down Expand Up @@ -354,8 +426,13 @@ def execute(self,context):
ws.object_mode=obj.mode
break
else:
if ws.name == scene.qsDefWSmodes:
ws.object_mode = scene.qsDefWSmodes[item][1]
wsN = ws.name
if wsN == 'UV Editing':
wsN = 'UV_Editing'
if wsN == 'Texture Painting':
wsN = 'UV_Painting'

ws.object_mode = scene.qsWSsmode[wsN]
try:
bpy.context.window.workspace = bpy.data.workspaces[self.wslayoutMenu]
return{'FINISHED'}
Expand All @@ -382,6 +459,7 @@ def draw(self, context):
ws = context.workspace
col = layout.column()

#layout.prop(scene, "qsDefWSmodes")
col.label(text='Hotkeys:')
col.label(text='Do NOT remove hotkeys, disable them instead!')

Expand Down Expand Up @@ -450,6 +528,7 @@ def draw(self, context):

#Classes for register and unregister
classes = (
QS_defaultWSSmodes,
AddPresetQuickSwitch,
QS_PT_presets,
QS_OT_QuickSwitchEngine,
Expand All @@ -463,12 +542,18 @@ def register():
for cls in classes:
bpy.utils.register_class(cls)

bpy.types.Scene.qsWSsmode = PointerProperty(type=QS_defaultWSSmodes)

# hotkey setup
add_hotkey()

bpy.app.handlers.depsgraph_update_pre.append(on_scene_update)



def unregister():
bpy.app.handlers.depsgraph_update_pre.remove(on_scene_update)

# handle the keymap
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
Expand All @@ -477,6 +562,8 @@ def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)

del bpy.types.Scene.qsWSsmode


if __name__ == "__main__":
register()

0 comments on commit c2564dd

Please sign in to comment.