Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to connect some widget made in TTK Designer to another TTK Designer output #210

Open
smartkid2024 opened this issue Jan 2, 2024 · 21 comments
Assignees
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@smartkid2024
Copy link

Hi I made a form with TTK Designer and it give me this code:

widget = TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkContainer', 'params': {'Name': 'MainWidget', 'Position': [2, 3], 'Size': [72, 24], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [0, 0, 0, 0], 'Layout': 'TTkLayout'}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 72, 24)}, 'children': [{'class': 'TTkFrame', 'params': {'Name': 'CheckLicenseFrame', 'Position': [1, 1], 'Size': [68, 22], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': '\x1b[0;1mCheck License'}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 66, 20)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [3, 7], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame-1', 'Position': [4, 8], 'Size': [57, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 55, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'LicenseInput', 'Position': [0, 0], 'Size': [54, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65530, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'CheckBtn', 'Position': [22, 11], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []})

I used this example to make this code:

from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox
from TermTk import pyTTkSlot

TTkLog.use_default_file_logging()

class MyTextEditor(TTkWindow):

    def __init__(self, root):
        self.root = root
        TTkUiLoader.loadDict(
        {'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)

        self.textMyInput = self.getWidgetByName('licenseTxtInput')
        self.checkButton = self.getWidgetByName('checkLicenseBtn')
        self.checkButton.clicked.connect(self.onCheckButtonClick)

    pyTTkSlot(str)
    def onCheckButtonClick(self):
        # Print the content of the text input when button is clicked
        print(self.textMyInput.text())
        TTkMessageBox.warning("Warning", "An error has occurred!")
        # Close the window and exit the application
        #TTk().quit()

root=TTk()
root.layout().addWidget(MyTextEditor(root))
root.mainloop()

So i get this output:
image

How can I connect another window or another TTK Designer to my code? suppose I make a error window like this:

widget = TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkContainer', 'params': {'Name': 'MainWidget', 'Position': [2, 2], 'Size': [97, 29], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [0, 0, 0, 0], 'Layout': 'TTkLayout'}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 97, 29)}, 'children': [{'class': 'TTkWindow', 'params': {'Name': 'TTkWindow', 'Position': [13, 6], 'Size': [38, 11], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [3, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': '\x1b[0;38;2;255;0;0;1mError\x1b[0m\x1b[0m ', 'Window Flags': 134217728}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 36, 7)}, 'children': [{'class': 'TTkButton', 'params': {'Name': 'TTkButton', 'Position': [8, 4], 'Size': [20, 3], 'Min Width': 4, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'OK', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [2, 1], 'Size': [32, 2], 'Min Width': 14, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'A lot of text \nor something', 'Color': '\x1b[48;2;255;0;0m', 'Alignment': 4}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []}")

Output:
image

How can I join the output of TTK designer to my previous code for example if some condition happens then the new window opens
it was very helpful to make an example work with some form and processing user input

@ceccopierangiolieugenio
Copy link
Owner

You can use the overlay helper

I made an example using your code in:
https://gist.github.com/ceccopierangiolieugenio/4b51a95e5f516d14e7c2c513ae51979f

you can tryItOnline

from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot

TTkLog.use_default_file_logging()

class MyTextEditor(TTkWindow):

    def __init__(self, root):
        self.root = root
        TTkUiLoader.loadDict(
        {'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)

        self.textMyInput = self.getWidgetByName('licenseTxtInput')
        self.checkButton = self.getWidgetByName('checkLicenseBtn')
        self.checkButton.clicked.connect(self.onCheckButtonClick)

    pyTTkSlot(str)
    def onCheckButtonClick(self):
        # You can use the log api to debug and print
        # using the built in "print" would interfere with 
        # the drawing routine
        TTkLog.debug(self.textMyInput.text())
        messageBox = TTkMessageBox(
                title="🤯 Error!!!",
                text="An error has occurred!\nA lot of text 💥\nor Something",
                icon=TTkMessageBox.Icon.Warning,
                standardButtons=TTkMessageBox.StandardButton.Ok)
        TTkHelper.overlay(self, messageBox, 2, 1, True)
        # Close the window and exit the application
        #TTk().quit()

root=TTk()

# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)

root.layout().addWidget(MyTextEditor(root))

root.mainloop()

@ceccopierangiolieugenio ceccopierangiolieugenio added the question Further information is requested label Jan 2, 2024
@smartkid2024
Copy link
Author

Hi Thanks for your answer and I have another problem. I want to make a widget (not a window) I want the user can not move the window and need only one frame with my form so I designed something in ttkDesigner but as the format of the window I made Python script like this:

from TermTk import TTkUiLoader, TTk,TTkWidget

class MyTextEditor(TTkWidget):

    def __init__(self, root):
        self.root = root
        TTkUiLoader.loadDict(
        {'version': '2.0.0', 'tui': {'class': 'TTkContainer', 'params': {'Name': 'MainWidget', 'Position': [3, 2], 'Size': [94, 31], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [0, 0, 0, 0], 'Layout': 'TTkLayout'}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 94, 31)}, 'children': [{'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [1, 1], 'Size': [71, 22], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 69, 20)}, 'children': [{'class': 'TTkTextEdit', 'params': {'Name': 'TTkTextEdit-1', 'Position': [28, 6], 'Size': [20, 5], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Line Number': False, 'Line Number Starting': 0, 'Read Only': False, 'Multi Line': True}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLineEdit', 'params': {'Name': 'TTkLineEdit', 'Position': [10, 6], 'Size': [49, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'TTkButton', 'Position': [25, 10], 'Size': [20, 3], 'Min Width': 8, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Button', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)


root=TTk()
root.layout().addWidget(MyTextEditor(root))
root.mainloop()

but I get this error:

Traceback (most recent call last):
  File "/mnt/My/Projects/server/.exclude/Test/gui/ttk/test10.py", line 12, in <module>
    root.layout().addWidget(MyTextEditor(root))
  File "/mnt/My/Projects/server/.exclude/Test/gui/ttk/test10.py", line 7, in __init__
    TTkUiLoader.loadDict(
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkUiTools/uiloader.py", line 315, in loadDict
    return cb(ui, baseWidget, kwargs)
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkUiTools/uiloader.py", line 258, in _loadDict_2_0_0
    widget =  _getWidget(ui['tui'], baseWidget, args)
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkUiTools/uiloader.py", line 176, in _getWidget
    raise TypeError(error)
TypeError: Base Widget 'MyTextEditor' is not a subclass of 'TTkContainer'
Exception ignored in: <function TTkWidget.__del__ at 0x7fb21bf80c10>
Traceback (most recent call last):
  File "/mnt/My/Projects/server/venv/lib/python3.10/site-packages/TermTk/TTkWidgets/widget.py", line 178, in __del__
    if hasattr(self._parent,'layout') and self._parent.layout():
AttributeError: 'MyTextEditor' object has no attribute '_parent'

Maybe need make an example for using only widget
Thanks

@ceccopierangiolieugenio
Copy link
Owner

This is because you are using a TTkContainer instead of a widget:
I noticed that the container is displayed after you resize the terminal, I need to investigate why a refresh is not triggered soon after you add the widget to the layout.

from TermTk import TTkUiLoader, TTk,TTkContainer

class MyTextEditor(TTkContainer):

    def __init__(self, root):
        self.root = root
        TTkUiLoader.loadDict(
        {'version': '2.0.0', 'tui': {'class': 'TTkContainer', 'params': {'Name': 'MainWidget', 'Position': [3, 2], 'Size': [94, 31], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [0, 0, 0, 0], 'Layout': 'TTkLayout'}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 94, 31)}, 'children': [{'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [1, 1], 'Size': [71, 22], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 69, 20)}, 'children': [{'class': 'TTkTextEdit', 'params': {'Name': 'TTkTextEdit-1', 'Position': [28, 6], 'Size': [20, 5], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Line Number': False, 'Line Number Starting': 0, 'Read Only': False, 'Multi Line': True}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLineEdit', 'params': {'Name': 'TTkLineEdit', 'Position': [10, 6], 'Size': [49, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'TTkButton', 'Position': [25, 10], 'Size': [20, 3], 'Min Width': 8, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Button', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)

root=TTk()
root.layout().addWidget(MyTextEditor(root))
root.mainloop()

@smartkid2024
Copy link
Author

I need a window that the user cannot move it. strict window with a fixed size. So what do you think you could suggest?
is it possible to use the window but disable moving ? I just need only fixed page (with a border) and a form inside it

@smartkid2024
Copy link
Author

In this code. how can I define an action for the button on the message box? if the user presses OK then something happens like quitting the program

from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot

TTkLog.use_default_file_logging()

class MyTextEditor(TTkWindow):

    def __init__(self, root):
        self.root = root
        TTkUiLoader.loadDict(
        {'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)

        self.textMyInput = self.getWidgetByName('licenseTxtInput')
        self.checkButton = self.getWidgetByName('checkLicenseBtn')
        self.checkButton.clicked.connect(self.onCheckButtonClick)

    pyTTkSlot(str)
    def onCheckButtonClick(self):
        # You can use the log api to debug and print
        # using the built in "print" would interfere with
        # the drawing routine
        TTkLog.debug(self.textMyInput.text())
        messageBox = TTkMessageBox(
                title="⛔️ Error!!!",
                text="Ann error has occurred!\n{}".format(self.textMyInput.text()),
                standardButtons=TTkMessageBox.StandardButton.Ok)
        TTkHelper.overlay(self, messageBox, 2, 1, True)
        # Close the window and exit the application
        TTk().quit()

root=TTk()

# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)

root.layout().addWidget(MyTextEditor(root))

root.mainloop()

@smartkid2024
Copy link
Author

I read this document for messagebox: (messagebox)
But I could not find out how can I put more buttons in the message box. for example OK and Help buttons. because there is no example there and docs are so short I tried this code and got the error:

        messageBox = TTkMessageBox(
                title="⛔️ Error!!!",
                text="Ann error has occurred!\n{}".format(self.textMyInput.text()),
                standardButtons=[TTkMessageBox.StandardButton.Ok,TTkMessageBox.StandardButton.Help])
        TTkHelper.overlay(self, messageBox, 2, 1, True)

@smartkid2024
Copy link
Author

Also, how can I colorize the title or text in the message box? For example for error message text should be red. I think you wrote docs for yourself it's very brief

@smartkid2024
Copy link
Author

I wrote this code but I can't change the messagebox text or title to the red color:

from TermTk import TTkUiLoader, TTk, TTkWindow, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot

TTkLog.use_default_file_logging()

class MyTextEditor(TTkWindow):

    def __init__(self, root):
        self.root = root
        TTkUiLoader.loadDict(
        {'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)

        self.textMyInput = self.getWidgetByName('licenseTxtInput')
        self.checkButton = self.getWidgetByName('checkLicenseBtn')
        self.checkButton.clicked.connect(self.onCheckButtonClick)

    pyTTkSlot(str)
    def onCheckButtonClick(self):
        # You can use the log api to debug and print
        # using the built in "print" would interfere with
        # the drawing routine
        TTkLog.debug(self.textMyInput.text())
        messageBox = TTkMessageBox(
            title="⛔️ Error!!!",
            text="Ann error has occurred!\n{}".format(self.textMyInput.text()),
            standardButtons=TTkMessageBox.StandardButton.Ok | TTkMessageBox.StandardButton.Cancel | TTkMessageBox.StandardButton.Yes)
        TTkHelper.overlay(self, messageBox, 2, 1, True)
        messageBox.buttonSelected.connect(self._buttonSelected)
        
    def _buttonSelected(self, btn):
        buttonName = {
            TTkMessageBox.StandardButton.Ok : 'Ok',
            TTkMessageBox.StandardButton.Open : 'Open',
            TTkMessageBox.StandardButton.Save : 'Save',
            TTkMessageBox.StandardButton.Cancel : 'Cancel',
            TTkMessageBox.StandardButton.Close : 'Close',
            TTkMessageBox.StandardButton.Discard : 'Discard',
            TTkMessageBox.StandardButton.Apply : 'Apply',
            TTkMessageBox.StandardButton.Reset : 'Reset',
            TTkMessageBox.StandardButton.RestoreDefaults : 'RestoreDefaults',
            TTkMessageBox.StandardButton.Help : 'Help',
            TTkMessageBox.StandardButton.SaveAll : 'SaveAll',
            TTkMessageBox.StandardButton.Yes : 'Yes',
            TTkMessageBox.StandardButton.YesToAll : 'YesToAll',
            TTkMessageBox.StandardButton.No : 'No',
            TTkMessageBox.StandardButton.NoToAll : 'NoToAll',
            TTkMessageBox.StandardButton.Abort : 'Abort',
            TTkMessageBox.StandardButton.Retry : 'Retry',
            TTkMessageBox.StandardButton.Ignore : 'Ignore',
            TTkMessageBox.StandardButton.NoButton : 'NoButton'}.get(int(btn),"???")
        TTkLog.debug(f"btn: {int(btn)}")
        TTkLog.debug(f"Selected: {buttonName}")

        if buttonName == "Ok":
            self.onMessageBoxButtonClick()

    def onMessageBoxButtonClick(self):
        # This function will be called when the user clicks the "Ok" button
        TTk().quit()

root=TTk()

# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)

root.layout().addWidget(MyTextEditor(root))

root.mainloop()

@smartkid2024
Copy link
Author

Is there any progress bar or something like that for example when the user clicks to check the checking button fills with dot's and repeats until connect to the license server and gets response something like this(but it doesn't work):

from TermTk import TTkUiLoader, TTk, TTkWindow, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
import time

TTkLog.use_default_file_logging()

class MyTextEditor(TTkWindow):

    def __init__(self, root):
        self.root = root
        TTkUiLoader.loadDict(
        {
        "version": "2.0.0",
        "tui": {
            "class": "TTkWindow",
            "params": {
                "Name": "MainWindow",
                "Position": [0, 0],
                "Size": [83, 25],
                "Min Width": 0,
                "Min Height": 0,
                "Max Width": 200,
                "Max Height": 200,
                "Visible": True,
                "Enabled": True,
                "ToolTip": "",
                "Padding": [1, 1, 1, 1],
                "Layout": "TTkLayout",
                "Border": True,
                "Title": "Check License",
                "Window Flags": 0,
            },
            "layout": {
                "class": "TTkLayout",
                "params": {"Geometry": (0, 0, 81, 23)},
                "children": [
                    {
                        "class": "TTkLabel",
                        "params": {
                            "Name": "TTkLabel",
                            "Position": [5, 11],
                            "Size": [21, 1],
                            "Min Width": 21,
                            "Min Height": 1,
                            "Max Width": 65536,
                            "Max Height": 65536,
                            "Visible": True,
                            "Enabled": True,
                            "ToolTip": "",
                            "Text": "Please Enter License:",
                            "Color": "\x1b[0m",
                            "Alignment": 0,
                        },
                        "row": 0,
                        "col": 0,
                        "rowspan": 1,
                        "colspan": 1,
                    },
                    {
                        "class": "TTkFrame",
                        "params": {
                            "Name": "TTkFrame",
                            "Position": [9, 12],
                            "Size": [62, 3],
                            "Min Width": 0,
                            "Min Height": 0,
                            "Max Width": 65536,
                            "Max Height": 65536,
                            "Visible": True,
                            "Enabled": True,
                            "ToolTip": "",
                            "Padding": [1, 1, 1, 1],
                            "Layout": "TTkLayout",
                            "Border": True,
                            "Title": "",
                        },
                        "layout": {
                            "class": "TTkLayout",
                            "params": {"Geometry": (0, 0, 60, 1)},
                            "children": [
                                {
                                    "class": "TTkLineEdit",
                                    "params": {
                                        "Name": "licenseTxtInput",
                                        "Position": [1, 0],
                                        "Size": [58, 1],
                                        "Min Width": 1,
                                        "Min Height": 1,
                                        "Max Width": 65536,
                                        "Max Height": 1,
                                        "Visible": True,
                                        "Enabled": True,
                                        "ToolTip": "",
                                        "Input Type": 1,
                                        "Text": "",
                                    },
                                    "row": 0,
                                    "col": 0,
                                    "rowspan": 1,
                                    "colspan": 1,
                                }
                            ],
                        },
                        "row": 0,
                        "col": 0,
                        "rowspan": 1,
                        "colspan": 1,
                    },
                    {
                        "class": "TTkButton",
                        "params": {
                            "Name": "checkLicenseBtn",
                            "Position": [30, 15],
                            "Size": [20, 3],
                            "Min Width": 7,
                            "Min Height": 3,
                            "Max Width": 65536,
                            "Max Height": 65536,
                            "Visible": True,
                            "Enabled": True,
                            "ToolTip": "",
                            "Text": "Check",
                            "Border": True,
                            "Checkable": False,
                            "Checked": False,
                        },
                        "row": 0,
                        "col": 0,
                        "rowspan": 1,
                        "colspan": 1,
                    },
                ],
            },
        },
            "connections": [],
        },self)

        self.textMyInput = self.getWidgetByName('licenseTxtInput')
        self.checkButton = self.getWidgetByName('checkLicenseBtn')
        self.checkButton.clicked.connect(self.onCheckButtonClick)

    pyTTkSlot(str)
    def onCheckButtonClick(self):
        TTkLog.debug(self.textMyInput.text())
        self.checkButton.setDisabled()
        self._checking()
        self.textMyInput.setDisabled()
        
        #self.checkButton.setDisabled()
        # messageBox = TTkMessageBox(
        #     title="⛔️ Error!!!",
        #     text="Ann error has occurred!\n{}".format(self.textMyInput.text()),
        #     detailedText="OKKKK",
        #     standardButtons=TTkMessageBox.StandardButton.Ok | TTkMessageBox.StandardButton.Cancel | TTkMessageBox.StandardButton.Yes)
        # TTkHelper.overlay(self, messageBox, 2, 1, True,True,True)
        # messageBox.buttonSelected.connect(self.onMessageBoxButtonClick)

    def _checking(self):
        while True:
            for i in range(4):
                self.checkButton.setText("Checking" + "." * i)
                time.sleep(1)  # Wait for 1 second

    def onMessageBoxButtonClick(self,btn):
        if self._buttonName(btn) == "Ok":
            TTk().quit()

    def _buttonName(self,btn):
        buttonName = {
        TTkMessageBox.StandardButton.Ok : 'Ok',
        TTkMessageBox.StandardButton.Open : 'Open',
        TTkMessageBox.StandardButton.Save : 'Save',
        TTkMessageBox.StandardButton.Cancel : 'Cancel',
        TTkMessageBox.StandardButton.Close : 'Close',
        TTkMessageBox.StandardButton.Discard : 'Discard',
        TTkMessageBox.StandardButton.Apply : 'Apply',
        TTkMessageBox.StandardButton.Reset : 'Reset',
        TTkMessageBox.StandardButton.RestoreDefaults : 'RestoreDefaults',
        TTkMessageBox.StandardButton.Help : 'Help',
        TTkMessageBox.StandardButton.SaveAll : 'SaveAll',
        TTkMessageBox.StandardButton.Yes : 'Yes',
        TTkMessageBox.StandardButton.YesToAll : 'YesToAll',
        TTkMessageBox.StandardButton.No : 'No',
        TTkMessageBox.StandardButton.NoToAll : 'NoToAll',
        TTkMessageBox.StandardButton.Abort : 'Abort',
        TTkMessageBox.StandardButton.Retry : 'Retry',
        TTkMessageBox.StandardButton.Ignore : 'Ignore',
        TTkMessageBox.StandardButton.NoButton : 'NoButton'}.get(int(btn),"???")

        return buttonName

root=TTk()

# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)

root.layout().addWidget(MyTextEditor(root))

root.mainloop()

@ceccopierangiolieugenio
Copy link
Owner

About the messagebox:

I made an example here:
https://gist.github.com/ceccopierangiolieugenio/e2e09796ef9eb1e6f880d8d47e1fd274

Where a multicolor title is defined, more buttons are used and the actions are processed, tryItOnline

from TermTk import TTkButton, TTk, TTkWindow, TTkString, TTkColor, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot


# To process the reeturn calue of rthe messagebox you need a slot that accept
# a Messagebox's Standard Button, the button pressed will be returned
@pyTTkSlot(TTkMessageBox.StandardButton)
def _processMessageBoxAction(btn):
    if btn == TTkMessageBox.StandardButton.Discard:
        TTkLog.debug("Discard Pressed 😎")
    if btn == TTkMessageBox.StandardButton.Save:
        TTkLog.debug("Save Pressed 😈")
    if btn == TTkMessageBox.StandardButton.Cancel:
        TTkLog.debug("Cancel Pressed 😇")


# In this example I am creating a message box that accept multiple actions
# and with colored text in the title and the main area
@pyTTkSlot()
def _testMessageBox():
    TTkLog.debug("Initialize the MessageBox 😮")
    messageBox = TTkMessageBox(
                    title = ( TTkString( f' Half Blue ',    TTkColor.fg("#FFFF00")+TTkColor.bg("#0000FF")) +
                              TTkString( f' Half Green 🤯', TTkColor.fg("#000000")+TTkColor.bg("#00FF00")) ),
                    text= (
                        TTkString( f'Bold Line\n', TTkColor.BOLD) +
                        TTkString( f'Red Line\n',  TTkColor.fg("#FF0000")) +
                        TTkString( f'Blue Line\n', TTkColor.fg("#FFFF00")+TTkColor.bg("#0000FF")) ),
                    icon=TTkMessageBox.Icon.Warning,
                    standardButtons=
                        TTkMessageBox.StandardButton.Discard |
                        TTkMessageBox.StandardButton.Save |
                        TTkMessageBox.StandardButton.Cancel )
    messageBox.buttonSelected.connect(_processMessageBoxAction)
    TTkHelper.overlay(None, messageBox, 5, 5, True)


root=TTk()

# Adding a log window to help debugging the messagebox pressed actions
logWin = TTkWindow(parent=root, text="Logs", pos=(5,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)

btn = TTkButton(parent=root, text="Test Messagebox",border=True)
btn.clicked.connect(_testMessageBox)

root.mainloop()

@ceccopierangiolieugenio
Copy link
Owner

Is there any progress bar or something like that for example when the user clicks to check the checking button fills with dot's and repeats until connect to the license server and gets response something like this(but it doesn't work):

There is an unofficial progeressbar widget and an animation helper that can be used to create this kind of animation,
I can help you to set it up.
Do you want some kind of idle animation for the time the connection take place?

@smartkid2024
Copy link
Author

smartkid2024 commented Jan 7, 2024

Is there any progress bar or something like that for example when the user clicks to check the checking button fills with dot's and repeats until connect to the license server and gets response something like this(but it doesn't work):

There is an unofficial progeressbar widget and an animation helper that can be used to create this kind of animation, I can help you to set it up. Do you want some kind of idle animation for the time the connection take place?

yes sure it can be animation of something that happened
also, I can use time to complete the process bar for example 20 seconds to connect to the server and get the response and it can show like process bar

I tried to use the example you put link I got this error:

Traceback (most recent call last):
  File "/mnt/My/Home/Projects/server/.exclude/Test/gui/ttk/test15.py", line 62, in <module>
    create_bar(win, 0.09, 0.01)
  File "/mnt/My/Home/Projects/server/.exclude/Test/gui/ttk/test15.py", line 40, in create_bar
    bar = TermTk.TTkProgressBar(parent=parent, look_and_feel=look_and_feel)
AttributeError: module 'TermTk' has no attribute 'TTkProgressBar'

@smartkid2024
Copy link
Author

smartkid2024 commented Jan 7, 2024

Can the border be red color in this window?
image

@smartkid2024
Copy link
Author

How can I switch between two containers? for example, I will show a form, and after the user clicks the check button the first container hides and the second container shows but when I set visible to False that object is removed from my page and it returns errors: self.getWidgetByName('InfoForm').setVisible(True) AttributeError: 'NoneType' object has no attribute 'setVisible'

class msgType(Enum):
    ERROR = 1
    INFO = 2
    MESSAGE = 3
    WARNING = 4


class MyCheckLicense(TTkWindow):

    def __init__(self, root):
        self.root = root

        TTkUiLoader.loadDict({
        "version": "2.0.0",
        "tui": {
            "class": "TTkWindow",
            "params": {
                "Name": "MainLicense",
                "Position": [0, 0],
                "Size": [59, 22],
                "Min Width": 0,
                "Min Height": 0,
                "Max Width": 65536,
                "Max Height": 65536,
                "Visible": True,
                "Enabled": True,
                "ToolTip": "",
                "Padding": [0, 0, 0, 0],
                "Layout": "TTkLayout",
                "Border": True,
                "Title": "Check License",
                "Window Flags": 0,
            },
            "layout": {
                "class": "TTkLayout",
                "params": {"Geometry": (0, 0, 59, 22)},
                "children": [
                    {
                        "class": "TTkContainer",
                        "params": {
                            "Name": "IpForm",
                            "Position": [1, 3],
                            "Size": [57, 18],
                            "Min Width": 0,
                            "Min Height": 0,
                            "Max Width": 65536,
                            "Max Height": 65536,
                            "Visible": True,
                            "Enabled": True,
                            "ToolTip": "",
                            "Padding": [0, 0, 0, 0],
                            "Layout": "TTkLayout",
                        },
                        "layout": {},
                        "row": 0,
                        "col": 0,
                        "rowspan": 1,
                        "colspan": 1,
                    },
                    {
                    "class": "TTkContainer",
                    "params": {
                        "Name": "InfoForm",
                        "Position": [1, 3],
                        "Size": [57, 18],
                        "Min Width": 0,
                        "Min Height": 0,
                        "Max Width": 65536,
                        "Max Height": 65536,
                        "Visible": True,
                        "Enabled": True,
                        "ToolTip": "",
                        "Padding": [0, 0, 0, 0],
                        "Layout": "TTkLayout",
                    },
                    "layout": {},
                    "row": 0,
                    "col": 0,
                    "rowspan": 1,
                    "colspan": 1,
                }
                ],
            },
        },
            "connections": [],
        }
            , self)

        server_ip=get_ip_address().split(".")
        self.getWidgetByName('InfoForm').setVisible(False)
        self.getWidgetByName('IpPart1').setText(server_ip[0])
        self.getWidgetByName('IpPart2').setText(server_ip[1])
        self.getWidgetByName('IpPart3').setText(server_ip[2])
        self.getWidgetByName('IpPart4').setText(server_ip[3])
        self.checkButton = self.getWidgetByName('CheckBtn')
        self.checkButton.clicked.connect(self.onCheckButtonClick)

    pyTTkSlot(str)
    def onCheckButtonClick(self):
        self.checkButton.setDisabled()
        self.checkButton.setText("Checking...")
        self.getServerInfo()

    def getServerInfo(self):
        get_info=True

        if get_info:
            self.getWidgetByName('IpForm').setVisible(False)
            self.getWidgetByName('InfoForm').setVisible(True)

    def msgBox(self,type,text,title=None):

        if title is None:
            if type == msgType.ERROR:
                title = ( TTkString( f'⛔️ Error!',    TTkColor.fg("#FF0000")+TTkColor.BOLD) )
                text = (TTkString( f'{text}',  TTkColor.fg("#FF0000")) )
            elif type == msgType.INFO:
                title = ( TTkString( f'✅️ Successful!',    TTkColor.bg("#FFFFFF")+TTkColor.fg("#008D19")+TTkColor.BOLD) )
                text = (TTkString( f'{text}',  TTkColor.fg("#5BFF6B")) )
            elif type == msgType.WARNING:
                title = ( TTkString( f'⚠️  Warning!',   TTkColor.fg("#FF4800")+TTkColor.BOLD) )
                text = (TTkString( f'{text}',  TTkColor.fg("#FF4800")) )
            else:
                title = ( TTkString( f'ℹ️️  Info!',    TTkColor.bg("#FFFFFF")+TTkColor.fg("#0062FF")+TTkColor.BOLD) )
                text = (TTkString( f'{text}',  TTkColor.fg("#FFFFFF")) )

        messageBox = TTkMessageBox(
            title=title,
            text=text,
            standardButtons=TTkMessageBox.StandardButton.Ok)
        TTkHelper.overlay(self, messageBox, 22, 10, True)

    def onMessageBoxButtonClick(self,btn):
        if self._buttonName(btn) == "Ok":
            TTk().quit()

    def _buttonName(self,btn):
        buttonName = {
        TTkMessageBox.StandardButton.Ok : 'Ok',
        TTkMessageBox.StandardButton.Open : 'Open',
        TTkMessageBox.StandardButton.Save : 'Save',
        TTkMessageBox.StandardButton.Cancel : 'Cancel',
        TTkMessageBox.StandardButton.Close : 'Close',
        TTkMessageBox.StandardButton.Discard : 'Discard',
        TTkMessageBox.StandardButton.Apply : 'Apply',
        TTkMessageBox.StandardButton.Reset : 'Reset',
        TTkMessageBox.StandardButton.RestoreDefaults : 'RestoreDefaults',
        TTkMessageBox.StandardButton.Help : 'Help',
        TTkMessageBox.StandardButton.SaveAll : 'SaveAll',
        TTkMessageBox.StandardButton.Yes : 'Yes',
        TTkMessageBox.StandardButton.YesToAll : 'YesToAll',
        TTkMessageBox.StandardButton.No : 'No',
        TTkMessageBox.StandardButton.NoToAll : 'NoToAll',
        TTkMessageBox.StandardButton.Abort : 'Abort',
        TTkMessageBox.StandardButton.Retry : 'Retry',
        TTkMessageBox.StandardButton.Ignore : 'Ignore',
        TTkMessageBox.StandardButton.NoButton : 'NoButton'}.get(int(btn),"???")

        return buttonName


root = TTk()

# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30, 10), size=(100, 20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)

root.layout().addWidget(MyCheckLicense(root))

root.mainloop()

@smartkid2024
Copy link
Author

smartkid2024 commented Jan 8, 2024

Checking... and setting disable on the button doesn't show it shows the next form after waiting for sleep

class MyCheckLicense(TTkWindow):

    def __init__(self, root):
        self.root = root

        TTkUiLoader.loadDict({}, self)

        server_ip=get_ip_address().split(".")
        self.ip_form_geometry=self.getWidgetByName('IpForm').geometry()
        self.info_form_geometry=self.getWidgetByName('InfoForm').geometry()

        self.getWidgetByName('InfoForm').setGeometry(0,0,0,0)
        self.getWidgetByName('IpPart1').setText(server_ip[0])
        self.getWidgetByName('IpPart2').setText(server_ip[1])
        self.getWidgetByName('IpPart3').setText(server_ip[2])
        self.getWidgetByName('IpPart4').setText(server_ip[3])
        self.checkButton = self.getWidgetByName('CheckBtn')
        self.checkButton.clicked.connect(self.onCheckButtonClick)

    pyTTkSlot(str)
    def onCheckButtonClick(self):
        self.checkButton.setDisabled()
        self.checkButton.setText("Checking...")
        self.getServerInfo()

    def getServerInfo(self):
        time.sleep(5)
        get_info=True
        if get_info:
            self.getWidgetByName('IpForm').setGeometry(0,0,0,0)
            self.getWidgetByName('InfoForm').setGeometry(*self.info_form_geometry)

@ceccopierangiolieugenio
Copy link
Owner

ceccopierangiolieugenio commented Jan 8, 2024

Sorry, I can't follow all those unrelated topics on this issue tracker.
Please raise a separate issue for any question you want to ask and details them.
Or use the discussion form.

And, you can use this way to initialize a basic widget (without any ui loaded):

class MyCheckLicense(TTkWindow):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)        

root = TTk()
MyCheckLicense(parent=root))
root.mainloop()

otherwise:

class MyCheckLicense(TTkWindow):
    def __init__(self, **kwargs):
        TTkUiLoader.loadDict(<THE_UI_DICT_DEFINITION>, self, kwargs)

root = TTk()
MyCheckLicense(parent=root))
root.mainloop()

it is more handy if you want to treat your class like a standard widget
I should have been more detailed in my tutporial

@smartkid2024
Copy link
Author

smartkid2024 commented Jan 10, 2024

Sorry, I can't follow all those unrelated topics on this issue tracker. Please raise a separate issue for any question you want to ask and details them. Or use the discussion form.

And, you can use this way to initialize a basic widget (without any ui loaded):

class MyCheckLicense(TTkWindow):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)        

root = TTk()
MyCheckLicense(parent=root))
root.mainloop()

otherwise:

class MyCheckLicense(TTkWindow):
    def __init__(self, **kwargs):
        TTkUiLoader.loadDict(<THE_UI_DICT_DEFINITION>, self, kwargs)

root = TTk()
MyCheckLicense(parent=root))
root.mainloop()

it is more handy if you want to treat your class like a standard widget I should have been more detailed in my tutporial
Ok i made topic for each question
What is that? it's reply to which question?

@ceccopierangiolieugenio
Copy link
Owner

It is just a note on the initialisation of the widget

i.e. your first one could be initialised as:

from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot

TTkLog.use_default_file_logging()

class MyTextEditor(TTkWindow):

    def __init__(self, **kwargs):
        TTkUiLoader.loadDict(
            {'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},
            self, kwargs)


root=TTk( title="Test LOGIN!!!" )
MyTextEditor(parent=root)
root.mainloop()

@ceccopierangiolieugenio
Copy link
Owner

Also, how can I colorize the title or text in the message box? For example for error message text should be red. I think you wrote docs for yourself it's very brief

You can use the classStyle, this is an alpha feature,
It is not properly documented yet because it is still undergoing a review process
it may change in the future.

I made an example here:
https://gist.github.com/ceccopierangiolieugenio/5e28a0d6f9804533dc6973ce8223976e

tryItOnline

from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout, TTkColor
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot

TTkLog.use_default_file_logging()

class MyTextEditor(TTkWindow):
    classStyle = {
                'default':     {'color': TTkColor.RST,
                                'borderColor': TTkColor.fg('#FF0000')},
            }

    def __init__(self, **kwargs):
        TTkUiLoader.loadDict(
            {'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},
            self, kwargs)

root=TTk( title="Test LOGIN!!!" )
MyTextEditor(parent=root)
root.mainloop()

@smartkid2024
Copy link
Author

Also, how can I colorize the title or text in the message box? For example for error message text should be red. I think you wrote docs for yourself it's very brief

You can use the classStyle, this is an alpha feature, It is not properly documented yet because it is still undergoing a review process it may change in the future.

I made an example here: https://gist.github.com/ceccopierangiolieugenio/5e28a0d6f9804533dc6973ce8223976e

tryItOnline

from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout, TTkColor
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot

TTkLog.use_default_file_logging()

class MyTextEditor(TTkWindow):
    classStyle = {
                'default':     {'color': TTkColor.RST,
                                'borderColor': TTkColor.fg('#FF0000')},
            }

    def __init__(self, **kwargs):
        TTkUiLoader.loadDict(
            {'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},
            self, kwargs)

root=TTk( title="Test LOGIN!!!" )
MyTextEditor(parent=root)
root.mainloop()

Thanks
And how can I use it for message box?

@ceccopierangiolieugenio
Copy link
Owner

You can use the setStyle:

from TermTk import TTkButton, TTk, TTkWindow, TTkString, TTkColor, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot

@pyTTkSlot()
def _testMessageBox():
    messageBox = TTkMessageBox(
                    title = "Title",
                    text= "Content",
                    icon=TTkMessageBox.Icon.Warning)
    messageBox.setStyle({
                'default': {'color': TTkColor.RST,
                            'borderColor': TTkColor.fg('#FF0000')}})
    TTkHelper.overlay(None, messageBox, 5, 5, True)


root=TTk()

btn = TTkButton(parent=root, text="Test Messagebox",border=True)
btn.clicked.connect(_testMessageBox)

root.mainloop()

@ceccopierangiolieugenio ceccopierangiolieugenio added the help wanted Extra attention is needed label Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants