File: colorpreview.py

package info (click to toggle)
mypaint 2.0.1-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 27,760 kB
  • sloc: python: 43,902; cpp: 6,920; xml: 2,475; sh: 473; makefile: 26
file content (54 lines) | stat: -rw-r--r-- 1,777 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# This file is part of MyPaint.
# Copyright (C) 2013-2018 by the MyPaint Development Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or


"""Color preview widget / current color indicator, for the status bar."""

# TODO: This *might* evolve to a color preview + alpha selector, possibly
# TODO:   with a history row taking up the bottom. For now let's draw it at
# TODO:   an aspect ratio of about 1:5 and see how users like it.

from __future__ import division, print_function

from .colors import PreviousCurrentColorAdjuster


class BrushColorIndicator (PreviousCurrentColorAdjuster):
    """Previous/Current color adjuster bound to app.brush_color_manager"""

    __gtype_name__ = "MyPaintBrushColorIndicator"

    HAS_DETAILS_DIALOG = False

    def __init__(self):
        PreviousCurrentColorAdjuster.__init__(self)
        self.connect("realize", self._init_color_manager)
        self._app = None
        self.clicked += self._clicked_cb

    def _init_color_manager(self, widget):
        from gui.application import get_app
        self._app = get_app()
        mgr = self._app.brush_color_manager
        assert mgr is not None
        self.set_color_manager(mgr)

    def _clicked_cb(self, adj, event, pos):
        x0, y0 = pos
        w = self.get_allocated_width()
        if x0 > w // 2:
            return
        chooser = self._app.drawWindow.color_chooser
        if chooser.get_visible():
            chooser.hide()
        else:
            chooser.popup(
                widget=self,
                above=True,
                textwards=True,
                event=event,
            )