@@ -172,6 +172,10 @@ def _popButton(self, index:int) -> Optional[TTkTabButton]:
172172 'default' : {'color' : TTkColor .fgbg ("#dddd88" ,"#000044" ),
173173 'bgColor' : TTkColor .fgbg ("#000000" ,"#8888aa" ),
174174 'borderColor' : TTkColor .RST ,
175+ 'closeColor' : {
176+ 'default' : TTkColor .CYAN ,
177+ 'hovered' : TTkColor .YELLOW
178+ },
175179 'borderHighlightColors' : {
176180 'main' : TTkColor .fg ('#00FFFF' ),
177181 'fade' : TTkColor .fg ('#88FF88' ),
@@ -262,10 +266,6 @@ def __init__(self, *,
262266 self ._tabStatus = tabStatus
263267 super ().__init__ (** kwargs )
264268
265- def mouseReleaseEvent (self , evt :TTkMouseEvent ) -> bool :
266- self .tcbClicked .emit (self )
267- return True
268-
269269 def keyEvent (self , evt :TTkKeyEvent ) -> bool :
270270 if ( evt .type == TTkK .Character and evt .key == " " ) or \
271271 ( evt .type == TTkK .SpecialKey and evt .key == TTkK .Key_Enter ):
@@ -280,17 +280,31 @@ class TTkTabButton(_TTkTabColorButton):
280280 classStyle = (
281281 _TTkTabColorButton .classStyle |
282282 { 'default' : _TTkTabColorButton .classStyle ['default' ] |
283- {'closeGlyph' :' □ ' } ,
283+ {
284+ 'closeGlyph' : {
285+ 'default' :' ○ ' ,
286+ 'hovered' :' ○ '
287+ }
288+ } ,
284289 'hover' : _TTkTabColorButton .classStyle ['hover' ] |
285- {'closeGlyph' :' x ' } } )
290+ {
291+ 'closeGlyph' :{
292+ 'default' :' □ ' ,
293+ 'hovered' :' ▣ '
294+ }
295+ }
296+ }
297+ )
286298
287299 '''TTkTabButton'''
288300 __slots__ = (
289- '_data' ,'_sideEnd' , '_buttonStatus' , '_closable' ,
301+ '_data' ,'_sideEnd' , '_buttonStatus' , '_closable' , '_closeHovered' ,
290302 'closeClicked' , '_closeButtonPressed' , '_text' )
291303
304+ _closeHovered :bool
305+
292306 def __init__ (self , * ,
293- text :TTkString = '' ,
307+ text :TTkStringType = '' ,
294308 data :object = None ,
295309 closable :bool = False ,
296310 ** kwargs ) -> None :
@@ -299,6 +313,7 @@ def __init__(self, *,
299313 self ._buttonStatus = TTkK .Unchecked
300314 self ._data = data
301315 self ._closable = closable
316+ self ._closeHovered = False
302317 self .closeClicked = pyTTkSignal ()
303318 super ().__init__ (** kwargs )
304319 self ._closeButtonPressed = False
@@ -308,7 +323,7 @@ def _resetSize(self) -> None:
308323 style = self .currentStyle ()
309324 size = self .text ().termWidth () + 2
310325 if self ._closable :
311- size += len (style ['closeGlyph' ])
326+ size += len (style ['closeGlyph' ][ 'default' ] )
312327 self .resize (size , self ._tabStatus .barType .vSize ())
313328 self .setMinimumSize (size , self ._tabStatus .barType .vSize ())
314329 self .setMaximumSize (size , self ._tabStatus .barType .vSize ())
@@ -344,25 +359,42 @@ def mousePressEvent(self, evt:TTkMouseEvent) -> bool:
344359 x ,y = evt .x ,evt .y
345360 w ,h = self .size ()
346361 self ._closeButtonPressed = False
347- if self ._closable and evt .key == TTkK .MidButton :
348- self .closeClicked .emit ()
349- return True
350362 offY = self ._tabStatus .barType .offY ()
351363 if self ._closable and y == offY and w - 4 <= x < w - 1 :
352364 self ._closeButtonPressed = True
365+ self .update ()
353366 return True
354- return super ().mouseReleaseEvent (evt )
367+ self .tcbClicked .emit (self )
368+ return True
355369
356370 def mouseReleaseEvent (self , evt :TTkMouseEvent ) -> bool :
357371 x ,y = evt .x ,evt .y
358372 w ,h = self .size ()
359373 offY = self ._tabStatus .barType .offY ()
360- if self ._closable and y == offY and w - 4 <= x < w - 1 and self ._closeButtonPressed :
361- self ._closeButtonPressed = False
374+ if self ._closable and evt .key == TTkK .MidButton :
375+ self .closeClicked .emit ()
376+ elif self ._closable and y == offY and w - 4 <= x < w - 1 and self ._closeButtonPressed :
362377 self .closeClicked .emit ()
363- return False
364378 self ._closeButtonPressed = False
365- return False
379+ return True
380+
381+ def leaveEvent (self , evt ):
382+ self ._closeHovered = False
383+ self .update ()
384+ return super ().leaveEvent (evt )
385+
386+ def mouseMoveEvent (self , evt ):
387+ x ,y = evt .x ,evt .y
388+ w ,h = self .size ()
389+ offY = self ._tabStatus .barType .offY ()
390+ if self ._closable and y == offY and w - 4 <= x < w - 1 :
391+ _new_closeHovered = True
392+ else :
393+ _new_closeHovered = False
394+ if self ._closeHovered != _new_closeHovered :
395+ self ._closeHovered = _new_closeHovered
396+ self .update ()
397+ return True
366398
367399 def mouseDragEvent (self , evt :TTkMouseEvent ) -> bool :
368400 drag = TTkDrag ()
@@ -390,7 +422,7 @@ def paintEvent(self, canvas: TTkCanvas) -> None:
390422
391423 borderColor :TTkColor = style ['borderColor' ]
392424 textColor :TTkColor = style ['color' ]
393- borderHighlightColors :TTkColor = style ['borderHighlightColors' ]
425+ borderHighlightColors :Dict [ str , TTkColor ] = style ['borderHighlightColors' ]
394426
395427 w ,h = self .size ()
396428 offY = self ._tabStatus .barType .offY ()
@@ -543,9 +575,14 @@ def paintEvent(self, canvas: TTkCanvas) -> None:
543575 canvas .drawText (pos = (1 ,offY ), text = self .text (), color = textColor )
544576
545577 if self ._closable :
546- closeGlyph = style ['closeGlyph' ]
578+ if self ._closeHovered :
579+ colorCloseHovered = textColor + style ['closeColor' ]['hovered' ]
580+ closeGlyph = style ['closeGlyph' ]['hovered' ]
581+ else :
582+ colorCloseHovered = textColor + style ['closeColor' ]['default' ]
583+ closeGlyph = style ['closeGlyph' ]['default' ]
547584 closeOff = len (closeGlyph )
548- canvas .drawText (pos = (w - closeOff - 1 ,offY ), text = closeGlyph , color = textColor )
585+ canvas .drawText (pos = (w - closeOff - 1 ,offY ), text = closeGlyph , color = colorCloseHovered )
549586
550587class _TTkTabMenuButton (TTkMenuBarButton ):
551588 def paintEvent (self , canvas : TTkCanvas ) -> None :
@@ -580,7 +617,8 @@ def setSideEnd(self, sideEnd: int) -> None:
580617 # This is a hack to force the action aftet the keypress
581618 # And not key release as normally happen to the button
582619 def mousePressEvent (self , evt :TTkMouseEvent ) -> bool :
583- return super ().mouseReleaseEvent (evt )
620+ self .tcbClicked .emit (self )
621+ return True
584622 def mouseReleaseEvent (self , evt :TTkMouseEvent ) -> bool :
585623 return False
586624 def mouseTapEvent (self , evt :TTkMouseEvent ) -> bool :
0 commit comments