diff --git a/TermTk/TTkAbstract/__init__.py b/TermTk/TTkAbstract/__init__.py index 5828fbe3..efa544d5 100644 --- a/TermTk/TTkAbstract/__init__.py +++ b/TermTk/TTkAbstract/__init__.py @@ -1 +1,2 @@ from .abstractscrollarea import * +from .abstractitemmodel import * diff --git a/TermTk/TTkAbstract/abstractitemmodel.py b/TermTk/TTkAbstract/abstractitemmodel.py new file mode 100644 index 00000000..550d84eb --- /dev/null +++ b/TermTk/TTkAbstract/abstractitemmodel.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +class TTkAbstractItemModel(): + def __init__(self, *args, **kwargs): + pass \ No newline at end of file diff --git a/TermTk/TTkAbstract/abstractscrollarea.py b/TermTk/TTkAbstract/abstractscrollarea.py index 6b1ddc61..cbff51f5 100644 --- a/TermTk/TTkAbstract/abstractscrollarea.py +++ b/TermTk/TTkAbstract/abstractscrollarea.py @@ -48,13 +48,17 @@ class TTkAbstractScrollArea(TTkWidget): @pyTTkSlot() def _viewportChanged(self): + if not self.isVisible(): return fw, fh = self._viewport.viewFullAreaSize() dw, dh = self._viewport.viewDisplayedSize() ox, oy = self._viewport.getViewOffsets() + if fw==0 or fh==0 or dw==0 or dh==0: + return hpage = dw vpage = dh hrange = fw - dw vrange = fh - dh + # TTkLog.debug(f"f:{fw,fh}, d:{dw,dh}, o:{ox,oy}") self._verticalScrollBar.setPageStep(vpage) self._verticalScrollBar.setRange(0, vrange) self._verticalScrollBar.setValue(oy) diff --git a/TermTk/TTkCore/canvas.py b/TermTk/TTkCore/canvas.py index 3468a06a..3421d8b2 100644 --- a/TermTk/TTkCore/canvas.py +++ b/TermTk/TTkCore/canvas.py @@ -200,8 +200,8 @@ class TTkCanvas: - def drawBox(self, pos, size, color=TTkColor.RST): - self.drawGrid(pos=pos, size=size, color=color) + def drawBox(self, pos, size, color=TTkColor.RST, grid=0): + self.drawGrid(pos=pos, size=size, color=color, grid=grid) def drawButtonBox(self, pos, size, color=TTkColor.RST, grid=0): if not self._visible: return @@ -228,42 +228,44 @@ class TTkCanvas: w,h = size gg = TTkCfg.theme.grid[grid] # 4 corners - self._set(y, x, gg[2], color) - self._set(y, x+w-1, gg[3], color) - self._set(y+h-1, x, gg[4], color) - self._set(y+h-1, x+w-1, gg[5], color) + self._set(y, x, gg[0x00], color) + self._set(y, x+w-1, gg[0x03], color) + self._set(y+h-1, x, gg[0x0C], color) + self._set(y+h-1, x+w-1, gg[0x0F], color) if w > 2: + # Top/Bottom Line for i in range(x+1,x+w-1): - self._set(y, i, gg[0], color) - self._set(y+h-1, i, gg[0], color) + self._set(y, i, gg[0x01], color) + self._set(y+h-1, i, gg[0x0D], color) if h > 2: + # Left/Right Line for i in range(y+1,y+h-1): - self._set(i, x, gg[1], color) - self._set(i, x+w-1, gg[1], color) + self._set(i, x, gg[0x04], color) + self._set(i, x+w-1, gg[0x07], color) # Draw horizontal lines for iy in hlines: iy += y if not (0 < iy < h): continue - self._set(iy, x, gg[6], color) - self._set(iy, x+w-1, gg[7], color) + self._set(iy, x, gg[0x08], color) + self._set(iy, x+w-1, gg[0x0B], color) if w > 2: for ix in range(x+1,x+w-1): - self._set(iy, ix, gg[10], color) + self._set(iy, ix, gg[0x09], color) # Draw vertical lines for ix in vlines: ix+=x if not (0 < ix < w): continue - self._set(y, ix, gg[8], color) - self._set(y+h-1, ix, gg[9], color) + self._set(y, ix, gg[0x02], color) + self._set(y+h-1, ix, gg[0x0E], color) if h > 2: for iy in range(y+1,y+h-1): - self._set(iy, ix, gg[11], color) + self._set(iy, ix, gg[0x06], color) # Draw intersections for iy in hlines: for ix in vlines: - self._set(y+iy, x+ix, gg[12], color) + self._set(y+iy, x+ix, gg[0x0A], color) - def drawScroll(self, pos, size, slider, orientation, color): + def drawScroll(self, pos, size, slider, orientation, color=TTkColor.RST): if not self._visible: return x,y = pos f,t = slider # slider from-to position @@ -281,9 +283,61 @@ class TTkCanvas: self._set(y+i,x, TTkCfg.theme.vscroll[2], color) self._set(y,x, TTkCfg.theme.vscroll[0], color) # Up Arrow self._set(y+size-1,x, TTkCfg.theme.vscroll[3], color) # Down Arrow - pass + def drawTab( + self, pos, size, + labels, labelsPos, selected, + offset, leftScroller, rightScroller, + color=TTkColor.RST, borderColor=TTkColor.RST, selectColor=TTkColor.RST): + x,y = pos + w,h = size + tt = TTkCfg.theme.tab + # phase 0 - Draw the Bottom bar + bottomBar = tt[11]+tt[12]*(w-2)+tt[15] + self.drawText(pos=(x,y+2),text=bottomBar) + # phase 1 - Draw From left to 'Selected' + # phase 2 - Draw From right to 'Selected' + def _drawTab(x,y,a,b,c,d,e,f,g,h,txt,txtColor,borderColor): + text = labels[i] + posx = labelsPos[i] + lentext = len(txt) + top = a+b*lentext+c + center = d+txt+e + bottom = f+g*(lentext)+h + self.drawText(pos=(x,y+0),text=top, color=borderColor) + self.drawText(pos=(x,y+1),text=center, color=borderColor) + self.drawText(pos=(x+1,y+1),text=txt, color=txtColor) + self.drawText(pos=(x,y+2),text=bottom, color=borderColor) + + for i in list( range(offset )) + \ + list(reversed(range(offset+1, len(labels)) )): + text = labels[i] + posx = labelsPos[i] + _drawTab(x+posx, y, tt[0], tt[1], tt[3], tt[9], tt[9], tt[12], tt[12], tt[12], text, color, borderColor) + # phase 3 - Draw 'Selected' + if selected != -1: + i = selected + text = labels[i] + posx = labelsPos[i] + _drawTab(x+posx, y, tt[4], tt[5], tt[6], tt[10], tt[10], tt[14], tt[12], tt[14], text, selectColor, borderColor) + if selected != offset: + i = offset + text = labels[i] + posx = labelsPos[i] + _drawTab(x+posx, y, tt[0], tt[1], tt[3], tt[9], tt[9], tt[12], tt[12], tt[12], text, color, borderColor) + # phase 4 - Draw left right tilt + if leftScroller: + top = tt[7]+tt[1] + center = tt[9]+tt[16] + self.drawText(pos=(x,y+0),text=top, color=borderColor) + self.drawText(pos=(x,y+1),text=center, color=borderColor) + if rightScroller: + top = tt[1]+tt[8] + center = tt[17]+tt[9] + self.drawText(pos=(x+w-2,y+0),text=top, color=borderColor) + self.drawText(pos=(x+w-2,y+1),text=center, color=borderColor) + def execPaint(self, winw, winh): pass diff --git a/TermTk/TTkCore/ttk.py b/TermTk/TTkCore/ttk.py index 85996f0a..871069a4 100644 --- a/TermTk/TTkCore/ttk.py +++ b/TermTk/TTkCore/ttk.py @@ -100,6 +100,7 @@ class TTk(TTkWidget): self._timerEvent.set() self._timer = TTkTimer(self._time_event, 0.03, self._timerEvent) self._timer.start() + self.show() self.running = True lbt.Term.init() diff --git a/TermTk/TTkGui/theme.py b/TermTk/TTkGui/theme.py index f71cc1bc..79df066c 100644 --- a/TermTk/TTkGui/theme.py +++ b/TermTk/TTkGui/theme.py @@ -52,29 +52,55 @@ class TTkTheme(): │ ││ ║ ║║ ║ │║ │ ║│ ├─┼┤ ╠═╬╣ ╟─┼╢ ╞═╬╡ └─┴┘ ╚═╩╝ ╚═╧╝ └─╨┘ - grid4 grid5 grid6 grid7 grid8 - ╓─╥╖ ╒═╤╕ ╓─┬┐ ┌─┬╖ ┌─┬┐ - ║ ║║ │ ││ ║ ││ │ │║ │ ││ - ╟─╫╢ ╞═╪╡ ╟─┼┤ ├─┼╢ ├─┼┤ - ╙─╨╜ ╘═╧╛ ╚═╧╛ ╘═╧╝ ╘═╧╛ + grid4 grid5 grid6 grid7 grid8 grid9 + ╓─╥╖ ╒═╤╕ ╓─┬┐ ┌─┬╖ ┌─┬┐ ╒═╤╕ + ║ ║║ │ ││ ║ ││ │ │║ │ ││ │ ││ + ╟─╫╢ ╞═╪╡ ╟─┼┤ ├─┼╢ ├─┼┤ ├─┼┤ + ╙─╨╜ ╘═╧╛ ╚═╧╛ ╘═╧╝ ╘═╧╛ └─┴┘ + + ids (hex): + 0 1 2 3 + ┌ ─ ┬ ┐ + 4 5 6 7 + │ │ │ + 8 9 A B + ├ ─ ┼ ┤ + C D E F + └ ─ ┴ ┘ ''' grid = ( - ( '─','│', # Grid 0 - '┌','┐','└','┘', - '├','┤','┬','┴', - '─','│','┼',), - ( '═','║', # Grid 1 - '╔','╗','╚','╝', - '╠','╣','╦','╩', - '═','║','╬',), - ( '═','║', # Grid 2 - '╔','╗','╚','╝', - '╟','╢','╤','╧', - '─','│','┼',), - ( '─','│', # Grid 3 - '┌','┐','└','┘', - '╞','╡','╥','╨', - '═','║','╬',)) + ( # Grid 0 + '┌','─','┬','┐', + '│',' ','│','│', + '├','─','┼','┤', + '└','─','┴','┘'), + ( # Grid 1 + '╔','═','╦','╗', + '║',' ','║','║', + '╠','═','╬','╣', + '╚','═','╩','╝'), + ( # Grid 2 + '╔','═','╤','╗', + '║',' ','│','║', + '╟','─','┼','╢', + '╚','═','╧','╝'), + ( # Grid 3 + '┌','─','╥','┐', + '│',' ','║','│', + '╞','═','╬','╡', + '└','─','╨','┘'), + (), # TODO: Grid 4 + (), # TODO: Grid 5 + (), # TODO: Grid 6 + (), # TODO: Grid 7 + (), # TODO: Grid 8 + ( # Grid 9 ╒═╤╕ + '╒','═','╤','╕', + '│',' ','│','│', + '├','─','┼','┤', + '└','─','┴','┘'), + (), # TODO: Grid 10 + ) ''' box0 box1 @@ -93,6 +119,28 @@ class TTkTheme(): hscroll = ('◀','┄','▓','▶') vscroll = ('▲','┊','▓','▼') + ''' + ┌──────╔══════╗──────┬──────┐ ┌─┌──────╔══════╗──────┬──────┐─┐ + │Label1║Label2║Label3│Label4│ │◀│Label1║Label2║Label3│Label4│▶│ + ╞═╧══════╩══════╩══════╧══════╧════╡ ╞═╧══════╩══════╩══════╧══════╧═╡ + ┌──────╔══════╗──────┬──────┐ ╭─┌──────╔══════╗──────┬──────┐─╮ + │Label1║Label2║Label3│Label4│ │◀│Label1║Label2║Label3│Label4│▶│ + ╞════════╩══════╩══════════════════╡ ╞════════╩══════╩═══════════════╡ + ┌──────┲━━━━━━┱──────┬──────┐ + │Label1┃Label2┃Label3│Label4│ + ┝━┷━━━━━━┻━━━━━━┻━━━━━━┷━━━━━━┷━━━━┥ + ''' + tab = ( + #0 1 2 3 4 5 6 7 8 + '┌','─','┬','┐','╔','═','╗','╭','╮', + #9 10 + '│','║', + #11 12 13 14 15 + '╞','═','╧','╩','╡', + #16 17 + '◀','▶' + ) + frameBorderColor = TTkColor.RST frameTitleColor = TTkColor.fg("#dddddd")+TTkColor.bg("#222222") @@ -120,4 +168,8 @@ class TTkTheme(): radioButtonContentColor = buttonTextColor radioButtonBorderColor = buttonBorderColor radioButtonContentColorFocus = buttonTextColorFocus - radioButtonBorderColorFocus = buttonBorderColorFocus \ No newline at end of file + radioButtonBorderColorFocus = buttonBorderColorFocus + + tabColor = TTkColor.fg("#aaaaaa") + tabBorderColor = frameBorderColor + tabSelectColor = TTkColor.fg("#ffff88")+TTkColor.bg("#000066")+TTkColor.BOLD \ No newline at end of file diff --git a/TermTk/TTkWidgets/__init__.py b/TermTk/TTkWidgets/__init__.py index a4d70c46..0d225434 100644 --- a/TermTk/TTkWidgets/__init__.py +++ b/TermTk/TTkWidgets/__init__.py @@ -12,6 +12,7 @@ from .lineedit import * from .texedit import * from .scrollbar import * from .window import * +from .tabwidget import * from .table import * from .tableview import * from .tree import * diff --git a/TermTk/TTkWidgets/filetree.py b/TermTk/TTkWidgets/filetree.py new file mode 100644 index 00000000..e69de29b diff --git a/TermTk/TTkWidgets/frame.py b/TermTk/TTkWidgets/frame.py index 4bc42091..cedd06cb 100644 --- a/TermTk/TTkWidgets/frame.py +++ b/TermTk/TTkWidgets/frame.py @@ -42,6 +42,9 @@ class TTkFrame(TTkWidget): if border: self.setPadding(1,1,1,1) else: self.setPadding(0,0,0,0) + def border(self): + return self._border + def paintEvent(self): if self._border: self._canvas.drawBox(pos=(0,0),size=(self._width,self._height), color=self._borderColor) diff --git a/TermTk/TTkWidgets/tabwidget.py b/TermTk/TTkWidgets/tabwidget.py new file mode 100644 index 00000000..f1f85003 --- /dev/null +++ b/TermTk/TTkWidgets/tabwidget.py @@ -0,0 +1,174 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from TermTk.TTkCore.constant import TTkConstant, TTkK +from TermTk.TTkCore.log import TTkLog +from TermTk.TTkCore.cfg import * +from TermTk.TTkCore.signal import pyTTkSlot, pyTTkSignal +from TermTk.TTkWidgets.widget import TTkWidget +from TermTk.TTkWidgets.spacer import TTkSpacer +from TermTk.TTkWidgets.frame import TTkFrame +from TermTk.TTkLayouts.gridlayout import TTkGridLayout + + +''' +_curentIndex = 2 +_labelPos = [0],[1], [2], [3], [4], + ╭─┌──┌──────╔══════╗──────┬──────┐─╮ +_labels= │◀│La│Label1║Label2║Label3│Label4│▶│ + ╞═══════════╩══════╩═══════════════╡ + leftscroller rightScroller +''' +class TTkTabWidget(TTkFrame): + __slots__ = ( + '_viewport', + '_tabColor', '_tabBorderColor', '_tabSelectColor', + '_tabWidgets', '_labels', '_labelsPos', + '_offset', '_currentIndex', + '_leftScroller', '_rightScroller', + '_tabMovable', '_tabClosable') + + def __init__(self, *args, **kwargs): + self._tabWidgets = [] + self._labels = [] + self._labelsPos = [] + self._currentIndex = 0 + self._offset = 0 + self._tabMovable = False + self._tabClosable = False + self._leftScroller = False + self._rightScroller = False + self._tabColor = TTkCfg.theme.tabColor + self._tabBorderColor = TTkCfg.theme.tabBorderColor + self._tabSelectColor = TTkCfg.theme.tabSelectColor + super().__init__(self, *args, **kwargs) + self._name = kwargs.get('name' , 'TTkTabWidget') + self.setLayout(TTkGridLayout()) + self._viewport = TTkWidget(layout=TTkGridLayout()) + self.layout().addWidget(self._viewport,0,0) + #self.layout().addWidget(TTkSpacer(),0,1) + #self.layout().addWidget(TTkSpacer(),1,0) + + + if self.border(): + self.setPadding(3,1,1,1) + else: + self.setPadding(3,0,0,0) + self.setFocusPolicy(TTkK.ClickFocus) + + + def addTab(self, widget, label): + widget.hide() + self._tabWidgets.append(widget) + self._labels.append(label) + self._viewport.addWidget(widget) + self._updateTabs() + + def insertTab(self, index, widget, label): + widget.hide() + self._tabWidgets.insert(index, widget) + self._labels.insert(index, label) + self._viewport.addWidget(widget) + self._updateTabs() + + def _updateTabs(self): + xpos = 0+2 + w = self.width()-4 + self._labelsPos = [] + self._leftScroller = False + self._rightScroller = False + minLabelLen = 0 + for label in self._labels: + labelLen = len(label) + if xpos+labelLen > w: + xpos = w-labelLen + self._leftScroller = True + self._rightScroller = True + self._labelsPos.append(xpos) + xpos += labelLen+1 + if minLabelLen < labelLen: + minLabelLen = labelLen + self.setMinimumWidth(minLabelLen+2+4) + + for i, widget in enumerate(self._tabWidgets): + if self._currentIndex == i: + widget.show() + else: + widget.hide() + self.update() + + def resizeEvent(self, w, h): + self._updateTabs() + + def mousePressEvent(self, evt): + x,y = evt.x, evt.y + w = self.width() + offset = self._offset + if y>2: return False + # Check from the selected to the left and from selected+1 to the right + if self._leftScroller and x<2 and offset>0: + self._offset -= 1 + self._updateTabs() + return True + if self._rightScroller and x>w-3 and offset2: return False + if evt.evt == TTkK.WHEEL_Down: + if self._currentIndex < len(self._labels)-1: + self._currentIndex += 1 + else: + if self._currentIndex > 0: + self._currentIndex -= 1 + self._offset = self._currentIndex + self._updateTabs() + return True + + def paintEvent(self): + if self.border(): + self._canvas.drawBox(pos=(0,2),size=(self._width,self._height-2), color=self._borderColor, grid=9) + self._canvas.drawTab( + pos=(0,0), size=self.size(), + labels=self._labels, labelsPos=self._labelsPos, + selected=self._currentIndex, offset=self._offset, + leftScroller=self._leftScroller, rightScroller=self._rightScroller, + color=self._tabColor, borderColor=self._tabBorderColor, selectColor=self._tabSelectColor) + diff --git a/TermTk/TTkWidgets/widget.py b/TermTk/TTkWidgets/widget.py index 54edaef0..630d33a4 100644 --- a/TermTk/TTkWidgets/widget.py +++ b/TermTk/TTkWidgets/widget.py @@ -101,6 +101,7 @@ class TTkWidget: if self._layout is not None: self._layout.addWidget(widget) self.update(repaint=True, updateLayout=True) + # widget.show() def removeWidget(self, widget): if self._layout is not None: diff --git a/tests/showcase/formwidgets.py b/tests/showcase/formwidgets.py new file mode 100755 index 00000000..007d1d90 --- /dev/null +++ b/tests/showcase/formwidgets.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os +import random + +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + +words = ["Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", "commodo", "consequat.", "Duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint", "occaecat", "cupidatat", "non", "proident,", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum."] +def getWord(): + return random.choice(words) +def getSentence(a,b): + return " ".join([getWord() for i in range(0,random.randint(a,b))]) + +def demoFormWidgets(root=None): + win_form1_grid_layout = ttk.TTkGridLayout(columnMinWidth=1) + frame = ttk.TTkFrame(parent=root, layout=win_form1_grid_layout, border=0) + + win_form1_grid_layout.addWidget(ttk.TTkButton(text='Button 1'),0,0) + win_form1_grid_layout.addWidget(ttk.TTkButton(text='Button 2'),1,0) + win_form1_grid_layout.addWidget(ttk.TTkButton(text='Button 3'),0,2) + win_form1_grid_layout.addWidget(ttk.TTkButton(text='Button 4'),1,2) + row = 2 + + row +=1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Combo Box'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkComboBox(list=['One','Two','Some Long Sentence That Is Not a Written Number','Three']),row,2) + row +=1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Combo long Box'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkComboBox(list=[getSentence(1,4) for i in range(100)]),row,2) + + + row +=1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 1'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 1'),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 2'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 2'),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 3'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 3'),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 4'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 4'),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Test 5'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Line Edit Test 5'),row,2) + + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Input Number'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='123456', inputType=ttk.TTkK.Input_Number),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Input Wrong Number'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='No num Text', inputType=ttk.TTkK.Input_Number),row,2) + + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Input Password'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Password', inputType=ttk.TTkK.Input_Password),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Line Edit Number Password'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkLineEdit(text='Password', inputType=ttk.TTkK.Input_Password+ttk.TTkK.Input_Number),row,2) + + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Checkbox'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkCheckbox(),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Checkbox Checked'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkCheckbox(checked=True),row,2) + + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Default)'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkRadioButton(),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Default)'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkRadioButton(),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Default)'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkRadioButton(),row,2) + + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name One)'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name One"),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name One)'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name One"),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name Two)'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name Two"),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name One)'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name One"),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkLabel(text='Radio Button (Name Two)'),row,0) + win_form1_grid_layout.addWidget(ttk.TTkRadioButton(name="Name Two"),row,2) + row += 1; win_form1_grid_layout.addWidget(ttk.TTkSpacer(),row,0) + return frame + + +def main(): + ttk.TTkLog.use_default_file_logging() + + root = ttk.TTk() + winForm = ttk.TTkWindow(parent=root,pos=(1,1), size=(60,40), title="Test Window 1", layout=ttk.TTkVBoxLayout(), border=True) + demoFormWidgets(winForm) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/showcase/layout.py b/tests/showcase/layout.py new file mode 100755 index 00000000..a92de8f4 --- /dev/null +++ b/tests/showcase/layout.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os + +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + + +def demoLayout(root=None): + rightframe = ttk.TTkFrame(parent=root, border=True, title="V Box Layout", titleColor=ttk.TTkColor.BOLD+ttk.TTkColor.fg('#8888dd')) + rightframe.setLayout(ttk.TTkVBoxLayout()) + + gridFrame = ttk.TTkFrame(parent=rightframe, border=True, title="Grid Layout", titleColor=ttk.TTkColor.fg('#88dd88')) + gridFrame.setLayout(ttk.TTkGridLayout()) + ttk.TTkButton(parent=gridFrame, border=True, text="Button1") + ttk.TTkButton(parent=gridFrame, border=True, text="Button2") + gridFrame.layout().addWidget(ttk.TTkButton(border=True, text="Button (1,0)"),1,0) + ttk.TTkButton(parent=gridFrame, border=True, text="Button4") + gridFrame.layout().addWidget(ttk.TTkButton(border=True, text="Button (0,3)"),0,3) + gridFrame.layout().addWidget(ttk.TTkButton(border=True, text="Button (1,2)"),1,2) + # Test (add a widget to the same parent with a different layout params than the default) + gridFrame.layout().addWidget(ttk.TTkButton(parent=gridFrame, border=True, text="Button (2,1)"),2,1) + gridFrame.layout().addWidget(ttk.TTkButton(border=True, text="Button (5,5)"),5,5) + + gridFrame.layout().addWidget(ttk.TTkFrame(border=True,title="Frame1"),0,5) + gridFrame.layout().addWidget(ttk.TTkFrame(border=True,title="Frame2"),2,3) + gridFrame.layout().addWidget(ttk.TTkFrame(border=True,title="Frame3"),5,3) + gridFrame.layout().addWidget(ttk.TTkFrame(border=True,title="Frame4"),5,1) + + + centerrightframe=ttk.TTkFrame(parent=rightframe, border=True, title="H Box Layout", titleColor=ttk.TTkColor.fg('#dd88dd')) + centerrightframe.setLayout(ttk.TTkHBoxLayout()) + ttk.TTkTestWidget(parent=rightframe, border=True, title="Test Widget", titleColor=ttk.TTkColor.fg('#dddddd')) + + + smallframe = ttk.TTkFrame(parent=centerrightframe, border=True) + # smallframe.setLayout(ttk.TTkVBoxLayout()) + ttk.TTkTestWidget(parent=centerrightframe, border=True) + ttk.TTkFrame(parent=centerrightframe, border=True) + + ttk.TTkButton(parent=smallframe, x=3, y=1, width=20, height=1, text=" Ui.003 Button") + ttk.TTkTestWidget(parent=smallframe, x=3, y=2, width=50, height=8, border=True) + ttk.TTkTestWidget(parent=smallframe, x=-5, y=12, width=50, height=15, border=True) + return rightframe + + + + +def main(): + ttk.TTkLog.use_default_file_logging() + + root = ttk.TTk() + root.setLayout(ttk.TTkHBoxLayout()) + demoLayout(root) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/showcase/splitter.py b/tests/showcase/splitter.py new file mode 100755 index 00000000..a4b6412b --- /dev/null +++ b/tests/showcase/splitter.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os + +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + + +def demoSplitter(root=None): + vsplitter = ttk.TTkSplitter(parent=root, orientation=ttk.TTkK.VERTICAL) + ttk.TTkTestWidgetSizes(parent=vsplitter ,border=True, title="Frame1.1") + hsplitter = ttk.TTkSplitter(parent=vsplitter) + ttk.TTkTestWidgetSizes(parent=vsplitter ,border=True, title="Frame1.2") + ttk.TTkTestWidgetSizes(parent=vsplitter ,border=True, title="Frame1.3") + ttk.TTkTestWidgetSizes(parent=hsplitter ,border=True, title="Frame3") + ttk.TTkTestWidgetSizes(parent=hsplitter ,border=True, title="Frame2", minSize=(33,7), maxSize=(33,7)) + ttk.TTkTestWidgetSizes(parent=hsplitter ,border=True, title="Frame4") + return vsplitter + + + +def main(): + ttk.TTkLog.use_default_file_logging() + + root = ttk.TTk() + winSplitter = ttk.TTkWindow(parent=root,pos = (10,5), size=(100,40), title="Test Splitter", border=True, layout=ttk.TTkGridLayout()) + demoSplitter(winSplitter) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/showcase/tab.py b/tests/showcase/tab.py new file mode 100755 index 00000000..dcd92da7 --- /dev/null +++ b/tests/showcase/tab.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os + +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + +ttk.TTkLog.use_default_file_logging() + +root = ttk.TTk() + +def demoTab(root= None): + tabWidget1 = ttk.TTkTabWidget(parent=root, border=True) + tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.1"), "Label 1.1") + tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.2"), "Label 1.2") + tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.3"), "Label Test 1.3") + tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.4"), "Label 1.4") + tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.5"), "Label Test 1.5") + tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.6"), "Label 1.6") + return tabWidget1 + +def main(): + ttk.TTkLog.use_default_file_logging() + + fullscreen = False + + root = ttk.TTk() + if fullscreen: + rootTab = root + root.setLayout(ttk.TTkGridLayout()) + else: + rootTab = ttk.TTkWindow(parent=root,pos=(1,1), size=(100,40), title="Test Tab", border=True, layout=ttk.TTkGridLayout()) + demoTab(rootTab) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/showcase/table.py b/tests/showcase/table.py new file mode 100755 index 00000000..91585c04 --- /dev/null +++ b/tests/showcase/table.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os +import random + +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + +words = ["Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", "commodo", "consequat.", "Duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint", "occaecat", "cupidatat", "non", "proident,", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum."] +def getWord(): + return random.choice(words) +def getSentence(a,b): + return " ".join([getWord() for i in range(0,random.randint(a,b))]) + +table_ii = 1000 + +def demoTable(root=None): + frame = ttk.TTkFrame(parent=root, border=False, layout=ttk.TTkVBoxLayout()) + top = ttk.TTkFrame(parent=frame, border=False, layout=ttk.TTkHBoxLayout()) + btn1 = ttk.TTkButton(parent=top, maxHeight=3, border=True, text='Add') + btn2 = ttk.TTkButton(parent=top, maxHeight=3, border=True, text='Add Many') + + table1 = ttk.TTkTable(parent=frame, selectColor=ttk.TTkColor.bg('#882200')) + + table1.setColumnSize((5,10,-1,10,20)) + table1.setAlignment(( + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.RIGHT_ALIGN, + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.LEFT_ALIGN, + ttk.TTkK.CENTER_ALIGN + )) + table1.setHeader(("id","Name","Sentence","Word","center")) + table1.setColumnColors(( + ttk.TTkColor.fg('#888800', modifier=ttk.TTkColorGradient(increment=6)), + ttk.TTkColor.RST, + ttk.TTkColor.fg('#00dddd', modifier=ttk.TTkColorGradient(increment=-4)), + ttk.TTkColor.RST, + ttk.TTkColor.fg('#cccccc', modifier=ttk.TTkColorGradient(increment=-2)) + )) + table1.appendItem((" - ","","You see it's all clear, You were meant to be here, From the beginning","","")) + for i in range(0, 5): + table1.appendItem((str(i), getWord(), getSentence(8,30), getWord(), getWord())) + table1.appendItem((" - ","This is the end", "Beautiful friend, This is the end My only friend", "the end", "...")) + + # Attach the add Event + + def add(): + global table_ii + table_ii+=1 + table1.appendItem((str(table_ii), getWord(), getSentence(8,30), getWord(), getWord())) + btn1.clicked.connect(add) + + def addMany(): + global table_ii + for i in range(0, 500): + table_ii+=1 + table1.appendItem((str(table_ii), getWord(), getSentence(8,30), getWord(), getWord())) + table1.appendItem((" - ","This is the end", "Beautiful friend, This is the end My only friend", "the end", "...")) + btn2.clicked.connect(addMany) + + return frame + +def main(): + ttk.TTkLog.use_default_file_logging() + + root = ttk.TTk() + win_table = ttk.TTkWindow(parent=root,pos = (3,3), size=(150,40), title="Test Table 1", layout=ttk.TTkHBoxLayout(), border=True) + demoTable(win_table) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/showcase/tree.py b/tests/showcase/tree.py new file mode 100755 index 00000000..b03cbd42 --- /dev/null +++ b/tests/showcase/tree.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# Demo inspired from: +# https://stackoverflow.com/questions/41204234/python-pyqt5-qtreewidget-sub-item + +import os +import sys + +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + +ttk.TTkLog.use_default_file_logging() + +def demoTree(root=None): + # tw = ttk.TTkTreeWidget(parent=rootTree1) + tw = ttk.TTkTree(parent=root) + tw.setHeaderLabels(["Column 1", "Column 2", "Column 3"]) + tw.setColumnSize((20,20,-1)) + tw.setColumnColors(( + ttk.TTkColor.RST, + ttk.TTkColor.fg('#00dddd', modifier=ttk.TTkColorGradient(increment=-4)), + ttk.TTkColor.fg('#cccc00', modifier=ttk.TTkColorGradient(increment=-2)) + )) + l1 = ttk.TTkTreeWidgetItem(["String A", "String B", "String C"]) + l2 = ttk.TTkTreeWidgetItem(["String AA", "String BB", "String CC"]) + l3 = ttk.TTkTreeWidgetItem(["String AAA", "String BBB", "String CCC"]) + l4 = ttk.TTkTreeWidgetItem(["String AAAA", "String BBBB", "String CCCC"]) + l5 = ttk.TTkTreeWidgetItem(["String AAAAA", "String BBBBB", "String CCCCC"]) + l2.addChild(l5) + + + for i in range(3): + l1_child = ttk.TTkTreeWidgetItem(["Child A" + str(i), "Child B" + str(i), "Child C" + str(i)]) + l1.addChild(l1_child) + + for j in range(2): + l2_child = ttk.TTkTreeWidgetItem(["Child AA" + str(j), "Child BB" + str(j), "Child CC" + str(j)]) + l2.addChild(l2_child) + + for j in range(2): + l3_child = ttk.TTkTreeWidgetItem(["Child AAA" + str(j), "Child BBB" + str(j), "Child CCC" + str(j)]) + l3.addChild(l3_child) + + for j in range(2): + l4_child = ttk.TTkTreeWidgetItem(["Child AAAA" + str(j), "Child BBBB" + str(j), "Child CCCC" + str(j)]) + l4.addChild(l4_child) + + for j in range(2): + l5_child = ttk.TTkTreeWidgetItem(["Child AAAAA" + str(j), "Child BBBBB" + str(j), "Child CCCCC" + str(j)]) + l5.addChild(l5_child) + + + tw.addTopLevelItem(l1) + tw.addTopLevelItem(l2) + tw.addTopLevelItem(l3) + tw.addTopLevelItem(l4) + return tw + + +def main(): + ttk.TTkLog.use_default_file_logging() + + fullscreen = False + + root = ttk.TTk() + if fullscreen: + rootTree1 = root + root.setLayout(ttk.TTkGridLayout()) + else: + rootTree1 = ttk.TTkWindow(parent=root,pos = (0,0), size=(150,50), title="Test Tree 1", layout=ttk.TTkGridLayout(), border=True) + demoTree(rootTree1) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/showcase/windows.py b/tests/showcase/windows.py new file mode 100755 index 00000000..b2116e67 --- /dev/null +++ b/tests/showcase/windows.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os + +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + + +def demoWindows(root=None): + frame = ttk.TTkFrame(parent=root, border=False) + + win2_1 = ttk.TTkWindow(parent=frame,pos = (3,3), size=(40,20), title="Test Window 2.1", border=True) + win2_1.setLayout(ttk.TTkHBoxLayout()) + ttk.TTkTestWidget(parent=win2_1, border=False) + + win2_2 = ttk.TTkWindow(parent=frame,pos = (5,5), size=(40,20), title="Test Window 2.2", border=True) + win2_2.setLayout(ttk.TTkHBoxLayout()) + ttk.TTkTestWidget(parent=win2_2, border=False) + return frame + + + +def main(): + ttk.TTkLog.use_default_file_logging() + root = ttk.TTk() + win1 = ttk.TTkWindow(parent=root,pos = (1,1), size=(60,30), title="Test Window 1", border=True, layout=ttk.TTkGridLayout()) + demoWindows(win1) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/test.showcase.001.py b/tests/test.showcase.001.py index 6bede6d8..76bc7fd6 100755 --- a/tests/test.showcase.001.py +++ b/tests/test.showcase.001.py @@ -28,104 +28,36 @@ import random sys.path.append(os.path.join(sys.path[0],'..')) import TermTk as ttk +from showcase.layout import demoLayout +from showcase.table import demoTable +from showcase.tab import demoTab +from showcase.tree import demoTree +from showcase.splitter import demoSplitter +from showcase.windows import demoWindows +from showcase.formwidgets import demoFormWidgets - -ttk.TTkLog.use_default_file_logging() - -root = ttk.TTk() - -btn1 = ttk.TTkButton(parent=root, pos=(0,0), size=(5,3), border=True, text='On') -btn2 = ttk.TTkButton(parent=root, pos=(5,0), size=(5,3), border=True, text='Off') -btn3 = ttk.TTkButton(parent=root, pos=(0,3), size=(5,3), border=True, text='On') -btn4 = ttk.TTkButton(parent=root, pos=(5,3), size=(5,3), border=True, text='Off') -btn5 = ttk.TTkButton(parent=root, pos=(0,6), size=(5,3), border=True, text='On') -btn6 = ttk.TTkButton(parent=root, pos=(5,6), size=(5,3), border=True, text='Off') -ttk.TTkLabel(parent=root, pos=(10,1), text='zOrder and max/min size') -ttk.TTkLabel(parent=root, pos=(10,4), text='Scollbars') -ttk.TTkLabel(parent=root, pos=(10,7), text='Basic Table') - -# Testing Widgets from "test.ui.004.windows.py" -test_win1 = ttk.TTkWindow(parent=root,pos = (10,1), size=(70,35), title="Test Window 1", border=True) -test_win1.hide() -btn1.clicked.connect(test_win1.show) -btn2.clicked.connect(test_win1.hide) - -test_win2_1 = ttk.TTkWindow(parent=test_win1,pos = (3,3), size=(40,20), title="Test Window 2.1", border=True) -test_win2_1.setLayout(ttk.TTkHBoxLayout()) -ttk.TTkTestWidget(parent=test_win2_1, border=False) - -test_win2_2 = ttk.TTkWindow(parent=test_win1,pos = (5,5), size=(40,20), title="Test Window 2.2", border=True) -test_win2_2.setLayout(ttk.TTkHBoxLayout()) -ttk.TTkTestWidget(parent=test_win2_2, border=False) - - -test_win3 = ttk.TTkWindow(parent=root,pos = (20,5), size=(70,25), title="Test Window 3", border=True) -test_win3.hide() -test_win3.setLayout(ttk.TTkHBoxLayout()) -btn1.clicked.connect(test_win3.show) -btn2.clicked.connect(test_win3.hide) - -ttk.TTkTestWidget(parent=test_win3, border=True, maxWidth=30, minWidth=20) -rightFrame = ttk.TTkFrame(parent=test_win3, border=True) -rightFrame.setLayout(ttk.TTkVBoxLayout()) - -ttk.TTkTestWidget(parent=rightFrame, border=True, maxSize=(50,15), minSize=(30,8)) -bottomrightframe = ttk.TTkFrame(parent=rightFrame,border=True) - -test_win4 = ttk.TTkWindow(parent=bottomrightframe, pos = (3,3), size=(40,20), title="Test Window 4", border=True) -test_win4.setLayout(ttk.TTkHBoxLayout()) -ttk.TTkTestWidget(parent=test_win4, border=False) - - -# Scroller window from test.ui.006.scroll.py -win_scroller = ttk.TTkWindow(parent=root,pos=(30,3), size=(50,30), title="Test Window 1", border=True) -win_scroller.hide() -btn3.clicked.connect(win_scroller.show) -btn4.clicked.connect(win_scroller.hide) -win_scroller.setLayout(ttk.TTkVBoxLayout()) -top = ttk.TTkFrame(parent=win_scroller, layout=ttk.TTkHBoxLayout()) -ttk.TTkScrollBar(parent=win_scroller, orientation=ttk.TTkK.HORIZONTAL, value=0, color=ttk.TTkColor.bg('#990044')+ttk.TTkColor.fg('#ffff00')) -ttk.TTkScrollBar(parent=win_scroller, orientation=ttk.TTkK.HORIZONTAL, value=10, color=ttk.TTkColor.bg('#770044')+ttk.TTkColor.fg('#ccff00')) -ttk.TTkScrollBar(parent=win_scroller, orientation=ttk.TTkK.HORIZONTAL, value=50, color=ttk.TTkColor.bg('#660044')+ttk.TTkColor.fg('#88ff00')) -ttk.TTkScrollBar(parent=win_scroller, orientation=ttk.TTkK.HORIZONTAL, value=80, color=ttk.TTkColor.bg('#550044')+ttk.TTkColor.fg('#55ff00')) -ttk.TTkScrollBar(parent=win_scroller, orientation=ttk.TTkK.HORIZONTAL, value=99, color=ttk.TTkColor.bg('#330044')+ttk.TTkColor.fg('#33ff00')) - - -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=0) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=10) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=40) -ttk.TTkSpacer(parent=top) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=40, pagestep=3) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=50, pagestep=5) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=60, pagestep=20) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=70, pagestep=30) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=80, pagestep=60) -ttk.TTkSpacer(parent=top) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=80) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=90) -ttk.TTkScrollBar(parent=top, orientation=ttk.TTkK.VERTICAL, value=99) - - -# Table window from test.ui.008.table.py words = ["Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", "commodo", "consequat.", "Duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint", "occaecat", "cupidatat", "non", "proident,", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum."] def getWord(): return random.choice(words) -def getSentence(): - return " ".join([getWord() for i in range(0,random.randint(6, 20))]) +def getSentence(a,b): + return " ".join([getWord() for i in range(0,random.randint(a,b))]) -win_table = ttk.TTkWindow(parent=root,pos = (10,0), size=(60,30), title="Test Table 1", layout=ttk.TTkHBoxLayout(), border=True) -win_table.hide() -btn5.clicked.connect(win_table.show) -btn6.clicked.connect(win_table.hide) -table = ttk.TTkTable(parent=win_table) +ttk.TTkLog.use_default_file_logging() -table.setColumnSize((20,-1,10,15)) -table.appendItem(("","You see it's all clear, You were meant to be here, From the beginning","","")) -for i in range(0, 100): - table.appendItem((str(i)+" - "+getWord(), getSentence(), getWord(), getWord())) -table.appendItem(("This is the end", "Beautiful friend, This is the end My only friend", "the end", "...")) +root = ttk.TTk() +winTabbed1 = ttk.TTkWindow(parent=root,pos=(1,1), size=(100,40), title="Test Tab", border=True, layout=ttk.TTkGridLayout()) +tabWidget1 = ttk.TTkTabWidget(parent=winTabbed1, border=True) +tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.1"), "Label 1.1") +tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.2"), "Label Test 1.2") +tabWidget1.addTab(demoLayout(), "Layout Test") +tabWidget1.addTab(demoFormWidgets(), "Form Test") +tabWidget1.addTab(demoTable(), "Table Test") +tabWidget1.addTab(demoTree(), "Tree Test") +tabWidget1.addTab(demoSplitter(), "Splitter Test") +tabWidget1.addTab(demoWindows(), "Windows Test") +tabWidget1.addTab(demoTab(), "Tab Test") -root.mainloop() \ No newline at end of file +root.mainloop() diff --git a/tests/test.ui.012.tab.py b/tests/test.ui.012.tab.py new file mode 100755 index 00000000..6963253d --- /dev/null +++ b/tests/test.ui.012.tab.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2021 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys, os + +sys.path.append(os.path.join(sys.path[0],'..')) +import TermTk as ttk + +ttk.TTkLog.use_default_file_logging() + +root = ttk.TTk() + +winTabbed1 = ttk.TTkWindow(parent=root,pos=(1,1), size=(100,40), title="Test Tab", border=True, layout=ttk.TTkGridLayout()) +tabWidget1 = ttk.TTkTabWidget(parent=winTabbed1, border=True) +tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.1"), "Label 1.1") +tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.2"), "Label 1.2") +tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.3"), "Label Test 1.3") +tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.4"), "Label 1.4") +tabWidget1.addTab(ttk.TTkTestWidget(border=True, title="Frame1.5"), "Label Test 1.5") +tabWidget1.addTab(ttk.TTkTestWidgetSizes(border=True, title="Frame1.6"), "Label 1.6") + +root.mainloop() \ No newline at end of file