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

small issue within dent on python #30

Open
mjoe67886 opened this issue Sep 26, 2023 · 11 comments
Open

small issue within dent on python #30

mjoe67886 opened this issue Sep 26, 2023 · 11 comments

Comments

@mjoe67886
Copy link

this python code isn't pasting right all the way just a very top line of the if statement is indented I have to put my mouse cursor next to the I and if and press shifting tab to indent it after pasting otherwise it works perfectly just an idea you know if you're not going to do it I'll do it later or something but I was thinking you could put it in GPT 4 and have it help you design this better for Python it shouldn't take that long if you're a really good programmer but GPT 4 because you have a easier time


if event.type == 'MOUSEMOVE':
    print("Mouse movement detected")
    v = self.manager.transform_nudge_prop

    if event.shift:
        print("Shift key pressed with mouse movement")
        v *= 0.005

    self.mouse_dx = self.mouse_dx - event.mouse_x
    offset = self.mouse_dx * v * 0.05  # Adjust the 0.05 factor for smoother scaling

    if hasattr(bpy.context.scene, "transform_local_prop") and bpy.context.scene.transform_local_prop:
        print("Transforming in local X-axis")
        for ob in context.selected_objects:
            ob.scale.x -= offset * ob.matrix_world.to_3x3().normalized()[0][0]
            print(f"{ob.name} Scale (Local X): X={ob.scale.x:.2f}, Y={ob.scale.y:.2f}, Z={ob.scale.z:.2f}")

    else:
        print("Transforming in global X-axis")
        for ob in context.selected_objects:
            mat = ob.matrix_world.to_3x3().normalized()
            ob.scale.x -= offset * mat[0][0]
            ob.scale.y -= offset * mat[1][0]
            ob.scale.z -= offset * mat[2][0]
            print(f"{ob.name} Scale (Global X): X={ob.scale.x:.2f}, Y={ob.scale.y:.2f}, Z={ob.scale.z:.2f}")

    self.mouse_dx = event.mouse_x

@mjoe67886
Copy link
Author

Here's the whole class and I'm trying to paste the class and the MODAL but leave the invoke function and it's indenting the class and the MODAL in this instance this is another test I did not the above one
`class FAST_OT_scale_x(bpy.types.Operator):
"""Scale objects in X direction"""
bl_idname = "fast.scale_x"
bl_label = "Scale X"
bl_options = {'REGISTER', 'GRAB_CURSOR', 'BLOCKING', 'UNDO'}

def modal(self, context, event):
    print("Modal called with event:", event.type)

    context.window.cursor_set("NONE")

    if event.type == 'WHEELUPMOUSE':
        print("WHEELUPMOUSE detected")
        self.manager.delta_float_prop *= 1.2

    elif event.type == 'WHEELDOWNMOUSE':
        print("WHEELDOWNMOUSE detected")
        self.manager.delta_float_prop *= 0.8

    if event.type == 'MOUSEMOVE':
        print("Mouse movement detected")
        v = self.manager.transform_nudge_prop

        if event.shift:
            print("Shift key pressed with mouse movement")
            v *= 0.005

        offset = (event.mouse_x - self.mouse_dx) * v * 0.05  # Adjust the 0.05 factor for smoother scaling
        print(f"Mouse DX: {self.mouse_dx}, Offset: {offset}")

        for ob in context.selected_objects:
            mat = ob.matrix_world.to_3x3().normalized()
            ob.scale.x -= offset * mat[0][0]
            ob.scale.y -= offset * mat[1][0]
            ob.scale.z -= offset * mat[2][0]
            print(f"{ob.name} Scale: X={ob.scale.x:.2f}, Y={ob.scale.y:.2f}, Z={ob.scale.z:.2f}")

        self.mouse_dx = event.mouse_x

    elif event.type == 'LEFTMOUSE':
        print("LEFTMOUSE button pressed")
        set_overlays(self.initial_overlays_state)  
        return {'FINISHED'}

    elif event.type in {'RIGHTMOUSE', 'ESC'}:
        print("Either RIGHTMOUSE button or ESC key pressed")
        for obj in context.selected_objects:
            obj.scale.x = self.start_x_values[obj.name]
            obj.scale.y = self.start_y_values[obj.name]
            obj.scale.z = self.start_z_values[obj.name]

        set_overlays(self.initial_overlays_state)  
        return {'CANCELLED'}

    return {'RUNNING_MODAL'}






def invoke(self, context, event):
    self.report({'INFO'}, "Scroll mouse wheel toward you to nudge.")

    # better to get the manager in here than in the modal
    try: 
        self.manager = bpy.context.preferences.addons[__name__].preferences.Prop
    except:
        self.report({'WARNING'}, 'Function failed')
        return {'CANCELLED'}

    # set initial dx from top left of window to mouse cursor position
    self.mouse_dx = event.mouse_x

    if context.selected_objects:
        self.initial_mouse_x = event.mouse_x
        # Initialization in invoke method
        self.start_x_values = {obj.name: obj.scale.x for obj in context.selected_objects}
        self.start_y_values = {obj.name: obj.scale.y for obj in context.selected_objects}
        self.start_z_values = {obj.name: obj.scale.z for obj in context.selected_objects}

        self.initial_values = {obj.name: obj.scale.x for obj in context.selected_objects}
        self.last_direction = 0 

        # Check the initial state of overlays
        self.initial_overlays_state = are_overlays_enabled()

        # Disable overlays
        set_overlays(False)

        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}
    else:
        self.report({'WARNING'}, "No selected objects, could not finish")
        return {'CANCELLED'}

`

@gazugafan
Copy link
Owner

Sounds like #21 and #25 yeah?

@mjoe67886
Copy link
Author

Yeah I'm not really sure uh I could send you a screen video if it would help

@mjoe67886
Copy link
Author

The main thing is it doesn't really work right when you're pasting a different sections of an operator with you know MODAL and execute and I invoke it it should work in every instance no matter what you come across otherwise it's kind of a confusing hindrance he should put it through GPT and just you know spend a day tackling it this really is a gift to the world I appreciate your stab at it and stuff so far I know you could probably do it just ask GPT to sync outside of the box you know like come up with a tell it specifically come up with other ways we could approach how I'm doing this I really appreciate you providing it though that gives me a starting point let me know if you need help i'll I'll help you tackle it

@gazugafan
Copy link
Owner

If you want, sure. It sounds like those issues above, though.

In short, this extension's indentation algorithm is just looking to see if you pasted above an "ending block" (like a closing } or something). If you did, it indents a level deeper than that. Otherwise it indents on the same level as the next line.

Python doesn't have those at all, though, so it's always indenting to the same level as the next line. You'd need a full-blown Python language server for it to be more intelligent.

Maybe give those issues a read and see if that makes more sense.

@mjoe67886
Copy link
Author

Oh Karen busy today trying to figure out a blender operator but I'll go ahead and uh see what I could come up with tomorrow as far as some new ideas I'm usually pretty good at figuring out workarounds you can always put a note 2 on your front page saying hey this isn't perfect if another programmer wants to get involved in developing this because you know this is a really important thing that really sucks having to indent code every time you paste..

@mjoe67886
Copy link
Author

should've been O K I don't know why it said O Karen...

@gazugafan
Copy link
Owner

Yeah there's a note about this under "Limitations" in the readme...
https://github.com/gazugafan/vscode-indent-on-paste#limitations

@mjoe67886
Copy link
Author

Yeah do you know how to use GPT 4 it's great at coming up with new angles on thing and logic you should really throw it in there and see if there's a way you could get around limitations

@gazugafan
Copy link
Owner

ChatGPT isn't going to give you a good solution to this because it's not really a solvable problem. Not in this context, at least. You're looking for a Python language server that can format your code. You're welcome to "throw it in there" and see what it gives you, though. PRs welcome ;)

@mjoe67886
Copy link
Author

mjoe67886 commented Sep 27, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants