Skip to content

Commit aa8ad28

Browse files
committed
fix session problem
Signed-off-by: Nikhil Dhandre <nik.digitronik@live.com>
1 parent 0acab00 commit aa8ad28

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
"Programming Language :: Python :: 3 :: Only",
2121
],
2222
description="Geometry of a rectangular screen region",
23-
entry_points={"console_scripts": ["xrectsel= xrectsel.console:cli"]},
23+
setup_requires=["setuptools_scm"],
2424
install_requires=["python-xlib"],
2525
long_description=readme,
2626
long_description_content_type="text/markdown",
27+
entry_points={"console_scripts": ["xrectsel= xrectsel.console:cli"]},
2728
include_package_data=True,
28-
setup_requires=["setuptools_scm"],
2929
python_requires=">=3.4",
3030
keywords="xrectsel, python-xrectsel",
3131
name="python-xrectsel",
32-
packages=find_packages(include=["python-xrectsel"]),
32+
packages=find_packages(include=["xrectsel"]),
3333
url="https://github.com/digitronik/python-xrectsel",
3434
version="1.0",
3535
license="GPLv3",

xrectsel/__init__.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#!/usr/bin/env python
2-
31
import sys
42
from Xlib import X, display, Xcursorfont
53

64

75
def coordinates(start_point, end_point):
6+
"""
7+
:param start_point: Start co-ordinates of rectangle
8+
:param end_point: End co-ordinates of rectangle
9+
:return: dict of start co-ordinates, end co-ordinates, width, height of rectangle.
10+
"""
811
X = dict(x=0, y=0)
912
Y = dict(x=0, y=0)
1013

@@ -18,11 +21,21 @@ def coordinates(start_point, end_point):
1821

1922

2023
class XRectSel(object):
21-
def __init__(self, _display=None, screen=None):
24+
"""
25+
Base class for python-xrectsel
26+
27+
TODO: Enhancement like colors, pixels customization.
28+
"""
29+
30+
def __init__(self, _display=None):
31+
"""
32+
:param _display: custom display else it will take default
33+
"""
2234
self.display = _display if _display else display.Display()
23-
self.screen = screen if screen else self.display.screen()
35+
self.screen = self.display.screen()
2436
self.window = self.screen.root
2537

38+
# Grab mouse pointer
2639
self.window.grab_pointer(
2740
1,
2841
X.PointerMotionMask | X.ButtonReleaseMask | X.ButtonPressMask,
@@ -33,6 +46,7 @@ def __init__(self, _display=None, screen=None):
3346
X.CurrentTime,
3447
)
3548

49+
# Grab keyboard
3650
self.window.grab_keyboard(1, X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
3751

3852
self.gc = self.window.create_gc(
@@ -61,13 +75,17 @@ def _cursor(self):
6175
font, Xcursorfont.crosshair, Xcursorfont.crosshair + 1, (65535, 65535, 65535), (0, 0, 0)
6276
)
6377

64-
def draw_rectangle(self, start_point, end_point):
65-
coords = coordinates(start_point, end_point)
78+
def draw_rectangle(self, coords):
6679
self.window.rectangle(
6780
self.gc, coords["start"]["x"], coords["start"]["y"], coords["width"], coords["height"]
6881
)
6982

7083
def select(self):
84+
"""
85+
Draw rectangle with mouse events
86+
87+
:return: dict of start co-ordinates, end co-ordinates, width, height of rectangle.
88+
"""
7189
start_point = {}
7290
end_point = {}
7391
tmp_point = {}
@@ -98,18 +116,25 @@ def select(self):
98116
continue
99117

100118
if tmp_point:
101-
self.draw_rectangle(start_point, tmp_point)
119+
coords = coordinates(start_point, tmp_point)
120+
self.draw_rectangle(coords)
102121
tmp_point = None
103122

104123
tmp_point = dict(x=event.root_x, y=event.root_y)
105-
self.draw_rectangle(start_point, tmp_point)
124+
coords = coordinates(start_point, tmp_point)
125+
self.draw_rectangle(coords)
106126

107127
# Mouse button release
108128
elif event.type == X.ButtonRelease:
109129
if tmp_point:
110-
self.draw_rectangle(start_point, tmp_point)
111-
130+
coords = coordinates(start_point, tmp_point)
131+
self.draw_rectangle(coords)
112132
end_point = dict(x=event.root_x, y=event.root_y)
113133

114134
self.display.flush()
115-
return start_point, end_point
135+
self.display.close()
136+
return coordinates(start_point, end_point)
137+
138+
139+
if __name__ == "__main__":
140+
print(XRectSel().select())

xrectsel/console.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from xrectsel import XRectSel, coordinates
1+
from xrectsel import XRectSel
22

33

44
def cli():
55
xrect = XRectSel()
6-
start, end = xrect.select()
7-
geormetry = coordinates(start, end)
6+
geormetry = xrect.select()
87

98
if geormetry["width"] <= 1 or geormetry["height"] <= 1:
109
pass

0 commit comments

Comments
 (0)