Main Application

UI

Starting the application as described in Usage will run the pheno_ui module to start the application.

DeepEtoProfile entry point: pheno_ui.py
  • Defines the pheno_ui class

  • The __main__ method intatiates this class with the number of processing tasks passed as parameter (default = 1) and shows the dialog

class pheno_ui(nProcTasks)

Bases: QMainWindow

The pheno_ui loads the graphic definition from MainWindow.ui and exposes the functionality to the user.

Takes one optional parameter, the maximum number of Docker processing instances - default is 1

nProcTasks: int

Maximum number of processing tasks that will be running in parallel

taskList: TaskList

Contains all the added files

tableData: []

Contains the view of data as it is displayed in the table of the main window

cc: CentralCommand

The background object handling the execution of the annotation processes and the related communication between them and the user interface

taskCounter: int

Counter for videos already added

startCommServer()

Constructs a CentralCommand.CentralCommand object in cc and start it in the background.

connectSignalsSlots()

Establishes communication between pheno_ui and the GUI signals.

connectTableView()

Connects the tableData to the main window. This data will be displayed in a table according to the specification from TaskTableModel.TaskTableModel

addMultipleClicked()

Opens the add_multiple.add_multiple dialog that allows to select and add several video files at once

addTaskClicked()

Opens the add_task.add_task dialog that allows to select, view, and add one video file to be processed

addNewFile(file)

Adds new file to taskList and sets the appropiate events. A new PhenoTask.PhenoTask object is created by calling TaskList.TaskList.addVideo() with file and taskCounter

Slots are created for the new task’s signals and then a new entry is added in tableData.

Parameters

file (str) – the path to the new video file

updateState(id, state)

Updates the displayed state of a task

Parameters
updateProgress(id, progress)

Updates the displayed execution progress of a task

Parameters
  • id (int) – The id of the element to be updated

  • progress (float) – The new progress percentage

closeEvent(event)

Calls the stop method of the CentralCommand.CentralCommand instance in cc before exiting.

class add_task

Bases: QDialog

Dialog that allows to select, view, and add a video to the processing queue.

The visual representation is specified in AddVideo.ui file.

connectSignalsSlots()

Establishes communication between add_task and the GUI signals.

browseButtonClicked()

Opens the selection dialog QFileDialog

In case of success, calls setVideoFile() to displays the video in the current dialog.

setVideoFile(filename)

Creates a QtMultimedia.QMediaPlayer instance and loads the video in the file that was passed as parameter.

Parameters

filename (string) – The path to the video to be displayed

class add_multiple

Bases: QDialog

Dialog allowing the selection and adding of multiple videos from one folder at once.

The visual representation is specified in AddMultiple.ui file.

videoList: []

Array of paths to selected video files. The pheno_ui.pheno_ui instance will check this array for new videos to be added in the processing queue.

connectSignalsSlots()

Establishes communication between add_multiple and the GUI signals.

browseButtonClicked()

Opens the selection dialog QFileDialog

In the case of successful selection, the paths to the videos will be stored in videoList.

class TaskTableModel(data)

Bases: QAbstractTableModel

Models the table representation of the processing queue.

headerData(section: int, orientation: PyQt5.QtCore.Qt.Orientation, role=PyQt5.QtCore.Qt.DisplayRole)

The columns are defined as: Id | File | Status | Progress Inherited from QAbstractTableModel

Parameters
  • section (int) – the section id

  • orientation (Qt.Orientation) – only the horizontal case is handled

  • role (TYPE, optional) – defaults to Qt.DisplayRole

Communication

class CentralCommand(taskList)

Processes the videos added by the user through taskList. This list is updated every time a new video is added or the status of any of the containing tasks is changed.

Provides the communication between the Docker instance(s) and the user interface.

procPortPool: PortPool

A list of ports currently available for opening communication channels to Docker images.

procPort = 20100

An offset for computing the communication ports between the Docker instances and the main application

taskList: TaskList

Contains the list of all the video files that were added by the user. Is passed as parameter when instantiating the class.

start(noProcClients=2)

Starts the method startGUIConnection() in a thread. This will process the videos that are added in the taskList.

Initializes the PortPool with the appropiate number of processes.

Parameters

noProcClients (int, optional) – maximum number of tasks that will be processed in parallel, defaults to 2

stop()

Informs the startGUIConnection() to stop processing new tasks.

The processing of videos in Docker images that are already started will run until they are finished and produce valid, complete results.

startGUIConnection()

