Convert RGB value to Hex: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
No edit summary
Line 23: Line 23:


</pre>
</pre>
'''''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.
* Also want to trim the result to eliminate the '0x' from the front to the hex result.

Revision as of 14:02, 3 December 2008

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.
  • 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)
    hexN = hex(colorN)
    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.
  • Also want to trim the result to eliminate the '0x' from the front to the hex result.