Modules

kvalikirstu2.arg_parser.py

A module for the argument parser class in Kvalikirstu.

exception kvalikirstu2.arg_parser.ConfigFileParsingException[source]

Bases: Exception

Raised when parsing args fails (during gui run)

class kvalikirstu2.arg_parser.Kvalikirstu2ConfigArgParser(*args, config_files=[], encoding='utf-8', **kwargs)[source]

Bases: configargparse.ArgumentParser

A class derived from configargparse.ArgumentParser for parsing arguments. Adds support for custom encoding.

error(message)[source]

Overwrites argparse error method so that systemexit is not called within gui

Parameters

message (str) – The error message.

kvalikirstu2.argument_parser.py

A module for parsing command line arguments and logging.

exception kvalikirstu2.argument_parser.ArgumentsNotParsedException[source]

Bases: Exception

get_args called before parsing arguments

exception kvalikirstu2.argument_parser.ArgumentsNotSavedException(inner_exception, *args, **kwargs)[source]

Bases: Exception

Exception occurred while saving args.

exception kvalikirstu2.argument_parser.ConfigFileParsingException[source]

Bases: Exception

Raised when parsing args fails (during gui run)

class kvalikirstu2.argument_parser.Settings[source]

Bases: object

Class for command line settings.

get_shared_args()[source]

Gets arguments that are shared between the GUI and the cmd version

parse_command_line(args)[source]

Parse command line arguments and assign parser options to settings.

Parameters

argv – arguments passed to configargparse.ArgumentParser

Returns

parsed arguments.

Return type

argparse.Namespace

parse_gui(args)[source]

Parse GUI arguments and return parser’s namespace.

Parameters

argv – arguments passed to configargparse.ArgumentParser

Returns

parsed arguments.

Return type

argparse.Namespace

set_up_cli_settings(argv)[source]

Sets up settings with command line arguments and starts logging

set_up_gui_settings(argv)[source]

Sets up settings and starts logging

setup_logging()[source]

Setup :mod: logging module.

kvalikirstu2.argument_parser.change_setting(setting_title, new_value)[source]

Change a single setting

Parameters
  • setting_title – The name of the setting.

  • new_value – The new value for the setting.

kvalikirstu2.argument_parser.get_args()[source]

Gets command line/config file arguments

kvalikirstu2.argument_parser.get_languages()[source]

Get language codes from the configuration.

kvalikirstu2.argument_parser.print_help()[source]

Print parser help message

kvalikirstu2.argument_parser.register_archive_interface(interface)[source]

Called when the package is loaded to allow for data archive specific arguments to be loaded.

Parameters

interface (DataArchiveInterface) – The interface.

kvalikirstu2.argument_parser.save_config(filepath=None)[source]

Save current config to file

Parameters

filepath (str) – The destination filepath of the config.

kvalikirstu2.argument_parser.store_parser(parser)[source]

Stores parser to global list _DATA

kvalikirstu2.argument_parser.store_settings(settings)[source]

Stores settings (parsed values) to global list _DATA

kvalikirstu2.backup_select_window.py

kvalikirstu2.converter.py

A module for converting arbitrary text to UTF-8 and converting other files to .odt with Libreoffice. All Libreoffice code is contained inside this module.

exception kvalikirstu2.converter.ConversionException[source]

Bases: Exception

Exception that should be raised when an error occurs in data conversion.

kvalikirstu2.converter.convert(content)[source]

Converts content in arbitrary encoding to UTF-8.

Parameters

content (bytes) – The content to be converted.

Returns

UTF-8 encoded string

kvalikirstu2.converter.convert_file(filepath, out_encoding)[source]

Converts a file to the given encoding:

Parameters
  • filepath – The path of the file to be converted.

  • out_encoding – The encoding to be used.

kvalikirstu2.converter.convert_file_encoding_in_folder(folder_path, out_encoding, file_extension)[source]

Converts all files to the given encoding.

Parameters
  • folder_path – The path of the folder.

  • out_encoding – The encoding to be used.

  • file_extension – The file extension.

kvalikirstu2.converter.convert_files_with_libreoffice_to_odt(path, timeout)[source]

Converts suitable files with LibreOffice from the path to odt.

Parameters
  • path – The path of the files to be converted.

  • timeout – The timeout used for Libreoffice.

kvalikirstu2.converter.convert_files_with_libreoffice_to_txt(path, timeout)[source]

Converts suitable files with LibreOffice from the path to txt.

Parameters
  • path – The path of the files to be converted.

  • timeout – The timeout used for Libreoffice.

kvalikirstu2.converter.libreoffice_installed()[source]

Test if Libreoffice is installed(Windows).

kvalikirstu2.csv_generator.py

A module for generating .csv files out of studies.

kvalikirstu2.csv_generator.create_csv(loaded_study: kvalikirstu2.study.Study, language, encoding, csv_filename, header_info, language_codes=None)[source]

Creates a .csv file from the study. This function assumes that headers have already been remapped prior to calling this function.

Parameters
  • loaded_study – The study from which the .csv file is generated from.

  • language – The language of the .csv file.

  • encoding – The encoding for the .csv file.

  • csv_filename – The filename for the csv file.

  • header_info – The header information for the study.

  • language_codes – The set of possible language codes.

kvalikirstu2.data_archive_interface.py

A module for the DataArchiveInterface base class.

class kvalikirstu2.data_archive_interface.Command(func, text, help_text)[source]

Bases: object

A command that can be issued via the GUI.

Variables
  • text – The label of the command.

  • help_text – The help text associated with the command.

execute()[source]

Executes the command.

class kvalikirstu2.data_archive_interface.DataArchiveInterface[source]

Bases: object

An abstract baseclass to isolate any FSD specific functionality out of the main program.

add_cli_arguments(argument_parser)[source]

Add CLI arguments based on the needs of the data repository.

Parameters

argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.

add_gui_arguments(argument_parser)[source]

Add GUI arguments based on the needs of the data repository.

Parameters

argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.

add_shared_arguments(argument_parser)[source]

Add shared arguments based on the needs of the data repository. Shared means it’s used for both the CLI and GUI

Parameters

argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.

create_csv_name(metadata: kvalikirstu2.data_archive_interface.MetadataInformation)[source]

Returns the name of the .csv file for the study with the given ID.

Parameters

metadata (MetadataInformation) – The metadata of the study.

get_commands()[source]

Returns a list of commands that can be executed from the GUI.

Returns

A list of commands.

get_metadata_files(study_path, data_path)[source]

Returns a list of files that are metadata files of the study in the data folder.

Parameters
  • study_path (str) – The path of the study.

  • data_path (str) – The path of the data folder.

get_study_data_filename(metadata: kvalikirstu2.data_archive_interface.MetadataInformation)[source]

Gets a data file name for the study with the given ID. Used when generating a single data file for a study that consists of external data files such as PDF-files or image files that are not directly readable.

Parameters

metadata (MetadataInformation) – The metadata of the study.

parse_study_information(study_path, data_path)[source]

Parses study metadata from given path.

Parameters
  • study_path – The path of the study folder.

  • data_path – The path of the data folder.

Return type

MetadataInformation

rename_data_files_in_folder(metadata: kvalikirstu2.data_archive_interface.MetadataInformation, data_path: str)[source]

Rename data files in a folder to use whatever the standard naming scheme is. In the FSD case this is FSDxxxx_xx.txt/odt/etc.

Parameters
  • metadata – The metadata of the study.

  • data_path (str) – The path of the data folder.

class kvalikirstu2.data_archive_interface.DummyInterface[source]

Bases: kvalikirstu2.data_archive_interface.DataArchiveInterface

An dummy class to implement basic functionality so that the program can work.

add_cli_arguments(argument_parser)[source]

Add CLI arguments based on the needs of the data repository.

Parameters

argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.

add_gui_arguments(argument_parser)[source]

Add GUI arguments based on the needs of the data repository.

Parameters

argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.

add_shared_arguments(argument_parser)[source]

Add shared arguments based on the needs of the data archive. Shared means it’s used for both the CLI and GUI

Parameters

argument_parser (Kvalikirstu2ConfigArgParser) – The argument parser.

create_csv_name(metadata: kvalikirstu2.data_archive_interface.MetadataInformation)[source]

Returns the name of the .csv file for the study with the given ID.

Parameters

metadata (MetadataInformation) – The metadata of the study.

get_metadata_files(study_path, data_path)[source]

Returns a list of files that are metadata files of the study in the data folder.

Parameters
  • study_path (str) – The path of the study.

  • data_path (str) – The path of the data folder.

get_study_data_filename(metadata: kvalikirstu2.data_archive_interface.MetadataInformation)[source]

Gets a data file name for the study with the given ID. Used when generating a single data file for a study that consists of external data files such as PDF-files or image files that are not directly readable.

Parameters

metadata (MetadataInformation) – The metadata of the study.

parse_study_information(study_path, data_path)[source]

Parses study metadata from given path.

Parameters
  • study_path – The path of the study folder.

  • data_path – The path of the data folder.

Return type

MetadataInformation

rename_data_files_in_folder(metadata: kvalikirstu2.data_archive_interface.MetadataInformation, data_path: str)[source]

Rename data files in a folder to use whatever the standard naming scheme is. In the FSD case this is FSDxxxx_xx.txt/odt/etc.

Parameters
  • metadata – The metadata of the study.

  • data_path (str) – The path of the data folder.

class kvalikirstu2.data_archive_interface.MetadataInformation(study_id, citation_requirement, title)[source]

Bases: object

A data container class for study metadata.

extract_study_number()[source]

Extracts the study number out of the study_id. Assumes first 3 characters should be excluded.

kvalikirstu2.data_file_tempwriter.py

A module for writing temporary data files, that can be modified by the user.

kvalikirstu2.data_file_tempwriter.generate_temp_path(orig_path, study_path)[source]

Generates a path for the temporary file.

Parameters
  • orig_path (str) – Path to the original file.

  • study_path (str) – The path of the study.

kvalikirstu2.data_file_tempwriter.write_to_file(temp_path, paragraphs)[source]

Writes the study to file.

Parameters

paragraphs (list(Paragraph)) – The paragraphs parsed from the file.

kvalikirstu2.exceptions.py

A module containing exceptions.

exception kvalikirstu2.exceptions.EncodingError(filepath, msg)[source]

Bases: Exception

Error occurred related to text encoding

exception kvalikirstu2.exceptions.HeaderEditException[source]

Bases: Exception

Exception occurred while editing headers.

exception kvalikirstu2.exceptions.InvalidFormatException[source]

Bases: Exception

Invalid file format was entered by the user.

exception kvalikirstu2.exceptions.InvalidHeaderException[source]

Bases: Exception

User gave an invalid header.

exception kvalikirstu2.exceptions.ParagraphParsingException(temp_path, row_min, row_max, msg='')[source]

Bases: Exception

Error occurred during parsing paragraphs.

Variables
  • temp_path – Path of the temp file.

  • row_min – The first row where the error occurs.

  • row_max – The last row where the error occurs.

  • msg – The error message.

exception kvalikirstu2.exceptions.TempFileException(exception, *args, **kwargs)[source]

Bases: Exception

An exception for generating temp files

Variables

inner_exception – The inner exception thrown during the generation of the temp files.

kvalikirstu2.folder_backup.py

A module for creating backups of folders for reverting changes to the study folder.

class kvalikirstu2.folder_backup.FolderTimestamp(index, timestamp)[source]

Bases: object

Folder timestamp for a backup.

Variables
  • index (int) – The index of the timestamp.

  • timestamp (float) – The unix timestamp.

kvalikirstu2.folder_backup.backup_folder(folder, max_folder_size, max_backups)[source]

Create a backup of the folder.

Parameters
  • folder (str) – The folder path.

  • max_folder_size – The maximum size of the folder.

  • max_backups – The maximum number of backups.

kvalikirstu2.folder_backup.clear_backups(folder)[source]

Clear old backups for the folder.

Parameters

folder – The path of the folder to clear backups for.

kvalikirstu2.folder_backup.folder_too_large(folder, max_folder_size)[source]

Is the folder too large to be backed up?

Parameters
  • folder – The path of the folder.

  • max_folder_size – The maximum size of the folder in bytes.

Returns

True/False based on whether or not the folder is too large to be backed up.

kvalikirstu2.folder_backup.get_timestamps(folder, max_backups)[source]

Get time stamps for a folder.

Parameters
  • folder (str) – Folder path to get backups for.

  • max_backups – Maximum number of backups.

kvalikirstu2.folder_backup.restore_backup(folder, index)[source]

Restore backup with index.

Parameters
  • folder (str) – The folder to get a backup for.

  • index (int) – The index that chooses the timestamp to restore from.

kvalikirstu2.folder_backup.should_backup_folder(folder, max_folder_size, max_backups)[source]

Should the folder be backed up?

Parameters
  • folder – The path of the folder.

  • max_folder_size – The maximum size of the folder being backed up.

  • max_backups – The maximum number of backups to store.

kvalikirstu2.gui.py

kvalikirstu2.gui_model.py

The model part of the MVC architecture.

class kvalikirstu2.gui_model.GUIModel[source]

Bases: object

A class that contains the program state for the GUI.

add_language_codes(mapping)[source]

Adds language codes to files.

Parameters

mapping – A dictionary from old file paths to language codes.

add_text_to_dafs(text)[source]

Adds text to data files.

Parameters

text – Text to be added.

broadcast_initial_messages()[source]

Broadcasts initial messages about program state after the GUI has been initialized. Has to be called manually.

change_header_property(indexes, change_func, no_action_condition=None)[source]

Changes a property of the headers selected on the listctrl.

Parameters
  • indexes – A list of indexes.

  • change_func (callable) – A function that changes a header property.

  • no_action_condition (callable) – When called with a HeaderLine object,

Returns

True if the property should not be changed.

check_changes_valid()[source]

Checks if the current changes are valid.

check_unsaved_changes()[source]

Returns whether or not model has unsaved changes.

convert_to_odt()[source]

