gui – The Graphical User Interface

The Main Window

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

class vdat.gui.gui.Ui_MainWindow[source]
setupUi(mainWindow)[source]

Set-up the user interface for VDAT

Parameters:

mainWindow : PyQt4.QtGui.MainWindow instance

the main window of the application

queue : vdat.gui.queue.Queue instance

queue where to push the command. It must have a add_command method

setup_layout()[source]

Setup the overall layout of the GUI

closeEvent(event)[source]

Override the user closing the window. Instead wait for anything on the immediate queue to finish running and then quit.

change_centralPanel(type_)[source]

Change the central panel of VDAT

Parameters:

type_ : str

a type of display from the tabs.yml file

update_progressbar(maximum, value)[source]

Update the progress bar.

Parameters:

maximum : int

The total number of output files to produce.

value : int

The number produced so far.

update_filebrowser()[source]

Point the filebrowser at the redux dir

setup_logpanel()[source]

Setup a text browser with which to read output from the code/cure

Returns:

PyQt4.QtGui.QTextEdit

A text browser widget

Panel with the focal plane

class vdat.gui.fplane.VDATRunControl[source]

Class to store variable which controls looping over IFUs

ifu_loop = True
vdat.gui.fplane.current_fplane()[source]

Return the current focal plane (or none if not set)

Returns:

fplane : pyhetdex.het.fplane.FPlane

the fplane (with the IFUs) of the currently displayed central panel

vdat.gui.fplane.yield_all_ifus()[source]

Grabs the IFUs from the fplane class variable of FplanePanel and check that that the IFUs have been properly initialized.

Returns:

ifu : vdat.gui.ifu_widget.IFUWidget

pyhetdex IFU objects

vdat.gui.fplane.yield_selected_ifus()[source]

Grabs the IFUs from the fplane class variable of FplanePanel and check that that the IFUs have been properly initialized. Yield selected IFUs

Returns:

ifu : vdat.gui.ifu_widget.IFUWidget

pyhetdex IFU objects

vdat.gui.fplane.select_all_ifus()[source]

Selects all IFUs in the FPlanePanel

vdat.gui.fplane.deselect_all_ifus()[source]

Selects all IFUs in the FPlanePanel

vdat.gui.fplane.change_focal_plane_panel(type_, parent=None)[source]

Create a new focal plane panel, and save it in the global. Delete the old one.

Returns:

__FPLANEPANEL__ : class:FplanePanel

a panel showing the focal plane

class vdat.gui.fplane.FplanePanel(type_, parent=None)[source]

Class to create and handle the focal plane window in the GUI

Set up the basic elements, like the combo box and the widget, of a viewer of HETDEX focal planes

Parameters:

type_ : str

a name of one of the sections of the tabs.yml file (e.g. cal, sci...)

updateScaleBoxes
update_scale_boxes(min_scale, max_scale)[source]

Update the contents of the image scale boxes

Parameters:

min_scale : float

value to display in the min_scale box

max_scale : float

value to display in the max_scale box

set_scaling()[source]

Set the image scale parameters, based on what is written in the min_cut and max_cut boxes.

set_scaling_mode(option_string, noFplane=False)[source]

Set what type of image scaling the focal plane has.

Parameters:

option_string: str

“Global scaling” or “individual scaling”

noFplane : optional

if true, do nbot attempt to update the IFUs in the panel

update_ifus(display_type)[source]

Loop through an fplane object plotting the IFUs

Parameters:

display_type : str

an entry in a tabs subsection of tabs.yml. Determines what is shown as a thumbnail for the IFU

A Custom Model for the Treeview Widget

A model to populate a treeview

Widget with custom items.

This was written following this tutorial

Examples

Simple hierachy

+- 20150622
    +-- Calibration
        +--- Model-1
        +--- Model-2
        +--- Model-3
+-- RawScience
>>>  model = ReductionTreeviewModel()
>>>  nights = ReductionNode("Nights", 1, model)
>>>  model.rootnode = nights
>>>  night1 = ReductionNode("20150622", 1, model, parent=nights)
>>>  nights.add_subnode(night1)
>>>  cal    = ReductionNode("Calibration", 1, model, parent=night1)
>>>  night1.add_subnode(cal)
>>>  cal.add_subnode(ReductionNode("Models-1",  1, model, parent=cal))
>>>  cal.add_subnode(ReductionNode("Models-2",  2, model, parent=cal))
>>>  cal.add_subnode(ReductionNode("Models-3",  3, model, parent=cal))
>>>  rawsci = ReductionNode("RawScience", 2, model, parent=night1)
>>>  night1.add_subnode(rawsci)
class vdat.gui.treeview_model.ReductionNode(name, path, row, model, type_=u'', selectable=False, checkable=False, parent=None)[source]

A class to store nodes in the custom treeview model.

Parameters:

name : String

a label for the node to appear in the treeview

path : string

path associated with the name

row : int

which row the node is on

model : ReductionTreeviewModel instance

the model to attach the node to

type_ : string

type of the shot in the node

selectable : bool, optional

where the current node is selectable or not

checkable : bool, optional

where the current node can have a check box associated

parent : ReductionNode instance, optional

parent of the current node

Attributes

name, row, model, parent (as in the parameters)
column (int) column index
subnodes (list) sub-nodes of the current node
index()[source]

Return the index of the node

Returns:

index : QModelIndex instance

an index to this node

add_subnode(node)[source]

Add a subnode to the current node

Parameters:

node : QModelIndex instance

the index of a subnode to add

subnode(row)[source]

Get the child at row

Parameters:

row : int

index of the child

Returns:

ReductionNode instance

required child

class vdat.gui.treeview_model.ReductionTreeviewModel(parent=None, column_title=u'Reduction Browser')[source]

A model that stores the tree structure for the treeview widget

Parameters:

parent : qtobject

parent object of the tree view model

column_title : string, optional

title of the column

rootnode[source]

Get the rootnode of this tree

Returns:

node : ReductionNode instance

the index of the node you want to be root node

checked_nodes[source]

Return the checked nodes.

setData() makes sure that at most one node per type is selected

Returns:

dictionary

key: type (str) of the node (‘sci’, ‘cal’) value: corresponding node instance

columnCount(parentIndex)[source]

Return number of columns, for us this is always 1

Parameters:

parentIndex : PyQt4.QtCore.QModelIndex

index to the parent node

Returns:

int

the number of columns under parent: always 1

rowCount(parentIndex)[source]

Return the number of subnodes under a parent node

Parameters:

parentIndex : PyQt4.QtCore.QModelIndex

index to the parent node

Returns:

nrows : int

the number of rows under parent

headerData(section, orientation, role)[source]

Return information about the header items

Parameters:

section : int

the section for which this is the header

orientation : int

flag indicating whether the header is horizontal or vertical

role : int

flag specifying the type of info requested (i.e. a title for the header, or an icon etc.)

data(index, role)[source]

Return information about the specified node

Parameters:

index : QtCore.QModelIndex instance

the index of the node you want data for

role : int

flag specifying the type of info requested (i.e. a title or an icon etc.)

setData(index, value, role)[source]

If the role is QtCore.Qt.CheckStateRole, change the check status of the index, making sure that at most one element per checkable node type is selected.

Parameters:

index : QtCore.QModelIndex instance

the index of the node you want data for

value :

value to set (ignored)

role : int

flag specifying the type of info requested (i.e. a title or an icon etc.)

flags(index)[source]
index(row, column, parentIndex)[source]

Return the index of the node with row, column and parent

Implementation from https://www.mail-archive.com/pyqt@riverbankcomputing.com/msg19414.html

Parameters:

row, column : int

index of the row and the column

parentIndex : QModelIndex

index to the parent node

Returns:

QtCore.QModelIndex

index of the node

parent(index)[source]

Return an index to the parent of the node with index

Parameters:

index : QtCore.QModelIndex instance

the index of the node you want the parent of

Returns:

QtCore.QModelIndex instance

the index of the parent (if the node has a parent)

insertRow(node, row, parent=<PyQt4.QtCore.QModelIndex object at 0x7eff50d0ec08>)[source]

Insert node in a new row before the given row

removeRows(row, count, parent=<PyQt4.QtCore.QModelIndex object at 0x7eff50d0ecf8>)[source]

Remove count rows starting at row

class vdat.gui.treeview_model.ReductionQTreeView(parent)[source]

Custom tree view widget

button_widget[source]

Returns the button widget

_pressed(index)[source]

Action executed when selecting a new

option_menu(position)[source]

Add an action menu to the tree view

Parameters:position : PyQt4.QtCore.QPoint instance
_clone_dir(index, node)[source]

Clone the directory associated to node and add it to the tree view and to the database

Parameters:

index : QModelIndex instance

index of the selected node

node : class:ReductionNode instance

selected node

_new_dir_name(original_name, parent_path)[source]

Ask the user the new directory name

Parameters:

original_name : string

name of the directory we are about to copy

parent_path : string

path of the parent directory of original_name

Returns:

new_name : string

name of the new directory

_clone_dialog(default_text, label_prefix=u'')[source]

Create a text dialog with the default text

Parameters:

default_text : string

text set by default in the dialog

label_prefix : string

if not empty added in the line before the standard label

Returns:

string

text from the dialog

_copy_dir(parent_path, src, dst, db_entry)[source]

Copy the directory src to dst. Both are children of parent_path.

Also set to true the is_clone entry in the shot file

Parameters:

parent_path : string

path where the original and new directories live

src, dst : string

copy src into dst

_insert_row(index, new_name)[source]

Clone node, update it and insert it

Parameters:

index : QModelIndex instance

index of the selected node

new_name : string

name of the new entry

_remove_dir(index, node)[source]

Remove the directory associated to node and add it to the tree view and to the database

Parameters:

index : QModelIndex instance

index of the selected node

node : class:ReductionNode instance

selected node

_confirm_remove_dialog(dir_name)[source]

Create the dialog to ask if you are sure

Parameters:

dir_name : string

name of the directory

Returns:

bool

where the directory can be removed

vdat.gui.treeview_model.setup_filebrowser(parent=None)[source]

Setup a treeview widget with which to browse the file structure

Parameters:

parent : QWidget

parent of the tree view

Returns:

PyQt4.QtGui.QTreeView instance

tree view widget

vdat.gui.treeview_model.create_dirstructure(parent=None)[source]

Create the directory structure in the redux directory

Parameters:

parent : QWidget

parent of the tree view

Returns:

model : ReductionTreeviewModel instance

The Queue window

Form implementation generated from reading ui file ‘listWindow.ui’

Created: Mon Jun 15 16:25:52 2015 by: PyQt4 UI code generator 4.10.4

class vdat.gui.queue.QueuedCommand(command, label, tool_tip=None, parent=None)[source]

A container for commands on the queue. Also saves the current config object.

Parameters:

command : CommandInterpreter

instance of the command interpreter to add to the queue

label : string

A label to appear for this command on the queue

tool_tip : string, optional

tool tip to show

parent : QtWidget instance

The QtWidget that the menu is attached to

class vdat.gui.queue.ModifyableListWidget[source]

Adds the ability to delete and modify items on the list by hand

keyPressEvent(event)[source]

Override the default method, removing the selected entry

Parameters:

event : QKeyEvent

object containing details of the key the user pressed

delete_selected()[source]

Delete all commands selected by the user

class vdat.gui.queue.Queue(parent=None)[source]

A queue that stores user commands and displays them in a GUI window.

closeSignal
job_added

A signal emitted when a job is added to the queue

setupUi()[source]

Setup the queue window

closeEvent(event)[source]

Override the user closing the window

toggle(tggl)[source]

Hide or show the panel

add_command(command, label, tool_tip=None)[source]

Add a command to the queue. Emit the job_added signal.

Parameters:

command : CommandInterpreter

instance of the command interpreter to add to the queue

label : string

A label to appear for this command on the queue

tool_tip : string, optional

tool tip to show

get_command()[source]

Get the top item from the queue.

Returns:

cmd : Callable

the function on the queue. None is queue empty

config : pyhetdex.tools.configuration.ConfigParser instance

the configuration with which to run the command (includes target directories). None if queue empty

Todo

Check that not deleting the item doesnt cause a memory leak.

class vdat.gui.queue.QueuAction(*args, **kwargs)[source]

Action for the queue window.

Create the menu entry and binds signals known by the queue window to show/hide it

_update_text(toggled)[source]
vdat.gui.queue.set_queue(parent=None)[source]

Create a Queue instance and save it. You can access it with get_queue()

Parameters:

parent : QtWidget instance

The QtWidget that the menu is attached to

vdat.gui.queue.get_queue()[source]

Get the locally stored Queue instance

Widgets for buttons and IFUs

Panel containing buttons to run reduction steps

class vdat.gui.buttons_menu.ButtonsMenu(parent=None, name=u'buttons_widget')[source]

Parent widget containing the buttons to run the reduction steps

Parameters:

parent : QtWidget instance

The QtWidget that the menu is attached to

name : string

name of the widget

get_subwidget(name)[source]

Returns a sub-widget called name. Create it if needed

setCurrentWidgetByName(name)[source]

Set the current widget by name

Parameters:

name : string

name associated with the widget

class vdat.gui.buttons_menu.ButtonWidget(parent=None, name=u'')[source]

Actual widget containing the buttons

Parameters:

parent : QtWidget instance

The QtWidget that the menu is attached to

name : string

name of the widget

add_button(name, commands, tool_tip=None)[source]

Adds a button to the widget.

Parameters:

name : string

name of the button

commands : list of strings, optional

strings defining the commands

tool_tip : string, optional

text that appears as a tool tip when the user hovers their mouse over the button

add_stretch(stretch=1)[source]

Add a stretch to the layout containing the buttons

Parameters:

stretch : int, optional

stretch factor

class vdat.gui.buttons_menu.CommandButton(name, commands, tool_tip=None, parent=None)[source]

Custom class implementing the button.

Parameters:

name : string

name of the button

commands : list of strings, optional

strings defining the commands

tool_tip : string, optional

text that appears as a tool tip when the user hovers their mouse over the button

parent : QtWidget instance

The QtWidget that the menu is attached to

Attributes

commands  
_callback()[source]
_config_with_dirs(command_name)[source]

Get the command configuration and add target_dir, zero_dir and cal_dir to the configuration.

Parameters:

command_name : string

name of the command

Returns:

command_conf : dict

configuration dictionary for the command at hand

_error_dialog(error, command)[source]

Create the dialog to show the error

Parameters:

error : Exception instance

error raised by the constructor

command : string

full command string

_selected_ifus()[source]

Collect the selected IFUs and return a list of ifu

vdat.gui.buttons_menu.setup_buttons(parent=None)[source]

Set up and return the buttons

Parameters:

parent : PyQt4.QtGui.QWidget

parent of the button widget

Returns:

ButtonsMenu

button widgets container

Widget showing the IFU in the focal plane

class vdat.gui.ifu_widget.IFUWidget(ifuid, x, y, xid, yid, specid, parent=None)[source]

A custom class, derived from QLabel, desgined to contain a picture of the IFU.

Initialize the widget and set a background colour and picture. Set the passed ifu ‘selected’ parameter and set a appropriate style for the border that reflects whether the IFU is selected or not. Save a reference to the IFU object.

Parameters:

ifuid : string

id of the ifu

x, y : string or float

x and y position of the ifu in the focal plane

xid, yid : string or int

x (column) and y (row) id of the ifu in the ifu head mounting plate (IHMP)

specid : string

id of the spectrograph where the ifu is plugged into

parent : QWidget or derived instance, optional

A window to parent the widget to.

set_image_signal

A signal that triggers setImage(), allowing the image on the IFU widget to be prompted to update from a thread

setImage()[source]

Set the image on the Widget, based on whether or not the IFU has any input files, and as to whether any thumbnail exists for the IFU

Todo

Consider saving processing time by having scaled versions of the empty.png and unreduced.png as class variables

mouseDoubleClickEvent(event)[source]

On double click open a popup with details on the selected IFU

mouseReleaseEvent(event)[source]

On a user clicking on the button, swap the logical value of the ifu.selected parameter and change the look of the button to reflect this.

Parameters:event : QMouseReleaseEvent
selected[source]
exists[source]

Background

Connection between the gui and the background thread to keep the gui responsive as vdat works

class vdat.gui.background.Worker(func, bg, immediate, *args, **kwargs)[source]

A worker object to stick into a QThread so it can run in the background and allow the GUI to still be responsive.

Attributes

finished (pyqtSignal) qt signal
Parameters:

func : callable

function to execute

bg : Background object

The background the worker is running in

immediate : bool

True if job is on the immediate thread

args : list

positional arguments to pass to the function

kwargs : dictionary

keyword arguments to pass to the function

finished
run()[source]

Run the function! Then emit a signal telling the rest of the code it’s done.

class vdat.gui.background.Relay(parent=None)[source]

Signals have to be attached to an object. This object contain the signal that is used to trigger Workers in the background thread.

Attributes

signal (pyqtSignal) qt signal
signal
emit()[source]
connect(call)[source]
class vdat.gui.background.Background(parent=None)[source]

Run a multiple QThreads in the background.

By doing this the GUI can remain response whilst the code is doing work. Have to keep the same QThread throughout as the VDAT database has to be queried from the Thread that created it.

The background needs to be given a queue to read jobs from.

queue[source]
run_now(func, conf, *args, **kwargs)[source]

Run a job on the immediate thread. These jobs don’t queue but kick off the old job and start up immediately (the functions have to be specially designed, see below)

Parameters:

func : function

this function must start by setting VDATRunControl.ifu_loop = True and stop when this variable is false

conf : vdat config object

run(*args, **kwargs)[source]

Grab a job from the queue and run it on the background thread if the thread is not already busy. Works its way recursively through the queue, until the queue is empty.

vdat.gui.background.set_backgound(parent)[source]

Set up a background instance

Parameters:

parent : QtWidget instance

The QtWidget that the menu is attached to

vdat.gui.background.get_background()[source]

Returns the Background instance created by set_backgound()