Skip to content

Commit 3fa23eb

Browse files
committed
CLN: misc cleanup and debug messages
1 parent 75d96b3 commit 3fa23eb

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

larray_editor/arraywidget.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def scroll_to_global_pos(self, global_v_pos, global_h_pos):
644644

645645
def autofit_columns(self):
646646
"""Resize cells to contents"""
647-
print(f"{self.__class__.__name__}.autofit_columns()")
647+
# print(f"{self.__class__.__name__}.autofit_columns()")
648648
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
649649

650650
# for column in range(self.model_axes.columnCount()):
@@ -1400,6 +1400,10 @@ def __init__(self, parent, data=None, readonly=False, attributes=None, bg_gradie
14001400
hlabels_h_header.sectionResized.connect(self.on_hlabels_column_resized)
14011401
vlabels_v_header.sectionResized.connect(self.on_vlabels_row_resized)
14021402

1403+
# only useful for debugging
1404+
# data_h_header = self.view_data.horizontalHeader()
1405+
# data_h_header.sectionResized.connect(self.on_data_column_resized)
1406+
14031407
# Propagate auto-resizing requests
14041408
axes_h_header.sectionHandleDoubleClicked.connect(self.resize_axes_column_to_contents)
14051409
hlabels_h_header.sectionHandleDoubleClicked.connect(self.resize_hlabels_column_to_contents)
@@ -1816,12 +1820,17 @@ def on_axes_row_resized(self, logical_index, old_size, new_size):
18161820

18171821
def on_hlabels_column_resized(self, logical_index, old_size, new_size):
18181822
# synchronize with linked view
1823+
# logger.debug(f"on_hlabels_column_resized {logical_index=} {new_size=}")
18191824
self.view_data.setColumnWidth(logical_index, new_size)
18201825
if self._updating_hlabels_column_widths:
18211826
return
18221827
h_offset = self.model_data.h_offset
18231828
self.user_defined_hlabels_column_widths[logical_index + h_offset] = new_size
18241829

1830+
# def on_data_column_resized(self, logical_index, old_size, new_size):
1831+
# log_caller()
1832+
# logger.debug(f"on_data_column_resized {logical_index=} {new_size=}")
1833+
18251834
def on_vlabels_row_resized(self, logical_index, old_size, new_size):
18261835
# synchronize with linked view
18271836
self.view_data.setRowHeight(logical_index, new_size)
@@ -2239,24 +2248,28 @@ def resize_axes_column_to_contents(self, col_idx):
22392248
# view_hlabels.horizontalHeader().sectionHandleDoubleClicked
22402249
def resize_hlabels_column_to_contents(self, local_col_idx,
22412250
min_width=None, max_width=None):
2242-
# clsname = self.__class__.__name__
2243-
# print(f"{clsname}.resize_hlabels_column_to_contents({local_col_idx})")
22442251
global_col_idx = self.model_data.h_offset + local_col_idx
22452252
prev_width = self.detected_hlabels_column_widths.get(global_col_idx, 0)
2253+
# logger.debug("ArrayEditorWidget.resize_hlabels_column_to_contents("
2254+
# f"{local_col_idx=}, {min_width=}, {max_width=})")
22462255
width = max(self.view_hlabels.sizeHintForColumn(local_col_idx),
22472256
self.view_data.sizeHintForColumn(local_col_idx),
22482257
prev_width)
2258+
# logger.debug(f" {global_col_idx=} {prev_width=} => (before clip) "
2259+
# f"{width=} ")
22492260
if min_width is not None:
22502261
width = max(width, min_width)
22512262
if max_width is not None:
22522263
width = min(width, max_width)
2264+
# logger.debug(f" -> (after clip) {width=}")
22532265
# view_data column width will be synchronized automatically
22542266
self.view_hlabels.horizontalHeader().resizeSection(local_col_idx, width)
22552267

22562268
# set that column's width back to "automatic width"
22572269
if global_col_idx in self.user_defined_hlabels_column_widths:
22582270
del self.user_defined_hlabels_column_widths[global_col_idx]
22592271
if width > prev_width:
2272+
# logger.debug(f" -> width > prev_width (updating detected)")
22602273
self.detected_hlabels_column_widths[global_col_idx] = width
22612274

22622275
# must be connected to signal:

larray_editor/tests/test_api_larray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ def make_test_df(size):
351351
pl_df3 = pl_df1.select(pl.from_epoch(pl.col('M')).alias('datetime_col'), 'M').limit(5)
352352
pl_df_big = pl.from_pandas(pd_df_big, include_index=True)
353353
pl_df_mixed = pl.from_pandas(pd_df_mixed, include_index=False)
354-
pl_lf1 = pl.scan_parquet('big.parquet')
355-
pl_lf2 = pl.scan_ipc('big.feather')
354+
pl_lf_parquet = pl.scan_parquet('big.parquet')
355+
pl_lf_feather = pl.scan_ipc('big.feather')
356356

357357
path_dir = Path('.')
358358
path_py = Path('test_adapter.py')

larray_editor/utils.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
# field is field_name + conversion if any
4242
M_SPECIFIER_PATTERN = re.compile(r'\{(?P<field>[^:}]*):(?P<format_spec>[^m}]*)m\}')
43+
ICON_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'images')
4344

