Skip to content

Commit

Permalink
Merge pull request #135 from hanjinliu/find-scroll
Browse files Browse the repository at this point in the history
Ensure selection visible during "find"
  • Loading branch information
hanjinliu authored Jun 21, 2024
2 parents 1f72a00 + 9c23ca6 commit 81fc4c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tabulous/_qt/_table/_base/_table_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def __init__(
_layout.addWidget(sizegrip, False, Qt.AlignmentFlag.AlignRight)

self.setLayout(_layout)
_screen_rect = QtGui.QGuiApplication.primaryScreen().geometry()
_screen_rect = QtGui.QGuiApplication.screenAt(
parent.mapToGlobal(parent.geometry().topLeft())
).geometry()
_screen_center = _screen_rect.center()
self.resize(int(_screen_rect.width() * 0.8), int(_screen_rect.height() * 0.8))
self.move(_screen_center - self.rect().center())
Expand Down
4 changes: 4 additions & 0 deletions tabulous/_qt/_table_stack/_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def findNext(self) -> None:
qtable.moveToItem(r + 2, c + 2)
qtable.moveToItem(r, c)
qtable.setSelections([(r, c)])
index = qtable._qtable_view.model().index(r, c)
qtable._qtable_view.scrollTo(index)
self._current_index = (r, c)
return

Expand All @@ -185,6 +187,8 @@ def findPrevious(self) -> None:
qtable.moveToItem(r + 2, c + 2)
qtable.moveToItem(r, c)
qtable.setSelections([(r, c)])
index = qtable._qtable_view.model().index(r, c)
qtable._qtable_view.scrollTo(index)
self._current_index = (r, c)
return

Expand Down
14 changes: 11 additions & 3 deletions tabulous/_slice_op.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import numpy as np

# utility functions for working with slices


Expand Down Expand Up @@ -51,11 +53,17 @@ def as_sized(sl: slice, size: int, allow_negative: bool = False):
def fmt(sl: slice) -> str:
"""Format a slice as a string."""
if isinstance(sl, slice):
s0 = repr(sl.start) if sl.start is not None else ""
s1 = repr(sl.stop) if sl.stop is not None else ""
s0 = _repr(sl.start) if sl.start is not None else ""
s1 = _repr(sl.stop) if sl.stop is not None else ""
return f"{s0}:{s1}"
return repr(sl)
return _repr(sl)


def has_none(sl: slice):
return sl.start is None or sl.stop is None


def _repr(x) -> str:
if isinstance(x, np.number):
return str(x)
return repr(x)

0 comments on commit 81fc4c1

Please sign in to comment.