Convert to odt.

convert_to_txt()[source]

Convert to txt.

convert_txt_encoding()[source]

Convert txt encoding.

daf_container_exists()[source]

Returns True if a header list file exists.

delete_index()[source]

Deletes the index.

delete_tempfiles()[source]

Deletes tempfiles.

execute_command(index)[source]

Executes a command.

Parameters

index – Index of the command.

generate_citation_requirement()[source]

Generates a citation requirement for all files.

generate_output()[source]

Generates index and other output files.

generate_tempfiles()[source]

Generates tempfiles.

get_backups()[source]

Returns the backups that the study state can be restored to.

get_commands()[source]

Returns a list of commands.

Returns

A list of commands.

get_daf_data()[source]

Returns a list of dafData instances, where content is a string that corresponds to the text content of the file. The content is an empty string if the file cannot be read.

get_data_path()[source]

Returns the data path.

get_file_count()[source]

Returns the number of files in the current study.

get_file_paths()[source]

Returns the paths of all files in the current study.

get_headerline(index)[source]

Returns the HeaderLine in given index.

Parameters

index (int) – The index of the header to get.

Return type

HeaderLine

get_language_codes()[source]

Gets the different language codes available.

get_metadata()[source]

Gets the metadata for a study.

get_preview(path)[source]

Returns a string with the first <20 lines of a file.

Parameters

path – The path of the file to preview.

get_study_path()[source]

Gets the study path.

get_tempfile_content(path)[source]

Gets the content from a temporary file for editing purposes.

Parameters

path – The path of the tempfile.

index_exists()[source]

Does the index exist?

move_down(index)[source]

Moves header in the index downwards by one.

Parameters

index (int) – The index of the header to move.

move_up(index)[source]

Moves header in the index upwards by one.

Parameters

index (int) – The index of the header to move.

open_data_folder()[source]

Opens the explorer at the directory of the current study data.

open_index()[source]

Opens the index.

redo()[source]

Redos top-most header change in the top stack.

rename_daf_files()[source]

Renames data files.

replace_text(old_text, new_text)[source]

Replace text in files.

Parameters
  • old_text – Text to replace.

  • new_text – Text to replace the old text with.

restore_backup(index)[source]

Restore backup in index.

Parameters

index – The index of the backup to restore to.

save_changes()[source]

Saves changes to headers.

save_changes_to_daf()[source]

Saves changes to data files.

save_tempfile_content(path, content)[source]

Saves tempfile with content.

Parameters
  • path – The path of the tempfile.

  • content – The content to save into the tempfile.

select_index_language(lang)[source]

Select language for the index.

Parameters

lang (str) – The language to set the index language to.

set_row_name(index, value)[source]

Sets the name for a header.

Parameters
  • index – The index of the row.

  • value (str) – New name of the header.

set_row_to_headerline(header_line)[source]

Replace header.

Parameters

header_line (HeaderLine) – The new header.

set_study_path(path)[source]

Sets study path to given path.

Parameters

path – The directory path for the study.

set_type_shown(header_type, should_show)[source]

Sets whether or not header type should be shown in the list.

Parameters
  • header_type (HeaderType) – The header type.

  • should_show (bool) – Should the header type be shown in the GUI?

setup_external_file_study(headers)[source]

Sets up an external file study.

Parameters

headers – List of headers.

toggle_move_rows()[source]

Toggles attribute move_rows_active.

undo()[source]

Undos top-most header change in the undo stack.

class kvalikirstu2.gui_model.HeaderLine(header, header_info)[source]

Bases: object

Stores information about each header row in GUIModel

add_value_mapping(pair, value)[source]

Adds a value mapping from (key, original_value) to value.

get_header_type()[source]

Gets the HeaderType enum for the header.

get_values()[source]

Gets values.

restore_original_header()[source]

Restores original header.

set_align(align)[source]

Sets HeaderLine alignment.

Parameters

align (str) – The new alignment.

set_mapping(pair, value)[source]

Sets a value mapping

set_status(status)[source]

Sets HeaderLine status.

Parameters

status (int) – The new status.

update_changed_values(new_values)[source]

Updates changed values for this header

class kvalikirstu2.gui_model.HeaderStatus[source]

Bases: enum.Enum

Header status enum.

SHOW = A header to include in the index file. HIDE = A header not to be included in the index file. NOT_HEADER = Indicates a data paragraph line. DAF_HEADER = The data file header.

DAF_HEADER = 4
HIDE = 2
NOT_HEADER = 3
SHOW = 1
class kvalikirstu2.gui_model.HeaderType[source]

Bases: enum.Enum

Enum class representing in which type a header belongs in.

BUILTIN = 2
NORMAL = 1
NOT_HEADER = 3
class kvalikirstu2.gui_model.Messages[source]

Bases: object

Contains the identifiers for the messages sent by the GUI model.

ALL_HEADERS_CHANGED = 'all_headers_changed'
HEADER_CHANGED = 'header_changed'
HEADER_TYPE_SHOW = 'header_type_shown'
INDEX_EXISTS = 'index_exists'
LANGUAGES = 'languages'
STUDY_EXISTS = 'study_exists'
TASK_FINISHED = 'task_finished'
TASK_PROGRESS = 'task_progress'
TEMP_EXISTS = 'temp_exists'
UNDO_REDO_CHANGED = 'undo_redo_changed'
UNSAVED_CHANGES = 'unsaved_changes'
exception kvalikirstu2.gui_model.StatusError[source]

Bases: Exception

An exception class to report issues with setting the status for a header.

kvalikirstu2.gui_utils.py

A module for GUI util functions.

class kvalikirstu2.gui_utils.Hotkey(keycode, modifiers, callback)[source]

Bases: object

A class to store information about a certain hotkey for a window.

Variables
  • keycode – The keycode of the key.

  • modifiers – The bit mask to determine if ctrl/alt/shift should be held down for this key.

  • callback – The function callback when the key is pressed.

is_pressed(event)[source]

Is the hotkey pressed?

Parameters

event – Key pressing event.

class kvalikirstu2.gui_utils.HotkeyMixin[source]

Bases: object

A mixin class to make adding hotkeys to windows easier.

Variables

hotkeys – A list of different hotkeys.

kvalikirstu2.gui_utils.add_border_and_fit(panel, sizer, frame=None, max_size=None)[source]

Adds a border and fit the frame.

Parameters
  • frame – Frame.

  • sizer – The sizer of the frame.

  • panel – The panel of the frame.

  • max_size – A tuple containing the maximum size of the frame.

kvalikirstu2.gui_utils.add_separator_to_ribbon_page(parent_page, padding=1, li_style=wx.LI_VERTICAL)[source]

Adds a separator line to wx.ribbon.RibbonPage parent_page.

kvalikirstu2.gui_utils.create_bitmap(img_name)[source]

Creates a bitmap from a .png image in the icons folder.

Parameters

img_name – The name of the .png file without extension.

kvalikirstu2.gui_utils.new_buttonbar(parent_page)[source]

Adds a new wx.ribbon.RibbonPanel with a wx.ribbon.RibbonButtonBar to a wx.ribbon.RibbonPage.

