Documentation for the code

Application

Main window of the application

Interface of the main window

Work with video and subtitles

class player_content.PlayerContentMixin[source]

Interaction with video and subtitles.

_seconds_to_readable(src)[source]

Converts an interval in seconds into a human readable interval value.

Parameters:src (int or float) – Value of time interval in seconds
Returns:Human readable interval value
Return type:unicode
_total_subtitle_fragments()[source]

Calculates the total number of subtitle.

Returns:Number of subtitles
Return type:int
edit_answer(output)[source]

Prints content of an answer after verification and ephasizes its words with appropriate colors.

Parameters:output (list of tuples) – Result of verification. List of pairs where first value is a symbol and second is an estimation of its correctness
find_subtitle(first=False)[source]

Find an actual subtitle.

Method searches for a subtitle which is appropriate to a current position in the video stream. If there isn’t such subtitle, None will be returned.

Parameters:first (bool) – If True first subtitle will be returned
Returns:An actual subtitle or None if there isn’t subtitles
Return type:pysrt.srtitem.SubRipItem
get_statistics()[source]

Calculates a part of generic statistical values.

This values are used with values received from verificator.Verificator.get_statistics() to show lesson statistics for user at the end of a lesson.

Returns:Several statistical values
Return type:dict
load_subtitles(event)[source]

Loads subtitles file.

Parameters:event (events.LoadSubtitles) – Event that contains path to subtitles file
load_video(event)[source]

Loads video file.

Parameters:event (events.LoadVideo) – Event that contains path to video file
on_video_backend_response(event)[source]

Notifies the player of the successful loading of a video.

on_video_backend_timeout()[source]

Runs the video handling without backend’s response.

show_statistics_dialog()[source]

Shows dialog with statistics of the lesson.

show_subtitle(subtitle=None)[source]

Shows subtitle text in “preview” mode.

Parameters:subtitle (pysrt.srtitem.SubRipItem) – Subtitle to showing

Work with user settings of the interface

class player_settings.PlayerSettingsMixin[source]

Settings of the application graphical interface.

_accept_args(pargs)[source]

Handles command line arguments on application start.

Parameters:pargs (argparse.Namespace) – Arguments
_get_video_slot_size()[source]

Calculates sizes available for video widget on the frame.

Returns:Pair of values where first is available width and seconds is available height
Return type:tuple
_save_frame_size_and_position()[source]

Saves player window size and position coordinates.

apply_color_settings()[source]

Applies color settings for widgets of player frame: text colors, background colors.

apply_font_settings()[source]

Applies font settings for widgets of player frame.

apply_frame_settings()[source]

Applies common and window settings for player frame: languages, window size, window position.

apply_playback_settings()[source]

Applies playback settings for player frame: real time translation, volume level, subtitles shift.

correct_highlighting()[source]

Returns a highlighting color for a correct part of user’s answer.

Returns:Highlighting color for correct text
Return type:wx.Colour
enable_menu_actions(**kwargs)[source]

Changes the availability of menu items in the playback menu.

Default values of every keyword argument is None, i.e. availability of menu item will remain the same if you will not pass argument for it.

Parameters:
  • play (bool) – Availability of “Play” menu item.
  • pause (bool) – Availability of “Pause” menu item.
  • stop (bool) – Availability of “stop” menu item.
  • hint (bool) – Availability of “hint” menu item.
  • repeat (bool) – Availability of “repeat” menu item.
get_filters(copy=False)[source]

Returns actual regex filters.

Parameters:copy (bool) – To copy dictionary with filters or not
Returns:Regex filters
Return type:dict
incorrect_highlighting()[source]

Returns a highlighting color for an incorrect part of user’s answer.

Returns:Highlighting color for incorrect text
Return type:wx.Colour
is_learning()[source]

Clarifies current working mode of the application.

Returns:True if application works in “learning” mode else False
Return type:bool
learning_language()[source]

Returns a code of the language which is studied by user.

Returns:Language code from defaults.Defaults.LANGUAGES
Return type:unicode
need_translation()[source]

Indicates the need for a translation.

Returns:Need for a translation.
Return type:bool
user_language()[source]

Returns a code of the language which is native for user.

Returns:Language code from defaults.Defaults.LANGUAGES
Return type:unicode

Check of user answers during training

class verificator.Verificator(player)[source]

Checks user answers in the learning process, prepares the subtitle text.

_accept_filters(src)[source]

Applies regex filters to a text.

Parameters:src (str or unicode) – Source grubby text
Returns:Filtered tidy text or None if src isn’t a text
Return type:unicode or None
_clean_includes()[source]

Returns a collection of symbols which may pass the filter.

Returns:“Safe” symbols
Return type:tuple
_clean_text(src)[source]

Removes unwanted characters from a text.

Parameters:src (str or unicode) – Source text
Returns:Clean text or None if src isn’t a text
Return type:unicode or None
_prepare_answer_words(text)[source]

Cleans user’s answer and splits it into words.

Parameters:text (str or unicode) – User’s answer
Returns:Cleaned words or empty list
Return type:list of unicode
_prepare_origin_words()[source]

Prepares the original subtitle text divided into words.

Returns:Original subtitle text like a list of words
Return type:list of unicode
clear_subtitle(complete=True)[source]

Clears the current subtitle and related private attributes.

Parameters:complete – Mark the current subtitle as completed
fragment_length()[source]

Calculates the length of the subtitles fragment in symbols.

Returns:Length of the fragment (in characters)
Return type:int
get_etalon()[source]

Prepares a filtered etalon phrase from the subtitle text.

Returns:Filtered subtitle text
Return type:unicode
get_etalon_words()[source]

Returns clean words prepared from the subtitle text

Returns:Clean words or None if there isn’t source for words
Return type:list of unicode or None
get_last_word()[source]

Returns last full word from user’s answer.

Returns:Last word from answer
Return type:unicode
get_statistics()[source]

Returns a statistics information about learning process.

Returns:Learning statistics
Return type:dict
get_subtitle()[source]

Getter for the current subtitle attribute.

Returns:Current subtitle or None if there isn’t
Return type:pysrt.srtitem.SubRipItem or None
has_subtitle()[source]

Checks the existence of current subtitle.

Returns:Existence of the current subtitle
Return type:boolean
hint(answer)[source]

Prompt next word to the user. If user began to write next word it will complete this, else it will add full next word.

Parameters:answer (str or unicode) – User’s input in actual state
Returns:Received input with completed or added next word
Return type:unicode
is_complete(answer)[source]

Checks completeness of current subtitles fragment.

Parameters:answer (unicode or str) – User’s answer in actual state
Returns:Whether the current fragment is finished or not
Return type:boolean
is_empty()[source]

Checks the content existence in current subtitles fragment.

Sometimes text ends after an application of filters.

Returns:Existence of the text
Return type:boolean
is_passed(position)[source]

Checks for the ending of the current subtitle.

Parameters:position (int) – Position in media stream (in seconds)
Returns:Achievement of the subtitle ending
Return type:boolean
set_subtitle(subtitle, replace=True, force=False)[source]

Sets the current subtitle which will be used to for comparison with user’s answer.

Parameters:
  • subtitle (pysrt.srtitem.SubRipItem) – Current subtitle
  • replace – Overwrite previously set subtitle
  • force – Set the subtitle even if it was completed previously
Returns:

Execution status

Return type:

boolean

verify_answer(answer)[source]

Checks the correctness of every symbol in user’s answer.

Parameters:answer (str or unicode) – User’s answer
Returns:Estimation of the answer as a list of pairs where first value is a symbol and second is an estimation of its correctness
Return type:list of tuples (list of pairs)
whether_complete(subtitle)[source]

Checks whether current subtitle previously completed or not.

Parameters:subtitle (pysrt.srtitem.SubRipItem) – Suspicious subtitle
Returns:State of completion
Return type:boolean

Translation of a content

Dialogs of the application

class dialogs.PreferencesDialog(player=None)[source]

Dialog allows user to edit the configuration using a graphical interface.

_set_filters()[source]

Receives filters from the player instance and inserts them into filters list.

_set_init_values()[source]

Sets initial values for widgets.

_set_languages()[source]

Sets initial values of language selection widgets.

_show_font_names()[source]

Sets labels for buttons of font selection dialogs.

change_filter(action, regex=None, repl=None)[source]

Changes values of a filter, adds a new filter or removes it.

Parameters:
  • action (int) – Identifier of requested operation (may be one of ids.ADD_FILTER, ids.REMOVE_FILTER)
  • regex (str or unicode) – RegEx pattern
  • repl (str or unicode) – Replacement data
get_filters()[source]

Returns a collection of filters.

Returns:RegEx filters
Return type:dict
get_preferences()[source]

Returns current configuration data.

Returns:Configuration data
Return type:dict
on_filter_action(event)[source]

Adds, updates or removes a selected filter.

Parameters:event (wx.CommandEvent with type wx.EVT_BUTTON) – Event that entailed an execution of the callback
on_filter_deselect(event)[source]

Clears fields for filter editing when user clears selection.

Parameters:event (wx.ListEvent with type :const: wx.EVT_LIST_ITEM_DESELECTED) – Event that entailed an execution of the callback
on_filter_select(event)[source]

Fills fields for filter editing by values of a selected filter.

Parameters:event (wx.ListEvent with type wx.EVT_LIST_ITEM_SELECTED) – Event that contains an identifier of a selected filter
on_font(event)[source]

Creates and shows a font selection dialog with initial data.

Parameters:event (wx.CommandEvent with type wx.EVT_BUTTON) – Event that entailed an execution of the callback
class dialogs.UserManualDialog(player=None)[source]

Dialog allows user to read user manual while working with the application.

_load_html()[source]

Loads the content of User Manual from html file.

Returns:Content of User Manual
Return type:unicode

Drag’n’drop handling

class droptargets.FileDropTarget(frame)[source]

Bases: wx._misc.FileDropTarget

Handles drag’n’drop files events.

OnDropFiles(x, y, filenames)[source]

Handles a file dropping to the frame.

