Skip to content

Commit

Permalink
Correct row position calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Jun 26, 2023
1 parent 3be907c commit 399baf3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
32 changes: 24 additions & 8 deletions cocoa/tests_backend/widgets/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ def row_position(self, row):
# Pick a point half way across horizontally, and half way down the row,
# taking into account the size of the rows and the header
row_height = self.native_table.rowHeight
return self.native.convertPoint(
return self.native_table.convertPoint(
NSPoint(
self.width / 2,
row * row_height + self.header_height + row_height / 2,
(row * row_height) + (row_height / 2),
),
toView=None,
)

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

async def activate_row(self, row):
point = self.row_position(row)
# Selection maintains an inner mouse event loop, so we can't
# Table maintains an inner mouse event loop, so we can't
# use the "wait for another event" approach for the mouse events.
# Use a short delay instead.
await self.mouse_event(NSEventType.LeftMouseDown, point, delay=0.1)
await self.mouse_event(NSEventType.LeftMouseUp, point, delay=0.1)
await self.mouse_event(
NSEventType.LeftMouseDown,
point,
delay=0.1,
)
await self.mouse_event(
NSEventType.LeftMouseUp,
point,
delay=0.1,
)

# Second click, with a click count.
await self.mouse_event(
NSEventType.LeftMouseDown, point, delay=0.1, clickCount=2
NSEventType.LeftMouseDown,
point,
delay=0.1,
clickCount=2,
)
await self.mouse_event(
NSEventType.LeftMouseUp,
point,
delay=0.1,
clickCount=2,
)
await self.mouse_event(NSEventType.LeftMouseUp, point, delay=0.1, clickCount=2)
9 changes: 5 additions & 4 deletions testbed/tests/widgets/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ async def multiselect_probe(main_window, multiselect_widget):
async def test_scroll(widget, probe):
"""The table can be scrolled"""

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

# Scroll to the bottom of the table
widget.scroll_to_bottom()
Expand All @@ -133,7 +132,9 @@ async def test_scroll(widget, probe):
widget.scroll_to_top()
await probe.wait_for_scroll_completion()
await probe.redraw("Table scrolled to bottom")
assert probe.scroll_position == initial_position

# Due to the interaction of scrolling with the header row, the scroll might be <0.
assert probe.scroll_position <= 0


async def test_select(widget, probe, source, on_select_handler):
Expand Down

0 comments on commit 399baf3

Please sign in to comment.