![]() |
Baby Language Lab Scripts
A collection of data processing tools.
|
A collection of static methods and constants for common UI-related tasks. More...
Static Public Member Functions | |
def | setup_gtk |
Sets some common GTK properties that all of the apps use. More... | |
def | set_font_size |
Sets the font size for a given widget. More... | |
def | get_icon_path |
Constructs the full path to an icon, given a value from the BUTTON_ICONS enum, and a value from the BUTTON_ICON_SIZES enum. More... | |
def | create_button |
Creates a gtk.Button with an icon on it. More... | |
def | show_confirm_dialog |
Displays a popup confirmation dialog with yes/no buttons. More... | |
def | show_no_sel_dialog |
Displays a popup dialog (with an ok button) that tells the user to select a row (presumably in some type of UI list). More... | |
def | show_empty_form_dialog |
Displays a popup dialog (with an ok button) that tells the user to make sure all options in a form have been filled out. More... | |
def | show_message_dialog |
Displays a popup dialog (with an ok button) that presents a textual message. More... | |
def | get_time_spinners |
Creates a set of gtk.SpinButton inputs to allow the user to input a time in the format hh:mm:ss. More... | |
def | get_cur_timestamp_str |
Returns a string containing the current date and time. More... | |
def | get_db_timestamp_str |
Accepts a string representing a datetime that was retrieved from the database, and converts it into a format suitable for display in the UI. More... | |
def | utc_to_local_str |
def | build_file_filter |
Constructs a gtk.FileFilter object for a set of file extensions. More... | |
def | build_simple_combo |
Builds a simple combo box. More... | |
def | build_simple_liststore |
Builds a simple gtk.ListStore. More... | |
def | build_multiselect_treeview |
Builds a treeview (a grid with selectable rows) with a single column. More... | |
def | build_options_liststore |
Builds a gtk.ListStore that contains a group of common combo options stored in the DBConstants.COMBO_OPTIONS enum (these ultimately come from the database). More... | |
def | calc_treeview_col_min_width |
Computes the minimum number of pixels (width) needed to show a treeview column with the specified title text. More... | |
def | build_options_combo |
Builds a gtk.ComboBox widget that contains a group of common combo options stored in the DBConstants.COMBO_OPTIONS enum (these ultimately come from the database). More... | |
def | build_regex_helper_combo |
Builds a gtk.ComboBox containing options for "common regexs" (COMBO_GROUPS.COMMON_REGEXS). More... | |
def | browse_file |
This method opens an "open file" dialog, and populates a text entry widget with the resulting path. More... | |
def | browse_folder |
This method opens an "open folder" dialog, and populates a text entry widget with the resulting path. More... | |
def | open_file |
Shows an "open file" dialog, returning a user-selected filename (if any). More... | |
def | open_folder |
Shows an "open folder" dialog, returning a user-selected foldername (if any). More... | |
def | save_file |
Shows a "Save file" dialog, returning the path to a user-selected location. More... | |
def | show_entry_dialog |
Shows a dialog box with a message, a single text entry, and a set of buttons (e.g. More... | |
def | show_file_dialog_with_checks |
This method shows a a file dialog box (for "open" or "save") that (in addition to its regular buttons and controls) contains one or more checkboxes that the user can toggle. More... | |
def | show_file_dialog |
This method shows a a file dialog box (for "open" or "save") with controls that allow the user to select a file. More... | |
Static Public Attributes | |
last_filechooser_location = None | |
WAV_FILE_FILTER = None | |
TRS_FILE_FILTER = None | |
ALL_FILE_FILTER = None | |
CSV_FILE_FILTER = None | |
TRS_CSV_FILE_FILTER = None | |
string | DB_DT_OUTPUT_FMT = '%Y-%m-%d %H:%M:%S' |
string | DT_DISPLAY_FMT = '%b %d, %Y %I:%M %p' |
tuple | BUTTON_ICONS |
tuple | BUTTON_ICON_SIZES |
Static Private Member Functions | |
def | _fill_entry |
This is an internal helper method for build_regex_helper_combo(). More... | |
A collection of static methods and constants for common UI-related tasks.
This class should never be instantiated.
Definition at line 18 of file ui_utils.py.
|
staticprivate |
This is an internal helper method for build_regex_helper_combo().
It populates a text entry with a regex string corresponding to the selected option in the combobox. It is called every time the combobox selection changes.
combo | (gtk.ComboBox) this is a combobox created with the options for the DBConstants.COMBO_GROUPS.COMMON_REGEXS group |
entry | (gtk.Entry) a text entry to populate with the regex string for the selected combobox option |
Definition at line 387 of file ui_utils.py.
|
static |
This method opens an "open file" dialog, and populates a text entry widget with the resulting path.
It's useful to hook up to a "browse" button in the UI. This method blocks until the user clicks ok.
title | (string) text to display in the titlebar of the "open file" dialog |
entry | (gtk.Entry) an entry widget to populate with the path name after the user clicks ok in the "open file" dialog |
filters | (list=[]) list of gtk.FileFilter objects. A dropdown list of file types displaying these is shown in the "open file" dialog. You can use the constants in this class to build a list (UIUtils.ALL_FILE_FILTER, UIUtils.WAV_FILE_FILTER, UIUtils.TRS_FILE_FILTER, etc.) |
auto_fill_entry | (gtk.Entry=None) an optional gtk entry. It is possible to automatically locate another file with the same name as the one the user selects, but a different file extension. This is useful, for example, when the user is locating a trs file, and you want to automatically locate the corresponding wav file. If this param is not None, an automatic search will be done for the corresponding wav file and, if it is found, the entry will be populated with the path. The search encompasses the current directory (the one the user's selected file is in) and the parent directory. |
auto_fill_file_extension | (string='wav') an optional file extension string, used together with auto_fill_entry. This dictates the type of file extension that the search described in the auto_fill_entry parameter documentation. |
Definition at line 420 of file ui_utils.py.
|
static |
This method opens an "open folder" dialog, and populates a text entry widget with the resulting path.
It's useful to hook up to a "browse" button in the UI. This method blocks until the user clicks ok.
title | (string) text to display in the titlebar of the "open folder" dialog |
entry | (gtk.Entry) an entry widget to populate with the path name after the user clicks ok in the "open folder" dialog |
filters | (list=[]) list of gtk.FileFilter objects. This specifies the types of files (via their extensions) that will be visible in the "open folder" dialog. Since the dialog doesn't let you select files (only folders), any visible files will appear "greyed out", and this param really just affects with the user can see, not what they can do. In general, it is probably most useful to either leave this empty or set it to UIUtils.ALL_FILE_FILTER. |
Definition at line 447 of file ui_utils.py.
|
static |
Constructs a gtk.FileFilter object for a set of file extensions.
title | (string) the title for this filer. This title is displayed in the dropdown combobox of file types in filechooser dialogs |
patterns | (list) a list of strings, where each is a shell-expandible file extension (like '*.wav' or '*.trs') |
Definition at line 241 of file ui_utils.py.
|
static |
Builds a treeview (a grid with selectable rows) with a single column.
The user may select multiple rows at once. The treeview has a hidden 'ID' column appended to it - you can use this to track the indices of the selected rows (or you can use the vals parameter). See the gtk docs for more info on treeviews. Here is what the treeview looks like:
labels | (list) list of strings. These are the values to display in the rows (one element per row). |
vals | (list) list of anything. These values will be assigned to the rows in the same order as the labels list (therefore it must be of the same length). You can retrieve the values of selected rows when querying the treeview widget's selection state. |
val_type | (function pointer) this is function pointer corresponding to a type (like str, int, float, etc.) or it is a type constant from the gobject module (eg. gobject.TYPE_STRING, gobject.TYPE_FLOAT, etc.). It indicates the type of the elements in the vals array. |
header_text | (string) text to display at the top of the single column. |
Definition at line 303 of file ui_utils.py.
|
static |
Builds a gtk.ComboBox widget that contains a group of common combo options stored in the DBConstants.COMBO_OPTIONS enum (these ultimately come from the database).
For example, you could create a combobox that allows you to select one of the LENA speaker codes.
group_id | (int) a value from the DBConstants.COMBO_GROUPS enum, indicating which group of options to insert into the liststore. |
active_index | (int=0) the row index of the entry to auto-select. If include_empty_option is True, and this is zero, then the empty entry will be selected. |
include_empty_option | (boolean=True) if True, an option with an empty string label will be pre-pended to the list of options. This can be used as a "nothing-selected" option. |
Definition at line 357 of file ui_utils.py.
|
static |
Builds a gtk.ListStore that contains a group of common combo options stored in the DBConstants.COMBO_OPTIONS enum (these ultimately come from the database).
For example, you could create a liststore of all LENA speaker codes, then display them in a treeview - this is what was done to create the screenshot below:
You could just as easily use this liststore to create a combobox, or something else.
group_id | (int) a value from the DBConstants.COMBO_GROUPS enum, indicating which group of options to insert into the liststore. Combo options are grouped according to their type. For example, passing a group_id of DBConstants.COMBO_GROUPS.SPEAKER_CODES would create a liststore like the one used in the screenshot shown above. |
include_empty_option | (boolean=True) if True, an option with an empty string label will be pre-pended to the liststore. This can be used as a "nothing-selected" option. |
Definition at line 328 of file ui_utils.py.
|
static |
Builds a gtk.ComboBox containing options for "common regexs" (COMBO_GROUPS.COMMON_REGEXS).
When the selected option changes, a text entry box is populated with the regex string. (This is just a wrapper around the build_options_combo() method for common regexs, to add the ability to connect the 'changed' signal.)
entry | (gtk.Entry) a text entry box that will be populated with a regular expression string when the selection changes |
Definition at line 376 of file ui_utils.py.
|
static |
Builds a simple combo box.
Each entry has a title and a value. The title is displayed, the value is hidden to the user. Here's what it looks like:
By default, the first option is selected. Note: You can make this a row with a label that is an empty string (and value None) if you want it to appear as though nothing is selected by default (as in the above image).
types | (tuple) a 2-tuple of type functions (e.g. int, float, str). The first element is the type of the label, and the second is the type of the value. In most cases, the type of the label should be string, so you should pass the the str function as the first element. Alternatively, you can also use the type constants from the gobject module (gobject.TYPE_STRING, gobject.TYPE_FLOAT, etc.). |
labels | (list) a list of strings - these will be the options made available for the user to select. |
vals | (list) a list of anything - the length must be equal to the length of the labels param. These are the values that the labels will be given in the combobox model (assigned in the same order as the elements in the labels list appear). These values can be retrieved when you query the combobox selection state. |
Definition at line 262 of file ui_utils.py.
|
static |
Builds a simple gtk.ListStore.
This is the data store backing for a combobox or treeview.
labels | (list) list of strings that will be displayed in the list of treeview |
vals | (list) list of objects, must be same length as labels list. These values are assigned to the rows/options in the widget, and can be retrieved when the widget's selection state is queried. |
val_type | (function pointer) this is function pointer corresponding to a type (like str, int, float, etc.) or it is a type constant from the gobject module (eg. gobject.TYPE_STRING, gobject.TYPE_FLOAT, etc.). It indicates the type of the elements in the vals array. |
Definition at line 282 of file ui_utils.py.
|
static |
Computes the minimum number of pixels (width) needed to show a treeview column with the specified title text.
This is an approximation that was emperically determined, and uses magic numbers. It is not guarenteed to work, and should probably be removed. But you can try it if you feel frustrated.
col_name | (string) the text that will be displayed in the column header |
Definition at line 347 of file ui_utils.py.
|
static |
Creates a gtk.Button with an icon on it.
You can create predefined types of buttons (corresponding to common actions) of any given size by passing in parameters from this class' button enums. Note: in order for this to work, you must first tell gtk to allow images on button - this is done in the setup_gtk() method, so you should call that first.
label | (string) the text to display on the button. |
img_path | (string) a value from the BUTTON_ICONS enum (indicates the button action) |
icon_size_dir | (string=BUTTON_ICON_SIZES.PX32) a value from the BUTTON_ICON_SIZES enum, indicating the size of the icon that will be placed on the button. Default is 32x32 pixels. |
Definition at line 112 of file ui_utils.py.
|
static |
Returns a string containing the current date and time.
Definition at line 209 of file ui_utils.py.
|
static |
Accepts a string representing a datetime that was retrieved from the database, and converts it into a format suitable for display in the UI.
timestamp | (string) a timestamp string (retrieved from the DB) in the format UIUtils.DB_DT_OUTPUT_FMT |
Definition at line 216 of file ui_utils.py.
|
static |
Constructs the full path to an icon, given a value from the BUTTON_ICONS enum, and a value from the BUTTON_ICON_SIZES enum.
img_path | (string) this must be a value from the BUTTON_ICONS enum |
icon_size_dir | (string=BUTTON_ICON_SIZES.PX32) this must be a value from the BUTTON_ICON_SIZES enum. Size defaults to 32x32 pixels. |
Definition at line 102 of file ui_utils.py.
|
static |
Creates a set of gtk.SpinButton inputs to allow the user to input a time in the format hh:mm:ss.
These entries are packing into a horizontal gtk.HBox container, which is fitted with a label. Here's what the container looks like when it's displayed in the UI:
label | (string=None) an optional label to pack at the left side of the container |
hours | (int=0) value to default the hours spinbutton to |
mins | (int=0) value to default the minutes spinbutton to |
secs | (int=0) value to default the seconds spinbutton to |
Definition at line 176 of file ui_utils.py.
|
static |
Shows an "open file" dialog, returning a user-selected filename (if any).
This method blocks until the user clicks ok.
title | (string='Open File') string to display in the dialog box titlebar |
filters | (list=[]) list of gtk.FileFilter objects for the dialog to use. A combobox is displayed listing these filters (generally file extensions). Only files matching the pattern will be viewable in the browse pane. If no filters are specified, all files will be visible. |
save_last_location | (boolean=False) if True, the directory containing the selected file will be saved (to UIUtils.last_filechoose_location), and the next "open" or "save" dialog will use it as the current directory |
cur_location | (string=None) if this is non-None, it specifies the path to the folder to use as the current directory - this is the directory initially displayed when the dialog pops up |
Definition at line 460 of file ui_utils.py.
|
static |
Shows an "open folder" dialog, returning a user-selected foldername (if any).
This method blocks until the user clicks ok.
title | (string='Open Folder') string to display in the dialog box titlebar |
filters | (list=[]) list of gtk.FileFilter objects. This specifies the types of files (via their extensions) that will be visible in the "open folder" dialog. Since the dialog doesn't let you select files (only folders), any visible files will appear "greyed out", and this param really just affects with the user can see, not what they can do. In general, it is probably most useful to either leave this empty or set it to UIUtils.ALL_FILE_FILTER. |
save_last_location | (boolean=False) if True, the directory containing the selected file will be saved (to UIUtils.last_filechoose_location), and the next "open" dialog will use it as the current directory |
cur_location | (string=None) if this is non-None, it specifies the path to the folder to use as the current directory - this is the directory initially displayed when the dialog pops up |
Definition at line 476 of file ui_utils.py.
|
static |
Shows a "Save file" dialog, returning the path to a user-selected location.
This method blocks until the user clicks ok.
title | (string="Save File") text to display in the dialog box titlebar |
filters | (list=[]) list of gtk.FileFilter objects. This specifies the types of files (via their extensions) that will be visible in the "save" dialog. |
open_now_opt | (boolean=False) if True, a checkbox will be displayed along the bottom of the save dialog box that allows the use to open the saved file as soon as it is finished being written to disk (opened in Excel). |
save_last_location | (boolean=False) if True, the directory containing the selected file will be saved (to UIUtils.last_filechoose_location), and the next "open" or "save" dialog will use it as the current directory |
cur_location | (string=None) a path to a folder to set the dialog to show when it opens. If None, this will display whatever directory GTK feels like. |
Definition at line 491 of file ui_utils.py.
|
static |
Sets the font size for a given widget.
widget | (Gtk Container) the widget whose font size you'd like to set |
pt_size | (int, possibly float too?) the font size (pt) |
bold | (boolean=False) Set to True to make font bold |
Definition at line 90 of file ui_utils.py.
|
static |
Sets some common GTK properties that all of the apps use.
This only needs to be called once at appliation startup.
app_icon_filename | (string) path to an image file. This icons will be used as the default application icon (appears in the top left-hand corner of all windows) |
Definition at line 79 of file ui_utils.py.
|
static |
Displays a popup confirmation dialog with yes/no buttons.
This method will block until one of the buttons is clicked, at which point it will return a boolean value (indicating which button was clicked) and the dialog will auto-destruct.
msg | (string) the confirmation message to display (should be a yes/no question so the buttons make sense) |
Definition at line 125 of file ui_utils.py.
|
static |
Displays a popup dialog (with an ok button) that tells the user to make sure all options in a form have been filled out.
This method blocks until the user clicks ok.
alt_msg | (string=None) alternate text to display in place of the default. The default is 'Please make sure that all options have been filled out.' |
Definition at line 146 of file ui_utils.py.
|
static |
Shows a dialog box with a message, a single text entry, and a set of buttons (e.g.
ok/cancel). This allows the user to enter a string value. This method blocks until the user clicks ok. Here is what the dialog looks like, (the red message at the bottom is shown only if the user clicks ok after entering invalid text/no text).
msg | (string) message to display above the entry. This is generally some instructions about what to type in the entry. |
entry_title | (string) This text will be displayed directly to the left of the entry. Usually it is some text with a colon that acts as a title for the entry. |
default_text | (string='') The entry will be prepopulated with this text when the dialog box opens. |
validate_regex | (string=r'^.+$') a regular expression that will be used to validate the text in the entry when the user clicks ok. If the regex does not match the text, invalid_msg will be displayed and the dialog will remain open. The default value for this parameter is a regex that matches any text except the empty string (this just makes sure the user enters something). |
invalid_msg | (string='Please enter a value') this text will be shown below the dialog, in red, if the user clicks ok and the text they entered does not match validate_regex. In this case, the dialog will not close. |
Definition at line 507 of file ui_utils.py.
|
static |
This method shows a a file dialog box (for "open" or "save") with controls that allow the user to select a file.
This method blocks until the user clicks ok.
title | (string) text to display in the dialog box titlebar |
filters | (list=[]) list of gtk.FileFilter objects. This specifies the types of files (via their extensions) that will be visible in the dialog. |
action | (int) This is a gtk filechooser action constant (one of gtk.FILE_CHOOSER_ACTION_OPEN, gtk.FILE_CHOOSER_ACTION_SAVE, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER or gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER), indicating the type of dialog to display. |
confirm_button_stock | (int) a gtk stock icon constant (e.g. gtk.STOCK_OK, gtk.STOCK_OPEN), indicating what type of text and icon to display on the "ok" button. For a complete list of stock constants, see the PyGTK docs here. |
open_now_opt | (boolean=False) if True, a checkbox will be displayed in the dialog with the title "Open Immediately". Its value (True=checked, False=unchecked) is returned along with the path when this method returns. Typically this is used in save dialogs to allow the user to indicate that they would like to open a file immediately after it is saved to disk. |
save_last_location | (boolean=False) if True, the directory containing the selected file will be saved (to UIUtils.last_filechoose_location), and the next "open" or "save" dialog will use it as the current directory |
cur_location | (string=None) a path to a folder to set the dialog to show when it opens. If None, this will display whatever directory GTK feels like. |
Definition at line 608 of file ui_utils.py.
|
static |
This method shows a a file dialog box (for "open" or "save") that (in addition to its regular buttons and controls) contains one or more checkboxes that the user can toggle.
The checkboxes' states are returned, along with the user-specified path string (corresponding to the filesystem location they chose). This method blocks until the user clicks ok.
title | (string) text to display in the dialog box titlebar |
filters | (list=[]) list of gtk.FileFilter objects. This specifies the types of files (via their extensions) that will be visible in the dialog. |
action | (int) This is a gtk filechooser action constant (one of gtk.FILE_CHOOSER_ACTION_OPEN, gtk.FILE_CHOOSER_ACTION_SAVE, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER or gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER), indicating the type of dialog to display. |
confirm_button_stock | (int) a gtk stock icon constant (e.g. gtk.STOCK_OK, gtk.STOCK_OPEN), indicating what type of text and icon to display on the "ok" button. For a complete list of stock constants, see the PyGTK docs here. |
checkbuttons | (list) a list of gtk.CheckButton objects (i.e. checkboxes) to display in the dialog. See return value description for how to obtain their state when the ok button is pressed. |
save_last_location | (boolean=False) if True, the directory containing the selected file will be saved (to UIUtils.last_filechoose_location), and the next "open" or "save" dialog will use it as the current directory |
Definition at line 556 of file ui_utils.py.
|
static |
Displays a popup dialog (with an ok button) that presents a textual message.
This method blocks until the user clicks ok.
message | (string) the text to display in the dialog box. |
dialog_type | (int) one of the gtk message type constants (see gtk docs for the MessageDialog class), indicating the type of icon to display in the dialog. This icon indicates whether the dialog is an info/question/warning/error message. Possible values are gtk.MESSAGE_INFO, gtk.MESSAGE_WARNING, gtk.MESSAGE_QUESTION, or gtk.MESSAGE_ERROR. |
Definition at line 156 of file ui_utils.py.
|
static |
Displays a popup dialog (with an ok button) that tells the user to select a row (presumably in some type of UI list).
This method blocks until the user clicks ok.
alt_msg | (string=None) alternate text to display in place of the default. The default is 'Please select a row.' |
Definition at line 138 of file ui_utils.py.
|
static |
Definition at line 220 of file ui_utils.py.
|
static |
Definition at line 25 of file ui_utils.py.
|
static |
Definition at line 65 of file ui_utils.py.
|
static |
Definition at line 36 of file ui_utils.py.
|
static |
Definition at line 26 of file ui_utils.py.
|
static |
Definition at line 30 of file ui_utils.py.
|
static |
Definition at line 32 of file ui_utils.py.
|
static |
Definition at line 20 of file ui_utils.py.
|
static |
Definition at line 27 of file ui_utils.py.
|
static |
Definition at line 24 of file ui_utils.py.
|
static |
Definition at line 23 of file ui_utils.py.