Skip to content

Commit

Permalink
ENH: Add drag and drop for files tab; testing; fixed updating global …
Browse files Browse the repository at this point in the history
…settings
  • Loading branch information
leloup314 committed May 18, 2017
1 parent 5c2bfec commit 678fae6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
10 changes: 5 additions & 5 deletions testbeam_analysis/gui/analysis_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ def _call_funcs(self):
"""
Call all functions in a row
"""
# pool = Pool()
pool = Pool()
for func, kwargs in self.calls.iteritems():
print(func.__name__, kwargs)
# pool.apply_async(self._call_func(func, kwargs))
# pool.close()
# pool.join()
# print(func.__name__, kwargs)
pool.apply_async(self._call_func(func, kwargs))
pool.close()
pool.join()

# Emit signal to indicate end of analysis
if self.tab_list is not None:
Expand Down
41 changes: 41 additions & 0 deletions testbeam_analysis/gui/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import tables as tb
import logging

from PyQt5 import QtCore, QtWidgets, QtGui

Expand Down Expand Up @@ -33,6 +34,7 @@ def _setup(self):
tab_layout = QtWidgets.QHBoxLayout()
left_widget.setLayout(tab_layout)
self._data_table = DataTable(parent=left_widget)
self._data_table.dragAndDropText.connect(lambda msg: self._emit_message(msg))
tab_layout.addWidget(self._data_table)

# Make option area
Expand Down Expand Up @@ -189,6 +191,7 @@ class DataTable(QtWidgets.QTableWidget):
"""

inputFilesChanged = QtCore.pyqtSignal()
dragAndDropText = QtCore.pyqtSignal('QString')

def __init__(self, parent=None):
super(DataTable, self).__init__(parent)
Expand All @@ -210,6 +213,44 @@ def __init__(self, parent=None):
self.setSortingEnabled(True)
self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)

# Drag and drop related
self.setAcceptDrops(True)
self.setMouseTracking(True)

def mouseMoveEvent(self, event):
if self.underMouse() and not self.input_files:
msg = 'Select files via the button on the right or "Drag & Drop" files directly onto table area'
self.dragAndDropText.emit(msg)
else:
self.setMouseTracking(False)

def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()

def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
else:
event.ignore()

def dropEvent(self, event):
if event.mimeData().hasUrls():
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
for url in event.mimeData().urls():
if '.h5' in url.toLocalFile():
self.input_files.append(url.toLocalFile())
else:
msg = 'Files must be HDF5-format'
logging.warning(msg)
self.handle_data()
else:
event.ignore()

def get_data(self):
"""
Open file dialog and select data files. Only *.h5 files are allowed
Expand Down
24 changes: 15 additions & 9 deletions testbeam_analysis/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def __init__(self, parent=None):
# Make dict to access tab widgets
self.tw = {}

# Add bool to indicate whether setup tab has been executed
self.setup_done = False

self._init_UI()

def _init_UI(self):
Expand Down Expand Up @@ -223,8 +226,9 @@ def connect_tabs(self, tabs=None):
self.tw[name].proceedAnalysis.connect(lambda: self.tw['Setup'].input_data(self.tw['Files'].data))

if name == 'Setup':
self.tw[name].proceedAnalysis.connect(lambda: self.update_tabs(data=self.tw['Setup'].data,
skip='Setup'))
for x in [lambda: self.update_tabs(data=self.tw['Setup'].data, skip='Setup'),
lambda: self.setup_complete()]:
self.tw[name].proceedAnalysis.connect(x)

if name == 'Alignment':
self.tw[name].skipAlignment.connect(lambda: self.update_tabs(data={'skip_alignment': True},
Expand All @@ -237,14 +241,13 @@ def connect_tabs(self, tabs=None):
except (AttributeError, KeyError):
pass

def update_tabs(self, data=None, tabs=None, skip=None, skip_alignment=False):
def update_tabs(self, data=None, tabs=None, skip=None):
"""
Updates the setup and options with data from the SetupTab and then updates the tabs
:param tabs: list of strings with tab names that should be updated, if None update all
:param data: dict with all information necessary to perform analysis, if None only update tabs
:param skip: str or list of tab names which should be skipped when updating tabs
:param skip_alignment: bool whether alignment was skipped or not
"""

# Save users current tab position
Expand All @@ -267,9 +270,9 @@ def update_tabs(self, data=None, tabs=None, skip=None, skip_alignment=False):

if skip is not None:
if isinstance(skip, list):
for tab in skip:
if tab in update_tabs:
update_tabs.remove(tab)
for t_name in skip:
if t_name in update_tabs:
update_tabs.remove(t_name)
else:
if skip in update_tabs:
update_tabs.remove(skip)
Expand Down Expand Up @@ -318,7 +321,6 @@ def update_tabs(self, data=None, tabs=None, skip=None, skip_alignment=False):
setup=self.setup,
options=self.options)
else:
# logging.info('Gui for %s not implemented yet!' % name)
continue

tmp_tw[name] = widget
Expand All @@ -343,6 +345,9 @@ def update_tabs(self, data=None, tabs=None, skip=None, skip_alignment=False):
# Connect updated tabs
self.connect_tabs(tabs)

def setup_complete(self):
self.setup_done = True

def global_settings(self):
"""
Creates a child SettingsWindow of the analysis window to change global settings
Expand All @@ -359,7 +364,8 @@ def update_globals(self):
self.setup = self.settings_window.setup
self.options = self.settings_window.options

self.update_tabs(skip='Setup')
if self.setup_done:
self.update_tabs(skip='Setup')

def save_session(self):
"""
Expand Down

0 comments on commit 678fae6

Please sign in to comment.