App
elva.apps.chat.app
App definition.
Classes:
-
MessageView
–Widget displaying a single message alongside its metadata.
-
MessageList
–Base container class for
MessageView
widgets. -
History
–List of already sent messages.
-
HistoryParser
–Parser for changes in the message history.
-
Future
–List of currently composed messages.
-
FutureParser
–Parser for changes in currently composed messages.
-
MessagePreview
–Preview of the rendered markdown content.
-
UI
–User interface.
Attributes:
-
WHITESPACE_ONLY
–Regular Expression for whitespace-only messages.
WHITESPACE_ONLY = re.compile('^\\s*$')
module-attribute
Regular Expression for whitespace-only messages.
MessageView(author, text, **kwargs)
Bases: Widget
Widget displaying a single message alongside its metadata.
Parameters:
-
author
(str
) –the author of the message.
-
text
(Text
) –an instance of a Y text data type holding the message content.
-
kwargs
(dict
, default:{}
) –keyword arguments passed to
Widget
.
Methods:
-
on_mount
–Hook called on mounting the widget.
-
compose
–Hook arranging child widgets.
-
on_unmount
–Hook called on unmounting.
-
text_callback
–Hook called on changes in the message text.
Source code in src/elva/apps/chat/app.py
on_mount()
Hook called on mounting the widget.
This method subscribes to changes in the message text and displays it if there is some content to show.
Source code in src/elva/apps/chat/app.py
compose()
on_unmount()
text_callback(event)
Hook called on changes in the message text.
This method updates the visibility of the view in dependence of the message content.
Parameters:
-
event
(TextEvent
) –object holding information about the changes in the Y text.
Source code in src/elva/apps/chat/app.py
MessageList(messages, user, **kwargs)
Bases: VerticalScroll
Base container class for MessageView
widgets.
Parameters:
-
messages
(Array | Map
) –Y array or Y map containing message objects.
-
user
(str
) –the current username of the app.
-
kwargs
(dict
, default:{}
) –keyword arguments passed to
VerticalScroll
.
Methods:
-
get_message_view
–Create a
MessageView
.
Source code in src/elva/apps/chat/app.py
get_message_view(message, message_id=None)
Create a MessageView
.
Parameters:
-
message
(Map | dict
) –mapping of message attributes.
-
message_id
(None | str
, default:None
) –Textual
DOM tree identifier to assign to the message view.
Returns:
-
MessageView
–a message view to be mounted inside an instance of this class.
Source code in src/elva/apps/chat/app.py
History(messages, user, **kwargs)
Bases: MessageList
List of already sent messages.
Methods:
-
compose
–Hook arranging child widgets.
Source code in src/elva/apps/chat/app.py
HistoryParser(history, widget)
Bases: ArrayEventParser
Parser for changes in the message history.
This class reflects the state of the Y array with history message in the History
message list on changes.
Parameters:
-
history
(Array
) –Y array containing already sent messages.
Methods:
-
history_callback
–Hook called on a change in the Y array message history.
-
before
–Hook called before the component sets the
RUNNING
state. -
on_insert
–Hook called on an insert action in a Y array change event.
-
cleanup
–Hook called after cancellation and before the component unsets its state to
NONE
. -
on_delete
–Hook called on a delete action in a Y array change event.
Source code in src/elva/apps/chat/app.py
history_callback(event)
Hook called on a change in the Y array message history.
This method parses the event and calls the defined action hooks accordingly.
Parameters:
-
event
(ArrayEvent
) –an object holding information about the change in the Y array.
Source code in src/elva/apps/chat/app.py
before()
async
Hook called before the component sets the RUNNING
state.
This method subscribes to changes in the Y array message history.
Source code in src/elva/apps/chat/app.py
on_insert(range_offset, insert_value)
async
Hook called on an insert action in a Y array change event.
This methods creates a new message view and mounts it to the message history.
Parameters:
Source code in src/elva/apps/chat/app.py
cleanup()
async
Hook called after cancellation and before the component unsets its state to NONE
.
on_delete(range_offset, range_length)
async
Hook called on a delete action in a Y array change event.
This method removes the all message views in the given index range.
Parameters:
-
range_offset
(int
) –the start index of the deletion.
-
range_length
(str
) –the number of subsequent indices.
Source code in src/elva/apps/chat/app.py
Future(messages, user, show_self=False, **kwargs)
Bases: MessageList
List of currently composed messages.
Parameters:
-
messages
(Map
) –mapping of message identifiers to their corresponding message object.
-
user
(str
) –the current username of the app.
-
show_self
(bool
, default:False
) –flag whether to show the own currently composed message.
-
kwargs
(dict
, default:{}
) –keyword arguments passed to
MessageList
.
Methods:
-
compose
–Hook arranging child widgets.
Source code in src/elva/apps/chat/app.py
compose()
Hook arranging child widgets.
Source code in src/elva/apps/chat/app.py
FutureParser(future, widget, user, show_self)
Bases: MapEventParser
Parser for changes in currently composed messages.
This class reflects the state of the Y map with currently composed messaged in the Future
message list on changes.
Parameters:
-
future
(Map
) –Y map mapping message identifiers to their corresponding message objects.
-
widget
(Future
) –the message list widget displaying the currently composed messages.
-
user
(str
) –the current username.
-
show_self
(bool
) –flag whether to show the own currently composed message.
Methods:
-
future_callback
–Hook called on changes in the Y map.
-
before
–Hook called before the component sets the
RUNNING
signal. -
cleanup
–Hook called after cancellation and before the component unsets its state to
NONE
. -
on_add
–Hook called on an add action.
-
on_delete
–Hook called on a delete action.
Source code in src/elva/apps/chat/app.py
future_callback(event)
Hook called on changes in the Y map.
This method parses the event object and calls action hooks accordingly.
Parameters:
-
event
(MapEvent
) –an object holding information about the change in the Y map.
Source code in src/elva/apps/chat/app.py
before()
async
Hook called before the component sets the RUNNING
signal.
This method subscribes to changes in the mapping of currently composed messages.
Source code in src/elva/apps/chat/app.py
cleanup()
async
Hook called after cancellation and before the component unsets its state to NONE
.
on_add(key, new_value)
async
Hook called on an add action.
This methods generates a message view from the added message object and mounts it to the list of currently composed messages.
Parameters:
-
key
(str
) –the message id that has been added.
-
new_value
(dict
) –the message object that has been added.
Source code in src/elva/apps/chat/app.py
on_delete(key, old_value)
async
Hook called on a delete action.
This methods removes the message view corresponding to the removed message id.
Parameters:
-
key
(str
) –the message id that has been deleted.
-
old_value
(dict
) –the message object that has been deleted.
Source code in src/elva/apps/chat/app.py
MessagePreview(ytext, *args, **kwargs)
Bases: Static
Preview of the rendered markdown content.
Parameters:
-
ytext
(Text
) –Y text with the markdown content of the own currently composed message.
-
args
(tuple
, default:()
) –positional arguments passed to
Static
. -
kwargs
(dict
, default:{}
) –keyword arguments passed to
Static
.
Methods:
-
on_show
–Hook called on a show message.
Source code in src/elva/apps/chat/app.py
UI(config, *args, **kwargs)
Bases: App
User interface.
Parameters:
-
config
(dict
) –mapping of configuration parameters.
-
args
(tuple
, default:()
) –positional arguments passed to
App
. -
kwargs
(dict
, default:{}
) –keyword arguments passed to
App
.
Methods:
-
get_new_id
–Get a new message id.
-
get_message
–Get a message object.
-
run_components
–Run all components the chat app needs.
-
on_mount
–Hook called on mounting the app.
-
compose
–Hook arranging child widgets.
-
on_unmount
–Hook called on unmounting.
-
action_send
–Hook called on an invoked send action.
-
on_tabbed_content_tab_activated
–Hook called on a tab activated message from a tabbed content widget.
-
on_provider_exception
–Wrapper method around the provider exception handler
-
on_awareness_update
–Wrapper method around the
-
action_save
–Action performed on triggering the
save
key binding. -
get_and_set_file_paths
–Get and set the data or render file paths after the input prompt.
-
action_render
–Action performed on triggering the
render
key binding. -
action_toggle_dashboard
–Action performed on triggering the
toggle_dashboard
key binding. -
push_client_states
–Method pushing the client states to the active dashboard.
-
push_config
–Method pushing the configuration mapping to the active dashboard.
Attributes:
-
CSS_PATH
–The path to the default CSS.
-
SCREENS
–The installed screens.
-
BINDINGS
–Key bindings for controlling the app.
Source code in src/elva/apps/chat/app.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
CSS_PATH = 'style.tcss'
class-attribute
instance-attribute
The path to the default CSS.
SCREENS = {'dashboard': Dashboard, 'input': InputScreen}
class-attribute
instance-attribute
The installed screens.
BINDINGS = [('shift+enter', 'send', 'Send currently composed message'), ('ctrl+enter', 'send', 'Send currently composed message'), ('ctrl+o', 'send', 'Send currently composed message'), ('ctrl+b', 'toggle_dashboard', 'Toggle the dashboard'), ('ctrl+s', 'save', 'Save to data file'), ('ctrl+r', 'render', 'Render to file')]
class-attribute
instance-attribute
Key bindings for controlling the app.
get_new_id()
get_message(text, message_id=None)
Get a message object.
Parameters:
-
text
(str
) –the content of the message.
-
message_id
(None | str
, default:None
) –the identifier of the message.
Returns:
-
tuple[Map, Text, str]
–a Y Map containing a mapping of message attributes as well as the Y Text and the message ID included therein.
Source code in src/elva/apps/chat/app.py
run_components()
async
Run all components the chat app needs.
Source code in src/elva/apps/chat/app.py
on_mount()
async
Hook called on mounting the app.
This methods waits for all components to set their RUNNING
state.
Source code in src/elva/apps/chat/app.py
compose()
on_unmount()
Hook called on unmounting.
It cancels the subscription to changes in the awareness states.
Source code in src/elva/apps/chat/app.py
action_send()
async
Hook called on an invoked send action.
This method transfers the message from the future to the history.
Source code in src/elva/apps/chat/app.py
on_tabbed_content_tab_activated(event)
Hook called on a tab activated message from a tabbed content widget.
Parameters:
-
event
(Message
) –object holding information about the tab activated message.
Source code in src/elva/apps/chat/app.py
on_provider_exception(exc, config)
Wrapper method around the provider exception handler
_on_provider_exception
.
Parameters:
-
exc
(WebSocketException
) –the exception raised by the provider.
-
config
(dict
) –the configuration stored in the provider.
Source code in src/elva/apps/chat/app.py
_on_provider_exception(exc, config)
async
Handler for exceptions raised by the provider.
It exits the app after displaying the error message to the user.
Parameters:
-
exc
(WebSocketException
) –the exception raised by the provider.
-
config
(dict
) –the configuration stored in the provider.
Source code in src/elva/apps/chat/app.py
on_awareness_update(topic, data)
Wrapper method around the
_on_awareness_update
callback.
Parameters:
-
topic
(Literal['update', 'change']
) –the topic under which the changes are published.
-
data
(tuple[dict, Any]
) –manipulation actions taken as well as the origin of the changes.
Source code in src/elva/apps/chat/app.py
_on_awareness_update(topic, data)
async
Hook called on a change in the awareness states.
It pushes client states to the dashboard and removes offline client IDs from the future.
Parameters:
-
topic
(Literal['update', 'change']
) –the topic under which the changes are published.
-
data
(tuple[dict, Any]
) –manipulation actions taken as well as the origin of the changes.
Source code in src/elva/apps/chat/app.py
action_save()
async
get_and_set_file_paths(data_file=True)
async
Get and set the data or render file paths after the input prompt.
Parameters:
-
data_file
(bool
, default:True
) –flag whether to add a data file path to the config.
Source code in src/elva/apps/chat/app.py
action_render()
async
Action performed on triggering the render
key binding.
Source code in src/elva/apps/chat/app.py
action_toggle_dashboard()
async
Action performed on triggering the toggle_dashboard
key binding.
Source code in src/elva/apps/chat/app.py
push_client_states()
Method pushing the client states to the active dashboard.
Source code in src/elva/apps/chat/app.py
push_config()
Method pushing the configuration mapping to the active dashboard.