Skip to main content

pyqttable

A simple configurable table widget based on PyQt5 and pandas

How to use

Get version

from pyqttable import version

print(version.VERSION)

Create table

from pyqttable import PyQtTable

table_widget = PyQtTable(
    parent=None,              # parent widget
    column_config=my_config,  # column configurations
    show_filter=True,         # show filter in header
    sortable=True,            # sortable column (triggered by right click)
    draggable=True,           # draggable column
)

Column Config

A list of configurations for each column

Config Key Description Value Type Default Value
key key of column (used to access data from DataFrame) str # required
name column name to display str # same as key
type column value type (required for conversion between real value and string) # see Column.Type str
editable controlling the cell value is read-only or not bool True
default default value when key is missing in data (not recommended) - None
h_align horizontal alignment # see Column.Align 'l'
v_align vertical alignment # see Column.Align 'c'
selection list of valid values list None
sort_lt DIY __lt__ methods for sorting (only effective when sortable is True) # see Column.Sort None
filter_type filter type (only effective when show_filter is True) # see Column.Filter 'contain'
color font color (in string or tuple indicating RGB) # see Column.Color None
bg_color background color (same format as color) # see Column.Color None

Example

{
    'key': 'gender',                        # same as DataFrame column
    'name': 'Gender',                       # shown as table header
    'type': str,                            # string variable
    'editable': False,                      # read-only
    'selection': ['male', 'female'],        # could be either 'male' or 'female'
    'h_align': 'r',                         # align right
    'sort_lt': lambda x, y: x == 'female',  # 'female' < 'male'
    'filter_type': 'multiple_choice',       # multiple-choice filter
    'bg_color': (135, 206, 250)},           # blue opaque background
}

Column.Type

Column type should be following class (not instance)

Column type
int
float
str
bool
datetime.datetime
datetime.date
datetime.time

Column type can also be instance of ColumnType Inherit from ColumnType to make DIY column type Inherit from EditorFactory to make DIY editor for DIY column type (if required)

from pyqttable.column import type_
from pyqttable.editor import EditorFactory

class MyEditorFactory(EditorFactory):
    ...

class MyColumnType(type_.ColumnType):
    EditorFactory = MyEditorFactory()
    ...

Column.Align

Key Valid value Flag
h_align 'l' / 'left' AlignLeft
h_align 'r' / 'right' AlignRight
h_align 'c' / 'center' AlignHCenter
v_align 't' / 'top' AlignTop
v_align 'b' / 'bottom' AlignBottom
v_align 'c' / 'center' AlignVCenter

Column.Color

Value type Value format
str '#RRGGBB'
Tuple[int] (R, G, B, Optional[T])

Column.Filter

Column filter type should by following string

Filter type
'exact'
'contain'
'expression'
'regex'
'multiple_choice'

Column filter type can also be instance of Filter Inherit from Filter to make DIY filter type

from pyqttable.column import filter_

class MyFilterType(filter_.Filter):
    ...

Column.Sort

Sorting is triggered by right click on headers Variable sort_lt should be a function with same signature as __lt__ When sort_lt is defined, sorting action will based on sort_lt instead of default __lt__

How to set data

import pandas as pd
my_data = pd.DataFrame(...)
table_widget.set_data(my_data)

How to get data

my_data = table_widget.get_data(data)
shown_data = table_widget.get_data(data, full=False)

How to get filter data

current_filter_dict = table_widget.get_filter_data()

Release files for pyqttable 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyqttable 0.0.2
File Size Uploaded
pyqttable-0.0.2.tar.gz 20.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyqttable 0.0.2
File Interpreter ABI Platform
pyqttable-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 47.6 kB

Release files / pyqttable-0.0.2.tar.gz

Download URL pyqttable-0.0.2.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f5e1900a5c3b93f89b5f3b8cd3d284a2164fdcbdfb6d99f4e12bacf24304b7a5
BLAKE2b-256 checksum
How to use checksums
c50e3d948595bc69cc728104662e3a92dbb7e88851d8e495ccd5e68fd3316e3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / pyqttable-0.0.2-py3-none-any.whl

Download URL pyqttable-0.0.2-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
556747481fc8e989f373b33487f2d362317db562bef80648f05c1f0b367e3131
BLAKE2b-256 checksum
How to use checksums
9b532debc0bfa35c557165c3156e23c4bd0168f9cb93a496a41208b21779113a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page