Global functions and classes

pydetecdiv

Utilities that can be useful in all places of the code

pydetecdiv.generate_uuid() str

Generate a universal id

Returns:

uuid

Return type:

str

pydetecdiv.copy_files(source: list[str], destination: str) Popen

Copy files from source to destination with OS-specific command

Parameters:
  • source (list of str) – the list of files to copy

  • destination (str) – the destination directory

Returns:

the subprocess copying the files

Return type:

subprocess.Popen

pydetecdiv.delete_files(file_list: Sequence[str]) Popen

Delete files with OS-specific command

Parameters:

file_list (list of str) – the list of files to delete

Returns:

the subprocess deleting the files

Return type:

subprocess.Popen

pydetecdiv.app

Definition of global objects and methods for easy access from all parts of the application

class pydetecdiv.app.DrawingTools(value)

Bases: StrEnum

Enumeration of available drawing tools

class pydetecdiv.app.PyDetecDiv(*args: list)

Bases: QApplication

PyDetecDiv application class extending QApplication to keep track of the current project and main window

static load_plugins() None

Load the available plugins

static check_data_source_paths(table_editor: TableEditor) None

Checks the data source path configuration and proposes a dialog window to edit any definition that may be required for use of shared data sources on the current device

Parameters:

table_editor

static set_main_window(main_window: MainWindow) None

Sets the main window global variable to make it accessible across the whole application

Parameters:

main_window – the Main Window object

static set_apply_drift(apply_drift: bool) None

Sets the global switch for drift correction, so it is available over the whole application

Parameters:

apply_drift – the global drift correction switch

pydetecdiv.app.pydetecdiv_project(project_name: str) Project

Context manager for projects.

Parameters:

project_name – the project name

class pydetecdiv.app.PyDetecDivThread

Bases: QThread

Thread used to run a process defined by a function and its arguments

set_function(func: Callable, *args: list, **kwargs: dict) None

Define the function to run in the thread

Parameters:
  • func – the function to run

  • args – arguments passed to the function

  • kwargs – keyword arguments passed to the function

run() None

Run the function

class pydetecdiv.app.AbstractWaitDialog(parent: QWidget, cancel_msg=None, ignore_close_event=True)

Bases: QDialog

Generic dialog box asking the user to wait for a thread to be finished. This box closes automatically when the thread is complete and the parent window is hidden as well if it is specified. This should be used for processes that do not last too long and that might generate inconsistency if cancelled as there is no possibility to interrupt it

wait_for(func: Callable, *args: list, **kwargs: dict) None

Run function in separate thread and launch local event loop to handle progress bar and cancellation

Parameters:
  • func – the function to run

  • args – positional arguments for the function

  • kwargs – keyword arguments for the function

close_window() None

Hide and destroy the Wait dialog window. The cursor is also set back to its normal aspect.

cancel() None

Set cancelling message and request for interruption of thread so that the running job can cleanly close processes and roll back any modification if needed.

set_ignore_close_event(ignore_close_event: bool = True) None

Set the _ignore_close_event flag to prevent or allow closing the window

Parameters:

ignore_close_event – value to set the flag to

closeEvent(event: QCloseEvent) None

Cancel the job if the window is closed unless close event is ignored by request.

Parameters:

event – close event

class pydetecdiv.app.WaitDialog(msg, parent: QWidget, progress_bar: bool = False, cancel_msg: str = None, ignore_close_event: bool = True)

Bases: AbstractWaitDialog

Generic dialog box asking the user to wait for a thread to be finished. This box closes automatically when the thread is complete and the parent window is hidden as well if it is specified. This should be used for processes that do not last too long and that might generate inconsistency if cancelled as there is no possibility to interrupt it

show_progress(i: int) None

Convenience method to send the progress value to the progress bar widget

Parameters:

i – the value to pass to the progress bar

cancel() None

Set cancelling message and request for interruption of thread so that the running job can cleanly close processes and roll back any modification if needed.

class pydetecdiv.app.MessageDialog(msg: str, html: bool = True)

Bases: QDialog

Generic dialog to communicate a message to the user (error, warning or any other information)

class pydetecdiv.app.ConfirmDialog(msg: str, action: Callable)

Bases: QDialog

Generic dialog asking for confirmation from the user to launch an action

accept()

Close the window and launch action

class pydetecdiv.app.StdoutWaitDialog(msg: str, parent: QWidget, cancel_msg: str = None, ignore_close_event: bool = True)

Bases: AbstractWaitDialog

A Wait dialog that also captures and displays stdout output on the fly.

addText(text: str) None

Add text to the log window

Parameters:

text – the text to add

cancel() None

Set cancelling message and request for interruption of thread so that the running job can cleanly close processes and roll back any modification if needed.

close_window() None

Closes the window and stops stdout capture

stop_redirection(signal: Signal) None

Stops capturing the stdout output, which is therefore printed to the terminal again

Parameters:

signal – the signal triggered by the event requesting to stop redirection

class pydetecdiv.app.StreamRedirector

Bases: QObject

Custom stream redirector to emit stdout/stderr output.

write(text: str) None

Write text to the stream redirector

Parameters:

text – text to be written

flush() None

A dummy method required only for compatibility with the Python IO system

pydetecdiv.app.get_settings() QSettings

Get settings in pydetecdiv.ini file

Returns:

the settings

pydetecdiv.app.get_project_dir(project_name: str = None) str

Gets the directory of a project

Parameters:

project_name – the name of the project

Returns:

the directory path of the project

pydetecdiv.app.project_list() list[str]

Get the list of available projects. This method hides its persistence layer equivalent from other widgets.

Returns:

the list of available projects

pydetecdiv.app.create_app() PyDetecDiv

Creates a GUI application (the global controller for the display layer)

Returns:

the application