Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sergius02 committed Sep 2, 2020
0 parents commit 17340d6
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
.cache
.mypy_cache/
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<p align="center">
<img src="screenshots/icon.png" alt="Icon" />
</p>

<h1 align="center">Color Converter</h1>

----------

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.
Binary file added images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()

23 changes: 23 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Binary file added screenshots/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/tohex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/torgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{ "required_api_version": "^1.0.0", "commit": "python2" },
{ "required_api_version": "^2.0.0", "commit": "master" }
]

0 comments on commit 17340d6

Please sign in to comment.