neurochat.nc_uiutils module

This module implements utility functions and classes for NeuroChaT UI.

@author: Md Nurul Islam; islammn at tcd dot ie

class neurochat.nc_uiutils.NLogBox(parent=None)[source]

Bases: PyQt5.QtWidgets.QTextEdit

This class creates a formatted text-editable log-box for NeuroChaT.

Subclassed from PyQt5.QtWidgets.QTextEdit

get_text()[source]

Return the text of log-box in plain text format.

Parameters:None
Returns:str – Plain text of log-box
insert_log(msg)[source]

Format further the HTML ‘msg’ to categorally add color.

Also displays it in the log-box or in any log-handler.

Parameters:msg – Log record that is to be displayed
class neurochat.nc_uiutils.NOut[source]

Bases: PyQt5.QtCore.QObject

Implements the Qt signalling mechanism.

Subclassed from PyQt5.QtCore.QObject, it implements the Qt signalling mechanism so that when a text is written using NOut() object, it emits a text to the output to an output console or file or where the emitted signal is connected to.

In NeuroChaT, the sys.stdout.write is replaced with NOut().write, which means print(‘some text’) will print to GUI log box in GUI and to the standard output console when used in API.

emitted
write(text)[source]

Emit the texts as Qt signal.

Parameters:text (str) – Text to be emitted
Returns:None
class neurochat.nc_uiutils.PandasModel(data, parent=None)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Class to populate a QT table view with a pandas dataframe.

Also implements methods that are to be overridden.

columnCount(parent=None)[source]

Override the columnCount() method.

Parameters:parent (QtCore.QModelIndex) – Specific model for item index. Usually not required.
Returns:int – Count of column in the item model
data(index, role=0)[source]

Data model for the QtCore.QAbstractTableModel.

Parameters:
  • index – Pandas DataFrame index
  • role (Qt.ItemDataRole) – Usually set for QtCore.Qt.DisplayRole which means the data to rendered in the form of text
Returns:

str – Returns the data in the DataFrame’s ‘index’ location in str format

headerData(index, orientation, role)[source]

Data model for the QtCore.QAbstractTableModel.

Parameters:
  • index – Pandas DataFrame index
  • orientation (Qt.Orientation) – Orientation of the data
  • role (Qt.ItemDataRole) – Usually set for QtCore.Qt.DisplayRole which means the data to be rendered in the form of text
Returns:

  • Data in the DataFrame().columns[index] if orientation is ‘Horizontal’
  • or DataFrame().index[index] if orientation is ‘Vertical’

rowCount(parent=None)[source]

Override the rowCount() method.

Parameters:parent (QtCore.QModelIndex) – Specific model for item index. Usually not required.
Returns:int – Count of row in the item model
class neurochat.nc_uiutils.ScrollableWidget[source]

Bases: PyQt5.QtWidgets.QWidget

This class creates a scrollable PyQt5 widget.

Subclassed from PyQt5.QtWidgets.QWidget

setContents(cont_layout)[source]

Set the contents of the scrollable widget.

Parameters:cont_layout – PyQt5 layout that is the container for scrollable elements.
neurochat.nc_uiutils.add_check_box(parent=None, position=None, obj_name='', text=None)[source]

Return a QtWidgets.QCheckBox() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • obj_name (str) – Name of the newly created object
  • text (str) – Check box text
Returns:

QtWidgets.QCheckBox – Instance of QtWidgets.QCheckBox Class

neurochat.nc_uiutils.add_combo_box(parent=None, position=None, obj_name='')[source]

Return a QtWidgets.QComboBox() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • obj_name (str) – Name of the newly created object
Returns:

QtWidgets.QComboBox – Instance of QtWidgets.QComboBox Class

neurochat.nc_uiutils.add_double_spin_box(parent=None, position=None, min_val=0, max_val=1, obj_name='')[source]

Return a QtWidgets.QDoubleSpinBox() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • min_val (float) – Minimum value of the spin-box
  • max_val (float) – Maximum value of the spin-box
  • obj_name (str) – Name of the newly created object
Returns:

QtWidgets.QDoubleSpinBox – Instance of QtWidgets.QDoubleSpinBox Class

neurochat.nc_uiutils.add_group_box(parent=None, position=None, obj_name='', title=None)[source]

Return a QtWidgets.QGroupBox() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • obj_name (str) – Name of the newly created object
  • title (str) – Title of the group-box
Returns:

QtWidgets.QGroupBox – Instance of QtWidgets.QGroupBox Class

neurochat.nc_uiutils.add_label(parent=None, position=None, obj_name='', text=None)[source]

Return a QtWidgets.QLabel() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • obj_name (str) – Name of the newly created object
  • text (str) – Label text
Returns:

QtWidgets.QLabel – Instance of QtWidgets.QLabel Class

neurochat.nc_uiutils.add_line_edit(parent=None, position=None, obj_name='', text=None)[source]

Return a QtWidgets.QLineEdit() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • obj_name (str) – Name of the newly created object
  • text (str) – Line-edit text
Returns:

QtWidgets.QLineEdit – Instance of QtWidgets.QLineEdit Class

neurochat.nc_uiutils.add_log_box(obj_name)[source]

Return a NLogBox() object.

Parameters:obj_name (str) – Name of the newly created object
Returns:NLogBox – Instance of NLogBox Class
neurochat.nc_uiutils.add_push_button(parent=None, position=None, obj_name='', text=None)[source]

Return a QtWidgets.QPushButton() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • obj_name (str) – Name of the newly created object
  • text (str) – Button text
Returns:

QtWidgets.QPushButton – Instance of QtWidgets.QPushButton Class

neurochat.nc_uiutils.add_radio_button(parent=None, position=None, obj_name='', text=None)[source]

Return a QtWidgets.QRadioButton() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • obj_name (str) – Name of the newly created object
  • text (str) – Button text
Returns:

QtWidgets.QRadioButton – Instance of QtWidgets.QRadioButton Class

neurochat.nc_uiutils.add_spin_box(parent=None, position=None, obj_name='', min_val=0, max_val=128)[source]

Return a QtWidgets.QSpinBox() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • min_val (int) – Minimum value of the spin-box
  • max_val (int) – Maximum value of the spin-box
  • obj_name (str) – Name of the newly created object
Returns:

QtWidgets.QSpinBox – Instance of QtWidgets.QSpinBox Class

neurochat.nc_uiutils.add_widget(parent=None, position=None, obj_name='')[source]

Return a QtWidgets.QWidget() object.

Parameters:
  • parent – Parent widget
  • position (tuple) – Position in the parent object
  • obj_name (str) – Name of the newly created object
Returns:

QtWidgets.QWidget – Instance of QtWidgets.QWidget Class

neurochat.nc_uiutils.xlt_from_utf8(s)[source]