diff options
Diffstat (limited to '')
| -rw-r--r-- | src/toolkit/common.py (renamed from src/toolkit.py) | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/toolkit.py b/src/toolkit/common.py index 5493f37..e3a1649 100644 --- a/src/toolkit.py +++ b/src/toolkit/common.py @@ -1,6 +1,7 @@ ''' Common functions ''' +from PyQt5 import QtWidgets import string import os import sys @@ -69,6 +70,39 @@ def disableWhenEncoding(func): return decorator +def pickColor(): + ''' + Use color picker to get color input from the user, + and return this as an RGB string and QPushButton stylesheet. + In a subclass apply stylesheet to any color selection widgets + ''' + dialog = QtWidgets.QColorDialog() + dialog.setOption(QtWidgets.QColorDialog.ShowAlphaChannel, True) + color = dialog.getColor() + if color.isValid(): + RGBstring = '%s,%s,%s' % ( + str(color.red()), str(color.green()), str(color.blue())) + btnStyle = "QPushButton{background-color: %s; outline: none;}" \ + % color.name() + return RGBstring, btnStyle + else: + return None, None + + +def rgbFromString(string): + '''Turns an RGB string like "255, 255, 255" into a tuple''' + try: + tup = tuple([int(i) for i in string.split(',')]) + if len(tup) != 3: + raise ValueError + for i in tup: + if i > 255 or i < 0: + raise ValueError + return tup + except: + return (255, 255, 255) + + def LoadDefaultSettings(self): ''' Runs once at each program start-up. Fills in default settings for any settings not found in settings.ini |
