Register Custom Actions¶
Tabulous viewer has several components that support custom action registration using
method register()
. All the register()
methods will be used as following syntax.
# viewer specific actions
@viewer.XXX.register("<Location description>")
def func(viewer):
...
# table specific actions
@table.XXX.register("<Location description>")
def func(table):
...
Contents
Custom Command in Command Palette¶
tabulous
provides a command palette for executing actions. You can register
your own actions to the command palette using register()
method.
from tabulous import TableViewer
viewer = TableViewer()
# will be register under "User defined" context
@viewer.command_palette.register("Print all table names")
def func(viewer: TableViewer):
for table in viewer.tables:
print(table.name)
# will be register under "Table" context
@viewer.command_palette.register("Table: Print current table name")
def func(viewer: TableViewer):
print(viewer.current_table.name)
Custom Keybindings¶
Both viewers and tables have keymap
attribute for keymap registration.
viewer.keymap.register()
… register keybindings to the viewer.table.keymap.register()
… register keybindings to a table.
from tabulous import TableViewer
viewer = TableViewer()
# register function "func" as an action for key "Ctrl+U"
@viewer.keymap.register("Ctrl+U")
def func(viewer: TableViewer):
print("Ctrl+U is pressed")
# register function "func" as an action for key combo "Ctrl+K, Ctrl+U"
@viewer.keymap.register("Ctrl+K, Ctrl+U")
def func(viewer: TableViewer):
print("keycombo Ctrl+K -> Ctrl+U is pressed")