interface ¤
This module contains all the code responsible for the HTOP-like interface.
Classes:
-
Column
–A class to specify a column in the interface.
-
Exit
–A simple exception to exit the interactive interface.
-
HorizontalScroll
–A wrapper around asciimatics' Screen.print_at and Screen.paint methods.
-
Interface
–The main class responsible for drawing the HTOP-like interface.
-
Key
–A class to represent an input key.
-
Keys
–The actions and their shortcuts keys.
-
Palette
–A simple class to hold palettes getters.
Functions:
-
color_palette_parser
–Return a color tuple (foreground color, mode, background color).
-
key_bind_parser
–Return a list of Key instances.
Column ¤
A class to specify a column in the interface.
It's composed of a header (the string to display on top), a padding (how to align the text), and three callable functions to get the text from a Python object, to sort between these objects, and to get a color palette based on the text.
Parameters:
-
header
(str
) –The string to display on top.
-
padding
(str
) –How to align the text.
-
get_text
(Callable
) –Function accepting a Download as argument and returning the text to display.
-
get_sort
(Callable
) –Function accepting a Download as argument and returning the attribute used to sort.
-
get_palette
(Callable
) –Function accepting text as argument and returning a palette or a palette identifier.
Source code in src/aria2p/interface.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
HorizontalScroll ¤
HorizontalScroll(screen: Screen, scroll: int = 0)
A wrapper around asciimatics' Screen.print_at and Screen.paint methods.
It allows scroll the rows horizontally, used when moving left and right: the first N characters will not be printed.
Parameters:
-
screen
(Screen
) –The asciimatics screen object.
-
scroll
(int
, default:0
) –Base scroll to use when printing. Will decrease by one with each character skipped.
Methods:
-
print_at
–Wrapper print_at method.
-
set_scroll
–Set the scroll value.
Source code in src/aria2p/interface.py
245 246 247 248 249 250 251 252 253 |
|
print_at ¤
Wrapper print_at method.
Parameters:
-
text
(str
) –Text to print.
-
x
(int
) –X axis position / column.
-
y
(int
) –Y axis position / row.
-
palette
(list | tuple
) –A length-3 tuple or a list of length-3 tuples representing asciimatics palettes.
Returns:
-
int
–The number of characters actually printed.
Source code in src/aria2p/interface.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
Interface ¤
Interface(api: API | None = None)
The main class responsible for drawing the HTOP-like interface.
It should be instantiated with an API instance, and then ran with its run
method.
If you want to re-use this class' code to create an HTOP-like interface for another purpose, simply change these few things:
- columns, columns_order and palettes attributes
- sort and reverse attributes default values
- get_data method. It should return a list of objects that can be compared by equality (==, eq, hash)
- init method to accept other arguments
- remove/change the few events with "download" or "self.api" in the process_event method
Parameters:
-
api
(API | None
, default:None
) –An instance of API.
Methods:
-
get_column_at_x
–For an horizontal position X, return the column index.
-
get_data
–Return a list of objects.
-
print_headers
–Print the headers (columns names).
-
print_rows
–Print the rows.
-
process_event
–Process an event.
-
run
–The main drawing loop.
-
set_screen
–Set the screen object, its scroller wrapper, width, height, and columns bounds.
-
sort_data
–Sort data according to interface state.
-
update_data
–Set the interface data and rows contents.
-
update_rows
–Update rows contents according to data and interface state.
Source code in src/aria2p/interface.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
|
get_column_at_x ¤
For an horizontal position X, return the column index.
Source code in src/aria2p/interface.py
1144 1145 1146 1147 1148 1149 |
|
get_data ¤
Return a list of objects.
Source code in src/aria2p/interface.py
1168 1169 1170 |
|
print_headers ¤
print_headers() -> None
Print the headers (columns names).
Source code in src/aria2p/interface.py
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 |
|
print_rows ¤
print_rows() -> None
Print the rows.
Source code in src/aria2p/interface.py
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 |
|
process_event ¤
process_event(event: KeyboardEvent | MouseEvent) -> None
Process an event.
For reactivity purpose, this method should not compute expensive stuff, only change the state of the interface, changes that will be applied by update_data and update_rows methods.
Parameters:
-
event
(KeyboardEvent | MouseEvent
) –The event to process.
Source code in src/aria2p/interface.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
|
run ¤
run() -> bool
The main drawing loop.
Source code in src/aria2p/interface.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
|
set_screen ¤
set_screen(screen: Screen) -> None
Set the screen object, its scroller wrapper, width, height, and columns bounds.
Source code in src/aria2p/interface.py
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 |
|
sort_data ¤
sort_data() -> None
Sort data according to interface state.
Source code in src/aria2p/interface.py
1180 1181 1182 1183 |
|
update_data ¤
update_data() -> None
Set the interface data and rows contents.
Source code in src/aria2p/interface.py
1172 1173 1174 1175 1176 1177 1178 |
|
update_rows ¤
update_rows() -> None
Update rows contents according to data and interface state.
Source code in src/aria2p/interface.py
1185 1186 1187 1188 1189 1190 1191 |
|
Key ¤
A class to represent an input key.
Parameters:
Source code in src/aria2p/interface.py
132 133 134 135 136 137 138 139 140 141 142 |
|
Keys ¤
The actions and their shortcuts keys.
Palette ¤
A simple class to hold palettes getters.
Methods:
name staticmethod
¤
Return the palette for a NAME cell.
Source code in src/aria2p/interface.py
302 303 304 305 306 307 308 309 310 311 |
|
color_palette_parser ¤
Return a color tuple (foreground color, mode, background color).
Parameters:
-
palette
(str
) –The palette name.
Returns:
Source code in src/aria2p/interface.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
key_bind_parser ¤
Return a list of Key instances.
Parameters:
-
action
(str
) –The action name.
Returns:
Source code in src/aria2p/interface.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|