initial
This commit is contained in:
68
__init__.py
Normal file
68
__init__.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
UUID generator extension.
|
||||
|
||||
Generates version 4 UUID(s).
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
import albert
|
||||
|
||||
md_iid = '4.0'
|
||||
md_name = "UUID Generator"
|
||||
md_description = "Generate version 4 UUID(s)"
|
||||
md_version = "0.0.1"
|
||||
md_license = "MIT"
|
||||
md_url = "https://gitea.felix-boers.de/fboers/albert-uuid-generator"
|
||||
md_authors = ["@felixboers"]
|
||||
md_maintainers = ["@felixboers"]
|
||||
|
||||
icon_path = os.path.dirname(__file__)+"/uuid.svg"
|
||||
|
||||
def expand_uuid_formats(uuid: str):
|
||||
return [
|
||||
uuid,
|
||||
uuid.replace('-', ''),
|
||||
"{" + uuid + "}"
|
||||
]
|
||||
|
||||
def build_query_items(uuids):
|
||||
results = []
|
||||
for uuid in uuids:
|
||||
results.append(
|
||||
albert.StandardItem(
|
||||
id='uuid',
|
||||
text=uuid,
|
||||
icon_factory=lambda: albert.makeImageIcon(icon_path),
|
||||
subtext=uuid,
|
||||
actions=[
|
||||
albert.Action(
|
||||
id='copy',
|
||||
text='Copy uuid to clipboard',
|
||||
callable=lambda: albert.setClipboardText(uuid)
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
return results
|
||||
|
||||
class Plugin(albert.PluginInstance, albert.TriggerQueryHandler):
|
||||
|
||||
def __init__(self):
|
||||
albert.PluginInstance.__init__(self)
|
||||
albert.TriggerQueryHandler.__init__(self)
|
||||
|
||||
def defaultTrigger(self):
|
||||
return 'uuid '
|
||||
|
||||
def handleTriggerQuery(self, query):
|
||||
if not query.isValid:
|
||||
return
|
||||
|
||||
uuid = str(uuid4())
|
||||
formats = expand_uuid_formats(uuid)
|
||||
query.add(build_query_items(formats))
|
||||
Reference in New Issue
Block a user