Get geometry info on screen
Although the solution below should quickly give you all the info you ask for, not sure if the way the info is presented will fully satisfy your description.
It is an edited version of this answer, now extended with a few extra calculations, now including the angle to an imaginary horizontal line, as well as the length of the line you draw, in (equivalents of) px:
The script
#!/usr/bin/env python3
import subprocess
import os
import math
home = os.environ["HOME"]
area = home+"/"+".measure_area.txt"
def get_pos():
pos_data = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8")
return [m[2:] for m in pos_data.split()[:2]]
def confirm():
get = subprocess.check_output(["xrandr", "--verbose"]).decode("utf-8").split()
for s in [get[i-1] for i in range(len(get)) if get[i] == "connected"]:
br_data = float(get[get.index("Brightness:")+1])
brightness = lambda br: ["xrandr", "--output", s, "--brightness", br]
flash = ["sleep", "0.1"]
for cmd in [brightness(str(br_data-0.1)), flash, brightness(str(br_data))]:
subprocess.call(cmd)
if not os.path.exists(area):
with open(area, "wt") as measure:
measure.write(str(get_pos()))
confirm()
else:
second = get_pos()
with open(area) as first_m:
try:
first = eval(first_m.read())
w = int(math.fabs(int(second[0]) - int(first[0])))
h = int(math.fabs(int(second[1]) - int(first[1])))
l = str(round(math.sqrt(pow(w, 2) + pow(h, 2))))
arc = math.degrees(math.atan(w/h))
angle = str(round(90-arc))
command = [
'zenity', '--info', '--title', 'Area Size', '--width', '200',
'--text', "rectangle: " + str(w) + 'px x ' + str(h) + "px"
"\nline length: " + l + "px\nangle: " + str(angle) + "°",
]
#---
confirm()
except SyntaxError:
text = "Please try again, there was an error in the data"
command = ['zenity', '--info', '--title', 'Please try again', '--text', text]
subprocess.Popen(command)
os.remove(area)
How it works
The script calculates the angle to an imaginary horizontal line, the length and the area size, between two locations of the mouse pointer.
It works as followes:
- Place the mouse pointer in the first position (without clicking)
- Press the key combination of your choice (see further below)
- Place the mouse in the second position (again without clicking)
- Press your key combination again. A Zenity window will show you the result as in the image above.
How to set up
The script uses xdotool
:
sudo apt-get install xdotool
Copy the script below into an empty file, save it in ~/bin
(you will probably have to create the directory) as measure_area
(no extension) and make it executable.
Add a key combination of your choice to run the script: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
measure_area
Notes
- You will have to log out / in first
- It does not make a difference what you take as first/second position; the script measures absolute values.