Widget#
Custom Widget, etc.#
Custom widget.
This module provides customuized widgets.
- class Button(parent=None, text='', toggle=False, size=None, bold=False)[source]#
Bases:
QPushButtonButton widget.
- Parameters:
parent (QWidget, optional) -- parent.
text (str, optional) -- text.
toggle (bool, optional) -- toggle button ?
size (int, optional) -- font size.
bold (bool, optional) -- bold face ?
- class Check(parent=None, text='', size=None, bold=False)[source]#
Bases:
QCheckBoxCheck widget.
- Parameters:
parent (QWidget, optional) -- parent.
text (str, optional) -- text.
size (int, optional) -- font size.
bold (bool, optional) -- bold face ?
- class ColorSelector(parent=None, current='', color_type='color', size=None, bold=False)[source]#
Bases:
QComboBoxColor selector widget.
- Parameters:
parent (QWidget, optional) -- parent.
current (str, optional) -- default color.
color_type (str, optional) -- color/colormap/color_both
size (int, optional) -- font size.
bold (bool, optional) -- bold face ?
Notes
connect currentTextChanged.
- class Combo(parent=None, item=None, init=None, size=None, bold=False)[source]#
Bases:
QComboBoxCombo widget.
- Parameters:
parent (QWidget, optional) -- parent.
item (list, optional) -- list of items, [str].
init (str, optional) -- initial value.
size (int, optional) -- font size.
bold (bool, optional) -- bold face ?
- class DSpin(parent=None, minimum=0.0, maximum=1.0, step=0.1, size=None, bold=False)[source]#
Bases:
QDoubleSpinBoxSpin widget.
- Parameters:
parent (QWidget, optional) -- parent.
minimum (float, optional) -- minimum value.
maximum (float, optional) -- maximum value.
step (float, optional) -- step value.
size (int, optional) -- font size.
bold (bool, optional) -- bold face ?
- class Editor(parent=None, text='', validator=None, color='black', size=None, bold=False, mathjax=None)[source]#
Bases:
PanelEditor widget with math/text display.
- Parameters:
parent (QWidget, optional) -- parent.
text (str, optional) -- text.
validator (tuple, optional) -- (validator_type, option).
color (str, optional) -- color name.
size (int, optional) -- font size.
bold (bool, optional) -- bold face ?
mathjax (MathJaxSVG, optional) -- mathjax converter.
- class HBar(parent=None)[source]#
Bases:
QFrameHorizontal bar widget.
- Parameters:
parent (QWidget, optional) -- parent.
- class Label(parent=None, text='', color='black', size=None, bold=False)[source]#
Bases:
QLabelLabel widget.
- Parameters:
parent (QWidget, optional) -- parent.
text (str, optional) -- text.
color (str, optional) -- font color.
size (int, optional) -- font size (pt).
bold (bool, optional) -- bold font ?
- class Layout(parent=None)[source]#
Bases:
QGridLayoutLayout widget.
- Parameters:
parent (QWidget, optional) -- parent.
- class LineEdit(parent=None, text='', validator=None, size=None, bold=False)[source]#
Bases:
QLineEdit
- class MathWidget(parent=None, text='', color='black', size=None, mathjax=None)[source]#
Bases:
QWidget
- class Panel(parent=None)[source]#
Bases:
QWidgetPanel widget.
- Parameters:
parent (QWidget, optional) -- parent.
- class Spin(parent=None, minimum=0, maximum=1, size=None, bold=False)[source]#
Bases:
QSpinBoxSpin widget.
- Parameters:
parent (QWidget, optional) -- parent.
minimum (int, optional) -- minimum value.
maximum (int, optional) -- maximum value.
size (int, optional) -- font size.
bold (bool, optional) -- bold face ?
Validator type.
- type: option.
int: (min, max)
float: (min, max, digit)
list_int: (shape, var)
list_float: (shape, var ,digit)
math: (shape, var)
site: (use var?)
bond: (use var?)
site_bond: (use var?)
vector_site_bond: (use var?)
orbital_site_bond: (use var?)
- check_symbol(expr)[source]#
Check symbol.
- Parameters:
expr (sympy or ndarray)
- Returns:
(bool) -- if expr contains symbol, return True otherwise False.
- convert_to_bond(bond, use_var=False)[source]#
Convert to bond from str.
- Parameters:
bond (str) -- bond.
use_var (bool, optional) -- use [x,y,z] for site/bond ?
- Returns:
(ndarray) -- bond vector.
(ndarray) -- bond center.
Note
bond string is "[tail];[head]/[vector]@[center]/[start]:[vector]".
- validator_bond(s, use_var=False)[source]#
Validator for bond.
- Parameters:
s (str) -- bond string.
use_var (bool, optional) -- use [x,y,z] for 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) -- float string.
opt (dict, optional) -- option, "min/max/digit". (default: "*","*",5)
- Returns:
(str) -- formatted string if it is valid, otherwise None.
- validator_int(text, **opt)[source]#
Validator for int.
- Parameters:
text (str) -- int string.
opt (dict, optional) -- option, "min/max". (default: "*","*")
- Returns:
(str) -- formatted string if it is valid, otherwise None.
- validator_list_float(text, **opt)[source]#
Validator for list float.
- Parameters:
text (str) -- string with list.
opt (dict, optional) -- option, "digit/shape/var". (default: 5,None,[""]) e.g., 15, (), (n,), (n,m), ..., ["x", "y", ...].
- Returns:
(str) -- formatted string if it is valid, otherwise None.
- validator_list_int(text, **opt)[source]#
Validator for list int.
- Parameters:
text (str) -- string with list.
opt (dict, optional) -- option, "shape/var". (default: None,[""]) e.g., (), (n,), (n,m), ..., ["x", "y", ...].
- Returns:
(str) -- formatted string if it is valid, otherwise None.
- validator_math(text, **opt)[source]#
Validator for math to LaTeX.
- Parameters:
text (str) -- sympy string.
opt (dict, optional) -- option, "shape/var". (default: None,None)
- Returns:
(str) -- LaTeX 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 ?
- 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_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.
MessageBox dialog.
This module provides message box dialog.
- class MessageBox(msg, title='Message Box')[source]#
Bases:
QDialogMessage box.
- Parameters:
msg (str) -- message.
title (str) -- window title.
TableView widget.
This module provides table view widget.
- class TableView(parent=None, data=None, header=None, vertical=False, color='black', size=12, mathjax=None)[source]#
Bases:
QTableWidgetTable 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.
MathJaxSVG converter.
This module provides mathjax to SVG converter.
Data View and Model#
Tab of GroupView.
This module provides a set of group view classes in tab format.
- class TabGroupView(parent=None, models=None, title='Data', mathjax=None)[source]#
Bases:
QDialogData view group.
- Parameters:
parent (QWidget, optional) -- parent.
models (dict, optional) -- set of models, {object_type: GroupModel}.
title (str, optional) -- window title.
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(parent=None, model=None, use_delegate=True, mathjax=None)[source]#
Bases:
QTreeViewGroup view.
- Parameters:
parent (QWidget, optional) -- parent.
model (GroupModel, optional) -- group model.
use_delegate (bool, optional) -- use delegate or plain text ?
Context menu.
Delegate for GroupModel and GroupView.
This module provides delegate for color selector, combo, and editor.
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(parent=None, name='model', column_info=None)[source]#
Bases:
QStandardItemModelGroup data model (2 layer parent-child tree model).
- Parameters:
parent (QWidget, optional) -- parent.
name (str, optional) -- model name.
column_info (list, optional) -- {header: (type,option,default)} for each column.
- 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 ?
- 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_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_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_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=None)[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.
Event Loop & Logging#
Control Qt event loop.
This module provides functions to control Qt event loop.
- class ExceptionHook(parent=None)[source]#
Bases:
QObjectException hook.
- Parameters:
parent (QObject, optional) -- parent.
Note
- call this before super().__init__() in __init__() of QMainWindow class as follows.
self.app = get_qt_application()
ExceptionHook()
- get_qt_application()[source]#
Get Qt application.
- Returns:
(QApplication) -- Qt application.
Note
- call this before super().__init__() in __init__() of QMainWindow class as follows.
self.app = get_qt_application()
ExceptionHook()
Logging utility.
This module provides utilities for logging.
- class LogHandler(level=10, stream=None, text_widget=None)[source]#
Bases:
HandlerLog handler.
- Parameters:
level (Level, optional) -- log level.
stream (TextIO, optional) -- stream.
text_widget (LogWidget, optional) -- text widget.
Note
if stream/text_widget is None, it is not used.
- class LogWidget(parent=None, title='log message', level=10, stream=None, hook=True)[source]#
Bases:
QWidgetLog widget.
- Parameters:
parent (QObject, optional) -- parent.
title (str, optional) -- window title.
level (Level, optional) -- log level.
stream (TextIO, optional) -- stream for logging.
hook (bool, optional) -- exception hook ?
Note
if stream is True, sys.stderr is used.
if level is None, no logging.
- start_logging(level=10, stream=None, text_widget=None, hook=True)[source]#
Start logging.
- Parameters:
level (Level, optional) -- logging level.
stream (TextIO, optional) -- stream for logging.
text_widget (LogWidget, optional) -- text widget.
hook (bool, optional) -- exception hook ?
Note
stream is True, sys.stderr is used.
Misc.#
Simple PDF viewer.
This module contains a class for simple PDF viewer. It can load PDF file, and save the same file to different directory (just by copying it).
- class PDFViewer(filename=None)[source]#
Bases:
QWidgetSimple PDF viewer.
- Parameters:
filename (str, optional) -- file name to load.
Color selector widget.
This module provides color selector widget.
- color2pixmap(color_type, size, aspect_ratio=4, step=50)[source]#
Convert color/colormap to QPixmap.
- Parameters:
color_type (str) -- color type, "color/colormap/color_both".
size (int) -- size of pixmap.
aspect_ratio (int, optional) -- aspect ratio of pximap (width/height).
steps (int, optional) -- division of colorbar gradation.
- Retruns:
(dict) -- pixmap dict {name: pixmap}.
(list) -- separator position.