PyLorentz_GUI module¶
Functions for GUI event handling.
Contains most functions for handling events in GUI. This includes controlling user events, calls to PyTIE, alignment calls to FIJI, saving images, creating image masks, and image manipulation for GUI display.
AUTHOR: Timothy Cote, ANL, Fall 2019.
-
PyLorentz_GUI.activate_spinner(window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc3950>, elem: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a050>) → None[source]¶ Activate loading spinner.
Parameters: - window – The element representing the passed GUI window.
- elem – The element who’s spinner should be disabled
Returns: None
-
PyLorentz_GUI.change_inp_readonly_bg_color(window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5390>, elem_list: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc53d0>], val: str)[source]¶ Change the readonly input background color.
Parameters: - window – The element representing the main GUI window.
- elem_list – The list of elements whose color will change
- val – The value to change the color to.
Returns: None
-
PyLorentz_GUI.change_list_ind_color(window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5250>, current_tab: str, elem_ind_val_list: List[int]) → None[source]¶ Change the listbox index color based off what images are loaded.
Parameters: - window – The element representing the main GUI window.
- current_tab – The key for the current tab.
- elem_ind_val_list – The list of tuples made of PySimpleGUI elements along with the value that the metadata of the element state ‘Set’ will change to.
Returns: None
-
PyLorentz_GUI.change_visibility(window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a1d0>, elem_val_list: List[Tuple[<sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a250>, Any]]) → None[source]¶ Take a list of element keys and change visibility of the element.
Parameters: - window – The element representing the main GUI window.
- elem_val_list – The list of elements with values whose state is to be changed.
Returns: None
-
PyLorentz_GUI.check_overwrite(winfo: util.Struct, save_win: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608ab50>, true_paths: List[str], orientations: List[str], image_dir: str, im_type: str, event: str, tfs) → List[bool][source]¶ Check whether the paths listed in the log box for each image will be overwritten.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- save_win – The save window element
- true_paths – A list of path names that will be checked if they exist.
- orientations – A list of strings that represent the orientations of the image (‘flip’, ‘unflip’, ‘stack’, etc.)
- image_dir – The path of the current working directory of images
- im_type – Image type (.bmp, .tiff, etc.)
- event – The key for the values dictionary that represents an event in the window.
- tfs – The through focal series value determined by the user for BUJ or LS.
Returns: The boolean values for overwriting the files.
Return type: overwrite_signals
-
PyLorentz_GUI.deactivate_spinner(window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a090>, elem: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a150>) → None[source]¶ Deactivate loading spinner.
Parameters: - window – The element representing the passed GUI window.
- elem – The element who’s spinner should be disabled
Returns: None
-
PyLorentz_GUI.defaults() → Dict[str, str][source]¶ Load the default Fiji and working directory if any is set.
Returns: Dictionary of the working directory paths. Return type: DEFAULTS
-
PyLorentz_GUI.disable_elements(window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a290>, elem_list: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a510>]) → None[source]¶ Take a list of element keys and disable the element.
Parameters: - window – The element representing the passed GUI window.
- elem_list – The list of elements whose state is to be changed.
Returns: None
-
PyLorentz_GUI.enable_elements(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a550>, elem_list: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a690>]) → None[source]¶ Take a list of element keys and enable the element.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the passed GUI window.
- elem_list – The list of elements whose state is to be changed.
Returns: None
-
PyLorentz_GUI.erase_mask_data(winfo: util.Struct, graph: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc3610>, current_tab: str, display_img: bytes, values: dict) → Tuple[bool, bool, bytes, Tuple, Tuple][source]¶ Erase the masks on the region selection planes
Parameters: - winfo – The data structure holding all information about windows and GUI.
- graph – The graph of the reconstruction tab.
- current_tab – The current selected tab in the GUI.
- display_img – The current display image.
- values – Dictionary of GUI window values associated with element keys.
Returns: Tuple that contains booleans of whether to draw/adjust mask, along with transformation and resulting image.
-
PyLorentz_GUI.event_handler(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608ac90>) → None[source]¶ The event handler handles all button presses, mouse clicks, etc. that can take place in the app. It takes the SG window and the struct containing all window data as parameters.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
Returns: None
-
PyLorentz_GUI.file_loading(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5090>, filename: str, active_key: str, image_key: str, target_key: str, conflict_keys: List[str], num_files: int, disable_elem_list: List[str]) → Tuple[bool, List[str]][source]¶ The function for loading stacks and other image files.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- filename – The name of the file being loaded.
- active_key – The key of the element that is active process.
- image_key – The key of the image in the image dictionary file should be loaded to.
- target_key – The target key that should be updated when image is loaded.
- conflict_keys – All the keys that should be disabled if they are in conflict with the active key.
- num_files – The number of files that should be loaded, 1 if not stack.
- disable_elem_list – The list of elements to disable based off active key or next active keys.
Returns: Boolean value if active key should be removed disable_elem_list: The list of elements to disable based off active key or next active keys.
Return type: remove
-
PyLorentz_GUI.get_arrow_transform(window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc6690>) → Tuple[str, str, str, str][source]¶ Get the mask transformation of the REC window.
Parameters: window – The element representing the main GUI window. Returns: The transformation to apply to REC mask, a list of strs. Return type: new_transform
-
PyLorentz_GUI.get_mask_transform(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc6950>, current_tab: str) → Tuple[Union[float, int], Union[float, int], Union[float, int]][source]¶ Get the mask transformation of the REC window.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- current_tab – The current tab of the window.
Returns: The transformation to apply to REC mask
Return type: transform
-
PyLorentz_GUI.get_open_tab(winfo: util.Struct, tabgroup: str, event: str) → str[source]¶ Recursively determine which tab is open.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- tabgroup – The key of the tabgroup.
- event – The event key.
Returns: The key for the current open tab.
Return type: tab_key
-
PyLorentz_GUI.get_orientation(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc6410>, pref: str) → str[source]¶ Get the current orientation value for the current window.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- pref – The prefix for the the key of the orientation for the window.
Returns: The orientation the current image should be.
Return type: orientation
-
PyLorentz_GUI.get_transformations(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc6dd0>, current_tab: str) → Tuple[source]¶ Gets transformations from the event window. Timers give user a limited amount of time before the rotation or shift is cleared.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- current_tab – The key of the current tab being viewed in the window.
Returns: - A tuple of the transformation variables for
rotation, x-translate, y-translate, and flip.
Return type: transform
-
PyLorentz_GUI.init(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c6158d10>, output_window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c6129f90>) → None[source]¶ The main element and window initialization. Creates all initial bindings.
- Initializes winfo arguments for the main GUI, includeing:
- The window element
- The output log window element
- Arguments for tracking the active window
- The keys available for elements in the window
- Tracks which tab is open
- Holds the buffer for printing output to log
- Managers for reconstruction threads and FIJI threads (and all processes)
- Tracks what paths are stored for the users defaults
- Managers for which loading icons should be displayed
- Tracks which element should have focus in the window
Parameters: - winfo – A data structure that holds a information about window and GUI.
- window – The main element that represents the GUI window.
- output_window – The main element that represents the Log output Window.
Returns: None
-
PyLorentz_GUI.init_rec(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c65461d0>, mask_reset: bool = True, arrow_reset: bool = True) → None[source]¶ Initialize Reconstruction Tab variables.
- Initializes winfo arguments for the reconstruction tab this includes:
- The image working directory
- Loaded image/stack dictionary
- The last enabled/disabled element list to see if enabling/disabling needs to change,
- this helps to prevent constantly enabling/disabling on every window call.
- The list of linear stack files
- ls_files1 is for unflip or tfs folder
- ls_files2 is for flip folder (when applicable)
- The fls files
- Tracking setting for the PYTIE parameters and object instances
- Trackers for the threads that are run or currently running for PYTIE
- initialization and reconstruction
- The last selected stack/image choice for viewing.
- Trackers for the stack and image choice sliders
- Dictionary of image choices available to view
- The transformation adjustments to apply to the non-reference image
- Trackers for the vector maps on the magnetic images
- Timers to update the transformation adjustment
- Arguments for tracking mask/ROI making and the corners/location of the mask/ROI.
Parameters: - winfo – A data structure that holds a information about window and GUI.
- window – The main element that represents the GUI window.
- mask_reset – Whether to reset the region select parameters.
- arrow_reset – Whether to reset the arrow parameters.
Returns: None
-
PyLorentz_GUI.metadata_change(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5410>, elem_val_list: List[Tuple[<sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc55d0>, str]], reset: bool = False) → None[source]¶ Change the metadata of the element to update between the default value and the user set value.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- elem_val_list – The list of tuples made of PySimpleGUI elements along with the value that the metadata of the element state ‘Set’ will change to.
- reset – If true, the ‘Set’ value is reset to ‘Def’. Otherwise the value will be ‘Set’ as defined by the user.
Returns: None
-
PyLorentz_GUI.ptie_init_thread(winfo: util.Struct, path: str, fls1_path: str, fls2_path: str, stack_name: str, files1: List[str], files2: List[str], single: bool, tfs_value: str) → None[source]¶ Create the PYTIE initialization thread.
Function initializes the parameters for PYTIE. See load_data from TIE_helper for more information on initialized parameters.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- path – The path to datafolder.
- fls1_path – Path to the first .fls file.
- fls2_path – Path to the second .fls file.
- stack_name – Name of the stack to perform reconstruction on.
- files1 – The files in the unflip or tfs folder.
- files2 – The files in the flip folder or None.
- single – Boolean value if a single tfs series or flipped tfs.
- tfs_value – The defined through focal series value by the user, whether it is a single series or unflip/flip series.
Returns: None
-
PyLorentz_GUI.ptie_recon_thread(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a6d0>, graph: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a910>, colorwheel_graph: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a950>, images: Dict[KT, VT], current_tab: str) → None[source]¶ Create the PYTIE reconstruction thread.
Function initializes the thread that runs the PYTIE reconstruction. For more information on the reconstruction, see TIE_reconstruct.py.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- graph – The reconstruction graph canvas.
- colorwheel_graph – The graph in the window where to place the colorwheel.
- images – The dictionary of images and their values.
- current_tab – The key representing the current main tab of the window.’
Returns: None
-
PyLorentz_GUI.ptie_save(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608aa50>, cwd: str, images: Dict[KT, VT], filenames: List[str], pref: str, im_dir: str, save_tie: Union[str, bool]) → None[source]¶ Save the current images of PYTIE.
Function saves the images of PYTIE, see TIE_reconstruct.py for more info.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- cwd – The current working directory that stores images and stacks.
- images – The dictionary of images and their values.
- filenames – List of filenames that will be saved.
- pref – The string denoting the prefix name for labeling the images.
- im_dir – The ‘image directory for saving.
- save_tie – The value for which save to apply to the current PYTIE images. Can be a full save, color image save, or saving of x/y magnetizations along with color.
Returns: None
-
PyLorentz_GUI.readlines(process: subprocess.Popen, queue: queue.Queue) → None[source]¶ Reads output that is passed to the queue from the running process.
Parameters: - process – The running process.
- queue – The queue of the output stream.
Returns: None
-
PyLorentz_GUI.rec_get_listbox_ind_from_key(key_list: List[str]) → List[int][source]¶ Get the listbox indices from key list to color once images have loaded.
Parameters: key_list – The list of keys of items in the rec listbox. Returns: The indices of the keys that were in the key_list. Return type: indices
-
PyLorentz_GUI.redraw_graph(graph: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608a190>, display_image: Optional[bytes]) → None[source]¶ Redraw graph.
Parameters: - graph – The graph element in the window.
- display_image – If None, the graph is erased Else, bytes representation of the image.
Returns: None
-
PyLorentz_GUI.reset(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc6550>, current_tab: str) → None[source]¶ Reset the current tab elements to default values.
Parameters: - winfo – A data structure that holds the information about the window and GUI.
- window – The main representation of the GUI window.
- current_tab – The key of the current tab being viewed in the window.
Returns: None
-
PyLorentz_GUI.retrieve_transform(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc6b10>, current_tab: str, transf_list: List[Tuple], old_transform: Tuple, new_transform: Tuple, mask: bool = False) → Tuple[source]¶ Return transformation to apply to image based off correct inputs and timers.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- current_tab – The key representing the current main tab of the window.
- transf_list – The list containing the tuple that has values and timers for each of rotation, x, and y inputs.
- old_transform – The previous transformation that was applied to img.
- new_transform – The next transformation to potentially apply to img.
- mask – The boolean value whether the transformation is for a mask or not.
Returns: The transformation to apply to the img.
Return type: transform
-
PyLorentz_GUI.run_home_tab(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608aa90>, event: str, values: Dict[KT, VT]) → None[source]¶ Run events associated with the Home tab.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- event – The key for the values dictionary that represents an event in the window.
- values – A dictionary where every value is paired with a key represented by an event in the window.
Returns: None
-
PyLorentz_GUI.run_reconstruct_tab(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608ab10>, current_tab: str, event: str, values: Dict[KT, VT]) → None[source]¶ Run events associated with the reconstruct tab.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- current_tab – The key representing the current main tab of the window. Ex. ‘
- event – The key for the values dictionary that represents an event in the window.
- values – A dictionary where every value is paired with a key represented by an event in the window.
Returns: None
-
PyLorentz_GUI.run_save_window(winfo: util.Struct, event: str, image_dir: str, orientations: Union[List[str], str, None] = None, defocus: Optional[str] = None, tfs: str = 'Unflip/Flip') → Tuple[List[str], List[bool], Optional[Tuple[str, bool, str]]][source]¶ Executes the save window.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- event – The key for the values dictionary that represents an event in the window.
- image_dir – The working directory where image will be saved
- orientations – List of the orientations or filetypes to categorize the saved file (‘flip’, ‘unflip’, ‘stack’, ‘’).
- defocus – The value for the defocus if running reconstruction.
- tfs – The through focal series value chosen for LS or BUJ.
Returns: The list of filenames to give the saved images. overwrite_signals: List of booleans of whether to overwrite files. prefix: The prefix for the tab to print to. save_tie: Boolean value of whether to execute saving of reconstructed images. im_dir: The image directory to save reconstructed images to.
Return type: filenames
-
PyLorentz_GUI.save_window_values(save_win: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c608ab90>, num_paths: int, event: str, orientations: List[str], defocus: Optional[str] = None, tfs: Optional[str] = None, true_paths: Optional[List[T]] = None) → List[str][source]¶ Sets ups the save window layout.
Parameters: - save_win – The representation of the save window.
- num_paths – The number of paths, to create the number of overwrite checkboxes and true_path input elements.
- event – The save event from the main GUI window.
- orientations – A list of strings that represent the orientations of the image (‘flip’, ‘unflip’, ‘stack’, etc.)
- defocus – The defocus value for the image if its REC.
- tfs – The selected through focal series.
- true_paths – The true_paths for the files to be saved.
Returns: The list containing the full path names.
Return type: true_paths
-
PyLorentz_GUI.set_crop_data(winfo: util.Struct, graph: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5b10>, images: Dict[KT, VT], ptie: TIE_params.TIE_params) → None[source]¶ Set the ptie crop data for reconstruction.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- graph – The graph of the reconstruction tab.
- images – The dictionary of the loaded reconstruction images.
- ptie – The TIE_params object for reconstruction.
Returns: The float of the mask size.
Return type: mask_transform
-
PyLorentz_GUI.set_pretty_focus(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc3810>, event: str) → None[source]¶ Sets the focus to reduce unwanted placements of cursor or focus within the GUI.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- event – The key for the values dictionary that represents an event in the window.
Returns: None
-
PyLorentz_GUI.shorten_name(path: str, ind: int = 1) → str[source]¶ Creates a string of the path name with only the direct parent “image_dir” and the child of “image_dir”.
Parameters: - path – The full_path to be shortened.
- ind – The index for checking how many ‘/’ to check in path.
Returns: The shortened pathname for window display.
Return type: shortname
-
PyLorentz_GUI.skip_save(filenames: List[str], image_dir: str) → bool[source]¶ Returns the flag on whether to skip saving a file.
If the path is not the intended path where the file will be saved, it will skip saving the file. This makes it so the files are stored where they are intended for use in reconstruction. The user may move them after they are saved at their own precaution.
Parameters: - filenames – The list of filenames to save.
- image_dir – The path of the current working directory for images.
Returns: The flag for whether to save the files.
-
PyLorentz_GUI.toggle(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5650>, elem_list: List[<sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5810>], state: Optional[str] = None) → None[source]¶ Toggle between the default state and set state of an elements metadata.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- elem_list – The list of elements whose state is to be changed.
- state – If the state is None, the state is changed from Set -> Def or Def -> Set. If the state is specified, that state will be activated.
Returns: None
-
PyLorentz_GUI.update_mask_size(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5ad0>, new_transform: Tuple[Union[int, float]]) → Tuple[float][source]¶ Update the mask size.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- new_transform – The next mask size to apply for REC graph.
Returns: The float of the mask size.
Return type: mask_transform
-
PyLorentz_GUI.update_rotxy(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5990>, current_tab: str, new_transform: Tuple[Union[int, float], Union[int, float], Union[int, float], bool]) → Tuple[Union[int, float], Union[int, float], Union[int, float], bool][source]¶ Update the rotation, x-trans, y-trans, and flip coordinates for the transform to apply to series of images.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- current_tab – The key representing the current main tab of the window.
- new_transform – The next transformation to potentially apply to img.
Returns: The transformation to apply to the img.
Return type: transform
-
PyLorentz_GUI.update_slider(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5850>, slider_list: List[Tuple[<sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5950>, Dict[KT, VT]]]) → None[source]¶ Updates sliders.
Updates sliders based off passing a list with element, dictionary pairs. The dictionary contains all values to update.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window. new_transform: The next mask size to apply for REC graph.
- slider_list – List of slider, dictionary tuple pairs where the dictionary contains the values to update.
Returns: None
-
PyLorentz_GUI.update_values(winfo: util.Struct, window: <sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5190>, elem_val_list: List[Tuple[<sphinx.ext.autodoc.importer._MockObject object at 0x7f37c5fc5210>, Any]]) → None[source]¶ Take a list of element key, value tuple pairs and update value of the element.
Parameters: - winfo – The data structure holding all information about windows and GUI.
- window – The element representing the main GUI window.
- elem_val_list – The list of elements, value paris to update.
Returns: None