Source code for vdat.gui.mainwindow
# Virus Data Analysis Tool: a data reduction GUI for HETDEX/VIRUS data
# Copyright (C) 2016, 2017, 2018 "The HETDEX collaboration"
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Create the main window of the VDAT GUI
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import logging
import os
from qtpy import QtCore, QtGui, QtWidgets
import vdat.config as vdatconfig
from vdat.gui.menubar import VDATMenuBar
from vdat.gui.queue import set_queue, get_queue
from vdat.gui.mainwidget import VDATMainWidget
from vdat.gui.progress import VDATStatusBar
from vdat.gui.logger_widget import TextWindowHandler
from vdat.gui.utils import static_directory
[docs]class VDATMainWindow(QtWidgets.QMainWindow):
'''VDAT customisation of the main window.
.. list-table:: **Custom slot**
:header-rows: 1
* - Name
- Signature
- Description
* - :meth:`remove_files`
- list, list
- run the removal of files in a thread and change the cursor to the
wait cursor
.. list-table:: **Connections between custom signals and/or slots**
:header-rows: 1
* - Signal
- Slot
* - :attr:`vdat.gui.queue.Queue.global_logger`
- :meth:`logging.Logger.log`
* - :attr:`vdat.gui.queue.Queue.progress`
- :meth:`vdat.gui.progress.VDATProgressBar.update_bar`
* - :attr:`vdat.gui.queue.Queue.n_primaries`
- :meth:`vdat.gui.progress.VDATProgressBar.setup_bar`
* - :attr:`vdat.gui.queue.Queue.command_done`
- :meth:`vdat.gui.progress.VDATProgressBar.reset_bar`
* - :attr:`vdat.gui.queue.Queue.command_string`
- :meth:`vdat.gui.progress.VDATStatusBar.clear_message`
* - :attr:`vdat.gui.queue.Queue.command_done`
- :meth:`vdat.gui.progress.VDATStatusBar.running_command`
* - :attr:`vdat.gui.menubar.VDATMenuBar.sig_close`
- :meth:`vdat.gui.mainwidget.VDATMainWidget.close`
* - :attr:`vdat.gui.menubar.VDATMenuBar.sig_symlink`
- :meth:`vdat.gui.mainwidget.VDATMainWidget.redoSymlink`
* - :attr:`vdat.gui.menubar.VDATMenuBar.sig_selectAll`
- :meth:`vdat.gui.mainwidget.VDATMainWidget.selectAllIFUs`
* - :attr:`vdat.gui.menubar.VDATMenuBar.sig_selectNone`
- :meth:`vdat.gui.mainwidget.VDATMainWidget.deselectAllIFUs`
* - :attr:`vdat.gui.menubar.VDATMenuBar.sig_remove_files`
- :meth:`remove_files`
* - :attr:`vdat.gui.treeview_model.ReductionQTreeView.sig_selectionChanged`
- :meth:`vdat.gui.menubar.VDATMenuBar.enable_on_selection`
* - :attr:`vdat.gui.menubar.TreeViewMenu.sig_collapse`
- :meth:`vdat.gui.treeview_model.ReductionQTreeView.collapseAll`
* - :attr:`vdat.gui.menubar.TreeViewMenu.sig_expand`
- :meth:`vdat.gui.treeview_model.ReductionQTreeView.expandAll`
'''
def __init__(self, ):
super(VDATMainWindow, self).__init__()
set_queue(parent=self)
self.setup()
self.connect_queue()
self.connect_menubar()
[docs] def connect_queue(self):
'connect signals from the queue'
queue = get_queue()
queue.global_logger.connect(logging.getLogger('logger').log)
queue.progress.connect(self.vdat_main.prog_bar.update_bar)
queue.n_primaries.connect(self.vdat_main.prog_bar.setup_bar)
queue.command_done.connect(self.vdat_main.prog_bar.reset_bar)
queue.command_string.connect(self.statusbar.running_command)
queue.command_done.connect(self.statusbar.clear_message)
[docs] def connect_menubar(self):
'''Connect the signals from the menu bar'''
self.menubar.sig_close.connect(self.close)
conf = vdatconfig.get_config('main', section='general')
if conf['rawdir']:
self.menubar.sig_symlink.connect(self.vdat_main.redoSymlink)
self.menubar.enableSymlink(True)
else:
self.menubar.enableSymlink(False)
self.menubar.sig_selectAll.connect(self.vdat_main.selectAllIFUs)
self.menubar.sig_selectNone.connect(self.vdat_main.deselectAllIFUs)
self.menubar.sig_remove_files.connect(self.remove_files)
(self.vdat_main.tree_view
.sig_selectionChanged.connect(self.menubar.enable_on_selection))
self.menubar.sig_collapse.connect(self.vdat_main.tree_view.collapseAll)
self.menubar.sig_expand.connect(self.vdat_main.tree_view.expandAll)
self.menubar.sig_clear_log.connect(self.vdat_main.log_panel.clear)
[docs] def setup(self):
"""Set-up the user interface for VDAT
Parameters
-----------
queue : :class:`vdat.gui.queue.Queue` instance
queue where to push the command. It must have a ``add_command``
method
"""
_translate = QtCore.QCoreApplication.translate
# Set up the basics of the main window
self.setObjectName("mainWindow")
self.resize(1000, 700)
self.setMinimumSize(QtCore.QSize(800, 600))
self.vdat_main = VDATMainWidget(self)
self.vdat_main.setObjectName("centralwidget")
self.setWindowTitle(_translate("mainWindow",
"VDAT - VIRUS Data Analysis Tool"))
self.setWindowIcon(QtGui.QIcon(os.path.join(static_directory(),
'vdat_icon.jpg')))
self.setCentralWidget(self.vdat_main)
self.vdat_main.setup()
# Setup menu bar
self.menubar = VDATMenuBar(parent=self)
# TODO attach menubar signals correctly
self.setMenuBar(self.menubar)
self.statusbar = VDATStatusBar(self)
self.setStatusBar(self.statusbar)
[docs] def closeEvent(self, event):
"""Override the user closing the window. Instead wait for anything on
the immediate queue to finish running and then quit.
"""
# wrap in a try, except so it always quits in the end
try:
event.ignore() # Ignore the request
log = logging.getLogger('logger')
remove_handlers = [h for h in log.handlers
if isinstance(h, TextWindowHandler)]
for rh in remove_handlers:
log.removeHandler(rh)
log.info("VDAT is shutting down (this should take no more than 10"
" seconds). Bye!")
except Exception as e:
print("Error when shutting down!")
print(e)
print("Quitting messy-ly")
QtWidgets.QApplication.quit()
[docs] @QtCore.Slot(list, list)
def remove_files(self, paths, matches):
'''Slot to connect the
:attr:`vdat.gui.menubar.VDATMenuBar.sig_remove_files` signal that
removes the files in a thread. The mouse cursor is temporarily set to
wait.
Parameters
----------
paths : list of strings
paths containing the files to remove
matches : list of string
file names or wildcards pattern for removal
'''
import vdat.gui.utils as vutils
vutils.run_wait_func_qthread(vutils.delete_files, paths, matches,
parent=self)