diff --git a/blender_manifest.toml b/blender_manifest.toml index 6a53e02..dd2654d 100644 --- a/blender_manifest.toml +++ b/blender_manifest.toml @@ -25,6 +25,7 @@ files = "preserve settings when enabling/disabling the add-on" paths_exclude_pattern = [ "__pycache__/", "/.git/", + "/.github/", "docs/", ".gitignore", "/*.zip", @@ -34,4 +35,6 @@ paths_exclude_pattern = [ "mypy.ini", "requirements.txt", "README.md", + ".flake8", + "ruff.toml", ] diff --git a/preferences.py b/preferences.py index d627579..3046089 100644 --- a/preferences.py +++ b/preferences.py @@ -141,12 +141,6 @@ class TOUCHVIEW_AP_OverlaySettings(AddonPreferences): default=True, ) - double_click_mode: EnumProperty( - name="Double Click Mode", - items=double_click_items, - default="screen.screen_full_area", - ) - enable_right_click: BoolProperty( name="Enable Right Click", default=True, @@ -470,7 +464,7 @@ def from_dict(self, data: dict): self.isVisible = data.get("is_visible", False) self.input_mode = data.get("input_mode", "FULL") self.enable_double_click = data.get("enable_double_click", True) - self.double_click_mode = data.get("double_click_mode", "screen.screen_full_area") + self.double_click_mode = data.get("double_click_mode", "wm.window_fullscreen_toggle") self.enable_right_click = data.get("enable_right_click", True) self.right_click_mode = data.get("right_click_mode", "wm.window_fullscreen_toggle") self.right_click_source = data.get("right_click_source", "MOUSE") @@ -506,7 +500,6 @@ def from_dict(self, data: dict): self.topology_mode = data.get("topology_mode", "MANUAL") self.show_float_menu = data.get("show_float_menu", False) self.floating_position = data.get("floating_position", (100, 0)) - self.double_click_mode = data.get("double_click_mode", "wm.window_fullscreen_toggle") self.active_menu = data.get("active_menu", "VIEW3D") self.gizmo_tabs = data.get("gizmo_tabs", "GIZMO") self.menu_sets = [TOUCHVIEW_PG_MenuModeGroup().from_dict(m) for m in data.get("menu_sets", [])] @@ -529,9 +522,6 @@ def save(self): with open(filename, "w") as file: json.dump(self.to_dict(), file) - def draw_v4(self, context): - pass - # set up addon preferences UI def draw(self, context): layout = self.layout @@ -645,9 +635,6 @@ def getGizmoSet(self, mode: str | int): return available return available + list(gizmo_sets[mode]) - def getShowLock(self): - return self.show_lock - def getWidth(self): return self.width / 100 diff --git a/source/ui/panel.py b/source/ui/panel.py index c030b47..8fc541b 100644 --- a/source/ui/panel.py +++ b/source/ui/panel.py @@ -15,6 +15,13 @@ class TouchView: class TOUCHVIEW_PT_view_3d_panel(TouchView, Panel): # bl_label = "Touchview Settings" + def draw_header(self, context): + prefs = preferences() + + layout = self.layout + icon = "RADIOBUT_ON" if prefs.is_enabled else "RADIOBUT_OFF" + layout.label(text="", icon=icon) + def draw(self, context): prefs = preferences() diff --git a/source/utils/gizmo_2d.py b/source/utils/gizmo_2d.py deleted file mode 100644 index c01831e..0000000 --- a/source/utils/gizmo_2d.py +++ /dev/null @@ -1,188 +0,0 @@ -import bpy -from mathutils import Matrix, Vector - -from .blender import * -from .gizmo_config import gizmo_colors, toggle_colors - -## -# GizmoSet -# - single-state -# - one icon -# - one action -# - possible toggle by variable state -# -# - 2-state (boolean) -# - 2 icons -# - 2 actions (or 1 action for both icons) -# -## - - -class GizmoSet: - group: bpy.types.GizmoGroup - - def setup(self, group: bpy.types.GizmoGroup, config: dict): - self.visible = True - self.config = config - self.has_dependent = "has_dependent" in config or False - self.group = group - self.scale = config["scale"] if ("scale" in config) else 14 - self.binding = config["binding"] - self.has_attribute_bind = self.binding["attribute"] if "attribute" in self.binding else False - self.primary = self.__buildGizmo(config["command"], config["icon"]) - - def draw_prepare(self): - prefs = preferences() - self.hidden = not prefs.show_gizmos - self.skip_draw = False - self.__updatevisible() - - if self.binding["name"] == "float_menu": - self.primary.hide = not prefs.show_float_menu - if self.binding["name"] in ["menu_controller"]: - self.primary.hide = "float" not in prefs.menu_style or not prefs.show_menu - if self.binding["name"] in [ - "menu_controller", - ]: - self.primary.scale_basis = (36 * prefs.menu_spacing) * prefs.gizmo_scale - self.primary.use_grab_cursor = False - self.primary.show_drag = True - else: - self.primary.scale_basis = 18 * prefs.gizmo_scale - - def move(self, position: Vector): - self.primary.matrix_basis = Matrix.Translation(position) - - def __updatevisible(self): - if not preferences().show_menu and self.binding["name"] not in ["float_menu"]: - self.visible = False - self.primary.hide = True - return - if self.binding["location"] == "prefs": - self.visible = getattr(preferences(), "show_" + self.binding["name"]) and self.binding["name"] in preferences().getGizmoSet( - bpy.context.mode - ) - - if self.visible: - self.visible = self.__visibilityLock() and not self.__checkAttributeBind() - self.primary.hide = not self.visible - - def __visibilityLock(self) -> bool: - if preferences().menu_style == "fixed.bar": - return True - return not self.hidden - - # if an attribute being assigned to active_object should hide/show bpy.types.Gizmo - def __checkAttributeBind(self): - if not self.has_attribute_bind: - return False - bind = self.binding["attribute"] - state = self.__findAttribute(bind["path"], bind["value"]) == bind["state"] - return not state - - # search for attribute, value through context. - # will traverse bpy.types.bpy_prop_collection entries - # by next attr to value comparison - def __findAttribute(self, path: str, value: str): - names = path.split(".") - current = bpy.context - for i, prop in enumerate(names): - current = getattr(current, prop) - if current is None: - return False - - if isinstance(current, bpy.types.bpy_prop_collection): - item = "" - for item in current: - if getattr(item, names[i + 1]) == value: - return True - return False - return getattr(current, value) - - # initialize each gizmo, add them to named list with icon name(s) - def __buildGizmo(self, command: str, icon: str) -> bpy.types.Gizmo: - gizmo = self.group.gizmos.new("GIZMO_GT_button_2d") - gizmo.target_set_operator(command) - gizmo.icon = icon # type: ignore - gizmo.use_tooltip = False # show tooltip - gizmo.use_event_handle_all = True # don't pass events e.g. shift+a to add - gizmo.use_grab_cursor = "use_grab_cursor" in self.config - gizmo.show_drag = False # show default cursor - gizmo.line_width = 5.0 - gizmo.use_draw_modal = True # show gizmo while dragging - gizmo.draw_options = {"BACKDROP", "OUTLINE"} # type: ignore - self.__setColors(gizmo) - gizmo.scale_basis = 0.1 - return gizmo - - def __setColors(self, gizmo: bpy.types.Gizmo): - gizmo.color = gizmo_colors["active"]["color"] - gizmo.color_highlight = gizmo_colors["active"]["color_highlight"] - gizmo.alpha = gizmo_colors["active"]["alpha"] - gizmo.alpha_highlight = gizmo_colors["active"]["alpha_highlight"] - - -class GizmoSetBoolean(GizmoSet): - def setup(self, group: bpy.types.GizmoGroup, config: dict): - self.visible = True - self.config = config - self.has_dependent = "has_dependent" in config or False - self.group = group - self.scale = config["scale"] if ("scale" in config) else 14 - self.binding = config["binding"] - self.has_attribute_bind = self.binding["attribute"] if "attribute" in self.binding else False - self.onGizmo = self._GizmoSet__buildGizmo(config["command"], config["onIcon"]) # type: ignore - self.offGizmo = self._GizmoSet__buildGizmo(config["command"], config["offIcon"]) # type: ignore - self.__setActiveGizmo(True) - - def __setActiveGizmo(self, state: bool): - self.onGizmo.hide = True - self.offGizmo.hide = True - self.primary = self.onGizmo if state else self.offGizmo - - def draw_prepare(self): - prefs = preferences() - self.hidden = not prefs.show_gizmos - self.skip_draw = False - self.__updatevisible() - self.primary.scale_basis = 18 * prefs.gizmo_scale - if self.binding["name"] == "float_toggle": - self.__setToggleColors(self.primary) - - def __updatevisible(self): - prefs = preferences() - bind = self.binding - if not preferences().show_menu and (bind["name"] not in ["float_menu"]): - self.visible = False - self.primary.hide = True - return - if bind["name"] == "float_toggle": - self.visible = prefs.input_mode != "FULL" or prefs.enable_floating_toggle - else: - self.visible = getattr(preferences(), "show_" + self.binding["name"]) - - if self.visible: - self.visible = ( - self._GizmoSet__visibilityLock() # type: ignore - and not self._GizmoSet__checkAttributeBind() # type: ignore - ) # type: ignore - - if bind["name"] == "float_toggle": - self.__setActiveGizmo(prefs.is_enabled) - else: - self.__setActiveGizmo(self._GizmoSet__findAttribute(bind["location"], bind["name"])) # type: ignore - self.primary.hide = not self.visible - - def __setToggleColors(self, gizmo: bpy.types.Gizmo): - mode = "active" if preferences().is_enabled else "inactive" - gizmo.color = toggle_colors[mode]["color"] - gizmo.color_highlight = toggle_colors[mode]["color_highlight"] - gizmo.alpha = toggle_colors[mode]["alpha"] - gizmo.alpha_highlight = toggle_colors[mode]["alpha_highlight"] - - -class GizmoSetEnum(GizmoSet): - gizmos: list[bpy.types.Gizmo] - - def setup(self, group: bpy.types.GizmoGroup, config): - pass diff --git a/source/utils/gizmo_config.py b/source/utils/gizmo_config.py deleted file mode 100644 index 821e2e9..0000000 --- a/source/utils/gizmo_config.py +++ /dev/null @@ -1,270 +0,0 @@ -from ..utils.constants import pivot_icon_items - -### -# Config Standard -# ( TYPE BINDING COMMAND ICON ) -# @TYPE - button type to instance (enum, bool, simple/default) -# @BINDING - used to determine context and visibility -# @COMMAND - operator to call when activated -# @ICON - icon to show on Gizmo -### - -# Simple 2D Gizmo -controllerConfig = { - "type": "default", - "binding": {"location": "", "name": "menu_controller"}, - "command": "touchview.move_float_menu", - "icon": "BLANK1", - "use_grab_cursor": True, -} - -floatingConfig = { - "type": "default", - "binding": {"location": "prefs", "name": "float_menu"}, - "command": "touchview.move_action_menu", - "icon": "SETTINGS", - "use_grab_cursor": True, -} - -floatingToggleConfig = { - "type": "boolean", - "binding": {"location": "", "name": "float_toggle"}, - "command": "touchview.move_toggle_button", - "onIcon": "OUTLINER_DATA_CAMERA", - "offIcon": "GREASEPENCIL", - "use_grab_cursor": True, -} - -undoConfig = { - "type": "default", - "binding": {"location": "prefs", "name": "undoredo"}, - "has_dependent": True, - "command": "ed.undo", - "icon": "LOOP_BACK", -} - -redoConfig = { - "type": "default", - "binding": {"location": "prefs", "name": "undoredo"}, - "command": "ed.redo", - "icon": "LOOP_FORWARDS", -} - -touchViewConfig = { - "type": "default", - "binding": { - "location": "prefs", - "name": "is_enabled", - }, - "command": "touchview.toggle_touch", - "icon": "VIEW_PAN", -} - -controlGizmoConfig = { - "type": "default", - "binding": { - "location": "prefs", - "name": "control_gizmo", - }, - "command": "touchview.cycle_control_gizmo", - "icon": "ORIENTATION_LOCAL", -} - -snapViewConfig = { - "type": "default", - "binding": {"location": "prefs", "name": "snap_view"}, - "command": "touchview.viewport_recenter", - "icon": "CURSOR", -} - -nPanelConfig = { - "type": "default", - "binding": {"location": "prefs", "name": "n_panel"}, - "command": "touchview.toggle_n_panel", - "icon": "EVENT_N", -} - -voxelSizeConfig = { - "type": "default", - "binding": { - "location": "prefs", - "name": "voxel_remesh", - "attribute": { - "path": "active_object.modifiers.type", - "value": "MULTIRES", - "state": False, - }, - }, - "command": "object.voxel_size_edit", - "icon": "MESH_GRID", -} - -voxelRemeshConfig = { - "type": "default", - "binding": { - "location": "prefs", - "name": "voxel_remesh", - "attribute": { - "path": "active_object.modifiers.type", - "value": "MULTIRES", - "state": False, - }, - }, - "command": "object.voxel_remesh", - "icon": "MOD_UVPROJECT", -} - -voxelStepDownConfig = { - "type": "default", - "binding": { - "location": "prefs", - "name": "voxel_remesh", - "attribute": { - "path": "active_object.modifiers.type", - "value": "MULTIRES", - "state": False, - }, - }, - "command": "touchview.density_down", - "icon": "TRIA_DOWN", -} - -voxelStepUpConfig = { - "type": "default", - "binding": { - "location": "prefs", - "name": "voxel_remesh", - "attribute": { - "path": "active_object.modifiers.type", - "value": "MULTIRES", - "state": False, - }, - }, - "command": "touchview.density_up", - "icon": "TRIA_UP", -} - -subdivConfig = { - "type": "default", - "binding": { - "location": "prefs", - "name": "multires", - "attribute": { - "path": "active_object.modifiers.type", - "value": "MULTIRES", - "state": True, - }, - }, - "has_dependent": True, - "command": "touchview.increment_multires", - "icon": "TRIA_UP", -} - -unsubdivConfig = { - "type": "default", - "binding": { - "location": "prefs", - "name": "multires", - "attribute": { - "path": "active_object.modifiers.type", - "value": "MULTIRES", - "state": True, - }, - }, - "command": "touchview.decrement_multires", - "icon": "TRIA_DOWN", -} - -brushResizeConfig = { - "type": "default", - "binding": {"location": "prefs", "name": "brush_dynamics"}, - "command": "touchview.brush_resize", - "icon": "ANTIALIASED", -} - -brushStrengthConfig = { - "type": "default", - "binding": {"location": "prefs", "name": "brush_dynamics"}, - "command": "touchview.brush_strength", - "icon": "SMOOTHCURVE", -} - -# Boolean 2D Gizmo -fullscreenToggleConfig = { - "type": "boolean", - "binding": { - "location": "screen", - "name": "show_fullscreen", - }, # property location, watch-boolean - "command": "screen.screen_full_area", - "onIcon": "FULLSCREEN_EXIT", # on-state - "offIcon": "FULLSCREEN_ENTER", # off-state -} - -quadviewToggleConfig = { - "type": "boolean", - "binding": {"location": "space_data", "name": "region_quadviews"}, - "command": "screen.region_quadview", - "onIcon": "IMGDISPLAY", - "offIcon": "MESH_PLANE", -} - -rotLocToggleConfig = { - "type": "boolean", - "binding": {"location": "region_data", "name": "lock_rotation"}, - "command": "touchview.viewport_lock", - "onIcon": "LOCKED", - "offIcon": "UNLOCKED", -} - -gizmo_colors = { - "disabled": { - "color": [0.0, 0.0, 0.0], - "color_highlight": [0.0, 0.0, 0.0], - "alpha": 0.3, - "alpha_highlight": 0.3, - }, - "active": { - "color": [0.0, 0.0, 0.0], - "alpha": 0.5, - "color_highlight": [0.5, 0.5, 0.5], - "alpha_highlight": 0.5, - }, - "error": { - "color": [0.3, 0.0, 0.0], - "alpha": 0.15, - "color_highlight": [1.0, 0.2, 0.2], - "alpha_highlight": 0.5, - }, - "warn": { - "color": [0.35, 0.3, 0.14], - "alpha": 0.15, - "color_highlight": [0.8, 0.7, 0.3], - "alpha_highlight": 0.3, - }, -} - -toggle_colors = { - "active": { - "color": [0.1, 0.1, 0.2], - "alpha": 0.5, - "color_highlight": [0.15, 0.15, 0.3], - "alpha_highlight": 0.7, - }, - "inactive": { - "color": [0.0, 0.0, 0.0], - "alpha": 0.5, - "color_highlight": [0.05, 0.05, 0.05], - "alpha_highlight": 0.7, - }, -} - -# Enum 2D Gizmo -# -# not implemented yet -pivotModeConfig = { - "type": "enum", - "binding": {"location": "prefs", "name": "pivot_mode"}, - "command": "", - "icons": pivot_icon_items, -}