Parameters:
  • x (int) – X-coordinate of the dropping
  • y (int) – Y-coordinate of the dropping
  • filenames (list) – Paths to files
_on_subtitles_drop(filename)[source]

Initializes loading of a subtitles file.

Parameters:filename (str or unicode) – Path to the file
_on_video_drop(filename)[source]

Initializes loading of a video file.

Parameters:filename (str or unicode) – Path to the file

Custom widgets

class widgets.FilterList(parent=None, widget_id=-1)[source]

Bases: wx._controls.ListCtrl

Implements the logics of a list of regex filters.

_init_columns()[source]

Creates columns of the list of filters.

add_or_update_filter(regex, repl)[source]

Adds or updates a filter data.

Parameters:
  • regex (str or unicode) – RegEx pattern
  • repl (str or unicode) – Replacement data
Returns:

Index of a filter which was modified

Return type:

int

get_filter(idx)[source]

Returns data of a filter with specified index.

Parameters:idx (int) – Index of a filter
Returns:Filter data
Return type:tuple
get_index_of(regex)[source]

Returns index of a filter by its regex pattern.

Parameters:regex (str or unicode) – RegEx pattern
Returns:Index of a filter or None if such filter isn’t found
Return type:int or None
on_deselect(event)[source]

Clears an index of a selected filter when user clears a selection.

Parameters:event (wx.ListEvent with type wx.EVT_LIST_ITEM_DESELECTED) – Event that entails an execution of the callback
on_resize(event)[source]

Resizes columns of the list of filters proportionally to a width of the widget.

Parameters:event (wx.SizeEvent) – Event which entails an execution of the callback
on_select(event)[source]

Preserves an index of a filter selected by user.

Parameters:event (wx.ListEvent with type wx.EVT_LIST_ITEM_SELECTED) – Event that contains an index of a selected filter
remove_selected()[source]

Removes a selected filter from the list.

Returns:Filter data or None
Return type:tuple or None
selected()[source]

Returns an index of a selected filter.

Returns:Index of a selected filter or None if no one is selected
Return type:int or None
class widgets.VideoWidget(*args, **kwargs)[source]

Bases: wx.media.MediaCtrl

Customization of MediaCtrl widget.

SetAspectRatio(aspect, slot_size)[source]

Sets video widget size in according to a selected aspect ratio.

Parameters:
  • aspect (tuple) – Aspect ratio value
  • slot_size (tuple) – Maximum size available for a widget
classmethod _calculate_size(slot_size, aspect)[source]

Calculates video widget size in according to a selected aspect ratio and a maximum size available for a widget.

Parameters:
  • slot_size (tuple) – Maximum size available for a widget
  • aspect (tuple) – Aspect ratio

Custom events

events.ConfigUpdate

Notification about settings changing.

Receivers:
Player (wx.Frame): player window.
Kwargs:
params (dict): changes (format: parameter_name-parameter_value). name (str or unicode): parameter name. value (str or unicode or bool or int or float): new parameter value. apply_updated (bool): apply changed settings now (default: False). apply_all (bool): apply all settings now (default: False).

alias of _Event

events.ContentLoadingState

Notification about successful video or subtitles file opening and loading.

Receivers:
Player (wx.Frame): player window.
Kwargs:

video (bool): video loading state:

True -- Chosen video successful loaded.
False -- Video is not loaded.
None -- Video loading state without changes.

subtitles (bool): subtitles loading state:

True -- Chosen subtitles successful loaded.
False -- Subtitles is not loaded.
None -- Subtitles loading state without changes.

alias of _Event

events.FragmentComplete

Notification about successful completion of current subtitles fragment.

Receivers:
Player (wx.Frame): player window.

alias of _Event

events.FragmentStarted

Notification about beginning of a next subtitles fragment learning.

Receivers:
Player (wx.Frame): player window.

alias of _Event

events.LoadSubtitles

Command to load chosen subtitles file.

Receivers:
Player (wx.Frame): player window.
Kwargs:
filepath (str): path to the subtitles file.

alias of _Event

events.LoadVideo

Command to load chosen video file.

Receivers:
Player (wx.Frame): player window.
Kwargs:
filepath (str): path to the video file.

alias of _Event

events.SubtitlesShift

Command to shift subtitles.

Receivers:
Player (wx.Frame): player window.
Kwargs:
shift (int): shift in milliseconds.

alias of _Event

events.TranslateAnswer

Command to translate an answer entered by user.

Receivers:
Player (wx.Frame): player window.
Kwargs:
answer (str or unicode): user’s answer.

alias of _Event

events.TranslateRequest

Command to translate a subtitles fragment or word.

Receivers:
Player (wx.Frame): player window.
Kwargs:

src (str or unicode): source text or word. details (bool): request detailed result or not (default is False):

True -- Details requested.
False -- Only translation.

alias of _Event

events.TranslationResult

Notification about successful translation.

Receivers:
Player (wx.Frame): player window.
Kwargs:

result (str or unicode): translated text. details (bool): is result detailed or not (default is False):

True -- Detailed result.
False -- Only translation.

alias of _Event