Convert RGB value to Hex: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
Line 25: Line 25:
     if len(hexN) == 1: hexN = '0' + hexN
     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)
     result = scribus.messageBox ('Hex Value','RGB value of '+ color + ' is \n Hex value of '+ hexN,scribus.BUTTON_OK)
</pre>


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

Revision as of 14:45, 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)
    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.
  • Also want to trim the result to eliminate the '0x' from the front to the hex result. Done