Browse Source

DumbPaintTool: Keep Color State alignd between toolkits

pull/267/head 0.40.0-a
Eugenio Parodi 2 years ago
parent
commit
9f00c1efba
  1. 2
      docs/MDNotes/DumbPaintTool.TODO.md
  2. 11
      tools/dumbPaintTool/app/painttoolkit.py
  3. 52
      tools/dumbPaintTool/app/palette.py
  4. 6
      tools/dumbPaintTool/app/toolspanel.py

2
docs/MDNotes/DumbPaintTool.TODO.md

@ -1,7 +1,7 @@
- [x] Save to open or last open/saved filename
- [ ] Ask to Save on quit
- [ ] Fix CanvasLayer Sizes on Save
- [ ] Brush colors applied back to Palette
- [x] Brush colors applied back to Palette
- [x] Fix multiple layers added linked together
- AppTemplate
- [ ] Title, show the bar

11
tools/dumbPaintTool/app/painttoolkit.py

@ -68,7 +68,7 @@ class PaintToolKit(ttk.TTkContainer):
self._bpBg.colorSelected.connect(self._refreshColor)
self._bpDef.colorSelected.connect(self.updatedTrans.emit)
glbls.brush.glyphChanged.connect( lambda:self._refreshColor(False))
glbls.brush.glyphChanged.connect( self._refreshColor)
glbls.brush.colorChanged.connect( self.setColor)
glbls.layers.changed.connect( self._layerChanged)
glbls.layers.layerSelected.connect(self._layerChanged)
@ -82,7 +82,7 @@ class PaintToolKit(ttk.TTkContainer):
self._sbLw.valueChanged.connect(self._pushLayerValues)
self._sbLh.valueChanged.connect(self._pushLayerValues)
self._refreshColor(emit=False)
self._refreshColor()
@ttk.pyTTkSlot()
def _pick():
@ -124,15 +124,14 @@ class PaintToolKit(ttk.TTkContainer):
self._sbLh.valueChanged.connect(self._pushLayerValues)
@ttk.pyTTkSlot()
def _refreshColor(self, emit=True):
def _refreshColor(self):
glyph = glbls.brush.glyph()
color = self.color()
self._lgliph.setText(
ttk.TTkString("Glyph: '") +
ttk.TTkString(glyph,color) +
ttk.TTkString("'"))
if emit:
glbls.brush.setColor(color)
glbls.brush.setColor(color)
def color(self):
color = ttk.TTkColor()
@ -159,4 +158,4 @@ class PaintToolKit(ttk.TTkContainer):
else:
self._cbBg.setCheckState(ttk.TTkK.Unchecked)
self._bpBg.setDisabled()
self._refreshColor(emit=False)
self._refreshColor()

52
tools/dumbPaintTool/app/palette.py