kvalikirstu2.gui_utils.set_ribbon_colours(ribbon, hide_panel_label=False)[source]

Sets wx.ribbon.RibbonBar ribbon color scheme.

kvalikirstu2.header_panel.py

A module for a panel in the main gui window that contains header related controls.

class kvalikirstu2.header_panel.EditableListCtrl(parent, style, editable_cols, *args, **kwargs)[source]

Bases: wx.ListCtrl, wx.lib.mixins.listctrl.TextEditMixin, wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin

A list control class that extends wx.ListCtrl, wx.lib.mixins.listctrl.TextEditMixin and wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin. The list control can be set to resize automatically and its text fields can be set editable.

OnChar(event)[source]

Catch the TAB, Shift-TAB, cursor DOWN/UP events. Overrides listctrl.EditableListCtrl.OnChar to fix bug with opening the editor at the right col and taking editable rows and cols into account.

OnItemSelected(evt)[source]

Overwrites OnItemSelected method of listctrl.TextEditMixin so that first item in the list can be selected.

OnLeftDown(evt=None)[source]

Overwrites OnLeftDown method of listctrl.TextEditMixin so that first item in the list can be selected. Disables editing any other column but the ones specified at init.

open_editor(col, row)[source]

Adds editable col and row check before opening editor.

set_header_item_colours(index, header)[source]

Sets text and background colours for header items in the listctrl.

Parameters
  • index (int) – The index of the listctrl row to edit.

  • header (HeaderLine) – The HeaderLine object that determines the listctrl row colours.

show_editor_at_row(row)[source]

Activate editor on the first column of the given row.

class kvalikirstu2.header_panel.HeaderPanel(parent, main_win, model, style=wx.TAB_TRAVERSAL)[source]

Bases: wx.Panel

A panel with header editing controls.

ID_HIDE_BUILTIN
ID_HIDE_NONHEADER
ID_MOVE_OFF
ID_MOVE_ON
ID_SHOW_BUILTIN
ID_SHOW_NONHEADER
add_move_headers_button(parent_tb)[source]

Removes and readds the move headers button with an icon and label according to if moving rows is activated.

add_show_builtin_button(parent_tb)[source]

Clears the button bar with the show builtin button and adds a new button with an icon and label according to the value of show_builtin_headers.

add_show_nonheader_button(parent_tb)[source]

Clears the button bar with the show non headers button and adds a new button with an icon and label according to the value of show_non_headers.

align_selected(alignment)[source]

Sets the alignment of selected headers.

Parameters

alignment (str) – The new alignment.

open_edit_value_dlg()[source]

Opens a dialog window for editing header values.

set_header_status(status)[source]

Changes the status of selected headers.

Parameters

status (int) – The new status.

toggle_move_rows(evt)[source]

Enables or disables moving listctrl rows.

toggle_show_builtin_headers(evt)[source]

Toggles builtin headers visibility.

toggle_show_non_headers(evt)[source]

Toggles non-header line visibility.

update_listctrl(headers)[source]

Updates all header changes to the listctrl.

exception kvalikirstu2.header_panel.StatusError[source]

Bases: Exception

An exception class to report issues with setting the status for a header.

class kvalikirstu2.header_panel.ValueEditDlg(parent, value_map, title)[source]

Bases: wx.Dialog

A Dialog window for editing values associated with a header in a subject.

get_updated_values_map()[source]

Returns a map with updated values.

init_btns()[source]

Inits the button sizer.

init_list_ctrl()[source]

Inits list ctrl elements.

on_close(ret_val=wx.ID_CANCEL)[source]

Asks to save unsaved changes when the window is about to close.

refresh_listctrl(row_index, new_value)[source]

Remaps a value on the given row with a new value.

Parameters
  • row_index (int) – The index of the row of the item to edit.

  • new_value (str) – The new value for the item.

remap_edited_values()[source]

Maps edited values to the old values and changes the item text of the corresponding listctrl rows.

show_popup_menu(evt)[source]

Opens the Popup menu when right click detected on a listctrl item.

kvalikirstu2.header_scanner.py

A module for scanning headers from data files.

kvalikirstu2.header_scanner.get_header_info_for_study(path: str)[source]

Inits HeaderInfo with headers and values scanned from files.

Parameters

path (str) – The path containing data files for the study.

kvalikirstu2.kvali_interface.py

Contains the interface through which the application communicates with the rest of the program

class kvalikirstu2.kvali_interface.DaFData(filepath, langcode, content)[source]

Bases: object

A class that contains information about a data file.

exception kvalikirstu2.kvali_interface.InvalidProgramStateException[source]

Bases: Exception

The program was in an invalid state for the function being called.

kvalikirstu2.kvali_interface.add_language_codes(mapping)[source]

Adds language codes to files.

Parameters

mapping – A dictionary from old file paths to language codes.

kvalikirstu2.kvali_interface.add_text_to_dafs(text)[source]

Add text to in front of every data file.

Parameters

text – The text added.

kvalikirstu2.kvali_interface.check_archive_interface()[source]

Checks if the archive interface is the dummy plugin.

kvalikirstu2.kvali_interface.convert_to_odt()[source]

Converts data files to txt.

kvalikirstu2.kvali_interface.convert_to_txt()[source]

Converts data files to txt.

kvalikirstu2.kvali_interface.convert_txt_encoding()[source]

Converts data files to txt.

kvalikirstu2.kvali_interface.convertable_files_exist()[source]

Returns True if there are convertable files in the selected study.

kvalikirstu2.kvali_interface.convertable_formats()[source]

Returns a list of convertable file formats.

kvalikirstu2.kvali_interface.data_files_and_mef_exist()[source]

Returns True if data path has been set, meF is found and data directory contains files.

kvalikirstu2.kvali_interface.delete_index()[source]

Deletes the generated html index.

kvalikirstu2.kvali_interface.delete_tempfiles()[source]

Deletes the temporary files used for generating the index.

kvalikirstu2.kvali_interface.generate_citreq()[source]

Generates a citation requirement for a folder

kvalikirstu2.kvali_interface.generate_output()[source]

Generates the index file for the study

kvalikirstu2.kvali_interface.generate_tempfiles()[source]

Generates the temporary files for the study

kvalikirstu2.kvali_interface.get_all_files_from_data_folder()[source]

Returns all files from the data folder except the meF and the data files.

Returns

A list of relative paths from the folder.

kvalikirstu2.kvali_interface.get_backups()[source]

Get backups with timestamps for the study folder.

kvalikirstu2.kvali_interface.get_commands()[source]

Gets commands that can be executed from the gui.

Returns

A list of commands.

kvalikirstu2.kvali_interface.get_current_study()[source]

Gets the current study.

Return type

Study

kvalikirstu2.kvali_interface.get_daf_container_path()[source]

Forms and returns the path of the daf container file.

kvalikirstu2.kvali_interface.get_daf_data()[source]

Returns a list of dafData instances, where content is a string that corresponds to the text content of the file. The content is an empty string if the file cannot be read.

