Skip to content

Commit a6e697a

Browse files
committed
FIX: fixed the editor being unstable after loading the demo data (closes #232)
The problem is that the path is given as a Path object, which is passed as is to QSettings (for saving the recent files list) and in the status. The first case prevents the editor from even starting *when using several Python versions on the same machine* (I suspect an incompatible pickle), the second case displayed annoying errors.
1 parent 5e69b01 commit a6e697a

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

larray_editor/editor.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
22
import re
33
import sys
4+
from pathlib import Path
5+
from typing import Union
6+
47

58
# Python3.8 switched from a Selector to a Proactor based event loop for asyncio but they do not offer the same
69
# features, which breaks Tornado and all projects depending on it, including Jupyter consoles
@@ -773,8 +776,9 @@ def set_current_array(self, array, name):
773776
self.current_array_name = name
774777
self.update_title()
775778

776-
def set_current_file(self, filepath):
777-
self.recent_data_files.add(filepath)
779+
def set_current_file(self, filepath: Union[str, Path]):
780+
if filepath is not None:
781+
self.recent_data_files.add(filepath)
778782
self.current_file = filepath
779783
self.update_title()
780784

@@ -1010,12 +1014,10 @@ def save_script(self):
10101014
else:
10111015
self._save_script(filepath, lines, overwrite)
10121016

1013-
1014-
#=============================#
1015-
# METHODS TO SAVE/LOAD DATA #
1016-
#=============================#
1017-
1018-
def _open_file(self, filepath):
1017+
# ============================= #
1018+
# METHODS TO SAVE/LOAD DATA #
1019+
# ============================= #
1020+
def _open_file(self, filepath: Union[str, Path]):
10191021
session = la.Session()
10201022
# a list => .csv files. Possibly a single .csv file.
10211023
if isinstance(filepath, (list, tuple)):

larray_editor/utils.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import sys
33
import math
44
import logging
5+
from pathlib import Path
6+
from typing import Union
7+
58
from larray.util.misc import Product
69

710
import numpy as np
@@ -605,13 +608,16 @@ def files(self, files):
605608
def actions(self):
606609
return self._actions
607610

608-
def add(self, filepath):
609-
if filepath is not None:
610-
recent_files = self.files
611-
if filepath in recent_files:
612-
recent_files.remove(filepath)
613-
recent_files = [filepath] + recent_files
614-
self.files = recent_files
611+
def add(self, filepath: Union[str, Path]):
612+
if filepath is None:
613+
return
614+
elif isinstance(filepath, Path):
615+
filepath = str(filepath)
616+
recent_files = self.files
617+
if filepath in recent_files:
618+
recent_files.remove(filepath)
619+
recent_files = [filepath] + recent_files
620+
self.files = recent_files
615621

616622
def clear(self):
617623
self.files = []
@@ -624,10 +630,12 @@ def _update_actions(self):
624630

625631
# zip will iterate up to the shortest of the two
626632
for filepath, action in zip(recent_files, self.actions):
633+
if isinstance(filepath, Path):
634+
filepath = str(filepath)
627635
action.setText(os.path.basename(filepath))
628636
action.setStatusTip(filepath)
629637
action.setData(filepath)
630638
action.setVisible(True)
631-
# if we have less recent recent files than actions, hide the remaining actions
639+
# if we have less recent files than actions, hide the remaining actions
632640
for action in self.actions[len(recent_files):]:
633641
action.setVisible(False)

0 commit comments

Comments
 (0)