-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathui.py
1417 lines (1018 loc) · 40.7 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
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
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
513
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Module containing classes for generic UI elements.
Contains base UI element class, along with UI implementation agnostic UI element classes.
"""
# Author: Jakub Wlodek
# Created: 19-Mar-2020
import py_cui
import py_cui.errors
import py_cui.colors
import inspect
from typing import Any, List, Optional, Tuple, Callable
class UIElement:
"""Base class for all UI elements. Extended by base widget and popup classes.
Interfaces between UIImplementation subclasses and CUI engine. For example,
a widget is a subclass of a UIElement. Then a TextBox widget would be a subclass
of the base widget class, and the TextBoxImplementation. The TextBoxImplementation
superclass contains logic for all textbox required operations, while the widget base
class contains all links to the CUI engine.
Attributes
----------
_id : str
Internal UI element unique ID
_title : str
UI element title
_padx, pady : int, int
padding in terminal characters
_start_x, _start_y: int, int
Coords in terminal characters for top-left corner of element
_stop_x, _stop_y : int, int
Coords in terminal characters for bottom-right corner of element
_height, width : int, int
absolute dimensions of ui element in terminal characters
_color : int
Default color for which to draw element
_border_color: int
Color used to draw the border of the element when not focused
_focus_border_color: int
Color used to draw the border of the element when focused
_selected : bool
toggle for marking an element as selected
_renderer : py_cui.renderer.Renderer
The default ui renderer
_logger : py_cui.debug.PyCUILogger
The default logger inherited from the parent
_help_text: str
Text to diplay when selected in status bar
"""
def __init__(self, id, title, renderer, logger):
"""Initializer for UIElement base class
"""
self._id = id
self._title = title
self._padx = 1
self._pady = 0
self._start_x, self._stop_y = 0, 0
self._stop_x, self._start_y = 0, 0
self._height, self._width = 0, 0
# Default UI Element color is white on black.
self._color = py_cui.WHITE_ON_BLACK
self._border_color = self._color
self._focus_border_color = self._color
self._selected_color = self._color
self._selected = False
self._renderer = renderer
self._logger = logger
self._help_text = ''
def get_absolute_start_pos(self) -> Tuple[int,int]:
"""Must be implemented by subclass, computes the absolute coords of upper-left corner
"""
raise NotImplementedError
def get_absolute_stop_pos(self) -> Tuple[int,int]:
"""Must be implemented by subclass, computes the absolute coords of bottom-right corner
"""
raise NotImplementedError
def get_absolute_dimensions(self) -> Tuple[int,int]:
"""Gets dimensions of element in terminal characters
Returns
-------
height, width : int, int
Dimensions of element in terminal characters
"""
start_x, start_y = self.get_absolute_start_pos()
stop_x, stop_y = self.get_absolute_stop_pos()
return (stop_y - start_y), (stop_x - start_x)
def update_height_width(self) -> None:
"""Function that refreshes position and dimensons on resize.
If necessary, make sure required widget attributes updated here as well.
"""
self._start_x, self._start_y = self.get_absolute_start_pos()
self._stop_x, self._stop_y = self.get_absolute_stop_pos()
self._height, self._width = self.get_absolute_dimensions()
def get_viewport_height(self) -> int:
"""Gets the height of the element viewport (height minus padding and borders)
Returns
-------
viewport_height : int
Height of element viewport in terminal characters
"""
return self._height - (2 * self._pady) - 3
def get_id(self) -> int:
"""Gets the element ID
Returns
-------
id : int
The ui element id
"""
return self._id
def get_title(self) -> str:
"""Getter for ui element title
Returns
-------
title : str
UI element title
"""
return self._title
def get_padding(self) -> Tuple[int,int]:
"""Gets ui element padding on in characters
Returns
-------
padx, pady : int, int
Padding on either axis in characters
"""
return self._padx, self._pady
def get_start_position(self) -> Tuple[int,int]:
"""Gets coords of upper left corner
Returns
-------
start_x, start_y : int, int
Coords of upper right corner
"""
return self._start_x, self._start_y
def get_stop_position(self) -> Tuple[int,int]:
"""Gets coords of lower right corner
Returns
-------
stop_x, stop_y : int, int
Coords of lower right corner
"""
return self._stop_x, self._stop_y
def get_color(self) -> int:
"""Gets current element color
Returns
-------
color : int
color code for combination
"""
return self._color
def get_border_color(self) -> int:
"""Gets current element border color
Returns
-------
color : int
color code for combination
"""
if self._selected:
return self._focus_border_color
else:
return self._border_color
def get_selected_color(self) -> int:
"""Gets current selected item color
Returns
-------
color : int
color code for combination
"""
return self._selected_color
def is_selected(self) -> bool:
"""Get selected status
Returns
-------
selected : bool
True if selected, False otherwise
"""
return self._selected
def get_renderer(self) -> 'py_cui.renderer.Renderer':
"""Gets reference to renderer object
Returns
-------
renderer : py_cui.renderer.Render
renderer object used for drawing element
"""
return self._renderer
def get_help_text(self) -> str:
"""Returns current help text
Returns
-------
help_text : str
Current element status bar help message
"""
return self._help_text
def set_title(self, title: str):
"""Function that sets the widget title.
Parameters
----------
title : str
New widget title
"""
self._title = title
def set_color(self, color: int) -> None:
"""Sets element default color
Parameters
----------
color : int
New color pair key code
"""
if self._border_color == self._color:
self._border_color = color
if self._focus_border_color == self._color:
self._focus_border_color = color
if self._selected_color == self._color:
self._selected_color = color
self._color = color
def set_border_color(self, color: int) -> None:
"""Sets element border color
Parameters
----------
color : int
New color pair key code
"""
self._border_color = color
def set_focus_border_color(self, color: int) -> None:
"""Sets element border color if the current element
is focused
Parameters
----------
color : int
New color pair key code
"""
self._focus_border_color = color
def set_selected_color(self, color: int) -> None:
"""Sets element sected color
Parameters
----------
color : int
New color pair key code
"""
self._selected_color = color
def set_selected(self, selected: bool) -> None:
"""Marks the UI element as selected or not selected
Parameters
----------
selected : bool
The new selected state of the element
"""
self._selected = selected
def set_help_text(self, help_text: str) -> None:
"""Sets status bar help text
Parameters
----------
help_text : str
New statusbar help text
"""
self._help_text = help_text
def set_focus_text(self, focus_text: str) -> None:
"""Sets status bar focus text. Legacy function, overridden by set_focus_text
Parameters
----------
focus_text : str
New statusbar help text
"""
self._help_text = focus_text
def _handle_key_press(self, key_pressed):
"""Must be implemented by subclass. Used to handle keypresses
"""
raise NotImplementedError
def _handle_mouse_press(self, x, y, mouse_event):
"""Can be implemented by subclass. Used to handle mouse presses
Parameters
----------
x, y : int, int
Coordinates of the mouse press event.
"""
pass
def _draw(self):
"""Must be implemented by subclasses. Uses renderer to draw element to terminal
"""
raise NotImplementedError
def _assign_renderer(self, renderer: 'py_cui.renderer.Renderer', quiet: bool=False) :
"""Function that assigns a renderer object to the element
(Meant for internal usage only)
Parameters
----------
renderer : py_cui.renderer.Renderer
Renderer for drawing element
Raises
------
error : PyCUIError
If parameter is not an initialized renderer.
"""
if renderer is None:
self._logger.debug('Renderer to assign is a NoneType')
elif self._renderer is not None:
raise py_cui.errors.PyCUIError('Renderer already assigned for the element')
elif isinstance(renderer, py_cui.renderer.Renderer):
self._renderer = renderer
else:
raise py_cui.errors.PyCUIError('Invalid renderer, must be of type py_cui.renderer.Renderer')
def _contains_position(self, x: int, y: int) -> bool:
"""Checks if character position is within element.
Parameters
----------
x : int
X coordinate to check
y : int
Y coordinate to check
Returns
-------
contains : bool
True if (x,y) is within the element, false otherwise
"""
within_x = self._start_x <= x and self._start_x + self._width >= x
within_y = self._start_y <= y and self._start_y + self._height >= y
return within_x and within_y
class UIImplementation:
"""Base class for ui implementations.
Should be extended for creating logic common accross ui elements.
For example, a textbox needs the same logic for a widget or popup.
This base class is only used to initialize the logger
Attributes
----------
_logger : py_cui.debug.PyCUILogger
parent logger object reference.
"""
def __init__(self, logger):
self._logger = logger
class TextBoxImplementation(UIImplementation):
"""UI implementation for a single-row textbox input
Attributes
----------
_text : str
The text in the text box
_initial_cursor : int
Initial position of the cursor
_cursor_x, _cursor_y : int
The absolute positions of the cursor in the terminal window
_cursor_text_pos : int
the cursor position relative to the text
_cursor_max_left, cursor_max_right : int
The cursor bounds of the text box
_viewport_width : int
The width of the textbox viewport
_password : bool
Toggle to display password characters or text
"""
def __init__(self, initial_text: str, password: bool , logger):
"""Initializer for the TextBoxImplementation base class
"""
super().__init__(logger)
self._text = initial_text
self._password = password
self._initial_cursor = 0
self._cursor_text_pos = 0
self._cursor_max_left = 0
self._cursor_x = 0
self._cursor_max_right = 0
self._cursor_y = 0
self._viewport_width = 0
# Variable getter + setter functions
def get_initial_cursor_pos(self) -> int:
"""Gets initial cursor position
Returns
-------
initial_cursor : int
Initial position of the cursor
"""
return self._initial_cursor
def get_cursor_text_pos(self) -> int:
"""Gets current position of cursor relative to text
Returns
-------
cursor_text_pos : int
the cursor position relative to the text
"""
return self._cursor_text_pos
def get_cursor_limits(self) -> Tuple[int,int]:
"""Gets cursor extreme points in terminal position
Returns
-------
cursor_max_left, cursor_max_right : int
The cursor bounds of the text box
"""
return self._cursor_max_left, self._cursor_max_right
def get_cursor_position(self) -> Tuple[int,int]:
"""Returns current cursor poition
Returns
-------
cursor_x, cursor_y : int
The absolute positions of the cursor in the terminal window
"""
return self._cursor_x, self._cursor_y
def get_viewport_width(self) -> int:
"""Gets the width of the textbox viewport
Returns
-------
viewport_width : int
The width of the textbox viewport
"""
return self._viewport_width
def set_text(self, text: str):
"""Sets the value of the text. Overwrites existing text
Parameters
----------
text : str
The text to write to the textbox
"""
self._text = text
if self._cursor_text_pos > len(self._text):
diff = self._cursor_text_pos - len(self._text)
self._cursor_text_pos = len(self._text)
self._cursor_x = self._cursor_x - diff
def get(self) -> str:
"""Gets value of the text in the textbox
Returns
-------
text : str
The current textbox test
"""
return self._text
def clear(self) -> None:
"""Clears the text in the textbox
"""
self._cursor_x = self._cursor_max_left
self._cursor_text_pos = 0
self._text = ''
def _move_left(self) -> None:
"""Shifts the cursor the the left. Internal use only
"""
if self._cursor_text_pos > 0:
if self._cursor_x > self._cursor_max_left:
self._cursor_x = self._cursor_x - 1
self._cursor_text_pos = self._cursor_text_pos - 1
def _move_right(self) -> None:
"""Shifts the cursor the the right. Internal use only
"""
if self._cursor_text_pos < len(self._text):
if self._cursor_x < self._cursor_max_right:
self._cursor_x = self._cursor_x + 1
self._cursor_text_pos = self._cursor_text_pos + 1
def _insert_char(self, key_pressed: int) -> None:
"""Inserts char at cursor position. Internal use only
Parameters
----------
key_pressed : int
key code of key pressed
"""
self._text = self._text[:self._cursor_text_pos] + chr(key_pressed) + self._text[self._cursor_text_pos:]
if len(self._text) < self._viewport_width:
self._cursor_x = self._cursor_x + 1
self._cursor_text_pos = self._cursor_text_pos + 1
def _jump_to_start(self) -> None:
"""Jumps to the start of the textbox. Internal use only
"""
self._cursor_x = self._initial_cursor
self._cursor_text_pos = 0
def _jump_to_end(self) -> None:
"""Jumps to the end to the textbox. Internal use only
"""
self._cursor_text_pos = len(self._text)
self._cursor_x = self._initial_cursor + self._cursor_text_pos
def _erase_char(self) -> None:
"""Erases character at textbox cursor. Internal Use only
"""
if self._cursor_text_pos > 0:
self._text = self._text[:self._cursor_text_pos - 1] + self._text[self._cursor_text_pos:]
if len(self._text) < self._viewport_width:
self._cursor_x = self._cursor_x - 1
self._cursor_text_pos = self._cursor_text_pos - 1
def _delete_char(self) -> None:
"""Deletes character to right of texbox cursor. Internal use only
"""
if self._cursor_text_pos < len(self._text):
self._text = self._text[:self._cursor_text_pos] + self._text[self._cursor_text_pos + 1:]
class MenuImplementation(UIImplementation):
"""A scrollable menu UI element
Allows for creating a scrollable list of items of which one is selectable.
Analogous to a RadioButton
Attributes
----------
_top_view : int
the uppermost menu element in view
_selected_item : int
the currently highlighted menu item
_view_items : list of str
list of menu items
"""
def __init__(self, logger):
"""Initializer for MenuImplementation base class
"""
super().__init__(logger)
self._top_view = 0
self._selected_item = 0
self._page_scroll_len = 5
self._view_items = []
self._on_selection_change: Optional[Callable[[Any],Any]] = None
def clear(self) -> None:
"""Clears all items from the Scroll Menu
"""
self._view_items = []
self._selected_item = 0
self._top_view = 0
self._logger.info('Clearing menu')
def set_on_selection_change_event(self, on_selection_change_event: Callable[[Any],Any]):
"""Function that sets the function fired when menu selection changes.
Event function must take 0 or 1 parameters. If 1 parameter, the new selcted item will be passed in.
Parameters
----------
on_selection_change_event : Callable
Callable function that takes in as an argument the newly selected element
Raises
------
TypeError
Raises a type error if event function is not callable
"""
#mypy false-positive
if not isinstance(on_selection_change_event, Callable): #type: ignore
raise TypeError('On selection change event must be a Callable!')
self._on_selection_change = on_selection_change_event
def _process_selection_change_event(self):
"""Function that executes on-selection change event either with the current menu item, or with no-args"""
# Identify num of args from callable. This allows for user to create commands that take in x, y
# coords of the mouse press as input
num_args = 0
try:
num_args = len(inspect.signature(self._on_selection_change).parameters)
except ValueError:
self._logger.error('Failed to get on_selection_change signature!')
except TypeError:
self._logger.error('Type of object not supported for signature identification!')
# Depending on the number of parameters for the self._on_selection_change, pass in the x and y
# values, or do nothing
if num_args == 1:
self._on_selection_change(self.get())
elif num_args == 0:
self._on_selection_change()
else:
raise ValueError('On selection change event must accept either 0 or 1 parameters!')
def get_selected_item_index(self) -> int:
"""Gets the currently selected item
Returns
-------
selected_item : int
the currently highlighted menu item
"""
return self._selected_item
def set_selected_item_index(self, selected_item_index: int) -> None:
"""Sets the currently selected item
Parameters
----------
selected_item : int
The new selected item index
"""
self._selected_item = selected_item_index
def _scroll_up(self) -> None:
"""Function that scrolls the view up in the scroll menu
"""
if self._top_view > 0 and self._selected_item == self._top_view:
self._top_view = self._top_view - 1
if self._selected_item > 0:
self._selected_item = self._selected_item - 1
self._logger.debug(f'Scrolling up to item {self._selected_item}')
def _scroll_down(self, viewport_height: int) -> None:
"""Function that scrolls the view down in the scroll menu
TODO: Viewport height should be calculated internally, and not rely on a parameter.
Parameters
----------
viewport_height : int
The number of visible viewport items
"""
if self._selected_item < len(self._view_items) - 1:
self._selected_item = self._selected_item + 1
if self._selected_item > self._top_view + viewport_height:
self._top_view = self._top_view + 1
self._logger.debug(f'Scrolling down to item {self._selected_item}')
def _jump_up(self) -> None:
"""Function for jumping up menu several spots at a time
"""
for _ in range(self._page_scroll_len):
self._scroll_up()
def _jump_down(self, viewport_height: int) -> None:
"""Function for jumping down the menu several spots at a time
Parameters
----------
viewport_height : int
The number of visible viewport items
"""
for _ in range(self._page_scroll_len):
self._scroll_down(viewport_height)
def _jump_to_top(self) -> None:
"""Function that jumps to the top of the menu
"""
self._top_view = 0
self._selected_item = 0
def _jump_to_bottom(self, viewport_height: int) -> None:
"""Function that jumps to the bottom of the menu
Parameters
----------
viewport_height : int
The number of visible viewport items
"""
self._selected_item = len(self._view_items) - 1
self._top_view = self._selected_item - viewport_height
if self._top_view < 0:
self._top_view = 0
def add_item(self, item: Any) -> None:
"""Adds an item to the menu.
Parameters
----------
item : Object
Object to add to the menu. Must have implemented __str__ function
"""
self._logger.debug(f'Adding item {str(item)} to menu')
self._view_items.append(item)
def add_item_list(self, item_list: List[Any]) -> None:
"""Adds a list of items to the scroll menu.
Parameters
----------
item_list : List[Object]
list of objects to add as items to the scrollmenu
"""
self._logger.debug(f'Adding item list {str(item_list)} to menu')
for item in item_list:
self.add_item(item)
def remove_selected_item(self) -> None:
"""Function that removes the selected item from the scroll menu.
"""
if len(self._view_items) == 0:
return
self._logger.debug(f'Removing {str(self._view_items[self._selected_item])}')
del self._view_items[self._selected_item]
if self._selected_item >= len(self._view_items) and self._selected_item > 0:
self._selected_item = self._selected_item - 1
def remove_item(self, item: Any) -> None:
"""Function that removes a specific item from the menu
Parameters
----------
item : Object
Reference of item to remove
"""
if len(self._view_items) == 0 or item not in self._view_items:
return
self._logger.debug(f'Removing {str(item)}')
i_index = self._view_items.index(item)
del self._view_items[i_index]
if self._selected_item >= i_index:
self._selected_item = self._selected_item - 1
def get_item_list(self) -> List[Any]:
"""Function that gets list of items in a scroll menu
Returns
-------
item_list : List[Object]
list of items in the scrollmenu
"""
return self._view_items
def get(self) -> Optional[Any]:
"""Function that gets the selected item from the scroll menu
Returns
-------
item : Object
selected item, or None if there are no items in the menu
"""
if len(self._view_items) > 0:
return self._view_items[self._selected_item]
return None
def set_selected_item(self, selected_item: Any):
"""Function that replaces the currently selected item with a new item
Parameters
----------
item : Object
A new selected item to replace the current one
"""
if selected_item is not None and self.get() is not None:
self._view_items[self._selected_item] = selected_item
class CheckBoxMenuImplementation(MenuImplementation):
"""Class representing checkbox menu ui implementation
Attributes
----------
_selected_item_dict : dict of object -> bool
stores each object and maps to its current selected status
_checked_char : char
Character to mark checked items
"""
def __init__(self, logger, checked_char):
"""Initializer for the checkbox menu implementation
"""
super().__init__(logger)
self._selected_item_dict = {}
self._checked_char = checked_char
def add_item(self, item: Any) -> None:
"""Extends base class function, item is added and marked as unchecked to start
Parameters
----------
item : object
The item being added
"""
super().add_item(item)
self._selected_item_dict[item] = False
def remove_selected_item(self) -> None:
"""Removes selected item from item list and selected item dictionary
"""
del self._selected_item_dict[self.get()]
super().remove_selected_item()
def remove_item(self, item) -> None:
"""Removes item from item list and selected item dict
Parameters
----------
item : object
Item to remove from menu
"""
del self._selected_item_dict[item]
super().remove_item(item)
def toggle_item_checked(self, item: Any):
"""Function that marks an item as selected
Parameters
----------
item : object