kvalikirstu2.kvali_interface.get_data_filepaths()[source]

Returns a list of paths of all supported and convertable files in the current study.

kvalikirstu2.kvali_interface.get_data_path()[source]

Returns the path of the current study.

kvalikirstu2.kvali_interface.get_file_count()[source]

Returns the number of supported and convertable files in the current study.

kvalikirstu2.kvali_interface.get_header_info()[source]

Returns the saved HeaderInfo object.

kvalikirstu2.kvali_interface.get_headers_json_path()[source]

Gets the .json path for the current study

kvalikirstu2.kvali_interface.get_index_path()[source]

Gets the path where the index will be created.

kvalikirstu2.kvali_interface.get_metadata()[source]

Get the metadata for the study.

kvalikirstu2.kvali_interface.get_rows_from_file(path, line_ct)[source]

Reads the first <line_ct lines from the file in path.

Parameters
  • path – The path of the file.

  • line_ct – The maximum number of lines to read.

kvalikirstu2.kvali_interface.get_selected_headers()[source]

Gets the selected headers.

kvalikirstu2.kvali_interface.get_study_json_path()[source]

Gets the .json path for the current study

kvalikirstu2.kvali_interface.get_study_path()[source]

Gets the study path.

kvalikirstu2.kvali_interface.get_temp_glob_pattern()[source]

Gets the glob pattern for temp files.

Return type

str

kvalikirstu2.kvali_interface.get_textfile_content(path)[source]

Gets the content from a temporary file for editing purposes.

Parameters

path (str) – The path of the temp file.

kvalikirstu2.kvali_interface.index_exists()[source]

Does the index exist?

kvalikirstu2.kvali_interface.paragraph_files_exist()[source]

Do the temporary paragraph files exists for the data files?

kvalikirstu2.kvali_interface.parse_metadata()[source]

Parses the metadata for the study.

kvalikirstu2.kvali_interface.register_interface_for_argument_parser()[source]

Registers the data archive interface for the argument parser.

kvalikirstu2.kvali_interface.rename_daf_files()[source]

Rename daFs in data folder.

kvalikirstu2.kvali_interface.rename_headers_in_data_files()[source]

Rename headers in data files.

kvalikirstu2.kvali_interface.replace_text(original_text, new_text)[source]

Replace text with new text in data folder.

Parameters
  • original_text – Original text.

  • new_text – New text to replace the original.

kvalikirstu2.kvali_interface.restore_backup(index)[source]

Restores a folder to a backup with the given index.

Parameters

index – The index of the backup.

kvalikirstu2.kvali_interface.save_header_info(header_info)[source]

Saves the modified header info.

Parameters

header_info (HeaderInfo) – New header info to be set.

kvalikirstu2.kvali_interface.save_headers()[source]

Saves header info content to a .json file.

kvalikirstu2.kvali_interface.save_tempfile_content(path, content)[source]

Rewrites the old temp file with new content.

Parameters
  • path (str) – The path of the temp file.

  • content (str) – The contents of the file.

kvalikirstu2.kvali_interface.set_header_info(header_info)[source]

Sets the header info.

kvalikirstu2.kvali_interface.set_headers(headers, headers_removed, header_indexes=None, header_alignment=None)[source]

Sets the header info from the header editing menu.

Parameters
  • headers – A map of old headers to new headers.

  • headers_removed – A list of headers that should be removed.

  • header_indexes – A map of header to index.

  • header_alignment – A map of header to alignment.

kvalikirstu2.kvali_interface.set_selected_headers(selected_headers)[source]

Set selected headers.

Parameters

selected_headers (dict) – A dictionary of str:bool items.

kvalikirstu2.kvali_interface.set_study_and_header_info()[source]

Sets the current study and loads header info.

kvalikirstu2.kvali_interface.set_study_path(path: str)[source]

Sets the path for the study

Parameters

path – The study path.

kvalikirstu2.kvali_interface.setup_external_file_study(headers)[source]

Transforms the study into one that contains external files that are linked to from the index. Any text in readable files is marked as data so it won’t be read.

kvalikirstu2.kvali_interface.study_exists()[source]

Does the study exist, ie. is a valid folder specified?

kvalikirstu2.kvali_interface.temp_files_exist()[source]

Have the temp files been generated for the study?

kvalikirstu2.lang_select_window.py

A GUI module for displaying a window for adding language tags to files.

class kvalikirstu2.lang_select_window.AutocomplComboBox(parent, choices)[source]

Bases: wx.ComboBox

A dropdown selection control with an autocomplete feature.

on_press(evt)[source]

Keeps track of if backspace key has been pressed.

on_text(evt)[source]

On user text input, suggests a matching value from the choices list.

class kvalikirstu2.lang_select_window.LangSelectWindow(parent, model)[source]

Bases: wx.Dialog

A window for adding language tags to files.

change_lang(lang, _evt=None)[source]

Changes the value in the language col for all selected rows.

kvalikirstu2.localization.py

A module for localization.

kvalikirstu2.localization.get_languages(user_locale='en_US')[source]

Gets a list of pairs of language codes and their display names in the users locale.

kvalikirstu2.localization.get_translation_func(language)[source]

Gets the translation function for the given language.

Parameters

language (str) – The language that the translation should be for.

kvalikirstu2.localization.set_language(language)[source]

Sets the language of the program.

Parameters

language – The language to use.

kvalikirstu2.main.py

A module for using the application from the command line.

kvalikirstu2.main.add_text(args)[source]

Adds string to the start of every data file.

Parameters

args – The arguments for the application.

kvalikirstu2.main.convert(args)[source]

Convert data files to default encoding.

Parameters

args – The arguments for the application.

kvalikirstu2.main.generate_citreq(args)[source]

Generates a citation requirement for the given folder.

Parameters

args – The arguments for the application.

kvalikirstu2.main.generate_index(args)[source]

Loads a study, and generates the index.

Parameters

args – The arguments for the application.

kvalikirstu2.main.main()[source]

The main function for the command line application.

kvalikirstu2.main.parse_study(args)[source]

Parses the study files, and prints some information about the study.

Parameters

args – The arguments for the application.

kvalikirstu2.main.rename_files(args)[source]

Renames files in study folder.

Parameters

args – The arguments for the application.

kvalikirstu2.main.rename_headers(args)[source]

Rename headers in data files.

Parameters

args – The arguments for the application.

kvalikirstu2.main.setup_external_file_study(args)[source]

Sets up an external file study.

kvalikirstu2.odt_reader.py

A module for reading .odt files line by line. Does not use Libreoffice, instead uses odfpy.

exception kvalikirstu2.odt_reader.ODTException(inner_exception, *args)[source]

Bases: Exception

Error occurred while reading odt file.

class kvalikirstu2.odt_reader.OdtReader(path: str)[source]

Bases: object

Reads .odt files line by line

Variables
  • doc – The .odt document

  • node_index (int) – Current text node in document

  • nodes – All the text nodes from the document.

can_read()[source]

Can read from file?

Return type

bool

Returns

True if not at the end of the file, False otherwise.

read_line()[source]

Read a line from the document

Return type

str

Returns

