-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathalbert.pyi
More file actions
1102 lines (855 loc) · 31.8 KB
/
albert.pyi
File metadata and controls
1102 lines (855 loc) · 31.8 KB
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
"""
.. https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html
.. https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
====================================================================================================
Albert Python interface v5.0
====================================================================================================
To be a valid Python plugin a Python module has to contain at least the mandatory metadata fields
and a class named ``Plugin`` that inherits the :class:`PluginInstance` class.
See Also:
`Albert C++ Reference <https://albertlauncher.github.io/reference/namespacealbert.html>`_
----------------------------------------------------------------------------------------------------
Mandatory metadata variables
----------------------------------------------------------------------------------------------------
``md_iid`` : *str*
Python interface version (<major>.<minor>)
``md_version`` : *str*
Plugin version (<major>.<minor>)
``md_name`` : *str*
Human readable name
``md_description`` : *str*
A brief, imperative description. (Like "Launch apps" or "Open files")
----------------------------------------------------------------------------------------------------
Optional metadata variables
----------------------------------------------------------------------------------------------------
``md_license`` : *str*
Short form e.g. MIT or BSD-2
``md_url`` : *str*
Browsable source, issues etc
``md_readme_url`` : *str*
Human readable online README
``md_authors`` : *List(str)*
The authors. Preferably using mentionable Github usernames.
``md_maintainers`` : *List(str)*
The current maintainers. Preferably using mentionable Github usernames.
``md_bin_dependencies`` : *List(str)*
Required executable(s). Have to match the name of the executable in $PATH.
``md_lib_dependencies`` : *List(str)*
Required Python package(s). Have to match the PyPI package name.
``md_credits`` : *List(str)*
Third party credit(s) and license notes
``md_platforms`` : *List(str)*
List of supported platforms. If empty all platforms are supported.
====================================================================================================
Changelog
====================================================================================================
- ``5.0``
This change adopts the coroutine based query handler API and internationalized tokenization.
- Class ``MatchConfig``
- Drop property ``separator_regex``.
- Drop constructor parameter ``separator_regex``.
- Class ``Query``
- Rename to ``QueryContext``.
- Remove ``add`` overloads.
- Add property ``usageScoring``.
- Rename property ``string`` to ``query``.
- Rename ``TriggerQueryHandler`` to ``QueryHandler`` (New async trigger query handler base class).
- Remove abstract method ``handleTriggerQuery`` (Use ``GeneratorQueryHandler`` instead).
- Add class ``GeneratorQueryHandler`` (Lazy, coroutine based query handler).
- Add abstract method ``items`` yielding batches of items.
- Add class ``RankedQueryHandler`` (Eager, usage scored query handler).
- Add abstract method ``rankItems`` returning scored items.
- Add static method ``lazySort`` yielding lazily sorted items.
- ``GlobalQueryHandler``
- Remove abstract method ``handleGlobalQuery`` (Use ``rankItems`` instead).
- Class ``Icon``
- Add static method ``Icon.image(str|Path)``
- Add static method ``Icon.fileType(str|Path)``
- Add static method ``Icon.theme(str)``
- Add enum ``Icon.StandardIconType``
- Add static method ``Icon.standard(StandardIconType)``
- Add static method ``Icon.grapheme(str, float, Color)``
- Add static method ``Icon.iconified(Icon, Color, float, int, Color)``
- Add static method ``Icon.composed(Icon, Icon, float, float, float, float, float, float)``
- Remove enum ``StandardIconType``
- Remove function ``makeImageIcon(str|Path)``
- Remove function ``makeFileTypeIcon(str|Path)``
- Remove function ``makeStandardIcon(StandardIconType)``
- Remove function ``makeThemeIcon(str)``
- Remove function ``makeGraphemeIcon(str, float, Color)``
- Remove function ``makeIconifiedIcon(Icon, Color, float, int, Color)``
- Remove function ``makeComposedIcon(Icon, Icon, float, float, float, float, float, float)``
- ``v4.0``
- Add built-in icon factories and related types:
- Add class ``Brush``
- Add class ``Color``
- Add class ``Icon``
- Add enum ``StandardIconType``
- Add function ``makeImageIcon(str|Path)``
- Add function ``makeFileTypeIcon(str|Path)``
- Add function ``makeStandardIcon(StandardIconType)``
- Add function ``makeThemeIcon(str)``
- Add function ``makeGraphemeIcon(str, float, Color)``
- Add function ``makeIconifiedIcon(Icon, Color, float, int, Color)``
- Add function ``makeComposedIcon(Icon, Icon, float, float, float, float, float, float)``
- ``Item``
- Remove abstract method ``Item.iconUrls(self) -> List[str]``
- Add abstract method ``Item.icon(self) -> Icon``
- ``StandardItem``
- Remove property ``iconUrls``
- Add property ``icon_factory``
- Rename property ``inputActionText`` to ``input_action_text``
- ``RankItem``
- Remove property access
- ``IndexItem``
- Remove property access
- ``v3.1``
- Add metadata field ``md_readme_url``.
- Add metadata field ``md_maintainers``.
- ``v3.0``
- Drop metadata field ``md_id``.
- ``PluginInstance``
- Add ``extensions(…)``.
- Drop ``__init__(…)`` parameter ``extensions``. Use ``extensions(…)``.
- Drop ``de``-/``registerExtension(…)``. Use ``extensions(…)``.
- Drop ``initialize(…)``/``finalize(…)``. Use ``__init__(…)``/``__del__(…)``.
- Make property a method:
- ``id``
- ``name``
- ``description``
- ``cacheLocation``
- ``configLocation``
- ``dataLocation``
- Do not implicitly create the directory in:
- ``cacheLocation``
- ``configLocation``
- ``dataLocation``
- Revert the property based approach of the extenision hierarchy. I.e. drop all properties and
constructors in relevant classes:
- ``Extension``
- ``TriggerQueryHandler``
- ``GlobalQueryHandler``
- ``IndexQueryHandler``
- ``FallbackHandler``
- ``Item``: Make all readonly properties methods.
- ``RankItem.__init__(…)`` add overload that takes a ``Match``.
- ``MatchConfig``: Add new class.
- ``Matcher.__init__(…)``: Add optional parameter ``config`` of type ``MatchConfig``.
- ``runTerminal(…)``:
- Drop parameter ``workdir``. Prepend ``cd <workdir>;`` to the script.
- Drop parameter ``close_on_exit``. Append ``exec $SHELL;`` to the script.
- Add ``openFile(…)``.
- ``v2.5``
- Matcher now not considered experimental anymore.
- Add ``Matcher.match(strings: List[str])``.
- Add ``Matcher.match(*args: str)``.
- ``v2.4``
- Deprecate parameter ``workdir`` of runTerminal. Prepend ``cd <workdir>;`` to your script.
- Deprecate parameter ``close_on_exit`` of runTerminal. Append ``exec $SHELL;`` to your script.
- ``v2.3``
- Module
- Deprecate ``md_id``. Use ``PluginInstance.id``.
- PluginInstance:
- Add read only property ``id``.
- Add read only property ``name``.
- Add read only property ``description``.
- Add instance method ``registerExtension(…)``.
- Add instance method ``deregisterExtension(…)``.
- Deprecate ``initialize(…)``. Use ``__init__(…)``.
- Deprecate ``finalize(…)``. Use ``__del__(…)``.
- Deprecate ``__init__`` extensions parameter. Use ``(de)``-/``registerExtension(…)``.
- Auto(de)register plugin extension if ``Plugin`` is instance of ``Extension``.
- Use ``Query`` instead of ``TriggerQuery`` and ``GlobalQuery``.
- The interface is backward compatible, however type hints may break.
- Add ``Matcher`` and ``Match`` convenience classes.
- Notification:
- Add property ``title``.
- Add property ``text``.
- Add instance method ``send()``.
- Add instance method ``dismiss()``.
- Note: Notification does not display unless ``send(…)`` has been called.
- ``v2.2``
- ``PluginInstance.configWidget`` supports ``'label'``
- ``__doc__`` is not used anymore, since 0.23 drops ``long_description`` metadata
- Deprecate ``md_maintainers`` not used anymore
- Add optional variable ``md_authors``
- ``v2.1``
- Add ``PluginInstance.readConfig``
- Add ``PluginInstance.writeConfig``
- Add ``PluginInstance.configWidget``
"""
from abc import abstractmethod, ABC
from enum import IntEnum
from pathlib import Path
from typing import Any, Callable, List, overload, final
from collections.abc import Generator
class Action:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1Action.html>`_
"""
def __init__(self,
id: str,
text: str,
callable: Callable):
...
class Color:
...
def __init__(self,
r: int,
g: int,
b: int,
a: int = 255):
...
r: int
g: int
b: int
a: int
class Icon(ABC):
@staticmethod
def image(path: str | Path) -> Icon:
"""
Returns an icon from an image file at **path**.
"""
@staticmethod
def fileType(path: str | Path) -> Icon:
"""
Returns an icon representing the file type of the file at **path**.
"""
@staticmethod
def theme(name: str) -> Icon:
"""
Returns an icon from the current icon theme with the given **name**.
"""
class StandardIconType(IntEnum):
TitleBarMenuButton = ...,
TitleBarMinButton = ...,
TitleBarMaxButton = ...,
TitleBarCloseButton = ...,
TitleBarNormalButton = ...,
TitleBarShadeButton = ...,
TitleBarUnshadeButton = ...,
TitleBarContextHelpButton = ...,
DockWidgetCloseButton = ...,
MessageBoxInformation = ...,
MessageBoxWarning = ...,
MessageBoxCritical = ...,
MessageBoxQuestion = ...,
DesktopIcon = ...,
TrashIcon = ...,
ComputerIcon = ...,
DriveFDIcon = ...,
DriveHDIcon = ...,
DriveCDIcon = ...,
DriveDVDIcon = ...,
DriveNetIcon = ...,
DirOpenIcon = ...,
DirClosedIcon = ...,
DirLinkIcon = ...,
DirLinkOpenIcon = ...,
FileIcon = ...,
FileLinkIcon = ...,
ToolBarHorizontalExtensionButton = ...,
ToolBarVerticalExtensionButton = ...,
FileDialogStart = ...,
FileDialogEnd = ...,
FileDialogToParent = ...,
FileDialogNewFolder = ...,
FileDialogDetailedView = ...,
FileDialogInfoView = ...,
FileDialogContentsView = ...,
FileDialogListView = ...,
FileDialogBack = ...,
DirIcon = ...,
DialogOkButton = ...,
DialogCancelButton = ...,
DialogHelpButton = ...,
DialogOpenButton = ...,
DialogSaveButton = ...,
DialogCloseButton = ...,
DialogApplyButton = ...,
DialogResetButton = ...,
DialogDiscardButton = ...,
DialogYesButton = ...,
DialogNoButton = ...,
ArrowUp = ...,
ArrowDown = ...,
ArrowLeft = ...,
ArrowRight = ...,
ArrowBack = ...,
ArrowForward = ...,
DirHomeIcon = ...,
CommandLink = ...,
VistaShield = ...,
BrowserReload = ...,
BrowserStop = ...,
MediaPlay = ...,
MediaStop = ...,
MediaPause = ...,
MediaSkipForward = ...,
MediaSkipBackward = ...,
MediaSeekForward = ...,
MediaSeekBackward = ...,
MediaVolume = ...,
MediaVolumeMuted = ...,
LineEditClearButton = ...,
DialogYesToAllButton = ...,
DialogNoToAllButton = ...,
DialogSaveAllButton = ...,
DialogAbortButton = ...,
DialogRetryButton = ...,
DialogIgnoreButton = ...,
RestoreDefaultsButton = ...,
TabCloseButtom = ...
@staticmethod
def standard(type: StandardIconType) -> Icon:
"""
Returns a standard icon for the given **type**.
"""
@staticmethod
def grapheme(grapheme: str,
scalar: float | None = None,
brush: Color | None = None) -> Icon:
"""
Returns an icon rendering the given **grapheme**, scaled by **scalar** and colored with
**brush**.
"""
@staticmethod
def iconified(icon: Icon,
background_brush: Color | None = None,
border_radius: float | None = None,
border_width: int | None = None,
border_color: Color | None = None) -> Icon:
"""
Returns an iconified **icon**. i.e. drawn in a colored rounded rectangle with a border.
**background_brush** specifies the background color, **border_width** the border width in
device independent pixels, **border_radius** the relative border radius (0.0 - 1.0),
and **border_color** the border color.
"""
@staticmethod
def composed(icon1: Icon,
icon2: Icon,
size1: float | None = None,
size2: float | None = None,
x1: float | None = None,
y1: float | None = None,
x2: float | None = None,
y2: float | None = None) -> Icon:
"""
Returns a composed icon of **icon1** and **icon2**.
**size1** and **size2** specify the relative sizes (0.0 - 1.0) of the icons.
**x1**, **y1**, **x2**, and **y2** specify the relative positions (0.0 - 1.0, 0.5 is
centered) of the icons.
"""
class MatchConfig:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1util_1_1MatchConfig.html>`_
"""
def __init__(self,
fuzzy: bool = False,
ignore_case: bool = True,
ignore_word_order: bool = True,
ignore_diacritics: bool = True):
"""
Constructs a ``MatchConfig`` initialized with the values of **fuzzy**, **ignore_case**,
**ignore_diacritics* and **ignore_word_order**. All parameters are optional.
"""
fuzzy: bool
"""
Match strings error tolerant.
"""
ignore_case: bool
"""
Match strings case insensitive.
"""
ignore_word_order: bool
"""
Match strings independent of their order.
"""
ignore_diacritics: bool
"""
Match strings normalized.
"""
class Match:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1util_1_1Match.html>`_
"""
@property
def score(self) -> float:
"""
The score of this match.
"""
def isMatch(self) -> bool:
"""
Returns ``True`` if this is a match, otherwise returns ``False``.
"""
def isEmptyMatch(self) -> bool:
"""
Returns ``True`` if this is a zero score match, otherwise returns ``False``.
"""
def isExactMatch(self) -> bool:
"""
Returns ``True`` if this is a perfect match, otherwise returns ``False``.
"""
def __bool__(self) -> bool:
"""
Converts the match to ``bool`` using ``isMatch()``.
"""
def __float__(self) -> float:
"""
Converts the match to ``float`` using ``score()``.
"""
class Matcher:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1util_1_1Matcher.html>`_
"""
def __init__(self,
string: str,
config: MatchConfig = MatchConfig()):
"""
Constructs a ``Matcher`` for the given **string** and **config**.
"""
@overload
def match(self, string: str) -> Match:
"""
Returns a ``Match`` for the **string**.
"""
@overload
def match(self, strings: List[str]) -> Match:
"""
Returns the best ``Match`` for the **strings**.
"""
@overload
def match(self, *args: str) -> Match:
"""
Returns the best ``Match`` for the **args**.
"""
class Item(ABC):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1Item.html>`_
"""
@abstractmethod
def id(self) -> str:
"""
Returns the item identifier.
"""
@abstractmethod
def text(self) -> str:
"""
Returns the item text.
"""
@abstractmethod
def subtext(self) -> str:
"""
Returns the item subtext.
"""
@abstractmethod
def inputActionText(self) -> str:
"""
Returns the item input action text.
"""
@abstractmethod
def icon(self) -> Icon:
"""
Creates and returns an item icon on demand.
"""
@abstractmethod
def actions(self) -> List[Action]:
"""
Returns the item actions.
"""
class RankItem:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1RankItem.html>`_
"""
def __init__(self,
item: Item,
score: float|Match):
...
class IndexItem:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1util_1_1IndexItem.html>`_
"""
def __init__(self,
item: Item,
string: str):
...
class UsageScoring:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1UsageScoring.html>`_
"""
def modifyMatchScores(self,
extension_id: str,
rank_items: list[RankItem]):
...
class StandardItem(Item):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1util_1_1StandardItem.html>`_
"""
def __init__(self,
id: str | None = None,
text: str | None = None,
subtext: str | None = None,
icon_factory: Callable[[], Icon] | None = None,
actions: List[Action] | None = None,
input_action_text: str | None = None
):
...
def id(self) -> str:
...
def text(self) -> str:
...
def subtext(self) -> str:
...
def inputActionText(self) -> str:
...
def icon(self) -> Icon:
...
def actions(self) -> List[Action]:
...
id: str
"""
The item identifier.
"""
text: str
"""
The item text.
"""
subtext: str
"""
The item subtext.
"""
icon_factory: Callable[[], Icon]
"""
The item icon.
"""
actions: List[Action]
"""
The item actions.
"""
input_action_text: str
"""
The item input action text.
"""
class QueryContext:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1QueryContext.html>`_
"""
@property
def trigger(self) -> str:
"""
Returns the trigger string of the query.
"""
@property
def query(self) -> str:
"""
Returns the query string of the query.
"""
@property
def isValid(self) -> bool:
"""
Returns ``True`` if the query is valid; ``False`` if it has been cancelled.
"""
@property
def usageScoring(self) -> UsageScoring:
"""
Returns the usage scoring.
"""
class Extension(ABC):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1Extension.html>`_
"""
@abstractmethod
def id(self) -> str:
"""
Returns the extension identifier.
"""
@abstractmethod
def name(self) -> str:
"""
Returns the pretty, human readable extension name.
"""
@abstractmethod
def description(self) -> str:
"""
Returns the brief extension description.
"""
class QueryHandler(Extension):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1QueryHandler.html>`_
"""
def synopsis(self, query: str) -> str:
"""
Returns the input hint for the given **query**.
The returned string will be displayed in the input line if space permits.
The base class implementation returns an empty string.
"""
def allowTriggerRemap(self) -> bool:
"""
Returns ``True`` if the user is allowed to set a custom trigger, otherwise returns ``False``.
The base class implementation returns ``True``.
"""
def defaultTrigger(self) -> str:
"""
Returns the default trigger.
The base class implementation returns ``Extension.id`` with a space appended.
"""
def setTrigger(self, trigger: str):
"""
Notifies that the user-defined trigger has changed to **trigger**.
The base class implementation does nothing.
"""
def supportsFuzzyMatching(self) -> bool:
"""
Returns ``True`` if the handler supports fuzzy matching, otherwise returns ``False``.
If ``True``, the user can enable fuzzy matching for this handler and
``setFuzzyMatching(bool)`` should be implemented accordingly.
The base class implementation returns ``False``.
"""
def setFuzzyMatching(self, enabled: bool):
"""
Sets the fuzzy matching mode to **enabled**.
This function is called when the user toggles fuzzy matching for this handler.
The base class implementation does nothing.
"""
class GeneratorQueryHandler(QueryHandler):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1GeneratorQueryHandler.html>`_
"""
@abstractmethod
def items(self, context: QueryContext) -> Generator[List[Item]]:
"""
Yields batches of items for **context** lazily.
The batch size is defined by the implementation.
Note: Executed in a background thread.
"""
class RankedQueryHandler(GeneratorQueryHandler):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1RankedQueryHandler.html>`_
"""
def items(self, context: QueryContext) -> Generator[List[Item]]:
"""
Implements ``GeneratorQueryHandler.items()``.
Yields result of ``rankItems`` for **context** usage scored and lazily sorted.
"""
@staticmethod
def lazySort(self, rank_items: List[RankItem]) -> Generator[List[Item]]:
"""
Yields **rank_items** lazily sorted.
"""
@abstractmethod
def rankItems(self, context: QueryContext) -> List[RankItem]:
"""
Returns a list of scored matches for **context**.
The match score should make sense and often is the fraction of matched characters (legth of
query string / length of matched string). The empty pattern matches everything and returns
all items with a score of 0.
Note: Executed in a background thread.
"""
class GlobalQueryHandler(RankedQueryHandler):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1GlobalQueryHandler.html>`_
"""
class IndexQueryHandler(GlobalQueryHandler):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1util_1_1IndexQueryHandler.html>`_
"""
@final
def setFuzzyMatching(self, enabled: bool):
"""
Sets the fuzzy matching mode to **enabled** and triggers ``updateIndexItems()``.
"""
@final
def supportsFuzzyMatching(self) -> bool:
"""
Returns ``True``.
"""
def rankItems(self, context: QueryContext) -> List[RankItem]:
"""
Implements ``RankedQueryHandler.rankItems()``.
Returns a list of scored matches for **context** using the index.
"""
def setIndexItems(self, index_items: List[IndexItem]):
"""
Sets the items of the index to **index_items**.
Meant to be called in ``updateIndexItems()``.
"""
@abstractmethod
def updateIndexItems(self):
"""
Updates the index.
Called when the index needs to be updated, i.e. for initialization, on user changes to the
index config (fuzzy, etc…) and probably by the client itself if the items changed. This
function should call ``setIndexItems`` to update the index.
Do not call this method on plugin initialization. It will be called once loaded.
"""
class FallbackHandler(Extension):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1FallbackHandler.html>`_
"""
@abstractmethod
def fallbacks(self, query: str) -> List[Item]:
"""
Returns fallback items for **query**.
"""
class Notification:
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1util_1_1Notification.html>`_
"""
def __init__(self,
title: str = '',
text: str = ''):
...
title: str
text: str
def send(self):
...
def dismiss(self):
...
def debug(arg: Any):
"""
Logs ``str(arg)`` as debug message in the logging category of this plugin.
Note:
This function is not part of the albert module and here for reference only.
The attribute is attached to the module at load time.
"""
def info(arg: Any):
"""
Logs ``str(arg)`` as info message in the logging category of this plugin.
Note:
This function is not part of the albert module and here for reference only.
The attribute is attached to the module at load time.
"""
def warning(arg: Any):
"""
Logs ``str(arg)`` as warning message in the logging category of this plugin.
Note:
This function is not part of the albert module and here for reference only.
The attribute is attached to the module at load time.
"""
def critical(arg: Any):
"""
Logs ``str(arg)`` as critical message in the logging category of this plugin.
Note:
This function is not part of the albert module and here for reference only.
The attribute is attached to the module at load time.
"""
def setClipboardText(text: str):
"""
Sets the system clipboard to **text**.
"""
def setClipboardTextAndPaste(text: str):
"""
Sets the system clipboard to **text** and paste the content to the front-most window.
Note:
Requires paste support. Check ``havePasteSupport()`` before using this function.
"""
def havePasteSupport() -> bool:
"""
Returns ``True`` if the platform supports pasting, otherwise returns ``False``.
Note:
This is a requirement for ``setClipboardTextAndPaste(…)`` to work.
"""
def openUrl(url: str):
"""
Opens the URL **url** with the default URL handler.
"""
def openFile(path: str):
"""
Opens the file at **path** with the default application.
"""
def runDetachedProcess(cmdln: List[str], workdir: str = '') -> int:
"""
Starts the **cmdln** in a new process, and detaches from it. Returns the PID on success;
otherwise returns 0. The process will be started in the directory **workdir**. If
**workdir** is empty, the working directory is the users home directory.
"""
def runTerminal(script: str):
"""
Runs a **script** in the users shell and terminal.
"""
class PluginInstance(ABC):
"""
`C++ Reference <https://albertlauncher.github.io/reference/classalbert_1_1PluginInstance.html>`_
"""
def id(self) -> str:
"""
Returns the id from the plugin metadata.
"""
def name(self) -> str:
"""
Returns the name from the plugin metadata.
"""
def description(self) -> str:
"""
Returns the description from the plugin metadata.
"""