Skip to content

Commit

Permalink
Added progress_widget aka todo list
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilipp committed Dec 25, 2018
1 parent 7d9327a commit a0ff27a
Show file tree
Hide file tree
Showing 6 changed files with 679 additions and 7 deletions.
11 changes: 11 additions & 0 deletions straditize/straditizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ class Straditizer(LabelSelection):
adjusting = _temp_bool_prop(
'adjusting', "True if xlim and ylim are adjusted")

#: straditizer tasks that are marked as done by the user. See the
#: :class:`straditize.widgets.progress_list.ProgressWidget` class
_done_tasks = set()

@property
def valid_attrs(self):
attrs = self.attrs
Expand Down Expand Up @@ -306,6 +310,7 @@ def __init__(self, image, ax=None, plot=True, attrs=None):
self.magni_marks = []
self.mark_cids = set()
self.remove_callbacks = {'image_array': [self.update_image]}
self._done_tasks = set()

def reset_image(self, image, reader=False):
"""Reset the straditizer image
Expand Down Expand Up @@ -441,6 +446,7 @@ def __reduce__(self):
'_yaxis_px_orig': self._yaxis_px_orig,
'yaxis_data': self.yaxis_data,
'_colnames_reader': self._colnames_reader,
'_done_tasks': self._done_tasks,
}
)

Expand All @@ -460,6 +466,8 @@ def __reduce__(self):
'yaxis_translation': {
'dims': ('px_data', 'limit'),
'long_name': 'Pixel to data mapping for y-axis'},
'done_tasks': {
'long_name': 'Tasks that are marked as done by the user'},
}

def to_dataset(self, ds=None):
Expand All @@ -483,6 +491,7 @@ def to_dataset(self, ds=None):
self.create_variable(ds, 'axis', ['y', 'x'])
self.create_variable(ds, 'limit', ['vmin', 'vmax'])
self.create_variable(ds, 'px_data', ['pixel', 'data'])
self.create_variable(ds, 'done_tasks', sorted(self._done_tasks))

# full straditizer image
self.create_variable(ds, 'image', self.image)
Expand Down Expand Up @@ -520,6 +529,8 @@ def from_dataset(cls, ds, ax=None, plot=True):
:meth:`to_dataset` method to intialize a new reader"""
stradi = cls(ds['image'].values, ax=ax, plot=plot,
attrs=ds.attrs)
if 'done_tasks' in ds:
stradi._done_tasks = set(ds['done_tasks'].values)
if 'data_lims' in ds:
stradi.data_xlim = ds['data_lims'].sel(axis='x').values
stradi.data_ylim = ds['data_lims'].sel(axis='y').values
Expand Down
16 changes: 13 additions & 3 deletions straditize/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def get_icon(fname):
return osp.join(osp.dirname(__file__), 'icons', fname)


doc_files = glob.glob(get_doc_file('*.rst')) + glob.glob(
get_psy_icon('*.png')) + glob.glob(get_doc_file('*.png')) + \
glob.glob(get_icon('*.png'))


class EnableButton(QPushButton):
"""A `QPushButton` that emits a signal when enabled"""

Expand Down Expand Up @@ -106,6 +111,7 @@ class StraditizerWidgets(QWidget, DockMixin):

def __init__(self, *args, **kwargs):
from straditize.widgets.menu_actions import StraditizerMenuActions
from straditize.widgets.progress_widget import ProgressWidget
from straditize.widgets.data import DigitizingControl
from straditize.widgets.selection_toolbar import SelectionToolbar
from straditize.widgets.marker_control import MarkerControl
Expand Down Expand Up @@ -142,6 +148,10 @@ def __init__(self, *args, **kwargs):
self.tree.setHeaderLabels(['', ''])
self.tree.setColumnCount(2)

self.progress_item = QTreeWidgetItem(0)
self.progress_item.setText(0, 'ToDo list')
self.progress_widget = ProgressWidget(self, self.progress_item)

self.menu_actions_item = QTreeWidgetItem(0)
self.menu_actions_item.setText(0, 'Images import/export')
self.tree.addTopLevelItem(self.menu_actions_item)
Expand Down Expand Up @@ -227,6 +237,7 @@ def __init__(self, *args, **kwargs):

self.apply_button.setEnabled(False)
self.cancel_button.setEnabled(False)
self.tree.expandItem(self.progress_item)
self.tree.expandItem(self.digitizer_item)

# ---------------------------------------------------------------------
Expand Down Expand Up @@ -371,6 +382,7 @@ def refresh(self):
self.attrs_button.setEnabled(enable)
# refresh controls
self.menu_actions.refresh()
self.progress_widget.refresh()
self.digitizer.refresh()
self.selection_toolbar.refresh()
self.plot_control.refresh()
Expand Down Expand Up @@ -608,9 +620,7 @@ def __init__(self, parent, fname=None, rst=None, name=None):
raise ValueError("A title must be specified for the rst document!")
self.fname = fname
self.rst = rst
self.files = glob.glob(get_doc_file('*.rst')) + glob.glob(
get_psy_icon('*.png')) + glob.glob(get_doc_file('*.png')) + \
glob.glob(get_icon('*.png'))
self.files = doc_files
self.name = name
QToolButton.__init__(self, parent)
self.setIcon(QIcon(get_psy_icon('info.png')))
Expand Down
2 changes: 1 addition & 1 deletion straditize/widgets/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def new_reader_for_selection(self, cls=None):
return
cls = readers[name]
reader.new_child_for_cols(cols, cls)
self.fill_cb_readers()
self.straditizer_widgets.refresh()

def change_reader(self, txt):
if not self._change_reader:
Expand Down
6 changes: 4 additions & 2 deletions straditize/widgets/menu_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def check_current():
def _export(self):
fname = self.txt_fname.text()
ending = osp.splitext(fname)[1]
meta = self.stradi.valid_attrs.copy(True)
meta.loc['exported'] = str(dt.datetime.now())
self.stradi.set_attr('exported', str(dt.datetime.now()))
meta = self.stradi.valid_attrs
if ending in ['.xls', '.xlsx']:
with pd.ExcelWriter(fname) as writer:
self.df.to_excel(writer, 'Data')
Expand Down Expand Up @@ -412,9 +412,11 @@ def open_straditizer(self, fname=None, *args, **kwargs):
stradi = Straditizer.from_dataset(ds.load(), *args, **kwargs)
stradi.set_attr('project_file', fname)
ds.close()
stradi.set_attr('loaded', str(dt.datetime.now()))
elif fname.endswith('.pkl'):
stradi = Straditizer.load(fname, *args, **kwargs)
stradi.set_attr('project_file', fname)
stradi.set_attr('loaded', str(dt.datetime.now()))
else:
from PIL import Image
image = Image.open(fname)
Expand Down

0 comments on commit a0ff27a

Please sign in to comment.