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

Trying to snap raises AttributeError: 'int' object has no attribute 'get_geometry' #4

Open
dietervansteenwegen opened this issue Oct 20, 2022 · 6 comments · May be fixed by #5
Open

Comments

@dietervansteenwegen
Copy link

I have two issues, The first is minor and likely a mistake on my end after installing/uninstalling several times but I'll add it just in case it is related.

I installed Snappyzones through pip (python -m pip install snappyzones) succesfully.
I'm running 5.4.0-128-generic kernel, Python 3.8.10, using Cinnamon.

My first issue: when trying to run snappy start from the command line, I get bash: /usr/local/bin/snappy: No such file or directory. Running which snappyreturns /home/dieter/.local/bin/snappy. That executable actually runs, so /home/dieter/.local/bin/snappy start works perfect. I've used that to config and save three zones.

Second (real issue): When trying to snap (so pressing and holding left shift, then dragging a window) I get an AttributeError with the following traceback:

  File "/home/dieter/.local/bin/snappy", line 8, in <module>
    sys.exit(main())
  File "/home/dieter/.local/lib/python3.8/site-packages/snappyzones/__main__.py", line 23, in main
    launch_background_process(*args, **kwargs)
  File "/home/dieter/.local/lib/python3.8/site-packages/snappyzones/process.py", line 38, in launch_background_process
    service = Service()
  File "/home/dieter/.local/lib/python3.8/site-packages/snappyzones/service.py", line 44, in __init__
    self.display.record_enable_context(self.context, self.handler)
  File "/home/dieter/.local/lib/python3.8/site-packages/Xlib/ext/record.py", line 239, in enable_context
    EnableContext(
  File "/home/dieter/.local/lib/python3.8/site-packages/Xlib/ext/record.py", line 220, in __init__
    rq.ReplyRequest.__init__(self, *args, **keys)
  File "/home/dieter/.local/lib/python3.8/site-packages/Xlib/protocol/rq.py", line 1369, in __init__
    self.reply()
  File "/home/dieter/.local/lib/python3.8/site-packages/Xlib/protocol/rq.py", line 1381, in reply
    self._display.send_and_recv(request = self._serial)
  File "/home/dieter/.local/lib/python3.8/site-packages/Xlib/protocol/display.py", line 612, in send_and_recv
    gotreq = self.parse_response(request)
  File "/home/dieter/.local/lib/python3.8/site-packages/Xlib/protocol/display.py", line 704, in parse_response
    gotreq = self.parse_request_response(request) or gotreq
  File "/home/dieter/.local/lib/python3.8/site-packages/Xlib/protocol/display.py", line 792, in parse_request_response
    req._parse_response(self.data_recv[:self.recv_packet_len])
  File "/home/dieter/.local/lib/python3.8/site-packages/Xlib/ext/record.py", line 224, in _parse_response
    self._callback(r)
  File "/home/dieter/.local/lib/python3.8/site-packages/snappyzones/service.py", line 72, in handler
    shift_window(self, keysym)
  File "/home/dieter/.local/lib/python3.8/site-packages/snappyzones/snap.py", line 46, in shift_window
    pg = window.query_tree().parent.query_tree().parent.get_geometry()
AttributeError: 'int' object has no attribute 'get_geometry'

Running tkinter.TkVersionfrom a Python repl returns version 8.6

If there is any more info required, please let me know!

@rcerqueira11
Copy link

I have the same error.

@mar-things
Copy link

Same error here, Is any solution available already?

@dietervansteenwegen
Copy link
Author

I don't see any comment mentioning that, so I wouldn't think so. I don't have any experience with tkinter (I picked PyQt once and stuck with it) so unless I'm magically given hours of spare time, I won't go looking for it myself very soon...

@mgdotdev
Copy link
Owner

mgdotdev commented Oct 2, 2023

sorry that it has taken me a while to chime in here

The issue that we're gonna have is that I wrote this on KDE and I don't have a Cinnamon DE to play around on for debugging. Furthermore, being able to solo support issues across the Nth linux DE is going to be impossible.

I'd be more than happy to accept merge requests if you find a fix; one thing you might be able to try is running snappyzones in the context of the python debugger using python -m pdb -m snappyzones so that the debugger (pdb) will drop you into the call stack at the point when calling get_geometry() throws an AttributeError. You can then poke around a bit in the call stack and see if you can get any further context as to what is going on.

My guess is that KDE and Cinnamon just have different philosophies for wrapping windows, maybe we're calling .query_tree().parent one too many times for the DE. If this is the case once you drop into pdb, you can try window.query_tree().parent.get_geometry() and see what that function call returns.

but IDK 🤷🏻

@dietervansteenwegen
Copy link
Author

Michael, obviously no worries about not responding earlier or not supporting other DE's than the one you're using.
I might take a look one of the next few months, but having no experience with Tkinter I'm afraid I might come up with something that works for me but isn't applicable to other systems and thus not a good idea to put in a merge request anyway.

@joaomcarlos
Copy link

joaomcarlos commented Dec 18, 2023

Hi,

In snap.py, if I change the following lines in shift_window method, it stops giving me the error :

# pg = window.query_tree().parent.query_tree().parent.get_geometry()
pg = window.get_geometry()  # this is actually not the right one

I can see the windows snapping around but they arent snapping correctly.

At first, I noticed that the zones.json in ~/.local/lib/python3.10/site-packages/snappyzones/conf were all having the same settings (full screen in width and height and 0 and 0 for x and y), which means the configuration sort of worked but not really, it did save 3 zones correctly but not their positions.

I manually edited the file for my ultra wide monitor (5120x1440) to this:

[
  {
    "height": 1440,
    "width": 1275,
    "x": 0,
    "y": 0
  },
  {
    "height": 1440,
    "width": 2550,
    "x": 1275,
    "y": 0
  },
  {
    "height": 1440,
    "width": 1270,
    "x": 3825,
    "y": 0
  }
]

This configuration should be basically like this: [ _ | _ _ | _ ] where each _ is exactly half of a 27' monitor. This is done so that I can utilize the center of the monitor as a full 27' monitor, and the left and right columns as side panels. Running the configuration again shows the zones in the right place but messes them up if I save again. Probably because of the needed code change above?

However, left_shift + dragging seems to conflict with some other tool (will figure that one later) and left_shift + arrows moves the windows around but to the wrong locations.

Left arrow: on first press puts it at full screen, on second press puts it on the left side but with some pretty big edges around the window.
Right arrow: on first press (after window is on the left) will move it to the right edge instead of center.

What I would expect is to be able to move from left -> center -> right and vice versa.

Edit: I am diving deeper into it and seeing if I can fix all the issues and send out a PR

@davet2001 davet2001 linked a pull request Jun 16, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

5 participants