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

Eventfilter in python plugins do not work as expected #3412

Open
1 of 3 tasks
amibranch opened this issue Feb 4, 2025 · 0 comments
Open
1 of 3 tasks

Eventfilter in python plugins do not work as expected #3412

amibranch opened this issue Feb 4, 2025 · 0 comments

Comments

@amibranch
Copy link

amibranch commented Feb 4, 2025

Environment information

  • Operating System: Arch Linux
  • Cutter version: a5442f6f99bbd1f150e8dcaa4d671c3049cec917 (more recent HEAD, build and installed via custom PKGBUILD)
  • Obtained from:
    • Built from source
    • Downloaded release from Cutter website or GitHub
    • Distribution repository
  • File format: arbitrary

Describe the bug

I was trying to create a python plugin for cutter that provides part of the ARM documentation in the disassembly-view as tooltip. Basically a clone of AMIE for cutter.

While trying to install an eventfilter on the cutter mainwindow, I discovered that the events will only pass my eventfilter if I raise an exception in the setupInterface function of my plugin.

To Reproduce

  1. Install cutter for linux
  2. Create a python plugin with the following content
#!/usr/bin/env python3

import sys

import cutter

from qtpy.QtCore import QObject

class MyEventFilter(QObject):
    def eventFilter(self, watched, event):
        print(f"Reached {event.type()} on {watched}")
        return super().eventFilter(watched, event)

class MyPlugin(cutter.CutterPlugin):
    name = "My Plugin"
    description = "A Minimalist Python plugin"
    version = "1.0"
    author = "amibranch"

    def setupInterface(self, main):
        obj = main
        event_filter = MyEventFilter()
        obj.setMouseTracking(True)
        obj.installEventFilter(event_filter)

        # Will work:
        raise ValueError('A very specific bad thing happened.')

        # Won't work:
        #return

    def setupPlugin(self):
        pass

    def terminate(self):
        pass

def create_cutter_plugin():
    return MyPlugin()
  1. Copy the plugin into a folder that will be used by cutter on default. E.g. ~/.local/share/rizin/cutter/plugins/python/
  2. Start cutter (at best from shell to observe stdout/stderr therein) and load an arbitrary project
  3. If you leave the exception in the code, the eventfilter will work as expected. If you remove it (i.e. leave just a return) it will not!

Expected behavior

  • I expect to have the possibility to add eventfilter to cutter main windows, in order to use them as intended by qtpy/pyside (without raising any exceptions that may introduce sideeffects.

Additional context

I figured out that the main difference is the execution of setupInterface from within cutter (CutterPluginWrapper::setupInerface). In case of an exception pyResult is denoted by gdb as:

(gdb) p pyResult
$2 = {m_pyObj = 0x0}

However, the impact of the following Shiboken::Errors::storePythonOverrideErrorOrPrint is beyond my knowledge of shiboken-/cutter-internals.

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

1 participant