A line.

kvalikirstu2.odt_reader.get_text_from_node(node)[source]

Gets text from the ODT node.

kvalikirstu2.odt_reader.get_text_nodes_from_odt(odt)[source]

Gets the text nodes from an OpenDocument instance.

Parameters

odt (OpenDocument) – The OpenDocument instance.

kvalikirstu2.paragraph_analyzer.py

A module for parsing paragrahs out of data files.

class kvalikirstu2.paragraph_analyzer.Paragraph(temp_path, par_type=<ParagraphType.UNKNOWN: 5>)[source]

Bases: object

Contains a paragraph of text, lines of text not separated by empty lines

Variables
  • lines – A list of lines contained in the paragraph.

  • par_type (ParagraphType) – The type of the paragraph.

  • manual_type (bool) – True if the type of the paragraph has been manually specified using BEGINDATA and ENDDATA tokens.

  • row_min – First row.

  • row_max – Last row.

  • temp_path – Temporary filepath.

  • args – The args of the application.

check_valid()[source]

Checks if the paragraph is valid. A paragraph is invalid in the case that it is a header paragraph, but contains non-header lines.

get_split_point(headers_selected)[source]

The split point of a header paragraph.

Parameters

headers_selected – A dictionary of which headers should be selected.

Returns

The index that the paragraph should be split on.

is_empty()[source]

Tests if the paragraph contains no information

is_header()[source]

Is the paragraph a header paragraph?

resolve_row(running_row)[source]

Resolves the span of rows that the paragraph appears in the file, given the starting row.

Parameters

running_row – The current running index of the row.

Returns

The new running row.

resolve_type(selected_headers: dict = None)[source]

Resolves if the paragraph is a header or not. Sets the is_header attribute to its correct value.

Parameters

selected_headers – The selected headers dictionary.

set_type(par_type)[source]

Sets the paragraph type manually.

Parameters

par_type (ParagraphType) – The type.

should_split(headers_selected)[source]

Should split the paragraph?

Parameters

headers_selected – A dictionary of which headers should be selected.

split_paragraph(index)[source]

Splits the paragraph at the index, returning the two resulting paragraphs.

Parameters

index – Where the paragraph should be split at.

write_to_stream(stream)[source]

Writes the paragraph to a stream

class kvalikirstu2.paragraph_analyzer.ParagraphReader(path: str, overwrite_temp: bool = True, selected_headers: dict = None, use_temp: bool = True, study_path: str = None, end_markers=True, split_headers=True)[source]

Bases: object

Reads a file into paragraphs

Variables
  • reader – Responsible for reading the file line by line

  • path (str) – The file path

  • paragraphs (list(Paragraph)) – Paragraphs contained in the text

  • overwrite_temp (bool) – Overwrite temporary files.

  • selected_headers – The selected headers dictionary.

  • use_temp – Whether or not temp files should be used when reading.

  • study_path – The path of the study.

  • end_markers – Whether or not end markers should be inserted in the temp file.

  • split_headers – Should split the paragraph.

get_reader()[source]

Gets the reader for a given file extension

Parameters

path (str) – The file path of the file to be read.

Returns

The reader to be used in the parsing process.

read_paragraphs()[source]

Reads paragraphs from a text file

Return type

list(Paragraph)

Returns

List of paragraphs in the text.

read_subjects()[source]

Returns all the subjects from the given file

Return type

list(Subject)

Returns

List of subjects from a given file

try_add_paragraph_to_list(par)[source]

Add paragraph if not empty.

Parameters

par (Paragraph) – Paragraph to be added.

class kvalikirstu2.paragraph_analyzer.ParagraphType[source]

Bases: enum.Enum

Paragraph type enum.

DATA = A normal data paragraph containing text relevant to a certain subject. HEADER = A header paragraph containing headers for a certain subject. BEGINDATA = Indicates the start of a data block. ENDDATA = Indicates the end of a data block. UNKNOWN = Type hasn’t been determined.

BEGINDATA = 3
DATA = 1
ENDDATA = 4
HEADER = 2
UNKNOWN = 5
class kvalikirstu2.paragraph_analyzer.Subject(data_file: str, temp_path)[source]

Bases: object

A subject and its relevant data in the study.

