PDielec.GUI.NoteBook
#
NoteBook module
Module Contents#
Classes#
A Qt widget that holds tabs for managing different aspects of a notebook-like interface. |
- class PDielec.GUI.NoteBook.NoteBook(parent, program, filename, spreadsheet, debug=False, progressbar=None, scripting=False, default_scenario='powder', ncpus=0, threading=False)[source]#
Bases:
PyQt5.QtWidgets.QWidget
A Qt widget that holds tabs for managing different aspects of a notebook-like interface.
This class manages a complex interface which includes a range of functionalities such as handling various scenarios (e.g., Powder or SingleCrystal), managing computational resources, offering plotting abilities, managing settings, etc. It utilizes multithreading, handles external spreadsheet files for input and output, and provides a user interface for configuring and monitoring the progress of analytical or simulation tasks.
Parameters#
- parentQWidget
The parent widget.
- programstr
Description or identifier of the program associated with the notebook.
- filenamestr
Name of the file, if any, associated with the notebook.
- spreadsheettype
The spreadsheet object associated with the notebook.
- debugbool, optional
Flag to activate debug mode, by default False.
- progressbarQProgressBar, optional
A progressbar object to reflect the current progress, by default None.
- scriptingbool, optional
Flag to indicate if the notebook is used in scripting mode, by default False.
- default_scenariostr, optional
The type of default scenario to load at initiation, by default ‘powder’.
- ncpusint, optional
The number of CPUs to use, by default 0 which means autodetect.
- threadingbool, optional
Flag to enable threading, by default False.
Attributes#
- appQWidget
The application the notebook is part of.
- readertype
Reserved for future use, currently None.
- progressbarslist of QProgressBar
List of progress bar objects for tracking progress.
- progressbar_statusint
Current status of the progressbar.
- progressbar_maximumint
Maximum value of the progressbar.
- spreadsheettype
Spreadsheet object associated with the notebook.
- threadingbool
State of threading use.
- ncpusint
Number of CPUs being used.
- layoutQVBoxLayout
The layout for adding widgets to the notebook.
- tabOffSetint
Offset value for tab indices.
- plottingTabQWidget
Tab for managing plotting related functions.
- settingsTabQWidget
Tab for managing settings.
- analysisTabQWidget
Tab for managing analysis functions.
- viewerTabQWidget
Tab for managing 3D viewing options.
- fitterTabQWidget
Tab for managing fitting tasks.
- scenarioslist of QWidget
List containing scenario-specific tabs.
- tabsQTabWidget
The QTabWidget managing multiple tabs in the notebook interface.
- debugbool
Debug mode state.
- overwritingbool
State indicating if overwriting files without prompt is enabled.
- addScenario(scenarioType=None, copyFromIndex=-2)[source]#
Add a new scenario tab
If a copy is requested then copy the appropriate information into the new tab.
Parameters#
- scenarioTypestring
scenarioType can be one of ‘Powder’ or ‘SingleCrystal’
- copyFromIndexint
if copyFromIndex is not -2 then use the index to determine the scenario type if copyFromIndex is -2 and the scenarioType has not been specified then just use the last scenario type there is Otherwise just find the last scenario type to copy
Returns#
None
- deleteAllScenarios()[source]#
Delete all scenarios except the first one.
This method sequentially deletes each scenario from the end of the collection until only one scenario is left. It also removes the corresponding tabs.
Parameters#
None
Returns#
None
- deleteScenario(index)[source]#
Delete a scenario from the scenarios list and update tabs accordingly.
Parameters#
- indexint
The index of the scenario to be deleted.
Returns#
None
Notes#
This function will remove a scenario from the scenarios list at the specified index and update the tabs in the UI to reflect this change. It ensures that there is at least one scenario remaining. If the scenario to be deleted is the first one, the selection moves to the next available scenario. Otherwise, it selects the previous scenario.
- keyPressEvent(e)[source]#
Handle key press events for the application.
Parameters#
- eQKeyEvent
An event parameter containing details of the key that was pressed.
Returns#
None
Notes#
This function checks for specific key combinations (Control + S, and Control + C) and performs actions accordingly: - Control + S: Calls the print_settings method. - Control + C: Prints a message and exits the program.
- on_tabs_currentChanged(tabindex)[source]#
Handle tab change events and refresh content accordingly.
This function responds to changes in the current tab index within a tabbed interface. It refreshes the content of the new current tab based on the index of the tab. This includes refreshing content in tabs corresponding to settings, plotting, analysis, viewing, fitting, or specific scenarios.
Parameters#
- tabindexint
The index of the newly selected tab.
Returns#
None
Notes#
The function first checks if scripting is currently active; if so, it exits early without refreshing to avoid conflicts.
The ntabs variable calculates the total number of tabs dynamically based on the number of scenarios present.
The function determines which tab has been selected based on the tabindex and calls the appropriate refresh function for the content of that tab.
For predefined tabs (such as settings, plotting, analysis, viewing, and fitting tabs), direct refresh calls are made.
For scenario-specific tabs, which are dynamically added based on the number of scenarios, the function calculates the appropriate scenario index and triggers a refresh for the selected scenario.
- openSpreadSheet(filename)[source]#
Open or create a spreadsheet file.
This function checks whether the specified spreadsheet (.xlsx) file exists. If the file exists and overwriting is allowed or confirmed by the user, it opens and overwrites the file. If the file does not exist, it creates a new spreadsheet file. The function also closes any previously opened spreadsheet before attempting to open or create a new one.
Parameters#
- filenamestr
The name of the spreadsheet file to open or create.
Returns#
None
Notes#
The function relies on the ‘SpreadSheetManager’ class for handling spreadsheet operations.
The function raises no exceptions, but will print a message if the provided filename does not have a ‘.xlsx’ extension.
- open_excel_spreadsheet()[source]#
Open an Excel spreadsheet based on the filename set in settings.
This method tries to open an Excel spreadsheet file (.xlsx) whose name is provided in the ‘Excel file name’ setting of the ‘mainTab’ attribute. It checks for the validity of the filename (i.e., whether it ends in ‘.xlsx’) and existence in the specified directory. On failure, it alerts the user accordingly.
Parameters#
None
Returns#
None
Raises#
- QMessageBox
If the spreadsheet name is not valid (does not end in .xlsx).
If the spreadsheet name is empty.
- print_settings(filename=None)[source]#
Prints the current program settings to a file.
Each tab in the notebook is processed in turn, including all the scenarios. This allows a script to be written which can be used to recall a configuration of the program. Some settings need careful handling, for example the sigmas_cm1 values for the settingsTab
Parameters#
- filenamestr, optional
The name of the file to save the settings. If not specified, a save file dialog will be shown.
Returns#
None
- print_tab_settings(tab, title, fd, new_scenario=False)[source]#
Prints the configuration settings of a specified tab to a file descriptor.
Parameters#
- tabObject
An object representing a tab that contains settings and other attributes.
- titlestr
The title of the tab.
- fdfile descriptor
An open file descriptor where the settings should be printed.
- new_scenariobool, optional
A flag indicating whether this is a new scenario, by default False.
Returns#
None
Notes#
This function iterates through the settings of the provided tab object and prints each setting to the provided file descriptor. If new_scenario is True, it adds a scenario definition to the file. It handles special cases for certain settings like ‘Optical permittivity’ and ‘Mass definition’, and formats string values and others appropriately for printing.
- progressbars_add(bar)[source]#
Add a progress bar to the list of progress bars.
Parameters#
- barobject
The progress bar object to be added.
Returns#
None
Notes#
After adding the new progress bar to the list, this method updates the maximum value of all progress bars by calling self.progressbars_set_maximum with the current maximum value defined in self.progressbar_maximum.
- progressbars_set_maximum(maximum)[source]#
Set the maximum value for all progress bars in an object and reset their current status.
Parameters#
- maximumint
The maximum value to set for each progress bar.
Returns#
None
Notes#
This method sets the maximum value of all progress bars stored in the object’s progressbars attribute. It also resets the progress to 0.
- progressbars_update(increment=1)[source]#
Update the progress bars status by a specified increment.
Parameters#
- incrementint, optional
The value by which to increment the progress bar status, by default 1.
Returns#
None
This method increments the progress bar status stored in progressbar_status by the specified increment amount. It then sets this updated value as the new value for all progress bars stored in the progressbars list attribute of the instance.
- refresh(force=False)[source]#
Refreshes the current state, optionally forcing a refresh regardless of scripting constraints.
Parameters#
- forcebool, optional
Force a refresh even if scripting is active, by default False.
Returns#
None
Notes#
This method initiates a refresh process on various components such as the main settings, scenarios, and several tabs including plotting, analysis, viewer, and fitter. It adjusts the active tab based on the current number of scenarios. If ‘force’ is set to True, the refresh process is executed disregarding any active scripting conditions.
- requestRefresh()[source]#
Request a refresh operation.
This method toggles the refresh requirement state to true, indicating that a refresh is needed.
Parameters#
None
Returns#
None
- startPool()[source]#
Initializes a pool of worker processes or threads for computation.
This method initializes a pool based on the instance’s specified number of CPUs and the threading model. It accesses a global debugger variable for potential debugging purposes.
Parameters#
None
Returns#
None
Notes#
The Calculator.get_pool method is expected to be a class method or static method of the class Calculator that initializes a pool of worker processes or threads.
The pool is stored in the instance’s pool attribute.
The method uses a global variable debugger which should be defined elsewhere in the global scope for debugging purposes.
The number of CPUs (ncpus) and the threading model (threading) are not parameters of this method, but are expected to be attributes of the instance (self).
- switchScenario(index, scenarioType=None)[source]#
Switch the scenario tab based on the scenario type.
Parameters#
- indexint
The index of the scenario to switch to.
- scenarioTypestr, optional
The type of scenario to switch to. Can be ‘Powder’ or None. If None, the scenario type is determined by the current scenario’s type. If the scenarioType is anything else a ‘SingleCrystal’ scenario is switched to.
Returns#
None
Notes#
This method switches the current scenario to a new scenario based on the given scenario type or the current scenario’s type if no scenario type is provided.
The method updates the current scenario tab and refreshes the UI to reflect the new scenario.
If scenarioType is ‘Powder’, switch to a Powder scenario tab. Otherwise, switch to a Single Crystal scenario tab.
This function also updates all scenario tabs’ names based on their index and requests a refresh of the currently selected scenario.
See Also#
SingleCrystalScenarioTab, PowderScenarioTab : Classes representing different types of scenario tabs.
- writeSpreadsheet()[source]#
Write data to an Excel spreadsheet.
Parameters#
None
Returns#
None
Notes#
This function assumes that the Excel spreadsheet is an attribute of the object this method belongs to. It attempts to write data to various tabs within the spreadsheet, namely ‘mainTab’, ‘settingsTab’, ‘analysisTab’, and ‘plottingTab’. The method opens the spreadsheet, writes data to these tabs if the spreadsheet is not None, and then closes the spreadsheet.