Skip to content

Commit 399baf3

Browse files
committed
Correct row position calculation.
1 parent 3be907c commit 399baf3

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

cocoa/tests_backend/widgets/table.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ def row_position(self, row):
7474
# Pick a point half way across horizontally, and half way down the row,
7575
# taking into account the size of the rows and the header
7676
row_height = self.native_table.rowHeight
77-
return self.native.convertPoint(
77+
return self.native_table.convertPoint(
7878
NSPoint(
7979
self.width / 2,
80-
row * row_height + self.header_height + row_height / 2,
80+
(row * row_height) + (row_height / 2),
8181
),
8282
toView=None,
8383
)
8484

8585
async def select_row(self, row, add=False):
8686
point = self.row_position(row)
87-
# Selection maintains an inner mouse event loop, so we can't
87+
# Table maintains an inner mouse event loop, so we can't
8888
# use the "wait for another event" approach for the mouse events.
8989
# Use a short delay instead.
9090
await self.mouse_event(
@@ -102,14 +102,30 @@ async def select_row(self, row, add=False):
102102

103103
async def activate_row(self, row):
104104
point = self.row_position(row)
105-
# Selection maintains an inner mouse event loop, so we can't
105+
# Table maintains an inner mouse event loop, so we can't
106106
# use the "wait for another event" approach for the mouse events.
107107
# Use a short delay instead.
108-
await self.mouse_event(NSEventType.LeftMouseDown, point, delay=0.1)
109-
await self.mouse_event(NSEventType.LeftMouseUp, point, delay=0.1)
108+
await self.mouse_event(
109+
NSEventType.LeftMouseDown,
110+
point,
111+
delay=0.1,
112+
)
113+
await self.mouse_event(
114+
NSEventType.LeftMouseUp,
115+
point,
116+
delay=0.1,
117+
)
110118

111119
# Second click, with a click count.
112120
await self.mouse_event(
113-
NSEventType.LeftMouseDown, point, delay=0.1, clickCount=2
121+
NSEventType.LeftMouseDown,
122+
point,
123+
delay=0.1,
124+
clickCount=2,
125+
)
126+
await self.mouse_event(
127+
NSEventType.LeftMouseUp,
128+
point,
129+
delay=0.1,
130+
clickCount=2,
114131
)
115-
await self.mouse_event(NSEventType.LeftMouseUp, point, delay=0.1, clickCount=2)

testbed/tests/widgets/test_table.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ async def multiselect_probe(main_window, multiselect_widget):
106106
async def test_scroll(widget, probe):
107107
"""The table can be scrolled"""
108108

109-
# Store the initial position; it might be <0 for implementation reasons.
110-
initial_position = probe.scroll_position
111-
assert initial_position <= 0
109+
# Due to the interaction of scrolling with the header row, the scroll might be <0.
110+
assert probe.scroll_position <= 0
112111

113112
# Scroll to the bottom of the table
114113
widget.scroll_to_bottom()
@@ -133,7 +132,9 @@ async def test_scroll(widget, probe):
133132
widget.scroll_to_top()
134133
await probe.wait_for_scroll_completion()
135134
await probe.redraw("Table scrolled to bottom")
136-
assert probe.scroll_position == initial_position
135+
136+
# Due to the interaction of scrolling with the header row, the scroll might be <0.
137+
assert probe.scroll_position <= 0
137138

138139

139140
async def test_select(widget, probe, source, on_select_handler):

0 commit comments

Comments
 (0)