Runs a loop as long as the flag started is True. The method is started in a thread by start().

It checks for available communication ports in procPortPool and tasks waiting to be executed in taskList. When it has found both, it starts a new process by calling the method startProc().

startProc(port, task)

Prepares the environment for the processing of a new video. A new Docker instance is created from the image ethoprofiler_nn_av. This image mounts the directory where the video file is found locally at /mnt/data. There is also a mapping between the Docked instance internal port 2000 and the communication port used to connect to the main application.

After the Docker instance is created, a new thread running procVideo() is started to handle the communication with it.

Parameters
  • port (int) – needed to compute the port where the communication between the main application and the Docker instance will happen

  • task (PhenoTask) – PhenoTask object containing the path to the video that will be processed

procVideo(port, task)

Provides an interface with a Docker instance. The communication is performed through a port identified in parameter and the video file to be processed is contained in task.

It updates the task with the current execution status - this will be propagated to the user interface.

Parameters
  • port (int) – offset of the communication port with the Docker instance

  • task (PhenoTask) – contains the video file name and state signals

receiveMessage(connSocket)

Receives a message from a Docker instance through the socket connSocket, decodes it and returns the string version.

Parameters

connSocket (socket.socket) – communication socket where the message is to be received

Returns

decoded version of the received message or ‘’

Return type

str

sendMessage(connSocket, message)

Encodes the message and sends it through the connSocket

Parameters
  • connSocket (connSocket: socket.socket) – socket through which to send the message

  • message (str) – message to be sent

Raises

RuntimeError – in case of failed send

class PhenoTask(id, videoPath)

Bases: QObject

Class encapsulating one video file and it’s current status.

Every time a video is selected for processing a new PhenoTask object is created. The current state and the processing progress are managed here. The class also contains the means to propagate changes to other parts of the application.

Parameters
  • id (int) – the unique id of this task

  • videoPath (str) – the path to the video corresponding to the current task

progressQt

Signal for updating the progress of the current task

alias of int

stateQt

Signal for updating the state of the current task

alias of int

videoPath: str

Full path to the video corresponding to this task

id: int

Unique id of the current task

state: TaskState

The current state of this task, initialized to TaskState.new

progress: int

Progress of the current operation, initialized to 0

dirPath: str

Path to the directory where the video corresponding to this task is found

fileName: str

File name of the video corresponding to this task

setState(state)

Set the state to state of the task and activates the stateQt signal to propagate the change.

Variable progress will be also set to 0.

Parameters

state (TaskState) – new state

setProgress(progress)

Set the state to progress of the task to the progress value in parameter. It also activates the progressQt signal to propagate the change.

Parameters

progress (int) – new progress value

getDirPath()

Returns the folder path where the video corresponding to this task is found.

Returns

folder path from dirPath

Return type

str

getFileName()

Returns the file name of the video corresponding to this task.

Returns

file name from fileName

Return type

str

class PortPool(noPorts)

Class implementing a single access list for managing the allocation of communication ports with the processing instances.

On construction a list of size noPorts is created and initialized to 0, meaning all ports are avaialble.

Parameters

noPorts (int) – the number of ports available for the application

portPool: []

internal array corresponding to the total number of ports and their availability

getPort()

Checks the portPool for an entry of 0, meaning available. The index of the first one found is returned. If none is found, the method returns -1, meaning all ports are already acquired.

Returns

a new positive number if a port is available or -1

Return type

int

resetPort(portId)

Resets the entry in portPool at index portId so that it can be acquired through a subsequent call to getPort()

Parameters

portId (int) – the id of the port to be reset

class TaskList

Class implementing a single access list for managing creation and accessing tasks.

tasksList: []

the list storing all the added tasks

listLock: allocate_lock

lock for accessing the tasksList

addVideo(id, filename)

Creates a new task with the provided parameters and adds it to the list. The list is locked during the process.

Parameters
  • id (int) – the id of the new task

  • filename (str) – the full path of the video file

Returns

the new task

Return type

PhenoTask

getNewTask()

Checks if there are any tasks with TaskState.TaskState.new state in tasksList. If one is found, its status is changed to TaskState.TaskState.selected and then it is returned.

The access to the list is blocked during the execution.

Returns

selected task or None

Return type

PhenoTask

class TaskState(value)

Bases: Enum

Describes the current status of a PhenoTask.PhenoTask

new = 1

just created and queued

processing = 2

currently being processed

finished = 3

processed

error = 4

error state - not used

other = 5

other - not used

selected = 6

selected from the list