Convert RGB value to Hex
Jump to navigation
Jump to search
This is a simple script that does one function: converts RGB decimal values to hex. As initially created, it will only do one value at a time. While it would be nice to allow this to remain open while you work with Scribus, this initial version will have to be closed to carry out any Scribus operations.
Usage
- Start the script – there are no requirements other than running it from Scribus. One could certainly alter this to run outside of Scribus by eliminating the valueDialog and messageBox features.
- Enter an RGB decimal value in the initial dialog. If you enter nothing, the value '255' is the default. Values greater than 255 default to 255, less than 0 to 0.
- When you are finished, enter '0' (the number zero, not the letter O).
#!/usr/bin/env python # File:rgb2hex.py # simple utility to convert rgb values to hex # within Scribus import scribus colorN = 255 while colorN != 0: color = scribus.valueDialog('Color Values','Enter the RGB value, 0 to quit') if color == '': color = '255' colorN = int(color) if colorN > 255: color = '255'; colorN = 255 if colorN < 0: color = '0'; colorN = 0 hexN = hex(colorN) hexN = hexN.lstrip('0x') if len(hexN) == 1: hexN = '0' + hexN result = scribus.messageBox ('Hex Value','RGB value of '+ color + ' is \n Hex value of '+ hexN,scribus.BUTTON_OK)
To Do
- I would like to add the ability to enter the complete RGB values for a given color. Just needs some parsing, maybe a tuple.