Variables
  • headers (dict) – A dictionary of (key, value) pairs, often containing metadata about the subject.

  • paragraphs (list(Paragraph)) – Contains all the text paragraphs relevant to this subject.

  • int) header_indexes (dict(str,) – A dictionary mapping header names to their index.

  • data_file (str) – The path to the relevant data file for the subject.

  • temp_path – The filepath of the temp file.

add_data(paragraph)[source]

Add a text paragraph for the subject.

Parameters

paragraph (Paragraph) – A paragraph containing some text.

check_validity()[source]

Checks that the subject is valid. Does not return anything, just raises an exception if the subject is invalid.

get_header_value(header)[source]

Gets the value of a header field.

Parameters

header (str) – The header which value is to be retrieved.

get_language_code(language_codes)[source]

Gets the language code for the given file.

Parameters

language_codes – Set of possible language codes.

has_headers()[source]

Does subject have headers read?

Return type

bool

Returns

True if subject has headers, False otherwise.

remap(header_info)[source]

Remaps the headers to their corresponding names.

Iterates through all the subjects headers and maps them to their new values. In some cases there are multiple headers in a study that have the same meaning, but are just different ways of phrasing it. In cases like this they should be all be remapped into the same name. In some cases you may also want to discard some attributes from the index.

If a header is in the dictionary, it means that it should be remapped to a possibly different name.

Parameters

header_info (HeaderInfo) – Contains information about the different headers in the study.

remap_values(value_mapping: dict)[source]

Remaps values to new values.

Parameters

value_mapping (dict) – A value mapping dictionary from (key, value) to value.

resolve_daf(header_info)[source]

Resolve the data file for the subject, accounting for data files specified in the header.

set_headers(paragraph)[source]

Adds a header paragraph to the file.

Parameters

paragraph (Paragraph) – A header paragraph that will be added to this subject.

kvalikirstu2.progress_dialog.py

kvalikirstu2.reader.py

A module for reading text and ODT files.

class kvalikirstu2.reader.TxtReader(path: str, encoding)[source]

Bases: object

Reads .txt files line by line.

Variables

fstream – A filestream in read-mode, that reads the file line by line.

can_read()[source]

Can read from the stream?

Return type

bool

Returns

True if can read, False otherwise.

read_line()[source]

Reads a line from the .txt. file

Return type

str

Returns

A line.

kvalikirstu2.reader.get_reader(path: str)[source]

Gets a reader for the given path.

Parameters

path (str) – The path of the file to be read.

kvalikirstu2.study.py

Contains the Study and HeaderInfo classes for storing data about a qualitative study.

class kvalikirstu2.study.Align[source]

Bases: object

Contains the untranslated alignment strings.

CENTER = 'center'
LEFT = 'left'
RIGHT = 'right'
class kvalikirstu2.study.HeaderInfo[source]

Bases: object

Contains the header information about the study.

Variables
  • header_mapping – A mapping for headers from name to name

  • header_indexes – A mapping from header to index

  • value_mapping – Maps (header, value) pairs to new values

  • header_enabled – A mapping from header to bool

  • header_alignment – A mapping from header to alignment

  • selected_headers – A mapping from header to booleans

  • deleted_headers – A mapping from header to booleans

add_header(header)[source]

Adds a new header for the study.

Parameters

header – The header to be added.

get_header_alignments()[source]

Gets the header alignments for the index.

get_index_headers()[source]

Gets the remapped headers for the index file.

get_original_headers()[source]

Get the original headers.

init_builtin_headers()[source]

Inits built-in headers.

is_ordinary_header(header)[source]

Is the header a not a built-in header? Also returns false if header not in study.

Parameters

header – The name of the header.

set_daf_header(header)[source]

Sets the data file header.

update_headers()[source]

Updates all headers that changed.

class kvalikirstu2.study.Study(study_id: str, study_path: str, study_title: str, data_folder=None)[source]

Bases: object

A study containing qualitative data.

Variables
  • study_id (str) – The ID of the study

  • subjects – Subjects and their data

add_subject(subject: kvalikirstu2.paragraph_analyzer.Subject)[source]

Add a new subject to the study

Parameters

subject (Subject) – The subject to be added.

get_data_folder_path()[source]

Gets the data folder path.

get_full_path()[source]

The location where the data for the study is stored in.

Returns

The path of the full object.

Return type

str

get_language_code(language_codes)[source]

Gets the language code for the whole study.

Parameters

language_codes – The set of possible language codes.

Returns

A language code as a three letter string.

get_relative_path(path)[source]

Get relative path.

get_subject_language_code(index, language_codes)[source]

Gets the language code for the given subject.

Parameters
  • index – The index of the subject.

  • language_codes – List of valid language codes.

load_from_file()[source]

Loads the study from file

remap_headers(header_info)[source]

Remap the headers after user has had a chance to give feedback. For all subjects all the headers are mapped into their new values.

Parameters

header_info – The header info used for the remapping process.

write_to_file()[source]

Writes study to file

kvalikirstu2.study_reader.py

A module for generating a study out of data files.

exception kvalikirstu2.study_reader.NoSubjectsException[source]

Bases: Exception

Study contained no subjects.

class kvalikirstu2.study_reader.StudyReader(study_id: str, study_title: str, overwrite_temp: bool = True, selected_headers: dict = None, study_path: str = None, data_folder_name: str = None, data_file: str = None)[source]

Bases: object

A class for reading studies from a folder.

get_data_path()[source]

Returns the data path.

get_files()[source]

Get all the files in the folder and subfolders. All the files in the folder that have a compatible file format are matched.

Return type

list

Returns

A list of files

get_study()[source]

Gets a study for a given folder

Parameters

output (Study) – A study where subjects are stored into.

Return type

Study

Returns

The study that was read.

get_subjects()[source]

Gets all subjects from the folder.

Return type

list

Returns

A list of subjects.

kvalikirstu2.template_generator.py

A module for generating html files using Jinja2.

Attributes

ENV(Environment): A jinja2 enviroment for generating templates.

class kvalikirstu2.template_generator.HTMLFileMapping[source]

Bases: object

A class that handles the file mapping for HTML files.

add_path(key, path)[source]

Add a path with a key.

Parameters
  • key – The key of the file.

  • path – The path of the file.

Gets link to given key relative to output path.

Parameters

key – The key of the file.

get_path(key)[source]

Returns the output path for the given key.

Parameters

key – The key of the file.

Gets link to subject relative to output path.

Parameters

index – The index of the subject.

kvalikirstu2.template_generator.generate_index(output_path: str, template_study: kvalikirstu2.study.Study, header_info, metadata)[source]

Generates an index file for the study.

Parameters
  • output_path (str) – The output path for the generated html index file.

  • template_study (Study) – The study from which the template is generated from.

  • header_info – Contains information about the study’s headers.

  • metadata – The metadata of the study.

kvalikirstu2.template_generator.get_html_path(output_path: str)[source]

Gets the folder for all the “under the hood” files for the index document.

Parameters

output_path (str) – The path where the index file goes to.

kvalikirstu2.template_generator.get_index_path(output_path)[source]
Parameters

output_path – The path of the output folder.

Returns

The path of the index file.

kvalikirstu2.template_generator.relpath_with_fwd_slash(path: str, start=None)[source]

Produces a relative path with forward slashes

Parameters
  • path (str) – The path for which the relative path should be determined.

  • start (str) – The path to which the path is relative to. If no argument is given, the current working directory is used.

kvalikirstu2.text_add_window.py

A module for the text adding window.

class kvalikirstu2.text_add_window.TextAddWindow(title, callback, confirm_action_msg='')[source]

Bases: wx.Dialog

Window for adding text to data files.

kvalikirstu2.text_replace_window.py

kvalikirstu2.tmp_edit_window.py

A module for editing files with a text editor.

class kvalikirstu2.tmp_edit_window.ParagraphErrorWindow(model, message, parsing_exception: kvalikirstu2.exceptions.ParagraphParsingException)[source]

Bases: wx.Dialog

Window for displaying paragraph errors.

class kvalikirstu2.tmp_edit_window.TmpEditWindow(model, parsing_exception, *args, **kwargs)[source]

Bases: wx.Dialog, kvalikirstu2.gui_utils.HotkeyMixin

The header editing window.

init_window()[source]

Initializes the window.

kvalikirstu2.tmp_edit_window.open_temp_error(model, message, exception)[source]

Open a temp file error window.

kvalikirstu2.utils.py

Module for small utility functions used in various places.

This module contains many small functions that are used in various places of Kvalikirstu.

Attributes

HEADER_LINE_REGEX(str): Contains the regex used for detecting header lines from files.

SUPPORTED_FORMATS(list(str)): Contains a list of strings that are the file formats supported by Kvalikirstu.

exception kvalikirstu2.utils.InvalidPathException[source]

Bases: Exception

User provided an invalid path.

kvalikirstu2.utils.add_language_code_to_path(path, code, codes)[source]

Gets the path with the language code.

Parameters
  • path (str) – The old filepath.

  • code (str) – The language code.

  • codes (list) – Valid language codes.

kvalikirstu2.utils.check_if_any_file_in_use(path: str, file_extensions)[source]

Checks if any file is in use in the folder.

Parameters
  • path – Folder path.

  • file_extensions – List of file extensions.

kvalikirstu2.utils.create_folder_if_not_exists(path: str)[source]

Creates a folder if one does not already exist.

Parameters

path (str) – The path of the folder.

kvalikirstu2.utils.delete_file_if_exists(path: str)[source]

Delete file if one exists.

Parameters

path (str) – The filepath to be deleted.

kvalikirstu2.utils.delete_folder_if_exists(path: str)[source]

Deletes a folder and its contents if it exists.

Parameters

path – The path of the folder.

kvalikirstu2.utils.folder_modified_timestamp(folder)[source]

Gets the timestamp for when any file in the folder was last modified.

Parameters

folder (str) – The folder to get the timestamp for.

kvalikirstu2.utils.get_convertable_files(path)[source]

Get all the files in the folder and subfolders. All the files in the folder that have a convertable file format are matched.

Parameters

path (str) – The path to search for files.

Return type

list

Returns

A list of files

kvalikirstu2.utils.get_files_with_extensions(path, formats)[source]

Get files with the given extensions from the path.

Parameters
  • path – The folder path.

  • formats – List of file extensions.

kvalikirstu2.utils.get_filesize(path)[source]

Gets the size of a file in kilobytes. Rounded to one decimal point.

Parameters

path – The filepath of the entry.

kvalikirstu2.utils.get_folder(path)[source]

Gets the folder for a file, for a folder returns itself.

Parameters

path (str) – The path to the folder/file.

Return type

str

kvalikirstu2.utils.get_folder_size(folder)[source]

Gets the total size of all files in the folder.

Parameters

folder – The path of the folder to be examined.

kvalikirstu2.utils.get_formatted_header_line(header, value)[source]

Formats the header line according to the format specified in configurations.

Parameters
  • header (str) – The header part of the line

  • value (str) – The value part of the line

Return type

str

Returns

The formatted header line.

kvalikirstu2.utils.get_language_code_from_path(filepath, codes=None)[source]

Gets the language code from path.

Parameters
  • filepath (str) – The path of the file.

  • codes (list) – Valid language codes.

kvalikirstu2.utils.get_list_without_duplicates(items: list)[source]

Removes duplicates from list.

Parameters

items – List to be pruned of duplicates.

Return type

list

Returns

List without duplicates.

kvalikirstu2.utils.get_pair_out_of_string(string_pair)[source]

Takes a string containing a pair and parses it and returns it.

Parameters

string_pair – A pair inside a string. Expected format is “(‘key’, ‘value’)”

kvalikirstu2.utils.get_path_extension(path: str)[source]

Returns the filepath with the file extension

Parameters

path (str) – The filepath.

Return type

str

kvalikirstu2.utils.get_path_without_extension(path: str)[source]

Returns the filepath without the file extension

Parameters

path (str) – The filepath.

Return type

str

kvalikirstu2.utils.get_supported_files(path)[source]

Get all the files in the folder and subfolders.

All the files in the folder that have a compatible file format are matched.

Parameters

path (str) – The path to search for files.

Return type

list

Returns

A list of files

kvalikirstu2.utils.get_temp_path(folder_path: str, extension: str)[source]

Gets a path for a new temporary file.

Parameters
  • folder_path (str) – The path of the folder where the temp file is created in.

  • extension (str) – The file extension of the file.

Return type

str

kvalikirstu2.utils.is_convertable_format(filename: str, formats)[source]

Is the text format convertable by Kvalikirstu?

Parameters
  • filename (str) – The filename to be checked

  • formats – The convertable formats.

Return type

bool

Returns

True if text format is valid, False otherwise

kvalikirstu2.utils.is_header_line(line: str, selected_headers: dict = None)[source]

Is the current line a header?

Parameters
  • line (str) – The line to be parsed

  • selected_headers – A dictionary from header names to booleans that determines if they are selected.

Return type

bool

Returns

True if line is a header, False otherwise

kvalikirstu2.utils.is_image_file(path: str)[source]

Tests is the file in the path is an image file

Parameters

path (str) – The path to the file.

Return type

bool

kvalikirstu2.utils.is_temp_file(path: str)[source]

Checks if the filename looks like a temporary file for an .odt document.

Parameters

path (str) – The filename of the file. Can be the full path or just the name of the file

Return type

bool

Returns

True if the file is a temp file, False otherwise

kvalikirstu2.utils.is_valid_header(header)[source]

Is the header a valid header?

Parameters

header – The header to be tested for validity.

kvalikirstu2.utils.is_valid_text_format(filename: str)[source]

Is the text format supported by Kvalikirstu?

Parameters

filename (str) – The filename to be checked

Return type

bool

Returns

True if text format is valid, False otherwise

kvalikirstu2.utils.is_windows()[source]

Returns True if the user’s OS is a Windows system.

Return type

bool

kvalikirstu2.utils.json_deserialize(path: str)[source]

Deserializes(loads) any object from filename

Parameters

path (str) – Where the saved file is located

Returns

The deserialized object

kvalikirstu2.utils.json_serialize(obj, path: str)[source]

Serializes(saves) any object to a file

Parameters
  • obj – Any python object you want to serialize

  • path (str) – Where the file should be saved

kvalikirstu2.utils.natsorted_glob(pathname, extensions=None, files_only=True)[source]

Return files from pathname in a naturally sorted order.

Parameters
  • pathname – The search path to use for glob.glob.

  • extensions – The set of allowed extensions. None for any extension.

  • files_only – Whether or not only files should be returned.

Returns

A list of filenames in natural sort order.

kvalikirstu2.utils.number_of_digits(number)[source]

Returns the number of digits in the given number.

Parameters

number (int) – The number whose digit number is being examined.

Return type

int

kvalikirstu2.utils.parse_header(line: str)[source]

Parses a header line

Parameters

line (str) – The line to be parsed

Return type

(str, str)

Returns

Header name and value pair

kvalikirstu2.warning_handler.py

A module for the warning handler in the GUI.

class kvalikirstu2.warning_handler.WarningHandler(stream=None)[source]

Bases: logging.StreamHandler

A handler class which gives pop-ups on logger warnings, does not give pop-ups on errors(errors should be handled separately).

emit(record)[source]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.

kvalikirstu2.writer.py

A module for writing odt and txt files.

kvalikirstu2.writer.add_text_to_file(path: str, output_path: str, text: str)[source]

Adds text to the start of the file, and saves it to a new path. Note: You can also ovewrite the original by setting output_path same as path.

Parameters
  • path (str) – The original filepath.

  • output_path (str) – The output filepath.

  • text – The text to be added.

kvalikirstu2.writer.add_text_to_folder(path: str, text: str, check_for_duplicate=False)[source]

Adds text to all .odt and .txt files in the folder

Parameters
  • path (str) – The path of the folder.

  • text (str) – The text to be added.

  • check_for_duplicate – Whether or not to check for duplicate text at the start of the file.

kvalikirstu2.writer.rename_headers_in_folder(path: str, header_info, encoding=None)[source]

Rename headers in folder path.

Parameters
  • path – The path of the folder.

  • header_info – Header info for the study.

  • encoding – Encoding to be used in the data files.

kvalikirstu2.writer.replace_in_folder(path, original_text, new_text, encoding=None)[source]

Replace text in a folder.

Parameters
  • path – The path of the folder.

  • original_text – The original text.

  • new_text – The new text.

  • encoding – The encoding used.

kvalikirstu2.writer.write_empty_odt(path: str)[source]

Writes an empty .odt file

Parameters

path (str) – The path for the empty .odt file

kvalikirstu2.writer.write_txt(path: str, content='', encoding=None)[source]

Writes an empty .txt file

Parameters
  • path (str) – The path for the .txt file

  • content (str) – The content to write into the file.

  • encoding (str) – The encoding of the output file.