Comments (2)
It is not wrong to create multiple widgets and hide/show when required, but I think it would be easier to have multiple widgets and initialize/show them when required otherwise the ttkDesigner definition may become too complex to be handled.
I will try to make an example soon, I am making some changes to the ttkDesigner to improve the usability.
from pytermtk.
I made an example here: https://gist.github.com/ceccopierangiolieugenio/228f35bef315f6b8d34c653317c14aa6
I split the 2 forms in separate widgets and kept the form logic inside the widget itself.
The main window is just responsible of collecting the widgets events and display the different forms.
I added a signal in the IpForm widget that is emitted when the check is performed.
The windows is resposible to dispose it and initialize the new one.
from TermTk import TTkUiLoader, TTk, TTkWindow, TTkContainer, TTkTimer, TTkMessageBox, TTkHelper, TTkGridLayout, TTkString, TTkColor
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSignal, pyTTkSlot
# import logging, jdatetime
from enum import Enum
class msgType(Enum):
ERROR = 1
INFO = 2
MESSAGE = 3
WARNING = 4
class IpForm(TTkContainer):
Def = {'version': '2.0.0', 'tui': {'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': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 57, 18)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'ShowIpLabel', 'Position': [5, 6], 'Size': [15, 1], 'Min Width': 15, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Your Server IP:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'IpFrame', 'Position': [14, 7], 'Size': [29, 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, 27, 1)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'dot1', 'Position': [6, 0], 'Size': [1, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': '.', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLineEdit', 'params': {'Name': 'IpPart2', 'Position': [8, 0], 'Size': [4, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': False, 'ToolTip': '', 'Input Type': 2, 'Text': '168'}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'dot2', 'Position': [13, 0], 'Size': [1, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': '.', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLineEdit', 'params': {'Name': 'IpPart3', 'Position': [15, 0], 'Size': [4, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': False, 'ToolTip': '', 'Input Type': 2, 'Text': '192'}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'dot3', 'Position': [20, 0], 'Size': [1, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': '.', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLineEdit', 'params': {'Name': 'IpPart4', 'Position': [22, 0], 'Size': [4, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': False, 'ToolTip': '', 'Input Type': 2, 'Text': '123'}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLineEdit', 'params': {'Name': 'IpPart1', 'Position': [1, 0], 'Size': [4, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': False, 'ToolTip': '', 'Input Type': 2, 'Text': '192'}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'CheckBtn', 'Position': [21, 10], 'Size': [16, 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': []}
def __init__(self, **kwargs):
self.formChecked = pyTTkSignal()
TTkUiLoader.loadDict(IpForm.Def,self,kwargs)
## Initialize ##
server_ip="192.168.1.1".split(".")
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])
## Triggers ##
self.getWidgetByName('CheckBtn').clicked.connect(self.onCheckBtnClick)
## Event Methods ##
pyTTkSlot()
def onCheckBtnClick(self):
self.getWidgetByName('CheckBtn').setDisabled()
self._stop_progress_bar_thread = False
# The internal TTkTimer can be used instead of the threads to
# keep the threading mechanism more consistent with the library
# And it is compatible with the web exporter
self._timer = TTkTimer()
self._timer.timeout.connect(lambda : self.reProgressBar("CheckBtn","Checking"))
self._timer.start(0.1)
timer = TTkTimer()
timer.timeout.connect(self.checkDone)
timer.start(5)
pyTTkSlot()
def checkDone(self):
self._stop_progress_bar_thread = True
self.formChecked.emit()
_animId = 0
# _animGlyph = ['/','-','\\','|']
_animGlyph = [' ','. ','.. ','... ', '....', ' ...', ' ..', ' .']
def reProgressBar(self,name,text,wait=0.2):
if self._stop_progress_bar_thread:
return
gliph = self._animGlyph[self._animId]
self._animId = (self._animId+1)%len(self._animGlyph)
self.getWidgetByName(name).setText(f"{text} {gliph}")
self._timer.start(wait)
class InfoForm(TTkContainer):
Def = {'version': '2.0.0', 'tui': {'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': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 57, 18)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'ShowIpLabel', 'Position': [9, 1], 'Size': [13, 1], 'Min Width': 13, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Your License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'LicenseFrame', 'Position': [23, 0], 'Size': [24, 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, 22, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'TTkLineEdit', 'Position': [1, 0], 'Size': [35, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': False, 'ToolTip': '', 'Input Type': 1, 'Text': 'M3SHZV8U01GSU7UJ1U5S'}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'KharegIpLabel', 'Position': [12, 3], 'Size': [10, 1], 'Min Width': 10, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Khareg IP:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'KharegIP', 'Position': [24, 3], 'Size': [20, 1], 'Min Width': 11, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': '192.168.1.2', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'KharegPortLabel-2', 'Position': [10, 5], 'Size': [12, 1], 'Min Width': 12, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Khareg Port:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'KharegPort', 'Position': [24, 5], 'Size': [20, 1], 'Min Width': 4, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': '2096', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'IranIpLabel', 'Position': [14, 7], 'Size': [8, 1], 'Min Width': 8, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Iran IP:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'IranIP', 'Position': [24, 7], 'Size': [20, 1], 'Min Width': 11, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': '192.168.0.3', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'IranPortLabel', 'Position': [12, 9], 'Size': [10, 1], 'Min Width': 10, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Iran Port:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'IranPort', 'Position': [24, 9], 'Size': [20, 1], 'Min Width': 4, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': '8800', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'EmailLable', 'Position': [11, 11], 'Size': [11, 1], 'Min Width': 11, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Your Email:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLabel', 'params': {'Name': 'Email', 'Position': [24, 11], 'Size': [26, 1], 'Min Width': 14, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': '[email protected]', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'CheckInfoBtn', 'Position': [18, 13], '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': []}
def __init__(self, **kwargs):
TTkUiLoader.loadDict(InfoForm.Def,self,kwargs)
class MyCheckLicense(TTkWindow):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._ipForm = IpForm(pos=(0,0))
self.showForm(self._ipForm)
self._ipForm.formChecked.connect(self._ipFormChecked)
def showForm(self, form):
w,h = form.size()
# I resize the widget considering the window borders
self.resize(w+2,h+4)
self.layout().addWidget(form)
pyTTkSlot()
def _ipFormChecked(self):
# To avoid unused references I ensure to clear
# all the slots connections of the objects disposed/closed
self._ipForm.formChecked.disconnect(self._ipFormChecked)
self._ipForm.close()
self._infoForm = InfoForm(pos=(0,0))
self.showForm(self._infoForm)
root = TTk(title="Check License")
# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30, 10), size=(100, 20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)
MyCheckLicense(parent=root, pos=(0,0), size=(60,22), title="Check License")
root.mainloop()
from pytermtk.
Related Issues (20)
- Add FusionCharts widget
- Fields Configurable in File Tree
- Copy disabled in new version of ttkDesigner==0.37.0a36 HOT 5
- How to set custom event for close icon on window HOT 5
- How can i set position message box on center of window? HOT 1
- Save as doesn't change file to the new file in TTk Designer HOT 7
- Add Undo/Redo in ttkDesigner
- Error when loading .tui.json file in ttkdesigner HOT 2
- ttkDesigner - Ask to save when exit or open a new file (and clear the clipboard)
- ttkDesigner - Implement a widgets clipboard
- Error: Pyperclip could not find a copy/paste mechanism for your system. HOT 5
- Clean the out buffer before releasing the main loop after quit.
- Missing DataTable HOT 2
- Support copykitten as clipboard manager
- Bracketed paste does not works on the web exporter
- Clipboard support in the webExporter
- Add UI file save signature to avoid to import the wrong json
- Add Slider Widget
- TreeWidget: Add resize column api
- TextEdit,LineEdit Return False for unhandled keypresses
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytermtk.