Skip to content

Commit

Permalink
Merge pull request #126 from hanjinliu/fix-slot
Browse files Browse the repository at this point in the history
Fix in-cell slots
  • Loading branch information
hanjinliu authored Sep 23, 2023
2 parents bd83d53 + c3bec90 commit d05bfa1
Show file tree
Hide file tree
Showing 32 changed files with 2,452 additions and 2,104 deletions.
4 changes: 0 additions & 4 deletions tabulous/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def main():
TXT_PATH.write_text("")

from . import TableViewer
from ._async_importer import import_plt, import_scipy
from ._qt._console import import_qtconsole_threading

viewer = TableViewer()
Expand All @@ -91,9 +90,6 @@ def main():
viewer.open(args.open_file)

import_qtconsole_threading()
import_plt()

import_scipy()
viewer.show()
return

Expand Down
28 changes: 8 additions & 20 deletions tabulous/_async_importer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import threading
from types import ModuleType
from typing import Callable, Generic, TypeVar
import concurrent.futures

THREAD: "threading.Thread | None" = None

_T = TypeVar("_T")

Expand All @@ -22,26 +21,15 @@ class AsyncImporter(Generic[_T]):

def __init__(self, import_func: Callable[[], _T]) -> None:
self._target = import_func
self._thread: "threading.Thread | None" = None
self._future: "concurrent.futures.Future[_T] | None" = None

def run(self) -> None:
with threading.Lock():
if self._thread is None:
self._thread = threading.Thread(target=self._target, daemon=True)
self._thread.start()
else:
self._thread.join()

def get(self, ignore_error: bool = True) -> _T:
try:
self.run()
except Exception as e:
if ignore_error:
return None
else:
raise e
else:
return self._target()
if self._future is None or self._future.done():
self._future = concurrent.futures.ThreadPoolExecutor().submit(self._target)

def get(self, timeout: float = None) -> _T:
self.run()
return self._future.result(timeout)

__call__ = get

Expand Down
2 changes: 1 addition & 1 deletion tabulous/_magicgui/_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _runner(parent=None, **param_options):
style = "dark_background"
bg = viewer._qwidget.backgroundColor().name()

plt = QtMplPlotCanvas(style=style)
plt = QtMplPlotCanvas(style=style, pickable=False)
if bg:
plt.set_background_color(bg)

Expand Down
10 changes: 0 additions & 10 deletions tabulous/_magicgui/_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ def value(self, val: str | SelectionOperator) -> None:
def format(self) -> str:
return self._format

def as_iloc(self) -> tuple[slice, slice]:
"""Return current value as a indexer for ``iloc`` method."""
df = self._find_table().data_shown
return self.value.as_iloc(df)

def as_iloc_slices(self) -> tuple[slice, slice]:
"""Return current value as slices for ``iloc`` method."""
df = self._find_table().data_shown
return self.value.as_iloc_slices(df)

def _find_table(self) -> TableBase:
table = find_current_table(self)
if table is None:
Expand Down
Loading

0 comments on commit d05bfa1

Please sign in to comment.