ceccopierangiolieugenio / pyTermTk

Python Terminal Toolkit - a Spiced Up TUI Library 🌶️
https://ceccopierangiolieugenio.github.io/pyTermTk/
MIT License
585 stars 22 forks source link

focusIn focusOut signals #113

Closed nickandwolf closed 9 months ago

nickandwolf commented 1 year ago

So I'm new to this "team coding" thing and have don't have the experience (yet) to help add the features I'd like to see but how about some Focus Signals?

My use case is when focusing in on a Spinbox, it changes a label's text to explain what that Spinbox does in more detail. I'm going to try overloading the Spinbox Class but later on, I would love to help add that kind of stuff. I just need to learn a bit more before then.

I haven't tested this yet...

class TTkSpinBox(TTkWidget):
    '''TTkSpinBox'''
    __slots__= (
        '_lineEdit', '_value', '_maximum', '_minimum',
        '_mouseDelta', '_valueDelta', '_draggable',
        # Signals
        'valueChanged','focusIn','focusOut')
    def __init__(self, *args, **kwargs):
        # Signals
        self.valueChanged=pyTTkSignal(int)
        self.focusIn=pyTTkSignal(str)
        self.focusOut=pyTTkSignal(str)

    def focusInEvent(self):
        self._lineEdit._color = TTkCfg.theme.lineEditTextColorFocus
        self._lineEdit.update()
        self.valueChanged.emit(self.__name__)

    def focusOutEvent(self):
        self._draggable = False
        self._lineEdit._color = TTkCfg.theme.lineEditTextColor
        self._lineEdit.focusOutEvent()
        self._lineEdit.update()
        self.valueChanged.emit(self.__name__)
ceccopierangiolieugenio commented 1 year ago

Actually, I was seriously thinking to remove the focus[In/Out]Event and replace them with a proper signal About your use case, you want some hint to be shown in the spinbox when highlighted?

something like: image

I think this could be implemented as a feature of the LineEdit widget. I need to investigate how other api are implementing this. Anyway, another feature I want to add is the ToolTip when you hover with the mouse. Is quite easy to be implemented but I am worried about the performances if I will add all the mouse move events.

nickandwolf commented 1 year ago

So I actually had an ugly ass box that just populated with info when the focus changed but your ideas are WAY better. I understand your consideration for performance. I think the best way to handle that would be to allow a "focus tooltip" or to default to tooltips being off. Also the shadow text would be awesome and cut down on a lot of useless labels I'm tossing around.

As for my program, it's probably 50% there to being in alpha. Then I can turn it over and show you the abomination I created with your wonderful library. I am probably doing something insane that was never expected with it so a good test run.

ceccopierangiolieugenio commented 1 year ago

ok, I will think about tooltip/hover as a prototype not enabled by default. the shadowtext is easier to be added and I will implement it soon

nickandwolf commented 1 year ago

The focus tool tip ideas is like when something is clicked (and the border color changes). You can have it so it'll only check the bounding box of the object for the mouse and place the tooltip at a nearby corner (to not obscure the widget). For windows or frames, have it only be the title bar. It would also cut down on mouse tracking because it would only be active for 1 widget at a time and would only activate if the mouse is in specific boundaries.

So if only the Window is focused, the Window Title would be the box. If LineEdit was focused, only it (and maybe we can extend/link/connect a label to it) would be the thing. Etc.

+++++++++++++++++++++++++
+ Window Title          +
+++++++++++++++++++++++++
+ #label# [_LineEdit_]  +
+ ###[_ComboBox_^]      +
+ [X] #RadioBttn#       +
+++++++++++++++++++++++++

Hopefully there's some fancy code that doesn't need to track the mouse's exact position constantly but instead reduces performance load because of the smaller area that needs to be checked.

ceccopierangiolieugenio commented 1 year ago

Prototyping with the toolTip

Peek 2023-02-12 23-47.webm

import TermTk as ttk

root = ttk.TTk(title="pyTermTk Demo", mouseTrack=True)

ttk.TTkLabel( parent=root, text="Label 1",  pos=(0,0),  size=(10,1), toolTip="TT Label 1")
ttk.TTkButton(parent=root, text="Button 1", pos=(0,1), size=(10,1),  toolTip="TT Button 1")
ttk.TTkButton(parent=root, text="Button 2", pos=(0,2), size=(10,3),  toolTip="TT Button 2", border=True)
ttk.TTkButton(parent=root, text="Button 3", pos=(0,5), size=(20,3),  toolTip="TT Button 3\n\nNewline", border=True)
ttk.TTkButton(parent=root, text="Button 3", pos=(21,0), size=(20,10), border=True,
    toolTip=
        ttk.TTkString(color=ttk.TTkColor.fg("#ff0000") ,text="   L😎rem ipsum\n")+
        ttk.TTkString(color=ttk.TTkColor.fg("#00ff00") ,text="dolor sit amet,\n ⌚ ❤ 💙 🙋'\nYepp!!!"))

w1 = ttk.TTkWindow(parent=root, title="LOG", pos=(0,10), size=(90,20), layout=ttk.TTkGridLayout(), toolTip="TT Log Window\n  With\nLogDump")
ttk.TTkLogViewer(parent=w1)
w2 = ttk.TTkWindow(parent=root, title="KeyLogger", pos=(0,30), size=(60,7), layout=ttk.TTkGridLayout())
ttk.TTkKeyPressView(parent=w2, toolTip="This is a\nKey Logger Widget")

root.mainloop()
nickandwolf commented 1 year ago

Looks absolutely fantastic

ceccopierangiolieugenio commented 1 year ago

Merged the MouseMove and ToolTip (and fixes here and there) and the mouse Hover prototype https://github.com/ceccopierangiolieugenio/pyTermTk/pull/114

And released the Version 0.22.0a0

You can Try It Here

Note: The mouse Tracking is not enabled by default (It will be in the future) This is required for the MouseMove/Hover and ToolTip feature. In order to enable it initiate the root widget with; root = ttk.TTk(mouseTrack=True)

as in: https://github.com/ceccopierangiolieugenio/pyTermTk/blob/0303f939f790d08a61c2240f06b550c0c99520a8/tests/test.ui.025.toolTip.py#L28-L46