diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..33417a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +.cache +.mypy_cache/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..f7170c9 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +

+ Icon +

+ +

Color Converter

+ +---------- + +This is an extension for [ULauncher](https://ulauncher.io/), it helps you to convert RGB <> HEX color codes + +| ![alt](screenshots/tohex.png) | ![alt](screenshots/torgb.png) | +|-------------------------------|-------------------------------| + +---------- + +## Options + +* tohex > Convert to Hex +* torgb > Convert to RGB + +You can get the code to your clipboard, just select pressing enter! + +> **IMPORTANT!** Please, don't change the default keywords. +> +> **For the moment** the code has them hardcoded, so the extension cant work if you change it. diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 0000000..1ec6f62 Binary files /dev/null and b/images/icon.png differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..04a41d6 --- /dev/null +++ b/main.py @@ -0,0 +1,79 @@ + +import logging +from ulauncher.api.client.Extension import Extension +from ulauncher.api.client.EventListener import EventListener +from ulauncher.api.shared.event import KeywordQueryEvent +from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem +from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction +from ulauncher.api.shared.action.CopyToClipboardAction import CopyToClipboardAction + +logger = logging.getLogger(__name__) + + +class HexCodeExtension(Extension): + + def __init__(self): + super(HexCodeExtension, self).__init__() + self.subscribe(KeywordQueryEvent, KeywordQueryEventListener()) + + def toRGB(self, text): + hex = text.replace("#","") + rgb = tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)).__str__() + + return [ + ExtensionResultItem( + icon='images/icon.png', + name="#" + hex.upper(), + description='HEX FORMAT', + on_enter=CopyToClipboardAction("#" + hex.upper()) + ), + ExtensionResultItem( + icon='images/icon.png', + name=rgb, + description='RGB FORMAT', + on_enter=CopyToClipboardAction(rgb) + ) + ] + + def toHex(self, text): + rgb = text.replace("(","") + rgb = rgb.replace(")","") + rgb = rgb.replace(" ", "") + + rgbtuple = tuple(map(int, rgb.split(','))) + + hex = '%02x%02x%02x' % rgbtuple + + return [ + ExtensionResultItem( + icon='images/icon.png', + name="#" + hex.upper(), + description='HEX FORMAT', + on_enter=CopyToClipboardAction("#" + hex.upper()) + ), + ExtensionResultItem( + icon='images/icon.png', + name=rgb, + description='RGB FORMAT', + on_enter=CopyToClipboardAction(rgb) + ) + ] + + +class KeywordQueryEventListener(EventListener): + + def on_event(self, event, extension): + items = [] + + text = event.get_argument() or "" + if event.get_keyword() == "tohex": + return RenderResultListAction(extension.toHex(text)) + + if event.get_keyword() == "torgb": + return RenderResultListAction(extension.toRGB(text)) + + return RenderResultListAction(items) + +if __name__ == '__main__': + HexCodeExtension().run() + \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..68639c4 --- /dev/null +++ b/manifest.json @@ -0,0 +1,23 @@ +{ + "required_api_version": "^2.0.0", + "name": "Color converter", + "description": "Convert RGB <> Hex codes", + "developer_name": "Sergio Fernández Celorio", + "icon": "images/icon.png", + "options": { + "query_debounce": 0.05 + }, + "preferences": [{ + "id": "color_converter_hex", + "type": "keyword", + "name": "toHex", + "default_value": "tohex" + }, + { + "id": "color_converter_rgb", + "type": "keyword", + "name": "toRGB", + "default_value": "torgb" + } + ] +} \ No newline at end of file diff --git a/screenshots/icon.png b/screenshots/icon.png new file mode 100644 index 0000000..23e75f4 Binary files /dev/null and b/screenshots/icon.png differ diff --git a/screenshots/tohex.png b/screenshots/tohex.png new file mode 100644 index 0000000..dfbcee0 Binary files /dev/null and b/screenshots/tohex.png differ diff --git a/screenshots/torgb.png b/screenshots/torgb.png new file mode 100644 index 0000000..8b875a7 Binary files /dev/null and b/screenshots/torgb.png differ diff --git a/versions.json b/versions.json new file mode 100644 index 0000000..fea1e59 --- /dev/null +++ b/versions.json @@ -0,0 +1,4 @@ +[ + { "required_api_version": "^1.0.0", "commit": "python2" }, + { "required_api_version": "^2.0.0", "commit": "master" } +]