4445
logger = logging.getLogger("editor")
4546

@@ -240,17 +241,17 @@ def get_idx_rect(index_list):
240241

241242
class IconManager:
242243
_icons = {'larray': 'larray.ico'}
243-
_icon_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'images')
244244

245245
def icon(self, ref):
246246
if ref in self._icons:
247-
icon_path = os.path.join(self._icon_dir, self._icons[ref])
247+
icon_path = os.path.join(ICON_DIR, self._icons[ref])
248+
assert os.path.exists(icon_path)
248249
return QIcon(icon_path)
249250
else:
250-
# By default, only X11 will support themed icons. In order to use
251-
# themed icons on Mac and Windows, you will have to bundle a compliant
252-
# theme in one of your PySide.QtGui.QIcon.themeSearchPaths() and set the
253-
# appropriate PySide.QtGui.QIcon.themeName() .
251+
# By default, only X11 supports themed icons. In order to use
252+
# themed icons on Mac and Windows, we need to bundle a
253+
# compliant theme in one of the QtGui.QIcon.themeSearchPaths()
254+
# directories and set QtGui.QIcon.themeName() accordingly.
254255
return QIcon.fromTheme(ref)
255256

256257

@@ -352,7 +353,8 @@ def __getitem__(self, key):
352353
key_isnan = np.isnan(key)[..., np.newaxis]
353354
color = color0 + (color1 - color0) * normalized_value[..., np.newaxis]
354355
color = np.where(key_isnan, self.nan_color.getHsvF(), color)
355-
return from_hsvf(color[..., 0], color[..., 1], color[..., 2], color[..., 3])
356+
return from_hsvf(color[..., 0], color[..., 1], color[..., 2],
357+
color[..., 3])
356358

357359

358360
class PlotDialog(QDialog):
@@ -493,7 +495,8 @@ def __init__(self, list_name, parent_action=None, triggered=None):
493495
if self.settings.value(list_name) is None:
494496
self.settings.setValue(list_name, [])
495497
if parent_action is not None:
496-
actions = [QAction(parent_action) for _ in range(self.MAX_RECENT_FILES)]
498+
actions = [QAction(parent_action)
499+
for _ in range(self.MAX_RECENT_FILES)]
497500
for action in actions:
498501
action.setVisible(False)
499502
if triggered is not None:
@@ -544,7 +547,8 @@ def _update_actions(self):
544547
action.setStatusTip(filepath)
545548
action.setData(filepath)
546549
action.setVisible(True)
547-
# if we have less recent files than actions, hide the remaining actions
550+
# if we have less recent files than actions, hide the remaining
551+
# actions
548552
for action in self.actions[len(recent_files):]:
549553
action.setVisible(False)
550554

@@ -553,7 +557,8 @@ def cached_property(must_invalidate_cache_method):
553557
"""A decorator to cache class properties."""
554558
def getter_decorator(original_getter):
555559
def caching_getter(self):
556-
if must_invalidate_cache_method(self) or not hasattr(self, '_cached_property_values'):
560+
if (must_invalidate_cache_method(self) or
561+
not hasattr(self, '_cached_property_values')):
557562
self._cached_property_values = {}
558563
try:
559564
# cache hit
@@ -803,7 +808,7 @@ def get_func_name(frame):
803808
func_name = frame.f_code.co_name
804809
if 'self' in frame.f_locals:
805810
# We do not use Python 3.11+ frame.f_code.co_qualname because
806-
# because it returns the (super) class where the method is
811+
# it returns the (super) class where the method is
807812
# defined, not the instance class which is usually much more useful
808813
func_name = f"{frame.f_locals['self'].__class__.__name__}.{func_name}"
809814
return func_name

0 commit comments

Comments
 (0)