diff options
Diffstat (limited to 'plugins/python/cglimpse/distro.py')
-rw-r--r-- | plugins/python/cglimpse/distro.py | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/plugins/python/cglimpse/distro.py b/plugins/python/cglimpse/distro.py index 5ffc523..4b490e6 100644 --- a/plugins/python/cglimpse/distro.py +++ b/plugins/python/cglimpse/distro.py @@ -1,20 +1,28 @@ +from gi.repository import Gdk +from pychrysalide.glibext import ConfigParam + from .method import GlimpseMethod class ByteDistribution(GlimpseMethod): - def __init__(self, builder): - """Prepare a Shannon entropy display.""" - super(ByteDistribution, self).__init__(builder) + @staticmethod + def setup_config(config): + """Register the configuration parameters for the method.""" - button = builder.get_object('shannon_color') - button.connect('color-set', self._on_color_set) + color = Gdk.RGBA() + color.parse('#3465A4') + + param = ConfigParam('cglimpse.distrib.color', ConfigParam.ConfigParamType.COLOR, color) + config.add(param) - self._on_color_set(button) - self._step = 0x80 + def __init__(self, builder, config, update_cb): + """Prepare a Distrib entropy display.""" + + super(ByteDistribution, self).__init__(builder, config, update_cb) self._v_legend = 'Quantity' self._h_legend = 'Byte values' @@ -24,41 +32,42 @@ class ByteDistribution(GlimpseMethod): self._values = {} + button = builder.get_object('distrib_color') + button.connect('color-set', self._on_color_set) - def _on_color_set(self, button): - """React on color chosen for the rendering.""" + param = config.search('cglimpse.distrib.color') + color = param.value - color = button.get_rgba() self._color = [ color.red, color.green, color.blue, color.alpha ] self._shadow_color = [ color.red * 0.5, color.green * 0.5, color.blue * 0.5, color.alpha ] + button.set_rgba(param.value) - def format_legend(self, value, vert): - """Build the label used for a rule.""" - if vert: - text = str(value) + def _on_color_set(self, button): + """React on color chosen for the rendering.""" - else: + color = button.get_rgba() - scale = [ ' kb', ' Mb', ' Gb', ' Tb' ] - suffix = '' + self._color = [ color.red, color.green, color.blue, color.alpha ] + self._shadow_color = [ color.red * 0.5, color.green * 0.5, color.blue * 0.5, color.alpha ] + + param = self._config.search('cglimpse.distrib.color') + param.value = color - for i in range(len(scale)): + self._update_cb() - if value < 1024: - break - value /= 1024 - suffix = scale[i] + def format_legend(self, value, vert): + """Build the label used for a rule.""" - text = '%u%s' % (value, suffix) + text = str(int(value)) return text - def update(self, data): - """Provide a description for the method.""" + def update(self, data, coverage): + """Compute internal values for the method.""" max_count = 0 @@ -67,7 +76,7 @@ class ByteDistribution(GlimpseMethod): for i in range(256): self._values[i] = 0 - for b in data: + for b in data[coverage[0] : coverage[1]]: if b in self._values.keys(): self._values[b] += 1 |