Widget

Contents

Widget#

Custom Widget#

Custom widget.

This module provides customuized widgets.

class Button(parent=None, text='', toggle=False)[source]#

Bases: QPushButton

Button widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • text (str, optional) -- text.

  • toggle (bool, optional) -- toggle button ?

class Check(parent=None, text='')[source]#

Bases: QCheckBox

Check widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • text (str, optional) -- text.

is_checked()[source]#

Is checked ?

Returns:

  • (bool) -- checked ?

class Color(color)[source]#

Bases: QColor

Parameters:

color (str) -- color name.

class ColorLabel(parent=None, color='', bold=False)[source]#

Bases: Panel

Color label widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • color (str, optional) -- color/colormap name.

  • bold (bool, optional) -- bold font ?

class ColorSelector(parent=None, current='', color_type='color')[source]#

Bases: QComboBox

Color selector widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • current (str, optional) -- default color.

  • color_type (str, optional) -- color/colormap/color_both

Notes

  • connect currentTextChanged.

class Combo(parent=None, item=[], init=None)[source]#

Bases: QComboBox

Combo widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • item (list, optional) -- list of items, [str].

  • init (str, optional) -- initial value.

find_index(key)[source]#

Find index.

Parameters:

key (str) -- item key.

Returns:

  • (int) -- index.

get_item()[source]#

Get item.

Returns:

  • (list) -- item list.

set_item(item)[source]#

Set item.

Parameters:

item (list) -- item list.

class DSpin(parent=None, min=0.0, max=1.0, step=0.1)[source]#

Bases: QDoubleSpinBox

Spin widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • min (float, optional) -- minimum value.

  • max (float, optioanl) -- maximum value.

  • step (float, optional) -- step value.

class Editor(parent=None, text='', validator=None, color='black', size=10, dpi=120)[source]#

Bases: Panel

Math equation label widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • text (str, optional) -- text.

  • validator (tuple, optional) -- (validator_type, option).

  • color (str, optioanl) -- color name.

  • size (int, optional) -- font size.

  • dpi (int, optional) -- DPI.

Note

  • following validators can be used.
    • int: (min, max).

    • float: (min, max, digit).

    • sympy_float: (digit).

    • sympy: (variable list).

    • ilist: (shape).

    • list: (shape, variable list, digit).

    • site: (use variable?).

    • bond: (use variable?).

    • site_bond: (use variable?).

    • vector_site_bond: (use variable?).

    • orbital_site_bond: (use variable?).

clearFocus()[source]#

Clear focus.

close_editor()[source]#

Close editor.

currentText()[source]#

Get current text.

Returns:

  • (str) -- current text.

mouseDoubleClickEvent(event)[source]#

Mouse double-click event.

mousePressEvent(event)[source]#

Mouse click event.

raw_text()[source]#

Raw text.

Returns:

  • (str) -- raw text.

setCurrentText(text)[source]#

Set current text.

Parameters:

text (str) -- text.

setText(text)[source]#

Set text.

Parameters:

text (str) -- text.

text()[source]#

Text.

Returns:

  • (str) -- text.

class HBar(parent=None)[source]#

Bases: QFrame

Horizontal bar item.

Parameters:

parent (QWidget, optional) -- parent.

class HSpacer[source]#

Bases: QSpacerItem

Horizontal spacer.

class Label(parent=None, text='', bold=False, color='black', size=10, math=False, dpi=120)[source]#

Bases: QLabel

Label widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • text (str, optional) -- text.

  • bold (bool, optional) -- bold font ?

  • color (str, optional) -- font color.

  • size (int, optional) -- font size.

  • math (bool, optional) -- for math ?

  • dpi (int, optional) -- DPI for math.

Note

  • in math mode, text is given in LaTeX code without $.

setText(text)[source]#

Set text.

Parameters:

text (xtr) -- text.

class Layout(parent=None)[source]#

Bases: QGridLayout

Layout widget.

Parameters:

parent (QWidget, optional) -- parent.

class LineEdit(parent=None, text='', validator=None)[source]#

Bases: QLineEdit

Line editor.

Parameters:
  • parent (QWidget, optional) -- parent.

  • text (str, optional) -- text.

  • validator (tuple, optional) -- (validator_type, option).

clearFocus()[source]#

Clear focus.

close_edit()[source]#

Close editor.

focusInEvent(event)[source]#

Focus-out event.

focusOutEvent(event)[source]#

Focus-out event.

keyPressEvent(event)[source]#

Key event.

Parameters:

event (str) -- event.

raw_text()[source]#

Raw text.

Returns:

  • (str) -- raw text.

setText(text)[source]#

Set text.

Parameters:

text (str) -- text.

set_read_only(flag)[source]#

Set read only.

Parameters:

flag (bool) -- read only ?

set_validator(validator)[source]#

Set validator.

Parameters:

validator (tuple) -- (validator_type, option).

property read_only#

Read only ?

Returns:

  • (bool) -- read only ?

property validator#

Validator type.

Returns:

  • (str) -- validator type.

class Panel(parent=None)[source]#

Bases: QWidget

Panel widget.

Parameters:

parent (QWidget, optional) -- parent.

class Spin(parent=None, min=0, max=1)[source]#

Bases: QSpinBox

Spin widget.

Parameters:
  • parent (QWidget, optional) -- parent.

  • min (int, optional) -- minimum value.

  • max (int, optional) -- maximum value.

class VSpacer[source]#

Bases: QSpacerItem

Vertical spacer.

Validator#

Validator type.

  • type: option ["*": no limit, digit only for no variable list=None(no check), [""](no variable)]
    • int: (min, max)

    • float: (min, max, digit)

    • sympy_float: (digit)

    • sympy: (variable list)

    • ilist: (shape)

    • list: (shape, variable list, digit)

    • site: (use variable?)

    • bond: (use variable?)

    • site_bond: (use variable?)

    • vector_site_bond: (use variable?)

    • orbital_site_bond: (use variable?)

validator_bond(s, use_var=False)[source]#

Validator for bond.

Parameters:
  • s (str) -- bond string.

  • use_var (bool, optional) -- use [x,y,z] for site/bond ?

Returns:

  • (str) -- input s if it is valid, otherwise None.

Note

  • bond sytles, start:vector, tail;head, vector@center, are accepted.

validator_float(text, opt)[source]#

Validator for float.

Parameters:
  • text (str) -- int string.

  • opt (tuple, optional) -- option, (min, max, digit).

Returns:

  • (str) -- formatted string if it is valid, otherwise None.

validator_ilist(s, opt)[source]#

Validator for int list.

Parameters:
  • s (str) -- int list string.

  • opt (tuple, optional) -- option, shape, (), (n,), (n,m), ...

Returns:

  • (str) -- formatted string if it is valid, otherwise None.

validator_int(text, opt)[source]#

Validator for int.

Parameters:
  • text (str) -- int string.

  • opt (tuple, optional) -- option, (min, max).

Returns:

  • (str) -- formatted string if it is valid, otherwise None.

validator_list(s, opt)[source]#

Validator for sympy list.

Parameters:
  • s (str) -- sympy list string.

  • opt (tuple, optional) -- option, (shape, var, digit).

Returns:

  • (str) -- formatted string if it is valid, otherwise None.

validator_orbital_site_bond(s, use_var=False)[source]#

Validator for orbital on site or bond.

Parameters:
  • s (str) -- orbital on site or bond string.

  • use_var (bool, optional) -- use [x,y,z] for site/bond ?

Returns:

  • (str) -- input s if it is valid, otherwise None.

Note

  • orbital can contain x, y, z, r.

  • bond sytles, start:vector, tail;head, vector@center, are accepted.

validator_site(s, use_var=False)[source]#

Validator for site.

Parameters:
  • s (str) -- site string, [x,y,z].

  • use_var (bool, optional) -- use [x,y,z] for site/bond ?

Returns:

  • (str) -- input s if it is valid, otherwise None.

validator_site_bond(s, use_var=False)[source]#

Validator for site or bond.

Parameters:
  • s (str) -- site or bond string.

  • use_var (bool, optional) -- use [x,y,z] for site/bond ?

Returns:

  • (str) -- input s if it is valid, otherwise None.

Note

  • bond sytles, start:vector, tail;head, vector@center, are accepted.

validator_sympy(text, opt)[source]#

Validator for sympy.

Parameters:
  • text (str) -- sympy string.

  • opt (list, optional) -- option, var.

Returns:

  • (str) -- LaTeX string if it is valid, otherwise None.

validator_sympy_float(text, opt)[source]#

Validator for sympy.

Parameters:
  • text (str) -- sympy string.

  • opt (int, optional) -- option, digit.

Returns:

  • (str) -- formatted string if it is valid, otherwise None.

validator_vector_site_bond(s, use_var=False)[source]#

Validator for vector on site or bond.

Parameters:
  • s (str) -- vector on site or bond string.

  • use_var (bool, optional) -- use [x,y,z] for site/bond ?

Returns:

  • (str) -- input s if it is valid, otherwise None.

Note

  • bond sytles, start:vector, tail;head, vector@center, are accepted.

Message Box#

MessageBox dialog.

This module provides message box dialog.

class MessageBox(msg, title='Message Box')[source]#

Bases: QDialog

Message box.

Parameters:
  • msg (str) -- message.

  • title (str) -- window title.

Table View#

TableView widget.

This module provides table view widget.

class TableView(parent=None, data=[['']], header=None, vertical=False, color='black', size=12, dpi=120)[source]#

Bases: QTableWidget

Table view (math).

Parameters:
  • parent (QWidget, optional) -- parent.

  • data (list, optional) -- table data in LaTeX code without "$".

  • header (list, optional) -- header string.

  • vertical (bool, optional) -- show vertical number header ?

  • color (str, optional) -- color name.

  • size (int, optional) -- font size.

  • dpi (int, optional) -- DPI.

Data View and Model#

Tab of GroupView.

This module provides a set of group view classes in tab format.

class TabGroupView(models, title='Data', parent=None)[source]#

Bases: QDialog

Data view group.

Parameters:
  • models (dict) -- set of models, {object_type: GroupModel}.

  • title (str, optional) -- window title.

  • parent (QWidget, optional) -- parent.

select_tab(object_type)[source]#

Select tab.

Parameters:

object_type (str) -- object type.

View panel for GroupModel.

This module provides a view class to show object data. By clicking right button of mouse, the context menu appears.

class GroupView(model, parent=None)[source]#

Bases: QTreeView

Group view.

Parameters:
  • model (GroupModel) -- group model.

  • parent (QWidget, optional) -- parent.

clear_selection()[source]#

Clear selection.

context_menu(position)[source]#

Context menu.

copy_row()[source]#

Copy row.

insert_row()[source]#

Insert row.

keyPressEvent(event)[source]#

Key press event for ESC and up and down keys.

mousePressEvent(event)[source]#

Mouse press event for focus or clear selection.

remove_row()[source]#

Remove row.

select_row(index)[source]#

Select row.

Parameters:

index (QModelIndex) -- index.

selection_changed(selected, deselected)[source]#

For Selection changed.

Parameters:
  • selected (list) -- selected indexes.

  • deselected (list) -- deselected indexes.

set_widget(item)[source]#

Set widget.

Parameters:

item (QStandardItem) -- item.

update_widget(force=False)[source]#

Update widget.

Two-layer tree model for managing objects.

This module provides a class to manage objects to draw. The objects are grouped by the first column, "name". All the objects in the same group can be modified together. When there are more than two objects in the same group, a child tree appears and the parent tree is the same as the first row of the child tree.

The raw data is maintained by dict, and the index model is just to keep the relation between parent and child, which is necessary to use other Qt functionalities.

class GroupModel(name, column_info, parent=None)[source]#

Bases: QStandardItemModel

Group data model (2 layer parent-child tree model).

Parameters:
  • name (str) -- model name.

  • column_info (list) -- {header: (type,option,default)} for each column.

  • parent (QWidget, optional) -- parent.

action_copy_row(indexes)[source]#

Slot for copy row action.

Parameters:

indexes (list) -- list of index.

action_insert_row(indexes)[source]#

Slot for insert row action.

Parameters:

indexes (list) -- list of index.

Returns:

  • (QModelIndex) -- parent index of inserted row.

action_remove_row(indexes)[source]#

Slot for remove row action.

Parameters:

indexes (list) -- list of index.

append_row(row_data=None, role=None, index=<PySide6.QtCore.QModelIndex(-1, -1, 0x0, QObject(0x0))>, copy_row=False)[source]#

Append row.

Parameters:
  • row_data (list, optional) -- row data.

  • role (int, optional) -- role.

  • index (QModelIndex, optional) -- index.

  • copy_row (bool, optional) -- copy from current index ?

block_update_widget(flag)[source]#

Block update widget.

Parameters:

flag (bool) -- block update ?

Note

  • in order to avoid unnecessary update of widget, otherwise it becomes very slow.

clear_data()[source]#

Clear data with keeping header and column info.

debug_data_changed(topLeft, bottomRight, roles=[])[source]#

Debug for dataChanged signal.

Parameters:
  • topLeft (QModelIndex) -- top left index.

  • bottomRight (QModelIndex) -- bottom right index.

  • roles (list, optional) -- list of roles.

debug_item_tree()[source]#

Debug for showing item tree.

debug_updata_data(name, row_data, role)[source]#

Debug for updateData signal.

Parameters:
  • name (str) -- group name.

  • row_data (list) -- row data.

  • role (int) -- role.

emit_update_all()[source]#

Emit update for all data.

emit_update_data(name, row_data, role, index)[source]#

Emit update data.

Parameters:
  • name (str) -- group name.

  • row_data (list) -- row_data.

  • role (int) -- role.

  • index (QModelIndex) -- index.

find_item(text, column=0, child=True)[source]#

Find item.

Parameters:
  • text (str) -- str to find.

  • column (int, optional) -- column.

  • child (bool, optional) -- find also for child ?

Returns:

  • (list) -- found items.

get_role_str(role)[source]#

Get role string.

Parameters:

role (int) -- role.

Returns:

  • (str) -- role string.

get_row_data(index, column=None)[source]#

Get row data.

Parameters:
  • index (QModelIndex) -- index.

  • column (int, optional) -- column.

Returns:

  • (list) -- row data.

Note

  • bool string is replaced by bool.

is_parent(index)[source]#

Is parent index ?

Parameters:

index (QModelIndex) -- index.

Returns:

  • (bool) -- parent index ?

move_row(index, value)[source]#

Move row.

Parameters:
  • index (QModelIndex) -- index.

  • value (QVariant) -- value.

remove_row(index, role=None)[source]#

Remove row.

Parameters:
  • index (QModelIndex) -- index.

  • role (int, optional) -- role.

setData(index, value, role=ItemDataRole.EditRole)[source]#

Set data (override).

Parameters:
  • index (QModelIndex) -- index.

  • value (QVariant) -- value to set.

  • role (int, optional) -- role.

Returns:

  • (bool) -- success to set data ?

set_check(index, column, data)[source]#

Set check state.

Parameters:
  • index (QModelIndex) -- index.

  • column (int) -- column.

  • data (QCheckState) -- check state.

set_check_state(item, row_data)[source]#

Set check state of row.

Parameters:
  • item (QItemModel) -- item of row(s).

  • row_data (list) -- row data, [str].

set_data(data)[source]#

Set data from list data.

Parameters:

- (list)

set_row_data(index, column, data)[source]#

Set row data.

Parameters:
  • index (QModelIndex) -- index.

  • column (int) -- column.

  • data (str) -- data.

show_index(index)[source]#

Get raw index.

Parameters:

index (QModelIndex) -- index.

Returns:

  • (str) -- raw index, P/C(row,column).

tolist()[source]#

Convert to list.

Parameters:

raw (bool, optional) -- raw data ?

Returns:

  • (list) -- list data.

tolist_index(topLeft, bottomRight)[source]#

Row data for given index.

Parameters:
  • topLeft (QModelIndex) -- index at top left.

  • bottomRight (QModelIndex) -- index at buttom right.

Returns:

  • (list) -- row data.

update_check_state(topLeft, bottomRight, roles=[])[source]#

Update check state data.

Parameters:
  • topLeft (QModelIndex) -- top left index.

  • bottomRight (QModelIndex) -- bottom right index.

  • roles (list, optional) -- list of roles.

Note

  • set check state (bool) in column+1.

property group_name#

Group name.

Returns:

  • (str) -- group name.

property header#

Header label.

Returns:

  • (list) -- header label.

Delegate for GroupModel and GroupView.

This module provides delegate for color selector, combo, and editor.

class ColorDelegate(parent)[source]#

Bases: Delegate

Create delegate for ColorSelector.

Parameters:

parent (QWidget) -- parent.

createEditor(parent, option, index)[source]#

Create color selector.

Parameters:
  • parent (QWidget) -- parent.

  • option (QStyleOptionViewItem) -- option.

  • index (QModelIndex) -- index.

Returns:

  • (ColorSelector) -- color selector widget.

class ComboDelegate(parent)[source]#

Bases: Delegate

Create delegate for Combo.

Parameters:

parent (QWidget) -- parent.

createEditor(parent, option, index)[source]#

Create combobox.

Parameters:
  • parent (QWidget) -- parent.

  • option (QStyleOptionViewItem) -- option.

  • index (QModelIndex) -- index.

Returns:

  • (Combo) -- combo widget.

class Delegate(parent)[source]#

Bases: QStyledItemDelegate

Base delegate.

Parameters:

parent (QWidget) -- parent.

paint(painter, option, index)[source]#

Paint cell.

Parameters:
  • painter (QPainter) -- painter.

  • option (QStyleOptionViewItem)

  • index (QModelIndex) -- index.

setEditorData(editor, index)[source]#

Set editor data.

Parameters:
  • editor (QWidget) -- editor.

  • index (QModelIndex) -- index.

setModelData(editor, model, index)[source]#

Set model data.

Parameters:
  • editor (QWidget) -- editor.

  • model (QAbstractItemModel)

  • index (QModelIndex) -- index.

updateEditorGeometry(editor, option, index)[source]#

Update editor geometry.

Parameters:
  • editor (QWidget) -- editor.

  • option (QStyleOptionViewItem)

  • index (QModelIndex) -- index.

class EditorDelegate(parent)[source]#

Bases: Delegate

Create delegate for Editor.

Parameters:

parent (QWidget) -- parent.

createEditor(parent, option, index)[source]#

Create editor.

Parameters:
  • parent (QWidget) -- parent.

  • option (QStyleOptionViewItem) -- option.

  • index (QModelIndex) -- index.

Returns:

  • (Editor) -- editor widget.