Skip to main content

A simple configurable table widget based on PyQt5 and pandas

Project description

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqttable-0.0.2.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

pyqttable-0.0.2-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file pyqttable-0.0.2.tar.gz.

File metadata

  • Download URL: pyqttable-0.0.2.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pyqttable-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f5e1900a5c3b93f89b5f3b8cd3d284a2164fdcbdfb6d99f4e12bacf24304b7a5
MD5 4806f270f9e5d7a0044b5c61b7a41457
BLAKE2b-256 c50e3d948595bc69cc728104662e3a92dbb7e88851d8e495ccd5e68fd3316e3a

See more details on using hashes here.

File details

Details for the file pyqttable-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyqttable-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pyqttable-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 556747481fc8e989f373b33487f2d362317db562bef80648f05c1f0b367e3131
MD5 5a30912f55b015ee11eb79c9157e1a5b
BLAKE2b-256 9b532debc0bfa35c557165c3156e23c4bd0168f9cb93a496a41208b21779113a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page