Source code for vdat.gui.gui

"""Create and handle the VDAT GUI, as well as some specific functions related
to handling particular elements of the GUI, like the progress
bar.

Originally created: Thu Apr 23 18:47:02 2015 by: PyQt5 UI code generator 5.2.1,
run on output from QtDesigner
"""
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)


import logging
import os
from time import sleep

from PyQt4 import QtCore, QtGui

import vdat.config as vdatconfig
from vdat.gui.buttons_menu import setup_buttons
from vdat.gui.fplane import change_focal_plane_panel, VDATRunControl
from vdat.gui.relay import get_relay
from vdat.libvdat.handlers import TextWindowHandler
from vdat.gui import treeview_model
from vdat.gui.menu import setup_menubar
from vdat.gui.background import get_background


[docs]class Ui_MainWindow(object):
[docs] def setupUi(self, mainWindow): """Set-up the user interface for VDAT Parameters ----------- mainWindow : :class:`PyQt4.QtGui.MainWindow` instance the main window of the application 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 mainWindow.setObjectName("mainWindow") mainWindow.resize(919, 706) mainWindow.setMinimumSize(QtCore.QSize(800, 600)) self.centralwidget = QtGui.QWidget(mainWindow) self.centralwidget.setObjectName("centralwidget") mainWindow.setWindowTitle(_translate("mainWindow", "VDAT - VIRUS Data Analysis Tool")) mainWindow.setCentralWidget(self.centralwidget) # Create the buttons self.buttons_menu = setup_buttons(parent=self.centralwidget) # Treeview and log panel setup self.filebrowser_treeView =\ treeview_model.setup_filebrowser(self.centralwidget) self.filebrowser_treeView.button_widget = self.buttons_menu self.log_panel = self.setup_logpanel() # Setup a progress bar self.prog_bar = QtGui.QProgressBar(parent=self.centralwidget) # Setup menu bar self.menubar = QtGui.QMenuBar(mainWindow) setup_menubar(self.menubar) self.menubar.setGeometry(QtCore.QRect(0, 0, 919, 20)) self.menubar.setObjectName("menubar") mainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(mainWindow) self.statusbar.setObjectName("statusbar") mainWindow.setStatusBar(self.statusbar) QtCore.QMetaObject.connectSlotsByName(mainWindow) # Connect signals to useful sockets, so # the code can communicate with the GUI signals = get_relay() signals.update_filebrowser.connect(self.update_filebrowser) signals.update_progressbar.connect(self.update_progressbar) signals.change_centralPanel.connect(self.change_centralPanel) # Setup central panel self.centralPanel = QtGui.QWidget() self.setup_layout()
[docs] def setup_layout(self): """ Setup the overall layout of the GUI """ self.gridLayout = QtGui.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") # Add everything to the layout self.gridLayout.addWidget(self.centralPanel, 0, 2, 1, 1) self.gridLayout.addWidget(self.filebrowser_treeView, 0, 0, 1, 1) self.gridLayout.addWidget(self.log_panel, 1, 0, 1, 4) self.gridLayout.addWidget(self.prog_bar, 2, 0, 1, 4) self.gridLayout.addWidget(self.buttons_menu, 0, 3, 1, 1)
[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 # stop the IFU loop VDATRunControl.ifu_loop = False i = 0 bg = get_background() log = logging.getLogger('logger') log.info("VDAT is shutting down (this should take no more than 10" " seconds). Bye!") # wait at most 10 seconds for the tasks to stop while i < 100 and bg.isImmRunning: sleep(0.1) i = i + 1 except Exception as e: print("Error when shutting down!") print(e) print("Quitting messy-ly") QtGui.QApplication.quit()
[docs] def change_centralPanel(self, type_): """ Change the central panel of VDAT Parameters ---------- type_ : str a type of display from the tabs.yml file """ self.centralPanel = change_focal_plane_panel(type_) self.gridLayout.addWidget(self.centralPanel, 0, 2, 1, 1)
[docs] def update_progressbar(self, maximum, value): """Update the progress bar. Parameters ---------- maximum : int The total number of output files to produce. value : int The number produced so far. """ self.prog_bar.setMaximum(maximum) self.prog_bar.setValue(value)
[docs] def update_filebrowser(self): """Point the filebrowser at the redux dir """ conf = vdatconfig.get_config('main') redux_dir = os.path.abspath(conf.get("general", 'redux_dir')) self.fmodel.setRootPath(redux_dir) self.filebrowser_treeView.setRootIndex(self.fmodel.index(redux_dir))
[docs] def setup_logpanel(self): """Setup a text browser with which to read output from the code/cure Returns ------- :class:`PyQt4.QtGui.QTextEdit` A text browser widget """ logger = logging.getLogger('logger') log_panel = QtGui.QTextEdit(self.centralwidget) log_panel.setEnabled(True) log_panel.setReadOnly(True) log_panel.setMaximumSize(QtCore.QSize(16777215, 350)) log_panel.setAcceptDrops(False) log_panel.setObjectName("log_panel") # Attach this to the logger logger.addHandler(TextWindowHandler(browser=log_panel, parent=log_panel)) return log_panel