@ -25,18 +25,18 @@ __all__ = ['Palette']
import TermTk as ttk
_defaultPalette = [
[( 64, 0, 0),(102, 0, 0),(140, 0, 0),(178, 0, 0),(217, 0, 0),(255, 0, 0),(255, 51, 51),(255,102,102),( 0, 32, 64),( 0, 51,102), ( 0, 70,140),( 0, 89,178),( 0,108,217),( 0,128,255),( 51,153,255),(102,178,255)],
[( 64, 16, 0),(102, 26, 0),(140, 35, 0),(178, 45, 0),(217, 54, 0),(255, 64, 0),(255,102, 51),(255,140,102),( 0, 0, 64),( 0, 0,102), ( 0, 0,140),( 0, 0,178),( 0, 0,217),( 0, 0,255),( 51, 51,255),(102,102,255)],
[( 64, 32, 0),(102, 51, 0),(140, 70, 0),(178, 89, 0),(217,108, 0),(255,128, 0),(255,153, 51),(255,178,102),( 16, 0, 64),( 26, 0,102), ( 35, 0,140),( 45, 0,178),( 54, 0,217),( 64, 0,255),(102, 51,255),(140,102,255)],
[( 64, 48, 0),(102, 77, 0),(140,105, 0),(178,134, 0),(217,163, 0),(255,191, 0),(255,204, 51),(255,217,102),( 32, 0, 64),( 51, 0,102), ( 70, 0,140),( 89, 0,178),(108, 0,217),(128, 0,255),(153, 51,255),(178,102,255)],
[( 64, 64, 0),(102,102, 0),(140,140, 0),(178,178, 0),(217,217, 0),(255,255, 0),(255,255, 51),(255,255,102),( 48, 0, 64),( 77, 0,102), (105, 0,140),(134, 0,178),(163, 0,217),(191, 0,255),(204, 51,255),(217,102,255)],
[( 48, 64, 0),( 77,102, 0),(105,140, 0),(134,178, 0),(163,217, 0),(191,255, 0),(204,255, 51),(217,255,102),( 64, 0, 64),(102, 0,102), (140, 0,140),(178, 0,178),(217, 0,217),(255, 0,255),(255, 51,255),(255,102,255)],
[( 32, 64, 0),( 51,102, 0),( 70,140, 0),( 89,178, 0),(108,217, 0),(128,255, 0),(153,255, 51),(178,255,102),( 64, 0, 48),(102, 0, 77), (140, 0,105),(178, 0,134),(217, 0,163),(255, 0,191),(255, 51,204),(255,102,217)],
[( 0, 64, 0),( 0,102, 0),( 0,140, 0),( 0,178, 0),( 0,217, 0),( 0,255, 0),( 51,255, 51),(102,255,102),( 64, 0, 32),(102, 0, 51), (140, 0, 70),(178, 0, 89),(217, 0,108),(255, 0,128),(255, 51,153),(255,102,178)],
[( 0, 64, 32),( 0,102, 51),( 0,140, 70),( 0,178, 89),( 0,217,108),( 0,255,128),( 51,255,153),(102,255,178),( 64, 0, 16),(102, 0, 26), (140, 0, 35),(178, 0, 45),(217, 0, 54),(255, 0, 64),(255, 51,102),(255,102,140)],
[( 0, 64, 48),( 0,102, 77),( 0,140,105),( 0,178,134),( 0,217,163),( 0,255,191),( 51,255,204),(102,255,217),( 26, 26, 26),( 51, 51, 51), ( 77, 77, 77),(102,102,102),(128,128,128),(158,158,158),(191,191,191),(222,222,222)],
[( 0, 64, 64),( 0,102,102),( 0,140,140),( 0,178,178),( 0,217,217),( 0,255,255),( 51,255,255),(102,255,255),( 26, 20, 13),( 51, 41, 26), ( 77, 61, 38),(102, 82, 51),(128,102, 64),(158,134,100),(191,171,143),(222,211,195)],
[( 0, 48, 64),( 0, 77,102),( 0,105,140),( 0,134,178),( 0,163,217),( 0,191,255),( 51,204,255),(102,217,255),( 0, 0, 0),(255,255,255), (0x33,0x32,0x38),(0x63,0x68,0x7B),(0x85,0x84,0x94),(0x96,0x94,0xA1),(0xAF,0xAE,0xBC),(0xB3,0xB2,0xC0)]]
[( 64, 0, 0),(102, 0, 0),(140, 0, 0),(178, 0, 0),(217, 0, 0),(255, 0, 0),(255, 51, 51),(255,102,102), ( 0, 48, 64),( 0, 77,102),( 0,105,140),( 0,134,178),( 0,163,217),( 0,191,255),( 51,204,255),(102,217,255)],
[( 64, 16, 0),(102, 26, 0),(140, 35, 0),(178, 45, 0),(217, 54, 0),(255, 64, 0),(255,102, 51),(255,140,102), ( 0, 32, 64),( 0, 51,102),( 0, 70,140),( 0, 89,178),( 0,108,217),( 0,128,255),( 51,153,255),(102,178,255)],
[( 64, 32, 0),(102, 51, 0),(140, 70, 0),(178, 89, 0),(217,108, 0),(255,128, 0),(255,153, 51),(255,178,102), ( 0, 0, 64),( 0, 0,102),( 0, 0,140),( 0, 0,178),( 0, 0,217),( 0, 0,255),( 51, 51,255),(102,102,255)],
[( 64, 48, 0),(102, 77, 0),(140,105, 0),(178,134, 0),(217,163, 0),(255,191, 0),(255,204, 51),(255,217,102), ( 16, 0, 64),( 26, 0,102),( 35, 0,140),( 45, 0,178),( 54, 0,217),( 64, 0,255),(102, 51,255),(140,102,255)],
[( 64, 64, 0),(102,102, 0),(140,140, 0),(178,178, 0),(217,217, 0),(255,255, 0),(255,255, 51),(255,255,102), ( 32, 0, 64),( 51, 0,102),( 70, 0,140),( 89, 0,178),(108, 0,217),(128, 0,255),(153, 51,255),(178,102,255)],
[( 48, 64, 0),( 77,102, 0),(105,140, 0),(134,178, 0),(163,217, 0),(191,255, 0),(204,255, 51),(217,255,102), ( 48, 0, 64),( 77, 0,102),(105, 0,140),(134, 0,178),(163, 0,217),(191, 0,255),(204, 51,255),(217,102,255)],
[( 32, 64, 0),( 51,102, 0),( 70,140, 0),( 89,178, 0),(108,217, 0),(128,255, 0),(153,255, 51),(178,255,102), ( 64, 0, 64),(102, 0,102),(140, 0,140),(178, 0,178),(217, 0,217),(255, 0,255),(255, 51,255),(255,102,255)],
[( 0, 64, 0),( 0,102, 0),( 0,140, 0),( 0,178, 0),( 0,217, 0),( 0,255, 0),( 51,255, 51),(102,255,102), ( 64, 0, 48),(102, 0, 77),(140, 0,105),(178, 0,134),(217, 0,163),(255, 0,191),(255, 51,204),(255,102,217)],
[( 0, 64, 32),( 0,102, 51),( 0,140, 70),( 0,178, 89),( 0,217,108),( 0,255,128),( 51,255,153),(102,255,178), ( 64, 0, 32),(102, 0, 51),(140, 0, 70),(178, 0, 89),(217, 0,108),(255, 0,128),(255, 51,153),(255,102,178)],
[( 0, 64, 48),( 0,102, 77),( 0,140,105),( 0,178,134),( 0,217,163),( 0,255,191),( 51,255,204),(102,255,217), ( 64, 0, 16),(102, 0, 26),(140, 0, 35),(178, 0, 45),(217, 0, 54),(255, 0, 64),(255, 51,102),(255,102,140)],
[( 0, 64, 64),( 0,102,102),( 0,140,140),( 0,178,178),( 0,217,217),( 0,255,255),( 51,255,255),(102,255,255), ( 26, 20, 13),( 51, 41, 26),( 77, 61, 38),(102, 82, 51),(128,102, 64),(158,134,100),(191,171,143),(222,211,195)],
[( 0, 0, 0),( 19, 19, 19),( 39, 39, 39),( 58, 58, 58),( 78, 78, 78),( 98, 98, 98),(117,117,117),(137,137,137), (156,156,156),(176,176,176),(196,196,196),(215,215,215),(235,235,235),(255,255,255),( 0, 0, 0),( 0, 0, 0)]]
class Palette(ttk.TTkWidget):
__slots__ = ('_bg', '_fg', '_mouseMove', '_palette',
@ -80,6 +80,34 @@ class Palette(ttk.TTkWidget):
else:
return ttk.TTkColor.RST
ttk.pyTTkSlot(ttk.TTkColor)
def setColor(self, color:ttk.TTkColor) -> None:
fg = color.foreground()
bg = color.background()
self.enableFg(fg!=None)
self.enableBg(bg!=None)
def _getPos(col):
for y,row in enumerate(self._palette):
for x,c in enumerate(row):
if c[0] == col or c[1] == col:
return x,y
return None
pw, ph = len(self._palette[0]),len(self._palette)
if fg:
if (pos:=_getPos(fg)) != None:
self._fg = pos
else:
self._fg = (pw-2,ph-1)
self._palette[ph-1][pw-2] = (fg,fg.invertFgBg())
if bg:
if (pos:=_getPos(bg)) != None:
self._bg = pos
else:
self._bg = (pw-1,ph-1)
self._palette[ph-1][pw-1] = (bg.invertFgBg(),bg)
self.update()
@ttk.pyTTkSlot(bool)
def enableFg(self, enable=True):
self._enabledFg = enable

6
tools/dumbPaintTool/app/toolspanel.py

@ -34,6 +34,7 @@ class ToolsPanel(ttk.TTkVBoxLayout):
__slots__ = ('_palette',
'_glyph','_color',
'_la_brush_g', '_ta_brush_a'
'_cb_p_fg', '_cb_p_bg',
# Signals
'pickArea', 'toolSelected','areaChanged')
def __init__(self, *args, **kwargs):
@ -85,6 +86,8 @@ class ToolsPanel(ttk.TTkVBoxLayout):
self._la_brush_g = la_brush_g
self._ta_brush_a = ta_brush_a
self._cb_p_fg = cb_p_fg
self._cb_p_bg = cb_p_bg
@ttk.pyTTkSlot()
def _checkTools():
@ -190,6 +193,7 @@ class ToolsPanel(ttk.TTkVBoxLayout):
glbls.brush.glyphEnabledChanged.connect(self._refreshColor)
glbls.brush.areaChanged.connect( self.setArea)
glbls.brush.colorChanged.connect(self._refreshColor)
glbls.brush.colorChanged.connect(self._palette.setColor)
glbls.brush.setColor(self._palette.color())
_checkTools()
@ -208,6 +212,8 @@ class ToolsPanel(ttk.TTkVBoxLayout):
ttk.TTkString("Glyph: '") +
ttk.TTkString(glyph,color) +
ttk.TTkString("'"))
self._cb_p_fg.setChecked(None != color.foreground())
self._cb_p_bg.setChecked(None != color.background())
@ttk.pyTTkSlot(ttk.TTkColor)
def setColor(self, color:ttk.TTkColor):

Loading…
Cancel
Save