add rand_color

This commit is contained in:
jdegenstein
2022-10-28 22:02:32 -05:00
committed by GitHub
parent fefb57c2b9
commit 73a5825f3f

View File

@@ -13,6 +13,7 @@ from logbook import info
from path import Path from path import Path
from pyqtgraph.parametertree import Parameter from pyqtgraph.parametertree import Parameter
from spyder.utils.icon_manager import icon from spyder.utils.icon_manager import icon
from random import randrange as rrr, seed
from ..cq_utils import find_cq_objects, reload_cq from ..cq_utils import find_cq_objects, reload_cq
from ..mixins import ComponentMixin from ..mixins import ComponentMixin
@@ -207,8 +208,28 @@ class Debugger(QObject,ComponentMixin):
_show_object(obj,name,options=dict(color='red',alpha=0.2)) _show_object(obj,name,options=dict(color='red',alpha=0.2))
def _rand_color(alpha = 0., cfloat=False):
#helper function to generate a random color dict
#for CQ-editor's show_object function
lower = 10
upper = 100 #not too high to keep color brightness in check
if cfloat: #for two output types depending on need
return (
(rrr(lower,upper)/255),
(rrr(lower,upper)/255),
(rrr(lower,upper)/255),
alpha,
)
return {"alpha": alpha,
"color": (
rrr(lower,upper),
rrr(lower,upper),
rrr(lower,upper),
)}
module.__dict__['show_object'] = _show_object module.__dict__['show_object'] = _show_object
module.__dict__['debug'] = _debug module.__dict__['debug'] = _debug
module.__dict__['rand_color'] = _rand_color
module.__dict__['log'] = lambda x: info(str(x)) module.__dict__['log'] = lambda x: info(str(x))
module.__dict__['cq'] = cq module.__dict__['cq'] = cq
@@ -220,7 +241,7 @@ class Debugger(QObject,ComponentMixin):
@pyqtSlot(bool) @pyqtSlot(bool)
def render(self): def render(self):
seed(371353) #reset the seed every time render is called (preserves colors run to run)
if self.preferences['Reload CQ']: if self.preferences['Reload CQ']:
reload_cq() reload_cq()