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

Update all references to device attribute 'fn' to use 'path' in keymapper #891

Open
RedBearAK opened this issue Feb 8, 2025 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@RedBearAK
Copy link
Contributor

@ rbreaves

FYI, I just had to do a quick update in xwaykeyz, my fork of xkeysnail/keyszer, due to the apparent removal of a deprecated InputDevice attribute name in an update to evdev that just happened this morning. (Saturday, Feb. 8, 2025)

This will most likely need to be dealt with in all forks of this keymapper. Anyone newly installing them along with evdev 1.9.0 or later will probably run into an AttributeError when attempting to run the keymapper.

There was a deprecation warning in the evdev code (in evdev/device.py), probably for quite some time now.

    @property
    def fn(self):
        msg = "Please use {0}.path instead of {0}.fn".format(self.__class__.__name__)
        warnings.warn(msg, DeprecationWarning, stacklevel=2)
        return self.path

And there's the note about the removal of the deprecated attribute in the evdev change log:

https://python-evdev.readthedocs.io/en/latest/changelog.html#feb-08-2025

Drop deprecated InputDevice.fn (use InputDevice.path instead).

I found that everywhere that device.fn was used needed to be updated to device.path in the keymapper's devices.py module. Including a couple of references that were in a formatting syntax in this, so it was a bit more abstract and needed more than a single simple find/replace operation:

    @staticmethod
    def print_list():
        devices = Devices.all()
        device_format = "{1.fn:<20} {1.name:<35} {1.phys}"
        device_lines = [
            device_format.format(n, d) for n, d in enumerate(devices)
        ]
        header_len = max([20 + 35 + 3 + len(x.phys) for x in devices])
        print("-" * header_len)
        print("{:<20} {:<35} {}".format("Device", "Name", "Phys"))
        print("-" * header_len)
        for i, line in enumerate(device_lines):
            dev = devices[i]
            if len(dev.name) > 35:
                fmt = "{1.fn:<20} {1.name:<35}"
                print(fmt.format(None, dev))
                print(" " * 57 + dev.phys)
            else:
                print(line)
        print("")

That needed to be updated like this, with {1.path:<20} replacing the two {1.fn:<20} instances:

    @staticmethod
    def print_list():
        devices = Devices.all()
        device_format = "{1.path:<20} {1.name:<35} {1.phys}"
        device_lines = [
            device_format.format(n, d) for n, d in enumerate(devices)
        ]
        header_len = max([20 + 35 + 3 + len(x.phys) for x in devices])
        print("-" * header_len)
        print("{:<20} {:<35} {}".format("Device", "Name", "Phys"))
        print("-" * header_len)
        for i, line in enumerate(device_lines):
            dev = devices[i]
            if len(dev.name) > 35:
                fmt = "{1.path:<20} {1.name:<35}"
                print(fmt.format(None, dev))
                print(" " * 57 + dev.phys)
            else:
                print(line)
        print("")

And that is all I know about that.

The fix worked for me after experiencing the AttributeError on a fresh install of Toshy this morning, and a Toshy user quickly confirmed that the updated xwaykeyz 1.4.0 release no longer had the AttributeError when the Toshy installer was run again and cloned the new version of the keymapper.

I'll be cross-posting this to the keyzer and xkeysnail GitHub issues.

@RedBearAK
Copy link
Contributor Author

And I also updated the print_list() method in my fork of the keymapper to use the newer f-strings syntax for the printed output:

    @staticmethod
    def print_list():
        # Get all devices
        devices = Devices.all()
        
        # Define column widths
        DEVICE_WIDTH = 20
        NAME_WIDTH = 35
        
        # Calculate the total width needed for the table
        max_phys_length = max(len(device.phys) for device in devices)
        total_width = DEVICE_WIDTH + NAME_WIDTH + max_phys_length + 3  # +3 for spaces between columns
        
        # Print header
        print("-" * total_width)
        print(f"{'Device':<{DEVICE_WIDTH}} {'Name':<{NAME_WIDTH}} {'Phys'}")
        print("-" * total_width)
        
        # Print each device
        for device in devices:
            if len(device.name) > NAME_WIDTH:
                # Handle long names by printing on two lines
                print(f"{device.path:<{DEVICE_WIDTH}} {device.name[:NAME_WIDTH]:<{NAME_WIDTH}}")
                print(f"{'':<{DEVICE_WIDTH + NAME_WIDTH}} {device.phys}")
            else:
                # Print everything on one line
                print(f"{device.path:<{DEVICE_WIDTH}} {device.name:<{NAME_WIDTH}} {device.phys}")
        
        print()

This is entirely optional and makes no real difference to how the method works. It's just more readable and searchable than the older style of string formatting.

@Udhay707
Copy link

Udhay707 commented Feb 15, 2025

@RedBearAK I think I have the same issue

Image

Is there some quick fix or workaround available for this?
I have been trying to find some pr / fork that fixed this issue, but unable to find one.

And because of this, I am unable to remap the keys on freshly installed Linux Mint.

@RedBearAK
Copy link
Contributor Author

@Udhay707

Toshy is my alternative to Kinto that has already fixed this issue. You can remove Kinto and try Toshy instead.

https://github.com/RedBearAK/toshy

Otherwise you’d have to fix it yourself in the Python file referenced in the error message. Find the four instances of “.fn” and replace them with “.path” to make the error go away.

@Udhay707
Copy link

@RedBearAK Thank you so much, toshy saved my day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants